Skip to content

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 ​

  1. The same contract can only be signed once per user. Repeated signing will return a failure.
  2. Both the merchant and user can terminate the contract after signing.
  3. Full refund after deduction will not return the remaining deduction times within the cycle.
  4. Auto debit currently only supports WeChat Pay.
  5. WeChat auto debit limits (please contact Business Development for specific limit details)

Auto Debit API ​

1. Auto Debit Signing ​

Request Parameters ​

ParameterRequiredTypeDescriptionExample
appIdNostringApp ID, required if multiple apps are enabled for differentiationwx123567
agreementIdYesstringContract ID, plan_id in WeChat scenario202301010001
usernameYesstring(32)Name of signing user for display, no URL encoding needed, parameter value does not support UTF8 non-3-byte encoded charactersZhang San
vendorYesstring(16)Payment channel, e.g. wechatpaywechatpay
currencyYesstring(3)Currency code, e.g. USDUSD
notifyUrlYesstringAsync notification URL for receiving signing resultshttps://api.example.com/notify
returnUrlNostringSync return URL, required for (H5, JSAPI) after signinghttps://api.example.com/return
userIdNostringUser identifier, required when vendor=wechatpay for JSAPI, MINI_APPoSC6Tw6SrhMMzMguby9cCqVzOo
platformYesstringPlatform type: WEB/H5 (web), APP (mobile app), MINI_APP (mini program), JSAPI (WeChat official account)WEB
clientIpNostringClient IP address for risk control,required when vendor=wechatpay for H5127.0.0.1
referenceYesstring(64)Merchant unique identifier for this signing request202301010001
remarkNostringRemarks for additional signing infoTest signing

Response Parameters ​

ParameterRequiredTypeDescriptionExample
codeYesstringReturn code, 00 for success, others for failure00
labelYesstringReturn code label00
messageYesstringReturn message describing operation resultsuccess
agreementIdYesstringContract ID, plan_id in WeChat scenario202301010001
contractNoYesstringContract number, unique identifier for nihaopay contract202301010001
signIdYesstringSigning URL, returns signId for APP/mini program, signUrl for WEB/H5202501111159364508440
signUrlYesstringSigning ID, returns signId for APP/mini program, signUrl for WEB/H5https://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 ​

ParameterRequiredTypeDescription
agreementIdOptionalstringContract ID, plan_id in WeChat scenario
referenceOptionalstring(64)Merchant unique identifier
reasonYesstringTermination reason
contractNoOptionalstringContract number, unique identifier for nihaopay contract, reference+agreementId and contractNo cannot be empty at the same time

Response Parameters ​

ParameterRequiredTypeDescription
codeNot nullstringReturn code, 00 for success
labelNot nullstringReturn code label
messageNot nullstringReturn message
contractIdNot nullstringContract ID
contractNoNot nullstringContract number, unique identifier for nihaopay contract
referenceNot nullstringMerchant 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 ​

ParameterRequiredTypeDescription
agreementIdOptionalstringContract ID, plan_id in WeChat scenario
referenceOptionalstring(64)Merchant unique identifier
contractNoOptionalstringContract number, unique identifier for nihaopay contract, reference+agreementId and contractNo cannot be empty at the same time

Response Parameters ​

ParameterRequiredTypeDescription
codeNot nullstringReturn code, 00 for success
labelNot nullstringReturn code label
messageNot nullstringReturn message
contractIdNot nullstringContract ID
contractNoNot nullstringContract number, unique identifier for nihaopay contract
contractStatusNot nullstringContract status: Signed (signed), Terminated (terminated), Processing (pending signing), FAIL (signing failed)
signedTimeMay be nullstringSigning time
terminateTimeMay be nullstringTermination time
terminateModeMay be nullstringTermination 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 ​

ParameterRequiredTypeDescription
amountNot nullstringDeduction amount
currencyNot nullstring(3)Currency code, e.g. USD
noteOptionalstringOrder remarks
descriptionNot nullstringDeduction description (visible to user)
ipn_urlNot nullstringAsync notification URL
referenceNot nullstring(64)Merchant unique identifier
vendorNot nullstring(16)Payment channel, e.g. wechatpay
contract_idNot nullstringContract ID, can be obtained from signing callback or query API

Response Parameters ​

ParameterRequiredTypeDescription
statusNot nullstringTransaction status: success/failure
referenceNot nullstringMerchant order number
currencyNot nullstring(3)Transaction currency, e.g. USD
amountNot nulldecimalTransaction amount
rmb_amountNot nulldecimalRMB amount
idNot nullstringTransaction ID
noteMay be nullstringOrder remarks
timeNot nullstringTransaction time in UTC format
messageNot nullstringTransaction 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 ​

ParameterRequiredTypeDescription
agreementIdNot nullstringContract ID, plan_id in WeChat scenario
userIdNot nullstringUser ID, open_id in WeChat scenario
contractIdNot nullstringContract ID, required for initiating deductions
contractNoNot nullstringContract number, unique identifier for nihaopay contract
referenceNot nullstringMerchant unique identifier
contractStatusNot nullstringStatus: Signed (signed), Terminated (terminated), Processing (pending signing), FAIL (signing failed)
signedAtMay be nullstringSigning time, required for signing notifications
terminateAtMay be nullstringTermination time, required for termination notifications
terminateModeMay be nullstringTermination 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 ​

  1. Maximum of 7 notifications
  2. Notification intervals: 0m,1m,2m,4m,8m,20m,30m

Last Updated - 01/16/2025