Cancel Subscription
post https://api-preprod.phonepe.com/apis/pg-sandbox/v3/recurring/subscription/cancel

To cancel the subscription permanently
anchor image
Copied !
FieldMandatoryDescription
Content-TypeYesapplication/json
X-VerifyYesSHA256(base64 encoded payload + “/v3/recurring/subscription/cancel” + salt key) + ### + salt index
X-CALLBACK-URLYesThe callback URL to receive the server to server callback response.
Sample Payload for Base64
{ "merchantId":"MID12345", "merchantUserId":"U123456789", "subscriptionId":"OMS2006110139450123456789", }

Convert the JSON Payload to Base64 Encoded Payload

The above JSON request payload should be converted to the Base64 Encoded Payload and then the request should be sent in the below format.

Sample Request
{ "request": "ewoJIm1lcmNoYW50SWQiOiJNSUQxMjM0NSIsCgkibWVyY2hhbnRVc2VySWQiOiJVMTIzNDU2Nzg5IiwKCSJzdWJzY3JpcHRpb25JZCI6Ik9NUzIwMDYxMTAxMzk0NTAxMjM0NTY3ODkiLAp9" }
anchor image
Copied !
Field NameData TypeMandatoryDescription
merchantIdStringYesUnique Id assigned to the merchant in the PhonePe system. Assigned during merchant onboarding.
merchantUserIdStringYesUnique Customer Id maintained by the merchant
subscriptionIdStringYesPhonePe generated Subscription Id
Sample Response
{ "success": true, "code": "SUCCESS", "message": "Your subscription has been successfully suspended.", "data": { "subscriptionId": "OMS2006110139450123456789", "state": "CANCEL_IN_PROGRESS" } }
anchor image
Copied !
Field NameData TypeDescriptionComments
subscriptionIdStringPhonePe Subscription Id
stateStringCANCEL_IN_PROGRESSInline state response is
available only when the user
authentication is not required
anchor image
Copied !
Field NameData TypeDescription
messageString
codeStringValues can be:
● SUBSCRIPTION_NOT_FOUND
● SUBSCRIPTION_NOT_ACTIVE
● SUBSCRIPTION_EXPIRED
● SUBSCRIPTION_FAILED
● SUBSCRIPTION_REVOKE_IN_PROGRESS
● SUBSCRIPTION_ALREADY_REVOKED
● SUBSCRIPTION_CANCEL_IN_PROGRES
● INVALID_SUBSCRIPTION_STATE
● SUBSCRIPTION_ALREADY_CANCELLED
anchor image
Copied !

Callback for Cancel Subscription

The server to server callback for Cancel Subscription will have the “callbackType”: “SUBSCRIPTION”.

Validations

Validate the checksum which has been passed in the response headers received in the Server to Server callback.

Callback Headers

Following are the response headers sent with a callback.

Header NameHeader Value
Content-Typeapplication/json
X-VERIFYSHA256(base64response + salt key) + ### + salt index

Sample Response

S2S Callback - Cancel Subscription - Base64 Sample Response
{ "response":"eyJzdWNjZXNzIjp0cnVlLCJjb2RlIjoiU1VDQ0VTUyIsIm1lc3NhZ2UiOiJZb3VyIHN1YnNjcmlwdGlvbiByZXF1ZXN0IGhhcyBiZWVuIHJldm9rZWQuIiwiZGF0YSI6eyJjYWxsYmFja1R5cGUiOiJTVUJTQ1JJUFRJT04iLCJtZXJjaGFudElkIjoiTUVSQ0hBTlRVQVQiLCJtZXJjaGFudFN1YnNjcmlwdGlvbklkIjoiYTcyOGE4NGEtIiwic3Vic2NyaXB0aW9uRGV0YWlscyI6eyJzdWJzY3JpcHRpb25JZCI6Ik9NUzIxMDcyMTEyMzYzNDUzNTU4NzM3OTUiLCJzdGF0ZSI6IlJFVk9LRUQifX19" }
S2S Callback - Cancel Subscription - Decoded Sample Response
{ "success": true, "code": "SUCCESS", "message": "Your subscription request has been cancelled.", "data": { "callbackType": "SUBSCRIPTION", "merchantId": "MERCHANTUAT", "merchantSubscriptionId": "a728a84a-", "subscriptionDetails": { "subscriptionId": "OMS2107211236345355873795", "state": "CANCELLED" } } }
{“method”:”post”,”url”:”/v3/recurring/subscription/cancel”,”auth”:”required”,”results”:{“codes”:[{“name”:””,”code”:”{\n \”success\”: true,\n \”code\”: \”SUCCESS\”,\n \”message\”: \”Your subscription has been successfully suspended.\”,\n \”data\”: {\n \”subscriptionId\”: \”OMS2006110139450123456789\”,\n \”state\”: \”CANCEL_IN_PROGRESS\”\n }\n}”,”language”:”json”,”status”:200},{“name”:””,”code”:”{\n \”success\”: false,\n \”code\”: \”SUBSCRIPTION_NOT_FOUND\”,\n \”message\”: \”No Subscription found with the given details.\”,\n \”data\”: {}\n}”,”language”:”json”,”status”:400}]},”params”:[{“name”:”Content-Type”,”type”:”string”,”enumValues”:””,”default”:”application/json”,”desc”:””,”required”:true,”in”:”header”,”ref”:””,”_id”:”60adeee6456229005a66586f”},{“name”:”X-VERIFY”,”type”:”string”,”enumValues”:””,”default”:””,”desc”:”SHA256(base64 encoded payload + \”/v3/recurring/subscription/cancel\” + salt key) + ### + salt index”,”required”:true,”in”:”header”,”ref”:””,”_id”:”60adeee6456229005a66586e”},{“name”:”request”,”type”:”string”,”enumValues”:””,”default”:””,”desc”:”base64 encoded payload”,”required”:true,”in”:”body”,”ref”:””,”_id”:”60b75a5b2c88440064baa036″},{“name”:”X-CALLBACK-URL”,”type”:”string”,”enumValues”:””,”default”:””,”desc”:”Dynamic callback URL for server to server callback”,”required”:false,”in”:”header”,”ref”:””,”_id”:”611b639d79490b001667708a”}],”apiSetting”:”63bb01b11abcf7046d98754c”,”examples”:{“codes”:[]}}
https://api-preprod.phonepe.com/apis/pg-sandbox

HEADERS
Content-Type string required
X-VERIFY string required
SHA256(base64 encoded payload + "/v3/recurring/subscription/cancel" + salt key) + ### + salt index
X-CALLBACK-URL string
Dynamic callback URL for server to server callback

BODY PARAMS
request string required
base64 encoded payload

RESPONSES
Code 200
200
Code 400
400