Buy an offer the decision engine offered
const url = 'https://your-tenant-host/edgekit/v1/checkout';const options = { method: 'POST', headers: {'x-edgekit-site-id': 'site_example', 'Content-Type': 'application/json'}, body: '{"offerToken":"example","recurlyTokenId":"example","email":"buyer@example.com","firstName":"Ada","lastName":"Lovelace","threeDSecureActionResultTokenId":"example","currency":"eur","couponCode":"spring20","paymentMethod":"card","country":"de","postalCode":"10115"}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://your-tenant-host/edgekit/v1/checkout \ --header 'Content-Type: application/json' \ --header 'x-edgekit-site-id: site_example' \ --data '{ "offerToken": "example", "recurlyTokenId": "example", "email": "buyer@example.com", "firstName": "Ada", "lastName": "Lovelace", "threeDSecureActionResultTokenId": "example", "currency": "eur", "couponCode": "spring20", "paymentMethod": "card", "country": "de", "postalCode": "10115" }'Redeems the offer_token an outcome field minted and buys the offer through the billing provider of the checkout page the token was minted for, else the default billing provider: the one active provider or the one marked default among several. A token minted for a checkout page also fixes the currency, and currency in the body is then ignored. A token minted for a checkout page set to sign-in first is bought by the signed-in user, whatever email says, and is refused with 409 sign_in_required when the request carries no session. Recurly: charges the card token the organization’s own Recurly.js took and writes the grant. Stripe: creates the subscription unpaid and answers 202 requires_confirmation with a client secret the page confirms in Stripe.js; re-send the same body until it answers granted. A token minted for a checkout page that charges tax needs country (and, in the United States and Canada, postalCode): the billing provider’s own tax is charged there. The body is an allowlist: offerToken and email, plus the optional firstName, lastName, currency, couponCode, paymentMethod, country and postalCode; under Recurly also recurlyTokenId (required) and the optional threeDSecureActionResultTokenId, which are refused under Stripe. Every other key is a 400 naming the key. A body carrying number or cvv means the card form failed to tokenize and raw card data reached EdgeKit. 200 is charged and granted. 202 is data, not a failure: charged (grant still being written; render a completed purchase), pending (the payment’s fate is not yet known; render still processing) or requires_confirmation (Stripe; nothing charged yet). 409 is a failed precondition, each with its own code: an expired or unknown offer token, a closed offer, an offer not sold in the requested currency, a dead card token, no active billing provider, no session on a sign-in first checkout page, a payment method the page has off, a coupon code that is not taken or cannot be redeemed, or a missing or untaxable address on a page that charges tax. 422 is a card decline, carrying Recurly’s own code. Retry-safe with the same offerToken: a settled purchase answers its original result and charges nothing again.
Parameters
Section titled “Parameters”Header Parameters
Section titled “Header Parameters”The site this request is for, within this tenant. Every official EdgeKit SDK sets it from the client you configured; set it yourself only when calling this API directly.
Example
site_exampleThe site this request is for, within this tenant. Every official EdgeKit SDK sets it from the client you configured; set it yourself only when calling this API directly.
Request Bodyrequired
Section titled “Request Bodyrequired”object
The stored handle an offer_token outcome field minted. It names one offer on one site, and its site must be the one this request selected. Opaque: it authorises nothing on its own.
Recurly.js’ card token id, from the organization’s own page: the only card-shaped value EdgeKit ever accepts. It lives about 20 minutes and is reusable inside that window. Required when the site sells through Recurly, refused (400) when it sells through Stripe, whose card is confirmed in Stripe.js after a requires_confirmation answer.
The buyer’s address, unverified. It resolves the user the grant belongs to: an existing user on an email match, a new one otherwise. Nothing on this path ever sets email_verified.
Example
buyer@example.comThe buyer’s given name, as typed on the card form. Written only when this purchase creates the user, never onto a user resolved by email match, so an unauthenticated caller cannot rename a stranger.
Example
AdaThe buyer’s family name. Same rule as firstName: written on a new user only, never as an update.
Example
LovelaceRecurly.js’ 3-D Secure result token id, sent only on the request that finalizes a three_d_secure_required refusal. It proves the buyer cleared their bank’s challenge. Never send the threeDSecureActionTokenId the refusal carried: that is the challenge itself. Send the same offerToken and recurlyTokenId alongside it: the offer token is replayable within its TTL and the card token is reusable within its 20 minutes.
The currency to charge in, as a three-letter ISO 4217 code such as eur, in any case. Absent, the site’s own currency applies, and with none set, the offer’s first active price. An offer with no active price in that currency answers 409 offer_not_priced_in_currency: checkout never charges another currency instead.
Example
eurA coupon code the user typed on a checkout page whose coupon code field is on. It must be a synced coupon of the page’s billing provider that applies to the offer’s price: Recurly’s coupon code, or Stripe’s coupon id (never a promotion code). It replaces the offer’s own discount. Refused with 409 coupon_code_not_accepted for a token minted for a page with the field off, or for no checkout page; 409 coupon_code_unknown or coupon_code_not_applicable when no such coupon can be redeemed on the offer; 409 coupon_code_refused when the billing provider itself refuses it. Send the request again without it to buy at the offer’s own price.
Example
spring20What the buyer pays with: card (the default), apple_pay, google_pay, paypal, or Stripe’s link. Refused with 409 payment_method_not_accepted for a token minted for a checkout page that has the method off, and link on Recurly. On a token with no checkout page any is taken, and under Stripe the subscription then takes that method only, so mount the same one in Stripe.js.
Example
apple_payWhere the buyer is taxed: an ISO 3166-1 alpha-2 country code such as de, in any case. Required for a token minted for a checkout page that charges tax (409 address_required without it), and read for no other token. Under Stripe it is the address on the buyer’s new Stripe Customer, which Stripe Tax charges on; 409 address_invalid when Stripe Tax cannot place it. Under Recurly, Recurly taxes the address on the card token, so put the same country and postal code in the Recurly.js form.
Example
deThe buyer’s postal code, beside country. Stripe Tax and Recurly need one in the United States and Canada; elsewhere the country alone is enough.
Example
10115Responses
Section titled “Responses”Charged, and the grant is written.
object
granted (200): charged, and the grant is written. charged (202): charged, and the grant is still being written. EdgeKit finishes it, and the buyer has paid either way. Open: treat an unknown member as pending.
The checkout attempt’s id (UUIDv7). Every response carries it; quote it to support.
Example
{ "status": "granted", "attemptId": "01999b1e-6f3a-7c2d-9e51-2a4c8d0f6b31"}charged: the buyer has paid, and EdgeKit finishes writing the grant. pending: the payment’s fate is not yet known. requires_confirmation (Stripe): nothing charged; confirm clientSecret in Stripe.js and send the same body again. Branch on status.
object
granted (200): charged, and the grant is written. charged (202): charged, and the grant is still being written. EdgeKit finishes it, and the buyer has paid either way. Open: treat an unknown member as pending.
The checkout attempt’s id (UUIDv7). Every response carries it; quote it to support.
object
The card’s fate is not known yet. Render still processing: never a failure, never an invitation to buy again.
The checkout attempt’s id (UUIDv7). Every response carries it; quote it to support.
The id of the background run finishing the purchase, when one is. Diagnostic only: quote it to support; a page cannot resolve it.
object
Stripe only. Nothing has been charged. Mount Stripe’s Payment Element on clientSecret with the organization’s own publishable key, confirm it, then send the same body again: it answers this again until the confirmation lands, then pending, then granted.
The checkout attempt’s id (UUIDv7). Every response carries it; quote it to support.
The client secret of the payment (or, for a trial, the setup) the page confirms. Hand it to Stripe.js; never log or store it.
payment_intent: call stripe.confirmPayment. setup_intent (a trial, nothing due today): call stripe.confirmSetup.
Example
{ "status": "granted", "attemptId": "01999b1e-6f3a-7c2d-9e51-2a4c8d0f6b31"}Invalid request.
object
object
Example
{ "error": { "code": "unauthorized", "message": "Invalid or missing API key." }}Not allowed.
object
object
Example
{ "error": { "code": "unauthorized", "message": "Invalid or missing API key." }}Resource not found.
object
object
Example
{ "error": { "code": "unauthorized", "message": "Invalid or missing API key." }}Conflicts with an existing record.
object
object
Example
{ "error": { "code": "unauthorized", "message": "Invalid or missing API key." }}The card was declined. code is Recurly’s own.
object
object
Example
{ "error": { "code": "unauthorized", "message": "Invalid or missing API key." }}Unexpected error.
object
object
Example
{ "error": { "code": "unauthorized", "message": "Invalid or missing API key." }}