Merchants
Charging for a reference
Take M-Pesa, e-Mola or a card on your own page for one of your customers' references, and have the money reported as an incoming transfer to that reference.
An account that collects for its own customers (a wallet: KulOffice) charges on its own page, through the API, never through a hosted link. It names the customer reference the money is for in deposit_reference: when the charge succeeds, KulPay also records it as an incoming transfer to that reference, in the same transaction, exactly as for a deposit at a partner. Your account credits its customer from the transfer, with all its own rules.
Cards are typed in KulPay's card fields on your page (a ctk_ token); a card may ask the payer for 3-D Secure, and the payer's browser then goes to the bank's page and comes back to your return_url.
Before you start
The account has cash_in_incoming on (an operator sets it), a key with payments:write and payments:read, and, for cards, a publishable pk_ key and your page's origin in the account's card_field_origins (PUT /v1/admin/accounts/{id}/card-settings): only those pages may embed the card fields.
The flow at a glance
| # | Who | What happens |
|---|---|---|
| 1 | Your system | Lists the rails for this payment, with its currency and amount. |
| 2 | Payer | Picks a rail; types a phone, or the card in KulPay's card fields (a ctk_ token). |
| 3 | Your system | Charges with deposit_reference and its own payment_id. |
| 4 | Payer | Approves on the phone, or completes 3-D Secure and returns to your page. |
| 5 | Your system | Reads the payment until it is final, and credits its customer from the incoming transfer charge:{payment_id}. |
1. List the rails for this payment
Your system.
GET /methods · API reference
GET /methods?currency=MZN&amount=250.00 (also /v1/methods) leaves out the rails whose currency or bounds do not fit, and, with your key, those your account cannot charge now. payer_code: true marks a rail charged with a one-time code from the payer's wallet rather than a push; leave it out if your page has no code field.
2. Charge for the reference
Your system.
POST /charges · API reference
Send the reference in deposit_reference (3-40 characters of letters, digits and @ . _ -), never in metadata (metadata.deposit_reference is reserved). Use your own payment id as payment_id and as the Idempotency-Key. A card answers requires_action with next_action: {type: "redirect_to_url", redirect_url, return_url} when the bank asks for 3-D Secure: send the payer's browser to redirect_url (a top-level navigation).
Request
{
"payment_id": "spy_3KXa9",
"money": {
"amount": "250.00",
"currency": "MZN"
},
"source": {
"type": "card",
"card": {
"token": "ctk_8Hq2LmP0vX"
}
},
"deposit_reference": "KC-7K3QXMD",
"description": "Loja Sol VD-AB12CD34",
"return_url": "https://pay.example.co.mz/pt-MZ/q/qrc_abc123?pagamento=spy_3KXa9"
}
3. Read the payment
Your system, while the payer approves, and when they come back from 3-D Secure.
GET /payments · API reference
GET /payments?payment_id=spy_3KXa9 (or GET /payments/{provider_payment_id}) reads the acquirer when the payment is not final and answers its status. next_action is there only while it is requires_action. An answer you lost is read back this way: never charge again with another key.
States
| State | What it means |
|---|---|
requires_action | The payer must complete 3-D Secure at |
processing | Waiting on the payer's phone or the acquirer. |
succeeded | Paid; the incoming transfer |
failed | Not paid. |
When the money moves
The money is your account's from the charge. The incoming transfer (partner_reference charge:{payment_id}, destination_type deposit_reference, matched_by charge_reference, confirmed_final) only tells you which reference it was for: it posts nothing more. A failed charge records none.
Events
| Event | What it tells you |
|---|---|
payment.succeeded | Paid. |
incoming_transfer.confirmed_final | The charge recorded for its reference; credit your customer. |
payment.failed | Not paid. |
Errors that matter here
Every error is application/problem+json with a stable code; branch on the code, not the message. The full list is in the error catalogue.
| Error | When | What to do |
|---|---|---|
400 invalid_deposit_reference | A malformed reference, a reference in metadata, or a payment_id over 120 characters. | Send a well-formed top-level deposit_reference. |
422 deposit_reference_unsupported | The account does not have cash_in_incoming on. | Ask the operator to turn it on, or charge without a reference. |
409 duplicate_payment_id | An incoming transfer already carries this payment_id (another Idempotency-Key). | Read the existing payment, or use a new payment_id. |
Testing it
Against the PSP simulator's SIMO, card 6399990000000016 is approved, 6399990000000024 asks for 3-D Secure (approve or decline on the simulator's page), 6399990000051019 is declined for funds and 6399990000005015 is declined by the issuer.