Integration guide
Take a payment end to end: get keys, charge through the hosted checkout or directly from your server, confirm the result, test in the sandbox and go live. Every request and response shown here matches the API; the API reference lists every field and error.
1. Keys and access
Your account has three kinds of key, each in a test and a live variant:
fl_sk_test_…/fl_sk_live_…— secret key. Sent asAuthorization: Bearer …from your server only.fl_pk_test_…/fl_pk_live_…— publishable key. Goes in thepublic_keyfield of a checkout session; sending it as the Bearer token is refused (PUBLIC_KEY_NOT_ALLOWED).fl_enck_test_…/fl_enck_live_…— card encryption key, for encrypting card data on your server (step 3). It is shown once when the key is created; if you lose it, rotate the key.
Create keys in the dashboard; each new key is confirmed with a 6-digit code emailed to the account owner. Live keys are available once your account is verified. Before a key accepts any request, add the IP addresses your servers call from to its allowed-IP list — a request from any other address, or to a key with an empty list, is refused with 403 IP_NOT_ALLOWED.
Base URLs: https://sandbox.swiftdime.com for testing and https://api.swiftdime.com for live. The key prefix decides which environment a request touches, so a test key never moves real money. All requests must use HTTPS. The optional API-Version header (for example 2025-11-26) pins a version; without it your account's pinned version, or the platform default, is used.
2. Hosted checkout
The quickest integration: your server creates a session, you send the customer to SwiftDime's page, and card data never touches your systems.
- Create a session with
POST /api/v1/payments/session.tx_refis your order reference and becomes the payment'sreference; it must be unique on your account. - Redirect the customer to
data.data.checkout_url(the session payload is nested one level deeper than other responses). The session expires after 30 minutes unless you setconfigurations.session_duration. - After a successful payment the customer lands on your
redirect_urlwithreference,status=successful,amount,currencyandpayment_methodquery parameters. A customer who cancels is sent tocancel_urlwithstatus=cancelled. - Confirm on your server with
GET /api/v1/payments/verify/{reference}before fulfilling (step 4).
curl -X POST https://sandbox.swiftdime.com/api/v1/payments/session \
-H "Authorization: Bearer $SWIFTDIME_SECRET_KEY" \
-H "Content-Type: application/json" \
-H "X-Idempotency-Key: session-ORD-12345" \
-d '{
"public_key": "fl_pk_test_your_publishable_key",
"tx_ref": "ORD-12345",
"amount": 150,
"currency": "ZMW",
"payment_options": "card,mobilemoney",
"redirect_url": "https://shop.example.com/payments/return",
"cancel_url": "https://shop.example.com/cart",
"customer": { "email": "customer@example.com", "name": "John Doe" },
"meta": { "order_id": "12345" }
}'
# 201 → send the customer to data.data.checkout_urlpayment_options takes card, mobilemoney or both (card,mobilemoney). Note the spelling: mobile_money is refused here with 400 INITIALIZATION_FAILED. customer.email is required.curl https://sandbox.swiftdime.com/api/v1/payments/verify/ORD-12345 \
-H "Authorization: Bearer $SWIFTDIME_SECRET_KEY"3. Direct charge
POST /api/v1/payments/initialize creates and charges a payment in one call from your server. It charges mobile_money, card and bank_transfer. Send reference (your order id, unique on your account) and an X-Idempotency-Key so a network retry cannot charge twice.
Reading the response
- 201 — the charge is underway or done.
data.statusisprocessingorpending(wait for the webhook) orcompleted. - 200 with
data.status: "failed"— declined. Read the buyer-safefailure_reasonfromGET /api/v1/transactions/{reference}; to try again, send a newreference. - 202 — card needs 3-D Secure: send the customer to
data.next_action.url. This body has noreferencefield; use the one you sent. - 4xx — the request was rejected;
error.codesays why. Body validation errors list every failing field inerror.fields.
Mobile money
payment_details.provider (the network code — list them with GET /api/v1/payments/initialize/mobile-money-providers?country=XX) and payment_details.phone_number are both required. The number is checked against the network's numbering plan and normalised to E.164. The response carries next_action.type: "payment_instruction"; show next_action.note so the customer approves the prompt on their phone.
curl -X POST https://sandbox.swiftdime.com/api/v1/payments/initialize \
-H "Authorization: Bearer $SWIFTDIME_SECRET_KEY" \
-H "Content-Type: application/json" \
-H "X-Idempotency-Key: charge-ORD-12345-1" \
-d '{
"amount": 150,
"currency": "ZMW",
"payment_type": "mobile_money",
"reference": "ORD-12345",
"customer": { "email": "customer@example.com", "phone_number": "+260761234567" },
"payment_details": { "provider": "mtn", "phone_number": "+260761234567" }
}'Cards
Raw card fields are refused. Send either client — the card encrypted on your server with your fl_enck_ key (below; it must be the only card field) — or a card_token from POST /api/v1/payment-methods/cards/tokenize together with last_four, brand, expiry_month and expiry_year. Card charges need redirect_url.
const crypto = require("crypto");
// client = base64( nonce(12) || ciphertext || tag(16) ), AES-256-GCM,
// key = SHA-256 of your fl_enck_ key string. Server-side only.
function encryptCard(card, encryptionKey) {
const key = crypto.createHash("sha256").update(encryptionKey, "utf8").digest();
const nonce = crypto.randomBytes(12);
const cipher = crypto.createCipheriv("aes-256-gcm", key, nonce);
const ct = Buffer.concat([cipher.update(JSON.stringify(card), "utf8"), cipher.final()]);
return Buffer.concat([nonce, ct, cipher.getAuthTag()]).toString("base64");
}
const client = encryptCard(
{ card_number: "4242424242424242", cvv: "123", expiry_month: "12",
expiry_year: "2029", cardholder_name: "John Doe" },
process.env.SWIFTDIME_ENCRYPTION_KEY
);
const res = await fetch(BASE + "/api/v1/payments/initialize", {
method: "POST",
headers: {
"Authorization": "Bearer " + process.env.SWIFTDIME_SECRET_KEY,
"Content-Type": "application/json",
"X-Idempotency-Key": "charge-ORD-12346-1",
},
body: JSON.stringify({
amount: 49.99,
currency: "USD",
payment_type: "card",
reference: "ORD-12346",
redirect_url: "https://shop.example.com/payments/return", // required for card
customer: { email: "customer@example.com" },
payment_details: { client }, // client must be the only card field
}),
});
const body = await res.json();
if (res.status === 202) {
// 3-D Secure: send the customer to body.data.next_action.url
} else if (res.ok && body.data.status === "completed") {
// paid
} else if (res.ok && body.data.status === "failed") {
// declined
}If the card issuer asks for a PIN, OTP or extra fields, the response's next_action.type is requires_pin, requires_otp or requires_additional_fields; collect it and send it with PUT /api/v1/transactions/{reference}/authorize.
Bank transfer
payment_details needs account_number, account_name and bank_name (and optionally bank_code). The response's next_action.type is requires_bank_transfer.
Split payments
Add a top-level subaccounts array (id, and optionally transaction_split_ratio, transaction_split, transaction_charge, transaction_charge_type, settlement_type). Subaccounts inside metadata are ignored. An unknown destination is refused with 400 INVALID_SUBACCOUNT before anything is charged.
X-Idempotency-Key per charge attempt and re-send it unchanged when you retry after a timeout: the same key and body return the original response instead of charging again. Keys are scoped to your account for 24 hours. A key reused with a different body returns 422 IDEMPOTENCY_MISMATCH; a key whose first request is still being processed returns 409 DUPLICATE_REQUEST — wait and retry with the same key.4. Webhooks and confirmation
SwiftDime posts events to the webhook URL configured on your account (the callback_url request field does not change where webhooks go). Status changes arrive as transaction.completed, transaction.failed, transaction.cancelled, transaction.expired, transaction.refunded or transaction.updated; card charges also send card.payment.completed and card.payment.failed. The body is { id, event, created_at, data }, and data.reference and data.status identify the payment.
Verify the Swiftdime-Signature header, acknowledge with a 2xx, then confirm the payment with GET /api/v1/payments/verify/{reference} and fulfil only on completed. Make fulfilment idempotent: the same payment can be announced more than once. Event details are on the Webhooks page.
const express = require("express");
const crypto = require("crypto");
const app = express();
// Swiftdime-Signature: t=<unix seconds>,v1=<hex HMAC-SHA256 of "<t>." + raw body>
app.post("/webhooks/swiftdime", express.raw({ type: "application/json" }), async (req, res) => {
const header = req.get("Swiftdime-Signature") || "";
const parts = Object.fromEntries(header.split(",").map((kv) => kv.split("=")));
if (!parts.t || !parts.v1) return res.sendStatus(400);
const expected = crypto
.createHmac("sha256", process.env.SWIFTDIME_WEBHOOK_SECRET)
.update(Buffer.concat([Buffer.from(parts.t + "."), req.body]))
.digest("hex");
const valid = expected.length === parts.v1.length &&
crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(parts.v1));
const fresh = Math.abs(Date.now() / 1000 - Number(parts.t)) < 300;
if (!valid || !fresh) return res.sendStatus(400);
res.sendStatus(200); // acknowledge first
const event = JSON.parse(req.body.toString("utf8"));
const reference = event.data.reference; // your reference
// Confirm before fulfilling — never rely on the event body alone:
// GET /api/v1/payments/verify/{reference} -> status === "completed"
});To reconcile amounts, read GET /api/v1/transactions/{reference}: net_amount is what you receive, and when the customer bore the fee (metadata.fee_bearer is customer) metadata.merchant_requested_amount is the amount you asked for while amount is what the customer was charged.
5. Test in the sandbox
Use your fl_sk_test_ key. Test payments run the same API as live, and each test card or phone number always produces the same outcome. An instrument not on the list is declined, so a typo shows up as a failure, not a false success.
| 4242 4242 4242 4242 | Success (Visa) |
| 5438 8980 1456 0229 | Success (Mastercard) |
| 4000 0000 0000 0002 | Declined |
| 4187 4274 1556 4246 | Insufficient funds |
| 5399 8312 3456 7897 | Expired card |
| 4000 0000 0000 3220 | 3-D Secure challenge, then success |
| +260761234567 (mtn) | Success |
| +260761234568 (mtn) | Insufficient funds |
| +260761234569 (mtn) | Wrong PIN |
| +260761234574 (mtn) | Stays pending (customer never approves) |
| +260971234567 (airtel) | Success |
| +260971234569 (airtel) | Invalid PIN |
| 260970000002 | Pending, then success after 3 seconds |
| 260970000003 | Pending, then times out after 3 seconds |
Test cards are matched on their first six and last four digits. With a test key you can also force an outcome with the X-Scenario-Key header (for example success, declined, insufficient_funds, pending_approval, timeout, three_ds_required); it is ignored on live keys. The full list of instruments and scenarios is on the Testing page.
Run sandbox payments as direct charges (POST /api/v1/payments/initialize). For test cards, store the card with POST /api/v1/payment-methods/cards/tokenize and charge the returned card_token.
6. Go live
- Complete account verification. Live keys are issued only to verified accounts, and live charges for an unverified account fail.
- Create a live key and add your production servers' IPs to its allowed-IP list.
- Switch the base URL to
https://api.swiftdime.comand the keys tofl_sk_live_/fl_pk_live_/fl_enck_live_. Keep secrets in your server's secret store, never in client code. - Set the webhook URL on your live account and verify signatures with the live webhook secret.
- Fulfil only after
GET /api/v1/payments/verify/{reference}returnscompleted; treat redirects and webhooks as notifications. - Send a unique
referenceand anX-Idempotency-Keyon every charge; handle 200failed, 202 and 409 as described above. - Payments and refunds can be paused by SwiftDime (503
kill_switch); retry later rather than failing the order.
7. Troubleshooting
| 403 IP_NOT_ALLOWED | Your server's IP is not on the key's allowed-IP list. Add it in the dashboard. |
| 401 PUBLIC_KEY_NOT_ALLOWED / INVALID_API_KEY_PREFIX | Send the fl_sk_ secret key as Authorization: Bearer … |
| 403 INSUFFICIENT_SCOPE | The key lacks payments:write, payments:read or refunds:write for this route. |
| 400 REDIRECT_URL_REQUIRED | Card charges need redirect_url. |
| 400 VALIDATION_ERROR “Invalid payment details: …” | error.details.field names the payment_details field to fix. |
| 409 DUPLICATE_REFERENCE | The reference / tx_ref was used before. Use a new one. |
| 409 DUPLICATE_REQUEST | A request with this idempotency key is still being processed. Wait and retry with the same key. |
| 400 INITIALIZATION_FAILED | Session-only; the message names the problem (payment_options spelling, amount, currency). |
| Payment stuck in processing | The customer has not approved yet. It expires automatically after the payment window; GET /transactions/{reference}/verify re-checks with the provider. |