The Commerce API
The Commerce API owns checkout, payment links, the catalog, orders, invoices, and subscriptions, on the Pay.com API's hosts and keys.
The Commerce API runs checkout sessions and their design profiles, payment links, your catalog, orders, invoices, credit notes, Insights, and subscriptions. It's a separate API on the same hosts as the Pay.com API, and it takes the same API keys, so your workspace's keys call both and there's no Commerce account to create. Every route is in the Commerce API reference.
How the two APIs split the work
Each resource belongs to either Commerce or the Pay.com API, never both. Commerce doesn't add routes or request fields to Pay.com API resources, so every route has one owner and every object has one shape.
Both APIs share everything else:
- Base URLs:
https://api.sandbox.pay.com/v1in the sandbox andhttps://api.pay.com/v1live. - Authentication: HTTP Basic, with your secret key as the password and an empty username. See Authentication.
- Idempotency: an
idempotency-keyheader makes aPOSTsafe to retry. See Idempotency and retries. - Lists: the same
limit, cursor, andcreatedfilters, sorted by creation time, oldest first. See Pagination and filtering. - Errors: the same error envelope, with
error.type,error.code, anderror.message. The Commerce API'serror.typecan also beauthentication_error,permission_error,not_found_error, orrate_limit_error, so read the HTTP status first, as Handle errors describes. - Webhooks: Commerce's events reach your existing webhook endpoints, in the same envelope and with the same signature.
Amounts are integers in the smallest currency unit, for example 1999 for $19.99 USD. IDs start with a prefix that names the object, such as ord_691204561890402304, and timestamps are ISO 8601, in UTC. Objects created with a sandbox key have test_mode set to true.
What Commerce owns
Commerce owns these resources and every route under them:
| Resource | Routes | Reference |
|---|---|---|
| Checkout sessions | /v1/checkout, /v1/checkout/{checkout_session_id}, and its actions | Checkout sessions |
| Payment links | /v1/payment_links, /v1/payment_links/{link_id} | Payment links |
| Products | /v1/products, /v1/products/{product_id} | Products |
| Prices | /v1/prices, /v1/prices/{price_id} | Prices |
| Shipping rates | /v1/shipping_rates, /v1/shipping_rates/{shipping_rate_id} | Shipping rates |
| Orders | /v1/orders, /v1/orders/{order_id}, its refund, and its refunds | Orders |
| Invoices | /v1/invoices, /v1/invoices/{invoice_id}, and its actions | Invoices |
| Credit notes | /v1/credit_notes, /v1/credit_notes/{credit_note_id} | Credit notes |
| Commerce settings | /v1/commerce_settings | Commerce settings |
| Design profiles | /v1/design_profiles, /v1/design_profiles/{design_profile_id} and its actions, and /v1/design_profile_previews | Design profiles |
| Insights | /v1/insights | Insights |
| Subscriptions | /v1/subscriptions and every route under it | Subscriptions |
| Subscription settings | /v1/subscription_settings | Subscription settings |
| Subscription connections | /v1/subscription_connections and its actions | Subscription connections |
| Portal sessions | /v1/portal_sessions | Customer portal sessions |
| Entitlements | /v1/entitlements | Entitlements |
| Customer claims | /v1/customer_claims | Customer claims |
| Report runs | /v1/report_runs, /v1/report_runs/{report_run_id} | Report runs |
Prices replace subscription packages. A recurring price has a schedule, and a subscription bills prices the same way a checkout session's line items do. Your subscription settings hold the failed-renewal and dispute rules that subscription packages previously held. An API key's permissions set which of these resources it can call, in the Checkout, Catalog, Orders, Subscriptions, and Financial reporting groups.
What the Pay.com API keeps
The Pay.com API continues to own refunds, customers, payment sessions, setup sessions, tokenization sessions, charges, holds, tax quotes, settlements, payment method domains, and webhook endpoints.
Charges and refunds made for an order include a read-only order field linking the payment back to what was sold. It's the only field Commerce adds to them.
Refunds go through what billed them
A refund goes through the Commerce object that billed it, so orders, invoices, and credit notes stay in sync:
| What was billed | How to refund it |
|---|---|
| An order | POST /v1/orders/{order_id}/refund. Calling POST /v1/refunds for the order's charge returns 422 with use_order_refund. |
| A renewal, on an invoice Pay.com issued | POST /v1/invoices/{invoice_id}/refund. Calling POST /v1/refunds for the invoice's charge returns 422 with use_invoice_refund. |
| A renewal, on an invoice another engine issued | At that engine. When Pay.com collected the charge, the engine asks Pay.com to refund it. |
A payment your system scheduled (merchant_scheduled) | POST /v1/refunds, since Commerce has no order or invoice for it. |
The order and invoice routes refund what's left by default, or the items or lines you send, with their tax. They return the same refund object (rfnd_) as the Pay.com API, so GET /v1/refunds/{id} returns it as well. When there's an invoice to credit, Pay.com issues a credit note. This works regardless of who sells. When Pay.com is the seller, Pay.com processes the refund on its own accounts. See Orders and refunds.
Subscription options
subscription_options specifies which engine runs a subscription and what it starts with. Only Commerce routes accept it:
POST /v1/checkout, insubscriptionmode, with the items inline_items.POST /v1/payment_linksandPUT /v1/payment_links/{link_id}. The seller and engine resolve when the link is opened, and lock when the customer confirms.POST /v1/subscriptions, with the items initems.
Payment sessions, setup sessions, charges, and holds don't take subscription_options. For an external (merchant_scheduled) subscription billed by your system, collect each payment with POST /v1/subscriptions/{subscription_id}/payments.
A price's own subscription_options sets the default engine, connection, failed-payment rules, and dispute rules for subscriptions on that price, overriding your account's subscription settings. Pay.com takes the engine from the session or request, then the price, then your account default, then pay_com. When Pay.com sells, the engine is pay_com. The engine is locked when the customer confirms, and the response shows how it resolved, with the seller and processor, in subscription_options.resolved. See Choose a subscription engine.
Webhook events
Commerce events lists every event Commerce sends, grouped by the object it carries. The checkout session and subscription events Pay.com sends today keep their names under Commerce, except subscription.payment_method.upcoming_expiry, which Commerce doesn't send. Each one carries the Commerce object in data, so check the fields your listeners read. For example, a canceled subscription's cancellation_reason is requested, ended, withdrawn, payment_failed, or dispute, and a subscription has trial_end and canceled_at, not trial_period_end and ended_at. Pay.com sends subscription.upcoming_renewal when a renewal is 7 days away. Commerce also adds events, such as checkout_session.expired, subscription.created, and subscription.paused.
Earlier reference pages
The Pay.com API reference's checkout, payment links, and subscriptions pages now redirect to their Commerce pages, and the subscription package pages to prices.
Next steps
- Checkout: create a session and fulfill from its webhook.
- Orders and refunds: follow a sale from payment to refund.
- Choose a subscription engine: set the engine per session, price, or account.
- Commerce API reference: every route, with its fields and errors.