Skip to content

Buy an offer the decision engine offered

POST
/edgekit/v1/checkout
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.

x-edgekit-site-id
required

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.

string
>= 1 characters <= 128 characters

Example

site_example

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.

Media typeapplication/json
object
offerToken
required

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.

string
>= 1 characters
recurlyTokenId

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.

string
>= 1 characters
email
required

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.

string format: email

Example

buyer@example.com
firstName

The 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.

string
>= 1 characters <= 100 characters

Example

Ada
lastName

The buyer’s family name. Same rule as firstName: written on a new user only, never as an update.

string
>= 1 characters <= 100 characters

Example

Lovelace
threeDSecureActionResultTokenId

Recurly.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.

string
>= 1 characters
currency

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.

string
/^[A-Za-z]{3}$/

Example

eur
couponCode

A 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.

string
>= 1 characters <= 100 characters

Example

spring20
paymentMethod

What 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.

string
Allowed values: card apple_pay google_pay paypal link

Example

apple_pay
country

Where 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.

string
/^[A-Za-z]{2}$/

Example

de
postalCode

The buyer’s postal code, beside country. Stripe Tax and Recurly need one in the United States and Canada; elsewhere the country alone is enough.

string
>= 1 characters <= 20 characters

Example

10115

Charged, and the grant is written.

Media typeapplication/json
object
status
required

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.

string
attemptId
required

The checkout attempt’s id (UUIDv7). Every response carries it; quote it to support.

string format: uuid

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.

Media typeapplication/json
Any of:
object
status
required

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.

string
attemptId
required

The checkout attempt’s id (UUIDv7). Every response carries it; quote it to support.

string format: uuid

Example

{
"status": "granted",
"attemptId": "01999b1e-6f3a-7c2d-9e51-2a4c8d0f6b31"
}

Invalid request.

Media typeapplication/json
object
error
required
object
code
required
string
message
required
string
details

Example

{
"error": {
"code": "unauthorized",
"message": "Invalid or missing API key."
}
}

Not allowed.

Media typeapplication/json
object
error
required
object
code
required
string
message
required
string
details

Example

{
"error": {
"code": "unauthorized",
"message": "Invalid or missing API key."
}
}

Resource not found.

Media typeapplication/json
object
error
required
object
code
required
string
message
required
string
details

Example

{
"error": {
"code": "unauthorized",
"message": "Invalid or missing API key."
}
}

Conflicts with an existing record.

Media typeapplication/json
object
error
required
object
code
required
string
message
required
string
details

Example

{
"error": {
"code": "unauthorized",
"message": "Invalid or missing API key."
}
}

The card was declined. code is Recurly’s own.

Media typeapplication/json
object
error
required
object
code
required
string
message
required
string
details

Example

{
"error": {
"code": "unauthorized",
"message": "Invalid or missing API key."
}
}

Unexpected error.

Media typeapplication/json
object
error
required
object
code
required
string
message
required
string
details

Example

{
"error": {
"code": "unauthorized",
"message": "Invalid or missing API key."
}
}

edgekit.ai