Subscription Cancellation
The cancelSubscription() 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.
Required Parameters
| Attribute | Data Type | Mandatory | Description |
| String | Yes | Unique order ID generated by the merchant. |
Code Reference
import com.phonepe.sdk.pg.subscription.v2.SubscriptionClient;
String clientId = "<clientId>";
String clientSecret = "<clientSecret>";
Integer clientVersion = <clientVersion>; //insert your client version here
Env env = Env.SANDBOX; //change to Env.PRODUCTION when you go live
String merchantSubscriptionId = "<MERCHANT_SUBSCRIPTION_ID>";
SubscriptionClient subscriptionClient = SubscriptionClient.getInstance(clientId, clientSecret, clientVersion, env);
subscriptionClient.cancelSubscripition(merchantSubscriptionId);✅ 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.
What’s Next ?
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.