QFPay Payment API Skill
Overview
QFPay API is a comprehensive payment solution that offers various payment methods to meet the needs of different businesses. This skill provides complete API integration guidelines including environment configuration, request formats, signature generation, payment types, supported currencies, and status codes.
Environment Configuration
QFPay API is accessible via three main environments:
| Environment | Base URL | Description |
|---|
| Sandbox | INLINECODE0 | For simulating payments without real fund deduction |
| Testing |
https://test-openapi-hk.qfapi.com | Real payment flow but linked to test accounts (no settlement) |
| Production |
https://openapi-hk.qfapi.com | Real live payments with actual settlement |
Important Notes:
- - Transactions in Testing environment using test accounts will NOT be settled
- Always ensure refunds are triggered immediately for test transactions
- Mixing credentials or endpoints across environments will result in signature or authorization errors
Environment Variables Setup
Configure these environment variables before using the API:
CODEBLOCK0
API Usage Guidelines
Rate Limiting
To ensure fair usage and optimal performance:
- - Limit: Maximum 100 requests per second (RPS) and 400 requests per minute per merchant
- Exceeding Limit: API responds with HTTP 429 (Too Many Requests)
Best Practices
- 1. Batch Requests: Use batch processing to minimize individual requests
- Efficient Queries: Utilize filtering and pagination
- Caching: Implement response caching to avoid repeated requests
- Monitoring: Track API usage and implement logging for request patterns
Error Handling
When receiving HTTP 429:
- 1. Pause further requests for a specified duration
- Implement exponential backoff for retries
- Log errors for monitoring
Traffic Spike Management
For anticipated traffic spikes (e.g., promotional events), contact:
- - Technical Support: technical.support@qfpay.com
Request Format
HTTP Request
CODEBLOCK1
Public Payment Request Parameters
| Attribute | Required | Type | Description |
|---|
| INLINECODE3 | Yes | Int(11) | Transaction amount in cents (100 = $1). Suggest > 200 to avoid risk control |
| INLINECODE4 |
Yes | String(3) | Transaction currency. See Currencies section for full list |
|
pay_type | Yes | String(6) | Payment type code. See Payment Types section |
|
out_trade_no | Yes | String(128) | External transaction number. Must be unique per merchant account |
|
txdtm | Yes | String(20) | Transaction time format: YYYY-MM-DD hh:mm:ss |
|
auth_code | Yes (CPM only) | String(128) | Authorization code for scanning barcode/QR. Expires within one day |
|
expired_time | No (MPM only) | String(3) | QR expiration in minutes. Default: 30, Min: 5, Max: 120 |
|
goods_name | No | String(64) | Item description. Max 20 chars, UTF-8 for Chinese. Required for App payments |
|
mchid | No | String(16) | Merchant ID. Required if assigned, must NOT be included if not assigned |
|
udid | No | String(40) | Unique device ID for internal tracking |
|
notify_url | No | String(256) | URL for asynchronous payment notifications |
HTTP Header Requirements
| Field | Required | Description |
|---|
| INLINECODE14 | Yes | App code assigned to merchant |
| INLINECODE15 |
Yes | Signature generated per signature algorithm |
|
X-QF-SIGNTYPE | No | Signature algorithm. Use
SHA256 or defaults to
MD5 |
Content Specifications
- - Character Encoding: UTF-8
- Method: POST/GET (depends on endpoint)
- Content-Type: application/x-www-form-urlencoded
Response Format
Success Response Structure
CODEBLOCK2
Response Fields
| Field | Type | Description |
|---|
| INLINECODE19 | String(4) | Return code. "0000" means success |
| INLINECODE20 |
String(64) | Message description of respcd |
|
data | Object | Payment transaction data |
Data Object Fields
| Field | Type | Description |
|---|
| INLINECODE22 | String | Transaction amount in cents |
| INLINECODE23 |
String | Merchant's original order number |
|
txcurrcd | String | Currency code (e.g., HKD) |
|
txstatus | String | Payment status: SUCCESS, FAILED, PENDING |
|
qf_trade_no | String | QFPay's unique transaction number |
|
pay_type | String | Payment method code |
|
txdtm | String | Payment time (YYYY-MM-DD HH:mm:ss) |
Signature Verification
Response may include X-QF-SIGN and X-QF-SIGNTYPE headers. Verify by:
- 1. Extracting data fields in sorted order
- Concatenating as key1=value1&key2=value2&...
- Appending client key
- Generating MD5 hash and comparing
Signature Generation
All API requests must include a digital signature in the HTTP header:
CODEBLOCK3
Step-by-Step Guide
Step 1: Sort Parameters
Sort all request parameters by parameter name in ASCII ascending order.
Example:
| Parameter | Value |
|---|
| INLINECODE31 | INLINECODE32 |
| INLINECODE33 |
100 |
|
txcurrcd |
HKD |
Sorted result:
CODEBLOCK4
Step 2: Append Client Key
Append your secret client_key to the string.
If client_key = abcd1234:
CODEBLOCK5
Step 3: Hash the String
Hash using MD5 or SHA256 (SHA256 recommended):
CODEBLOCK6
Step 4: Add to Header
CODEBLOCK7
Important Notes
- - Do NOT insert line breaks, tabs, or extra spaces
- Parameter names and values are case-sensitive
- Double-check parameter order and encoding if signature fails
Code Examples
Python
CODEBLOCK8
Payment Types
The pay_type parameter specifies which payment method to use. This affects transaction routing and UI requirements.
Note: Not all pay_type values are enabled for every merchant. Contact technical.support@qfpay.com for clarification.
Supported Payment Types
| Code | Description |
|---|
| 800008 | CPM for WeChat, Alipay, UnionPay QuickPass, PayMe |
| 800101 |
Alipay MPM (Overseas Merchants) |
| 800108 | Alipay CPM (Overseas & HK Merchants) |
| 801101 | Alipay Web Payment (Overseas) |
| 801107 | Alipay WAP Payment (Overseas) |
| 801110 | Alipay In-App Payment (Overseas) |
| 800107 | Alipay Service Window H5 Payment |
| 801501 | Alipay MPM (HK Merchants) |
| 801510 | Alipay In-App (HK Merchants) |
| 801512 | Alipay WAP (HK Merchants) |
| 801514 | Alipay Web (HK Merchants) |
| 800201 | WeChat MPM (Overseas & HK) |
| 800208 | WeChat CPM (Overseas & HK) |
| 800207 | WeChat JSAPI Payment (Overseas & HK) |
| 800212 | WeChat H5 Payment |
| 800210 | WeChat In-App Payment (Overseas & HK) |
| 800213 | WeChat Mini-Program Payment |
| 801008 | WeChat Pay HK CPM (Direct Settlement, HK) |
| 801010 | WeChat Pay HK In-App (Direct Settlement, HK) |
| 805801 | PayMe MPM (HK Merchants) |
| 805808 | PayMe CPM (HK Merchants) |
| 805814 | PayMe Web Payment (HK Merchants) |
| 805812 | PayMe WAP Payment (HK Merchants) |
| 800701 | UnionPay QuickPass MPM |
| 800708 | UnionPay QuickPass CPM |
| 800712 | UnionPay WAP Payment (HK) |
| 800714 | UnionPay PC-Web Payment (HK) |
| 802001 | FPS MPM (HK Merchants) |
| 803701 | Octopus MPM (HK Merchants) |
| 803712 | Octopus WAP Payment (HK) |
| 803714 | Octopus PC-Web Payment (HK) |
| 802801 | Visa / Mastercard Online |
| 802808 | Visa / Mastercard Offline |
| 806527 | ApplePay Online |
| 806708 | UnionPay Card Offline |
| 806808 | American Express Card Offline |
Special Remarks
- - 801101: Transaction amount must be greater than 1 HKD
- 802001: This payment method does not support refunds
Supported Currencies
All codes follow ISO 4217 format (3-letter uppercase):
| Code | Description |
|---|
| AED | Arab Emirates Dirham |
| CNY |
Chinese Yuan |
| EUR | Euro |
| HKD | Hong Kong Dollar |
| IDR | Indonesian Rupiah |
| JPY | Japanese Yen |
| MMK | Myanmar Kyat |
| MYR | Malaysian Ringgit |
| SGD | Singapore Dollar |
| THB | Thai Baht |
| USD | United States Dollar |
| CAD | Canadian Dollar |
| AUD | Australian Dollar |
Note: Some payment methods may only support HKD. Verify with your integration manager before non-HKD transactions.
Status Codes
Standard respcd values returned by QFPay API:
| Code | Description |
|---|
| 0000 | Transaction successful |
| 1100 |
System under maintenance |
| 1101 | Reversal error |
| 1102 | Duplicate request |
| 1103 | Request format error |
| 1104 | Request parameter error |
| 1105 | Device not activated |
| 1106 | Invalid device |
| 1107 | Device not allowed |
| 1108 | Signature error |
| 1125 | Transaction already refunded |
| 1136 | Transaction does not exist or not operational |
| 1142 | Order already closed |
| 1143 | Order not paid, password being entered |
| 1145 | Processing, please wait |
| 1147 | WeChat Pay transaction error |
| 1150 | T0 billing method does not support cancellation |
| 1155 | Refund request denied |
| 1181 | Order expired |
| 1201 | Insufficient balance |
| 1202 | Incorrect or expired payment code |
| 1203 | Merchant account error |
| 1204 | Bank error |
| 1205 | Transaction failed, try again later |
| 1212 | Please use UnionPay overseas payment code |
| 1241 | Store does not exist or status incorrect |
| 1242 | Store not configured correctly |
| 1243 | Store has been disabled |
| 1250 | Transaction forbidden |
| 1251 | Store configuration error |
| 1252 | System error making order request |
| 1254 | Problem occurred, resolving issue |
| 1260 | Order already paid |
| 1261 | Order not paid |
| 1262 | Order already refunded |
| 1263 | Order already cancelled |
| 1264 | Order already closed |
| 1265 | Transaction cannot be refunded (11:30pm-0:30am) |
| 1266 | Transaction amount wrong |
| 1267 | Order information mismatch |
| 1268 | Order does not exist |
| 1269 | Insufficient unsettled balance for refund |
| 1270 | Currency does not support partial refund |
| 1271 | Transaction does not support partial refund |
| 1272 | Refund amount exceeds maximum refundable |
| 1294 | Transaction non-compliant, prohibited by bank |
| 1295 | Connection slow, waiting for network response |
| 1296 | Connection slow, try again later |
| 1297 | Banking system busy |
| 1298 | Connection slow, do not repeat payment if already paid |
| 2005 | Customer payment code incorrect or expired |
| 2011 | Transaction serial number repeats |
Usage Examples
Complete Payment Flow (Python)
CODEBLOCK9
Environment Configuration with Multiple Merchants
CODEBLOCK10
Important Notes
- 1. Signature Security: Never expose your
client_key in frontend code or client-side applications. Always compute signatures on the server side.
- 2. Order Number Uniqueness:
out_trade_no must be unique across all payment and refund requests under the same merchant account.
- 3. Character Encoding: All requests and responses use UTF-8 encoding.
- 4. Timeout Handling: For payment requests that don't return promptly, implement a polling mechanism to query transaction status.
- 5. Async Notifications: Configure
notify_url to receive asynchronous payment completion notifications and verify notification signatures.
- 6. Refund Limitations: FPS (802001) payment type does not support refunds. Confirm business requirements before integration.
- 7. Amount Format: Amount is in cents. For example, 100 represents 1 HKD.
- 8. Timezone: The
txdtm parameter uses the merchant's local timezone.
- 9. Environment Variables: Always load sensitive credentials from environment variables, never hardcode them in source files.
Technical Support
For any integration issues, contact:
- - Email: technical.support@qfpay.com
- Documentation: https://sdk.qfapi.com
- Postman Collection: https://sdk.qfapi.com/assets/files/qfpayopenapipaymentrequest.postmancollection-c8de8c8fe69f3fcd5a7653d41c289a29.json
See Also
QFPay 支付API技能
概述
QFPay API 是一个全面的支付解决方案,提供多种支付方式以满足不同业务需求。本技能提供完整的API集成指南,包括环境配置、请求格式、签名生成、支付类型、支持货币和状态码。
环境配置
QFPay API 可通过三个主要环境访问:
| 环境 | 基础URL | 描述 |
|---|
| 沙箱 | https://openapi-int.qfapi.com | 用于模拟支付,不进行实际扣款 |
| 测试 |
https://test-openapi-hk.qfapi.com | 真实支付流程,但关联测试账户(不清算) |
| 生产 | https://openapi-hk.qfapi.com | 真实在线支付,进行实际清算 |
重要提示:
- - 在测试环境中使用测试账户的交易将不会进行清算
- 务必确保测试交易立即触发退款
- 跨环境混用凭证或端点将导致签名或授权错误
环境变量设置
使用API前请配置以下环境变量:
bash
export QFPAYAPPCODE=yourappcodehere
export QFPAYKEY=yourclientkeyhere
export QFPAYMCHID=yourmerchant_id # 可选,取决于账户设置
export QFPAY_ENV=sandbox # 选项:prod, test, sandbox
API使用指南
速率限制
为确保公平使用和最佳性能:
- - 限制:每个商户每秒最多100次请求(RPS),每分钟最多400次请求
- 超出限制:API返回HTTP 429(请求过多)
最佳实践
- 1. 批量请求:使用批量处理以最小化单个请求
- 高效查询:利用过滤和分页
- 缓存:实现响应缓存以避免重复请求
- 监控:跟踪API使用情况并记录请求模式
错误处理
收到HTTP 429时:
- 1. 暂停后续请求指定时长
- 对重试实施指数退避
- 记录错误以便监控
流量高峰管理
对于预期流量高峰(如促销活动),请联系:
- - 技术支持:technical.support@qfpay.com
请求格式
HTTP请求
POST /trade/v1/payment
公共支付请求参数
| 属性 | 必填 | 类型 | 描述 |
|---|
| txamt | 是 | Int(11) | 交易金额(分,100 = 1美元)。建议大于200以避免风控 |
| txcurrcd |
是 | String(3) | 交易货币。详见货币部分 |
| pay_type | 是 | String(6) | 支付类型代码。详见支付类型部分 |
| out
tradeno | 是 | String(128) | 外部交易号。每个商户账户下必须唯一 |
| txdtm | 是 | String(20) | 交易时间,格式:YYYY-MM-DD hh:mm:ss |
| auth_code | 是(仅CPM) | String(128) | 扫描条码/二维码的授权码。一天内过期 |
| expired_time | 否(仅MPM) | String(3) | 二维码过期时间(分钟)。默认:30,最小:5,最大:120 |
| goods_name | 否 | String(64) | 商品描述。最多20个字符,中文使用UTF-8。App支付必填 |
| mchid | 否 | String(16) | 商户ID。如已分配则必填,如未分配则不得包含 |
| udid | 否 | String(40) | 用于内部跟踪的唯一设备ID |
| notify_url | 否 | String(256) | 异步支付通知的URL |
HTTP头部要求
| 字段 | 必填 | 描述 |
|---|
| X-QF-APPCODE | 是 | 分配给商户的应用代码 |
| X-QF-SIGN |
是 | 根据签名算法生成的签名 |
| X-QF-SIGNTYPE | 否 | 签名算法。使用SHA256或默认为MD5 |
内容规范
- - 字符编码:UTF-8
- 方法:POST/GET(取决于端点)
- Content-Type:application/x-www-form-urlencoded
响应格式
成功响应结构
json
{
respcd: 0000,
respmsg: success,
data: {
txamt: 100,
outtradeno: 20231101000001,
txcurrcd: HKD,
txstatus: SUCCESS,
qftradeno: 9000020231101000001,
pay_type: 800101,
txdtm: 2023-11-01 10:00:00
}
}
响应字段
| 字段 | 类型 | 描述 |
|---|
| respcd | String(4) | 返回码。0000表示成功 |
| respmsg |
String(64) | respcd的消息描述 |
| data | Object | 支付交易数据 |
数据对象字段
| 字段 | 类型 | 描述 |
|---|
| txamt | String | 交易金额(分) |
| outtradeno |
String | 商户原始订单号 |
| txcurrcd | String | 货币代码(如HKD) |
| txstatus | String | 支付状态:SUCCESS, FAILED, PENDING |
| qf
tradeno | String | QFPay的唯一交易号 |
| pay_type | String | 支付方式代码 |
| txdtm | String | 支付时间(YYYY-MM-DD HH:mm:ss) |
签名验证
响应可能包含X-QF-SIGN和X-QF-SIGNTYPE头部。验证方法:
- 1. 按排序顺序提取数据字段
- 拼接为key1=value1&key2=value2&...
- 附加客户端密钥
- 生成MD5哈希并比较
签名生成
所有API请求必须在HTTP头部包含数字签名:
X-QF-SIGN:
分步指南
第1步:排序参数
按参数名称的ASCII升序对所有请求参数进行排序。
示例:
100 |
| txcurrcd | HKD |
排序结果:
mchid=ZaMVg12345&txamt=100&txcurrcd=HKD
第2步:附加客户端密钥
将您的密钥client_key附加到字符串末尾。
如果client_key = abcd1234:
mchid=ZaMVg12345&txamt=100&txcurrcd=HKDabcd1234
第3步:哈希字符串
使用MD5或SHA256进行哈希(推荐SHA256):
SHA256(mchid=ZaMVg12345&txamt=100&txcurrcd=HKDabcd1234)
第4步:添加到头部
X-QF-SIGN: hashedsignature>
重要提示
- - 不要插入换行符、制表符或额外空格
- 参数名称和值区分大小写
- 如果签名失败,请仔细检查参数顺序和编码
代码示例
Python
python
import os
import hashlib
APPCODE = os.getenv(QFPAY_APPCODE)
KEY = os.getenv(QFPAY_KEY)
def generate_signature(params, key):
生成MD5签名
keys = list(params.keys())
keys.sort()
query = []
for k in keys:
if k not in (sign, sign_type) and (params[k] or params[k] == 0):
query.append(f{k}={params[k]})
data = &.join(query) + key
md5 = hashlib.md5()
md5.update(data.encode(utf-8))
return md5.hexdigest().upper()
def generatesignaturesha256(params, key):
生成SHA256签名
keys = list(params.keys())
keys.sort()
query = []
for k in keys:
if k not in (sign, sign_type) and (params[k] or params[k] == 0):
query.append(f{k}={params[k]})
data = &.join(query) + key
sha256 = hashlib.sha256()
sha