Developers

Integrate PayX in an afternoon

PayX is a hosted payment gateway: your server creates a payment, we hand back a checkout link, and your customer pays on a page we host. Card and mobile money are supported. Merchant developers can create payments, check payment status, and read account balances. Webhooks report payment state changes; verify important outcomes with PayX before fulfilling orders.

Base URL

https://payx.benepharx.com

Auth

Authorization: Bearer

Format

JSON over HTTPS

These authenticated API calls belong on your server, not in browser JavaScript. Never expose a PayX API key. The customer's browser should only be redirected to the returned hosted checkout_url.

Refunds and payouts are managed from the authenticated merchant portal. They are not endpoints for third-party merchant integrations and are intentionally excluded from this guide.

Quickstart

  1. 1

    Grab a test API key from the settings page on the API keys tab. Test keys never move real money.

  2. 2

    Create a payment from your server. You'll get back a checkout_url.

  3. 3

    Redirect your customer to that URL. They pay on a page we host, then land back on your return_url.

  4. 4

    Listen for the payment.succeeded webhook to fulfill the order — that's the source of truth, not the redirect.

curl -X POST https://payx.benepharx.com/api/v1/payments \
  -H "Authorization: Bearer sk_test_xxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "amount": 250.00,
    "currency": "GHS",
    "payment_method": "MOMO",
    "return_url": "https://yourapp.com/orders/8842/thanks",
    "payer_phone": "0551234567"
  }'
const res = await fetch("https://payx.benepharx.com/api/v1/payments", {
  method: "POST",
  headers: {
    "Authorization": "Bearer sk_test_xxxxxxxxxxxx",
    "Content-Type": "application/json",
    "Idempotency-Key": crypto.randomUUID(),
  },
  body: JSON.stringify({
    amount: 250.00,
    currency: "GHS",
    payment_method: "MOMO",
    return_url: "https://yourapp.com/orders/8842/thanks",
    payer_phone: "0551234567",
  }),
});

const payment = await res.json();
// payment.checkout_url -> redirect your customer here
$ch = curl_init('https://payx.benepharx.com/api/v1/payments');
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer sk_test_xxxxxxxxxxxx',
        'Content-Type: application/json',
        'Idempotency-Key: ' . bin2hex(random_bytes(16)),
    ],
    CURLOPT_POSTFIELDS => json_encode([
        'amount' => 250.00,
        'currency' => 'GHS',
        'payment_method' => 'MOMO',
        'return_url' => 'https://yourapp.com/orders/8842/thanks',
        'payer_phone' => '0551234567',
    ]),
]);

$payment = json_decode(curl_exec($ch), true);
// $payment['checkout_url'] -> redirect your customer here

Response:

{
  "payment_id": "b3f1c2a4-9e21-4a3e-8b2d-1e0d4f9c7a11",
  "checkout_url": "https://payx.benepharx.com/checkout/b3f1c2a4-9e21-4a3e-8b2d-1e0d4f9c7a11",
  "status": "PENDING",
  "is_test_payment": true
}

Authentication

Merchant REST API calls are authenticated with a bearer API key in the Authorization header. Each merchant account has two keys — a test key and a live key — issued separately from your settings page. Which one you use decides everything: requests made with a test key are always flagged is_test_payment: true and skip real balance movement, with no override field to change that. Hosted checkout routes are browser-facing and use the checkout/payment ID; do not put your API key in a browser request.

Authorization: Bearer sk_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxx

Keep live keys server-side only. A key pasted into mobile or frontend code is a key anyone can read.

Making requests

Send and expect application/json. For payment creation, include an Idempotency-Key UUID generated once per user action. Reuse the same key and exact request when retrying after a timeout so a network retry does not create another operation. A new payment action must use a new key. The header is optional in the published schema but recommended for safe retries.

REST request/response amount values are in major units — 250.00 means GHS 250.00. Webhook data.amount uses minor units (pesewas/cents).

POST /api/v1/payments

Creates a payment and returns a hosted checkout link. Rate limited to 10 requests/minute per merchant.

Headers

HeaderRequired
AuthorizationYes
Idempotency-KeyRecommended; reuse the same value for retries
Content-TypeYes — application/json

Body

FieldTypeDescription
amountdecimalRequired. Major currency units, e.g. 250.00.
currencystringRequired, e.g. GHS.
payment_methodstringOptional. CARD or MOMO locks the method; omit it or use ANY to let the customer choose at checkout.
return_urlstringOptional customer return URL after checkout. Treat the redirect as informational, not proof of payment.
payer_namestringOptional customer name; displayed on checkout when supplied.
payer_emailstringOptional customer email.
payer_phonestringOptional MoMo number; pre-fills the checkout phone field.

Example request

curl -X POST https://payx.benepharx.com/api/v1/payments \
  -H "Authorization: ******" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "amount": 250.00,
    "currency": "GHS",
    "payment_method": "MOMO",
    "return_url": "https://yourapp.com/orders/8842/thanks",
    "payer_phone": "0551234567"
  }'

Response:

{
  "payment_id": "b3f1c2a4-9e21-4a3e-8b2d-1e0d4f9c7a11",
  "checkout_url": "https://payx.benepharx.com/checkout/b3f1c2a4-9e21-4a3e-8b2d-1e0d4f9c7a11",
  "status": "PENDING",
  "is_test_payment": true
}
GET /api/v1/payments/{payment_id}

Fetches the current state of a payment. Use this to reconcile or as a fallback if a webhook never arrives. Returns a 403 if the payment belongs to a different merchant than the authenticated account.

Example request

curl -X GET https://payx.benepharx.com/api/v1/payments/b3f1c2a4-9e21-4a3e-8b2d-1e0d4f9c7a11 \
  -H "Authorization: ******"

Successful response

{
  "id": "b3f1c2a4-9e21-4a3e-8b2d-1e0d4f9c7a11",
  "status": "SUCCEEDED",
  "amount": 250.00,
  "currency": "GHS",
  "payment_method": "MOMO",
  "created_at": "2026-09-10T14:02:31.442Z"
}

Possible statuses

PENDING PROCESSING SUCCEEDED FAILED CHARGEBACKED
GET /api/v1/accounts/{account_id}/balance

Returns the current balance of one of your settlement accounts, computed live from the ledger. Use the settlement account_id issued for your merchant account; it is not a payment ID.

curl https://payx.benepharx.com/api/v1/accounts/<ACCOUNT_ID>/balance \
  -H "Authorization: Bearer <YOUR_API_KEY>"
{
  "account_id": "9a7c1e20-6b3d-4f1a-8c9e-2d5f8b1a0c33",
  "balance": 18420.50,
  "currency": "GHS"
}

Hosted checkout & redirects

The checkout_url from the create-payment response is a PayX-hosted page — send the customer's browser there with a normal redirect. It handles card entry or the MoMo prompt itself; you don't build any of that UI.

On success

Customer sees a confirmation page, then is auto-redirected to your return_url after ~3 seconds — with no query parameters appended.

On failure

Customer sees a decline page with a link back to return_url?error=payment_failed&payment_id={id}.

Treat the redirect as a hint, not proof of payment — the success page doesn't carry a payment ID or signature in its URL. A customer can close the tab before the redirect fires, or land on return_url without ever having paid. Confirm real status with a GET request or, better, the webhook.

Checkout endpoints

Use the hosted checkout URL returned by POST /api/v1/payments for the standard integration. The hosted page calls the submit and status routes below itself. Do not build your own card form unless you are prepared to handle the additional PCI obligations; never send raw card data through an untrusted frontend or log it.

GET /checkout/{payment_id}

Serves the hosted payment page. Redirect the customer's browser to the returned checkout_url; do not construct this URL from untrusted input.

POST /checkout/{payment_id}/submit

Submits checkout payment details. The hosted PayX page calls this endpoint. For MoMo, it returns PROCESSING while PayX completes the provider operation asynchronously.

Request body fields

payment_methodRequired: CARD or MOMO.
card_numberCard number for a card checkout.
expiry_month, expiry_year, cvvCard expiry and security code for a card checkout.
phone_number, networkCustomer MoMo phone and network for a MoMo checkout.
GET /checkout/{payment_id}/status

Returns the latest checkout/payment status. If it is still processing, PayX may query MojoPay for an updated status. Use this for checkout UI polling only; use authenticated payment status and webhooks as your server-side fulfillment signals.

GET /payment/{payment_id}/receipt.pdf

Serves a PDF receipt for the payment. Link to it or open it in a browser after verifying payment success.

PayX also serves browser result pages at GET /payment/success and GET /payment/failed. These are display/redirect pages, not server-side payment verification APIs.

Events & payload

Set your delivery URL from the Webhooks page in your dashboard. PayX POSTs an event envelope to it every time a payment's state changes — card and MoMo payments emit the exact same shape.

Event types

EventFired when
payment.processingA MoMo prompt was sent and is awaiting the customer's PIN.
payment.succeededFunds captured. Safe to fulfill the order.
payment.failedDeclined, timed out, or the customer cancelled.

Headers on every delivery

X-Webhook-SignatureHMAC-SHA256 of the raw body, as sha256=<hex>. See below.
X-Event-TypeSame value as the body's event_type field.
X-Event-IDUnique per delivery attempt — use it to de-duplicate.

Payload

{
  "event_type": "payment.succeeded",
  "event_id": "e5a2f9c1-...",
  "aggregate_id": "b3f1c2a4-9e21-4a3e-8b2d-1e0d4f9c7a11",
  "timestamp": "2026-09-10T14:02:41.108Z",
  "data": {
    "reference": "b3f1c2a4-9e21-4a3e-8b2d-1e0d4f9c7a11",
    "status": "success",
    "providerReference": "b3f1c2a4-9e21-4a3e-8b2d-1e0d4f9c7a11",
    "amount": 25000,
    "currency": "GHS",
    "transaction_id": "MTN-8827199201",
    "is_test": false,
    "error_code": null,
    "error_message": null,
    "timestamp": "2026-09-10T14:02:41.108Z",
    "merchant_id": "7c1a9e02-..."
  }
}

data.amount is in minor units (pesewas/cents) — 25000 above is GHS 250.00. This is the one place the API departs from major units.

Retries: on a 5xx or timeout, PayX retries with backoff, up to 3 attempts total. A 4xx is treated as permanent and isn't retried — return a 2xx as soon as you've durably recorded the event, then do slow work asynchronously. Failed deliveries can be retried manually from the dashboard.

Verifying signatures

Compute an HMAC-SHA256 of the exact raw request body using your webhook signing secret, then compare it to the X-Webhook-Signature header. Work from the raw bytes your framework received — don't re-serialize the parsed JSON first, since key order or spacing could differ from what was signed and the comparison would fail even for a legitimate request.

$rawBody = file_get_contents('php://input');
$header  = $_SERVER['HTTP_X_WEBHOOK_SIGNATURE'] ?? '';
$secret  = getenv('PAYX_WEBHOOK_SECRET');

$expected = 'sha256=' . hash_hmac('sha256', $rawBody, $secret);

if (!hash_equals($expected, $header)) {
    http_response_code(401);
    exit('Invalid signature');
}

$event = json_decode($rawBody, true);
// handle $event['event_type'] ...
http_response_code(200);
import crypto from "crypto";

app.post("/webhooks/payx", express.raw({ type: "*/*" }), (req, res) => {
  const signature = req.headers["x-webhook-signature"] || "";
  const secret = process.env.PAYX_WEBHOOK_SECRET;

  const expected =
    "sha256=" +
    crypto.createHmac("sha256", secret).update(req.body).digest("hex");

  const ok =
    expected.length === signature.length &&
    crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(signature));

  if (!ok) return res.status(401).send("Invalid signature");

  const event = JSON.parse(req.body.toString("utf8"));
  // handle event.event_type ...
  res.sendStatus(200);
});

Note the Node example reads the body as a raw Buffer (not JSON-parsed by middleware first) — that's what preserves the exact bytes the signature was computed over.

Test mode

Authenticate with your sk_test_... key and every payment you create is automatically a test payment — there's no flag to set. Test payments skip real balance checks on the card and MoMo engines but otherwise run the full state machine, including real webhook deliveries with is_test: true in the payload. That makes test mode safe for full end-to-end integration testing, including your webhook handler, without moving any money.

Errors & rate limits

Errors are a non-2xx status with a JSON body shaped {"detail": "..."}.

StatusMeaning
400Bad request or malformed input; check the error detail.
401Missing or invalid API key.
403Valid key, but it doesn't own this resource.
404Resource doesn't exist.
422Validation or business-rule rejection, such as unsupported currency or invalid payment details. Check detail.
429Rate limit exceeded — back off and retry.
500Something broke on our side. Safe to retry with the same idempotency key.

Rate limits

EndpointLimit
POST /api/v1/payments10 / minute per merchant