API Docs
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_optionWhat happens
immediately (default)The subscription is cancelled now and nothing more is charged. You receive subscription_cancelled.
end_of_termThe 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

HeaderTypeRequiredDescription
api-keystringYesYour secret API key.
X-Profile-IdstringNoNot 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

ParameterTypeDescription
subscription_idstringRequired. ID of the subscription.

Body Parameters

ParameterTypeRequiredDescription
cancel_optionstringNoimmediately 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

CodeWhen
IR_37No subscription with this ID on your account, or X-Profile-Id names a different profile than the subscription's.
IR_06The subscription is already cancelled, or it is failed (a failed signup is already final).