Appearance
Card element routes
The four routes the card element (mookhpay.js) calls from the payer's browser to take a card payment for a direct charge. They open the card attempt, run 3-D Secure, charge the card and refresh the card form.
mookhpay.js calls these, not you
Use the card element. It handles the CyberSource fields, the transient token, device data collection, the bank's challenge and the return page's message, none of which a hand-written client can do safely. These routes are documented so you can read network traces and understand refusals. A server-to-server call is refused anyway: there is no Origin header, and a missing origin is 403 and code 2776.
They take no API key and no session. What stands in for one is the charge's client_secret and an allowed Origin.
Endpoint
POST /v1/payments/public/charges/{id}/card
POST /v1/payments/public/charges/{id}/card/payer-auth
POST /v1/payments/public/charges/{id}/card/charge
POST /v1/payments/public/charges/{id}/card/refresh| Host | The payments host for the charge's country. ch_ke_… is Kenya, ch_ug_… is Uganda. See Environments |
| Auth | client_secret in the JSON body, from the charge's create answer. No Authorization header |
| Origin | The browser's Origin header must be on the charge owner's allowed list for the charge's mode. For a charge made on_behalf_of a seller, the platform's list |
| Switched on by | DIRECT_CHARGES_ENABLED and DIRECT_CHARGE_CARDS_ENABLED. Where either is off, the routes do not exist and answer 404 with no code |
Before these checks, the body and headers are validated (400 1701, including a missing Idempotency-Key where it is required) and the per-address rate limit is counted. Then every route runs the same checks, in this order:
- The charge and the secret. An unknown charge, a malformed charge id, a wrong or missing
client_secret, and a secret past the charge'sexpires_atall answer401and code3006, with the same body. - The origin. A missing
Origin, the literalnull, or an origin not on the list is403and code2776. Nothing is created and no other service is asked before this passes. ThenAccess-Control-Allow-Originis set to that one origin, withVary: Origin. - The charge is pending. A charge that has succeeded, failed, expired or been cancelled is
409and code3007.
client_secret is marked optional in the body schemas so that a missing one reaches check 1 and gets 3006, not a validation 400. It is required.
CORS
The preflight (OPTIONS) for any path under /v1/payments/public/charges/ is answered for any origin, allowing POST with Content-Type and Idempotency-Key, cached for 600 seconds, with no credentials. A real request gets Access-Control-Allow-Origin only after its origin has passed check 2. The element sends requests with credentials: "omit".
Open the card attempt
POST /v1/payments/public/charges/{id}/cardOpens the charge's card attempt and issues a CyberSource Microform capture context bound to the page's origin. Nothing is charged. The element calls it on mount.
An attempt still waiting for its card, with nothing charged, is cancelled and replaced. One with a payment in flight is 409 and code 2786. The Idempotency-Key is namespaced to the charge, so the same element asking again with the same key gets the same attempt with a fresh capture context.
Headers
| Header | Required | Value |
|---|---|---|
Content-Type | Yes | application/json |
Origin | Yes | Set by the browser. Must be on the allowed list |
Idempotency-Key | Yes | 1 to 128 characters. The element sends one per element instance |
Parameters
Path:
| Name | Type | Required | Constraints |
|---|---|---|---|
id | string | Yes | The charge id, ch_<country>_<24 hex> |
Body (unknown fields are refused):
| Name | Type | Required | Constraints |
|---|---|---|---|
client_secret | string | Yes | 1 to 256 characters. The charge's client_secret |
Response
202 Accepted for a new attempt, 200 OK for a replay:
json
{
"ok": true,
"description": "Card payment initiated",
"data": {
"charge": "ch_ke_5b0e2d9a7c41f3e86d2a90b1",
"intent_id": "pi_3c9e1a4b7d20f68e5a1c9b04",
"status": "created",
"amount": "150000",
"fee": "2500",
"total": "152500",
"currency": "KES",
"rail": "card-uc",
"form": "microform",
"capture_context": "eyJraWQiOi…",
"client_library": "https://flex.cybersource.com/microform/bundle/v2.0/flex-microform.min.js",
"client_library_integrity": "sha256-…",
"context_expires_at": "2026-11-20T10:16:00.000Z",
"order_number": "pi_3c9e1a4b7d20f68e5a1c9b04",
"payer_auth": true
}
}Response fields
| Field | Type | Meaning |
|---|---|---|
charge | string | The charge id |
intent_id | string | The card attempt's payment intent |
status | string | The intent's status |
amount | string | What the payee receives, minor units |
fee | string | The card fee the payer adds, minor units |
total | string | What the card is charged, minor units |
currency | string | The charge's currency |
rail | string | Always card-uc |
form | string | Always microform |
capture_context | string | The Microform capture context (a JWT), bound to the matched origin |
client_library, client_library_integrity | string | The Microform script and its integrity hash, from the capture context |
context_expires_at | string | When the capture context stops minting tokens. About 15 minutes |
fingerprint | object | { org_id, session_id } for device fingerprinting. Present only where MOOKHPay has it configured |
order_number | string | What the 3-D Secure return page names. The element matches the return message against it |
payer_auth | boolean | Whether the payment runs 3-D Secure |
The answer carries no callback token and no callback URL.
Errors
| HTTP | Code | Name | When | What to do |
|---|---|---|---|---|
400 | 1701 | INVALID_REQUEST_DATA | The body or headers break the schema, such as a missing Idempotency-Key | Fix the request |
401 | 3006 | CHARGE_CLIENT_SECRET_INVALID | Unknown charge, wrong, missing or expired secret | Read the charge on your server |
403 | 2776 | CARD_ORIGIN_NOT_ALLOWED | The origin is missing, null or not on the list | Add the origin to the allowed list |
403 | 2775 | CARD_SANDBOX_CURRENCY_BLOCKED | Card payments for this currency are not live yet | Offer another method |
409 | 3007 | CHARGE_NOT_PENDING | The charge has ended | Read the charge |
409 | 2786 | CHECKOUT_IN_PROGRESS | A card payment for this charge is already in flight | Wait for the outcome |
404 | 2783 | CHECKOUT_NOT_FOUND | The checkout behind the charge is gone, or its payee can no longer be paid | Read the charge on your server |
409 | 2785 | CHECKOUT_PAID | The checkout behind the charge is already paid | Read the charge |
409 | 2784 | CHECKOUT_EXPIRED | The checkout behind the charge has expired | Read the charge |
409 | 2709 | WALLET_NOT_PROVISIONED | The payee's wallet is not set up yet | Try again in a moment |
409 | 2707 | INTENT_FINALIZED | The attempt opened without a Microform session | Try again |
422 | 2771 | CARD_CURRENCY_NOT_SUPPORTED | Cards do not take this currency | Offer another method |
429 | 1804 | RATE_LIMIT_EXCEEDED | See the rate limit below | Wait Retry-After seconds |
502 | 2774 | CARD_CAPTURE_CONTEXT_FAILED | CyberSource did not issue a capture context | Try again |
503 | 2752 | LEDGER_UNAVAILABLE | The ledger did not answer | Try again |
Start 3-D Secure
POST /v1/payments/public/charges/{id}/card/payer-authCalled only when the attempt answered payer_auth: true, with the transient token the element is about to charge. Sets up 3-D Secure device data collection. Nothing is charged or claimed.
Headers
| Header | Required | Value |
|---|---|---|
Content-Type | Yes | application/json |
Origin | Yes | Set by the browser |
Idempotency-Key | No | 1 to 128 characters. Not used |
Parameters
Path: id, as above.
Body (unknown fields are refused):
| Name | Type | Required | Constraints |
|---|---|---|---|
client_secret | string | Yes | 1 to 256 characters |
transient_token | string | Yes | 1 to 8192 characters. The token CyberSource's fields produced |
Response
200 OK, one of:
json
{ "ok": true, "description": "Pay without 3-D Secure", "data": { "payer_auth": "off" } }json
{
"ok": true,
"description": "…",
"data": {
"payer_auth": "collect",
"device_data_collection_url": "https://centinelapi.cardinalcommerce.com/…",
"access_token": "eyJhbGciOi…",
"reference_id": "…"
}
}Response fields
| Field | Type | Meaning |
|---|---|---|
payer_auth | string | off: charge without 3-D Secure. collect: collect device data first |
device_data_collection_url | string | Where the hidden device data form posts. With collect only |
access_token | string | The JWT the device data form carries. With collect only |
reference_id | string | The 3-D Secure session's reference. With collect only |
Errors
The three checks above (3006, 2776, 3007), and:
| HTTP | Code | Name | When |
|---|---|---|---|
400 | 1701 | INVALID_REQUEST_DATA | The body breaks the schema |
403 | 2772 | CARD_TOKEN_INVALID | The token is from another card form |
409 | 2772 | CARD_TOKEN_INVALID | No card attempt is open for this charge |
409 | 2778 | CARD_CONTEXT_EXPIRED | The transient token has expired |
409 | 2707 | INTENT_FINALIZED | The attempt has ended |
409 | 2777 | CARD_PAYMENT_IN_VERIFICATION | A charge holds the attempt |
403 | 2775 | CARD_SANDBOX_CURRENCY_BLOCKED | Card payments for this currency are not live yet |
429 | 1804 | RATE_LIMIT_EXCEEDED | See the rate limit below |
Charge the card
POST /v1/payments/public/charges/{id}/card/chargeCharges the transient token. On a challenged payment it is called a second time with challenge_completed: true, which is the only call that authorises it, and only once the bank's return page has fired for this order.
The attempt is claimed before CyberSource is asked, so of two calls at once only one charges and the other is 409 and code 2777. The Idempotency-Key is required, but it is not what stops a second charge.
Headers
| Header | Required | Value |
|---|---|---|
Content-Type | Yes | application/json |
Origin | Yes | Set by the browser |
Idempotency-Key | Yes | 1 to 128 characters. The element sends a new one on every attempt |
Parameters
Path: id, as above.
Body (unknown fields are refused):
| Name | Type | Required | Constraints |
|---|---|---|---|
client_secret | string | Yes | 1 to 256 characters |
transient_token | string | Yes | 1 to 8192 characters. Sent on both calls of a challenged payment |
cardholder_name | string | No | Up to 100 characters |
browser | object | No | { color_depth, java_enabled, language, screen_height, screen_width, time_difference } for 3-D Secure. color_depth 0 to 64, language up to 16 characters, screen_height and screen_width 0 to 100000, time_difference −1440 to 1440 minutes. No other keys |
challenge_window | string | No | 01 to 05: the size the bank's page may use |
challenge_completed | boolean | No | true on the second call after a challenge |
Response
200 OK, the card was approved:
json
{
"ok": true,
"description": "Payment completed",
"data": {
"charge": "ch_ke_5b0e2d9a7c41f3e86d2a90b1",
"intent_id": "pi_3c9e1a4b7d20f68e5a1c9b04",
"status": "completed",
"payment": "succeeded"
}
}202 Accepted, the bank wants to see the payer:
json
{
"ok": true,
"description": "Confirm the payment with your bank",
"data": {
"charge": "ch_ke_5b0e2d9a7c41f3e86d2a90b1",
"intent_id": "pi_3c9e1a4b7d20f68e5a1c9b04",
"status": "pending",
"payment": "challenge",
"challenge": {
"step_up_url": "https://centinelapi.cardinalcommerce.com/…",
"access_token": "eyJhbGciOi…",
"width": 390,
"height": 400
}
}
}202 Accepted with payment pending (being verified) or review (held for a risk review). The outcome follows by webhook.
402 Payment Required, the card was declined. The charge stays pending and another card may be tried:
json
{
"ok": false,
"description": "Your card was declined. Try a different card.",
"code": 2723,
"data": {
"charge": "ch_ke_5b0e2d9a7c41f3e86d2a90b1",
"failure": { "code": "declined", "message": "Your card was declined. Try a different card." }
}
}Response fields
| Field | Type | Meaning |
|---|---|---|
charge | string | The charge id |
intent_id | string | The card attempt |
status | string | The intent's status. completed once approved |
payment | string | succeeded, challenge, pending or review |
challenge | object | With challenge only: step_up_url, access_token, width, height of the bank's page |
failure | object | On 402 and on 502 2779: { code, message }. code is insufficient_funds, limit_exceeded, rail_unavailable or declined. message is safe to show the payer |
payment: "succeeded" is the card approval. The charge itself moves to succeeded when the payment is booked, the moment payment.succeeded is sent.
Errors
The three checks above (3006, 2776, 3007), and:
| HTTP | Code | Name | When |
|---|---|---|---|
402 | 2723 | COLLECTION_DECLINED | The card was declined. data.failure says why |
502 | 2779 | CARD_CHARGE_FAILED | CyberSource refused the request. Nothing was taken. data.failure.code is rail_unavailable |
409 | 2778 | CARD_CONTEXT_EXPIRED | The transient token has expired. The element refreshes the form |
409 | 2777 | CARD_PAYMENT_IN_VERIFICATION | Another charge call holds the attempt, or a payment is being verified |
409 | 2773 | CARD_VERIFICATION_FAILED | The charge could not be verified with CyberSource |
403 or 409 | 2772 | CARD_TOKEN_INVALID | The token is from another form, or no attempt is open |
409 | 2707 | INTENT_FINALIZED | The attempt has ended |
403 | 2775 | CARD_SANDBOX_CURRENCY_BLOCKED | Card payments for this currency are not live yet |
422 | 1701 | INVALID_REQUEST_DATA | The charge was refused for its data |
429 | 1804 | RATE_LIMIT_EXCEEDED | See the rate limit below |
Refresh the card form
POST /v1/payments/public/charges/{id}/card/refreshA new capture context for the same attempt, called when the old one nears the end of its 15 minutes.
Headers
| Header | Required | Value |
|---|---|---|
Content-Type | Yes | application/json |
Origin | Yes | Set by the browser |
Idempotency-Key | No | 1 to 128 characters |
Parameters
Path: id, as above. Body: client_secret (required, 1 to 256 characters), nothing else.
Response
200 OK: data is { charge, intent_id, form, capture_context, client_library, client_library_integrity, context_expires_at, fingerprint, order_number }, each as on Open the card attempt. fingerprint only where configured.
Errors
The three checks above (3006, 2776, 3007), and 409 2707 INTENT_FINALIZED, 403 or 409 2772 CARD_TOKEN_INVALID, 403 2775 CARD_SANDBOX_CURRENCY_BLOCKED, 502 2774 CARD_CAPTURE_CONTEXT_FAILED and 429 1804.
Example request
Only a browser on an allowed page can call these, so the samples are a browser fetch and a curl that shows the headers the browser sends. A server-side sample in Node, Python or PHP would be refused, or would be pretending to be a browser, so there is none.
js
const res = await fetch(
`https://payments-ke-staging.mookhpay.co/v1/payments/public/charges/${chargeId}/card`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
"Idempotency-Key": crypto.randomUUID(),
},
body: JSON.stringify({ client_secret: clientSecret }),
credentials: "omit",
mode: "cors",
},
);
const body = await res.json();sh
curl -X POST https://payments-ke-staging.mookhpay.co/v1/payments/public/charges/ch_ke_5b0e2d9a7c41f3e86d2a90b1/card \
-H "Origin: https://shop.example.com" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 6f1c2a9e-4b7d-4e20-9a31-0c5d8e7f1b23" \
-d '{ "client_secret": "ch_ke_5b0e2d9a7c41f3e86d2a90b1_secret_Xq3v9Tn0bS2kLw7yPz1aRc4dEf5gHi6jKl8mNo0pQrs" }'Rate limit
| Route | Buckets | 429 |
|---|---|---|
/card | 200 an hour per client IP (counted before the secret check, and shared with the card routes of MOOKHPay's own hosted checkout and payment link pages), and 10 an hour per charge | 1804 |
/card/payer-auth, /card/charge, /card/refresh | 30 a minute per client IP, one bucket across all three routes (counted before the secret check), and 60 an hour per charge for each route | 1804 |
A 429 carries Retry-After and data.retryAfter in seconds. The element reports it as try_again.