Skip to main content

Reversal/ Cancel

warning

Reversals should be used as a last resort when the transaction status cannot be determined, e.g. no payment notification is received, the response timed-out, there are network issues, etc. The query API endpoint should be used first to check the transaction status. Hong Kong PayTypes do not support transaction cancel.

The reversal API endpoint allows the merchant to cancel/ reverse a transaction that is currently in progress. Transactions that have already been processed successfully (return code 0000 = successful) can no longer be reversed or cancelled. If you would like to revert a successful transaction please refer to the Refund Endpoint.


For code instructions select Python, Java, Node.js or PHP with the tabs below.


import urllib.request, urllib.parse, urllib.error, urllib.request, urllib.error, urllib.parse, hashlib
import requests
from hashids import Hashids
import datetime
import string
import random

# Enter Client Credentials
environment = 'https://test-openapi-hk.qfapi.com'
app_code = '3F504C39125E4886AB4741**********'
client_key = '5744993FBC034DBBB995FA**********'


# Create parameter values for data payload
current_time = datetime.datetime.now().replace(microsecond=0)
random_string = ''.join(random.choices(string.ascii_uppercase + string.digits, k=32))

print(current_time)

# Create signature
def make_req_sign(data, key):
keys = list(data.keys())
keys.sort()
p = []
for k in keys:
v = data[k]
p.append('%s=%s'%(k,v))
unsign_str = ('&'.join(p) + key).encode("utf-8")
print(unsign_str)
s = hashlib.md5(unsign_str).hexdigest()
return s.upper()



# Body payload
txamt = '2500' #In USD,EUR,etc. Cent
out_trade_no = '4MDGEJ7L496LAAU1V1HBY9HMOGWZWLXQ'
syssn = '20200305066100020000977812'
txdtm = '2020-03-05 16:50:30'
mchid = 'MNxMp11FV35qQN'
key = client_key

#data ={'txamt': txamt, 'out_trade_no': out_trade_no, 'syssn': syssn, 'txdtm': txdtm, 'udid': udid, 'mchid': mchid}
data ={'txamt': txamt, 'out_trade_no': out_trade_no, 'txdtm': txdtm, 'mchid': mchid}

r = requests.post(environment+"/trade/v1/reversal",data=data,headers={'X-QF-APPCODE':app_code,'X-QF-SIGN':make_req_sign(data, key)})

print(r.json())

The above command returns JSON structured like this:


{
"surcharge_fee": "0",
"resperr": "success",
"txdtm": "2020-03-05 16:50:30",
"syssn": "20200305066100020000977814",
"sysdtm": "2020-03-05 16:54:38",
"txcurrcd": "EUR",
"respmsg": "",
"chnlsn2": "",
"cardcd": "",
"udid": "qiantai2",
"txamt": "2500",
"orig_syssn": "20200305066100020000977813",
"surcharge_rate": "0",
"respcd": "0000",
"chnlsn": ""
}

HTTP Request for Alipay CPM & MPM and WeChat Pay CPM

Endpoint : /trade/v1/reversal

Method : GET

HTTP Request for WeChat Pay MPM and other qualified Wallets

Endpoint : /trade/v1/close

Method : GET

*If you would like to use this endpoint on a wallet other than Alipay & Wechat Pay please contact us for instructions.

Request Parameters

AttributeMandatoryTypeDescription
mchidNoString(16)Merchant ID allocated by QFPay
syssnYes*String(40)QFPay transaction number, returned by the system once payment is completed
out_trade_noYes*String(128)External transaction number
txamtYesInt(11)Amount of the transaction. Unit in cents (i.e. 100 = $1)
txdtmYesString(20)Transaction time format: YYYY-MM-DD hh:mm:ss
udidNoString(40)Unique transaction device ID. Is displayed on the merchant portal.

*Either the syssn or out_trade_no must be provided.

Response Parameters

AttributeTypeDescription
orig_syssnString(40)Refers to the original QFPay transaction number
syssnString(40)QFPay transaction number of the cancel/ reversal
out_trade_noString(128)External transaction number
txamtInt(11)Amount of the transaction. Unit in cents (i.e. 100 = $1)
txcurrcdString(3)Transaction currency. View the Currencies table for a complete list of available currencies
txdtmString(20)Transaction time. Format: YYYY-MM-DD hh:mm:ss
sysdtmString(20)System transaction time. Format: YYYY-MM-DD hh:mm:ss
This parameter value is used as the cut-off time for settlements.
chnlsnStringTransaction number from payment channel (wallet side)
respcdString(4)Response code
0000 = Reversal/ cancel successul
1143/1145 = Reversal/ cancel in progress
others = Reversal/ cancel failed
resperrString(128)Result description
respmsgString(128)Information description