> Index of every page: https://docs.merchantservicedepot.com/llms.txt

# Subscriptions and plans

> Define what you sell on a schedule, then put customers on it.

A plan is a price and a cadence. A subscription puts one customer on one plan and charges one of their saved cards each cycle. The billing cycles run at the payment provider behind your account, not at Myela, and each cycle is a charge there.

## Before you start

You need a customer and a card saved to that customer. See [Customers and addresses](https://docs.merchantservicedepot.com/docs/payments/customers/) and [Save a card](https://docs.merchantservicedepot.com/docs/payments/save-a-card/).

Plans and subscriptions depend on what your account supports. Call `GET /v1/capabilities` first and check `subscriptions.create`. Where it reads `unsupported`, these routes won't work on that account.

## Create a plan

`POST /v1/plans` takes the price and how often to charge it. Amounts are integers in minor units, so 4900 is $49.00.

| Field | Type | Meaning |
| --- | --- | --- |
| `name` | string | Required. Your label for the plan. |
| `amount` | integer | Required. The price per cycle in minor units, greater than 0. |
| `currency` | string | Required. Three letters. Only two-decimal currencies are accepted. |
| `interval` | string | Required. day, week, month, or year. |
| `intervalCount` | integer | Optional. How many intervals between charges. Defaults to 1. |

Plans are unique by amount, currency, interval, and interval count. Create a plan that matches one you already have and you get the existing plan back with `200` instead of `201`. Its `name` may not be the one you sent, because the name isn't part of the match.

Plans can't be changed or deleted. To charge a different price, create a new plan. List them with `GET /v1/plans` and read one with `GET /v1/plans/{id}`.

## Subscribe a customer

`POST /v1/subscriptions` binds the customer, the plan, and the card. The first charge lands on `startAt`, or today if you leave it out.

**Node**

```ts title="server.ts"
const plan = await myela.gateway.plans.create({
  name: 'Pro',
  amount: 4900,
  currency: 'USD',
  interval: 'month',
});

await myela.gateway.subscriptions.create({
  customerId: customer.id,
  planId: plan.id,
  paymentMethodId: card.id,
  timezone: 'America/New_York', // decides which calendar day a charge lands on
});
```

**cURL**

```bash title="terminal"
# Create the plan
curl -X POST https://payments-api-sandbox.merchantservicedepot.com/v1/plans \
  -H "Authorization: Bearer myela_sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{ "name": "Pro", "amount": 4900, "currency": "USD", "interval": "month" }'

# Subscribe a customer to it
curl -X POST https://payments-api-sandbox.merchantservicedepot.com/v1/subscriptions \
  -H "Authorization: Bearer myela_sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{
    "customerId": "{customerId}",
    "planId": "{planId}",
    "paymentMethodId": "{paymentMethodId}",
    "timezone": "America/New_York"
  }'
```

| Field | Type | Meaning |
| --- | --- | --- |
| `customerId` | string | Required. An existing customer. |
| `planId` | string | Required. The plan to bill. |
| `paymentMethodId` | string | Required. A saved card that belongs to this customer. |
| `startAt` | YYYY-MM-DD | Optional. The first bill date. A date, not a timestamp. Defaults to today in UTC. |
| `timezone` | string | Optional. An IANA zone such as America/New_York. Decides which calendar day a charge lands on. Defaults to UTC. |

The response is the subscription, with its `status` and, while it's billing, `nextBillingAt`. If the request is refused:

| Status | When |
| --- | --- |
| `404` | The customer, plan, or card doesn't exist, or was deleted. |
| `422` | The card belongs to a different customer, or a field is invalid. |

## Cancel a subscription

Cancel takes no body and ends billing at once. The current period isn't prorated or refunded. After cancel, the subscription no longer has a `nextBillingAt`.

```bash title="terminal"
curl -X POST https://payments-api-sandbox.merchantservicedepot.com/v1/subscriptions/{id}/cancel \
  -H "Authorization: Bearer myela_sk_test_…"
```

Cancel is the only change the API makes to a subscription. There's no route to pause, resume, or update one, or to switch its card. To move a customer to another plan or card, cancel and create a new subscription. The amount is fixed by the plan. If it varies from cycle to cycle, use [recurring invoices](https://docs.merchantservicedepot.com/docs/payments/invoices/) instead.

## Status

A subscription's `status` is one of these:

| status | Means |
| --- | --- |
| `active` | Billing on schedule. A new subscription usually starts here. |
| `past_due` | Reported by the provider. The API doesn't set it, so you may only see it after the subscription is refreshed. |
| `cancelled` | You canceled it. No more charges. |
| `completed` | The provider reports billing has finished. No more charges. |

Read a subscription with `GET /v1/subscriptions/{id}`, or list them with `GET /v1/subscriptions`. What you get back is Myela's stored copy. The API doesn't refresh it from the provider; only the Myela dashboard does. So `status` and `nextBillingAt` can lag behind what the provider has done.

There are no subscription webhooks. Nothing tells you when a cycle charges or fails, so don't build on an event that won't arrive. Treat the stored status as Myela's last known view, not a live one. The events that do exist are in [Webhooks](https://docs.merchantservicedepot.com/docs/payments/webhooks/).

Source: https://docs.merchantservicedepot.com/docs/payments/subscriptions/
