Create a subscription
Start recurring billing from your server with a recurring price from your catalog and a customer's saved payment method.
Create a subscription from your server when you already have the customer's
saved payment method. The subscription bills a recurring price from your
catalog, on the price's schedule. To collect the payment method and start the
subscription in one step, use checkout with mode set
to subscription instead. This guide runs the subscription on Pay.com's
engine. To run subscriptions on another engine, see
Choose a subscription engine.
Requirements
Before you begin, make sure you have the following set up:
- A payment method saved for off-session use (
pm_card_...), with the customer it belongs to. See Save a payment method. - A product for what you sell, from
POST /v1/productsor the Commerce tab. See Products and prices. - Your API keys. The examples use the sandbox
(
https://api.sandbox.pay.com/v1) with ansk-pay-com-sandbox-key.
Set up the subscription
Create a recurring price for the product, then create a subscription that bills it to the customer's saved payment method.
- 1
Create a recurring price
A price is an amount for a product. A recurring price adds a
schedule, so it defines how much to charge, in which currency, and how often. You create it once and use it for as many customers as you need.Send a
POSTrequest to/v1/priceswith the following parameters:Parameter Description productThe product ( prod_...) the price belongs to.currencyThree-letter ISO currency code in lowercase (for example, usd).unit_amountThe amount for each period, in the smallest currency unit. For example, 1999equals $19.99 USD.scheduleObject with interval(day,week,month, oryear) andinterval_count(number of intervals between charges).tax_behaviorOptional. exclusiveadds tax tounit_amount, andinclusiveincludes it.referenceOptional. Your ID for the price, unique for its product. curl https://api.sandbox.pay.com/v1/prices \ -u ':sk-pay-com-sandbox-…' \ -H "Content-Type: application/json" \ -H "idempotency-key: $(uuidgen)" \ -d '{ "product": "prod_691180236711641088", "currency": "usd", "unit_amount": 1999, "schedule": { "interval": "month", "interval_count": 1 }, "reference": "premium-monthly" }'{ "id": "prc_691180240037724160", "resource": "price", "product": "prod_691180236711641088", "reference": "premium-monthly", "type": "recurring", "currency": "usd", "unit_amount": 1999, "schedule": { "interval": "month", "interval_count": 1 }, "tax_behavior": "exclusive", "version": 1, "active": true, "created": "2026-11-25T10:30:00.000Z", "test_mode": true }Store the
idfrom the response (prc_...). You'll use it when creating subscriptions in the next step. A later change to the amount adds a version of the price, and live subscriptions keep theirs. See Prices are kept as versions. - 2
Create the subscription
A subscription links a customer and their saved payment method to the prices it bills. Once active, Pay.com charges the customer on the prices' schedule.
Send a
POSTrequest to/v1/subscriptionswith the following parameters:Parameter Description customer_reference_idYour internal customer identifier. itemsWhat the subscription bills, each with price(prc_...) andquantity.payment_methodOptional. The saved payment method ID ( pm_card_...). Defaults to the customer's default payment method.subscription_optionsOptional. The engine, a trial, your referencefor the subscription, and how it starts. See Subscription options.curl https://api.sandbox.pay.com/v1/subscriptions \ -u ':sk-pay-com-sandbox-…' \ -H "Content-Type: application/json" \ -H "idempotency-key: $(uuidgen)" \ -d '{ "customer_reference_id": "cust-jane-doe-001", "items": [{ "price": "prc_691180240037724160", "quantity": 1 }], "payment_method": "pm_card_684790996696828928", "subscription_options": { "reference": "sub-jane-doe-premium-001" } }'{ "id": "sub_684790996696828928", "resource": "subscription", "version": 1, "status": "active", "customer_reference_id": "cust-jane-doe-001", "reference": "sub-jane-doe-premium-001", "items": [ { "id": "subitem_684790996696828930", "price": "prc_691180240037724160", "price_version": 1, "quantity": 1 } ], "currency": "usd", "current_period_start": "2026-11-25T10:30:00.000Z", "current_period_end": "2026-12-25T10:30:00.000Z", "payment_method": "pm_card_684790996696828928", "engine": { "type": "pay_com", "connection": null, "collection_model": "native" }, "created": "2026-11-25T10:30:00.000Z" }The subscription is
activeonce its first payment succeeds, or once its trial ends and the first period is paid. If the first payment is declined, the subscription isfailed, and Pay.com sendssubscription.failed. When a renewal fails, Pay.com retries it on your subscription settings'failed_paymentrules, or the price's own. See Failed renewals.
Listen for webhooks
Pay.com charges subscriptions in the background on your behalf. Subscribe to these events to keep your system in sync:
subscription.active: the subscription started, or recovered after a failed charge.subscription.charged: a renewal charge succeeded.subscription.unpaid: a renewal charge failed, and retries started.subscription.canceled: the subscription ended.cancellation_reasonindicates why.subscription.access.updated: the customer's access changed. Grant or revoke access from it.
See Commerce events for all subscription events.
Next steps
- Manage subscriptions: handle renewals, failed charges, payment method updates, and cancellations.
- Trials, plan changes, and canceling: add a trial, preview a plan change, and cancel.
- Checkout: start a subscription and collect the payment method in one step.