> For the complete documentation index, see [llms.txt](https://asiabill.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://asiabill.gitbook.io/docs/zhi-fu/geng-duo-zhi-fu-chang-jing/xun-huan-kou-kuan/zhi-lian-zhi-fu.md).

# 直连支付

## 交互流程

![ 循环扣款，首次支付交互图](https://4182117768-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcSYgMg71VCxeEVhWhVFp%2Fuploads%2FxaOaMbeKzFMZBr5S8LQE%2FInitRecurring%EF%BC%88%E6%9C%89PCI%E8%B5%84%E8%B4%A8%EF%BC%89.png?alt=media\&token=8f36f561-b02e-4a36-bf3e-cfbd63c9f16b)

![循环扣款，非首次支付交互图](https://4182117768-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcSYgMg71VCxeEVhWhVFp%2Fuploads%2FdCtUVfHTUlS8Q8UotK5W%2FRecurring.png?alt=media\&token=5669f620-a361-4be7-b3d4-665b9ee4f41c)

## 循环扣款对接流程（首次支付）:

### 1. 创建customer <mark style="color:blue;">**`server`**</mark>

&#x20;         商户服务端调用 创建客户接口：[/customers](https://asiabill.gitbook.io/api-explorer/api-reference/jiao-yi/customer)，获取customerId

### 2. 创建paymentMethod <mark style="color:blue;">**`server`**</mark>

&#x20;         商户服务端调用 创建支付方式接口：[/payment\_methods](https://asiabill.gitbook.io/api-explorer/api-reference/jiao-yi/payment-methods)，获取customerPaymentMethodId

### 3. 扣款请求 <mark style="color:blue;">**`server`**</mark>

&#x20;        1\. 商户服务端调用[/confirmCharge](https://asiabill.gitbook.io/api-explorer/api-reference/jiao-yi/confirm-charge)发起扣款业务.

{% hint style="info" %}

1. 建议商户通过<mark style="color:red;">**服务端**</mark>调用 **confirmCharge** 接口，避免 **signkey** 等信息暴露在浏览器客户端，或者币种、金额在客户端被修改。
2. 首次支付应该传入上述创建的customerId和customerPaymentMethodId，并指定字段tokenType="InitRecurring"，如下图所示：
   {% endhint %}

![](https://4182117768-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcSYgMg71VCxeEVhWhVFp%2Fuploads%2FjhTUF3Crl0aMSduTwzg1%2FInitRecurring%E8%AF%B7%E6%B1%82%E4%BB%A3%E7%A0%81%E6%A1%88%E4%BE%8B.png?alt=media\&token=2f6ff13c-306f-421f-9210-b5464cfda898)

### 4. 验证签名

&#x20;          根据 [数据签名过程](https://asiabill.gitbook.io/api-explorer/fu-lu/shu-ju-qian-ming-guo-cheng) 验证返回信息

### 5. 解析返回信息

1. 首次发起循环扣款，需要进行3DS验证，将解析后的redirectUrl返回给前端，前端跳转用户到3DS页面进行验证
   1. 3DS验证完成后，Asiabill将跳转到商户的returnUrl地址（请参阅 [支付结果跳转](https://asiabill.gitbook.io/api-explorer/webhook/zhi-fu-jie-guo-tiao-zhuan) ），商户端验证签名并解析数据后，将解析结果（成功、失败）返回给前端，前端跳转用户到交易结果展示页面

### 6. webhook 通知处理

在订单完成后，AsiaBill系统会触发webhook，调用商户交易时给定的CallbackUrl，来通知商户交易结果状态，详情请参阅 [webhook](https://asiabill.gitbook.io/api-explorer/webhook/gai-shu)

## 循环扣款对接流程（非首次支付）:

### 1. 扣款请求 <mark style="color:blue;">**`server`**</mark>

&#x20;        商户服务端调用[/confirmCharge](https://asiabill.gitbook.io/api-explorer/api-reference/jiao-yi/confirm-charge)发起扣款业务

{% hint style="info" %}

1. 如果首次支付失败了，则需要重新创建并发起首次扣款成功后，才能发起后续循环扣款。
2. 如果首次支付成功，可以使用首次支付时创建的customerId,paymentMethodId来发起循环扣款，并指定字段tokenType="Recurring"，如下图所示：
3. 为降低拒付风险，建议尽可能清楚地告知客户收取费用的频率和金额。我们建议在非首次扣款前几天通知客户，例如通过向他们发送电子邮件。
   {% endhint %}

![](https://4182117768-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcSYgMg71VCxeEVhWhVFp%2Fuploads%2FzSSqSBWQZcmsdlHN99Ly%2FRecurring%E8%AF%B7%E6%B1%82%E4%BB%A3%E7%A0%81%E6%A1%88%E4%BE%8B.png?alt=media\&token=5836f659-538f-4227-bc85-c4c34208482d)

### 2. 验证签

&#x20;          根据 [数据签名过程](https://asiabill.gitbook.io/api-explorer/fu-lu/shu-ju-qian-ming-guo-cheng) 验证返回信息

### 3. 解析返回信息

&#x20;          不需要进行3DS验证，直接解析交易结果

### 4. webhook 通知处理

在订单完成后，AsiaBill系统会触发webhook，调用商户交易时给定的callbackUrl，来通知商户交易结果状态，详情请参阅 [webhook](https://asiabill.gitbook.io/api-explorer/webhook/gai-shu)
