Skip to content

Create a Payment Intent

A Payment Intent represents the intent to collect a payment. It is the central resource of the Sangho payment cycle. Here is the complete flow in 3 steps.

Step 1 (Server): Create the Payment Intent

From your backend server, create a Payment Intent with the desired amount, currency, and payment methods. The Payment Intent ID will be used to confirm the payment.

Step 2 (Client): Redirect to the payment page

The @sanghosdk/js SDK is a server-side client (Node.js) — there is no embedded payment widget on the browser side. Simply return the url field of the Payment Intent to your frontend and redirect the client to this Sangho-hosted page, which handles displaying the form.

Step 3 (Server): Confirm via Webhook

Listen for the payment_intent.succeeded event to confirm the payment server-side. Never rely on the frontend alone to confirm a payment.

Attention

The Payment Intent contains sensitive data: never expose the full details client-side. Send only the ID to the frontend.

Step 1: Create (Server)

bash
curl -X POST https://api.sangho.ga/v1/payment-intents/ \
  -H "Authorization: Bearer sk_test_xxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 5000,
    "currency": "XAF",
    "payment_method_types": ["mobile_money", "bank_card"],
    "metadata": {"order_id": "CMD-001"}
  }'
# → { "id": "pi_xxx", "url": "https://checkout.sangho.ga/pay/pi_xxx", ... }

Step 2: Redirect (Frontend)

javascript
// The server returned { paymentIntentId, checkoutUrl } in step 1.
// Simply redirect the browser to the Sangho-hosted URL:
globalThis.location.href = checkoutUrl; // e.g. https://checkout.sangho.ga/pay/pi_xxx

PaymentIntent Response

Response200 OK
json
{
  "id": "pi_xxxxxxxxxxxx",
  "object": "PaymentIntent",
  "reference": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "amount": 5000,
  "currency": "XAF",
  "status": "requires_payment_method",
  "payment_method_types": ["mobile_money", "bank_card"],
  "customer": "cust_xxxx",
  "url": "https://checkout.sangho.ga/pay/pi_xxx",
  "metadata": {"order_id": "CMD-001"},
  "created_at": "2026-03-01T10:00:00Z",
  "updated_at": "2026-03-01T10:00:00Z"
}