Skip to main content

Checkout from your server

Available on staging; production release pending. POST /v1/commerce/checkouts and GET /v1/commerce/checkouts/{id} are not in production yet.
Create the checkout from your server when you already know who is buying what and the buyer must not be able to change it: a contract signed in your own system, a renewal you priced, a seat you reserved. You send the product, the plan, the buyer’s email and your reference with your secret API key; COPE answers with a checkout_url for you to send the buyer to. Unlike a prefilled checkout, which your page creates with the publishable key, a checkout created this way is the seller’s:
  • The buyer cannot change the products, plans or quantities. Changing a line from the checkout page is refused with lines_locked.
  • The buyer cannot change the email you set. The checkout page shows it read-only. The other details you send stay the buyer’s to correct, such as a postal code.
  • Your metadata and external_reference cannot be changed from the checkout page, and arrive on the order’s webhooks as order.metadata.
  • Redirect URLs must be registered. A success_url or cancel_url that is not one of your registered redirect URLs is refused with invalid_redirect_url rather than ignored.

Create the checkout

The response is a checkout object. Send the buyer to its checkout_url. It comes only with the create response: the checkout keeps a digest of the link’s token, so retrieving the checkout later does not return it. A repeat of the create with the same Idempotency-Key within 24 hours replays the stored response, link included, so its status may be out of date and its link may already have expired: a checkout expires 30 minutes after it was created.
  • Idempotency-Key is required. A repeat with the same key answers with the same checkout.
  • Ids are COPE’s public ids. A line’s plan_id is the plan’s plan_ id from payment_plans[].uuid; an integer is refused with validation_error.
  • metadata is yours. external_reference, intended_payment_method and the keys COPE reserves for itself are refused inside it with reserved_metadata_key.
  • A member the operation does not take is refused with invalid_request (400). A checkout created from your server does not take buyer consents: the buyer gives them on the checkout page.

Confirm the order by the checkout’s id

Store the chk_ id. When the buyer has paid, GET /v1/commerce/checkouts/{id} names the order.
status reads completed whenever order is set. A checkout expires 30 minutes after you create it; create a new one for a buyer who comes back later. Match the order in payment.sale.succeeded to that order.id before you fulfil, rather than matching on external_reference: a checkout link anyone can open can carry the same reference. See the API reference for every member and error.