# NihaoPay API Documentation (zh) - full text Base URL: https://api.nihaopay.com/v1.2 Index: https://docs.nihaopay.com/llms.txt # 版本 > **API Version** ```shell /v1.2 ``` 我们的产品,服务和API也在不断改进,以更好的适应客户的需求。为帮助客户追踪API变更,我们的API使用版本区分,当前最新的版本是1.2 (`v1.2`)。 要指定版本,只需要将版本号添加到资源命名空间之前。例如,要使用版本1.2,完整的请求路径应该是:`https://api.nihaopay.com/v1.2/transactions`。 # 认证 > **请求示例** ```shell $ curl https://api.nihaopay.com/v1.2/transactions \ -H "Authorization: Bearer " ``` > 请将示例中的 \ 替换成你自己的API Token。 所有的 API 请求必须通过 HTTPS 发送,并提供API Token作为身份验证。您可以在[商户交易管理平台(TMS)](https://tms.nihaopay.com)的设置 -> 证书管理内下载或管理您的API Token. 名称 | 描述 ------ | ----------- **Authorization**
必须| 设置`Bearer` 加API Token 作为认证方式 如果您的API Token已泄漏,请在商户管理后台重新生成。一旦您重新生成新的API Token,旧的API Token将立即作废,请及时修改您请求API使用的Token,保证所有接口正常使用。 # 接口说明 ## 支付模式 NihaoPay提供在五种支付模式,分别是安全支付,信用卡快捷支付,In-APP支付,支付二维码和线下扫码支付。

安全支付

安全支付是指客户付款时页面跳转到付款渠道方,并在付款渠道方的支付页面完成订单支付的模式。

APP支付

APP支付是商户通过在移动端应用APP中集成SDK调起支付宝或者银联支付模块完成付款的模式。

支付二维码

支付二维码是指API返回商户一个包含二维码URL的对象,商户将二维码URL图像化展示在网页或者终端设备上,用户打开微信或者支付宝扫描二维码完成支付的模式。

扫码支付

扫码支付是商家使用带摄像头或者其他扫码功能的终端扫描用户展示的二维码,并完成扣款。 ### 以下产品请参考[MuskPay API Documentation](https://docs.muskpay.io/)

卡支付(CardPay)

卡支付是指商户在网站的付款页面收集客户的信用卡等信息,请求API直接完成支付的模式,该模式要求商户的网站需通过PCI认证。 ## 应用场景 在不同的应用场景中,根据付款方式的不同,支付模式的应用参见下表: | 付款方式 →
应用场景 ↓ | 支付宝
AliPay | 微信支付
WechatPay | 银联
UnionPay| | ------------------------------ | -------------------- | ----------------------- | ---------------- | | PC 浏览器
`terminal=ONLINE`| [标准安全支付](./securepay#标准安全支付) | [标准安全支付](./securepay#标准安全支付)
[微信二维码](./securepay#获取付款二维码) | [标准安全支付](./securepay#标准安全支付)
[信用卡支付](https://docs.muskpay.io/) | | 手机浏览器
`terminal=WAP`| [标准安全支付](./securepay#标准安全支付) | [微信H5支付](./securepay#标准安全支付)
请联系BD开启 | [标准安全支付](./securepay#标准安全支付)
[信用卡支付](https://docs.muskpay.io/) | | 微信浏览器
`terminal=WAP`| NA | [标准安全支付](./securepay#标准安全支付) | [标准安全支付](./securepay#标准安全支付)
[信用卡支付](https://docs.muskpay.io/) | | In-APP| [APP支付](./securepay#in-app支付)| [APP支付](./securepay#in-app支付)
接入前请先提供AppID | [APP支付](./securepay#in-app支付) | | 微信小程序| NA| [微信小程序支付](./securepay#微信小程序支付)
接入前请先提供小程序AppID | NA | | 线下商户主扫
|[扫码支付](./offline#扫码支付)| [扫码支付](./offline#扫码支付) | [扫码支付](./offline#扫码支付)
仅限美国地区商户 | | 线下商户被扫
| [展示二维码](./offline#展示交易二维码)
[固定二维码](./offline#多合一固定收款码)| [展示二维码](./offline#展示交易二维码)
[固定二维码](./offline#多合一固定收款码) | [展示二维码](./offline#展示交易二维码)
仅限美国地区商户 | ## 接口规则 ### 1.金额 接口中包含的金额精确到币种的最小单位,参数值中不能带小数点。如1.00美元,在接口请求是应该上送100. ### 2.币种 NihaoPay支持的币种取值列表: * USD:美元 * JPY:日元 * GBP:英镑 * EUR:欧元 * HKD:港币 * CAD:加拿大元 * SGD:新加坡元 * AUD:澳大利亚元 ### 3.人民币金额 针对商户标价为人民币的订单,可以使用`rmb_amount`这个参数来替换`amount`, NihaoPay根据付款渠道方提供的当前汇率将人民币金额转化对应的外币金额,并在支付成功后返回转换后的外币金额。 | 请求 | 返回 | 说明 | | ------------------------------ | -------------------- | ----------------------- | | `rmb_amount=10000`
`currency=USD`| `rmb_amount=10000`
`amount=1441`
`currency=USD` | 订单金额为100元人民币,记账金额为14.41美元 | | `amount=10000`
`currency=USD`| `amount=10000`
`currency=USD` | 订单金额为100美元 | ### 4.商户订单号 商户订单号由商户自己生成,NihaoPay要求商户订单号保持唯一性,对于未支付的订单使用原订单号重新发起支付时,要避免重复支付,已支付成功的订单号不能再次发起支付。 ### 5.订单商品信息 > **form 请求参数示例** ```shell items[0][name]=T-Shirt&items[0][unitAmount]=500&items[0][quantity]=1&items[1][name]=Hat&items[1][unitAmount]=500&items[1][quantity]=2 ``` `items` 是一个数组,每个元素代表一个商品。数组中的每个元素包含以下字段: | 字段名称 | 描述 | | -------- | ---- | | **items** | **商品信息列表**,包含一个或多个商品对象。 | | **items[n].name**
`不为空` | **商品名称**。 | | **items[n].unitAmount**
`不为空` | **商品单价信息,与订单currency对应。金额为对应货币中的最小单位。详见[接口规则](#接口规则)。** | | **items[n].quantity**
`不为空` | **商品数量**。 | 商品总金额应等于订单总金额: `amount = (items[0].unitAmount * items[0].quantity + items[1].unitAmount * items[1].quantity + ...)` ### 6.付款方式 目前NihaoPay支持的付款方式包括: `alipay`:支付宝 `wechatpay`:微信支付 `unionpay`:银联 ### 7. 通知URL 接口中`callback_url`必须是在Internet中可以访问的地址,不能是内网地址(如`localhost`)或内网IP。在处理callback和ipn的返回时,IPN通知可能比Callback返回先到达。 默认仅支付成功会跳转`callback_url`,如果商户希望其他状态也跳转,请在`callback_url`上增加参数`accept`,如`callback_url?accept=pending,failure`表示支付失败或者支付取消跳转`callback_url`。 ### 8. 终端 Terminal 参数支持`ONLINE` 和`WAP`两种,具体使用规则参见[应用场景](#应用场景)。 ```shell sys_reserve = {"vendor_id":"4200000117201806013734875340"} ``` ### 9. 系统保留域 sys_reserve 系统保留域,主要是用于返回一些特殊信息,比如付款在支付渠道的支付流水号,用户付款使用的付款银行等信息,当前包含的主要字段有: key | valye -------- | ----------- **vendor_id**| 付款成功后在支付渠道的支付流水号,通常显示在客户的付款凭证上 ## 异步通知 ### 异步返回说明 订单支付成功后,NihaoPay会异步返回交易结果到`IPN url`,请求方式为HTTP POST。**请尽可能根据IPN url收到的结果处理商户系统中的订单状态。** NihaoPay会在2小时内自动重复多次发送异步通知,直到商户服务器响应http状态码200。 针对`ipn_url`要求如下: * `ipn_url` 必须是在Internet中可以访问的地址,不能是内网地址(如`localhost`)或内网IP * IPN通知可能比Callback返回先到达 * 多次的IPN异步通知,不要重复处理 * NihaoPay使用POST方式发送IPN通知信息,注意接受参数的处理方式 * 必须保证异步通知页面(ipn_url)上无任何字符,如空格,HTML标签等,商户处理成功返回HTTP状态码200,否则NihaoPay服务器会不断重发通知,最多发送8次 * 一般情况下,NihaoPay会在支付成功后的2小时内完成8次通知(通知的间隔频率为:0m,1m,2m,4m,8m,20m,30m) * 程序执行完成后,ipn_url页面不能执行页面跳转,否则NihaoPay会因收不到正确结果而重发结果通知 > **异步返回示例** ```shell id = 20170519103602011338 amount = 2 currency = USD rmb_amount = 12 reference = 20170519103456437807 sys_reserve = {"vendor_id":"4200000117201806013734875340"} status = success time = 2017-05-19T10:36:32Z note = null verify_sign = 46072c81e3c6140d6bc92655196b247f ``` ### 异步返回报文 字段 | 说明 ------- | ----------- **id**
`string` | NihaoPay生成的唯一交易流水号. **status**
`string` | 交易状态. 包括:支付成功 `success`, 支付失败`failure`, 支付中`pending`, 交易关闭`closed`. **currency**
`string` | 订单记账币种. **amount**
`int` | 订单记账金额. **rmb_amount**
`int` | 订单人民币金额,如果请求时上送,返回与请求一致,如果未上送,会根据渠道返回客户实际付款的人民币金额. **time**
`string` | 交易在NihaoPay系统中的完成时间. 例如: `2015-01-01T01:01:00Z`(NihaoPay使用的是UTC时区). **reference**
`string` | 商户订单号. **note**
`string` | 商户备注,与请求一致,如果请求是为空,则该字段为 null. **sys_reserve**
`json` | 系统保留字段,返回格式为json字符串,详细用法参见[接口规则](#接口规则) **verify_sign**
`string` | 返回的签名验证 > **签名方法** ```shell verify_sign = MD5(key1=value1&key2=value2&...&keyn=valuen&MD5(TOKEN)) ``` ### 异步通知签名校验 在异步通知返回时,NihaoPay会对返回信息做MD5签名,商户接受到异步通知后,应该按照签名方法验证返回的信息是否被篡改。 签名方法如下: A. 关键信息对和合作密钥信息对的拼接方法为: * 单个对的表示方式为 key=value,如果该key对应的value为空,则不参与签名。 * 多个对的拼接方式为 key1=value1&key2=&key3=value3。多个对根据key值做升序排序。 * 合作密钥信息的拼接方式为key1=value1&key2=&key3=value3&MD5(Token)。将Token做MD5之后拼接在字符串的末尾,注意MD5(Token)之后应将字符串全部转化为小写字符。 B. 签名方法 verify_sign = MD5(key1=value1&key2=&key3=value3...&keyn=value&MD5(Token)) 注意: * NihaoPay使用的字符集是UTF-8,请注意编码格式 * NihaoPay使用的MD5方法,输出都是小写字符,在签名比较时请忽略大小写。 * 返回报文中的参数可能由于业务需要会有增改,请根据动态获取的key来参与签名 # 安全支付 ## 标准安全支付 ```shell POST https://api.nihaopay.com/v1.2/transactions/securepay ``` > **请求示例** ```shell $ curl https://api.nihaopay.com/v1.2/transactions/securepay \ -H "Authorization: Bearer " \ -d amount=100 \ -d currency="USD" \ -d vendor="unionpay" \ -d reference="jkh25jh1348fd89sg" \ -d items[0].name="T-Shirt Test" \ -d items[0].unitAmount=100 \ -d items[0].quantity=1 \ -d ipn_url="http://website.com/ipn" \ -d callback_url="http://website.com/callback" ``` ```shell $ curl https://api.nihaopay.com/v1.2/transactions/securepay \ -H "Authorization: Bearer " \ -d amount=100 \ -d currency="USD" \ -d vendor="unionpay" \ -d reference="jkh25jh1348fd89sg" \ -d items[0].name="T-Shirt Test" \ -d items[0].unitAmount=100 \ -d items[0].quantity=1 \ -d ipn_url="http://website.com/ipn" \ -d in_wechat="false" \ -d callback_url="http://website.com/callback" ``` > **json响应示例1** ```json { "url": "https://openapi.alipay.com/gateway.do?app_id=2019031263534265" } ``` > **json响应示例2** ```json { "form": { "actionUrl": "https://www.nihaopay.com/", "method": "POST", "target": "_self", "params": { "bizType": "000201", "backUrl": "https://bgw.nihaopay.com/payBackResp/44e4af32d6494c71aaafe2eaf6c05910", "orderId": "u20230827102153QvCEZp", "txnSubType": "01" } } } ``` 安全支付是一个异步的,需要页面跳转的支付方式。商家请求NihaoPay API后,同步收到一个HTML页面,商家需将该页面写入到当前的网页请求中,该页面会自动跳转到支付服务商的页面,在支付页面,客户输入支付信息,完成支付。一旦支付完成,页面将跳转至商家提供的callback URL,NihaoPay会在返回callback URL时带上返回参数,需要使用GET方式获取。 由于重定向的性质,以及用户可能在重定向发生之前关闭浏览器,为保证支付结果通知到商户,NihaoPay使用server-to-server的实时通知(IPN url)返回交易结果,IPN 结果需要使用POST方式获取。 ### 请求报文 参数 | 说明 -------- | ----------- **currency**
`不为空`| 币种,3位货币代码. 当前支持的币种参见[接口规则](./apirule#接口规则) **amount**
`有条件的` | 订单外币金额,与currency对应。金额为对应货币中的最小单位。详见[接口规则](./apirule#接口规则) **rmb_amount**
`有条件的` | 订单人民币金额,使用人民币标价替代外币金额标价。金额单位为分,如金额为100时,表示1.00元人民币。详见[接口规则](./apirule#接口规则) **vendor**
`不为空`| 付款方式,客户付款时选择的支付方式,目前支持支付宝 `alipay`,微信支付 `wechatpay`,银联 `unionpay` 和 PayPal `paypal`。 **payment_source**
`允许为空` | PayPal 的支付来源。默认为 PayPal 钱包;传 `crypto` 发起 PayPal Crypto 支付;传 `ACDC` 用于商户使用 PayPal Javascript SDK 创建订单,详见[参考代码](https://docs.nihaopay.com/api/v1.2/paypal-acdc.html)。 **given_name**
`有条件的` | PayPal Crypto 付款人名字。当 `vendor=paypal` 且 `payment_source=crypto` 时必填。 **surname**
`有条件的` | PayPal Crypto 付款人姓氏。当 `vendor=paypal` 且 `payment_source=crypto` 时必填。 **reference**
`不为空` | 商户订单号,1-30位的字母,数字和'-'组合,必须在商户系统中唯一。详见[接口规则](./apirule#接口规则) **items**
`允许为空` | 订单商品列表,详见[接口规则](./apirule#接口规则)。 **ipn_url**
`不为空` | 接收支付结果异步通知的URL。详见[异步通知](./apirule#异步通知) **callback_url**
`不为空` | 支付完成后浏览器返回商户网站的URL。 **description**
`允许为空` | 订单描述,可以订单商品信息摘要等,会显示在支付页面和客户付款收据中。 **note**
`允许为空` | 供商家使用的备注字段,NihaoPay不做处理,在返回时,原数据将返回给商户。 **terminal**
`允许为空`
默认: ONLINE | 指定支付页面是在PC(`ONLINE`) 上显示,还是手机浏览器mobile (`WAP`)上显示。 **timeout**
`允许为空`
默认: 120 | 订单超时时间,在NihaoPay接受到订单请求后,如果在timeout(分钟)指定的时间内,客户未付款的,订单将会被关闭。接受的范围为`1 - 1440(1天)`。 **in_wechat**
`允许为空`
| 当前支付场景是微信内置浏览器时传`true`否则传`false`且仅当vendor=`wechatpay`时有效,当in_wechat=`false`时如果您开通了微信H5支付则使用[微信H5](https://pay.weixin.qq.com/doc/global/v3/zh/4013014399)支付否则降级为[扫码](https://pay.weixin.qq.com/doc/global/v3/zh/4013013953)支付,当in_wechat=`true`时使用[JSAPI支付](https://pay.weixin.qq.com/doc/global/v3/zh/4013014150)。 **response_format**
`允许为空`
默认: HTML | 指定返回的数据是(`JSON`) 格式,还是 (`HTML`)格式。 ### JSON 响应报文字段说明 (当`response_format`为`JSON`) 参数 | 说明 -------- | ----------- **url**
`有条件的`| 重定向url,当接口返回的是url时,调用者拿到url后直接重定向到此url即可 **orderId**
`有条件的`| PayPal Order Id,用于商户使用PayPal Javascript SDK创建订单[参考代码](https://docs.nihaopay.com/api/v1.2/paypal-acdc.html)。 **form**
`有条件的`| form表单对象,和url互斥,当url不存在时则form对象存在 **form.actionUrl**
`不为空`| form表单的action属性 **form.method**
`不为空` | form表单的method属性 **form.target**
`不为空` | form表单的target属性 **form.params**
`不为空`| form表单的参数,map格式,key为参数名,value为参数值。 ### 同步返回 1. HTML格式响应 >安全支付接口同步返回一个HTML页面,商家请展示该页面在浏览器上,页面将自动跳转到支付服务方上的支付页面。 2. JSON格式响应 (当`response_format`为`JSON`) >返回的json数据返回一个form对象或者url(不会同时存在)。如果返回的是url则调用者拿到url后直接重定向到此url即可,如果返回的是form对象则需要调用者使用form对象内的字段自行构造一个form表单,并将form表单写入到当前的网页请求中,提交后该页面会跳转到支付页面。 ### PayPal Crypto 支付 PayPal Crypto 使用标准安全支付接口。商户在创建订单时传入 `vendor=paypal`、`payment_source=crypto`、`given_name` 和 `surname`;接口返回的 `url` 需要在浏览器中重定向打开,由买家在 PayPal Crypto 页面完成付款。支付结果以 `callback_url` 前端跳转和 `ipn_url` 服务端通知为准。 > **请求示例** ```shell $ curl https://api.nihaopay.com/v1.2/transactions/securepay \ -H "Authorization: Bearer " \ -d amount=100 \ -d currency="USD" \ -d vendor="paypal" \ -d payment_source="crypto" \ -d given_name="Jane" \ -d surname="Doe" \ -d reference="paypal-crypto-001" \ -d ipn_url="https://merchant.example.com/payment-ipn" \ -d callback_url="https://merchant.example.com/payment-callback" \ -d response_format="JSON" ``` > **异步返回示例** ```shell id = 20170519103602011338 amount = 2 currency = USD rmb_amount = 12 reference = 20170519103456437807 sys_reserve = {"vendor_id":"4200000117201806013734875340"} status = success time = 2017-05-19T10:36:32Z note = null verify_sign = 46072c81e3c6140d6bc92655196b247f ``` ### 异步返回报文 订单支付成功后,NihaoPay会返回交易结果到商户的`callback url`和`IPN url`。在最新版本中使用GET方式返回给`callback url`,使用POST方式返回给`IPN url`。**请尽可能根据IPN url收到的结果处理商户系统中的订单状态。** NihaoPay会在2小时内自动重复多次发送异步通知,直到商户服务器回复“ok”消息在响应中。 字段 | 说明 ------- | ----------- **id**
`string` | NihaoPay生成的唯一交易流水号. **status**
`string` | 交易状态. 包括:支付成功 `success`, 支付失败`failure`, 支付中`pending`, 交易关闭`closed`. **currency**
`string` | 订单记账币种. **amount**
`int` | 订单记账金额. **rmb_amount**
`int` | 订单人民币金额,如果请求时上送,返回与请求一致,如果未上送,会根据渠道返回客户实际付款的人民币金额. **time**
`string` | 交易在NihaoPay系统中的完成时间. 例如: `2015-01-01T01:01:00Z`(NihaoPay使用的是UTC时区). **reference**
`string` | 商户订单号. **note**
`string` | 商户备注,与请求一致,如果请求是为空,则该字段为 null. **sys_reserve**
`json` | 系统保留字段,返回格式为json字符串,详细用法参见[接口规则](./apirule#接口规则) **verify_sign**
`string` | 返回的签名验证 ## 获取付款二维码 ```shell POST https://api.nihaopay.com/v1.2/transactions/qrcode ``` > **请求示例** ```shell $ curl https://api.nihaopay.com/v1.2/transactions/qrcode \ -H "Authorization: Bearer " \ -d amount=100 \ -d currency="USD" \ -d vendor="wechatpay" \ -d reference="jkh25jh1348fd89sg" \ -d ipn_url="http://website.com/ipn" ``` 商户请求该接口获得一个包含二维码URL的json对象,将URL使用二维码生成软件生成一个图片格式的二维码展示在商户的网站上,客户打开微信或者云闪付,使用”扫一扫"扫描二维码,并完成支付。一旦客户付款成功,NihaoPay将发送异步通知到商户的IPN URL。商户也可以请求查询接口,获取订单的支付结果。 **IPN异步通知信息与安全支付的返回机制一样** ### 请求报文 字段 | 说明 -------- | ----------- **currency**
`不为空`| 订单币种,3位货币代码. 当前支持的币种参见[接口规则](./apirule#接口规则) **amount**
`有条件的` | 订单外币金额,与currency对应。金额为对应货币中的最小单位。详见[接口规则](./apirule#接口规则) **rmb_amount**
`有条件的` | 订单人民币金额,使用人民币标价替代外币金额标价。金额单位为分,如金额为100时,表示1.00元人民币。详见[接口规则](./apirule#接口规则) **vendor**
`不为空`| 付款方式,客户付款时选择的支付方式,目前支持微信支付 `wechatpay`和银联云闪付 `unionpay`。 **reference**
`不为空` | 商户订单号,1-30位的字母,数字和’-‘组合,必须在商户系统中唯一。 **items**
`允许为空` | 订单商品列表,详见[接口规则](./apirule#接口规则)。 **ipn_url**
`不为空` | 支付通知接收的URL。详见[异步通知](./apirule#异步通知) **timeout**
`允许为空`
默认:120 | 订单超时时间,在NihaoPay接受到订单请求后,如果在timeout(分钟)指定的时间内,客户未付款的,订单将会被关闭。接受的范围为1 - 1440(1天)。 **description**
`允许为空`| 订单描述,可以订单商品信息摘要等,会显示在支付页面和客户付款收据中。 **note**
`允许为空` | 供商家使用的备注字段,NihaoPay不做处理,在返回时,原数据将返回给商户。 > **返回示例** ```json { "id": "20160829075820003759", "code_url": "weixin://wxpay/bizpayurl?pr=1dVyJZF", "timeout": 90, "amount": 100, "currency": "USD", "reference": "jkh25jh1348fd89sg", "time": "2017-10-10T06:35:12Z" } ``` ### 返回报文 字段 | 说明 ------- | ----------- **code_url**
`string` | 二维码URL **id**
`string` | NihaoPay生成的唯一交易ID **amount**
`int` | 订单金额。 **currency**
`string` | 订单币种 **timeout**
`int`
| 二维码的有效时间(分钟),超过该时间,二维码将失效。 **reference**
`string` | 商户订单号 **time**
`string` | 交易在NihaoPay系统中的完成时间. 例如: `2015-01-01T01:01:00Z`(NihaoPay使用的是UTC时区). ## In-App支付 ```shell POST https://api.nihaopay.com/v1.2/transactions/apppay ``` > **请求示例** ```shell $ curl https://api.nihaopay.com/v1.2/transactions/apppay \ -H "Authorization: Bearer " \ -d amount=100 \ -d currency="USD" \ -d vendor="alipay" \ -d reference="alipay20170503000300" \ -d ipn_url="http://website.com/ipn" ``` ### 请求报文 字段 | 说明 -------- | ----------- **currency**
`不为空`| 订单币种,3位货币代码. 当前支持的币种参见[接口规则](./apirule#接口规则) **amount**
`有条件的` | 订单外币金额,与currency对应。金额为对应货币中的最小单位。详见[接口规则](./apirule#接口规则) **rmb_amount**
`有条件的` | 订单人民币金额,使用人民币标价替代外币金额标价。金额单位为分,如金额为100时,表示1.00元人民币。详见[接口规则](./apirule#接口规则) **vendor**
`不为空`| 付款方式,客户付款时选择的支付方式,支持支付宝`alipay` , 微信支付`wechatpay` 和银联 `unionpay`。 **app_id**
`允许为空` | APP在[微信开放平台](https://open.weixin.qq.com/)审核通过的APPID。当vendor=wechatpay时,不能为空。 **reference**
`不为空` | 商户订单号,1-30位的字母,数字和’-‘组合,必须在商户系统中唯一。 **items**
`允许为空` | 订单商品列表,详见[接口规则](./apirule#接口规则)。 **ipn_url**
`不为空` | 支付通知接收的URL。详见[异步通知](./apirule#异步通知) **description**
`允许为空`| 订单描述,可以订单商品信息摘要等,会显示在支付页面和客户付款收据中。 **note**
`允许为空` | 供商家使用的备注字段,NihaoPay不做处理,在返回时,原数据将返回给商户。 **timeout**
`允许为空`
默认: 120 | 订单超时时间,在NihaoPay接受到订单请求后,如果在timeout(分钟)指定的时间内,客户未付款的,订单将会被关闭。接受的范围为`1 - 1440(1天)`。 **ostype**
`不为空` | 指定支付页面是在Android手机(`ANDROID`) 上显示,还是iphone手机 (`IOS`)上显示。 > **返回示例** ```json { "orderInfo": "orderinfo string.....", "redirectUrl": "https://wallet.com/xxx?xxx=xx....." } ``` ### 返回报文 > 同一时间 orderInfo 和 redirectUrl 只有一个会返回, 优先使用orderInfo 字段 | 说明 ------- | ----------- **orderInfo**
`string` | 用于调起渠道方sdk的订单信息,具体使用参见NihaoPay提供的[IOS Demo](https://github.com/nihaopay/NihaoPay-IOSDemo) or [Android Demo](https://github.com/nihaopay/nihaopay-as-demo)。微信支付的In-app功能需要特殊流程,如果要开通,请联系NihaoPay获取帮助。 **redirectUrl**
`string` | 在浏览器或者webview中使用此Url将用户重定向到对应的wap或web支付页面,具体使用参见NihaoPay提供的[IOS Demo](https://github.com/nihaopay/NihaoPay-IOSDemo) or [Android Demo](https://github.com/nihaopay/nihaopay-as-demo)。 ## 支付宝 A+ > 支持钱包: AlipayHK,GCASH,DANA,KaKaoPay,TNG,TrueMoney ```shell POST https://api.nihaopay.com/v1.2/transactions/aplus ``` > **请求示例** ```shell $ curl https://api.nihaopay.com/v1.2/transactions/aplus \ -H "Authorization: Bearer " \ -d amount=100 \ -d currency="USD" \ -d reference="alipay20170503000300" \ -d ipn_url="http://website.com/ipn" \ -d callback_url="http://website.com/callback" ``` ### 请求报文 字段 | 说明 -------- | ----------- **currency**
`不为空`| 订单币种,3位货币代码. 当前支持的币种参见[接口规则](./apirule#接口规则) **amount**
`有条件的` | 订单外币金额,与currency对应。金额为对应货币中的最小单位。详见[接口规则](./apirule#接口规则) **rmb_amount**
`有条件的` | 订单人民币金额,使用人民币标价替代外币金额标价。金额单位为分,如金额为100时,表示1.00元人民币。详见[接口规则](./apirule#接口规则) **reference**
`不为空` | 商户订单号,1-30位的字母,数字和’-‘组合,必须在商户系统中唯一。 **items**
`允许为空` | 订单商品列表,详见[接口规则](./apirule#接口规则)。 **ipn_url**
`不为空` | 支付通知接收的URL。详见[异步通知](./apirule#异步通知) **callback_url**
`有条件的` | Terminal=`ONLINE` 或 terminal=`WAP` 时必须, 支付完成后浏览器返回商户网站的URL。 **description**
`允许为空`| 订单描述,可以订单商品信息摘要等,会显示在支付页面和客户付款收据中。 **note**
`允许为空` | 供商家使用的备注字段,NihaoPay不做处理,在返回时,原数据将返回给商户。 **timeout**
`允许为空`
默认: 10 | 订单超时时间,在NihaoPay接受到订单请求后,如果在timeout(分钟)指定的时间内,客户未付款的,订单将会被关闭。接受的范围为`1 - 10`。 **terminal**
`允许为空`
默认: ONLINE | 指定支付页面是在PC(`ONLINE`) 上显示,应用程序(`APP`),小程序(`MICRO`),还是手机浏览器mobile (`WAP`)上显示。 **ostype**
`有条件的` | 指定支付页面是在Android手机(`ANDROID`) 上显示,还是iphone手机 (`IOS`)上显示,terminal=`WAP` 或 terminal=`APP`或 terminal=`MICRO` 时必须。 **wallet**
`允许为空` | 默认:`CONNECT_WALLET`,可选值`ALIPAY_CN`,`ALIPAY_HK`,`TRUEMONEY`,`TNG`,`GCASH`,`DANA`,`KAKAOPAY`,`CONNECT_WALLET`时展示所有可用钱包,由支付者自行选择。 > **返回示例** ```json { "amount": 100, "timeout": 10, "currency": "USD", "reference": "1657808342862", "id": "20220714221903000379", "time": "2022-07-14T22:19:03Z", "redirectUrl": "https://alipay.com/connect.html?code=281666040098ZTL79hJiG7" } ``` ### 返回报文 字段 | 说明 ------- | ----------- **amount**
`int` | 订单金额,与currency对应,金额为对应货币中的最小单位。 **timeout**
`int` | 超时时间,单位分钟。 **currency**
`string` | 订单币种,3位货币代码。 **reference**
`string` | 商户订单号。 **id**
`string` | nihaopay 订单号。 **time**
`string` | 下单时间。 **redirectUrl**
`string` | 支付重定向Url,建议使用新窗口打开。 ## 微信小程序支付 ```shell POST https://api.nihaopay.com/v1.2/transactions/micropay ``` 在对接小程序支付API之前,需要先将商家通过微信认证的海外小程序对应的AppID和主体名称发送给支持团队配置后才可以使用。 商家在小程序内,请求预下单接口,生成预下单的支付参数,使用小程序的[wx.requestpayment()](https://developers.weixin.qq.com/miniprogram/dev/api/payment/wx.requestPayment.html)唤醒微信支付。在订单支付完成后,NihaoPay会发送IPN通知到商户的IPN_url。开发步骤见下图 ![Mini Program Flow](/images/miniprogram-flow.png) > **请求示例** ```shell $ curl https://api.nihaopay.com/v1.2/transactions/micropay \ -H "Authorization: Bearer " \ -d amount=100 \ -d currency="USD" \ -d reference="wechatpay20171109000300" \ -d ipn_url="http://website.com/ipn" \ -d open_id="oSC6Tw7--mfjTCpIr-72rWloA8TU" \ -d client_ip="180.167.25.154" ``` ### 请求报文 字段 | 说明 -------- | ----------- **currency**
`不为空`| 订单币种,3位货币代码. 当前支持的币种参见[接口规则](./apirule#接口规则) **amount**
`有条件的` | 订单外币金额,与currency对应。金额为对应货币中的最小单位。详见[接口规则](./apirule#接口规则) **rmb_amount**
`有条件的` | 订单人民币金额,使用人民币标价替代外币金额标价。金额单位为分,如金额为100时,表示1.00元人民币。详见[接口规则](./apirule#接口规则) **reference**
`不为空` | 商户订单号,1-30位的字母,数字和’-‘组合,必须在商户系统中唯一。 **items**
`允许为空` | 订单商品列表,详见[接口规则](./apirule#接口规则)。 **app_id**
`不为空` | 微信小程序对应的APPID。 **ipn_url**
`不为空` | 支付通知接收的URL。详见[异步通知](./apirule#异步通知) **client_ip**
`不为空` | 用户客户端IP **open_id**
`不为空` | 用户标识,微信用户在商户小程序内的唯一标识,获取方式请[点击这里](https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html). **description**
`允许为空`| 订单描述,可以订单商品信息摘要等,会显示在支付页面和客户付款收据中。 **note**
`允许为空` | 供商家使用的备注字段,NihaoPay不做处理,在返回时,原数据将返回给商户。 **timeout**
`允许为空`
默认: 120 | 订单超时时间,在NihaoPay接受到订单请求后,如果在timeout(分钟)指定的时间内,客户未付款的,订单将会被关闭。接受的范围为`1 - 1440(1天)`。 > **成功返回示例** ```json { "timeStamp": "1510341967363", "nonceStr": "a611bda03d544b9f941393c48c2e517f", "wechatPackage": "prepay_id=wx201711110326070ccf2a7f060678638664", "signType": "MD5", "paySign": "09E5BE5B9D93080E3B7DD05C8F41049E" } ``` ### 返回报文 字段 | 说明 ------- | ----------- **timeStamp**
`string` | 时间戳 **nonceStr**
`string` | 随机字符串 **wechatPackage**
`string` | prepay_id等信息 **signType**
`string` | 微信的签名类型 **paySign**
`string` | 签名 ## PayPal ACDC 订单捕获 ```shell POST https://api.nihaopay.com/v1.2/transactions/paypal/capture/{transaction_id} ``` > **请求示例** ```shell $ curl https://api.nihaopay.com/v1.2/transactions/paypal/capture/{transaction_id} \ -H "Authorization: Bearer " \ ``` 商户调用此接口完成对PayPal ACDC订单资金的捕获,即通过PayPal Javascript SDK创建的订单[参考代码](https://docs.nihaopay.com/api/v1.2/paypal-acdc.html)。 > **返回示例** ```json { "paypal_order_id": "80J3567205747094K", "paypal_capture_id": "0CW443673C1190047", "id": "20251215131749104834", "status": "success" } ``` ### 请求报文 `transaction_id` NihaoPay唯一的交易ID。 ### 返回报文 字段|说明 ---------|----------- **id**
`string`| 原交易流水号 **paypal_order_id**
`string`|PayPal 订单号 **paypal_capture_id**
`string`|PayPal 交易号 **status**
`string`|请求结果,包括:成功 `success`, 失败`failure` **processor_response_code**
`string`|PayPal或卡组返回的状态码 # 线下面对面支付 ## 扫码支付 ![Scan QRcode](/images/scanqrcode.png) ```shell POST https://api.nihaopay.com/v1.2/transactions/scanqrcode ``` > **请求示例** ```shell $ curl https://api.nihaopay.com/v1.2/transactions/scanqrcode \ -H "Authorization: Bearer " \ -d amount=100 \ -d currency="USD" \ -d vendor="alipay" \ -d reference="alipay201705030002" \ -d buyer_identity_code="288463639882104202" \ -d client_ip="184.167.25.158" \ -d note="alipay" \ -d description="Scan AliPay QrCode" ``` ### 请求报文 参数 | 说明 -------- | ----------- **currency**
`不为空`| 订单币种,3位货币代码. 扫码支付支持的币种有:`USD` 美元 和 `JPY` 日元。 **amount**
`不为空` | 订单金额,金额为对应货币中的最小单位。详见[接口规则](./apirule#接口规则) **vendor**
`不为空`| 付款方式,客户付款时选择的支付方式,目前支持支付宝 `alipay`,微信支付`wechatpay`和银联`unionpay`。 **reference**
`不为空` | 商户订单号,1-30位的字母,数字和'-'组合,必须在商户系统中唯一。详见[接口规则](./apirule#接口规则) **items**
`允许为空` | 订单商品列表,详见[接口规则](./apirule#接口规则)。 **buyer_identity_code**
`不为空` | 客户付款二维码或者条形码的信息 **client_ip**
`不为空` | 终端IP,调用API的终端设备的IP **description**
`允许为空` | 订单描述,可以订单商品信息摘要等,会显示在支付页面和客户付款收据中。 **note**
`允许为空` | 供商家使用的备注字段,NihaoPay不做处理,在返回时,原数据将返回给商户。 > **返回示例** ```json { "amount": 12, "id": "20170519093105011337", "time": "2017-05-19T09:31:05Z", "status": "success", "note": "123456789", "sys_reserve": "{'vendor_id':'2018031421001004970502155891'}", "reference": "alipay201705030004", "currency": "USD" } ``` ### 返回报文 字段 | 说明 ------- | ----------- **id**
`string` | NihaoPay生成的唯一交易流水号. **status**
`string` | 交易状态. 包括:支付成功 `success`, 支付失败`failure`, 支付中`pending`, 交易关闭`closed`. **sys_reserve**
`string` | 系统备用字段。返回Json格式的字符串,如果支付成功,返回渠道的交易流水号。 **amount**
`int` | 订单金额. **currency**
`string` | 订单币种. **time**
`string` | 交易在NihaoPay系统中的完成时间. 例如: `2015-01-01T01:01:00Z`(NihaoPay使用的是UTC时区). **reference**
`string` | 商户订单号. **note**
`string` | 商户备注,与请求一致,如果请求是为空,则该字段为 null. ## 展示交易二维码 ```shell POST https://api.nihaopay.com/v1.2/transactions/showqrcode ``` 商户请求该接口获得一个包含二维码URL的json对象,将URL使用二维码生成软件生成一个图片格式的二维码展示在商户的收款终端上,客户打开微信或者支付宝,使用”扫一扫"扫描二维码,并完成支付。一旦客户付款成功,NihaoPay将发送异步通知到商户的IPN URL。商户也可以请求查询接口,获取订单的支付结果。 ![Show QRcode](/images/showqrcode.png) > **请求示例** ```shell $ curl https://api.nihaopay.com/v1.2/transactions/showqrcode \ -H "Authorization: Bearer " \ -d amount=100 \ -d currency="USD" \ -d vendor="alipay" \ -d reference="jkh25jh1348fd89sg" \ -d ipn_url="http://website.com/ipn" ``` ### 请求报文 字段 | 说明 -------- | ----------- **amount**
`不为空` | 订单金额,金额为对应货币中的最小单位。详见[接口规则](./apirule#接口规则) **currency**
`不为空`| 订单币种,3位货币代码. 该产品支持的币种有:`USD` 美元和 `JPY` 日元。 **vendor**
`不为空`| 付款方式,客户付款是选择的支付方式,目前支持支付宝 `alipay`,微信支付`wechatpay`和银联`unionpay`。 **reference**
`不为空` | 商户订单号,1-30位的字母,数字和’-‘组合,必须在商户系统中唯一。 **items**
`允许为空` | 订单商品列表,详见[接口规则](./apirule#接口规则)。 **ipn_url**
`不为空` | 支付通知接收的URL。详见[异步通知](./apirule#异步通知) **timeout**
`允许为空`
默认:120 | 订单超时时间,在NihaoPay接受到订单请求后,如果在timeout(分钟)指定的时间内,客户未付款的,订单将会被关闭。接受的范围为1 - 1440(1天)。 **description**
`允许为空`| 订单描述,可以订单商品信息摘要等,会显示在支付页面和客户付款收据中。 **note**
`允许为空` | 供商家使用的备注字段,NihaoPay不做处理,在返回时,原数据将返回给商户。 > **返回示例** ```json { "code_url": "https://qr.alipay.com/bax02617gyevjsjqxgoz2038", "id": "20170519093828105112", "timeout": 120, "currency": "USD", "amount": 100, "reference": "20170427-137-0011", "time": "2017-05-19T09:38:28Z" } ``` ### 返回报文 字段 | 说明 ------- | ----------- **code_url**
`string` | 二维码URL **id**
`string` | NihaoPay生成的唯一交易ID **amount**
`int` | 订单金额。 **currency**
`string` | 订单币种 **timeout**
`int`
| 二维码的有效时间(分钟),超过该时间,二维码将失效。 **reference**
`string` | 商户订单号 **time**
`string` | 交易在NihaoPay系统中的时间. 例如: `2015-01-01T01:01:00Z`(NihaoPay使用的是UTC时区). ## 多合一固定收款码 ### 生成固定收款码 ```shell POST https://api.nihaopay.com/v1.2/merchantqrcode ``` 商户请求该接口获得一个包含NihaoPay固定收款码URL的json对象,将URL使用二维码生成软件生成一个图片格式的二维码,打印后张贴在商户的店铺中。客户打开支付宝或微信,使用”扫一扫"扫描二维码,在显示的页面中输入消费金额,确认后完成支付。商户通过NihaoPay商户后台查询客户付款记录。 > **请求示例** ```shell $ curl https://api.nihaopay.com/v1.2/merchantqrcode \ -H "Authorization: Bearer " \ -d ipn_url="http://website.com/ipn" \ -d trade_currency="USD" \ -d seller_name="NihaoPay" \ -d store_name="LA Branch" \ -d store_no="B001" ``` ### 请求报文 字段 | 说明 -------- | ----------- **trade_currency**
`不为空`| 订单币种,3位货币代码. 该产品支持的币种有:`USD` 美元 和 `JPY` 日元。 **ipn_url**
`允许为空` | 支付通知接收的URL。详见[异步通知](./apirule#异步通知) **seller_name**
`不为空`| 商家名称,用于显示在扫描二维码后的收银页面上 **store_name**
`不为空` | 分店名称 **store_no**
`不为空` | 分店编号 > **返回示例** ```json { "seller_name": "NihaoPay", "store_name": "LA Branch", "store_no": "B001", "qrcode_img_url": "https://apitest.nihaopay.com/merqrcode/9b2487be23a3434b9eb62870fcb73680", "qrcode": "https://apitest.nihaopay.com/topayment/9b2487be23a3434b9eb62870fcb73680" } ``` ### 返回报文 字段 | 说明 ------- | ----------- **seller_name**
`string` | 商家名称 **store_name**
`string` | 分店名称 **store_no**
`string` | 分店编号 **qrcode_img_url**
`string` | 二维码图片地址 **qrcode**
`string`
| 二维码Url ### 固定收款码支付 ```shell POST https://api.nihaopay.com/v1.2/transactions/staticqrcode ``` 多合一的固定收款码,NihaoPay是提供标准收银页面的。为方便服务商或商户在收银页面中展现自己的品牌标识,NihaoPay支持商家自己构建二维码对应的H5收银页面,该页面确认支付时,调用如下接口唤醒微信或支付宝的付款。 > **请求示例** ```shell $ curl https://api.nihaopay.com/v1.2/transactions/staticqrcode \ -H "Authorization: Bearer " \ -d amount=100 \ -d vendor="alipay" \ -d reference="201705030002" \ -d qrcode="https://apitest.nihaopay.com/topayment/9b2487be23a3434b9eb62870fcb73680" \ -d callback_url="https://nihaopay.com" \ -d description="static QrCode" ``` ### 请求报文 参数 | 说明 -------- | ----------- **amount**
`不为空` | 订单金额,金额为对应货币中的最小单位。详见[接口规则](./apirule#接口规则) **vendor**
`不为空`| 付款方式,根据客户扫描二维码使用的APP决定,如果用微信扫码,该参数为`wechatpay`,如果用支付宝钱包扫码,该参数为`alipay`。 **qrcode**
`不为空` | 收款码url。该参数为创建收款码接口的返回字段`qrcode` **reference**
`允许为空` | 商户订单号,1-30位的字母,数字和'-'组合,必须在商户系统中唯一。详见[接口规则](./apirule#接口规则) **items**
`允许为空` | 订单商品列表,详见[接口规则](./apirule#接口规则)。 **callbacl_url**
`允许为空` | 支付完成后浏览器返回商户网站的URL。 **description**
`允许为空` | 订单描述,可以订单商品信息摘要等,会显示在支付页面和客户付款收据中。 > **返回示例** ```json { "redirect_url": "https://wxcode.nihaopay.com/wechatpay/openid?txnId=20180314095142025479" } ``` ### 返回报文 当请求无误时,接口返回一个页面跳转url, 商家需要页面重定向到该地址,由APP自动唤醒支付功能。 字段 | 说明 ------- | ----------- **redirect_url**
`string` | 页面跳转地址。 ## 支付宝收款码 ```shell POST https://api.nihaopay.com/v1.2/merchantqrcode ``` 商户请求该接口获得一个包含支付宝静态二维码URL的json对象,将URL使用二维码生成软件生成一个图片格式的二维码,打印后张贴在商户的店铺中。客户打开支付宝,使用”扫一扫"扫描二维码,在显示的页面中输入消费金额,确认后完成支付。一旦客户付款成功,NihaoPay将发送异步通知到商户的IPN URL。商户也可以登录商户后台查询客户付款记录。 > **请求示例** ```shell $ curl https://api.nihaopay.com/v1.2/merchantqrcode \ -H "Authorization: Bearer " \ -d vendor="alipay" \ -d ipn_url="http://website.com/ipn" \ -d trade_currency="USD" \ -d seller_name="NihaoPay" \ -d store_name="LA Branch" \ -d store_no="B001" ``` ### 请求报文 字段 | 说明 -------- | ----------- **trade_currency**
`不为空`| 订单币种,3位货币代码. 该产品支持的币种有:`USD` 美元 和 `JPY` 日元。 **vendor**
`不为空`| 固定值:`alipay`。 **ipn_url**
`允许为空` | 支付通知接收的URL。详见[异步通知](./apirule#异步通知) **seller_name**
`不为空`| 商家名称,用于显示在扫描二维码后的付款页面上 **store_name**
`不为空` | 分店名称 **store_no**
`不为空` | 分店编号 > **返回示例** ```json { "seller_name": "NihaoPay", "store_name": "LA Branch", "store_no": "B001", "qrcode_img_url": "https://mobilecodec.alipay.com/show.htm?code=ocx09459xspxxdajnvzik3d", "qrcode": "https://qr.alipay.com/ocx09459xspxxdajnvzik3d" } ``` ### 返回报文 字段 | 说明 ------- | ----------- **seller_name**
`string` | 商家名称 **store_name**
`string` | 分店名称 **store_no**
`string` | 分店编号 **qrcode_img_url**
`string` | 带支付宝logo的二维码图片地址 **qrcode**
`string`
| 二维码Url # 报关 报关产品是为跨境电商行业商户提供直邮中国业务场景下支付单海关申报的服务。 ## 报关接口 目前支持使用银联,支付宝和微信付款的订单做海关申报,如果开通微信支付的商户,需要使用报关产品前请先将海关备案号和海关备案名称邮件发送至[业务支持团队](mailto:support@nihaopay.com),避免出现报关失败的问题。 身份信息校验申报规则: * 身份信息校验不管是否一致,微信或支付宝都以系统登记的支付人信息推送海关 * 商户重推上传新的用户身份信息,渠道会重新校验 ```shell POST https://api.nihaopay.com/v1.2/customs/declaration/{transaction_id} ``` > **请求示例** ```shell $ curl https://api.nihaopay.com/v1.2/customs/declaration/20180529073648029764 \ -H "Authorization: Bearer " \ -d request_no=20180529073648029702 \ -d customs=ningbo \ -d merchant_customs_code=440316T004 \ -d merchant_customs_name=财付通支付科技有限公司 \ -d customs_amount=1284 \ -d split=true \ -d product_amount=1284 \ -d transport_amount=0 \ -d sub_order_id=20180529073648029701 ``` ### 请求报文 参数 | 说明 -------- | ----------- **request_no**
String(36) `不为空`| 请求订单号 **customs**
String(64) `不为空` | 申报海关 **merchant_customs_code**
String(32) `不为空` | 商户海关备案号 **merchant_customs_name**
String(64) `不为空`| 商户海关备案名称 **customs_amount**
Int `不为空` | 报关人民币金额,以分为单位 **duty_amount**
Int `允许为空` | 关税,以分为单位。部分海关需要上报关税信息 **description**
String(128) `允许为空` | 报关信息描述 **split**
bool `不为空`
| 是否拆单,默认为`true` **sub_order_id**
String(64) `不为空` | 商户子订单号,用于在海关系统中匹配物流单和订单信息 **product_amount**
Int `有条件的` | 商品金额,以分为单位。在拆单情况下,该字段不能为空 **transport_amount**
Int `有条件的` | 物流费用,以分为单位。在拆单情况下,该字段不能为空 **cert_type**
String(16) `不为空`| 订购人证件类型,目前只支持大陆身份证,默认固定值`ID_CARD` **cert_name**
String(64) `不为空`| 订购人姓名,如张三 **cert_no**
String(32) `不为空`| 用户大陆身份证号,尾号为X的,请用大写字母X。 ### 请求参数说明 支持的申报海关包括: * ZONGSHU:海关总署 * BEIJING:北京海关 * HANGZHOU:杭州海关 * NINGBO:宁波海关 * GUANGZHOU:广州海关 * GUANGZHOU_HUANGPU:广州黄埔国检 * SHENZHEN:深圳海关 * NANSHA:南沙国检 * ZHENGZHOU:河南保税物流中心 * XINZHENG:新郑综合保税区 * CHONGQING:重庆海关 * SHANGHAI:上海海关 * XIAN:西安海关 * TIANJING:天津海关 * XIAMEN:厦门海关 > **返回示例** ```json { "id": "20180529084416000000", "status": "pending", "transaction_id": "20180529073648029764", "pay_transaction_id": "2019011122001376840500835544", "ver_dept": 2, "pay_code": "312226T001", "cert_check": "UNCHECKED" } ``` ### 返回报文 字段 | 说明 ------- | ----------- **id**
`string` | NihaoPay生成的报关流水号. **status**
`string` | 报关状态. 包括:成功 `success`, 失败`failure`, 报关中`pending`. **transaction_id**
`string` | 原交易流水号. **pay_transaction_id**
`string` | 支付流水号,来自支付机构,如微信或者支付宝的交易交易流水号,供商户海关报备使用 **ver_dept**
`int` | 核验机构,包括 0-银联,1-网联,2-其他 **pay_code**
`string` | 支付企业的海关注册登记编号 **cert_check**
`string` | 订购人和支付人身份信息校验结果,`UNCHECKED`:商户未上传订购人身份信息,`SAME`:商户上传的订购人身份信息与支付人身份信息一致,`DIFFERENT`:商户上传的订购人身份信息与支付人身份信息不一致 ### 支付企业海关注册编号 银联付款的订单对应的支付企业海关信息如下: * 备案名称:中国银联股份有限公司 * 备案编号:312228034U 微信付款的订单对应的支付企业海关信息如下: * 备案名称:财付通支付科技有限公司 * 备案编号:4403169D3W 支付宝付款的订单对应的支付企业海关信息如下: * 备案名称:支付宝(中国)网络技术有限公司 海关 | 支付宝备案号 ------- | ----------- 总署 | 31222699S7 上海海关 | 31222699S7 宁波海关 | 31222699S7 河南保税物流中心 | 31222699S7 新郑综合保税区 | P460400005 杭州海关 | ZF14021901 广州海关 | C000010000416158 天津海关 | Q12150016000019 ## 报关查询接口 ```shell GET https://api.nihaopay.com/v1.2/customs/{request_no} ``` > **请求示例** ```shell $ curl https://api.nihaopay.com/v1.2/customs/20180529073648029702 \ -H "Authorization: Bearer " ``` ### 请求报文 字段 | 说明 -------- | ----------- **request_no**
`不为空` | 需要查询的报关请求单号 > **返回示例** ```json { "id": "20180529084416000000", "request_no": "20180529073648029702", "status": "pending", "vendor_id": "4200000112201805292728213273", "customs": "NINGBO", "split": true, "customs_amount": 1284, "product_amount": 1284, "transport_amount": 0, "transaction_id": "20180529073648029764", "sub_order_id": "20180529073648029701", "pay_transaction_id": "2019011122001376840500835544", "ver_dept": 2, "pay_code": "312226T001" } ``` ### 返回报文 字段 | 说明 ------- | ----------- **id**
`string`| 报关请求ID **transaction_id**
`string`| 原支付交易ID **vendor_id**
`string`| 原支付交易在渠道方的流水号 **status**
`string`| 报关状态, 包括:成功 `success`, 失败`failure`, 报关中`pending`. **customs**
`string` | 申报海关 **customs_amount**
`int` | 报关人民币金额,以分为单位 **duty_amount**
`int` | 关税,以分为单位。部分海关需要上报关税信息 **split**
`bool` | 是否拆单,默认为不拆单 **sub_order_id**
`string` | 商户子订单号,在拆单情况下,该字段不能为空 **product_amount**
`int` | 商品金额,以分为单位。在拆单情况下,该字段不能为空 **transport_amount**
`int` | 物流费用,以分为单位。在拆单情况下,该字段不能为空 **pay_transaction_id**
`string` | 支付流水号,来自支付机构,如微信或者支付宝的交易交易流水号,供商户海关报备使用 **ver_dept**
`int` | 核验机构,包括 0-银联,1-网联,2-其他 **pay_code**
`string` | 支付企业的海关注册登记编号 ## 报关重推接口 ```shell POST https://api.nihaopay.com/v1.2/customs/redeclaration/{request_no} ``` > **请求示例** ```shell $ curl https://api.nihaopay.com/v1.2/customs/redeclaration/20210810150833001421 \ -H "Authorization: Bearer " ``` ### 请求报文 字段 | 说明 -------- | ----------- **request_no**
`不为空` | 需要重推的报关请求单号 > **返回示例** ```json { "transaction_id": "20210810150833001421", "cert_check": "DIFFERENT", "ver_dept": 3, "request_no": "20210810150833001421", "pay_code": "31222699S7", "pay_transaction_id": "2021081011082640020055578", "merchant_id": "M001100001", "id": "20210810150935000155", "status": "success" } ``` ### 返回报文 字段 | 说明 ------- | ----------- **request_no**
`string`| 原报关请求订单号 **id**
`string` | NihaoPay生成的报关流水号. **merchant_id**
`string`| NihaoPay的商户号 **status**
`string` | 报关状态. 包括:成功 `success`, 失败`failure`, 报关中`pending`. **transaction_id**
`string` | 原交易流水号. **pay_transaction_id**
`string` | 支付流水号,来自支付机构,如微信或者支付宝的交易交易流水号,供商户海关报备使用 **ver_dept**
`int` | 核验机构,包括 0-银联,1-网联,2-其他 **pay_code**
`string` | 支付企业的海关注册登记编号 **cert_check**
`string` | 订购人和支付人身份信息校验结果,`UNCHECKED`:商户未上传订购人身份信息,`SAME`:商户上传的订购人身份信息与支付人身份信息一致,`DIFFERENT`:商户上传的订购人身份信息与支付人身份信息不一致 ## 报关接口错误码列表 code|label|message -------|-------|----------- 400|31| Transaction reference number must be unique. Please re-submit.商户订单号不能重复,请更换订单号后重新提交 402|61| Transaction not found.交易未找到 500|81| Merchant config error 商户配置错误,请联系NihaoPay 500|82| Merchant unavailable 商户不可用 400|90| The field not valid. 请求参数格式不正确 500|91| Signature error 签名错误 500|92| The {0} field is required.请求字段不能为空 500|96| Timeout 请求超时 500|97| Inner error 内部错误 500|98| Vendor error 渠道系统出错,请稍后再试 500|99| System error 系统错误,请联系NihaoPay 401|301| Invalid merchant credentials provided 无效的认证信息,或身份验证失败 402|100| Transaction retransmission fail, Please try it after 5 minutes. 交易重传失败 402|101| Customs not supported. 报关不支持 402|102| Customs infomation changed. 报关信息篡改 402|103| Certification not correct. 认证不正确 402|104| Split amount not correct. 拆分金额不正确 402|105| Can not be modified as it is on declaration. 报关时无法修改 402|106| Same customs declare once. 同一个海关申报一次 402|107| Your request has been submitted, please confirm that it has taken effect. 您的请求已提交,请确认已生效 402|108| The original customs does not exist 原报关订单不存在 402|109| The declaration is not allowed for refunded orders. 已退款订单不能申报 # 代扣 ## 代扣功能描述 和用户完成签约后即可直接从用户签约钱包完成扣款. ## 代扣规则 1. 同一个合约同一个用户只能签约一次, 重复签约会返回签约失败 2. 签约后商户和用户都可以解约 3. 扣款后全额退款不会返还周期内剩余扣款次数 4. 代扣目前仅支持微信支付 5. 微信代扣限制(请咨询BD具体的天/月/次额度限制) ## 代扣接口 ### 1.代扣签约 #### 请求参数说明 | 参数名 | 是否必须 | 类型 | 说明 | 示例值 | |------------------|----------|-------------|----------------------------------|---------------------------------| | appId | 否 | string | 应用ID,如果开通了多个为了区分则必传 | wx123567 | | agreementId | 是 | string | 签约协议ID,微信场景即`plan_id` | 202301010001 | | username | 是 | string(32) | 签约用户的名称,用于页面展示,不需要对值进行URL编码,参数值不支持UTF8非3字节编码的字符 | 张三 | | vendor | 是 | string(16) | 支付渠道,如:`wechatpay`(微信支付) | wechatpay | | currency | 是 | string(3) | 货币代码,如:`USD`(美元) | USD | | notifyUrl | 是 | string | 异步通知URL,用于接收签约结果通知 | https://api.example.com/notify | | returnUrl | 否 | string | 同步返回URL,(`H5`,`JSAPI`时必须)用户签约完成后跳转的URL | https://api.example.com/return | | userId | 否 | string | 用户标识,(`JSAPI`,`MINI_APP`时必须),vendor=wechatpay时填充openid | oSC6Tw6SrhMMzMguby9cCqVzOo | | platform | 是 | string | 平台类型,如:`WEB`/`H5`(网页)、`APP`(移动应用)、`MINI_APP`(小程序)、`JSAPI`(微信公众号) | WEB | | clientIp | 否 | string | 客户端IP地址(`H5`时必须),用于风控校验 | 127.0.0.1 | | reference | 是 | string(64) | 商户唯一标识号,用于标识本次签约请求 | 202301010001 | | remark | 否 | string | 备注信息,用于记录本次签约的附加信息 | 测试签约 | #### 响应参数说明 | 参数名 | 是否必须 | 类型 | 说明 | 示例值 | |------------------|----------|-------------|----------------------------------|---------------------------------| | code | 是 | string | 返回码,`00`表示成功,其他表示失败 | 00 | | label | 是 | string | 返回码标签,用于标识返回码类型 | 00 | | message | 是 | string | 返回信息,描述操作结果 | success | | agreementId | 是 | string | 签约协议ID,微信场景即`plan_id` | 202301010001 | | contractNo | 是 | string | 合约编号,nihaopay合约唯一标识 | 202301010001 | | signId | 是 | string | 签约URL,APP/小程序返回signId,WEB/H5返回signUrl | 202501111159364508440 | | signUrl | 是 | string | 签约ID,APP/小程序返回signId,WEB/H5返回signUrl | https://api.example.com/sign | >**请求示例** >**场景1:WEB签约** ```shell curl --location 'https://api.nihaopay.com/v1.2/contract/sign' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer ' \ --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", "userId": "your_user_id" }' ``` >**请求失败响应示例** ```json { "code": "01", "label": "01", "message": "failed" } ``` >**请求成功响应示例** >**场景1:APP/小程序** ```json { "code": "00", "label": "00", "message": "success", "agreementId": "your agreementId", "contractNo": "our contractNo", "signId": "xxxxxxxx" } ``` >**场景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.代扣解约 #### 请求参数说明 | 参数 | 是否必须 | 类型 | 说明| | ----------------- | ------- | ---------- | --- | | **agreementId** | `可选` | string | 签约协议ID,微信场景即plan_id | | **reference** | `可选` | string(64) | 商户唯一标识符 | | **reason** | `必须` | string | 解约原因 | | **contractNo** | `可选` | string | 合约编号,nihaopay合约唯一标识,reference+agreementId 和 contractNo 不能同时为空 | #### 响应参数说明 | 参数 | 是否必须 | 类型 | 说明| | ----------------- | ------- | ---------- | --- | | **code** | `不为空` | string | 返回码,00表示成功 | | **label** | `不为空` | string | 返回码标签 | | **message** | `不为空` | string | 返回信息 | | **contractId** | `不为空` | string | 合约ID | | **contractNo** | `不为空` | string | 合约编号,nihaopay合约唯一标识 | | **reference** | `不为空` | string | 商户唯一标识号 | >**请求示例** >**使用agreementId + reference** ```shell curl --location 'https://api.nihaopay.com/v1.2/contract/terminate' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer ' \ --data '{ "agreementId": "your agreementId", "reference": "your unique reference", "reason": "your terminate reason" }' ``` >**使用contractNo** ```shell curl --location 'https://api.nihaopay.com/v1.2/contract/terminate' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer ' \ --data '{ "contractNo": "d649252400014ea7a8a890704cc600d6", "reason": "your terminate reason" }' ``` >**成功响应示例** ```json { "code": "00", "label": "00", "message": "success", "contractId": "contract id", "contractNo": "our contract number", "reference": "your unique reference" } ``` >**失败响应示例** ```json { "code": "01", "label": "01", "message": "failed" } ``` ### 3.代扣合约查询 #### 请求参数说明 | 参数 | 是否必须 | 类型 | 说明| | ----------------- | ------- | ---------- | --- | | **agreementId** | `可选` | string | 签约协议ID,微信场景即`plan_id` | | **reference** | `可选` | string(64) | 商户唯一标识符 | | **contractNo** | `可选` | string | 合约编号,nihaopay合约唯一标识,reference+agreementId 和 contractNo 不能同时为空 | #### 响应参数说明 | 参数 | 是否必须 | 类型 | 说明| | ----------------- | ------- | ---------- | --- | | **code** | `不为空` | string | 返回码,00表示成功 | | **label** | `不为空` | string | 返回码标签 | | **message** | `不为空` | string | 返回信息 | | **contractId** | `不为空` | string | 合约ID | | **contractNo** | `不为空` | string | 合约编号,nihaopay合约唯一标识 | | **contractStatus**| `不为空` | string | 合约状态,`Signed`(已签约)、`Terminated`(已解约),`Processing`(待签约),`FAIL`(签约失败) | | **signedTime**| `可能为空` | string | 签约时间 | | **terminateTime**| `可能为空` | string | 解约时间 | | **terminateMode**| `可能为空` | string | 解约模式,`USER`(用户主动解约)、`MERCHANT`(商户解约)、`PLATFORM`(商户解约平台解约) | >**请求示例** >**场景: agreementId + reference** ```shell curl --location 'https://api.nihaopay.com/v1.2/contract/query' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer ' \ --data '{ "agreementId": "your agreementId", "reference": "your unique reference" }' ``` >**场景: contractNo** ```shell curl --location 'https://api.nihaopay.com/v1.2/contract/query' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer ' \ --data '{ "contractNo": "d649252400014ea7a8a890704cc600d6" }' ``` >**返回示例** ```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.发起扣款 #### 请求参数说明 | 参数 | 是否必须 | 类型 | 说明| | ----------------- | ------- | ---------- | --- | | **amount** | `不为空` | string | 扣款金额 | | **currency** | `不为空` | string(3) | 货币代码,如USD | | **note** | `可选` | string | 订单备注 | | **description** | `不为空` | string | 扣款描述信息(用户端能看到的扣款内容) | | **ipn_url** | `不为空` | string | 异步通知URL | | **reference** | `不为空` | string(64) | 商户唯一标识符 | | **vendor** | `不为空` | string(16) | 支付渠道,如wechatpay | | **contract_id** | `不为空` | string | 合约ID,可以从签约回调中的通知获得,也可以主动调用query查询得到 | #### 响应参数说明 | 参数 | 是否必须 | 类型 | 说明| | ----------------- | ------- | ---------- | --- | | **status** | `不为空` | string | 交易状态,可能值: `success`/`failure` | | **reference** | `不为空` | string | 商户订单号 | | **currency** | `不为空` | string(3) | 交易货币,如 USD | | **amount** | `不为空` | decimal | 交易金额 | | **rmb_amount** | `不为空` | decimal | 人民币金额 | | **id** | `不为空` | string | 交易流水号 | | **note** | `允许为空` | string | 订单备注 | | **time** | `不为空` | string | 交易时间,UTC格式 | | **message** | `不为空` | string | 交易结果描述 | >**请求示例** ```shell curl --location 'https://api.nihaopay.com/v1.2/transactions/autodebit' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer ' \ --data '{ "amount": "1", "currency": "USD", "note": "your order note", "description": "", "ipn_url": "", "reference": "", "vendor": "wechatpay", "contract_id": "" }' ``` >**成功返回示例** ```json { "status": "success", "reference": "", "currency": "USD", "amount": 1, "rmb_amount": 0, "id": "20250111220054100012", "note": "autodebit test", "time": "2025-01-11T22:00:54Z", "message": "" } ``` >**错误返回示例** ```json { "status": "failure", "reference": "", "currency": "USD", "amount": 1, "rmb_amount": 0, "id": "20250111220054100012", "note": "autodebit test", "time": "2025-01-11T22:00:54Z", "message": "用户账户支付已达上限" } ``` ## 签约状态异步通知 ### 通知参数说明 | 参数 | 是否必须 | 类型 | 说明| | ----------------- | ------- | ---------- | --- | | **agreementId** | `不为空` | string | 签约协议ID,微信场景即`plan_id` | | **userId** | `不为空` | string | 用户ID,微信场景即`open_id` | | **contractId** | `不为空` | string | 合约ID,发起扣款时需要 | | **contractNo** | `不为空` | string | 合约编号,nihaopay合约唯一标识 | | **reference** | `不为空` | string | 商户唯一标识符 | | **contractStatus** | `不为空` | string | 状态:`Signed`(已签约)、`Terminated`(已解约),`Processing`(待签约),`FAIL`(签约失败) | | **signedAt** | `可能为空` | string | 签约时间,签约通知时必须 | | **terminateAt** | `可能为空` | string | 解约时间,解约通知时必须 | | **terminateMode** | `可能为空` | string | 解约模式,解约通知时必须,`USER`(用户主动解约)、`MERCHANT`(商户解约)、`PLATFORM`(商户解约平台解约) | >**签约通知示例** ```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", }' ``` ### 签约通知签名 `signature = MD5(body + '&' + MD5(token))` ### 回调通知重试机制 1. 最多通知7次 2. 通知的间隔频率为:0m,1m,2m,4m,8m,20m,30m # 分账 ## 分账功能描述 分账功能是指将支付订单款项中的一部分金额支付给其他收款方商户的功能。分账分为两种: - **指定订单分账**:对某一笔支付订单(传 `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.80 | 0.00 | -9.80 | | 商户 B | 9.80 | 0.20 | 9.60 | ### 场景 2 手续费从源账户扣除 | 账户 | 分账金额 | 手续费 | 到手金额 | | ------ | -------- | ------ | -------- | | 商户 A | -9.80 | 0.20 | -10.00 | | 商户 B | 9.80 | 0.00 | 9.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.80 | 0.00 | -9.80 | | 商户 B | 9.80 | 0.20 | 9.60 | | 商户 A | 9.60 | 0.19 | 9.41 | | 商户 B | -9.60 | 0.00 | -9.60 | ### 场景 2 手续费从源账户扣除 | 账户 | 分账金额 | 手续费 | 到手金额 | | ------ | -------- | ------ | -------- | | 商户 A | -9.80 | 0.20 | -10.00 | | 商户 B | 9.80 | 0.00 | 9.80 | | 商户 A | 9.80 | 0.00 | 9.80 | | 商户 B | -9.80 | 0.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** | `不为空` | int | 0:分账,2:撤销分账 | | **splitMethod** | `有条件` | int | 0: 百分比分账, 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 | `可选` | int | 0:手续费从交易中扣除(收款方承担)
1:手续费从源账户扣除
默认 0 | | baseFrom | `可选` | int | 按百分比计算时的基准金额
0: 原支付订单的净结算金额
1: 原分账的分账金额(仅撤销分账时有效)
2: 原支付订单的订单金额
默认 0.按百分比部分撤销时,通常应传 1 | | originConfId | `有条件` | string(21) | 撤销分账时必须,要撤销的原分账配置 id | | notifyUrl | `可选` | string(256) | 分账结果回调通知地址,失败或成功都会通知,[数据格式](#分账回调).必须是 http 或 https 地址,且可以从公网访问 | ## 分账接口 [postman 配置下载](https://docs.nihaopay.com/api/sharing.postman.json) > 场景:发起全局按比例分账 ```shell curl --location 'https://api.nihaopay.com/v1.2/sharing/apply' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer ' \ --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 ' \ --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 ' \ --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 ' \ --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 ' \ --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 | `可选` | int | 0:分账,2:撤销分账 | | currency | `可选` | string(3) | 分账币种 | > 查询所有分账配置 ```shell curl --location 'https://apitest.nihaopay.com/v1.2/sharing/query' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer ' \ --data '{}' ``` > 查询指定支付订单的分账配置 ```shell curl --location 'https://apitest.nihaopay.com/v1.2/sharing/query' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer ' \ --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 ' \ --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" } ``` 响应字段说明: | 字段 | 说明 | | ------------------------------------------------ | ----------------------------------------------------------------------- | | txnType | SHARE_PROFIT:分账,SHARE_REVERSE:撤销分账 | | sharingStatus | SUCCESS:成功,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 ' \ --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 ' \ --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 | 撤销金额超过原分账剩余可撤销金额 | # 退款/查询等接口 ## 查询订单状态 ```shell GET https://api.nihaopay.com/v1.2/transactions/merchant/{reference} ``` > **请求示例** ```shell $ curl https://api.nihaopay.com/v1.2/transactions/merchant/{reference} \ -H "Authorization: Bearer " ``` 使用商户订单号查询订单当前状态。 ### 请求 `reference` 商户订单号作为URL的请求参数. > **返回示例** ```json { "id": "bn2345nb53454kjb", "status": "success", "type": "charge", "amount": 1111, "currency": "USD", "time": "2015-01-01T01:01:01Z", "reference": "jkh25jh1348fd89sg", "note": "sample note" } ``` ### 返回 字段 | 说明 ------- | ----------- **id**
`string` | NihaoPay生成的唯一交易流水号. **status**
`string` | 交易状态. 包括:支付成功 `success`, 支付失败`failure`, 支付中`pending`, 交易关闭`closed`. **vendor**
`string` | 付款方式. 包括:银联 `unionpay`, 支付宝`alipay`, 微信支付`wechatpay`, 支付宝香港钱包`alipayhk`. **vendor_id**
`string` | 付款成功后在支付渠道的支付流水号,通常显示在客户的付款凭证上 **amount**
`int` | 订单金额. **currency**
`string` | 订单币种. **time**
`string` | 交易在NihaoPay中的完成时间. 例如: `2015-01-01T01:01:00Z`(NihaoPay使用的是UTC时区). **reference**
`string` | 商户订单号. **note**
`string` | 商户备注,与请求一直,如果请求是为空,则该字段为 null. ## 查询交易详情 ```shell GET https://api.nihaopay.com/v1.2/transactions/{transaction_id} ``` > **请求示例** ```shell $ curl https://api.nihaopay.com/v1.2/transactions/{transaction_id} \ -H "Authorization: Bearer " ``` 请求参数为NihaoPay返回的唯一交易ID,返回对应ID的交易详情对象。只有SecurePay的交易会被返回。如果要查看撤销,退款等交易信息,请登录[商户交易管理后台(TMS)](https://tms.nihaopay.com)。 ### 请求报文 `transaction_id` NihaoPay唯一的交易ID。 > **返回示例** ```json { "id": "bn2345nb53454kjb", "status": "success", "type": "charge", "amount": 1111, "currency": "USD", "time": "2015-01-01T01:01:01Z", "reference": "jkh25jh1348fd89sg", "note": "sample note" } ``` ### 返回报文 返回对应ID的交易对象。 字段 | 说明 ------- | ----------- **id**
`string` | NihaoPay生成的唯一交易流水号 **status**
`string` | 交易状态. 包括:支付成功 `success`, 支付失败`failure`, 支付中`pending`, 交易关闭`closed` **type**
`string` | 交易类型,包括:直接消费 `charge`, 预授权`authorization`, 预授权完成`capture` **vendor**
`string` | 付款方式. 包括:银联 `unionpay`, 支付宝`alipay`, 微信支付`wechatpay`, 支付宝香港钱包`alipayhk`. **vendor_id**
`string` | 付款成功后在支付渠道的支付流水号,通常显示在客户的付款凭证上 **amount**
`int` | 订单金额 **currency**
`string` | 订单币种 **time**
`string` | 交易在NihaoPay系统中的完成时间. 例如: `2015-01-01T01:01:00Z`(NihaoPay使用的是UTC时区) **reference**
`string` | 商户订单号 **note**
`string` | 商户备注,与请求一致,如果请求为空,则返回null ## 申请退款 ```shell POST https://api.nihaopay.com/v1.2/transactions/refund/{transaction_id} ``` > **请求示例** ```shell $ curl https://api.nihaopay.com/v1.2/transactions/refund/{transaction_id} \ -H "Authorization: Bearer " \ -d amount=100 \ -d currency="USD" \ -d reference="refund-001" \ -d ipn_url="https://merchant.example.com/refund-ipn" ``` 商户可以对已经付款成功的交易发起全额或者部分退款,每笔交易商户可以发起多次部分退款,但累计退款金额不得大于原交易金额。根据支付方式不同,订单退款期限也不同,银联付款成功的交易可在180天内退款,支付宝和微信付款成功的交易可在1年内发起退款。 PayPal(包括 PayPal Crypto)退款可能为异步处理。对于此类退款,商户传入 `ipn_url` 后,同步响应可能返回 `status=pending`、`refunded=false`;后续以退款 IPN 或退款结果查询中的状态为准。未传 `ipn_url` 的存量请求保持原有同步成功响应语义。 ### 请求报文 `transaction_id` 原支付交易ID作为URL中的参数. 字段 | 说明 -------- | ----------- **currency**
`不为空`| 退款币种,与原交易币种一致。 **amount**
`有条件的`| 退款外币金额,交易币种对应的最小单位,人民币为分,日元最小单位为元。
退款金额必须等于或小于原交易金额。 **rmb_amount**
`有条件的`| 退款人民币金额,如果原订单请求使用人民币标价,退款也必须使用人民币标价。 **reason**
`允许为空`|退款原因 **reference**
`允许为空`| 商户退款流水号。建议每笔退款唯一,用于商户侧幂等处理;同一商户不可重复使用。 **ipn_url**
`允许为空`| 接收退款结果异步通知的 URL。PayPal 异步退款需要传入该字段才能返回 `pending` 并接收后续退款 IPN。 > **返回示例** ```json { "id": "bn2345nb53454kjb", "status": "success", "refunded": true, "transaction_id": "jkh25jh1348fd89sg" } ``` > **异步退款返回示例(PayPal,传入 `ipn_url`)** ```json { "id": "20260910114323034765", "status": "pending", "refunded": false, "transaction_id": "20260910114042101626" } ``` ### 返回报文 字段|说明 ---------|----------- **id**
`string`| 退款交易流水号 **status**
`string`| 退款交易状态,包括:退款成功 `success`、退款失败 `failed`、退款处理中 `pending`。`pending` 仅可能在 PayPal 退款且请求传入 `ipn_url` 时返回。 **refunded**
`bool` | 是否已退款成功。`status=success` 时为 `true`;`status=pending` 时为 `false`。 **transaction_id**
`string`|原支付交易ID ### 退款异步通知 对于传入 `ipn_url` 的 PayPal 异步退款,NihaoPay 以 HTTP POST 向该地址发送退款状态通知。通知可能包含 `pending`,并在状态变为 `success` 或 `failed` 后再次通知;请以退款交易号 `id` 和状态实现幂等处理。通知签名规则与[异步通知签名校验](./apirule#异步通知签名校验)一致,商户处理成功后应返回 HTTP 200。 > **退款 IPN 示例** ```shell id = 20260910114323034765 status = success currency = USD amount = 100 time = 2026-09-10T11:45:12Z reference = refund-001 verify_sign = ``` 字段 | 说明 ------- | ----------- **id**
`string` | NihaoPay 退款交易流水号。 **status**
`string` | 退款状态:`pending`、`success` 或 `failed`。 **currency**
`string` | 原支付订单记账币种。 **amount**
`int` | 本笔退款金额,单位为该币种最小货币单位。 **time**
`string` | 通知生成时间,UTC 格式。 **reference**
`string` | 商户退款流水号,与退款请求一致。 **verify_sign**
`string` | 通知签名。 ## 退款结果查询 ```shell GET https://api.nihaopay.com/v1.2/transactions/refunds/{transaction_id}/ ``` > **请求示例** ```shell $ curl https://api.nihaopay.com/v1.2/transactions/refunds/{transaction_id}/ \ -H "Authorization: Bearer " ``` ### 请求报文 `transaction_id` 原支付交易ID作为URL中的参数. > **返回示例** ```json { "note": null, "amount": 2, "type": "charge", "refunded_amount": 2, "refunds": [ { "refund_time": "2021-11-29T05:42:33Z", "refund_id": "20211129054233008405", "refunded_amount": 1, "status": "success" }, { "refund_time": "2021-11-29T05:41:55Z", "refund_id": "20211129054155008404", "refunded_amount": 1, "status": "success" } ], "reference": "20211129134105329326", "vendor": "unionpay", "vendor_id": "512111291341178330258", "currency": "USD", "id": "20211129054117043676", "time": "2021-11-29T05:41:17Z", "status": "success" } ``` ### 返回报文 字段 | 说明 ------- | ----------- **id**
`string` | NihaoPay生成的唯一支付交易流水号 **status**
`string` | 交易状态. 包括:支付成功 `success`, 支付失败`failure`, 支付中`pending`, 交易关闭`closed` **type**
`string` | 交易类型,包括:直接消费 `charge`, 预授权`authorization`, 预授权完成`capture` **amount**
`int` | 订单金额 **currency**
`string` | 订单币种 **time**
`string` | 交易在NihaoPay系统中的完成时间. 例如: `2015-01-01T01:01:00Z`(NihaoPay使用的是UTC时区) **reference**
`string` | 商户订单号 **note**
`string` | 商户备注,与请求一致,如果请求为空,则返回null **vendor**
`string` | 付款方式. 包括:银联 `unionpay`, 支付宝`alipay`, 微信支付`wechatpay`, 支付宝香港钱包`alipayhk`. **vendor_id**
`string` | 付款成功后在支付渠道的支付流水号,通常显示在客户的付款凭证上 **refunded_amount**
`int` | 累计退款金额 **refunds**
`list` | 退款记录 **refund_time**
`string` | 退款发起时间 **refund_id**
`string` | 退款交易流水号 **refunded_amount**
`int` | 退款金额 **status**
`string` | 退款状态,包括:退款成功 `success`、退款失败 `failed`、退款处理中 `pending`。 ## 批量查询交易信息 ```shell GET https://api.nihaopay.com/v1.2/transactions/ ``` > **请求示例** ```shell $ curl https://api.nihaopay.com/v1.2/transactions/?starting_after=2015-01-01T01:01:00Z \ -H "Authorization: Bearer " ``` 返回满足要求的交易列表,返回交易按照时间倒序排列,按照limit参数要求返回对应的条数,默认返回10条记录。 只有SecurePay的交易会被返回。如果要查看撤销,退款等交易信息,请登录[商户交易管理后台(TMS)](https://tms.nihaopay.com). 参数`starting_after`表示读取该时间点之后的交易;`ending_before` 表示读取该时间点之前的交易。如果两个参数都有值,表示读取该时间范围内的交易信息,请注意`ending_before` 必须晚于 `starting_after`。 ### 请求报文 使用GET方式请求。 字段 | 说明 -------- | ----------- **limit**
`允许为空`
默认: 10| 每次请求返回的交易笔数,接受的范围是1-100条 **starting_after**
`允许为空`| 开始时间,时间格式:yyyy-mm-ddThh:mm:ssZ **ending_before**
`允许为空`| 截止时间,时间格式:yyyy-mm-ddThh:mm:ssZ > **返回示例** ```json { "transactions": [ { "id": "bn2345nb53454kjb", "status": "success", "type": "charge", "amount": 1111, "currency": "USD", "time": "2015-01-01T01:05:0Z", "reference": "jkh25jh1348fd89sg", "note": "sample note" }, { "id": "16zfmK2eZvKYlo2C6X3", "status": "success", "type": "authorization", "amount": 1111, "currency": "USD", "time": "2015-01-01T01:01:01Z", "reference": "6LJDMbC6Ybqlt7fd", "note": "sample note" } ] } ``` ### 返回报文 返回一个交易对象的数组,如果在请求的时间段内没有交易,则返回为空数组。 字段 | 说明 ------- | ----------- **id**
`string` | NihaoPay生成的唯一交易ID **status**
`string` | 交易状态. 包括:支付成功 `success`, 支付失败`failure`, 支付中`pending`, 交易关闭`closed` **type**
`string` | 交易类型,包括:直接消费 `charge`, 预授权`authorization`, 预授权完成`capture` **amount**
`int` | 订单金额 **currency**
`string` | 订单币种 **time**
`string` | 交易在NihaoPay系统中的完成时间. 例如: `2015-01-01T01:01:00Z`(NihaoPay使用的是UTC时区) **reference**
`string` | 商户订单号 **note**
`string` | 商户备注,与请求一致,如果请求为空,则返回null ## 汇率查询接口 ```shell GET https://api.nihaopay.com/v1.2/exchangerate ``` 如果商户网站的商品以外币标价,可以使用这个接口来查询当前支付渠道方的参考汇率。一般情况下,汇率更新时间为北京时间上午10:30,一天更新一次(频率限制: 每分钟1次,建议每天仅查询一次即可)。 > **请求示例** ```shell $ curl https://api.nihaopay.com/v1.2/exchangerate/?rate_date=20170308¤cy=USD \ -H "Authorization: Bearer " ``` ### 请求报文 使用GET方式请求,如果不指定vendor参数,默认返回所有渠道的汇率。 字段 | 说明 -------- | ----------- **rate_date**
`不为空`| 要查询的汇率日期,格式为YYYYMMDD **currency**
`不为空`| 外币币种,当前NihaoPay接受的币种有:`USD` 美元, `JPY` 日元, `HKD` 港币, `GBP` 英镑 and `EUR` 欧元 **vendor**
`允许为空`| 渠道方,目前支付宝 `alipay`,微信支付 `wechatpay`和银联 `unionpay`使用的汇率不一致,您可以指定该参数查询某一渠道的汇率。 > **返回示例** ```json { "rates": [ { "rate_date": "20170308", "currency": "usd", "vendor": "unionpay", "rate": "6.948700" }, { "rate_date": "20170308", "currency": "usd", "vendor": "alipay", "rate": "6.921791" }, { "rate_date": "20170308", "currency": "usd", "vendor": "wechatpay", "rate": "6.921911" } ] } ``` ### 返回报文 如果请求成功,返回一个json格式的汇率列表。 字段 | 说明 -------- | ----------- **rate_date**
`string`| 汇率日期,格式为YYYYMMDD **currency**
`string`| 外币币种 **vendor**
`string`| 支付宝 `alipay`,微信支付 `wechatpay` 或银联 `unionpay` **rate**
`string`| 外币币种兑换人民币的汇率 ## 交易下载 ```shell GET https://api.nihaopay.com/v1.2/download/transactions ``` 商家可以请求该接口下载历史消费交易。 > **请求示例** ```shell $ curl https://api.nihaopay.com/v1.2/download/transactions/?start_date=20170801&end_date=20170805 \ -H "Authorization: Bearer " ``` ### 请求报文 使用GET方式请求。注意:开始日期和结束日期间隔最长10天;不能请求当天的交易。 字段 | 说明 -------- | ----------- **start_date**
`不为空`| 交易的开始日期,格式为YYYYMMDD. **end_date**
`不为空`| 交易的结束日期,格式为YYYYMMDD. ### 返回报文 如果请求成功,返回带交易记录的csv文件;如果请求失败,返回一个json格式的错误对象。 ## 对账文件下载 ```shell GET https://api.nihaopay.com/v1.2/billing ``` 商家需要对交易进行对账,可以通过该接口下载最长10天时间范围内的交易来对账。注意,NihaoPay端未支付成功的订单不会出现对账文件中,支付成功后撤销的交易也不出现对账文件中。北京时间23点启动生成前一天23点到当天23点之间的对账单,建议商户0点之后再获取。 > **请求示例** ```shell $ curl https://api.nihaopay.com/v1.2/billing/?start_date=20170101&end_date=20170105 \ -H "Authorization: Bearer " ``` ### 请求报文 使用GET方式请求。注意:开始日期和结束日期间隔最长10天;不能请求当天的交易。 字段 | 说明 -------- | ----------- **start_date**
`不为空`| 交易的开始日期,格式为YYYYMMDD. **end_date**
`不为空`| 交易的结束日期,格式为YYYYMMDD. ### 返回报文 如果请求成功,返回带交易记录的csv文件;如果请求失败,返回一个json格式的错误对象。 # 账户/提款等 ## 查询账户余额 ```shell GET https://api.nihaopay.com/v1.2/accounts ``` 该接口提供查询商家当前账户余额的功能。 > **请求示例** ```shell $ curl https://api.nihaopay.com/v1.2/accounts \ -H "Authorization: Bearer " ``` ### 请求 使用GET方式请求,无请求参数 > **返回示例** ```json { "accounts": [ { "balance": "100.00", "currency": "USD", "pending_amount": "12.40", "freeze_amount": "0.00" } ] } ``` ### 返回报文 如果请求成功,返回json格式的账户余额对象;如果请求失败,返回一个json格式的错误对象。 字段 | 说明 ------- | ----------- **currency**
`string` | 账户币种 **balance**
`string` | 当前账户余额 **pending_amount**
`string` | 当前未结算消费金额 **freeze_amount**
`string` | 当前未结算退款金额 ## 查询提现历史记录 ```shell GET https://api.nihaopay.com/v1.2/withdrawal/history ``` 返回满足要求的提现交易列表,返回按照时间倒序排列。最多可以查询6个月的提款记录 > **请求示例** ```shell $ curl https://api.nihaopay.com/v1.2/withdrawal/history/?start_date=20170101&end_date=20170105 \ -H "Authorization: Bearer " ``` ### 请求报文 使用GET方式请求。 字段 | 说明 -------- | ----------- **start_date**
`不为空`| 开始日期,格式为YYYYMMDD. **end_date**
`不为空`| 结束日期,格式为YYYYMMDD. > **返回示例** ```json { "withdrawal": [ { "id": "bn2345nb53454kjb", "status": "completed", "amount": "100.00", "currency": "USD", "fee": "0.30", "fee_currency":"USD", "date": "20170101" } ] } ``` ### 返回报文 返回一个提款交易对象的数组,如果在请求的时间段内没有交易,则返回为空数组。 字段 | 说明 ------- | ----------- **id**
`string` | NihaoPay生成的withdrawal ID **status**
`string` | 提款状态. 包括:处理中 `processing`, 完成`completed` **amount**
`int` | 提款金额 **currency**
`string` | 到账币种 **fee**
`string` | 提款手续费 **fee_currency**
`string` | 手续费扣费币种 **date**
`string` | 提款日期,格式:YYYYMMDD ## 查询提现明细 ```shell GET https://api.nihaopay.com/v1.2/withdrawal/detail/{withdrawal_id} ``` 通过withdrawl_id取得相对应的交易金额以及明细 > **请求示例** ```shell $ curl https://api.nihaopay.com/v1.2/withdrawal/detail/{withdrawal_id} \ -H "Authorization: Bearer " ``` ### 请求报文 `withdrawal_id` 以申请提款生成的withdrawal ID作为URL请求参数. ### 返回报文 返回一个CSV文件 # 测试 > **测试地址** ```shell https://apitest.nihaopay.com ``` 我们的API提供测试环境供商户在集成开发时使用,测试时请使用测试请求地址,例如:`https://apitest.nihaopay.com/v1.2/transactions`。在您完成集成开发,转入生产环境时,请将请求地址更换为生产环境地址。 在测试环境,我们提供测试卡和测试账户供您模拟交易,真实的银行卡是不能使用的。 **如果您还没有测试账号,您可以在[NihaoPay网站](https://www.nihaopay.com/apply)上申请一个测试账号来进行接入测试。** ## 银联测试卡 当您通过NihaoPay API请求银联在线支付时,请使用以下测试卡模拟交易。 ### 银联信用卡一 | | | |---|---| 卡号 | 6250 9470 0000 0014 校验码 | 123 有效期 | 12/2033 手机号 | 852-11112222 短信验证码 | 111111 ### 银联借记卡 | | | |---|---| 卡号 | 6226 0900 0000 0048 密码 | 123456 手机号 | 1810000000 短信验证码 | 111111 ## 支付宝测试账号 我们不提供支付宝的测试账号,您可以使用您自己的支付宝账号进行支付测试。一旦您支付成功造成扣款,您可以请求退款或撤销接口将已扣款资金退回至原账户。 ## 微信支付测试信息 我们不提供微信的测试账号,您可以使用您自己的微信账号进行支付测试。一旦您支付成功造成扣款,您可以请求退款或撤销接口将已扣款资金退回至元账户. ## PayPal测试账号 ### 测试账号 | | | |---|---| 账号 | sb-s47aho8657191@personal.example.com 登录密码 | J^Fby/5@ ### PayPal ACDC 测试卡 以下卡片信息来自 NihaoPay PayPal ACDC 商户接入说明,仅限 NihaoPay/PayPal 测试环境使用,请勿用于生产环境。 | | | |---|---| 卡号 | 4111 1111 1111 1111 有效期 | 12/35 CVV | 123 PayPal 当前的[沙箱卡测试指南](https://developer.paypal.com/sandbox-testing/card-testing)列出了其他静态测试卡号和卡号生成器。如果该 NihaoPay ACDC 测试卡在您的沙箱配置中无法使用,请使用 PayPal 指南中的测试卡。 # 错误码 > **错误示例** ```json { "code": 409, "label": "64", "message": "Refund or capture currency does not match the original transaction currency." } ``` 当请求API失败,NihaoPay会返回一个json格式的错误对象. NihaoPay的错误对象遵循HTTP状态码,`2xx` 表示请求成功,你将不会看到错误对象。 `4xx` 表示请求的信息中有错误,可能是请求参数格式不正确,也可能是未经身份验证的请求或未知的请求端点。`5xx` 表示NihaoPay服务器存在内部错误,请与我们的技术支持团队tech_support@nihaopay.com 联系。 ## 错误对象 字段 | 描述 ---------|----------- **code**
`int`| HTTP状态码. **label**
`string`| NihaoPay的错误代码,请提供该字段以便于我们追踪错误信息。 **message**
`string`|错误代码对应的错误描述. ## 错误码列表 code|label|message -------|-------|----------- 200|00| Success 交易成功 402|01| Transaction failed. Please try again.交易失败,请重试 402|02| Cardholder input an incorrect card number. 卡号不正确 402|03| Cardholder\'s issuing bank prevented the transaction.发卡行拒绝交易 402|06| Customer input an expired card number. 卡片已过期 402|11| Customer has insufficient funds available. 账户余额不足 402|14| Cardholder input an incorrect expiration date. 卡片有效期不正确 402|15| Cardholder authentication failed. Please verify cardholder\'s information.验证失败,请检查卡片等信息 402|21| Cardholder authentication failed. Please verify cardholder\'s information.验证失败,请检查卡片等信息 402|22| Card state is incorrect. 卡状态错误 402|30| The amount exceeds transaction limit placed.订单金额超过限额 400|31| Transaction reference number must be unique. Please re-submit.商户订单号不能重复,请更换订单号后重新提交 400|32| This payment channel is restricted. Please contact NihaoPay customer service. 支付方式受限制,请联系NihaoPay 409|33| Transaction failed. Information submitted in a repeat transaction must match the original attempted transaction exactly. 交易失败,重复提交的订单号请与原订单信息一致 402|36| Transaction exceeds the cardholder\'s credit limit. 订单金额超过持卡人的信用卡额度。 429|39| Too many transactions attempts by cardholder.交易次数过多,卡号被限制 402|56| Cardholder\'s chosen payment card is not supported in this Gateway.不支持的卡片 402|57| Cardholder has not activated online payments with their issuing bank.持卡人未激活在线支付功能 404|59| Failed. Transaction have refund or chargeback. 交易失败,原交易已经退款或者被拒付,不能撤销 404|60| Transaction has been cleared, please request refund.交易已清算,不能撤销,请使用退款接口 402|61| Transaction not found.交易未找到 402|62| Transaction is not within the acceptance time range. 不在接受时间范围内,消费交易已被关闭,已经超过退款期限。 402|63| The original transaction failed. You cannot refund, cancel, capture, or release an unsuccessful transaction.原交易支付失败,不能进行退款,撤销或预授权完成等其他管理交易 409|64| Refund or capture currency does not match the original transaction currency.退款或预授权完成交易币种必须与原交易币种一致 409|65| Transaction has previously been cancelled.交易已经取消 409|66| Failed to refund transaction. Transaction has previously been fully refunded.退款失败,交易已经全额退款 402|67| Failed to refund transaction. Refund amount exceeds original transaction amount or remaining transaction balance .退款失败,退款金额超过原交易金额或账户可用余额不足,不能退款 402|68| Failed to capture transaction. Transaction has previously been released.预授权完成失败,预授权交易已经取消 402|69| Failed to capture transaction. Transaction has previously been captured.预授权完成失败,预授权交易已经被捕获扣款,不能重复扣款 402|70| Failed to capture transaction. Capture amount exceeds authorization amount.预授权完成失败,捕获扣款金额不能超过预授权交易金额的115% 402|71| Buyer not exist or buyer account info error 付款人账户不存在或者错误 402|72| Transaction amount is exceed the limit 交易金额超过单笔限额或者超过单日累计总限额 500|81| Merchant config error 商户配置错误,请联系NihaoPay 500|82| Merchant unavailable 商户不可用 500|83| QRcode has expired 二维码已过期 500|84| Service is not activated for this account 服务未开通 402|86| Withdrawal amount exceeds account balance 提款金额超过账户余额 402|87| Withdrawal amount less than the minimum withdrawal amount 提款金额小于最小提款金额 402|88| Invalid application, it's only available for manually withdrawal merchant 提款申请仅对手工提款的商户开放 400|90| The field not valid. 请求参数格式不正确 500|91| Signature error 签名错误 500|92| The {0} field is required.请求字段不能为空 404|93| The Exchange rate not found. 未找到汇率 500|96| Timeout 请求超时 500|97| Inner error 内部错误 500|98| Vendor error 渠道系统出错,请稍后再试 500|99| System error 系统错误,请联系NihaoPay 401|301| Invalid merchant credentials provided 无效的认证信息,或身份验证失败 # API更新日志 ### 2026-11-17 * 分账规则更新:分账币种必须与结算币种一致;收款方必须有该币种结算账户;仅支持自收款渠道;全局分账与指定订单分账不能叠加;北京时间 23:00 至次日 02:00 不能取消分账;reference/remark/notifyUrl 增加格式校验;部分撤销按比例退还手续费.补充查询可代理分账的商户接口,修正查询、执行结果和回调的响应示例. ### 2026-09-15 * 标准安全支付新增 PayPal Crypto:使用 `vendor=paypal` 和 `payment_source=crypto` 发起支付。 * PayPal(包括 Crypto)退款支持 `ipn_url` 异步通知;退款处理中会返回 `pending`,后续以退款 IPN 或退款结果查询为准。 ### 2025-01-16 * 新增微信代扣支付 ### 2024-09-18 * 新增信用卡支付 ### 2023-08-23 * SecurePay支持返回json格式的数据 ### 2023-08-05 * 增加[分账功能](./sharing#分账) ### 2022-07-18 * 增加[Alipay A+接口](./securepay#支付宝-a) ### 2020-09-01 * 更新支持的币种列表 * 新增银联的海关报关支持 ### 2018-06-01 * 新增海关清关接口 * IPN通知中增加渠道付款流水号 ### 2018-05-17 * In-app支持微信支付 * 扫码支付支持银联境外二维码,仅限美国地区商户 ### 2018-03-15 * 新增多合一固定收款码接口 * 新增支付宝收款码接口 ### 2017-11-10 * 新增微信小程序支付接口 ### 2017-08-21 * 新增交易下载接口 * 新增固定二维码接口 * 新增查询余额接口 * 新增提现接口 * 新增提现记录查询接口 ### 2017-05-25 * 新增线下[面对面支付接口](./offline#线下面对面支付) * 新增[In-APP支付接口](./securepay#in-app支付) * IPN通知机制的修改 * IPN通知增加签名验证 ### 2017-04-10 * 更新错误码列表 * 新增支持人民币标价金额 ### 2017-03-07 * 新增中文文档 * 快捷支付接口增加`client_ip`字段 * 新增汇率查询接口 * 新增下载对账单接口 ### 2017-01-01 * 启用1.2版本