Sell an offer with checkout
Checkout buys an offer from your own page. It is one browser request, POST /edgekit/v1/checkout, that takes an offer
token, a card token and the buyer’s email address. EdgeKit charges the card through your billing provider, then
writes the grant. Your page renders the card form. With Stripe, your page confirms the
card between two calls instead: see Confirm the card with Stripe.
Card numbers never reach EdgeKit. Your billing provider’s card fields on your page turn the card into a token, and
checkout accepts only that token. A request body carrying any key other than the ones below is refused with 400, so a
form that sends number or cvv by mistake fails loudly.
Several billing providers
Section titled “Several billing providers”An organization can have several billing providers active at once. One of them is the default, and checkout charges through it. With one active billing provider, that one is the default and there is nothing to set.
With several, mark the default in Revenue › Billing provider › Pricing, on the Billing providers tab: Make default on an active billing provider. The change is a draft and goes live on the next deploy. The deploy gate blocks a deploy while several billing providers are active and none is the default, and names them. A billing provider that is retiring or retired takes no new purchases and cannot be the default.
Your page’s card fields must be the default billing provider’s: the request body differs by billing provider, as below.
An offer token minted for a checkout page is the exception: it is charged
through that page’s billing provider, in the currency the page was opened with, and currency in the body is
ignored. A token with no checkout page is charged through the default.
What checkout needs
Section titled “What checkout needs”- An active billing provider that checkout charges through. Not every billing provider supports checkout yet:
see Integrations. EdgeKit holds your billing provider’s key and charges with it. Without the
key, or with no active billing provider, every checkout answers
409 no_billing_provider. With a billing provider checkout does not support, it answers409 billing_provider_unsupported. With several active billing providers, checkout charges through the default: see Several billing providers. - An offer that can be sold: Purchasable,
active, with an active price from your billing provider attached to it, and a billing provider coupon if it has an introductory discount. See Create and sell an offer. - An outcome that sells it: an
offer_tokenfield naming the offer, on an outcome a feature returns, in Revenue › Decision Engine › Outcomes, deployed. - Your page’s origin in the site’s Allowed origins. Checkout is checked against the origin like every other browser request. See Site settings.
- Your billing provider’s card fields on your page. Your Content Security Policy must allow them. Your billing provider’s page under Integrations lists the hosts.
Checkout is served on the /edgekit/ mount only. There is no API-key twin for servers. See
First-party mount and site proxy.
1. Get an offer token
Section titled “1. Get an offer token”Ask for the feature as usual. When the decision returns an outcome with an offer_token field, the field’s value is
a fresh offer token.
import { createClient } from '@edgekitcloud/client-browser';
const client = createClient({ siteId: 'site_example' });const { paywall } = await client.decide('paywall');
let offerToken: string | undefined;
if (paywall.status === 'decided' && paywall.outcome === 'subscribe') { // `checkout` is the name you gave the outcome's offer_token field. offerToken = (paywall.value as { checkout: string }).checkout;}An offer token names one offer on one site. On its own it authorizes nothing: it only says which offer the buyer was
shown. It stays valid for 12 hours by default and can be sent again until then, so a declined card can be retried
with the same token. A token used on another site answers 409 offer_token_unknown.
2. Take the card
Section titled “2. Take the card”Render your billing provider’s card fields and tokenize them when the buyer selects Buy. You get a card token id. How to load the fields and how long a token lives are on your billing provider’s page under Integrations. With Stripe, skip this step: checkout comes first.
3. Call checkout
Section titled “3. Call checkout”// Your billing provider's tokenize call, returning the card token id.const cardTokenId = await tokenizeCard();
const result = await client.checkout({ offerToken: offerToken!, // from step 1 recurlyTokenId: cardTokenId, email: 'ada@example.com', firstName: 'Ada', // optional lastName: 'Lovelace', // optional});
if (result.status === 'ok') { // 'granted', 'charged' or 'pending'. The buyer may have paid in every case. showReceipt(result.data.status);} else if (result.status === 'failed') { handleRefusal(result.code, result.details);} else { showTryAgainLater();}curl -i https://<tenant>.edgekit.ai/edgekit/v1/checkout \ -H 'x-edgekit-site-id: site_example' \ -H 'Origin: https://www.example.com' \ -H 'Content-Type: application/json' \ --data '{"offerToken":"<offer token>","recurlyTokenId":"<card token>","email":"ada@example.com"}'The body takes these keys and no others:
| Key | Required | What it is |
|---|---|---|
offerToken |
Yes | The offer token from the decision. |
recurlyTokenId |
Recurly | The card token id from Recurly.js. Refused with 400 under Stripe. |
email |
Yes | The buyer’s address. It decides which user gets the grant. |
firstName, lastName |
No | Up to 100 characters each. Written only when checkout creates the user. |
threeDSecureActionResultTokenId |
No | Sent only to finish a 3-D Secure challenge. See 3-D Secure. |
currency |
No | The currency to charge in, such as eur. See Currency. |
couponCode |
No | A code typed on a checkout page with the field on. Refused for any other offer token. |
paymentMethod |
No | What the buyer pays with: card (the default), apple_pay, google_pay, paypal or link. See Payment method. |
country |
Tax on | Where the buyer is taxed: an ISO 3166-1 alpha-2 code such as de. Required on a token of a checkout page with Tax on, else 409 address_required. Ignored on any other. See Tax. |
postalCode |
No | Up to 20 characters, beside country. Needed in the United States and Canada. Read only where country is. |
checkout has no timeout: it waits for the card authorization. An AbortSignal passed as signal stops waiting
but does not cancel the charge. Nothing is retried for you. See the
CheckoutRequestBody and
CheckoutResponseBody reference.
4. Handle the answer
Section titled “4. Handle the answer”| Status | Body | Meaning | Browser client |
|---|---|---|---|
200 |
{ "status": "granted", "attemptId" } |
Charged, and the grant is written. | ok |
202 |
{ "status": "charged", "attemptId" } |
Charged. The grant is still being written, and EdgeKit finishes it. Show a receipt. | ok |
202 |
{ "status": "pending", "attemptId", "runId"? } |
The charge’s outcome is not known yet. EdgeKit resolves it in the background. Show “still processing”. | ok |
202 |
{ "status": "requires_confirmation", "attemptId", "clientSecret", "confirmationType" } |
Stripe only. Nothing is charged yet. See Confirm the card with Stripe. | ok |
400 |
bad_request |
A missing or malformed field, such as an invalid email, or a key checkout does not accept (named in the message). | throws |
403 |
forbidden |
The page’s origin is not allowed for the site. | throws |
404 |
not_found |
The site is unknown, disabled or not yet deployed. | throws |
409 |
one of the codes below | A precondition failed. Fix it and try again. | failed |
422 |
your billing provider’s code, or declined |
The card was declined. Show the message and let the buyer try another card. | failed |
5xx |
an error, such as internal_error |
No answer. The buyer may still have been charged. | unavailable |
Never show a 200 or a 202 as a failure, and never invite the buyer to buy again after pending: money may have
moved. Treat a status you do not recognize as pending. Every 200 and 202 carries attemptId; quote it to
support.
The browser client throws EdgeKitConfigError on 400, 403 and 404, because each means the page is wired
wrongly.
409 codes
Section titled “409 codes”| Code | Message | What to do |
|---|---|---|
offer_token_unknown |
That checkout link is not valid. | Decide again for a fresh token. |
offer_token_expired |
That checkout link has expired. Reload the page and try again. | Decide again for a fresh token. |
offer_unknown |
That offer is no longer available. | The deployed catalog no longer has the offer. |
offer_not_purchasable |
That offer is not for sale. | Tick Purchasable and deploy. |
offer_not_active |
That offer is no longer for sale. | The offer is archived. |
offer_discount_unsupported |
That offer cannot be bought here right now. | Pick the billing provider coupon and deploy. |
offer_not_priced |
That offer cannot be bought here. | Attach a price for your billing provider and deploy. |
offer_not_priced_in_currency |
That offer is not sold in that currency. | Send a currency the offer has an active price in. |
no_billing_provider |
This site is not selling right now. | No active billing provider, or no key for it. |
billing_provider_unsupported |
This site is not selling through a supported billing provider. | Checkout does not charge through it yet. |
trial_already_used |
That trial has already been used on this account. | Offer a paid offer instead. |
sign_in_required |
Sign in to buy this offer. | The token’s checkout page is set to sign in first. |
email_invalid |
That is not an email address. | Ask for the address again. |
coupon_code_not_accepted |
This checkout takes no coupon code. | Send couponCode only from a checkout page with the field on. |
coupon_code_unknown |
That coupon code is not valid. | Send the request again without the code. |
coupon_code_not_applicable |
That coupon code cannot be used for this offer. | Send the request again without the code. |
coupon_code_refused |
That coupon code cannot be used for this purchase. Nothing was charged. Remove the code to continue. | The billing provider refused the code. Send it again without. |
attempt_coupon_code_changed |
This purchase was started with another coupon code. Reload the page and start again. | Send the coupon code the purchase started with, or none if it had none. |
payment_method_not_accepted |
This checkout does not take that payment method. | Pay another way. link is refused under Recurly, and PayPal on a Recurly checkout page with Tax on. |
address_required |
Choose your country to buy this offer. | Send country from a checkout page with Tax on. |
address_invalid |
Nothing was charged: tax cannot be worked out for that country and postal code. | Ask for the country and postal code again. |
card_token_expired |
Your card details could not be used for this purchase. Re-enter them and try again. | Tokenize the card again. |
three_d_secure_required |
Your bank needs to verify this payment. Complete the check and the purchase will finish. | Run the challenge. See 3-D Secure. |
billing_provider_busy |
That purchase is already being processed. Try again shortly. | Wait for Retry-After (5 seconds) and send it again. |
billing_provider_rejected |
The billing provider refused this purchase. Nothing was charged. | Check the offer’s price and coupon there. |
attempt_possibly_charged |
A purchase on this link is still being resolved. Reload the page and try again in a few minutes. | Wait. EdgeKit is settling an earlier attempt. |
attempt_email_mismatch |
A purchase on this link is already in progress for a different email address. | Decide again for a fresh token. |
attempt_offer_repriced |
This offer has changed since that checkout link was created. Reload the page and start again. | Decide again for a fresh token. |
Branch on code. The messages are written for the buyer and may change.
3-D Secure
Section titled “3-D Secure”When the buyer’s bank wants them to authenticate, checkout answers 409 three_d_secure_required with
details.threeDSecureActionTokenId. This is not a decline.
- Run your billing provider’s 3-D Secure challenge with
details.threeDSecureActionTokenId. Its page under Integrations names the call. - Call
checkoutagain with the sameofferTokenandrecurlyTokenId, plus the challenge’s result token asthreeDSecureActionResultTokenId.
Read details only after checking code.
Confirm the card with Stripe
Section titled “Confirm the card with Stripe”With Stripe as your billing provider, your page calls checkout before it takes the card, and confirms the card with
Stripe.js in between. Load Stripe.js with your organization’s own publishable key. Your page picks this flow from
the key it holds, never from a response: a Recurly body sent to a site selling through Stripe is a 400.
- Call
checkoutwithofferToken,emailand the optional names, and no card token. Nothing is charged. It answers202withstatusrequires_confirmation, aclientSecretand aconfirmationType. - Mount Stripe’s Payment Element on
clientSecret. When the buyer selects Buy, callstripe.confirmPaymentforpayment_intentorstripe.confirmSetupforsetup_intent, withredirect: 'if_required'. Stripe.js runs 3-D Secure on your page. A refused card is a Stripe.js error: show its message, and the same Payment Element takes another card. - Call
checkoutagain with the same body until it answers200 granted. Each call asks Stripe for the payment, so the first call after the card is confirmed usually answersgranted. Until Stripe reports the payment it answers202 pending: wait longer between each call and show “still processing”. Before the card is confirmed it answers the samerequires_confirmationagain, so a reload picks up where the buyer left off.
const body = { offerToken, email: 'ada@example.com' };const first = await client.checkout(body);
if (first.status === 'ok' && first.data.status === 'requires_confirmation') { // `stripe` is Stripe.js on your page, with your publishable key. const elements = stripe.elements({ clientSecret: first.data.clientSecret }); elements.create('payment').mount('#payment-element');
// When the buyer selects Buy: const options = { elements, redirect: 'if_required', confirmParams: { return_url: location.href }, } as const; const { error } = first.data.confirmationType === 'setup_intent' ? await stripe.confirmSetup(options) : await stripe.confirmPayment(options);
if (error) { showCardError(error.message); } else { // Call client.checkout(body) again, waiting longer each time, until it // answers 'granted'. Show "still processing" meanwhile. }}The Content Security Policy hosts are on the Stripe page.
Payment method
Section titled “Payment method”paymentMethod names what the buyer pays with. Without it, checkout reads card.
- Recurly: Recurly.js’ Apple Pay, Google Pay and PayPal each give a token. Send it as
recurlyTokenId, as a card’s, withpaymentMethodnaming which. A wallet’s token can be used once: after a 3-D Secure challenge that fails, ask the buyer to pay with the wallet again. - Stripe: the subscription takes that payment method only. Apple Pay and Google Pay are cards to Stripe, so
apple_pay,google_payandcardall take a card;paypalandlinktake that method. Mount the same one in Stripe.js. A buyer who wants another method after a decline needs a new offer token. - PayPal on Stripe leaves your page. Stripe sends the buyer back to the
return_urlyou passed toconfirmPaymentorconfirmSetup. Callcheckoutagain there with the same body until it answersgranted.
Who gets the grant
Section titled “Who gets the grant”Checkout reads the EdgeKit session for one kind of offer token only: one minted for a
checkout page set to sign in first. The grant then goes to
the signed-in user and the email in the request is not read. With no session, checkout answers
409 sign_in_required.
For every other offer token checkout reads no session. The grant goes to the user whose email address the buyer typed:
- If a user with that address exists, they get the grant. EdgeKit does not ask the buyer to prove the address, so a mistyped address gives the grant to whoever holds it.
- Otherwise checkout creates the user, with the address not yet verified, then charges. The buyer signs in with that address to use the access.
Addresses are compared after trimming and lower-casing, and nothing else: ada+news@example.com is a different user
from ada@example.com.
The user is created or found before the card is charged, in the same step that records the attempt, so a grant never waits for a user. The grant is the user’s own, never a user organization’s. It is not pinned to a site: it reaches every site the product covers.
The purchase itself sends no cookies. When it answers granted or charged, client.checkout() reads the session
(POST /edgekit/v1/id/get-session) before it resolves, which refreshes the copy of the user’s access the browser
holds, so the next decision reads the new grant. A page that calls the checkout route without the client does that
read itself.
Trials
Section titled “Trials”When the offer is marked The offer is the trial, checkout applies your organization’s trial reuse rule before it
charges. By default a user gets one trial per product: buying a trial offer for a product the user already had a
trial of answers 409 trial_already_used. The rule is shown as Trial reuse under Configuration on each
site’s screen in Delivery › Delivery › Sites. The console marks it not read yet, but checkout reads
it.
Double clicks and retries
Section titled “Double clicks and retries”Requests with the same offer token converge on one purchase attempt, so a double click never charges twice. A second
request while the first is still in flight answers the first one’s result or 409 billing_provider_busy. A request
after the purchase settled answers the original result again and charges nothing, for up to an hour after the first
attempt, or a day with Stripe. After a decline, send the same offer token again with the card the buyer enters next.
Currency
Section titled “Currency”Checkout charges in the currency the body names in currency: a three-letter ISO 4217 code such as eur, in any
case. Send the currency your page showed the buyer. Without currency, checkout charges in the site’s currency, set
in the site’s Currency section (see Site settings). With neither, it
charges the offer’s first active price.
If the offer has no active price in that currency, checkout answers 409 offer_not_priced_in_currency. It never
charges another currency instead.
A site that sells an offer with active prices in more than one currency needs a currency of its own. Until it has one, the deploy gate blocks every deploy. When an offer on a site has no active price in the site’s currency, the deploy gate warns: a checkout for it that names no currency is refused.
What checkout does not do
Section titled “What checkout does not do”- It does not take a coupon code from your own card form. An offer’s introductory discount applies to every buyer. A checkout page can show a coupon code field.
- It does not pick a currency from the buyer’s location.
- It does not check the offer’s Eligibility or show Trial days: those are for your page.
- It does not sell through every billing provider yet. See Integrations.
- It does not sell to a user organization.