API-Driven Card Checkout
This page shows how to accept card payments with your own UI by calling the checkout and card endpoints directly. Use this when you want to render the card form on your own site or mobile app instead of redirecting the customer to a hosted page.
What This Flow Does
You build and host the payment UI. Transfaar provides the payment session, card encryption key, and card processing endpoints:
- Initialize a payment session on your backend.
- Fetch the public key used to encrypt the card data.
- Select the payment method for the session.
- Encrypt and submit the card details.
- Handle 3-D Secure if the acquirer requires it.
- Track the result via status endpoints or webhooks.
Supported Currencies
USD—CARDNGN—CARD
Flow Overview
Step 1 — Initialize the payment session
POST /client/checkout/initialize (protected — HMAC API key)
Create the payment session from your backend. This is the only step that requires your signed API key — keep it off the browser or mobile client.
Request Body
Success Response
Keep the access_code — it authenticates every subsequent step in this flow. The checkout_link is not needed when you build your own UI.
Step 2 — Fetch the card encryption key
GET /card/encryption-key (public)
The card data you submit in Step 4 is encrypted before it leaves the client. This endpoint returns the public key used for that encryption.
Response
Step 3 — Select the payment method
POST /checkout/:access_code/select-method (public — access_code auth)
Tell the session which payment method the customer is using. For card payments, send CARD.
Request Body
Success Response
Step 4 — Encrypt and submit the card details
POST /card/card-charge (public — access_code auth)
Card data is submitted in a hybrid-encrypted envelope:
- Generate a random 32-byte AES key and a 12-byte IV/nonce.
- Encrypt the card payload with AES-256-GCM using that key.
- Encrypt the AES key with RSA-OAEP-SHA256 using the public key from Step 2.
- Send the envelope with the
access_codekept in plaintext so the backend can resolve the session.
Envelope Request Body
Decrypted Inner Payload
The plaintext inside encrypted_payload (encrypt exactly this JSON):
Success Response (payment completed)
Step 5 — Handle 3-D Secure
If the acquirer requires 3-D Secure, the charge response is not final. Redirect the customer to the returned threeDsUrl to complete the challenge, then continue to Step 6.
Response (3-D Secure required)
After the customer completes the challenge, poll the status endpoint below until it reaches a terminal state.
Step 6 — Check payment status
GET /checkout/:access_code/payment-status (public — access_code auth)
Poll this endpoint to track the session to completion, or rely on webhooks as your source of truth.
Response
For a server-side check from your backend, you can also call GET /client/payment/verify?reference={transaction_reference} (HMAC) with the transactionRef from Step 1.
Webhooks
Configure a webhook endpoint on your API key to receive the final result automatically. See Webhooks for the payload shape and delivery behavior.
Security Best Practices
- Never sign requests on the client. HMAC-signing requires your secret key — keep it on your backend.
- Encrypt card data before it leaves the client. Use the key from Step 2 and the AES-256-GCM + RSA-OAEP-SHA256 envelope described above.
- Do not store card data. Your servers never need to see a plaintext card number.
- Use webhooks as the source of truth. Do not rely on redirects or client-side callbacks alone.
- Use unique references for every initialization to prevent duplicate charges.