Skip to main content

Consumer Present Mode (CPM)

CPM process-flow

CPM API Request

Endpoint : ../trade/v1/payment

Method : POST

PayType :

PayTypeDescription
800008Consumer Present QR Code Mode (CPM) for WeChat, Alipay, UNIONPAY Quick Pass
800108Alipay Consumer Presented QR Code Payment (CPM) (Overseas & HK Merchants)
800208WeChat Consumer Presented QR Code Payment (CPM) (Overseas & HK Merchants)
801008WeChat Pay HK Consumer Presented QR Code Payment (CPM) (Direct Settlement, HK Merchants)
805808PayMe Consumer Presented QR Code Payment (CPM) (HK Merchants)
800708UNIONPAY Quick Pass Consumer Presented QR Code Payment (CPM)

Description : The customer generates a dynamic QR code in their QR code wallet and presents it to the cashier for scanning. This szenario applies to offline payments only. If the response codes 1143/1145 are returned, the transaction is being processed or the customer is required to input the wallet password. Merchants have to query the transaction result for a final assessment of the transaction status.

Request Header:

{
Content-Type: application/x-www-form-urlencoded;
charset=UTF-8,
Content-Length: 218,
Chunked: false
X-QF-APPCODE:A6A49A66B4C********94EA95032
X-QF-SIGN:3b020a6349646684ebeeb0ec2cd3d1fb
}

Request Body:

{
auth_code=13485790*******88557&goods_name=qfpay&mchid=R1zQrTdJnn&out_trade_no=Native201907221520536a25477909&pay_type=800208&txamt=10&txcurrcd=HKD&txdtm=2019-07-22 15:20:54&udid=AA
}
#coding=utf8
import urllib.request, urllib.parse, urllib.error, urllib.request, urllib.error, urllib.parse, hashlib
import requests
import datetime
import string

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

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


# Body payload
txamt = '10' #In USD,EUR,etc. Cent
txcurrcd = 'HKD'
pay_type = '800108' # Alipay CPM = 800108 , WeChat Pay CPM = 800208
auth_code = '280438849930815813' # Mandatory for CPM
out_trade_no = '01234567890123'
txdtm = current_time
goods_name = 'test1'
mchid = 'ZaMVg*****'
notify_url = 'https://xxx.com/notify/success'
key = client_key


#data ={'txamt': txamt, 'txcurrcd': txcurrcd, 'pay_type': pay_type, 'out_trade_no': out_trade_no, 'txdtm': txdtm, 'goods_name': goods_name, 'udid': udid, 'auth_code': auth_code, 'mchid': mchid, 'notify_url': notify_url}
data ={'txamt': txamt, 'txcurrcd': txcurrcd, 'pay_type': pay_type, 'out_trade_no': out_trade_no, 'txdtm': txdtm, 'mchid': mchid, 'auth_code': auth_code}

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

{
"pay_type": "800108",
"sysdtm": "2019-07-22 15:20:54",
"paydtm": "2019-07-22 15:20:56",
"txdtm": "2019-07-22 15:20:54",
"udid": "AA",
"txcurrcd": "EUR",
"txamt": 10,
"resperr": "交易成功",
"respmsg": "OK",
"out_trade_no": "201907221520536a25477909",
"syssn": "20190722000300020081074842",
"respcd": "0000",
"chnlsn": "4200000384201907223585006133"
}

Request Parameters

AttributeMandatoryTypeDescription
Public payment parametersPlease refer to the Public Payment Section for more details
auth_codeYes
(CPM only)
String(128)Specifies the authorization code for scanning a barcode/QR Code. The auth_code returned is unique in each authorization. Each auth_code can only be used once and will automatically expire. For testing CPM with Alipay and WeChat Pay the auth_code can be extracted by any QRC reader or manually found in the consumer wallet below the barcode.

Response Parameters

AttributeMandatoryTypeDescription
Public payment parametersPlease refer to the Public Payment Section for more details