Accept payments
Checkout
Send your customer to a hosted payment page, then confirm the payment from your server.
Your server creates a checkout session, and you send your customer to the page it returns. The customer picks MTN or Airtel, approves the prompt on their phone, and comes back to your site. You build no payment form.
See the page first
Try the demo checkout: the page your customers pay on, for a demo store, in Rwanda or Uganda, approved or declined. It runs in your browser, so nothing you type is sent anywhere and no money moves.
The redirect is never proof of payment. The customer's browser decides
where it goes, and anyone can open your success_url. Before you fulfil an
order, confirm the session from your server with
GET /checkout/sessions/{id}, or with the checkout.session.completed
webhook.
Checkout, a direct charge, or a payment link
| Checkout | Direct charge | Payment link | |
|---|---|---|---|
| Use it when | You sell on a website and want the payment page built for you. | You already collect the number and network in your own app. | You bill people by message and have no website. |
| The customer types their number on | Our page | Your page | Our page |
| Created by | Your server, once per order | Your server, once per payment | You, in the dashboard |
| Amount | Fixed by your server | Fixed by your server | Fixed, or chosen by the payer |
| Customer returns to your site | Yes, to success_url or cancel_url | You stay on your site | Optional redirect_url |
Key requirements
- A secret key with
payments:writeto create sessions, andpayments:readto read them back. Ask_test_key while you build. - Your server makes the call. Never put a secret key in a web page or an app.
- Your business holds the currency: RWF or UGX. Test sessions check this too.
- Two pages on your site:
success_url, where the customer lands after paying, andcancel_url, where they land if they give up. - A webhook endpoint, recommended, so you hear about a payment even when the customer closes the tab.
| Rwanda | |
|---|---|
| Currency | RWF (country_code RW) |
| Phone format | 250788123456. Also accepted: 0788123456, +250788123456. |
| Networks | MTN or Airtel |
| Collect | MTN and Airtel mobile money |
| Pay out | MTN and Airtel mobile money, Bank account. A bank payout needs a bank_code from GET /payout-banks?country_code=RW. |
| Amounts | Whole francs: amount_minor a multiple of 100. 5,000 RWF is 500000. |
| Test numbers | Yes, for payouts: +250788000001 to +250788000005 force an outcome. |
How it works
- Your server creates a session with the amount, currency, your
reference, and the two return URLs. You get back an
id(cs_test_…orcs_live_…) and aurl. - You redirect the customer to
url:https://checkout.inversepay.app/c/{id}. - The customer pays on our page. They see your business name and the amount, pick MTN or Airtel, confirm or type their number, and approve the prompt on their phone. The page waits for the answer.
- The page sends them back. Paid: to your
success_url. Cancelled: to yourcancel_url. Both getsession_idadded to the query string. - Your server confirms the payment with the webhook or
GET /checkout/sessions/{id}, and fulfils only when the status iscomplete.
Step 1 — Create a session
Call this from your server when the customer chooses to pay.
curl -X POST https://api.inversepay.app/api/b/v1/checkout/sessions \
-H "Authorization: Bearer $INVERSEPAY_TEST_KEY" \
-H "Content-Type: application/json" \
-d '{
"amount_minor": 500000,
"currency": "RWF",
"reference": "ORDER-1042",
"success_url": "https://shop.example.com/orders/1042/paid",
"cancel_url": "https://shop.example.com/cart",
"customer": { "name": "Aline Uwase", "phone": "250788123456" },
"metadata": { "order_id": "1042" },
"expires_in_minutes": 30
}'{
"id": "cs_test_Q2h8mXv0pL4rT9sYw1bN6cJ3kD7fG5aE",
"url": "https://checkout.inversepay.app/c/cs_test_Q2h8mXv0pL4rT9sYw1bN6cJ3kD7fG5aE",
"status": "open",
"is_test": true,
"amount_minor": 500000,
"currency": "RWF",
"reference": "ORDER-1042",
"customer": { "name": "Aline Uwase", "email": null, "phone": "250788123456" },
"methods": null,
"success_url": "https://shop.example.com/orders/1042/paid",
"cancel_url": "https://shop.example.com/cart",
"metadata": { "order_id": "1042" },
"charge_id": null,
"failure_reason": null,
"expires_at": "2026-11-25T09:30:00Z",
"created_at": "2026-11-25T09:00:00Z",
"completed_at": null,
"expired_at": null,
"failed_at": null
}| Field | ||
|---|---|---|
amount_minor | required | What the customer pays, in minor units, in whole francs or shillings: a multiple of 100. Fixed for the life of the session; the page cannot change it. |
currency | required | RWF or UGX. A currency your business holds. |
reference | required | Your own, 1–128 characters, unique per business and mode. It makes the call safe to retry: see Idempotency. |
success_url | required | Where the customer goes after paying. http or https, up to 2,048 characters. |
cancel_url | required | Where the customer goes if they give up, or the payment fails or expires. Same rules. |
customer | optional | name, email and phone, all optional. Send phone in international form without the +, and the page offers it, masked, for the customer to confirm instead of typing it. |
metadata | optional | Your own data. Returned on the session, its webhooks and the charge it creates. Never shown to the customer. |
expires_in_minutes | optional | How long the customer has to start paying: 15 to 1,440 minutes. Default 30. |
methods | optional | ["mobile_money"], the only method today. Leave it out to offer every method. |
embed_origins | optional | The websites that may open this session with checkout.js and receive its result message. Up to 5 exact origins, such as https://shop.example.com: scheme, host and optional port, with no path or wildcard. https only, except that a test session also accepts http on your own machine (127.0.0.1, [::1] or the loopback host name). Leave it out to allow the origins of success_url and cancel_url. Not needed for the redirect. |
You do not need an Idempotency-Key header here: reference does that job.
Step 2 — Send the customer to the page
Redirect the customer's browser to the url from the response. Use it as it
comes; do not build it yourself.
app.post('/checkout', async (req, res) => {
const session = await createCheckoutSession(req.body.orderId); // Step 1
res.redirect(303, session.url);
});What the customer sees on the page:
- Your business name and the amount, and how long they have left.
- A test banner on a
cs_test_session: "Test mode. No real money moves for this payment." - The networks they can pay with: MTN or Airtel mobile money, as available for the currency.
- Their number. If you sent
customer.phone, they see only its last three digits (•••••••••456) and choose "That's me" or "Use another number". Otherwise they type it. - "Check your phone." The prompt comes from their network. The page waits, and keeps waiting if they reload it.
Whoever holds the URL can pay it. The page shows your business name, the amount and the masked number, and nothing else: not your reference, your metadata, or the customer's email. Send the URL to your customer only.
Step 3 — Handle the return
| What happened | Where the customer goes |
|---|---|
| Paid | Your success_url, automatically, a few seconds after the page sees the payment succeed. |
| Pressed Cancel | Your cancel_url. |
| The payment failed, or the session expired | The page says so, with a link back to your cancel_url. |
Both URLs arrive with session_id added, keeping any query string you gave
them:
https://shop.example.com/orders/1042/paid?session_id=cs_test_Q2h8mXv0pL4rT9sYw1bN6cJ3kD7fG5aEOn your success page, read session_id, then confirm it from your server
(Step 4) before you show "Paid". If the session is not complete yet, show
"We are confirming your payment" and let the webhook finish the order.
Cancel does not close the session. It stays open until expires_at, and
the customer can still pay it with the same URL until then. Do not treat a
visit to cancel_url as "this order will never be paid".
Step 4 — Verify the payment
Do this on your server, with your secret key, every time.
With the API
curl https://api.inversepay.app/api/b/v1/checkout/sessions/$SESSION_ID \
-H "Authorization: Bearer $INVERSEPAY_TEST_KEY"status: "complete" with a charge_id is the confirmation. Check that
the reference, amount and currency are the order's too. A session of another
business, of the other mode, or no session at all, all return
404 CHECKOUT_SESSION_NOT_FOUND.
To find a session by your own reference, list them:
curl "https://api.inversepay.app/api/b/v1/checkout/sessions?reference=ORDER-1042" \
-H "Authorization: Bearer $INVERSEPAY_TEST_KEY"GET /checkout/sessions returns an array, newest first, in your key's mode.
Filter with reference or status, and set limit from 1 to 200 (default
50).
To page, pass the id of the last session on a page as before to get the
next, older one. A page with fewer than limit sessions is the last. Sessions
created while you page never shift a page, so nothing is shown twice or
skipped. Keep status and reference the same on every page of one walk. A
before this listing did not give you is refused with 400 INVALID_CURSOR.
With a webhook
Register an endpoint and you receive:
| Event | When |
|---|---|
checkout.session.completed | The customer paid. Fulfil the order. |
checkout.session.failed | The payment failed. event.payload.reason says why. |
checkout.session.expired | Nobody started paying before expires_at, or you expired it. Release the order. |
Verify the X-InversePay-Signature header before you trust the body, exactly
as on Webhooks. data is the
session as GET /checkout/sessions/{id} returns it now, with the charge it
created under data.charge (or null if none). event is what was recorded
when it happened.
{
"id": "8f14e45f-ceea-467a-9c4b-1f0bd4f1a2c3",
"type": "checkout.session.completed",
"created_at": "2026-11-25T09:04:12Z",
"data": {
"id": "cs_test_Q2h8mXv0pL4rT9sYw1bN6cJ3kD7fG5aE",
"url": "https://checkout.inversepay.app/c/cs_test_Q2h8mXv0pL4rT9sYw1bN6cJ3kD7fG5aE",
"status": "complete",
"is_test": true,
"amount_minor": 500000,
"currency": "RWF",
"reference": "ORDER-1042",
"metadata": { "order_id": "1042" },
"charge_id": "3f1c9a2e-...",
"failure_reason": null,
"expires_at": "2026-11-25T09:30:00Z",
"completed_at": "2026-11-25T09:04:11Z",
"charge": {
"id": "3f1c9a2e-...",
"reference": "ORDER-1042",
"amount_minor": 500000,
"currency": "RWF",
"status": "succeeded",
"channel": "mobile_money",
"is_test": true
}
},
"event": {
"id": "c2b0...",
"created_at": "2026-11-25T09:04:11Z",
"payload": {
"session_id": "cs_test_Q2h8mXv0pL4rT9sYw1bN6cJ3kD7fG5aE",
"reference": "ORDER-1042",
"status": "complete",
"charge_id": "3f1c9a2e-..."
}
}
}- Each event fires at most once per session. A payment the network
confirms late arrives as
checkout.session.failed, thencheckout.session.completed. Letcompletedwin. - Handle duplicates and order by session id. The same delivery can arrive
twice, and order is not guaranteed. Read
data.status. - The payment is also an ordinary charge, so an endpoint that takes every
event also receives
charge.createdandcharge.succeededorcharge.failedfor it, with your reference. Fulfil from one of them, not both.
Statuses and expiry
status | What it means |
|---|---|
open | Waiting for the customer, or their payment is in progress. |
complete | Paid. charge_id is set. Final. |
failed | The payment failed. failure_reason says why, from the same list as a charge. |
expired | Nobody started paying before expires_at, or you expired it. Final. |
Only complete means you were paid.
- A session is single use. It produces at most one payment. After
failedorexpired, create a new session with a new reference. failedis not always final. A payment the network confirms late moves the session fromfailedtocomplete. Do not cancel the order the momentfailedarrives.- A session expires
expires_in_minutesafter you create it: 30 by default, 15 to 1,440. Reads apply the clock, so an overdue session reads asexpiredat once.checkout.session.expiredfollows within about a minute. - A payment already started does not expire. Once the customer has
approved, or is approving, the session follows the payment to
completeorfailed, whatever the clock says. So a session can complete after itsexpires_at. - The customer pressing Cancel does not end the session. They are sent to
your
cancel_url, and may come back and pay beforeexpires_at. To make the link dead, expire it.
End a session early
For a cart your customer abandoned or an order that changed, expire the session so its link can no longer be paid:
curl -X POST https://api.inversepay.app/api/b/v1/checkout/sessions/$SESSION_ID/expire \
-H "Authorization: Bearer $INVERSEPAY_TEST_KEY"- It returns the session, now
expired, and sendscheckout.session.expiredonce. Expiring a session that has already expired returns it unchanged with200, so a retry is safe. - Only a session nobody has started paying can be expired. While a payment
is in progress the answer is
409 CHECKOUT_IN_PROGRESS: that money may still arrive, and the session ends ascompleteorfailedby itself. Wait for the webhook. - A session already
completeorfailedis409 CHECKOUT_SESSION_CLOSED, withstatussaying which. expires_atkeeps its original value;expired_atsays when it ended.
To make Cancel final, call this from your cancel_url handler.
Idempotency
reference is the idempotency key, unique per business and per mode.
- The same request again: you get the existing session back as it now
stands, with
201, not a second one. Retrying after a timeout is safe, even after the customer has paid (status: complete). - The same reference with any field changed (amount, currency, a redirect
URL, customer, methods, metadata, expiry or
embed_origins): refused with409 REFERENCE_IN_USE.session_idnames the session that holds the reference, andfieldslists what differs. Send the original request to get it back, or use a new reference. - A reference whose session expired or failed: refused with
409 REFERENCE_SESSION_CLOSED, withsession_idandstatus. A session is single use, so for the next attempt at the same order use a new reference, such asORDER-1042-2. - Test and live never share a reference, so references you used while building cannot collide with real ones.
Test mode
A sk_test_ key creates test sessions: the id starts cs_test_, the page
shows a test banner, no phone is prompted, and no money moves. Use the same
page at the same address; the session decides the mode.
The payment resolves as soon as the customer confirms on the page, by amount:
amount_minor | Result | Checkout webhook |
|---|---|---|
999999 | failed, failure_reason: insufficient_funds | checkout.session.failed |
999998 | The payment starts and never finishes. The session stays open and the page keeps waiting. It never expires. | none |
| anything else | complete | checkout.session.completed |
The magic amounts work in RWF test sessions, although they are not whole
francs. Live RWF sessions take whole francs only: a multiple of 100.
The number is still checked in test mode: it must be a Rwandan mobile number,
2507XXXXXXXX, on MTN or Airtel. The page shows the refusal and lets the
customer correct it.
- The magic phone numbers on Testing are for payouts. A checkout payment is decided by the amount alone.
- Webhooks go to endpoints registered with a test key, about five seconds after the change. A live endpoint never receives a test event.
Publishable keys
A publishable key (pk_test_… or pk_live_…) names your business and mode to
the checkout page. It is built to sit in a web page's source.
- It authenticates nothing. It has no scopes, and every authenticated
endpoint refuses it with
401. It cannot create a session, read one, or read anything else. - It is a check. When a page sends one with a session, in the
X-InversePay-Publishable-Keyheader, the session must belong to that key's business and mode, or the page is refused with400 PUBLISHABLE_KEY_MISMATCH. That catches a test session on your live site, or the reverse. - You do not need one for the redirect described on this page. It goes next to the checkout script, below.
- Get one in the dashboard, under Settings → API & developer. A live one needs the same verified business a live secret key does.
Popup and overlay
checkout.js opens the same hosted page over your site instead of sending the
customer away: in a popup window (the default) or an overlay dialog on
your page. You create the session on your server exactly as in
Step 1, and send only its id to the browser.
1. Load the script.
<script
src="https://checkout.inversepay.app/v1/checkout.js"
integrity="sha384-FliseaspptLzZrCF4A7TM1cDovKx6vXGXajGIr7YoOil6FJWpkxUy1o2t26KwiKH"
crossorigin="anonymous"></script>integrity pins these exact bytes, and crossorigin="anonymous" is required
with it. When v1 changes (fixes only, never a breaking change) this page
publishes the new hash, and a page still pinning the old one fails closed: the
script does not load until you update it. Leave integrity out to always get
the current v1.
2. Open the checkout from a click. Browsers allow popups only on a user gesture.
document.querySelector('#pay').addEventListener('click', () => {
const handle = InversePay.checkout({
sessionId: 'cs_test_…', // from your server
publishableKey: 'pk_test_…', // never sk_…
mode: 'popup', // or 'overlay'
onComplete: ({ sessionId }) => confirmOnServer(sessionId), // NOT proof of payment
onFailed: () => showRetry(), // the session is over: create a new one
onExpired: () => showRetry(),
onClose: ({ sessionId }) => confirmOnServer(sessionId), // they may have paid first
onPopupBlocked: ({ url }) => showLink(url), // optional, popup only
});
});| Option | |
|---|---|
sessionId | Required. cs_test_… or cs_live_…. |
publishableKey | Required. A publishable key in the session's mode. A secret key is refused before anything is sent or opened. |
mode | popup (the default) or overlay. |
onComplete, onFailed, onExpired | How the session ended: at most one of them, once. The checkout stays on its receipt until the customer closes it; call handle.close() to close it yourself. |
onClose | The customer closed it (Cancel, Close, Escape, or the window's own close box). |
onPopupBlocked | Popup only. Called with { sessionId, url } if the browser blocks the window. Without it, your page goes to the full-page checkout, which ends on your success_url or cancel_url. |
Each callback gets { sessionId, status }. Bad input throws an
InversePayError with a code: invalid_session_id,
invalid_publishable_key, mode_mismatch, invalid_mode, invalid_callback
or secret_key. Opening a second checkout closes the first.
Which sites can open it. A session can be opened only from the origins in
its embed_origins, or, if you sent none, the origins of its success_url and
cancel_url. www.shop.example and shop.example are different origins. Any
other site that frames it gets a page with nothing to click.
Your own headers.
- Your Content-Security-Policy must allow
script-src https://checkout.inversepay.app, and for the overlayframe-src https://checkout.inversepay.app. - For the popup, don't send
Cross-Origin-Opener-Policy: same-origin: it cuts the popup off from your page, so nothing can be reported back. Usesame-origin-allow-popups.
The rule does not change. The callbacks are a signal for your interface, never proof of payment: anything that runs script on your page can fake them, and a customer can close the window just before the payment lands. Confirm the session from your server, as in Step 4, before you fulfil.
Errors
When you create, read or expire a session
| Status | code | What happened |
|---|---|---|
400 | INVALID_CHECKOUT_SESSION | The amount is not in whole units, your business does not hold the currency, success_url or cancel_url is not an http(s) URL with a host, methods is empty or names an unknown method, or an embed_origins entry is not an exact https origin (more than 5, a path, a wildcard, or http other than your own machine on a test session; then field is embed_origins). The message says which. |
400 | INVALID_CURSOR | before on the listing is not the id of a session it gave you. |
403 | INSUFFICIENT_AUTHORITY | The key lacks payments:write (to create or expire) or payments:read (to read), or your business is suspended. |
404 | CHECKOUT_SESSION_NOT_FOUND | No session with this id for your business in this mode. |
409 | REFERENCE_IN_USE | The reference already belongs to a session set up differently. session_id names it and fields lists what differs. |
409 | REFERENCE_SESSION_CLOSED | The reference's session expired or failed. Use a new reference. session_id and status name it. |
409 | CHECKOUT_IN_PROGRESS | Expiring a session whose payment has started. It ends by itself; wait for the webhook. |
409 | CHECKOUT_SESSION_CLOSED | Expiring a session that is already complete or failed. status says which. |
422 | VALIDATION_FAILED | A field is missing or out of range: amount_minor of 0, a currency that is not three letters, an empty reference, or expires_in_minutes outside 15–1,440. errors lists each field. |
All codes are on Errors.
What the page may tell your customer
The page calls its own endpoints and handles these itself. You never call them, but your support team may hear about them:
code | What the customer sees it for |
|---|---|
INVALID_PAYMENT | Their number or network was refused. They can correct it and try again on the same session. |
CHECKOUT_IN_PROGRESS | A payment for this session is already running, in another tab say. |
CHECKOUT_NOT_PAYABLE | The session is already paid, failed or expired. |
PAYMENT_NOT_ACCEPTED | A collection limit on your account. The customer is not told which. |
COLLECTIONS_PAUSED | We have paused collections for now. |
RATE_LIMIT_EXCEEDED | Too many attempts on one session. |
Go-live checklist
- Sessions are created on your server, with a
sk_live_key that never reaches a browser or an app. - Your live key can reach the API: if your business has an IP allowlist, your server's address is on it.
- Your business holds the live currency, RWF or UGX.
- You fulfil only on
complete, read from your server or a verified webhook, and you check the reference, amount and currency against the order. - Your success page copes with a session that is still
open. - A live webhook endpoint is registered, verifies signatures, handles
duplicates by session id, and lists the
checkout.session.*events if it filters byevent_types. - You release the order on
checkout.session.expired, and do not cancel it oncheckout.session.failedalone. - If you use checkout.js: a live publishable key, your site's origin in
embed_origins(or onsuccess_url/cancel_url), and your CSP and COOP allow the script, the frame and the popup. - Each new attempt at an order uses a new
reference; a retry of the same create call reuses it. - You have run a test session to
complete, tofailedand to "never finishes", and watched each webhook arrive.