C2B Register URLs and Simulation
Register your URLs
Section titled “Register your URLs”await mpesa.c2b.registerUrls({ confirmationUrl: "https://example.com/mpesa/c2b/confirm", validationUrl: "https://example.com/mpesa/c2b/validate", responseType: "Completed",});Simulate in sandbox
Section titled “Simulate in sandbox”await mpesa.c2b.simulate({ amount: 100, msisdn: "254712345678", billRefNumber: "invoice-001",});Important behavior
Section titled “Important behavior”simulate()is sandbox-only and the SDK will reject production usage.- Validation and confirmation routes should be real public URLs when you test against Daraja.
- The SDK normalizes the API response shape so you consistently receive
OriginatorConversationIDeven if older samples use a misspelled variant.
When to use validation vs confirmation
Section titled “When to use validation vs confirmation”- Validation runs before completion and lets you reject bad bill references or account numbers.
- Confirmation runs after payment completion and should be treated as your payment receipt event.