M-Pesa B2B

How to automate disbursement to PayBill and Till Numbers

The M-Pesa B2B API is used to send money to PayBill and Till Numbers from the IntaSend's configured PayBill Number. Use case for this is mainly bill and suppliers payments.

M-Pesa B2B Fields

When sending payment using the M-Pesa B2B API, the following fields must be specified in your transaction item. Please note the difference between sending to a Paybill and the TillNumber. An account_type must be specified. For Paybill, account_reference is required.

A. Sending to PayBill

FieldValue
nameName of the beneficiary i.e business
accountPaybill number
account_referenceProvide reference account for this transaction.
account_typePaybill
amountAmount to send in KES
narrativePurpose of payment

B. Sending to TillNumber

FieldValue
nameName of the beneficiary i.e business
accountTill number of the beneficiary
account_typeTillNumber
amountAmount to send in KES
narrativePurpose of payment

πŸ“˜

Note:

The account_type field is case-sensitive and must be specified exactly as shown in the tables above.

Step 1: Initiate M-Pesa B2B

To begin, please go through the Send Money Pre-requisite 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': 'Business 1', 'account': 247247, 'account_type': 'PayBill', 'account_reference': '5172627278', 'amount': 10, 'narrative': 'Invoice X'},
                {'name': 'Business 2', 'account': 123211, 'account_type': 'TillNumber', 'amount': 10000, 'narrative': 'Purchase'}]

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

$transactions = [
  ['name' => 'Business A','account'=>'524311','amount'=>'200', 'account_type'=>'PayBill', 'account_reference'=>'29822182', 'narrative'=> 'Bill Payment'],
  ['name' => 'Business B','account'=>'17626','amount'=>'150', 'account_type'=>'TillNumber', 'narrative'=> 'Purchase']
];

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

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

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

let payouts = intasend.payouts();

payouts
  .mpesaB2B({
    currency: 'KES',
    transactions: [
      {
        name: 'Business A',
        account: '21222',
        account_type: 'PayBill',
        account_reference: '5172627278',
        amount: 20,
        narrative: 'Purchase'
      }, 
      {
        name: 'Business B',
        account: '45422',
        account_type: 'TillNumber',
        amount: 50,
        narrative: 'Purchase'
      }
    ]
  })
  .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);
  });

Like the M-Pesa B2C transactions, the B2B is also a two step and requires approval.

Step 2: How to approve B2B Transaction

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);
    });