Skip to Content
Docs

Manage subscriptions

List and retrieve subscriptions, handle failed charges, update payment methods, and cancel subscriptions with the Commerce API.

Once a subscription is active, Pay.com handles billing automatically. From your server, you can still find a customer's subscriptions, read their state, respond to failed charges, update the payment method, and cancel. Customers can make the same changes themselves in the customer portal.

Requirements

Before you can manage subscriptions, you need:

List a customer's subscriptions

Send a GET request to /v1/subscriptions with customer_reference_id to find every subscription a customer has, from both sellers and every engine. Filter by status, and page through the results with limit and starting_after.

curl -G https://api.sandbox.pay.com/v1/subscriptions \
  -u ':sk-pay-com-sandbox-…' \
  -d customer_reference_id=cust-jane-doe-001

Retrieve a subscription

Send a GET request to /v1/subscriptions/{subscription_id} to get the current state of a subscription:

curl https://api.sandbox.pay.com/v1/subscriptions/sub_684790996696828928 \
  -u ':sk-pay-com-sandbox-…'

The status field reflects the current billing state. See Subscription statuses for each status and what causes each transition.

Handle a failed charge

When a renewal fails, the subscription moves to unpaid and Pay.com retries it on the failed_payment rules in your subscription settings, or the price's own. Each attempt fires a subscription.attempted event. Once the retries are used up, Pay.com applies final_action. With cancel, the subscription ends with cancellation_reason set to payment_failed and fires subscription.canceled. With pause, billing is suspended and the subscription moves to paused. With leave_unpaid, it stays unpaid. See Failed renewals.

You can also retry the renewal yourself. Send a POST request to /v1/subscriptions/{subscription_id}/retry with no body. It charges the payment method on the subscription, so to use another card, update the payment method first. The retry takes only unpaid subscriptions on Pay.com's engine. Other engines retry on their own, so the request returns 422 with not_collector.

curl -X POST https://api.sandbox.pay.com/v1/subscriptions/sub_684790996696828928/retry \
  -u ':sk-pay-com-sandbox-…' \
  -H "idempotency-key: $(uuidgen)"

A successful retry returns status: active. A failed retry returns status: unpaid. Subscribe to these events to automate retry and recovery logic:

  • subscription.attempted: fires for each renewal attempt.
  • subscription.active: fires when a retry succeeds and the subscription recovers.

Update a payment method

To replace the billing card on an active subscription, send a PATCH request to /v1/subscriptions/{subscription_id} with the new payment method ID. The card must already be saved for off-session use. See save a payment method.

curl -X PATCH https://api.sandbox.pay.com/v1/subscriptions/sub_684790996696828928 \
  -u ':sk-pay-com-sandbox-…' \
  -H "Content-Type: application/json" \
  -d '{ "payment_method": "pm_card_685125114794084354" }'

Change the plan or quantity

To move a subscription to another price or quantity, preview the change with POST /v1/subscriptions/{subscription_id}/previews, then apply the preview with PATCH /v1/subscriptions/{subscription_id}. See Plan changes.

Cancel a subscription

Canceling a subscription stops future billing without immediately ending access. Send a POST request to /v1/subscriptions/{subscription_id}/cancel. You can cancel at the end of the current billing period or on any later date.

Send an empty body. The subscription stays active until the current period ends, then Pay.com cancels it automatically.

curl https://api.sandbox.pay.com/v1/subscriptions/sub_684790996696828928/cancel \
  -u ':sk-pay-com-sandbox-…' \
  -H "Content-Type: application/json" \
  -H "idempotency-key: $(uuidgen)" \
  -d '{}'

In both cases the subscription doesn't end immediately, and the customer keeps access until it does. The canceled_at field is set when the cancellation takes effect. The cancellation_reason field records why it ended (requested when you or the customer canceled it, ended when it reached its cancel_at date, withdrawn when the customer withdrew from the contract, payment_failed when retries were used up, or dispute after a dispute action).

Test a renewal in the sandbox

You don't have to wait for a billing date to test a renewal. In the sandbox, send a POST request to /v1/subscriptions/{subscription_id}/simulate/charge to run the next renewal immediately without waiting for the scheduled billing date. The request returns the subscription after the renewal, and Pay.com sends the renewal's subscription events, such as subscription.charged. Live keys return 403.

curl -X POST https://api.sandbox.pay.com/v1/subscriptions/sub_684790996696828928/simulate/charge \
  -u ':sk-pay-com-sandbox-…' \
  -H "idempotency-key: $(uuidgen)"

Next steps

Was this page helpful?