M-Pesa B2C

How to initiate and approve M-Pesa B2C transactions

M-Pesa B2C are ideal for payment disbursement to M-Pesa accounts. M-Pesa B2C is normally used for salary and promotional payments, remittance termination, and even business payouts if the beneficiary prefer to be paid direct to their M-Pesa phone number accounts rather than Till/PayBill numbers.

Like other send money transactions, the M-Pesa B2C is a two step process. The first step is to initiate the transaction and the second one is to approve the transactions. Both the initiate and the approval are automated with the API.

The payload contains transactions field which is of type array. This means you can send money to many beneficiaries in a single request.

M-Pesa B2C Transaction Fields

The following fields must be specified in your transaction item

FieldDescription
nameName of the beneficiary
accountBeneficiary phone number. Must be prefixed with the country code e.g 254....
amountAmount to send in KES
narrativePurpose of payment

Step 1: Initiate M-Pesa B2C

To begin, please go through the Introduction to obtain the API Keys, Device ID and everything else you need to proceed.

Once setup we recommend using the SDKs provided by IntaSend to make it easy for you to sign and approve with less efforts. We have done the heavy lifting for you, so do not reinvent the wheel if the SDK of your stack is already available.

NB: Refer to how to authenticate documentation for more details on client libraries setup.

from intasend import APIService

service = APIService(token=token)

transactions = [{'name': 'Awesome Customer 1', 'account': 25472.., 'amount': 10},
                {'name': 'Awesome Customer 2', 'account': 25472.., 'amount': 10000}]

response = service.transfer.mpesa(currency='KES', transactions=transactions)
print(response)
use IntaSend\IntaSendPHP\Transfer;

$transactions = [
    ['account'=>'254723890353','amount'=>'20'],
    ['account'=>'254723890260','amount'=>'15']
];

$transfer = new Transfer();
$transfer->init($credentials);

$response=$transfer->mpesa("KES", $transactions);
const IntaSend = require('intasend-node');

const intasend = new IntaSend(/*...Authenticate*/)

let payouts = intasend.payouts();

 payouts
   .mpesa({
     currency: 'KES',
     transactions: [{
       name: 'Joe Doe',
       account: '254708374149',
       amount: '10',
       narrative: 'Reason for payment'
     }]
 		})
   .then((resp) => {
     console.log(`Payouts response:`, resp);
     // Approve payouts method can be called here if you would
     // like to auto-approve immediately
   })
   .catch((err) => {
     console.error(`Payouts error:`, err);
   });

Step 2: Approve and release payment

Response from Step 1 is passed to the approve function.

approved_response = service.transfer.approve(response)
print(approved_response)
$response = $transfer->approve($response);
print_r($response);
payouts
  .approve(resp, false)
  .then((resp) => {
    console.log(`Payouts approve:`, resp);
  })
  .catch((err) => {
    console.error(`Payouts approve error:`,err);
  });