Skip to content

OpenAPI and SDKs

The whole API is described in an OpenAPI 3.1 specification, from which a Postman collection and three official SDKs are provided: Node.js, PHP and Python. The SDKs cover every endpoint, pass livemode through untouched, and ship with webhook signature verification.

File Address
OpenAPI 3.1 (JSON) cartflox.com/docs/openapi.json
OpenAPI 3.1 (YAML) cartflox.com/docs/openapi.yaml
Postman collection (v2.1) cartflox.com/docs/cartflox.postman_collection.json
Index for AI assistants (llms.txt) cartflox.com/llms.txt, llms-full.txt

In Postman: Import, then paste the collection address. Set the bearerToken variable to your secret key (the test one to start with). For another language (Go, Java, C#, Ruby…), generate a client from the specification with openapi-generator.

Node.js 18 or newer, no dependency, TypeScript included, ESM and CommonJS.

Fenêtre de terminal
curl -O https://cartflox.com/docs/sdk/cartflox-node.tgz
npm install ./cartflox-node.tgz
import { Cartflox } from "cartflox";
const cartflox = new Cartflox({ apiKey: process.env.CARTFLOX_SECRET_KEY });
const session = await cartflox.checkout.sessions.create(
{ amount: 5000, currency: "XOF", customer_email: "awa@example.com", metadata: { order_id: "1042" } },
{ idempotencyKey: "order-1042" },
);
// Redirect the customer to session.url, then wait for the payment.completed webhook
const status = await cartflox.checkout.sessions.retrieveStatus(session.id);
if (status.paid) { /* fulfil */ }

Each SDK verifies the signature (X-Afriflow-Signature, X-Afriflow-Timestamp, 5-minute tolerance) and returns the decoded event. Pass the raw request body, never an already parsed JSON.

import { Webhooks, WebhookSignatureError } from "cartflox";
app.post("/webhooks/cartflox", express.raw({ type: "application/json" }), (req, res) => {
try {
const event = Webhooks.constructEvent(req.body, req.get("X-Afriflow-Signature"), req.get("X-Afriflow-Timestamp"), process.env.CARTFLOX_SECRET_KEY);
if (event.event === "payment.completed" && event.livemode) { /* fulfil event.data.order_id */ }
res.sendStatus(200);
} catch (e) {
if (e instanceof WebhookSignatureError) return res.sendStatus(400);
throw e;
}
});

Give the client your test secret key (af_test_sec_...): nothing else changes. isTestKey (Node and PHP) or is_test_key (Python) tells you which key the client holds, and checkout.sessions.simulate(id, issue) settles a test session without opening the page, for your automated tests. See Test mode.

Sessions (create, status, methods, simulate), payment links, transfers (create, retrieve, list, options), webhook deliveries (list, retrieve, resend), webhook configuration, routing, transaction export, and the partner API. Each method returns the full JSON of the response; HTTP errors raise CartfloxError (Node), CartfloxException (PHP) or CartfloxError (Python) with the status, the code and the message.