Envision a world where payments are processed instantly, with customers increasingly opting for mobile money transactions. The M-Pesa C2B (Consumer To Business) API facilitates such transactions, offering convenience for both merchants and customers alike. With the M-Pesa C2B API, businesses can streamline payment processes effectively.
The C2B API enables Paybill and Buy Goods merchants to integrate with M-PESA Mobile Money and receive real-time payment notifications.
To get started, simply provide us with your Paybill or Buy Goods number. You can set up as many Paybill or Buy Goods numbers as needed, each linked to Safaricom's M-PESA through their payment channels.
Validation is often the first step in completing a C2B transaction. It helps detect errors (e.g., wrong account number or amount), reducing the need for transaction reversals. Understanding how to integrate M-Pesa C2B API is key to successful implementation.
To enable C2B validation, configure a validation URL in your account. The POST request sent to your validation callback URL will include a JSON object with the following parameters:
{ "result_code": "200", "result_desc": "Processed Successfully", "request_id": "Rm20180307054639H4adfKDJDKQ7H", "phone_number": "2547*****149", "customer_name": "James", "amount": "200", "short_code": "888555", "bill_ref_number": "QWERT", "third_party_trans_id": "HR8584JDJD", "account_balance": "34000.00", "transaction_time": "2017-05-18 18:23:23" }
Respond to a validation callback with a JSON object indicating the transaction status. Use "status_code": 200 for Validated or 400 for Failed. A Validated status means the transaction will proceed; a Failed status means it will be canceled.
Parameter | Type | Description | Example |
---|---|---|---|
status_code | Number | Status code of the transaction: 200 for Validated, 400 for Failed | 200 |
description | String | Description of the status code | Validated |
{ "status_code": 200, // or 400 "description": "Validated" // or "Failed" }
Payment confirmation is the final step in completing a transaction. After processing a payment, M-PESA sends a confirmation request to your Paybill or Buy Goods number, notifying you of the transaction's completion.
The POST parameters in the confirmation request are as follows:
Parameter | Type | Description | Example |
---|---|---|---|
request_id | String | Unique reference number assigned by the API | Rw20180307054639H4adfKDJDKQ7H |
result_code | String | Result code of the transaction | 200 |
result_desc | String | Description of the transaction status | Processed Successfully |
third_party_trans_id | String | Reference number assigned by the mobile money provider | HR8584JDJD |
short_code | String | Paybill number or Till number being paid to | 888555 |
transaction_time | String | Date and time of the transaction | 2017-05-18 18:23:23 |
account_balance | String | Paybill or Buy Goods account balance | 34000.00 |
bill_ref_number | String | Account number entered by the subscriber (optional for Paybill payments) | QWERT |
phone_number | String | Subscriber's phone number (payer) | 2547*****149 |
customer_name | String | Name of the subscriber who made the payment | John |
amount | String | Transaction amount | 200 |
{ "result_code": "200", "result_desc": "Processed Successfully", "request_id": "Rm20180307054639H4adfKDJDKQ7H", "phone_number": "2547*****149", "customer_name": "James", "amount": "200", "short_code": "888555", "bill_ref_number": "QWERT", "third_party_trans_id": "HR8584JDJD", "account_balance": "34000.00", "transaction_time": "2017-05-18 18:23:23" }
Want to simplify your payment processes? Contact Statum today to integrate the M-Pesa C2B API for seamless transactions with real-time validation and confirmation.