palbaseDocs

Palbase IAP · API

POST/iap/checkout

Buy on the web

Opens a Stripe Checkout session to buy one of the catalog's products sold on the web, at the plan's price on the project's Stripe account: send the buyer to url. Stripe sends them back to success_url or cancel_url, which go back to one of the project's registered apps — a web app's origin, or a native app's own scheme — and nowhere else. With a customer's session — a guest's as well: what a guest buys is theirs, and goes with them to the account they sign in to — the purchase is that customer's; a customer who already has the product, or a subscription of its group, from any store is refused (409 already_entitled, naming the store to manage it in): nothing is charged twice. Credits can always be bought again. A free trial is given once per customer, across every channel, and not to a guest: a new one is free to make. With the project's secret key and customer_id, the checkout is for the customer the server names — a team or a company buying seats, a user it acts for — and the purchase is theirs at once. A plan sold by the seat (its max_quantity) takes quantity: the plan's price is one seat's, and a customer who already has the subscription is refused with its payments_subscription_id, by which its quantity is changed. With the app's key alone (no session), or the secret key naming no customer, the buyer is no one yet: Checkout asks their email, no free trial is given, and what they buy waits for the app user who redeems it — its link is shown on the success page to the holder of redemption_key (POST /iap/stripe/checkout/redemption) and sent to that email. Checkouts are limited per address and per project with the app's key alone, per customer and per address with a session (429 too_many_checkouts). source records where the checkout was opened: an app linking out to buy on the web (the App Store's United States storefront allows it, Guideline 3.1.1(a)) says its platform and storefront, and the charts take the App Store's link fee (settings) off what it brings. The checkout is kept as the record of it. The purchase is applied once Stripe reports it (POST /iap/webhooks/stripe).

Called by your app, with the publishable key; or a signed-in user of your app, with their token and the publishable key; or your server, with the project's secret key.

Request body

cancel_urlstring · requiredWhere Stripe sends the customer back when they do not pay; the same rule.
channelstring · optionalOptional explicit payment channel override in the payments module.
currencystring · optionalOptional ISO 4217 currency override from the plan's web price overrides.
customer_idstring · optionalThe customer the checkout is for, named by the project's server (its secret key) — a team, a company, a user it acts for: the purchase is theirs at once, with nothing to redeem. They become a customer if they were not one. Refused with any other credential (403 `customer_id_not_allowed`): a signed-in customer buys for themselves.
offerstring · optionalOne of the catalog's offers the customer may take, on this plan: its coupon (or the promotion code of the coupon code that opened it), or its free trial, on the checkout.
planstring · requiredIts plan.
productstring · requiredThe catalog's product (sold on the web).
quantityinteger · optionalHow many seats of the plan to buy: 1 when absent, at most the plan's `max_quantity` (`invalid_quantity`). The plan's price is one seat's; the subscription is charged that times the seats, each period. More or fewer seats of a subscription the customer already has are a change of its quantity (POST /payments/subscriptions/{id}/quantity), not another checkout.
sourceobject · optionalWhere a checkout was opened: an app linking out to buy on the web says its platform and its store's storefront. Kept with the checkout as the record of the link.
success_urlstring · requiredWhere Stripe sends the buyer back once paid: a registered web app's origin, or a native app's own scheme. Stripe replaces `{CHECKOUT_SESSION_ID}` in it with the session's id: the page asks the redemption link with it.
curl
curl -X POST "https://<your-ref>.palbase.studio/iap/checkout" \
  -H "apikey: $PALBASE_SECRET_KEY" \
  -H "content-type: application/json" \
  -d '{"cancel_url":"string","plan":"string","product":"string","success_url":"string"}'

Responses

201The session

400`success_url` or `cancel_url` goes elsewhere than the project's apps (`return_url_not_allowed`), `source` is not a platform and storefront (`invalid_source`), `quantity` is not 1 to the plan's `max_quantity` (`invalid_quantity`), `customer_id` is longer than 128 characters (`invalid_customer_id`), or the body is not the request

401No key of the project (`key_required`); or the edge refused the key or token

403The offer is not the buyer's to take on this plan (`offer_not_open`): it ended or has not started, it was taken, it is for an audience they are not in, it is on another plan — or the buyer has no session: an offer is a customer's, once; or `customer_id` was given with a credential other than the project's secret key (`customer_id_not_allowed`)

404The catalog sells no such product and plan on the web (`product_not_on_sale`), or the user's id is longer than a customer's (`customer_not_found`)

409The customer already has it (`already_entitled`, with the store and product); or the payments module refused it, its code and words passed on as it answered them — `managed_payments_needs_key`: web_tax is managed and the channel web checkouts go to cannot sell with Stripe's Managed Payments (the Stripe App's, or one not Stripe's): connect the account with a restricted key (palbase payments:stripe:grant), or set web_tax to none

410The user was deleted (`customer_erased`): their id is no customer's again

413The request body is too large (`request_too_large`)

422The payments module refused it, its code and words passed on as it answered them: `discount_not_supported` or `quantity_not_supported` (the channel's provider sells no offer's discount, or no subscription by the seat), or the provider's refusal of the checkout. A project with no payment channel the checkout can go to is answered `412 no_payment_channel`

429Too many checkouts opened with the app's key alone, from this address or in the project (`too_many_checkouts`); retrying is safe after Retry-After

502Stripe could not be reached (`stripe_unreachable`); retrying is safe after Retry-After

503Another change to this customer is in progress (`customer_busy`), or the platform could not answer now; retrying is safe after Retry-After

defaultAn error: the envelope names it (`error`) and explains it (`error_description`).

Operation CreateCheckout of iap's contract.