POST: Initiate MPESA STK Push Request
This endpoint enables you to initiate an MPESA STK Push request to a customer number to receive payments to your linked payment channel
Easily initiate an MPESA STK Push request to a customer's phone, facilitating seamless mobile payments. You can link your own Till Number, Pay bill Number or Bank Account. By using this endpoint, you can automate payment requests, streamline the payment process, and easily track transactions through Pay Hero's centralized system. This feature is designed to enhance payment efficiency for businesses and individuals using MPESA services.
API Description
POST
https://backend.payhero.co.ke/api/v2/payments
Headers
Authorization:*
String
Basic basicAuthToken
Request Body
amount*
Integer
Eg: 100
phone_number*
String
Eg: 0787677676
channel_id*
Integer
Your registered payment channel ID eg: 133
Can be found by logging in, under the Payment Channels menu, then My Payment Channels.
provider*
String
Value: m-pesa Or sasapay if you provided your wallet channel ID
external_reference
String
Your unique reference to track this transaction Eg: INV-009
customer_name
String
Customer name : Optional
callback_url
String
Your endpoint URL that we will use to send payment status response eg: https://example.com/callback.php
credential_id
String
Optional: this is the ID of your registered credential if you wish to integrate with your own API keys for Mpesa Daraja
network_code
String
Value: 63902 , This is provided If you provided your wallet channel ID, and provider is sasapay
{
"success": true,
"status": "QUEUED",
"reference": "E8UWT7CLUW",
"CheckoutRequestID": "ws_CO_15012024164321519708344109"
}
Ready Made Payment Page
Click on the above link to download ready made deposit page to start accepting payments on your app.
Sample Code To External Channel
This represents PHP Curl example of how to make the request to an external channel eg: Paybill,Till or Bank, you can implement this in your specific language of choice
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://backend.payhero.co.ke/api/v2/payments',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{
"amount": 10,
"phone_number": "0798766765",
"channel_id": 911,
"provider": "m-pesa",
"external_reference": "INV-009",
"customer_name":"John Doe",
"callback_url": "https://example.com/callback.php"
}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'Authorization: Basic 3A6anVoWFZrRk5qSVl0MGNMOERGMlR3dlhrQ0VWUWJHNDVVVnNaMEdDSw=='
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Sample Code To Wallet
This represents PHP Curl example of how to make the request to your Wallet you can implement this in your specific language of choice
Notes:
channel_id -is your wallet channel ID, can be found under payment channels
provider- use: sasapay
network_code- use 63902 for MPESA
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://backend.payhero.co.ke/api/v2/payments',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{
"amount": 10,
"phone_number": "0798766765",
"channel_id": 911,
"provider": "sasapay",
"network_code":"63902",
"external_reference": "INV-009",
"customer_name":"John Doe",
"callback_url": "https://example.com/callback.php"
}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'Authorization: Basic 3A6anVoWFZrRk5qSVl0MGNMOERGMlR3dlhrQ0VWUWJHNDVVVnNaMEdDSw=='
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Callback URL Response Sample
This represents the JSON that will be sent to your request callback_url, NOTE: it contains the ExternalReference that you provided in the request and CheckoutRequestID that was returned in the request response, you can use those to track and update your payments in your system/app
{
"forward_url": "",
"response": {
"Amount": 10,
"CheckoutRequestID": "ws_CO_14012024103543427709099876",
"ExternalReference": "INV-009",
"MerchantRequestID": "3202-70921557-1",
"MpesaReceiptNumber": "SAE3YULR0Y",
"Phone": "+254709099876",
"ResultCode": 0,
"ResultDesc": "The service request is processed successfully.",
"Status": "Success"
},
"status": true
}
Last updated
Was this helpful?