Subscription Cancellation


The cancel_subscription() method allows you to terminate an active subscription. Once a subscription is cancelled, no further redemption or payment attempts will be allowed.
To cancel a subscription, you need to provide the merchant-generated subscription ID as the input parameter.

AttributeData TypeMandatoryDescription
merchant_subscription_idStringYesUnique order ID generated by the merchant.
Code Reference
from phonepe.sdk.pg.subscription.v2.subscription_client import SubscriptionClient
 
client_id = "<client_id>"
client_secret = "<client_secret>"
client_version = 1          # insert your client version here
env = Env.SANDBOX           # change to Env.PRODUCTION when you go live
 
merchant_subscription_id = "<MERCHANT_SUBSCRIPTION_ID>"
 
subscription_client = SubscriptionClient.get_instance(client_id,client_secret,client_version,env)
subscription_client.cancel_subscription(merchant_subscription_id)

Success Behaviour!


If the call is successful, no response body is returned, and the subscription for the given ID is cancelled.

Failure Behaviour!


If the call fails, an exception is raised with the reason for failure.

You’ve just seen how simple it is to terminate an active subscription—now, let’s explore how to refund the amount for a paid subscription.

Is this article helpful?