M-Pesa STK Push

How to trigger M-Pesa STK push directly without generating a link.

You might want to trigger the M-Pesa STK push directly to the user i.e without introducing additional steps e.g redirecting the user to a URL. With this request, the user gets then M-Pesa prompt to enter their PIN and completes the transaction.

Below is a code example on how to send M-Pesa STK Push.

from intasend import APIService

publishable_key = "INTASEND_PUBLISHABLE_KEY"

service = APIService(token=token,publishable_key=publishable_key)

response = service.collect.mpesa_stk_push(phone_number=2547...,
                                  email="[email protected]", amount=10, narrative="Purchase")
print(response)
use IntaSend\IntaSendPHP\Collection;

$collection = new Collection();
$collection->init($credentials);

$response = $collection->create($amount=10, $phone_number="2547...", $currency="KES", $method="MPESA_STK_PUSH", $api_ref="Your API Ref", $name="", $email="[email protected]");
print_r($response);
const IntaSend = require('intasend-node');

let intasend = new IntaSend(
    '<INTASEND_PUBLISHABLE_KEY>',
    '<INTASEND_SECRET_KEY>',
    true, // Test ? Set true for test environment
);

let collection = intasend.collection();
collection
   .mpesaStkPush({
  		first_name: 'Joe',
    	last_name: 'Doe',
    	email: '[email protected]',
    	host: 'https://yourwebsite.com',
  		amount: 10,
    	phone_number: '254722000000',
    	api_ref: 'test',
  })
  .then((resp) => {
  	// Redirect user to URL to complete payment
  	 console.log(`STK Push Resp:`,resp);
	})
  .catch((err) => {
     console.error(`STK Push Resp error:`,err);
  });