Create a checkout session
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
product: 'prod_9Xk2mQ1pL0vRsT',
success_url: 'https://acme.test/welcome',
cancel_url: 'https://acme.test/pricing',
max_duration_seconds: 1296030
})
};
fetch('http://localhost:4000/v1/checkout/sessions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));curl --request POST \
--url http://localhost:4000/v1/checkout/sessions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"product": "prod_9Xk2mQ1pL0vRsT",
"success_url": "https://acme.test/welcome",
"cancel_url": "https://acme.test/pricing",
"max_duration_seconds": 1296030
}
'{
"id": "cs_3fT8kLm2Qp9RxV",
"object": "checkout.session",
"status": "open",
"livemode": true,
"created": 123,
"expires_at": 123,
"success_url": "<string>",
"cancel_url": "<string>",
"product": {
"id": "prod_9Xk2mQ1pL0vRsT",
"object": "product",
"name": "<string>",
"description": "<string>",
"rate_usd_per_second": "0.004",
"rate_per_second_wei": "4000",
"currency": "ausd",
"allow_pause": true,
"start_mode": "checkout",
"active": true,
"active_subscriptions": 123,
"livemode": true,
"created": 123
},
"merchant": {
"name": "<string>",
"logo_url": "<string>",
"accent": "<string>",
"support_url": "<string>"
},
"customer": "<string>",
"subscription": "<string>",
"max_duration_seconds": 123,
"max_escrow_usd": "<string>"
}{
"error": {
"type": "api_error",
"message": "<string>",
"code": "<string>",
"param": "<string>"
}
}{
"error": {
"type": "api_error",
"message": "<string>",
"code": "<string>",
"param": "<string>"
}
}{
"error": {
"type": "api_error",
"message": "<string>",
"code": "<string>",
"param": "<string>"
}
}Checkout
Create a checkout session
POST
/
v1
/
checkout
/
sessions
Create a checkout session
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
product: 'prod_9Xk2mQ1pL0vRsT',
success_url: 'https://acme.test/welcome',
cancel_url: 'https://acme.test/pricing',
max_duration_seconds: 1296030
})
};
fetch('http://localhost:4000/v1/checkout/sessions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));curl --request POST \
--url http://localhost:4000/v1/checkout/sessions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"product": "prod_9Xk2mQ1pL0vRsT",
"success_url": "https://acme.test/welcome",
"cancel_url": "https://acme.test/pricing",
"max_duration_seconds": 1296030
}
'{
"id": "cs_3fT8kLm2Qp9RxV",
"object": "checkout.session",
"status": "open",
"livemode": true,
"created": 123,
"expires_at": 123,
"success_url": "<string>",
"cancel_url": "<string>",
"product": {
"id": "prod_9Xk2mQ1pL0vRsT",
"object": "product",
"name": "<string>",
"description": "<string>",
"rate_usd_per_second": "0.004",
"rate_per_second_wei": "4000",
"currency": "ausd",
"allow_pause": true,
"start_mode": "checkout",
"active": true,
"active_subscriptions": 123,
"livemode": true,
"created": 123
},
"merchant": {
"name": "<string>",
"logo_url": "<string>",
"accent": "<string>",
"support_url": "<string>"
},
"customer": "<string>",
"subscription": "<string>",
"max_duration_seconds": 123,
"max_escrow_usd": "<string>"
}{
"error": {
"type": "api_error",
"message": "<string>",
"code": "<string>",
"param": "<string>"
}
}{
"error": {
"type": "api_error",
"message": "<string>",
"code": "<string>",
"param": "<string>"
}
}{
"error": {
"type": "api_error",
"message": "<string>",
"code": "<string>",
"param": "<string>"
}
}Authorizations
Your secret key: sk_test_… for test mode, sk_live_… for live. Server-side only.
Body
application/json
Example:
"prod_9Xk2mQ1pL0vRsT"
Example:
"https://acme.test/welcome"
Example:
"https://acme.test/pricing"
Fix the subscriber's cap. Omit to let them choose on the page (60 s – 30 days).
Required range:
60 <= x <= 2592000Response
The session. Hand id to <Authorize session> in your own page; there is no hosted page to send anyone to.
Example:
"cs_3fT8kLm2Qp9RxV"
Available options:
checkout.session Available options:
open, complete, expired Unix seconds; 24 h after creation.
Show child attributes
Show child attributes
Show child attributes
Show child attributes
cus_ id once the subscriber has signed in.
sub_ id once prepared; retrieve it for status.
rate × max_duration_seconds, exact decimal.