Skip to content

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
HostThe payments host for the charge's country. ch_ke_… is Kenya, ch_ug_… is Uganda. See Environments
Authclient_secret in the JSON body, from the charge's create answer. No Authorization header
OriginThe 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 byDIRECT_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:

  1. The charge and the secret. An unknown charge, a malformed charge id, a wrong or missing client_secret, and a secret past the charge's expires_at all answer 401 and code 3006, with the same body.
  2. The origin. A missing Origin, the literal null, or an origin not on the list is 403 and code 2776. Nothing is created and no other service is asked before this passes. Then Access-Control-Allow-Origin is set to that one origin, with Vary: Origin.
  3. The charge is pending. A charge that has succeeded, failed, expired or been cancelled is 409 and code 3007.

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}/card

Opens 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 ​

HeaderRequiredValue
Content-TypeYesapplication/json
OriginYesSet by the browser. Must be on the allowed list
Idempotency-KeyYes1 to 128 characters. The element sends one per element instance

Parameters ​

Path:

NameTypeRequiredConstraints
idstringYesThe charge id, ch_<country>_<24 hex>

Body (unknown fields are refused):

NameTypeRequiredConstraints
client_secretstringYes1 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 ​

FieldTypeMeaning
chargestringThe charge id
intent_idstringThe card attempt's payment intent
statusstringThe intent's status
amountstringWhat the payee receives, minor units
feestringThe card fee the payer adds, minor units
totalstringWhat the card is charged, minor units
currencystringThe charge's currency
railstringAlways card-uc
formstringAlways microform
capture_contextstringThe Microform capture context (a JWT), bound to the matched origin
client_library, client_library_integritystringThe Microform script and its integrity hash, from the capture context
context_expires_atstringWhen the capture context stops minting tokens. About 15 minutes
fingerprintobject{ org_id, session_id } for device fingerprinting. Present only where MOOKHPay has it configured
order_numberstringWhat the 3-D Secure return page names. The element matches the return message against it
payer_authbooleanWhether the payment runs 3-D Secure

The answer carries no callback token and no callback URL.

Errors ​

HTTPCodeNameWhenWhat to do
4001701INVALID_REQUEST_DATAThe body or headers break the schema, such as a missing Idempotency-KeyFix the request
4013006CHARGE_CLIENT_SECRET_INVALIDUnknown charge, wrong, missing or expired secretRead the charge on your server
4032776CARD_ORIGIN_NOT_ALLOWEDThe origin is missing, null or not on the listAdd the origin to the allowed list
4032775CARD_SANDBOX_CURRENCY_BLOCKEDCard payments for this currency are not live yetOffer another method
4093007CHARGE_NOT_PENDINGThe charge has endedRead the charge
4092786CHECKOUT_IN_PROGRESSA card payment for this charge is already in flightWait for the outcome
4042783CHECKOUT_NOT_FOUNDThe checkout behind the charge is gone, or its payee can no longer be paidRead the charge on your server
4092785CHECKOUT_PAIDThe checkout behind the charge is already paidRead the charge
4092784CHECKOUT_EXPIREDThe checkout behind the charge has expiredRead the charge
4092709WALLET_NOT_PROVISIONEDThe payee's wallet is not set up yetTry again in a moment
4092707INTENT_FINALIZEDThe attempt opened without a Microform sessionTry again
4222771CARD_CURRENCY_NOT_SUPPORTEDCards do not take this currencyOffer another method
4291804RATE_LIMIT_EXCEEDEDSee the rate limit belowWait Retry-After seconds
5022774CARD_CAPTURE_CONTEXT_FAILEDCyberSource did not issue a capture contextTry again
5032752LEDGER_UNAVAILABLEThe ledger did not answerTry again

Start 3-D Secure ​

POST /v1/payments/public/charges/{id}/card/payer-auth

Called 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 ​

HeaderRequiredValue
Content-TypeYesapplication/json
OriginYesSet by the browser
Idempotency-KeyNo1 to 128 characters. Not used

Parameters ​

Path: id, as above.

Body (unknown fields are refused):

NameTypeRequiredConstraints
client_secretstringYes1 to 256 characters
transient_tokenstringYes1 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 ​

FieldTypeMeaning
payer_authstringoff: charge without 3-D Secure. collect: collect device data first
device_data_collection_urlstringWhere the hidden device data form posts. With collect only
access_tokenstringThe JWT the device data form carries. With collect only
reference_idstringThe 3-D Secure session's reference. With collect only

Errors ​

The three checks above (3006, 2776, 3007), and:

HTTPCodeNameWhen
4001701INVALID_REQUEST_DATAThe body breaks the schema
4032772CARD_TOKEN_INVALIDThe token is from another card form
4092772CARD_TOKEN_INVALIDNo card attempt is open for this charge
4092778CARD_CONTEXT_EXPIREDThe transient token has expired
4092707INTENT_FINALIZEDThe attempt has ended
4092777CARD_PAYMENT_IN_VERIFICATIONA charge holds the attempt
4032775CARD_SANDBOX_CURRENCY_BLOCKEDCard payments for this currency are not live yet
4291804RATE_LIMIT_EXCEEDEDSee the rate limit below

Charge the card ​

POST /v1/payments/public/charges/{id}/card/charge

Charges 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 ​

HeaderRequiredValue
Content-TypeYesapplication/json
OriginYesSet by the browser
Idempotency-KeyYes1 to 128 characters. The element sends a new one on every attempt

Parameters ​

Path: id, as above.

Body (unknown fields are refused):

NameTypeRequiredConstraints
client_secretstringYes1 to 256 characters
transient_tokenstringYes1 to 8192 characters. Sent on both calls of a challenged payment
cardholder_namestringNoUp to 100 characters
browserobjectNo{ 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_windowstringNo01 to 05: the size the bank's page may use
challenge_completedbooleanNotrue 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 ​

FieldTypeMeaning
chargestringThe charge id
intent_idstringThe card attempt
statusstringThe intent's status. completed once approved
paymentstringsucceeded, challenge, pending or review
challengeobjectWith challenge only: step_up_url, access_token, width, height of the bank's page
failureobjectOn 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:

HTTPCodeNameWhen
4022723COLLECTION_DECLINEDThe card was declined. data.failure says why
5022779CARD_CHARGE_FAILEDCyberSource refused the request. Nothing was taken. data.failure.code is rail_unavailable
4092778CARD_CONTEXT_EXPIREDThe transient token has expired. The element refreshes the form
4092777CARD_PAYMENT_IN_VERIFICATIONAnother charge call holds the attempt, or a payment is being verified
4092773CARD_VERIFICATION_FAILEDThe charge could not be verified with CyberSource
403 or 4092772CARD_TOKEN_INVALIDThe token is from another form, or no attempt is open
4092707INTENT_FINALIZEDThe attempt has ended
4032775CARD_SANDBOX_CURRENCY_BLOCKEDCard payments for this currency are not live yet
4221701INVALID_REQUEST_DATAThe charge was refused for its data
4291804RATE_LIMIT_EXCEEDEDSee the rate limit below

Refresh the card form ​

POST /v1/payments/public/charges/{id}/card/refresh

A new capture context for the same attempt, called when the old one nears the end of its 15 minutes.

Headers ​

HeaderRequiredValue
Content-TypeYesapplication/json
OriginYesSet by the browser
Idempotency-KeyNo1 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 ​

RouteBuckets429
/card200 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 charge1804
/card/payer-auth, /card/charge, /card/refresh30 a minute per client IP, one bucket across all three routes (counted before the secret check), and 60 an hour per charge for each route1804

A 429 carries Retry-After and data.retryAfter in seconds. The element reports it as try_again.

Staging documentation. A checkout made with a secret key on staging charges a real phone. See Environments.