Subscriptions
Bill customers again and again on a schedule: a monthly box, a yearly membership, a weekly delivery. You make a plan (a price every month, every 3 months, every year, …); customers sign up to it; OnCharge bills each period for you. Each period is an OnCharge invoice (INV-0042) charged to the card the customer saved at your store, through an ordinary OnCharge checkout session, so its payment, fees, payout and webhooks are those of any other payment.
Customers sign up, agree to the recurring charges and manage their subscription on OnCharge's own pages: the sign-up page and their subscription page. Your customers never see another company's page.
You can do everything from the dashboard (Payments → Subscriptions: subscriptions, Plans and add-ons, Settings) or with the API below. Every request is signed like the rest of the API: see Authentication & signing.
Turning it on#
Once subscriptions are available there is nothing to switch on: create a plan. Your store needs:
- to be active (
409 store_inactiveotherwise); - card payments set up for saved cards, as for charging a saved card (
409 subscriptions_unavailableotherwise); - for a subscription you start for an existing customer, the customer's email address: OnCharge emails them the link to confirm it.
Under Payments → Subscriptions → Settings choose, per store, what happens when a customer's payments keep failing (cancel the subscription, the default, or pause it) and whether customers may pause their own subscriptions (on by default, for up to 3 periods; up to 12).
Plans and add-ons#
A plan is a price per period. An add-on is an extra billed with a plan, in the same periods (a second bag, a gift wrap): it has no interval, trial or intro price of its own.
POST /api/v1/plans
Idempotency-Key: plan-monthly-box{
"name": "Monthly box",
"description": "A box of our best sellers, every month.",
"amount": 3000,
"currency": "USD",
"interval": "month",
"interval_count": 1,
"trial_days": 14,
"intro": { "amount": 1500, "periods": 2 },
"requires_shipping": true
}{
"id": "c1d2e3f4-a5b6-4c7d-8e9f-0a1b2c3d4e5f",
"object": "plan",
"name": "Monthly box",
"amount": 3000,
"currency": "USD",
"interval": "month",
"interval_count": 1,
"interval_text": "month",
"trial_days": 14,
"intro": { "amount": 1500, "periods": 2 },
"requires_shipping": true,
"active": true,
"metadata": {},
"created_at": "2026-12-01T00:00:00.000Z"
}| Field | What it does |
|---|---|
kind | plan (default) or addon. |
name, description | What the customer sees on the sign-up page, their emails and invoices. |
amount, currency | The price per period, per unit, in minor units (cents). Default currency USD. Add-ons must be in their plan's currency. |
interval, interval_count | day, week, month or year, times interval_count (default 1). A period is at most a year: up to 365 days, 52 weeks, 12 months or 1 year. Plans only, and required for them. |
trial_days | A free trial: 0 (none) or 7 to 365 days. The customer signs up and saves a card; the first charge is when the trial ends, and they are reminded 7 days before. A shorter trial is refused (400 invalid_request), so the reminder the card networks require always fits. |
intro | A lower price for the first periods: { "amount": 1500, "periods": 2 } charges 15.00 for the first two periods, then amount. Lower than amount, for 1 to 24 periods. |
requires_shipping | Each period is a shipped order: the subscription needs a shipping address, and each period is paid out after carrier-confirmed delivery. On a store set up as shipping physical goods, every period ships whatever this says. |
metadata | Up to 20 of your own keys. |
A subscription has a quantity (1 to 1000, default 1): the plan's price is multiplied by it. Add-ons have their own quantities.
A plan's price and terms never change once it is created. Customers agreed to them. To charge a different price, create another plan and move subscriptions to it with change: a higher price applies only after the customer is given notice (below). You can rename a plan, change its description or metadata, or archive it:
PATCH /api/v1/plans/{id}
{ "active": false }An archived plan takes no new subscriptions; those already on it go on. GET /api/v1/plans lists active plans and add-ons (?include_archived=true for all), newest first; GET /api/v1/plans/{id} returns one.
Start a subscription#
Nothing is charged until the customer agrees to the recurring charges on OnCharge's sign-up page (below). You never put a card on a subscription yourself. There are three ways to bring a customer to that page.
1. For an existing customer: OnCharge emails them#
POST /api/v1/subscriptions
Idempotency-Key: sub-ada-box{
"customer_id": "9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d",
"plan_id": "c1d2e3f4-a5b6-4c7d-8e9f-0a1b2c3d4e5f",
"quantity": 1,
"addons": [{ "plan_id": "d2e3f4a5-b6c7-4d8e-9f0a-1b2c3d4e5f6a", "quantity": 1 }],
"shipping": { "name": "Ada Lovelace", "line1": "1 Main St", "city": "Austin", "state": "TX", "postal_code": "78701", "country": "US" }
}The subscription is created as incomplete and OnCharge emails the customer a link to its sign-up page. The page may offer the cards they already saved at your store. The link is never returned to you: only the cardholder can choose a card for the subscription. It works for 7 days (sign_up_expires_at); after that the subscription is incomplete_expired. The customer needs an email address (409 customer_email_required).
2. A hosted sign-up page you send the customer to#
POST /api/v1/subscriptions/checkout
Idempotency-Key: signup-ada{
"plan_id": "c1d2e3f4-a5b6-4c7d-8e9f-0a1b2c3d4e5f",
"customer_email": "ada@example.com",
"customer_name": "Ada Lovelace",
"shipping": { "name": "Ada Lovelace", "line1": "1 Main St", "city": "Austin", "state": "TX", "postal_code": "78701", "country": "US" },
"success_url": "https://shop.example.com/welcome"
}{
"id": "7e2f9a1c-3b4d-4e5f-8a6b-9c0d1e2f3a4b",
"object": "subscription",
"status": "incomplete",
"status_text": "Waiting for customer",
"plan": { "id": "c1d2e3f4-a5b6-4c7d-8e9f-0a1b2c3d4e5f", "name": "Monthly box", "amount": 3000, "currency": "USD", "interval": "month", "interval_count": 1 },
"payment_method": null,
"source": "checkout",
"sign_up_expires_at": "2026-12-02T00:00:00.000Z",
"url": "https://app.oncharge.io/s/subscribe/7e2f9a1c-3b4d-4e5f-8a6b-9c0d1e2f3a4b?token=ocs_…"
}Send the customer to url (it works for 24 hours). They enter a new card there; this page never offers saved cards, because you hold the link. Give customer_id for an existing customer, or customer_email (the customer is found by email, or added to your store). success_url (https) is where they go after signing up; it is kept in the subscription's metadata.
3. A payment link for a plan#
POST /api/v1/plans/{id}/payment-link
{ "title": "Join the Monthly box" }{ "id": "5f0c9d4e-2a1b-4c3d-9e8f-7a6b5c4d3e2f", "code": "k7Hq2mNpR4sT", "url": "https://app.oncharge.io/l/k7Hq2mNpR4sT", "plan_id": "c1d2e3f4-a5b6-4c7d-8e9f-0a1b2c3d4e5f" }Share the link anywhere. A shopper who opens it enters their email (and shipping address if the plan ships) and continues to the sign-up page with a new card. It is one of your payment links: it appears with them, and you turn it off the same way.
Each way: a repeat with the same Idempotency-Key returns the first subscription (200); the same key for another customer or plan is refused (409 idempotency_conflict). A subscription that ships needs shipping (422 shipping_address_required).
Recurring consent#
On the sign-up page the customer reads the terms before anything else: the price and how often, any intro price and for how many payments, the trial and the date of the first charge, shipping, and how to cancel. They choose a saved card or enter a new one (a new card records the save-card consent and is saved before anything is charged). With the card known, the page shows the recurring-charge disclosure naming it (for example "Card to be charged: Visa ending 4242."), and they tick a box to agree to the recurring charges on that card.
Each consent is recorded with the version of the words and the SHA-256 of exactly what was shown (your store's name, the terms and the card's brand and last four digits included), with the time, IP address and browser. If the terms changed while the page was open, or the customer picks another card, they are asked to agree again. A customer whose first card is declined agrees again on the next one. No charge is made for a subscription without its consent.
Then the subscription starts: a trial starts at once; otherwise the first period is charged and the subscription starts when it is paid. If the customer's bank asks them to confirm the payment, the page sends them to OnCharge's confirmation page. The customer gets a confirmation email naming the card charged, with a link to their subscription page.
When the customer cancels, their consent is withdrawn: nothing is charged for that subscription again.
Statuses#
status | What it means |
|---|---|
incomplete | Waiting for the customer to sign up (sign_up_expires_at). |
incomplete_expired | They did not sign up in time. Nothing was charged. |
trialing | In its free trial (trial_end). Nothing charged yet. |
active | Paid up. Charged again at next_billing_at. |
past_due | A payment failed and is being retried (failed payments). |
paused | Nothing is charged or shipped until it resumes (pause.resume_at, or when you or the customer resume it). |
canceled | Ended (ended_at, cancel_reason: merchant, customer, api, dunning, store_closed or reminder_undeliverable). Nothing more is charged. |
A subscription also says what is waiting for the end of the period: cancel_at_period_end, pause.at_period_end and pending_change.
Billing and proration#
Periods. Periods are counted from the day the subscription started, never from the previous period's end: a subscription started on January 31 is billed on February 28, March 31, April 30, and so on. A trial's end starts the first period; resuming after a pause, or moving to a plan with another interval, starts the count again.
Each period's bill. At the start of each period OnCharge opens a bill (a SubscriptionBilling): its lines (the plan at its intro or regular price, times quantity, then each add-on), minus any credit from earlier downgrades. The bill has its own OnCharge invoice, listed with your invoices, and is charged to the subscription's card through a checkout session whose order_id and reference are the invoice number. That payment fires the usual payment.* webhooks with data.invoice_id, then subscription.period.paid.
Reminders. Each reminder counts as sent only once the email service accepted it, as of that moment; one that did not go is tried again on the next run (with the same idempotency key, so a retry never sends it twice). The customer is emailed:
- 7 days before the first charge after a trial (a 7-day trial: as it starts), whatever plan the subscription is on by then, with the date and amount of that charge. The first charge never comes before this reminder went at least 7 days ahead, nor before the date it named:
- sent late, it names a date 7 days and an hour away, and the first charge moves to that date;
- not sent yet when the trial ends, the charge is held (nothing is charged or moved) and the reminder is tried again after a growing wait (10 minutes up to 6 hours); if it still could not be emailed 72 hours after it first failed, the subscription ends without being charged (
cancel_reason: "reminder_undeliverable") and you are told; - a trial paused at its end is reminded 7 days before it resumes; resumed early (by you, the API or the customer), it is not charged at once: the reminder goes then, and the first charge comes 7 days (and an hour) later;
- 14 days before an introductory price ends, when the intro offer lasts more than 31 days, with the regular price from then and the card;
- 30 days before each renewal of a plan billed every year (
interval: "year"); - before a price increase you make (below).
Change the plan, quantity or add-ons#
POST /api/v1/subscriptions/{id}/change
{ "plan_id": "…", "quantity": 2 }- A change that raises the price waits for the customer's notice: see price increases. It is never applied at once (
"proration": "now"is refused with409 price_increase_needs_notice), and a change applied now never charges more for the current period. - Any other change applies at once by default (
"proration": "now"). The rest of the current period is prorated: the difference between the old and the new price per period, for the time left (to the second), rounded half up to the minor unit, is a credit (credit_balance) taken off the next bills; the answer'sprorationsays how much. "proration": "next_period"applies it at the renewal; until then it shows aspending_change.- A shipped subscription changes at the next period only (each charge is one shipped period's order), and so does a move to a plan with another interval: ask for
nowand you get409 change_at_next_period. A paused subscription always changes at the next period. A trialing one changes at once with nothing to prorate. - A new plan ends any intro price left.
addonsreplaces every add-on ([]removes them). The new plan must be in the same currency.
The customer is emailed the new price and when it applies.
Price increases#
A change that makes the customer pay more is scheduled, never applied at once. It pays more when either a charge gets bigger or the price per day rises: another plan, more units, more add-ons, a plan without the intro price they still had, or another interval ($30 a month to $10 a week costs more per day; $30 a month to $300 a year is a bigger charge; both need the notice):
- It waits in
pending_change, withincrease: the price before and after (each with its period,from_everyandto_every), and the period it applies from (effective_at): the first period that starts at least 7 days from now on the subscription's real schedule. For a paused subscription that is the day it resumes; with no resume date it has no date yet (null). - The customer is emailed a notice 7 to 30 days before
effective_at: at once when it is 30 days away or nearer, otherwise 30 days before. It names the new price, the date and the card, and how to cancel online before then.increase.notice_sent_atis set only once the email service accepted it; one that did not go is tried again. A notice belongs to one change and one date (pending_change.change_id,increase.version): a newer change, or a new date, is always told again. - The new price is charged only for the period starting
effective_at, when the notice went 7 to 30 days before. If the notice could not go out in time, or the schedule moved (a pause, an earlier resumption), the increase moves on to the next period far enough ahead and the customer is told the new date.
subscription.updated arrives with change: "change_scheduled" when you make it, and change: "price_increase_notice" when the customer is told. A change that lowers the price needs no notice.
Failed payments#
When a period's charge fails, the subscription becomes past_due and OnCharge works to collect it:
- Retries 1, 3, 7 and 14 days after the first failure.
- Failures a retry cannot fix wait for the customer. If the bank wants the customer to confirm the payment, OnCharge emails them a link to confirm it. If the card can no longer be used (expired, wrong details, not supported, refused as suspected fraud), they are asked to add another card. Neither is retried blindly.
failure.waits_for_customersays so, andnext_attempt_atis null. - The customer is emailed after each failure, with a link to their subscription page (to change the card) and to the period's invoice page (to pay it another way). A card they save there is charged at once.
- You are told in the dashboard at the first failure and when collecting ends, and by
subscription.period.payment_failed(each failed attempt) andsubscription.past_duewebhooks. - When it ends. 14 days after the first failure, with nothing left to try, the bill is given up (
status: "uncollectible", its invoice voided) and the subscription is cancelled (cancel_reason: "dunning"), or paused if your Settings say so.
Paid in the meantime (a retry, the customer's new card, the invoice page), the subscription is active again and subscription.updated arrives with change: "payment_recovered". You can also charge it now with POST /api/v1/subscriptions/{id}/retry, or ask the customer to switch to another of their saved cards with PATCH /api/v1/subscriptions/{id} and payment_method_id (below). A sign-up's first charge is not retried: the customer is on the page and can use another card.
Change the card#
Only the customer changes the card a subscription is charged to: it is the card they agreed to. With PATCH /api/v1/subscriptions/{id} and payment_method_id (another of their saved cards at your store) OnCharge emails the customer a link to switch to that card on their subscription page, naming it (for example "Visa ending 5555"), and answers 202 with card_change: { "status": "customer_asked" }. You can ask once an hour per subscription (429 too_many_requests otherwise). If the email cannot be sent, nothing in the request is saved (502 customer_not_emailed).
The subscription keeps its card, and nothing is charged to the other one, until the customer switches. On their page they agree to the charges on the new card (the disclosure names it), which is recorded as a new consent; a past-due subscription is then charged to it at once.
Pause, resume and cancel#
| Request | What it does |
|---|---|
POST /api/v1/subscriptions/{id}/pause { "periods": 2 } | Pauses from the end of the current period (nothing already paid is lost): for periods periods (1 to 12), until resume_at, or, with neither, until resumed. While paused nothing is charged or shipped. Only an active or trialing subscription; a past-due one must be paid first (409 payment_required). |
POST /api/v1/subscriptions/{id}/resume | A paused subscription starts again now: a new period begins and is charged at once. On a subscription with a pause or a cancellation waiting for the period's end, calls it off. A cancellation the customer asked for is theirs: only they can subscribe again (409 canceled_by_customer). |
POST /api/v1/subscriptions/{id}/cancel | By default (at_period_end: true) an active or trialing subscription ends when its current period or trial ends: no more charges, and it is canceled then. { "at_period_end": false }, or any other status, ends it now; anything unpaid is voided. |
The customer is emailed when their subscription is paused, cancelled or ends.
The customer's subscription page#
Customers manage their subscriptions at your store on an OnCharge page, reached only by a link emailed to them: every subscription email carries one, and it works for 24 hours. To get a fresh link, a customer enters their email at https://app.oncharge.io/s/manage?store=<your store id>; if they have a subscription at your store, OnCharge emails them one. On the page they can:
- change the card: one of their cards saved at your store, or a new one (a past-due subscription is charged at once);
- cancel at the end of the current period;
- pause and resume, if your Settings allow it, for up to the number of periods you chose.
Delivery-gated payouts#
Subscriptions keep OnCharge's payout rule: a shipped order is paid out only after the carrier confirms delivery. Each shipped period is its own order: its checkout session carries the subscription's shipping address and the period's lines, and its payout waits for delivery like any other order (Shipments & payouts). A period that does not ship is paid out like any digital order.
So when a period ships, report its tracking number with that period's session: data.session_id of its subscription.period.paid (or payment.captured) webhook, or the period's invoice number as order_id:
{ "session_id": "8f14e45f-ceea-467a-9575-2c3b8e1f0b6d", "shipments": [{ "carrier": "usps", "tracking_number": "9400111899223344556677" }] }The shipping address belongs to the subscription: change it with PATCH /api/v1/subscriptions/{id} and shipping, and the next periods ship there.
Webhooks#
Subscription events arrive at your webhook endpoints like every other event, signed the same way, alongside the payment.* events of each period's payment. Choose them (or the whole subscription.* group) for an endpoint on the Webhooks page of the portal.
type | When |
|---|---|
subscription.created | A customer agreed and the subscription started: its trial began, or its first period was paid. |
subscription.updated | The plan, quantity, card, or a waiting cancellation or pause changed. data.change: plan_changed (with prorated_charge, prorated_credit), change_scheduled (with pending_change), price_increase_notice (the customer was emailed the notice of a price increase, with price_increase), change_applied, payment_method, cancel_scheduled, pause_scheduled, kept (a waiting cancellation or pause was called off), trial_ended or payment_recovered. |
subscription.trial_will_end | A trial ends soon; the customer was reminded. Once per trial. |
subscription.past_due | A period's payment failed; OnCharge is retrying it. |
subscription.paused | It paused: nothing is charged or shipped until it resumes. |
subscription.resumed | A paused subscription started again; a new period began and was charged. |
subscription.canceled | It ended: cancelled by you or the customer, or after its payment failed on every retry. |
subscription.period.paid | A period (or a plan change) was paid. If it ships, ship it and report the tracking with data.session_id. |
subscription.period.payment_failed | A charge for a period failed. data.failure says why and data.next_attempt_at when it is tried again (null: it waits for the customer). |
subscription.* events carry the subscription:
{
"id": "evt_5f0c2a8e-1b7d-4c39-9e64-2d8f1a7b3c90",
"type": "subscription.canceled",
"created": 1767225600,
"livemode": true,
"data": {
"subscription_id": "7e2f9a1c-3b4d-4e5f-8a6b-9c0d1e2f3a4b",
"customer_id": "9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d",
"status": "canceled",
"plan_id": "c1d2e3f4-a5b6-4c7d-8e9f-0a1b2c3d4e5f",
"plan_name": "Monthly box",
"amount": 3000,
"currency": "USD",
"interval": "month",
"interval_count": 1,
"quantity": 1,
"trial_end": null,
"current_period_start": "2026-12-01T00:00:00.000Z",
"current_period_end": "2027-01-01T00:00:00.000Z",
"cancel_at_period_end": false,
"canceled_at": "2026-12-20T00:00:00.000Z",
"cancel_reason": "customer",
"paused_at": null,
"resume_at": null,
"rail": "card"
}
}subscription.period.* events carry one bill and its payment:
{
"id": "evt_5f0c2a8e-1b7d-4c39-9e64-2d8f1a7b3c90",
"type": "subscription.period.paid",
"created": 1767225600,
"livemode": true,
"data": {
"subscription_id": "7e2f9a1c-3b4d-4e5f-8a6b-9c0d1e2f3a4b",
"billing_id": "2b3c4d5e-6f7a-4b8c-9d0e-1f2a3b4c5d6e",
"reason": "period",
"period_index": 1,
"period_start": "2027-01-01T00:00:00.000Z",
"period_end": "2027-02-01T00:00:00.000Z",
"amount": 3000,
"currency": "USD",
"invoice_id": "4d5e6f7a-8b9c-4d0e-8f1a-2b3c4d5e6f7a",
"invoice_number": "INV-0042",
"session_id": "8f14e45f-ceea-467a-9575-2c3b8e1f0b6d",
"payment_reference": "ocpay_8f14e45fceea467a95752c3b8e1f0b6d",
"attempt": 1,
"ships": true,
"failure": null,
"next_attempt_at": null,
"status": "paid",
"rail": "card"
}
}On subscription.period.payment_failed, status is failed, session_id and payment_reference may be null, and failure is { "reason", "message" } with reason one of declined, authentication_required, unusable_card, error or store_unavailable. Each event is sent once per change; acknowledge (2xx) any type you do not handle.
Endpoints#
| Request | What it does |
|---|---|
GET /api/v1/plans | Plans and add-ons, newest first (include_archived=true for archived ones too): { data }. |
POST /api/v1/plans | Create a plan or add-on. Idempotency-Key honoured. |
GET /api/v1/plans/{id} | One plan. |
PATCH /api/v1/plans/{id} | Rename, describe, archive (active: false) or change its metadata. |
POST /api/v1/plans/{id}/payment-link | A payment link that signs shoppers up to the plan. |
GET /api/v1/subscriptions | Subscriptions, newest first: { data, has_more }. Filter with status and customer_id; page with limit (up to 100, default 25) and starting_after (the last id of the previous page). |
POST /api/v1/subscriptions | Start one for an existing customer (OnCharge emails them). Idempotency-Key honoured. |
POST /api/v1/subscriptions/checkout | Start one with a hosted sign-up page (url). Idempotency-Key honoured. |
GET /api/v1/subscriptions/{id} | The subscription with every bill (billings: lines, invoice, attempts, failure, payment_reference) and its history. |
PATCH /api/v1/subscriptions/{id} | Change the shipping address or the metadata (replaced), or ask the customer to switch to another of their saved cards (payment_method_id). |
POST /api/v1/subscriptions/{id}/change | Change the plan, quantity or add-ons. |
POST /api/v1/subscriptions/{id}/pause | Pause from the end of the period. |
POST /api/v1/subscriptions/{id}/resume | Resume, or call off a waiting pause or cancellation. |
POST /api/v1/subscriptions/{id}/cancel | Cancel at the end of the period (default) or now. |
POST /api/v1/subscriptions/{id}/retry | Charge a past-due subscription now. |
PATCH requests are signed like any other, with PATCH as the method and the JSON body. Every field and answer is in the API reference.
With curl#
With the oncharge helper from Authentication & signing:
oncharge POST /api/v1/plans '{"name":"Monthly box","amount":3000,"currency":"USD","interval":"month","trial_days":14}'
oncharge POST /api/v1/subscriptions/checkout '{"plan_id":"c1d2e3f4-a5b6-4c7d-8e9f-0a1b2c3d4e5f","customer_email":"ada@example.com"}'
oncharge GET "/api/v1/subscriptions?status=past_due&limit=50"
oncharge PATCH /api/v1/subscriptions/7e2f9a1c-3b4d-4e5f-8a6b-9c0d1e2f3a4b '{"payment_method_id":"5b6c7d8e-9f0a-4b1c-8d2e-3f4a5b6c7d8e"}'
oncharge POST /api/v1/subscriptions/7e2f9a1c-3b4d-4e5f-8a6b-9c0d1e2f3a4b/cancel '{"at_period_end":true}'To send an Idempotency-Key, add -H "Idempotency-Key: …" to the helper's curl arguments.
With the SDK#
import { OnCharge } from '@oncharge/node';
const oncharge = new OnCharge({ apiKey: process.env.ONCHARGE_API_KEY!, apiSecret: process.env.ONCHARGE_API_SECRET! });
const plan = await oncharge.plans.create(
{ name: 'Monthly box', amount: 3000, currency: 'USD', interval: 'month', trial_days: 14, requires_shipping: true },
{ idempotencyKey: 'plan-monthly-box' },
);
const signup = await oncharge.subscriptions.checkout(
{ plan_id: plan.id, customer_email: 'ada@example.com', shipping: { name: 'Ada Lovelace', line1: '1 Main St', city: 'Austin', state: 'TX', postal_code: '78701', country: 'US' } },
{ idempotencyKey: 'signup-ada' },
);
// signup.status → 'incomplete'; send the customer to signup.url
const sub = await oncharge.subscriptions.retrieve(signup.id); // with billings and history
await oncharge.subscriptions.change(sub.id, { quantity: 2, proration: 'next_period' });
await oncharge.subscriptions.pause(sub.id, { periods: 1 });
await oncharge.subscriptions.resume(sub.id);
await oncharge.subscriptions.cancel(sub.id); // at the end of the period
const link = await oncharge.plans.createPaymentLink(plan.id); // link.url signs shoppers upOnCharge.webhooks.constructEvent types every subscription event: switch on event.type and event.data has its shape. See SDKs.
Errors#
Errors are { "error": "<code>", "message": "<text>" }. Besides the errors every endpoint can return:
| Status | error | Meaning |
|---|---|---|
| 400 | invalid_request, invalid_json | The body is not valid; the message names the first invalid field (a trial of 1 to 6 days, an intro price not lower than the price, an add-on listed twice or in another currency, both periods and resume_at, …). |
| 400 | invalid_idempotency_key | The Idempotency-Key is longer than 255 characters or has control characters. |
| 400 | currency_mismatch | A plan change to a plan in another currency. |
| 404 | not_found | No such subscription in your store, or subscriptions are not available yet. |
| 404 | plan_not_found, addon_not_found, customer_not_found, payment_method_not_found | No such plan, add-on, customer or active saved card of the customer in your store. |
| 409 | plan_inactive | The plan or an add-on is archived. |
| 409 | store_inactive, subscriptions_unavailable | The store is not taking payments, or has no card payments set up for saved cards. |
| 409 | customer_email_required | The customer has no email address to send the sign-up link to, or to ask them to switch cards. |
| 409 | idempotency_conflict | The Idempotency-Key was used for another customer or plan. |
| 409 | subscription_ended, not_started | It has ended; or it has not started, so the customer chooses the card. |
| 409 | not_pausable, payment_required, cancel_scheduled | Only an active or trialing subscription pauses; a past-due one must be paid first; one ending at the period's end cannot pause. |
| 409 | not_paused, canceled_by_customer | Nothing to resume; the customer cancelled it themselves. |
| 409 | not_changeable, change_at_next_period | It cannot change now (past due, ended or not started); or the change must wait for the next period (proration: "next_period"). |
| 409 | price_increase_needs_notice | The change raises the price, so it cannot apply now: leave proration out (or send "next_period") to schedule it with the customer's notice. |
| 429 | too_many_requests | You asked this customer to switch cards less than an hour ago. |
| 502 | customer_not_emailed | The email asking the customer to switch cards could not be sent; nothing in the request was saved: try again. |
| 409 | trial_too_short | The plan's trial is shorter than 7 days (a plan made before the minimum): it takes no new subscriptions and cannot be taken out of the archive. |
| 409 | not_past_due | Only a past-due subscription is retried. |
| 409 | payment_in_progress, conflict | A payment for it is being collected, or it changed meanwhile: try again in a minute. |
| 422 | shipping_address_required | The subscription ships each period: send shipping. |