Checkout from your server
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 acheckout_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
metadataandexternal_referencecannot be changed from the checkout page, and arrive on the order’s webhooks (see reading it back). The checkout carries no marketing attribution. - Redirect URLs must be registered. A
success_urlorcancel_urlthat is not one of your registered redirect URLs is refused withinvalid_redirect_urlrather than ignored.
Create the checkout
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-Keyis required. A repeat with the same key answers with the same checkout.- Ids are COPE’s public ids. A line’s
plan_idis the plan’splan_id frompayment_plans[].uuid; an integer is refused withvalidation_error. metadatais yours, within the metadata limits. Send your identifier asexternal_reference, never insidemetadata: a reserved key insidemetadatais refused with422 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 thechk_ 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 match the order by its ID).
See the API reference for every member and error.