Subscriptions
API ReferenceSubscriptionsCancel Subscription
Cancel Subscription
End a subscription, either now or when the period the customer paid for ends.
POST /subscriptions/:subscription_id/cancel
cancel_option | What happens |
|---|---|
immediately (default) | The subscription is cancelled now and nothing more is charged. You receive subscription_cancelled. |
end_of_term | The subscription stays active until the current period ends, then it is cancelled without charging again. The response shows cancel_at_period_end: true, and you receive subscription_cancelled when the period ends. |
A created, active, paused or unpaid subscription can be cancelled.
Cancelling never refunds a payment that was already taken. To refund, use Create Refund on the payment.
Headers
| Header | Type | Required | Description |
|---|---|---|---|
api-key | string | Yes | Your secret API key. |
X-Profile-Id | string | No | Not needed: the subscription's own profile is used. If you send it, it must be that profile, otherwise the request fails with IR_37 (subscription not found). |
Path Parameters
| Parameter | Type | Description |
|---|---|---|
subscription_id | string | Required. ID of the subscription. |
Body Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
cancel_option | string | No | immediately or end_of_term. Defaults to immediately. |
Request Example
curl -X POST 'https://api.moonlinkpay.com/subscriptions/sub_YZQbEYEnzrjzBorzniG3/cancel' \ -H "Content-Type: application/json" \ -H "api-key: snd_YOUR_API_KEY" \ -d '{ "cancel_option": "end_of_term"}'Response
{"id": "sub_YZQbEYEnzrjzBorzniG3","status": "active","merchant_reference_id": "order_1001","profile_id": "pro_YOUR_PROFILE_ID","merchant_id": "merchant_1234567890","customer_id": "cus_jane_42","cancelled_at": null,"cancel_at_period_end": true}With cancel_option: "immediately", status is cancelled and cancelled_at is set.
Errors
| Code | When |
|---|---|
IR_37 | No subscription with this ID on your account, or X-Profile-Id names a different profile than the subscription's. |
IR_06 | The subscription is already cancelled, or it is failed (a failed signup is already final). |