Intent Cancel Request API


Intent Cancel Request API is used by merchants in order to cancel the raised intent generated requests like DQR, Collect Call, etc when the customer asks for the cancellation.

Header NameHeader Value
Content-Typeapplication/json
X-VERIFYSHA256(“/v1/intent/{merchantId}/{transactionId}/cancel” +
salt key) + ### + salt index
X-PROVIDER-IDUsed for the cases where the merchants are getting onboarded via their Providers
X-CALLBACK-URLMerchants need to pass their Callback URL to receive automated callbacks/ webhooks from Phonepe post performing transactions
Parameter NameTypeDescriptionMandatory
merchantIdSTRINGUnique Merchant ID assigned to the merchant by PhonePeYes
transactionIdSTRINGUnique Transaction ID generated by the merchant to track this request to PhonePeYes
Parameter NameTypeDescription
successBOOLEANSuccess status of the request
codeENUMSee below section for list of codes
messageSTRINGShort message about status
dataOBJECTEmpty object

The code in the above API response could be.

  • SUCCESS
  • INTERNAL_SERVER_ERROR : There can be internal server error. Merchant should retry the cancel API request.
  • INVALID_TRANSACTION_ID
  • PAYMENT_ALREADY_COMPLETED : Payment has been succesful hence can’t cancel the request. For this case merchant should trigger successful transaction, generating the bill.
SampleResponseforSuccess
{
  "success":true,
 "code":"SUCCESS",
 "message":"Your request has been successfully completed."
}
SampleResponseforFailed
{
  "success":false,
  "code":"PAYMENT_ALREADY_COMPLETED",
  "message":"Payment is already complete."
}
Python SampleCode
from django.shortcuts import render
from django.http import HttpResponse
import requests
import base64
import hashlib
from rest_framework.decorators import api_view
import json
from django.http import JsonResponse
import qrcode
import os

txnid = "TEST20231004021525T"
baseUrl = 'https://mercury-uat.phonepe.com/enterprise-sandbox'
MID = 'MERCHANTUAT'
saltkey = 'f1fed176-917c-4c1b-b5ae-1e1d39e1f8d5'
keyindex = '1'

def canceltransaction(request):
    merchantId = MID
    transactionId = txnid
    url = baseUrl + '/v1/intent/' + merchantId + '/' + transactionId + '/cancel'
    # for Sha256 calculation
    api_saltkey = saltkey
    str_forSha256 = '/v1/intent/' + merchantId + '/' + transactionId + '/cancel' + api_saltkey
    sha_value = hashlib.sha256(str_forSha256.encode('UTF-8')).hexdigest()
    x_verify = sha_value + '###' + keyindex

    headers = {
        "Content-Type": "application/json",
        "X-VERIFY": x_verify,
        "x-callback-url":"https://webhook.site/83892277-ac4f-4bc8"
    }
    print(headers)
    print(url)
    res = requests.post(url=url, headers=headers)
    return HttpResponse(res)
Is this article helpful?