End-to-End Payment Flow
This guide describes a complete Charge SDK payment integration from checkout to settlement: what your frontend and backend are each responsible for, when to call the Charge API, when to mount the Charge SDK, and how to confirm the result of a payment.
Integration at a glance
| Component | Owned by | Responsibilities |
|---|---|---|
| Checkout frontend | Merchant | Requests checkout from your backend, mounts the Charge SDK, handles the post-payment redirect |
| Backend | Merchant | Authenticates with the Charge API, creates orders, receives webhooks, retrieves and stores payment results |
| Charge SDK | DataMesh | Renders the payment UI, collects payment details (keeping you outside PCI scope), processes the payment |
| Charge API | DataMesh | Order creation, charge processing, charge status retrieval |
| Webhooks | DataMesh | Push payment and settlement results to your backend |
| Settlement API | DataMesh | Settlement reporting for finance/ERP reconciliation (optional) |
Before you start
During onboarding, DataMesh provides the credentials your integration uses:
| Credential | Used by | Purpose |
|---|---|---|
jwt_public_key | Backend | Authenticates with the Charge API. Store securely; never expose in client-side code. |
jwt_secret | Backend | Authenticates with the Charge API. Store securely; never expose in client-side code. |
merchant_id | Frontend | Your unique merchant identifier, used when mounting the Charge SDK. This is the same value as your service_id. |
config_id | Frontend | Identifies the payment configuration (allowed origins, enabled payment methods, redirect URLs) used to construct the Charge SDK. Environment-specific — use the correct config_id for staging vs production. |
public_key | Frontend | Authenticates the Charge SDK mount. |
You must also provide DataMesh with:
- A redirect URL for your checkout result page — either separate success and failure URLs, or a single result URL. Must be HTTPS in production. Configured per
config_idin the Merchant Portal. - A webhook endpoint on your backend — must be HTTPS in production and reachable from the internet. Configured in the Merchant Portal.
See Authentication for how to construct the Charge API JWT.
Payment flow
Step by step
- Customer reaches your checkout. Your frontend asks your backend to create a checkout session.
- Backend authenticates with the Charge API. Create a JWT from your
jwt_public_keyandjwt_secret— see Authentication. - Backend creates the order with
POST /order_token. Setyour_order_reference(string, max 32 characters) to your own order ID — it appears as the searchable Merchant Reference field in the Merchant Dashboard. If your finance systems reconcile through the Settlement API, also add the same value as amerchant_order_refkey/value pair inyour_order_details; these key/value pairs are returned in the Settlement API transactionnotes. - Backend returns the
order_idfrom the response to your frontend. - Frontend mounts the Charge SDK using the dynamic
order_idplus the staticmerchant_id,config_id, andpublic_key. The payment UI renders inside the container element you nominate, showing the payment methods enabled for your merchant configuration. - The customer pays. The Charge SDK collects payment details and processes the payment with DataMesh and the payment service provider. Your systems never touch the payment details.
- The Charge SDK redirects the customer to your configured result URL with query parameters
status(completedon success, otherwise the charge status),charge_id,order_id, andconfig_id. Treat this redirect as display-only — use it to show the customer a result page, not to update your records (the customer can close the window, lose connectivity, or never return). - Your webhook receives the result. DataMesh POSTs a charge webhook to your backend as the charge changes status. Delivery is attempted up to 7 times at increasing intervals until your endpoint responds
200 OK— so respond200promptly, and handle redelivery idempotently. - Backend confirms the charge. On a
completedwebhook, extract thecharge_idand callGET /charge/{charge_id}. The payment is successful whenstatus.statusiscompleted. Do not treat any other status — or the redirect alone — as confirmation of payment.
Confirm payments from the webhook plus GET /charge/{charge_id} on your backend, never from frontend events or the redirect. Frontend signals are best-effort: they fail when the customer closes the payment window, loses network connectivity, or abandons the flow mid-payment.
Settlement (optional)
If your finance or ERP systems reconcile settlements, two further integrations are available:
- A settlement webhook fires as a settlement changes status (for example
settled). The payload contains thesettlement_id. - Query the Settlement API with that
settlement_idfor the settlement header (gross amount, fees, tax,accountingToken) and the individual transactions it contains. Each transaction carries yourmerchant_order_ref/merchant_customer_refvalues in itsnotes, linking settlements back to your orders.
See the Settlement API reference for endpoints and payloads.
Next steps
- Charge SDK — mounting, configuration, and events
- Charge API — order and charge endpoints
- Webhooks — payload reference and handling guidance
- Settlement API — settlement reporting