Skip to content

分账 ​

分账功能描述 ​

分账功能是指将支付订单款项中的一部分金额支付给其他收款方商户的功能。分账分为两种:

  • 指定订单分账:对某一笔支付订单(传 relationTxnId)进行分账.
  • 全局分账:不传 relationTxnId,对之后每天清算的支付订单按配置自动分账.

分账申请提交后不会立即执行,而是在每天的日结中执行,执行结果通过回调通知,也可以通过查询当前分账执行结果获取.

分账规则 ​

  1. 币种:分账币种必须与支付订单的结算币种一致,不支持跨币种分账.全局分账的币种必须是源商户已开通的结算币种.
  2. 收款方:收款方商户(targetMerCode)必须是状态正常的商户,并且已开通分账币种的结算账户.源商户和收款方商户不能相同.
  3. 渠道:只有自收款渠道的支付订单支持分账.对非自收款渠道的订单发起指定订单分账会被拒绝,全局分账会自动跳过这类订单.可分账的渠道请联系 BD 确认.
  4. 全局分账:同一源商户、同一收款方、同一币种只能有一条生效中的全局分账.全局分账只对配置生效期间、当日日结清算的支付订单执行,不会追溯已经清算的历史订单.
  5. 不能叠加:同一笔支付订单只能使用全局分账或指定订单分账中的一种.已经执行过全局分账的订单不能再发起指定订单分账;当日有待执行的指定订单分账的订单,全局分账会跳过.
  6. 金额:对支付订单的分账可以执行多次,但累计分账金额不能超过原支付订单的可分账金额(净结算金额减去已退款金额和已分账金额).分账金额按币种精度舍入,低于 0.01 的分账会失败.
  7. 执行时间:每天北京时间 23:00(UTC 15:00)开始执行.指定订单分账在支付订单完成清算后才会执行,在此之前保持待分账状态.分账成功后状态变更为成功,分账失败后状态变更为失败.
  8. 取消:待分账的指定订单分账和生效中的全局分账可以取消.北京时间 23:00 至次日 02:00(UTC 15:00 至 18:00)分账执行期间不能取消,请在执行完成后使用撤销分账.已成功的分账不能取消,只能撤销.
  9. 撤销:只能撤销自己发起的、已成功的分账,待分账状态的分账不能撤销.可以一次全额撤销,也可以多次部分撤销,累计撤销金额不能超过原分账的到手金额.
  10. 手续费:分账和撤销分账分别按发起方的分账费率、撤销分账费率收取手续费,四舍五入到币种精度.如果原分账费率配置了退还手续费,撤销时按撤销金额占原分账金额的比例退还原分账手续费.未配置分账费率时分账会失败,请联系 BD 开通.
  11. 由于分账会产生手续费,无论是分账还是撤销分账,累计总金额都不能超过原支付订单或原分账扣除手续费后的金额,你可能需要将手续费设置为从源账户扣除.
  12. 权限:商户只能对自己的支付订单进行分账.平台型商户可以对所属商户的支付订单发起分账(通过 sourceMerCode 指定所属商户),可代理的商户见查询可代理分账的商户.
  13. 次数:每笔支付订单最多 50 次分账,每笔分账最多撤销 10 次.

分账的实际效果说明 ​

前置条件 ​

  1. 支付订单 100 美元,平台收取手续费 2 美元,商户 A 实际结算到手 98 美元.
  2. 商户 A 发起分账,分账比例为 10%到商户 B(基准金额为支付订单净结算金额 98 美元).
  3. 支付手续费费率 2%,分账手续费费率 2%.
  4. 手续费四舍五入到分:9.80 × 2% = 0.196,记为 0.20.

场景 1 手续费从交易中扣除 ​

账户分账金额手续费到手金额
商户 A-9.800.00-9.80
商户 B9.800.209.60

场景 2 手续费从源账户扣除 ​

账户分账金额手续费到手金额
商户 A-9.800.20-10.00
商户 B9.800.009.80

撤销分账的实际效果说明 ​

前置条件 ​

  1. 支付订单 100 美元,平台收取手续费 2 美元,商户 A 实际结算到手 98 美元.
  2. 商户 A 发起分账,分账比例为 10%到商户 B,手续费 2%.
  3. 商户 A 发起全额撤销分账(不传 splitMethod/splitValue),撤销金额为原分账的到手金额,注意原分账有可能因为扣除手续费,导致不能按原金额撤销.
  4. 支付手续费费率 2%,分账手续费费率 2%,撤销分账手续费费率 2%,原分账费率未配置退还手续费.
  5. 撤销分账的 feeFrom 需要在撤销请求中单独指定,下面两个场景中撤销请求和原分账的 feeFrom 相同.

场景 1 手续费从交易中扣除 ​

账户分账金额手续费到手金额
商户 A-9.800.00-9.80
商户 B9.800.209.60
商户 A9.600.199.41
商户 B-9.600.00-9.60

场景 2 手续费从源账户扣除 ​

账户分账金额手续费到手金额
商户 A-9.800.20-10.00
商户 B9.800.009.80
商户 A9.800.009.80
商户 B-9.800.20-10.00

固定金额分账金额说明 ​

  1. JPY,KRW,VND 等常见货币的最小单位是元,当 currency 是这些货币时,splitValue 的单位是元,例如 splitValue=1000,即分账 1000 元.
  2. USD,CNY 等常见货币的最小单位是分,当 currency 是这些货币时,splitValue 的单位是分,例如 splitValue=1023,即分账 10.23 元.
  3. 查询结果和回调中的金额字段也使用货币的最小单位.

参数说明 ​

参数是否必须类型说明
reference不为空string(240)分账发起方单号,分账配置唯一性判断依据.只能包含字母、数字和 _ . : -
sharingType不为空int0:分账,2:撤销分账
splitMethod有条件int0: 百分比分账, 1:固定金额分账.分账时必须;撤销分账时可选,不传则全额撤销
splitValue有条件int当 splitMethod=0 时为分账百分比,精度万分之一,取值 1 至 9999,例如传 1023 即为 10.23%
当 splitMethod=1 时为实际分账金额(货币的最小单位)币种规则
分账时必须;撤销分账时与 splitMethod 一起传
targetMerCode有条件string(11)分账的收款方商户,分账时必须.撤销分账时不需要传,与原分账相同
sourceMerCode可选string(11)分账的资金来源商户,不传则为当前商户.指定订单分账时必须与支付订单所属商户一致;为其他商户分账时,当前商户必须是该商户的平台商户
currency有条件string(3)分账币种,例如 USD,CNY 等,分账时必须,且必须与支付订单的结算币种一致.撤销分账时不需要传,与原分账相同
relationTxnId有条件string(21)要分账的支付订单 id, nihaopay 的 transactionId.分账时不传表示全局分账配置,生产环境请谨慎配置;撤销分账时必须
remark可选string(128)备注, 在查看订单详情时会出现在订单描述的位置.只能包含字母、数字、_ . : - 和汉字,不能包含空格和中文标点
feeFrom可选int0:手续费从交易中扣除(收款方承担)
1:手续费从源账户扣除
默认 0
baseFrom可选int按百分比计算时的基准金额
0: 原支付订单的净结算金额
1: 原分账的分账金额(仅撤销分账时有效)
2: 原支付订单的订单金额
默认 0.按百分比部分撤销时,通常应传 1
originConfId有条件string(21)撤销分账时必须,要撤销的原分账配置 id
notifyUrl可选string(256)分账结果回调通知地址,失败或成功都会通知,数据格式.必须是 http 或 https 地址,且可以从公网访问

分账接口 ​

postman 配置下载

场景:发起全局按比例分账

shell
curl --location 'https://api.nihaopay.com/v1.2/sharing/apply' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <TOKEN>' \
--data '{
    "sharingType": 0,
    "splitMethod": 0,
    "splitValue": 10,
    "reference": "20211111153109001472",
    "targetMerCode": "M001000001",
    "currency": "USD",
    "remark": "test_remark",
    "notifyUrl": "https://www.nihaopay.com/sharing/notify"
}'

场景:对指定订单发起按比例分账

shell
curl --location 'https://api.nihaopay.com/v1.2/sharing/apply' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <TOKEN>' \
--data '{
    "relationTxnId": "20211111153109001472",
    "sharingType": 0,
    "splitMethod": 0,
    "splitValue": 1000,
    "targetMerCode": "M001000001",
    "reference": "20211111153109001472",
    "remark": "test_remark",
    "notifyUrl": "https://www.nihaopay.com/sharing/notify",
    "currency": "USD"
}'

场景:对指定订单发起固定金额分账

shell
curl --location 'https://api.nihaopay.com/v1.2/sharing/apply' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <TOKEN>' \
--data '{
    "relationTxnId": "20211111153109001472",
    "sharingType": 0,
    "splitMethod": 1,
    "splitValue": 100,
    "targetMerCode": "M001000001",
    "reference": "20211111153109001472",
    "remark": "test_remark",
    "notifyUrl": "https://www.nihaopay.com/sharing/notify",
    "currency": "USD"
}'

场景:对分账发起部分撤销分账(撤销原分账金额的 50%)

shell
curl --location 'https://api.nihaopay.com/v1.2/sharing/apply' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <TOKEN>' \
--data '{
    "relationTxnId": "20211111153109001472",
    "sharingType": 2,
    "splitMethod": 0,
    "splitValue": 5000,
    "baseFrom": 1,
    "reference": "20211111153109001473",
    "remark": "test_remark",
    "notifyUrl": "https://www.nihaopay.com/sharing/notify",
    "originConfId": "20211111153109001472"
}'

场景:对分账发起全额撤销分账

shell
curl --location 'https://api.nihaopay.com/v1.2/sharing/apply' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <TOKEN>' \
--data '{
    "relationTxnId": "20211111153109001472",
    "sharingType": 2,
    "reference": "20211111153109001474",
    "remark": "test_remark",
    "notifyUrl": "https://www.nihaopay.com/sharing/notify",
    "originConfId": "20211111153109001472"
}'

分账发起成功响应

json
{
  "confId": "20230804021118097285"
}

分账发起失败响应

json
{
  "code": 400,
  "label": "N/A",
  "message": "sharing config already exist"
}

申请时的常见失败原因:

message说明
reference is invalid / remark is invalid / notifyUrl is invalid参数格式不符合要求
relation transaction currency not match分账币种与支付订单的结算币种不一致
source merchant has no settlement account in sharing currency全局分账的源商户没有该币种的结算账户
target merchant has no settlement account in sharing currency收款方商户没有该币种的结算账户
targetMerCode not exist / targetMerCode is not active收款方商户不存在或状态异常
channel provider not support sharing支付订单的渠道不支持分账(非自收款渠道)
transaction already shared by global sharing config支付订单已经执行过全局分账,不能再做指定订单分账
no transaction sharing permission没有为该商户分账的权限
sharing config already exist分账配置重复
reverse amount exceed available amount撤销金额超过可撤销金额

查询当前分账配置 ​

只返回当前商户发起的、状态为待分账(APPLY)或成功/生效中(SUCCESS)的分账配置,最多 50 条.已取消和失败的分账不会返回,失败原因请通过查询当前分账执行结果或回调获取.

参数是否必须类型说明
relationTxnId可选string(21)支付订单 id
originConfId可选string(21)原分账配置 id(查询撤销分账)
reference可选string分账发起方单号
sharingType可选int0:分账,2:撤销分账
currency可选string(3)分账币种

查询所有分账配置

shell
curl --location 'https://apitest.nihaopay.com/v1.2/sharing/query' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <TOKEN>' \
--data '{}'

查询指定支付订单的分账配置

shell
curl --location 'https://apitest.nihaopay.com/v1.2/sharing/query' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <TOKEN>' \
--data '{
    "relationTxnId": "20230804021118097285"
}'

分账配置成功响应

json
{
  "sharingConfItems": [
    {
      "confId": "20230804021822097288",
      "reference": "9200",
      "originConfId": "",
      "relationTxnId": "20230804021118097285",
      "sourceMerCode": "M001000001",
      "targetMerCode": "M001000002",
      "sharingType": 0,
      "splitMethod": 0,
      "splitValue": 22,
      "sharingCurrency": "USD",
      "txnStatus": "SUCCESS",
      "failReason": "",
      "feeFrom": 0,
      "baseFrom": 0,
      "remark": "test",
      "notifyUrl": "https://www.nihaopay.com/sharing/notify"
    }
  ]
}

没有符合条件的分账配置

json
{
  "sharingConfItems": []
}

查询当前分账执行结果 ​

查询某个分账配置对某笔支付订单的执行结果.relationTxnId 和 confId 都必须传;全局分账会对多笔订单执行,请传具体的支付订单 id.结果最多缓存 1 小时.

参数是否必须类型说明
relationTxnId不为空string(21)支付订单 id
confId不为空string(21)分账配置 id

请求示例

shell
curl --location 'https://apitest.nihaopay.com/v1.2/sharing/detail' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <TOKEN>' \
--data '{
    "relationTxnId": "20230804021118097285",
    "confId": "20230804021822097288"
}'

成功响应示例(分账执行成功)

json
{
  "txnType": "SHARE_PROFIT",
  "sharingStatus": "SUCCESS",
  "reference": "9200",
  "sharingType": 0,
  "relationTxnId": "20230804021118097285",
  "sharingConfId": "20230804021822097288",
  "sourceMerCode": "M001000001",
  "targetMerCode": "M001000002",
  "sharingCurrency": "USD",
  "txnCurrency": "USD",
  "exchangeRate": 1.0,
  "baseAmount": 13075,
  "sourceSharingTxnAmount": -29,
  "targetSharingTxnAmount": 29,
  "sourceServiceFee": 0,
  "targetServiceFee": 1,
  "feeRate": {
    "refundReturn": false,
    "rateAlgorithm": 0,
    "percentage": 2,
    "fixedAmount": 0,
    "minAmount": 0,
    "maxAmount": 0,
    "extraRefundFee": 0
  }
}

成功响应示例(分账执行失败)

json
{
  "txnType": "SHARE_PROFIT",
  "sharingStatus": "FAIL",
  "reference": "9200",
  "sharingType": 0,
  "relationTxnId": "20230804021118097285",
  "sharingConfId": "20230804021822097288",
  "sourceMerCode": "M001000001",
  "targetMerCode": "M001000002",
  "sharingCurrency": "USD",
  "failReason": "sharing amount more than available amount"
}

失败响应示例(尚未执行或不存在)

json
{
  "code": 400,
  "label": "N/A",
  "message": "sharing history not exist"
}

响应字段说明:

字段说明
txnTypeSHARE_PROFIT:分账,SHARE_REVERSE:撤销分账
sharingStatusSUCCESS:成功,FAIL:失败
baseAmount按比例计算时的基准金额(货币最小单位)
sourceSharingTxnAmount / targetSharingTxnAmount源商户 / 收款方的分账金额(货币最小单位,负数表示扣款)
sourceServiceFee / targetServiceFee源商户 / 收款方承担的手续费(货币最小单位)
feeRate本次使用的费率,percentage 单位为 %
originSharingConfId仅撤销分账返回,原分账配置 id
failReason仅失败时返回,失败原因,见分账回调中的常见失败原因

取消分账 ​

待分账的指定订单分账和生效中的全局分账可以取消.北京时间 23:00 至次日 02:00(UTC 15:00 至 18:00)分账执行期间不能取消,已成功的分账只能撤销.

请求

shell
curl --location 'https://apitest.nihaopay.com/v1.2/sharing/cancel' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <TOKEN>' \
--data '{
    "confId": "20230719002724096890"
}'

成功响应

json
{
  "confId": "20230719002724096890",
  "reason": "",
  "txnStatus": "SUCCESS"
}

失败响应

json
{
  "confId": "20230719002724096890",
  "reason": "sharing config not exist",
  "txnStatus": "FAIL"
}

常见失败原因(reason):

reason说明
sharing config not exist分账配置不存在
sharing config not belong to merchant不是当前商户发起的分账配置
cancel is not allowed between 23:00 and 02:00 ...分账执行期间不能取消,请执行完成后撤销
sharing operation was success,cannot cancel分账已成功,只能撤销
operation failed, please check the transaction status.分账配置状态已变化(例如已取消或已失败)

查询可代理分账的商户 ​

平台型商户查询可以代为发起分账的所属商户列表.

请求

shell
curl --location 'https://apitest.nihaopay.com/v1.2/sharing/merchants' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <TOKEN>' \
--data '{}'

响应

json
{
  "merchants": [
    { "merCode": "M001000001" },
    { "merCode": "M001000002" }
  ]
}

分账回调 ​

每笔分账执行后(成功或失败)会向 notifyUrl 以 JSON 格式 POST 通知:

  1. 通知只发送一次,不会重试;请求超时时间为 10 秒,不跟随重定向.
  2. 返回 HTTP 2xx 视为通知成功.
  3. notifyUrl 必须可以从公网访问,内网地址不会收到通知.
  4. 回调不带签名,收到回调后请通过查询当前分账执行结果确认结果.
  5. 金额字段为结算币种的最小单位;rate.percentage 的单位为 %.
  6. 撤销分账的回调中 txnType 为 SHARE_REVERSE,sourceMerCode 为原分账的收款方(被扣回的一方),targetMerCode 为原分账的源商户,并额外返回 originSharingConfId、originSharingType、originRate.

分账成功回调

json
{
  "sharingStatus": "SUCCESS",
  "txnType": "SHARE_PROFIT",
  "sharingType": 0,
  "reference": "TEST_20230803211516007112",
  "sharingConfId": "20230803211516007112",
  "relationTxnId": "20230803211516007111",
  "sourceMerCode": "M001100001",
  "targetMerCode": "M086100129",
  "txnCurrency": "USD",
  "stlCurrency": "USD",
  "sharingCurrency": "USD",
  "exchangeRate": 1.0,
  "baseAmount": 2496,
  "sourceSharingTxnAmount": -499,
  "targetSharingTxnAmount": 499,
  "sourceServiceFee": 0,
  "targetServiceFee": 10,
  "rate": {
    "minAmount": 0,
    "percentage": 2,
    "txnCurrency": "USD",
    "refundReturn": 0,
    "fixedAmount": 0,
    "maxAmount": 0
  }
}

分账失败回调

json
{
  "sharingStatus": "FAIL",
  "txnType": "SHARE_PROFIT",
  "sharingType": 0,
  "reference": "TEST_20230803211516007112",
  "sharingConfId": "20230803211516007112",
  "relationTxnId": "20230803211516007111",
  "sourceMerCode": "M001100001",
  "targetMerCode": "M086100129",
  "txnCurrency": "USD",
  "stlCurrency": "USD",
  "sharingCurrency": "USD",
  "failReason": "sharing amount more than available amount"
}

执行时的常见失败原因(failReason):

failReason说明
rate not found发起方未配置分账费率,请联系 BD
sharing amount more than available amount分账金额超过支付订单剩余可分账金额
sharing amount less than minimum amount分账金额低于 0.01
sharing currency not match settlement currency分账币种与支付订单的结算币种不一致
transaction already shared by global sharing config支付订单已经执行过全局分账
target merchant is not active / target merchant not exist收款方商户状态异常或不存在
target merchant has no settlement account in sharing currency收款方商户没有该币种的结算账户
sharing reverse amount more than origin sharing amount撤销金额超过原分账剩余可撤销金额

最后更新 - 01/16/2025