Reference
End-to-end examples
Copy-paste flows that run against the sandbox with your own credentials. Each uses raw HTTP only; replace the placeholder host with the one you receive at onboarding.
Authorize, capture, refund
Gets a token, authorizes 150.00 SAR, captures 100.00, refunds 25.00 and prints the final state. Expected statuses: Authorized → PartiallyCaptured → PartiallyRefunded.
#!/usr/bin/env bash
# Requires curl, jq and uuidgen. Sandbox only.
set -euo pipefail
BASE_URL="https://api.sandbox.meem-dev.example"
# 1. Token (client credentials)
TOKEN=$(curl -sf -X POST "$BASE_URL/api/v1/auth/token" \
--data-urlencode "grant_type=client_credentials" \
--data-urlencode "client_id=$MEEM_CLIENT_ID" \
--data-urlencode "client_secret=$MEEM_CLIENT_SECRET" | jq -r .access_token)
# 2. Authorize 150.00 SAR with the sandbox "approve" card
PAYMENT_ID=$(curl -s -X POST "$BASE_URL/api/v1/payments" \
-H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{"amount":150,"currency":"SAR","cardToken":"4000001111112223","cvv":"123"}' | jq -r .paymentId)
echo "authorized: $PAYMENT_ID"
# 3. Capture 100.00 (partial capture)
curl -s -X POST "$BASE_URL/api/v1/payments/$PAYMENT_ID/capture" \
-H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{"amount":100,"currency":"SAR"}' | jq -r .status # PartiallyCaptured
# 4. Refund 25.00 (partial refund)
curl -s -X POST "$BASE_URL/api/v1/payments/$PAYMENT_ID/refund" \
-H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{"amount":25,"currency":"SAR"}' | jq -r .status # PartiallyRefunded
# 5. Inspect
curl -s "$BASE_URL/api/v1/payments/$PAYMENT_ID" -H "Authorization: Bearer $TOKEN" \
| jq '{status, capturedAmount, refundedAmount, attempts: [.attempts[] | {gatewayName, normalizedOutcome}]}'Hosted checkout with server-side confirmation
/pay creates a session and redirects with 303; /return re-reads the payment before marking the order paid. getAccessToken is the cached token helper from Authentication.
// A minimal Node server: create a session, redirect, confirm on return.
import { createServer } from "node:http";
const BASE_URL = "https://api.sandbox.meem-dev.example";
declare function getAccessToken(): Promise<string>; // see Authentication
declare function markOrderPaid(orderRef: string, paymentId: string): Promise<void>;
const meem = async (path: string, init: RequestInit = {}) => {
const res = await fetch(`${BASE_URL}${path}`, {
...init,
headers: { Authorization: `Bearer ${await getAccessToken()}`, "Content-Type": "application/json", ...init.headers },
});
return { status: res.status, body: await res.json() };
};
createServer(async (req, res) => {
const url = new URL(req.url ?? "/", "https://shop.example.com");
if (url.pathname === "/pay") {
const { body } = await meem("/api/v1/checkout/sessions", {
method: "POST",
body: JSON.stringify({
amount: 249.5,
currency: "SAR",
orderRef: "ORDER-2001",
successUrl: "https://shop.example.com/return",
failureUrl: "https://shop.example.com/return",
locale: "ar",
}),
});
res.writeHead(303, { Location: body.checkoutUrl }).end();
return;
}
if (url.pathname === "/return") {
// Never trust the query string: confirm the payment server-side.
const paymentId = url.searchParams.get("paymentId") ?? "";
const { status, body: payment } = await meem(`/api/v1/payments/${encodeURIComponent(paymentId)}`);
const paid = status === 200 && ["Authorized", "Captured"].includes(payment.status) && payment.amount === 249.5;
if (paid) await markOrderPaid("ORDER-2001", payment.paymentId);
res.writeHead(200, { "Content-Type": "text/plain" }).end(paid ? "Thank you!" : "Payment not completed.");
return;
}
res.writeHead(404).end();
}).listen(3000);Sandbox failover drill
Runs five test cards and prints each payment's attempts. With a two-gateway workflow you should see: approve on the first attempt; technical failure on Mock 1 then success on Mock 2; soft decline on Mock 1 then approval on Mock 2; INSUFFICIENT_FUNDS with no failover; STOLEN_CARD with no failover.
# Prerequisites: Mock 1 and Mock 2 accounts active, and a published workflow that
# tries Mock 1 then Mock 2 with failover enabled for technical failures and soft declines.
for CARD in 4000001111112223 4000031111111115 4000101111111116 4000011111111117 4000061111111112; do
RESULT=$(curl -s -X POST "$BASE_URL/api/v1/payments" \
-H "Authorization: Bearer $MEEM_ACCESS_TOKEN" -H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d "{\"amount\":50,\"currency\":\"SAR\",\"cardToken\":\"$CARD\"}")
ID=$(echo "$RESULT" | jq -r .paymentId)
echo "$CARD -> $(echo "$RESULT" | jq -r '.status + " " + (.code // "")')"
curl -s "$BASE_URL/api/v1/payments/$ID" -H "Authorization: Bearer $MEEM_ACCESS_TOKEN" \
| jq -c '[.attempts[] | {gatewayName, normalizedOutcome, nextAction}]'
doneMore samples
- Token requests in every language: Authentication.
- Webhook signature verification in five languages: Webhooks.
- Every operation and field: API reference.
Documentation reflects the platform as verified on 3 December 2026. Placeholder hosts and credentials are used throughout; your real sandbox host and keys are provided at onboarding.