Browse documentation

APIs

Checkout API

Take a one-off payment. Create a checkout session for an amount, send the customer to the hosted page, and read the result.

View as Markdown

The Checkout API is a small REST surface for taking a single payment. You create a checkout session for an amount, Payer returns a hosted payment page, the customer pays there, and you read the session's status — or let a webhook tell you — to know when it's done.

All endpoints live under /checkout and authenticate with a publishable or secret key holding the checkout:write scope.

Create a session

POST /checkout/sessions
POST /checkout/sessions

Creates a checkout session and returns a hosted payment link. Send an Idempotency-Key so a retried create replays the first response instead of making a second session. Requires the checkout:write scope.

Body parameters

FieldTypeRequiredDescription
amountintegerYesAmount in laari (100 laari = 1 MVR). Between 100 and 500000.
titlestringYesShown on the checkout page. Max 255 characters.
referencestringYesYour own identifier. Must be unique for your account.
descriptionstringNoExtra line under the title. Max 255 characters.
return_urlstring (url)NoWhere the payer is sent after the session reaches a terminal state.
Request
curl https://api.payer.app/checkout/sessions \
  -H "Authorization: Bearer sk_test_..." \
  -H "Idempotency-Key: order_10482" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 2490,
    "title": "Order #10482",
    "reference": "order_10482",
    "return_url": "https://example.com/thanks"
  }'
200 OK
{
  "id": "9b1c8f2e-3d4a-4f11-a0c2-1e2d3c4b5a69",
  "reference": "order_10482",
  "url": "https://api.payer.app/9b1c8f2e-3d4a-4f11-a0c2-1e2d3c4b5a69"
}

Redirect the customer to url. A session expires 24 hours after it's created if it hasn't been paid.

Retrieve a session

GET /checkout/sessions/{id}
GET /checkout/sessions/{id}

Returns the current state of a session. The {id} may be the session UUID or the reference you set when creating it.

Request
curl https://api.payer.app/checkout/sessions/9b1c8f2e-3d4a-4f11-a0c2-1e2d3c4b5a69 \
  -H "Authorization: Bearer sk_test_..."
200 OK
{
  "id": "9b1c8f2e-3d4a-4f11-a0c2-1e2d3c4b5a69",
  "reference": "order_10482",
  "status": "COMPLETED"
}

status is one of:

StatusMeaning
INITIATEDCreated, not yet paid.
COMPLETEDPaid and settled.
CANCELLEDCancelled before payment.
EXPIREDThe 24-hour window elapsed unpaid.

Tip

Don't poll in a tight loop. Register a webhook for checkout.session.completed and read the session once when it arrives.

Cancel a session

POST /checkout/sessions/{id}/cancel
POST /checkout/sessions/{id}/cancel

Cancels a session that hasn't been paid. Requires the checkout:write scope. Send an Idempotency-Key so a retried cancel is safe.

Request
curl -X POST https://api.payer.app/checkout/sessions/9b1c8f2e-.../cancel \
  -H "Authorization: Bearer sk_test_..." \
  -H "Idempotency-Key: cancel_order_10482"
200 OK
{ "message": "Checkout session cancelled" }

A session that is already cancelled, or already in another terminal state, returns 400:

400 Bad Request
{ "message": "Checkout session already cancelled" }

Read a session over GraphQL

The session is also readable at POST /graphql, and this query is public — the UUID is the capability, so no key is needed. This is the same data the hosted checkout page loads.

Query
query CheckoutSession($id: UUID!) {
  checkoutSession(id: $id) {
    id
    merchantName
    reference
    title
    description
    amount
    currency
    status
    expiresAt
    returnUrl
  }
}

Note

Over GraphQL, amount is in major MVR units (24.90), not laari — this query drives the customer-facing page. returnUrl is only exposed once the session reaches a terminal state.

Try it live

The panel below runs real requests from your browser straight to api.payer.app. Paste an sk_test_ key, edit the inputs, and send. Nothing is proxied through this site, and the key stays in this browser tab.

Modetest

Kept in this tab only. Sent straight to api.payer.app.

POST/checkout/sessionsCreate

Add an API key in the bar above to run this request.

GET/checkout/sessions/{id}Retrieve

Add an API key in the bar above to run this request.

POST/checkout/sessions/{id}/cancelCancel

Add an API key in the bar above to run this request.

POST/graphqlQuery · public, no key