Skip to main content

Refunds

tip

Only transactions with the return code 0000 (transaction successful) can be refunded.

API Endpoint for Refunds

Request Header:

{
Content-Type: application/x-www-form-urlencoded;
X-QF-APPCODE: D5589D2A1F2E42A9A60C37**********
X-QF-SIGN: 6FB43AC29175B4602FF95F8332028F19
}

Request Body:

{
txamt=10&syssn=20191227000200020061752831&out_trade_no=12345678&txdtm=2019-12-27 10:39:39&key=0E32A59A8B454940A2FF39**********&mchid=ZaMVg*****
}

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 = 'D5589D2A1F2E42A9A60C37**********'
client_key = '0E32A59A8B454940A2FF39**********'


# 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))


# 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")
s = hashlib.md5(unsign_str).hexdigest()
return s.upper()


# Body payload
txamt = '10' #Partial or full refund amount
syssn = '20191227000200020061752831' #Original transaction number
out_trade_no = random_string
txdtm = current_time
key = client_key
mchid = 'ZaMVg*****'


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

r = requests.post(environment+"/trade/v1/refund",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:

{
"orig_syssn": "20191227000200020061752831",
"sysdtm": "2019-12-27 11:11:23",
"paydtm": "2019-12-27 11:11:26",
"txdtm": "2019-12-27 11:10:38",
"udid": "qiantai2",
"txcurrcd": "EUR",
"txamt": "10",
"resperr": "success",
"respmsg": "",
"out_trade_no": "RGNOEIVU9JZLNP9GGYXWXCW7OEMI720F",
"syssn": "20191227000300020061652643",
"respcd": "0000",
"chnlsn": "2019122722001411461404119764",
"cardcd": ""
}

HTTP Request

Endpoint : /trade/v1/refund

Method : POST

Description : Merchants can use the refund interface to refund transactions. The merchant account must have a sufficient transaction amount on the same trading day in order to refund transactions. The maximum refund amount for a transaction must not exceed to original payment amount. Unless otherwise specified, once a refund request is submitted and accepted, it is not reversible. The refund capability and the maximum time period for refund varies across payment channels. Please contact your QFPay support representative for more information.

Request Parameters

AttributeMandatoryTypeDescription
syssnYesString(128)QFPay transaction number. Original transaction ID syssn that is supposed to be refunded
out_trade_noYesString(128)API order number. External refund transaction number / Merchant platform refund transaction number: This parameter must be unique for each payment and refund request under the same merchant account in the system.
txamtYesInt(11)Amount of the refund. Unit in cents (i.e. 100 = $1)
Required for both full refund and partial refund. Some payment channel may not support partial refund. Suggest value > 200 to avoid risk control.
txdtmYesString(20)Transaction request time. Format: YYYY-MM-DD hh:mm:ss
mchidNoString(16)Merchant ID. May or may not be given to merchant. If MCHID is given, it is mandatory to provide the MCHID. On the contrary, if MCHID is not provided, merchants shall not pass the MCHID field in the API request.
txzoneNoString(5)Transaction time. Used to record the local transaction time. The default is Beijing time UTC+8 (+0800)
udidNoString(40)Unique transaction device ID

Response Parameters

AttributeTypeDescription
syssnString(40)Refund Transaction ID referring to the newly created refund transaction
orig_syssnString(128)Original Transaction ID, previous transaction ID referring to the original transaction that has been refunded
txamtInt(11)Amount of the refund. Unit in cents (i.e. 100 = $1)
sysdtmString(20)System transaction time. Format: YYYY-MM-DD hh:mm:ss
This parameter value is used as the cut-off time for settlements.
respcdString(4)Return code, 0000-Request successful.
1143/1145 - merchants are required to continue to query the refund transaction result.
All other return codes indicate transaction failure. Please refer to the section payment status codes for a complete list of return codes.
resperrString(128)Response message
cash_feeStringActual payment amount by user = transaction amount - discounts
cash_fee_typeStringActual payment currency e.g. CNY
cash_refund_feeStringActual refund amount
cash_refund_fee_typeStringActual refund currency e.g. CNY