Skip to main content

Programmatic Checkout

When the price or product context needs to come from your backend — a custom quote, a WordPress shortcode, a dynamic subscription plan — create the checkout session on your server and hand the resulting session token to the SDK on the client. This is the flow used internally by the Khaime WordPress [khaime_checkout] shortcode.

1. Create the session on your server

Call the initialize endpoint with your secret API key.
The response is a CheckoutSession:
The session token is single-use and short-lived. Generate it per customer, per transaction.

Example: PHP / WordPress

Example: Node.js

2. Render the payment UI on the client

Pass the session token to sdk.createPayment():
createPayment does three things:
  1. Fetches the session via GET /api/v1/sdk/checkout/session/{sessionToken} to retrieve gateway credentials.
  2. Lazy-loads the checkout modal component.
  3. Renders Stripe Elements or Paystack inline based on the session’s paymentGateway.
No API key is needed on the client — the session token is the authorization.

3. Confirm and fulfil

When the customer submits, the SDK calls POST /api/v1/sdk/checkout/session/{sessionToken}/confirm. On success, onSuccess fires with the order ID.
Always verify the order server-side via a webhook before fulfilling. The client callback only confirms the payment UI completed — webhooks confirm the charge.

When to use this flow

Shortcut: server-side one-shot + redirect

If you don’t need an embedded UI, you can skip createPayment() entirely and redirect the customer to the Khaime-hosted checkout URL returned by the initialize endpoint. See the Create Session API reference.

Next steps