Skip to main content

Transaction Enquiry

warning

If the mchid is provided, it is mandatory to submit the mchid when calling the API (unless otherwise specified). On the contrary, if mchid is not provided, merchants shall not pass the mchid field in the API request.

API Endpoint for Transaction Enquiry

After making a payment, refund or cancellation request, the merchant can use the query interface to obtain the transaction status.

The merchant can use the query interface to enquire transaction status of one or multiple transactions. In case the interface does not return syssn in time, use out_trade_no as a condition to query the transaction status.

If merchants would like to query transactions in a month, they can provide start_time and end_time then records will be filtered according to the system transaction time sysdtm. The interval must be within one calendar month. Otherwise, it is recommended to include the syssn parameter as a query condition.

When the query transaction is a refund then an additional parameter origssn will be returned. The origssn shows the QFPay transaction number of the original transaction that has been refunded.

HTTP Request

Endpoint : /trade/v1/query

Method : POST

Request Header:

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

Request Body:

{
mchid=ZaMVg*****&syssn=20191227000200020061752831&start_time=2019-12-27 00:00:00&end_time=2019-12-27 23:59:59
}

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
mchid = 'ZaMVg*****' #(Agent ID, Merchant ID)
syssn = '20191227000200020061752831' #Search by transaction number only
out_trade_no = '2019122722001411461404119764' #Search by out_trade_no only
start_time = '2019-12-27 00:00:00'
end_time = '2019-12-27 23:59:59'
key = client_key


#data ={'mchid': mchid, 'syssn': syssn, 'out_trade_no': out_trade_no, 'start_time': start_time, 'end_time': end_time}
data ={'mchid': mchid, 'syssn': syssn}

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

print(make_req_sign(data, key))
print(r.json())

The above command returns JSON structured like this:

{
"respmsg": "",
"resperr": "请求成功",
"respcd": 0000,
"data":
[{
"cardtp": "5",
"cancel": "0",
"pay_type": "800101",
"order_type": "payment",
"clisn": "038424",
"txdtm": "2019-12-27 10:39:39",
"goods_detail": "",
"out_trade_no": "CHZ7D61JN1ANJF2R2K1I7TXP2JTCEWBL",
"syssn": "20191227000200020061752831",
"sysdtm": "2019-12-27 10:40:24",
"paydtm": "2019-12-27 10:42:18",
"goods_name": "",
"txcurrcd": "EUR",
"chnlsn2": "",
"udid": "qiantai2",
"userid": "2605489",
"txamt": "10",
"chnlsn": "2019122722001411461404119764",
"respcd": "0000",
"goods_info": "",
"errmsg": "success"
}],
"page": "1",
"page_size": "10"
}

Request Parameters

AttributeMandatoryTypeDescription
mchid-String(16)Merchant number. 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.
syssnNoString(128)QFPay transaction number. Multiple entries are seperated by commas
out_trade_noNoString(128)API order number, external transaction number / Merchant platform transaction number, multiple entries are seperated by commas
pay_typeNoString(6)Payment type, multiple entries are seperated by commas
respcdNoString(4)Transaction return code, returns all orders with return code status by default
start_timeNoString(20)Starting time, it is ignored when syssn or out_trade_number is provided. The default date time is the start of current month. Cross-month queries must add the time query parameters start_time and end_time.
Format: YYYY-MM-DD hh:mm:ss
end_timeNoString(20)End Time, it is ignored when syssn or out_trade_number is provided. The default date time is the end of current month. Cross-month queries must add the time query parameters start_time and end_time.
Format: YYYY-MM-DD hh:mm:ss
txzoneNoString(5)Time zone, used to record the local order time. The default is Beijing time UTC+8 (+0800)
pageNoInt(8)Number of pages, default value is 1
page_sizeNoInt(8)Number of items displayed per page, by default 10 transactions will be displayed. The maximum page_size value is 100

Response Parameters

AttributeTypeDescription
pageInt(8)Page number
resperrString(128)Request result description
page_sizeInt(8)Display number of items per page
respcdString(4)Request result code, 0000 - Interface call succeeded
dataObjectQuery result, in JSON format
syssnString(40)QFPay transaction number
out_trade_noString(128)API order number, external transaction number / Merchant platform transaction number
chnlsnStringWallet/Channel transaction number
goods_nameString(64)Product name, Goods Name / Marking: Cannot exceed 20 alphanumeric or contain special characters. Cannot be empty for app payment. Parameter needs to be UTF-8 encoded if it is written in Chinese characters.
txcurrcdString(3)Transaction currency, view the Currencies table for a complete list of available currencies
origssnString(40)Original transaction number, refers to the original QFPay transaction number. This parameter is only available when the syssn of a refund is queued
pay_typeString(6)Payment type, please refer to the section Payment Codes for a complete list of payment types
order_typeString(16)Order type. Payment: Payment transaction Refund: Refund transaction
txdtmString(20)Request transaction time provided by merchant in payment and refund request. Format: YYYY-MM-DD hh:mm:ss
txamtInt(11)Amount of the transaction. 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.
cancelString(1)Cancellation or refund indicator. Transaction cancel status:
0 = Not cancelled
1 = For CPM: Transaction reversed or refunded successfully
2 = For MPM: Transaction canceled successfully
3 = Transaction refunded
4 = Alipay Preauth order finished
5 = Transaction partially refunded
respcdString(4)Payment status, 0000 = transaction succeeded
1143/1145 = Please wait to evaluate the transaction status. All other response codes indicate transaction failure
errmsgString(128)Payment status message
exchange_rateStringApplied currency conversion exchange rate
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

Account Statement

The clearing statement for a particular payment channel is downloaded regularly. Additional requests can only be made in the production environment. The system response is in form of a compressed zip file. Data is based on the selected payment channel and contains all merchants therefore the mchid cannot be passed in as a request parameter.

API Endpoint for Account Statement

HTTP Request

Endpoint : /download/v1/trade_bill

Method : GET

Request Parameter

AttributeMandatoryTypeDescription
trade_dateYesString(10)Get a specific account statement for the selected date. Example: 2017-10-17