Initialize payment
Initialize a payment transaction with HMAC signature verification and idempotency protection.
🔐 HMAC Signing (REQUIRED)
All payment initialization requests MUST include HMAC-SHA256 signature:
- Generate Timestamp: Get current Unix timestamp in seconds
- Create Payload: Concatenate
timestamp + "." + JSON_body - Sign Payload:
HMAC-SHA256(hmac_secret, payload)→ base64 encode - Include Headers:
X-Timestamp: Unix time in seconds or milliseconds (within 5 minutes of server time)X-Signature: Base64-encoded HMAC signatureIdempotency-Key: Unique key to prevent duplicate payments
🔄 Idempotency Protection (REQUIRED)
Include Idempotency-Key header to prevent duplicate payment initialization.
If the same key is used, the original payment initialization is returned.
- Recommended format:
payment-{timestamp}-{random} - Must be unique per payment attempt
- Prevents duplicate charges on network retries
- Returns existing payment if key already used
- A request refused before it reaches a payment provider (an invalid body, an unknown order, an amount that does not match the order) does not use up the key: the corrected request can be sent with the same key
- While another request with the same key is still being initialized, the response is
409 idempotency_in_progress; retry shortly with the same key
🛡️ Amount validation (anti-tampering)
When you pass an order_id, the server validates amount against that order’s authoritative
total — a amount that doesn’t match the order total is rejected with 400 amount_mismatch.
The order total was itself validated against the catalog + the shopper’s real promotions/gift card
at order creation (see the order endpoint’s server-side price validation), so you cannot charge
less than the order is worth. Pass the order’s real total_amount; don’t compute or alter it
client-side.
An order that is already paid is refused with 409 order_already_paid, and a cancelled order
with 409 order_not_payable. An order is charged only in its own currency: omit currency
to use it, and a different currency is rejected with 400 payment_currency_mismatch.
Provider-Specific Flows:
Stripe (redirect):
- Initialize payment with amount, currency, email
- Redirect customer to
checkout_url - Customer completes payment on Stripe
- Stripe redirects to success/cancel URL
- Verify payment status with
/v1/payments/verify
Stripe (embedded):
- Initialize payment with
mode: "embedded", amount, currency, email and theorder_id - Mount the Stripe payment form in your page with the returned
publishable_keyandclient_secret - The customer pays in place (card, Apple Pay, Google Pay or Link)
- The order settles from Stripe’s confirmation; verify with
/v1/payments/verifyusing thereferenceor thepayment_intent_id - Repeating the request with the same
Idempotency-Keywhile the payment is still open returns the sameclient_secretwithidempotent: true
The publishable_key and client_secret are for the browser; they are never the secret key. A
publishable key from a different mode than the secret key (test and live) is refused with
409 provider_misconfigured. Apple Pay appears on the hosts registered for the store in Payments settings.
PayPal (popup):
- Initialize payment with amount and currency
- Use the returned
client_idandpaypal_order_idto render the PayPal Buttons popup in your frontend - Customer approves the payment in the PayPal window
- Verify payment status with
/v1/payments/verify— this captures the approved order
Paystack (popup):
- Initialize payment with amount, currency, email
- Use returned
public_keyandreferenceto open Paystack popup - Customer completes payment in popup
- Verify payment status with
/v1/payments/verify
M-Pesa (STK Push):
- Initialize payment with amount and phone (254XXXXXXXXX format)
- Customer receives STK Push prompt on their phone
- Customer enters M-Pesa PIN
- Verify payment status with
/v1/payments/verify
Security Notes:
- HMAC secret is displayed in the Integrations page (Developer section)
- Never expose HMAC secret in client-side code
- Regenerate secret immediately if compromised
- Requests with invalid/missing signatures return 401 Unauthorized
- Timestamps older than 5 minutes are rejected (prevents replay attacks)
Rate Limiting:
- Additional 100 requests/hour limit for payment initialization
- Separate from global API rate limits
Key Type Support:
- ✅ Secret keys (full access)
- ❌ Publishable keys (forbidden - returns 403)
curl --request POST \
--url https://api.tybritelabs.com/v1/payments/initialize \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: <idempotency-key>' \
--header 'X-Signature: <x-signature>' \
--header 'X-Timestamp: <x-timestamp>' \
--data '
{
"provider": "stripe",
"amount": 100,
"currency": "usd",
"email": "john.doe@example.com",
"order_id": "880e8400-e29b-41d4-a716-446655440003",
"success_url": "https://example.com/payment-success",
"cancel_url": "https://example.com/payment-cancelled"
}
'{
"success": true,
"provider": "stripe",
"type": "redirect",
"reference": "PAY-12345678-ABC123",
"checkout_url": "https://checkout.stripe.com/c/pay/cs_test_...",
"session_id": "cs_test_...",
"environment": "test",
"expires_at": "2026-02-10T12:00:00Z"
}Authorizations
API Key Authentication
Use your API key in the Authorization header:
Authorization: Bearer tybrite_sk_live_YOUR_KEY
Key Types:
Secret Keys (Server-Side Only):
- Format:
tybrite_sk_live_*(production) ortybrite_sk_test_*(sandbox) - Full read/write access to all endpoints
- ⚠️ NEVER expose in client-side code or public repositories
- Required for: every write a shopper does not make for themselves, authentication, payment verification, AI recommendations
Publishable Keys (Client-Safe):
- Format:
tybrite_pk_live_*(production) ortybrite_pk_test_*(sandbox) - Catalogue reads, plus the actions a shopper takes for themselves
- ✅ Safe for client-side JavaScript, mobile apps, and public code
- Allowed for: browsing products, search, CMS content, pricing queries, cart and wishlist, reviews, storefront events, and the Agent API's quotes, cart drafts and checkout intents
Endpoint-Specific Requirements:
- Authentication endpoints (
/v1/auth/*): state-changingPOSTcalls require a secret key, for store and marketplace keys alike;GET /v1/auth/meaccepts either key - Payment verification (
POST /v1/payments/verify): Secret key required - AI Recommendations (
POST /v1/recommendations): Secret key required - Semantic Search (
POST /v1/search): Both key types allowed (read-only operation) - Shopper actions (cart, wishlist, reviews, storefront events, Agent API quotes, cart drafts and checkout intents): Both key types allowed
- All other write operations: Secret key required
- All read operations: Both key types allowed
Using a publishable key for restricted operations returns 403 Forbidden.
Limited publishable keys:
A publishable key can be limited to the products that carry one tag (for example starter:jewellery), created from
the store's Developers page. The limit applies to the key, never to the shopper: shopper sign-up and sign-in stay store-wide.
- Reads return only the slice: products (with their facets, filters, search, brands and specifications), categories and
subcategories that hold in-slice products, collections, promotions, posts and lookbooks that carry the tag, reviews of
in-slice products, prices, discovery lists and the store information summary, with every count computed on the slice.
A product outside the slice answers
404, as if it did not exist. - A write that names a product or variant outside the slice (adding to the cart or wishlist, reserving stock, an order line,
a review, a promotion calculation, a storefront event) answers
403with the error codeout_of_scope, and nothing is written or reserved. An order is refused as a whole. - A route that carries no slice behaviour is not available to the key: it answers
403withendpoint_not_allowed. - Orders placed through such a key record the tag on the order's attribution as
key_scope. - Secret keys and connected-app keys cannot be limited.
- Responses are cached per key limit: a limited key never receives a response cached for the whole store, and the reverse.
Headers
Body
Payment provider to use. The built-in providers are stripe, paypal, paystack,
and mpesa. A store that has connected its own payment provider can also pass that
provider's identifier here — the same value returned as provider (with
custom_provider: true) by GET /v1/payments/methods.
"stripe"
Payment amount in MAJOR currency units — 100.00 is one hundred dollars, not one
dollar. This matches every other amount in the API: catalog prices, order totals
and refunds are all major units. The processor's own smallest-denomination amounts (Stripe
cents, Paystack kobo) are converted server-side; never send those here.
When order_id is supplied the amount must equal that order's total to the cent,
or the request is rejected with amount_mismatch. Sending 10000 for a 100.00
order fails that check rather than charging a hundred times over.
x >= 0.01100
Currency code (ISO 4217). Case-insensitive — it is normalised to whatever the
chosen processor expects, so usd and USD behave identically.
Required for Stripe and Paystack.
- Stripe: Defaults to store's default currency
- PayPal: Defaults to store's default currency
- Paystack: Must be one of NGN, GHS, ZAR, KES, USD
- M-Pesa: Always KES (ignored)
"usd"
Keep the shopper's card so the store can charge it for the later deliveries of a Subscribe &
Save subscription. Honoured only when order_id names an order that carries subscribe_save
and was placed by a signed-in shopper, and only for stripe and paystack; it is
ignored otherwise. The shopper sees the processor's own page and agrees to the card being
kept there; the card details never reach your site or this API. The response's
renewal_mode says how the later deliveries will be paid.
true
Stripe only. redirect (the default) returns a hosted checkout_url. embedded returns a client_secret and publishable_key so the storefront can take the payment on its own page (cards, Apple Pay, Google Pay, Link) and needs no success_url or cancel_url. Any other provider rejects embedded with 400 invalid_request.
redirect, embedded "embedded"
Response
Payment initialized successfully
- Option 1
- Option 2
- Option 3
- Option 4
- Option 5
Present when the payment is for an order that carries subscribe_save. off_session means the
shopper's card is kept and charged for each later delivery. confirm means the shopper pays each
later delivery from a link sent to them, which is always the case for a payment method that cannot
keep a card and when save_payment_method was not requested.
off_session, confirm "off_session"
curl --request POST \
--url https://api.tybritelabs.com/v1/payments/initialize \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: <idempotency-key>' \
--header 'X-Signature: <x-signature>' \
--header 'X-Timestamp: <x-timestamp>' \
--data '
{
"provider": "stripe",
"amount": 100,
"currency": "usd",
"email": "john.doe@example.com",
"order_id": "880e8400-e29b-41d4-a716-446655440003",
"success_url": "https://example.com/payment-success",
"cancel_url": "https://example.com/payment-cancelled"
}
'{
"success": true,
"provider": "stripe",
"type": "redirect",
"reference": "PAY-12345678-ABC123",
"checkout_url": "https://checkout.stripe.com/c/pay/cs_test_...",
"session_id": "cs_test_...",
"environment": "test",
"expires_at": "2026-02-10T12:00:00Z"
}
