Appearance
Change your integration
Replace the legacy login, create call and callback with a key, one create call and a read of the checkout.
Before and after
Legacy request:
POST /api/checkout/init/payment
Authorization: Bearer <token>
Accept: application/json
{
"payment_method": "cards",
"currency": "KES",
"amount": "10",
"customer_name": "test name",
"customer_phone": "254700000000",
"customer_email": "testname@gmail.com",
"customer_address": null,
"order_number": "order-1042",
"callback_url": "http://localhost:8043/sample/return/callback",
"callback_method": "get",
"multiple_iframes": 1,
"checkout_mode": 1,
"custom_fields": []
}MOOKHPay request:
POST /v1/payments/merchant/checkouts
Authorization: Bearer mkp_…
Idempotency-Key: order-1042
Content-Type: application/json
{
"amount": 1000,
"reference": "order-1042",
"description": "Order 1042",
"return_url": "https://yourshop.example/paid",
"phone": "254700000000"
}The response has a checkout id and a url. Redirect the payer to url. See Create a checkout.
Map each field
| Legacy | MOOKHPay | What to do |
|---|---|---|
POST /api/login | A key | Send Authorization: Bearer mkp_…. Remove the login call and the token cache |
amount in whole units | amount in minor units | Multiply by 100. "10" becomes 1000 |
currency | None | Remove it. The host sets KES or UGX |
payment_method | None | Remove it. The payer chooses on the hosted page |
customer_name, customer_email, customer_address | None | Remove them |
customer_phone | phone | Optional. It fills the phone field of the payer. Use 9 to 15 digits with the country code and no + |
order_number | reference and Idempotency-Key | Send the same order id in both. See Idempotency |
callback_url, callback_method | return_url | The payer goes to return_url after a completed payment. It must use https |
checkout_mode 0 | The hosted page | Redirect the payer to url |
checkout_mode 1 | None | Move to the hosted page |
custom_fields, multiple_iframes | None | Remove them. Use reference and description |
MOOKHPay refuses unknown fields with 400 and code 1701. Remove every field in the table that has no replacement.
Pick the host
Each country has its own host. A checkout exists only on the host that created it. A Kenyan key works only on the Kenyan host. See Environments.
Confirm the payment
The legacy API sent a callback or IPN to your server. MOOKHPay does not call a URL that you set for each order. You read the checkout.
- Store the checkout
idwith your order. - Send the payer to
url. - When the payer returns to
return_url, readcheckoutfrom the query string. - Call
GET /v1/payments/merchant/checkouts/{id}with your key. - Fulfill the order only when
statusiscompleted. - Fulfill each checkout once.
Do not trust status in the query string. Anyone can open that URL. See Confirming a payment for how to check payments that you did not see return.
Statuses
Legacy payment_status | MOOKHPay status |
|---|---|
paid | completed |
pending | open |
failed | No equivalent. A declined prompt leaves the checkout open. The payer can try again |
partial | No equivalent |
cancelled | No equivalent |
| None | expired. The checkout time ran out and no attempt is in progress |
Find a payment later
There is no lookup by order_number or by payment reference. Store the checkout id when you create the checkout. Read it with GET. The reference that you send comes back in the response, and the payer does not see it.
Common mistakes
| Mistake | Cause | Fix |
|---|---|---|
| The payer is charged 100 times too little | You sent the legacy amount | Multiply by 100 |
400 and code 1701 | The body has a legacy field, or Idempotency-Key is missing | Remove the field. Send the header |
422 and code 3015 | You reused an Idempotency-Key with a new body | Use one key for each order, and a new key when the order changes. A replay with the same body returns the first checkout |
| A new checkout for each retry | You made a new random Idempotency-Key for each try | Store the key with the order and reuse it |
400 for phone | The number has a + | Send digits only |
401 and code 2781 | The key is wrong, revoked, or was replaced more than 24 hours ago | Check the key. Deploy the key that replaced it |
404 and code 2783 | The id belongs to another organisation | Use the id from your own create call |
| The order ships twice | You fulfilled from the return URL or on each read | Fulfill once for each checkout id, and only after GET says completed |
See Errors for every code.