Auto Debit
Auto Debit Description
After completing the contract with the user, funds can be directly deducted from the user's contracted wallet.
Auto Debit Rules
- The same contract can only be signed once per user. Repeated signing will return a failure.
- Both the merchant and user can terminate the contract after signing.
- Full refund after deduction will not return the remaining deduction times within the cycle.
- Auto debit currently only supports WeChat Pay.
- WeChat auto debit limits (please contact Business Development for specific limit details)
Auto Debit API
1. Auto Debit Signing
Request Parameters
| Parameter | Required | Type | Description | Example |
|---|---|---|---|---|
| appId | No | string | App ID, required if multiple apps are enabled for differentiation | wx123567 |
| agreementId | Yes | string | Contract ID, plan_id in WeChat scenario | 202301010001 |
| username | Yes | string(32) | Name of signing user for display, no URL encoding needed, parameter value does not support UTF8 non-3-byte encoded characters | Zhang San |
| vendor | Yes | string(16) | Payment channel, e.g. wechatpay | wechatpay |
| currency | Yes | string(3) | Currency code, e.g. USD | USD |
| notifyUrl | Yes | string | Async notification URL for receiving signing results | https://api.example.com/notify |
| returnUrl | No | string | Sync return URL, required for (H5, JSAPI) after signing | https://api.example.com/return |
| userId | No | string | User identifier, required when vendor=wechatpay for JSAPI, MINI_APP | oSC6Tw6SrhMMzMguby9cCqVzOo |
| platform | Yes | string | Platform type: WEB/H5 (web), APP (mobile app), MINI_APP (mini program), JSAPI (WeChat official account) | WEB |
| clientIp | No | string | Client IP address for risk control,required when vendor=wechatpay for H5 | 127.0.0.1 |
| reference | Yes | string(64) | Merchant unique identifier for this signing request | 202301010001 |
| remark | No | string | Remarks for additional signing info | Test signing |
Response Parameters
| Parameter | Required | Type | Description | Example |
|---|---|---|---|---|
| code | Yes | string | Return code, 00 for success, others for failure | 00 |
| label | Yes | string | Return code label | 00 |
| message | Yes | string | Return message describing operation result | success |
| agreementId | Yes | string | Contract ID, plan_id in WeChat scenario | 202301010001 |
| contractNo | Yes | string | Contract number, unique identifier for nihaopay contract | 202301010001 |
| signId | Yes | string | Signing URL, returns signId for APP/mini program, signUrl for WEB/H5 | 202501111159364508440 |
| signUrl | Yes | string | Signing ID, returns signId for APP/mini program, signUrl for WEB/H5 | https://api.example.com/sign |
Request ExampleScenario 1: WEB Signing
shell
curl --location 'https://api.nihaopay.com/v1.2/contract/sign' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <TOKEN>' \
--data '{
"appId": "your appId",
"agreementId": "your agreementId",
"usersame": "your customer name",
"vendor": "wechatpay",
"currency": "USD",
"notifyUrl": "https://YOUR_HOST/notify",
"returnUrl": "https://YOUR_HOST/callback",
"platform": "WEB",
"clientIp": "127.0.0.1",
"reference":"your unique reference",
"remark": "remark"
}'Failed Response Example
json
{
"code": "01",
"label": "01",
"message": "failed"
}Successful Response ExampleScenario 1: APP/Mini Program
json
{
"code": "00",
"label": "00",
"message": "success",
"agreementId": "your agreementId",
"contractNo": "our contractNo",
"signId": "xxxxxxxx"
}Scenario 2: JSAPI/WEB/H5
json
{
"code": "00",
"label": "00",
"message": "success",
"agreementId": "your agreementId",
"contractNo": "our contractNo",
"signUrl": "https://api.mch.weixin.qq.com/global/papay/contracts/login?os_session_id=xxx#wechat_pay"
}2. Auto Debit Termination
Request Parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
| agreementId | Optional | string | Contract ID, plan_id in WeChat scenario |
| reference | Optional | string(64) | Merchant unique identifier |
| reason | Yes | string | Termination reason |
| contractNo | Optional | string | Contract number, unique identifier for nihaopay contract, reference+agreementId and contractNo cannot be empty at the same time |
Response Parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
| code | Not null | string | Return code, 00 for success |
| label | Not null | string | Return code label |
| message | Not null | string | Return message |
| contractId | Not null | string | Contract ID |
| contractNo | Not null | string | Contract number, unique identifier for nihaopay contract |
| reference | Not null | string | Merchant unique identifier |
Request ExampleUsing agreementId + reference
shell
curl --location 'https://api.nihaopay.com/v1.2/contract/terminate' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <TOKEN>' \
--data '{
"agreementId": "your agreementId",
"reference": "your unique reference",
"reason": "your terminate reason"
}'Using contractNo
shell
curl --location 'https://api.nihaopay.com/v1.2/contract/terminate' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <TOKEN>' \
--data '{
"contractNo": "d649252400014ea7a8a890704cc600d6",
"reason": "your terminate reason"
}'Successful Response Example
json
{
"code": "00",
"label": "00",
"message": "success",
"contractId": "contract id",
"contractNo": "our contract number",
"reference": "your unique reference"
}Failed Response Example
json
{
"code": "01",
"label": "01",
"message": "failed"
}3. Auto Debit Contract Query
Request Parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
| agreementId | Optional | string | Contract ID, plan_id in WeChat scenario |
| reference | Optional | string(64) | Merchant unique identifier |
| contractNo | Optional | string | Contract number, unique identifier for nihaopay contract, reference+agreementId and contractNo cannot be empty at the same time |
Response Parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
| code | Not null | string | Return code, 00 for success |
| label | Not null | string | Return code label |
| message | Not null | string | Return message |
| contractId | Not null | string | Contract ID |
| contractNo | Not null | string | Contract number, unique identifier for nihaopay contract |
| contractStatus | Not null | string | Contract status: Signed (signed), Terminated (terminated), Processing (pending signing), FAIL (signing failed) |
| signedTime | May be null | string | Signing time |
| terminateTime | May be null | string | Termination time |
| terminateMode | May be null | string | Termination mode: USER (user initiated), MERCHANT (merchant initiated), PLATFORM (platform initiated) |
Request ExampleScenario: agreementId + reference
shell
curl --location 'https://api.nihaopay.com/v1.2/contract/query' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <TOKEN>' \
--data '{
"agreementId": "your agreementId",
"reference": "your unique reference"
}'Scenario: contractNo
shell
curl --location 'https://api.nihaopay.com/v1.2/contract/query' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <TOKEN>' \
--data '{
"contractNo": "d649252400014ea7a8a890704cc600d6"
}'Response Example
json
{
"code": "00",
"label": "00",
"message": "success",
"contractId": "contract id",
"contractNo": "our contract number",
"contractStatus": "Signed/Terminated",
"signedTime": "2025-01-15 19:15:14",
"terminateTime": "2025-01-15 19:15:14",
"terminateMode": "USER/MERCHANT/PLATFORM",
}4. Initiate Deduction
Request Parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
| amount | Not null | string | Deduction amount |
| currency | Not null | string(3) | Currency code, e.g. USD |
| note | Optional | string | Order remarks |
| description | Not null | string | Deduction description (visible to user) |
| ipn_url | Not null | string | Async notification URL |
| reference | Not null | string(64) | Merchant unique identifier |
| vendor | Not null | string(16) | Payment channel, e.g. wechatpay |
| contract_id | Not null | string | Contract ID, can be obtained from signing callback or query API |
Response Parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
| status | Not null | string | Transaction status: success/failure |
| reference | Not null | string | Merchant order number |
| currency | Not null | string(3) | Transaction currency, e.g. USD |
| amount | Not null | decimal | Transaction amount |
| rmb_amount | Not null | decimal | RMB amount |
| id | Not null | string | Transaction ID |
| note | May be null | string | Order remarks |
| time | Not null | string | Transaction time in UTC format |
| message | Not null | string | Transaction result description |
Request Example
shell
curl --location 'https://api.nihaopay.com/v1.2/transactions/autodebit' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <TOKEN>' \
--data '{
"amount": "1",
"currency": "USD",
"note": "your order note",
"description": "<your debit description>",
"ipn_url": "<your ipn url>",
"reference": "<your unique reference>",
"vendor": "wechatpay",
"contract_id": "<your contract id>"
}'Successful Response Example
json
{
"status": "success",
"reference": "<your unique reference>",
"currency": "USD",
"amount": 1,
"rmb_amount": 0,
"id": "20250111220054100012",
"note": "autodebit test",
"time": "2025-01-11T22:00:54Z",
"message": ""
}Failed Response Example
json
{
"status": "failure",
"reference": "<your unique reference>",
"currency": "USD",
"amount": 1,
"rmb_amount": 0,
"id": "20250111220054100012",
"note": "autodebit test",
"time": "2025-01-11T22:00:54Z",
"message": "User account payment limit reached"
}Contract Status Async Notification
Notification Parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
| agreementId | Not null | string | Contract ID, plan_id in WeChat scenario |
| userId | Not null | string | User ID, open_id in WeChat scenario |
| contractId | Not null | string | Contract ID, required for initiating deductions |
| contractNo | Not null | string | Contract number, unique identifier for nihaopay contract |
| reference | Not null | string | Merchant unique identifier |
| contractStatus | Not null | string | Status: Signed (signed), Terminated (terminated), Processing (pending signing), FAIL (signing failed) |
| signedAt | May be null | string | Signing time, required for signing notifications |
| terminateAt | May be null | string | Termination time, required for termination notifications |
| terminateMode | May be null | string | Termination mode, required for termination notifications: USER (user initiated), MERCHANT (merchant initiated), PLATFORM (platform initiated) |
Signing Notification Example
shell
curl -X POST ${YOUR_NOTIFY_URL} \
--header 'Content-Type: application/json' \
--header 'Signature: ${signature}' \
--data '{
"agreementId": "your agreementId",
"userId": "contract user id",
"contractId": "contract id",
"contractNo": "our contract number",
"reference": "your unique reference",
"contractStatus": "Signed/Terminated",
"signedAt": "yyyy-MM-dd'T'HH:mm:ss.SSSZZZ",
"terminateAt": "yyyy-MM-dd'T'HH:mm:ss.SSSZZZ",
"terminateMode": "USER/MERCHANT/PLATFORM",
}'Signing Notification Signature
signature = MD5(body + '&' + MD5(token))
Callback Notification Retry Mechanism
- Maximum of 7 notifications
- Notification intervals: 0m,1m,2m,4m,8m,20m,30m
