When customers pay a business directly by entering its shortcode into their M-Pesa app — rather than responding to an STK Push — those payments arrive through a different channel: the Safaricom C2B webhook. The iVendNext Kenya M-Pesa Integration captures these incoming payments automatically, records them in a structured register, and provides tools to link each payment to a customer and reduce the outstanding balance on the matching invoice. This article explains how the C2B payment capture and reconciliation workflow operates in iVendNext Desk.
For paybill or till payments initiated by customers, Safaricom posts a webhook notification to a registered callback URL the moment a payment is confirmed. iVendNext receives this webhook and automatically creates a Mpesa C2B Payment Register record — no manual entry is required.
For this to work, the callback URL must be registered with Safaricom once per shortcode before payments can be received. This registration is done from within iVendNext Desk using the Mpesa C2B Payment Register URL DocType.Go to Mpesa C2B Payment Register URL and click New.
Enter the Business Shortcode that matches the Mpesa Settings record for your shortcode.
Select your Company and the Mode of Payment that was created automatically by your Mpesa Settings.
Click Register URL.
iVendNext builds the callback URL from your site address and submits it to Safaricom's Daraja API. This is a one-time step per shortcode. After registration, all incoming payments to that shortcode are delivered to iVendNext automatically.
Each incoming C2B payment creates a Mpesa C2B Payment Register record. The company, currency, and Mode of Payment are populated automatically from the configuration set on the registered URL — the finance team does not need to fill these in manually.
Key fields on this record include:
Trans ID — Safaricom's unique transaction identifier for the incoming payment
Trans Time — the timestamp of the payment as reported by Safaricom
Trans Amount — the amount paid in KES
Bill Ref Number — the reference entered by the customer when paying (for example, an invoice number)
MSISDN — the customer's phone number
First Name, Last Name — customer name as registered with Safaricom
Customer — a link to the iVendNext customer record, which the finance team can set manually to enable reconciliation
Company, Currency, Mode of Payment — set automatically from the registered URL configuration
Posting Date — set automatically from the transaction time
Submit Payment — a checkbox controlling whether submitting the record triggers Payment Entry creation
Once a C2B Payment Register record has been created, the accountant links it to the correct customer by setting the Customer field. This lookup allows iVendNext to match the payment to open invoices for that customer.
When the record is submitted with Submit Payment enabled, iVendNext calls the Payment Entry creation logic, which:
Creates a Payment Entry linked to the customer and the Mode of Payment
Matches the payment against any outstanding invoice references associated with the customer
Reduces the outstanding balance on those invoices accordingly

For businesses that prefer a fully hands-off workflow, the Auto Reconcile C2B setting on Mpesa Settings eliminates the manual submission step entirely. When this option is enabled, iVendNext automatically submits every incoming C2B Payment Register record the moment the webhook is received. If a matching customer can be determined from the Bill Ref Number or MSISDN, the Payment Entry is created and the invoice is reconciled without any human action.

Safaricom's STK Push flow and the C2B webhook flow can sometimes reference the same underlying transaction. For example, a payment confirmed through an STK Push also generates a C2B webhook notification. Without a guard, this could result in the same transaction being recorded twice — once as an Mpesa Express Request and once as a C2B Payment Register — leading to a doubled Payment Entry.
iVendNext prevents this with a before-insert check on the C2B Payment Register. When a new record is about to be created, the system checks whether an Mpesa Express Request already exists with the same transaction identifier. If a match is found, the insert is blocked and an error is raised: "Cannot record C2B payment: Express Request {name} already exists." This ensures that each payment is recorded exactly once, regardless of how many Safaricom callbacks reference it.In normal operations, the finance team opens the Mpesa C2B Payment Register list at the start of the day and sees all overnight incoming payments already created and waiting. Each record shows the amount, the customer's phone number, and the Bill Ref Number. The accountant sets the Customer field, checks the amount against the invoice, and submits. If Auto Reconcile C2B is enabled, the list may already show records in Submitted status with Payment Entries linked.
