Cancel Subscription
Delete a subscription from the database.
When the subscription is canceled immediately, this method triggers the following webhooks:
Subscription Canceled Webhook. This webhook contains the same information as the response.
The following asynchronous webhook provides information about later changes to the subscription object:
When the subscription is canceled at the end of the current billing period, all of these webhooks are triggered asynchronously.
subscription
ID of the subscription. String starting with sub_.
cancel_at_period_end
Determines when the subscription is canceled.
true - Cancels the subscription at the end of the current period.
false - Cancels the subscription immediately.
false
Code Samples
.NET
using System; using System.Text.Json; namespace RapydApiRequestSample { class Program { static void Main(string[] args) { try { string subscriptionItem = "sub_5b47720e0281b501092a695773fb2279"; string result = RapydApiRequestSample.Utilities.MakeRequest("DELETE", $"/v1/payments/subscriptions/{subscriptionItem}"); Console.WriteLine(result); } catch (Exception e) { Console.WriteLine("Error completing request: " + e.Message); } } } }
JavaScript
const makeRequest = require('<path-to-your-utility-file>/utilities').makeRequest; async function main() { try { const result = await makeRequest( 'DELETE', '/v1/payments/subscriptions/sub_5b47720e0281b501092a695773fb2279' ); console.log(result); } catch (error) { console.error('Error completing request', error); } }
PHP
<?php $path = $_SERVER['DOCUMENT_ROOT']; $path .= "/<path-to-your-utility-file>/utilities.php"; include($path); try { $object = make_request('delete', '/v1/payments/subscriptions/sub_5b47720e0281b501092a695773fb2279'); var_dump($object); } catch(Exception $e) { echo "Error: $e"; } ?>
Python
from pprint import pprint from utilities import make_request result = make_request(method='delete', path='/v1/payments/subscriptions/sub_c120969b649d4a029b660228e00c8d97') pprint(result)
/v1/payments/subscriptions/:subscription
Cancel Subscription Immediately
curl -X delete 'https://sandboxapi.rapyd.net/v1/payments/subscriptions/sub_6f634b7aced3e9f872f66fc8ef708ae5' \ -H 'access_key: your-access-key-here' \ -H 'Content-Type: application/json' \ -H 'salt: your-random-string-here' \ -H 'signature: your-calculated-signature-here' \ -H 'timestamp: your-unix-timestamp-here'
{ "status": { "error_code": "", "status": "SUCCESS", "message": "", "response_code": "", "operation_id": "1fc01453-f7ee-4535-9bb8-562493dd3df7" }, "data": { "id": "sub_5f599d4bec8598f8fcee195df58b1621", "billing": "pay_automatically", "billing_cycle_anchor": 1761226148, "created_at": 1761226148, "customer_token": "cus_4e25112ac20e144ad073a614dc46934b", "days_until_due": 30, "metadata": {}, "tax_percent": 0, "cancel_at_period_end": false, "canceled_at": 1761226167, "current_period_end": 1761226167, "current_period_start": 1761226148, "discount": null, "ended_at": null, "subscription_items": { "data": [ { "id": "subi_372c7bcee656bc2123697f53ebc474f8", "created": 1761226148, "metadata": null, "quantity": 1, "plan": { "id": "plan_9338044c6ca654abd79da7319c40b7dc", "aggregate_usage": "sum", "amount": 0, "billing_scheme": "tiered", "created_at": 1761210135, "currency": "USD", "interval": "month", "interval_count": 2, "metadata": {}, "product": { "id": "product_88fde8f1365082b50e8f4b37127edd99", "active": true, "attributes": [ "users" ], "created_at": 1673509005, "description": "SaaS Users", "images": [ "64bit-encoded-image-1" ], "metadata": { "merchant_defined": true }, "name": "SaaS Users", "package_dimensions": { "height": 0, "length": 0, "weight": 0, "width": 0 }, "shippable": false, "skus": [], "statement_descriptor": "Number of Users", "type": "services", "unit_label": "users", "updated_at": 1673509005 }, "nickname": "SaaS Users", "tiers": [ { "amount": 35, "up_to": 5, "flat_amount": 25 }, { "amount": 30, "up_to": 10, "flat_amount": 0 }, { "amount": 25, "up_to": 25, "flat_amount": 0 }, { "amount": 20, "up_to": 100, "flat_amount": 0 }, { "amount": 15, "up_to": 500, "flat_amount": 0 }, { "amount": 10, "up_to": "inf", "flat_amount": 0 } ], "tiers_mode": "volume", "transform_usage": { "divide_by": 1, "round": "up" }, "trial_period_days": 0, "usage_type": "licensed", "active": true } } ], "has_more": false, "total_count": 1, "url": "/v1/subscription_items?subscription=sub_5f599d4bec8598f8fcee195df58b1621" }, "status": "canceled", "trial_end": null, "trial_start": null, "payment_method": "card_b9548d9b53a565b2315fecdc6c87f158", "payment_fields": null, "payout_fields": null, "type": "payment", "simultaneous_invoice": true } }
Cancel Subscription at end of billing cycle
curl -X delete 'https://sandboxapi.rapyd.net/v1/payments/subscriptions/sub_6f634b7aced3e9f872f66fc8ef708ae5?cancel_at_period_end=true' \ -H 'access_key: your-access-key-here' \ -H 'Content-Type: application/json' \ -H 'salt: your-random-string-here' \ -H 'signature: your-calculated-signature-here' \ -H 'timestamp: your-unix-timestamp-here'
{ "status": { "error_code": "", "status": "SUCCESS", "message": "", "response_code": "", "operation_id": "167bbb6c-d540-4bac-b8b1-f188df0e11ed" }, "data": { "id": "sub_d25185e18bd1509108cbc0b285a8243c", "billing": "pay_automatically", "billing_cycle_anchor": 1761226223, "created_at": 1761226223, "customer_token": "cus_4e25112ac20e144ad073a614dc46934b", "days_until_due": 30, "metadata": {}, "tax_percent": 0, "cancel_at_period_end": true, "canceled_at": 1761226268, "current_period_end": 1766496623, "current_period_start": 1761226223, "discount": null, "ended_at": null, "subscription_items": { "data": [ { "id": "subi_1bba618bdb03542772fd608e3e6fe2bf", "created": 1761226223, "metadata": null, "quantity": 1, "plan": { "id": "plan_9338044c6ca654abd79da7319c40b7dc", "aggregate_usage": "sum", "amount": 0, "billing_scheme": "tiered", "created_at": 1761210135, "currency": "USD", "interval": "month", "interval_count": 2, "metadata": {}, "product": { "id": "product_88fde8f1365082b50e8f4b37127edd99", "active": true, "attributes": [ "users" ], "created_at": 1673509005, "description": "SaaS Users", "images": [ "64bit-encoded-image-1" ], "metadata": { "merchant_defined": true }, "name": "SaaS Users", "package_dimensions": { "height": 0, "length": 0, "weight": 0, "width": 0 }, "shippable": false, "skus": [], "statement_descriptor": "Number of Users", "type": "services", "unit_label": "users", "updated_at": 1673509005 }, "nickname": "SaaS Users", "tiers": [ { "amount": 35, "up_to": 5, "flat_amount": 25 }, { "amount": 30, "up_to": 10, "flat_amount": 0 }, { "amount": 25, "up_to": 25, "flat_amount": 0 }, { "amount": 20, "up_to": 100, "flat_amount": 0 }, { "amount": 15, "up_to": 500, "flat_amount": 0 }, { "amount": 10, "up_to": "inf", "flat_amount": 0 } ], "tiers_mode": "volume", "transform_usage": { "divide_by": 1, "round": "up" }, "trial_period_days": 0, "usage_type": "licensed", "active": true } } ], "has_more": false, "total_count": 1, "url": "/v1/subscription_items?subscription=sub_d25185e18bd1509108cbc0b285a8243c" }, "status": "active", "trial_end": null, "trial_start": null, "payment_method": "card_b9548d9b53a565b2315fecdc6c87f158", "payment_fields": null, "payout_fields": null, "type": "payment", "simultaneous_invoice": true } }