Skip to content

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": "[email protected]",
  "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 ​

LegacyMOOKHPayWhat to do
POST /api/loginA keySend Authorization: Bearer mkp_…. Remove the login call and the token cache
amount in whole unitsamount in minor unitsMultiply by 100. "10" becomes 1000
currencyNoneRemove it. The host sets KES or UGX
payment_methodNoneRemove it. The payer chooses on the hosted page
customer_name, customer_email, customer_addressNoneRemove them
customer_phonephoneOptional. It fills the phone field of the payer. Use 9 to 15 digits with the country code and no +
order_numberreference and Idempotency-KeySend the same order id in both. See Idempotency
callback_url, callback_methodreturn_urlThe payer goes to return_url after a completed payment. It must use https
checkout_mode 0The hosted pageRedirect the payer to url
checkout_mode 1NoneMove to the hosted page
custom_fields, multiple_iframesNoneRemove 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.

  1. Store the checkout id with your order.
  2. Send the payer to url.
  3. When the payer returns to return_url, read checkout from the query string.
  4. Call GET /v1/payments/merchant/checkouts/{id} with your key.
  5. Fulfill the order only when status is completed.
  6. 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_statusMOOKHPay status
paidcompleted
pendingopen
failedNo equivalent. A declined prompt leaves the checkout open. The payer can try again
partialNo equivalent
cancelledNo equivalent
Noneexpired. 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 ​

MistakeCauseFix
The payer is charged 100 times too littleYou sent the legacy amountMultiply by 100
400 and code 1701The body has a legacy field, or Idempotency-Key is missingRemove the field. Send the header
422 and code 3015You reused an Idempotency-Key with a new bodyUse 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 retryYou made a new random Idempotency-Key for each tryStore the key with the order and reuse it
400 for phoneThe number has a +Send digits only
401 and code 2781The key is wrong, revoked, or was replaced more than 24 hours agoCheck the key. Deploy the key that replaced it
404 and code 2783The id belongs to another organisationUse the id from your own create call
The order ships twiceYou fulfilled from the return URL or on each readFulfill once for each checkout id, and only after GET says completed

See Errors for every code.

Next ​

Check your payment methods and payouts.

Staging documentation. A checkout made with a secret key on staging charges a real phone. See Environments.