# 接受银行转账 用 Payment Intents API 接受银行转账付款。 当您第一次接受客户的银行转账付款时,Stripe 会为他们生成一个虚拟银行账户,然后您可以直接分享给他们。今后来自该客户的所有银行转账付款都会发到此银行账户。在一些国家,Stripe 还为您提供一个独特的转账参考码,您的客户每次转账时都需包含此号码,以更方便地进行对账。在某些国家,可以免费创建的虚拟银行账号数量是有限制的。 下图概括介绍了接受银行转账付款时的常用步骤: #### 用账单 接受银行转账付款时的一般步骤 (See full diagram at https://docs.stripe.com/payments/bank-transfers/accept-a-payment) #### 不用账单 ![](https://b.stripecdn.com/docs-statics-srv/assets/without-invoices-diagram-1.a17fe04695ef532427f25a9e1276ee2e.svg) ## 处理少付和多付 通过银行转账付款时,客户的实际转账金额有可能多于或少于预期付款金额。如果客户转账金额不足,Stripe 会先将收到的部分款项记入未结的 Payment Intent 中。但账单不会部分入账,将在全额到账前保持未结状态。 如果客户支付的金额超过预期金额,Stripe 会尝试核对收到的金额和未结金额,并将剩余的超出金额保留在客户余额中。了解更多有关 [Stripe 如何处理对账](https://docs.stripe.com/payments/customer-balance/reconciliation.md) 的信息。 #### 用账单 客户少付时: 客户发送了一笔小于预期金额的银行转账 (See full diagram at https://docs.stripe.com/payments/bank-transfers/accept-a-payment) 客户多付时: 客户发送了一笔大于预期金额的银行转账 (See full diagram at https://docs.stripe.com/payments/bank-transfers/accept-a-payment) #### 不用账单 ![](https://b.stripecdn.com/docs-statics-srv/assets/without-invoices-diagram-2.464fe916d5822422144c8aea0f31ed45.svg) ![](https://b.stripecdn.com/docs-statics-srv/assets/without-invoices-diagram-3.b1992851a5f3492d14eaa35e336b0e9f.svg) ## 多个开启付款或账单的处理 您可能有多个开启的付款或账单,可通过银行转账来支付。在默认设置中,Stripe 会尝试用诸如转账的参考码或转账金额来[自动对账](https://docs.stripe.com/payments/customer-balance/reconciliation.md)银行转账。 您可以禁用自动对账,然后自行[手动对账](https://docs.stripe.com/payments/customer-balance/reconciliation.md#cash-manual-reconciliation)付款和账单。可单独覆盖掉对某个客户的自动对账行为,方法是将[对账模式](https://docs.stripe.com/api/customers/create.md#create_customer-cash_balance-settings-reconciliation_mode)设置为手动模式。 > 如果您的集成使用账单,请参阅[“发送附带银行转账说明的账单”](https://docs.stripe.com/invoicing/bank-transfer.md)。 # 直接 API ## 设置 Stripe [服务器端] 首先,您需要有一个 Stripe 账户。[立即注册](https://dashboard.stripe.com/register)。 用我们的官方库从您的应用程序访问 Stripe API: #### Ruby ```bash # Available as a gem sudo gem install stripe ``` ```ruby # If you use bundler, you can add this line to your Gemfile gem 'stripe' ``` ## 创建或检索客户 [服务器端] 您必须关联一个代表您客户的对象,以便对每笔银行转账支付进行对账。如果您已有现有客户,可跳过此步骤。否则,请创建一个新客户。 > #### 使用 Accounts v2 API 表示客户 > > Accounts v2 API 通常面向 Connect 用户开放,并对其他 Stripe 用户开放公开预览。如果您参与了 Accounts v2 预览,您需要在代码中[指定预览版本](https://docs.stripe.com/api-v2-overview.md#sdk-and-api-versioning)。 > > 如需申请 Accounts v2 预览版的访问权限, > > 在大多数应用场景下,我们建议[将您的客户建模为客户配置的 Account 对象](https://docs.stripe.com/accounts-v2/use-accounts-as-customers.md),而不是使用 [Customer](https://docs.stripe.com/api/customers.md) 对象。 当客户在您的企业创建账户或保存支付方式时,创建一个客户配置的 [Account](https://docs.stripe.com/api/v2/core/accounts/create.md#v2_create_accounts-configuration-customer) 或 [Customer](https://docs.stripe.com/api/customers/create.md)。将该对象的 ID 与您系统内部的客户标识进行关联。 创建新客户或检索现有客户,并将其与该笔支付关联。 #### Accounts v2 ```curl curl -X POST https://api.stripe.com/v2/core/accounts \ -H "Authorization: Bearer <>" \ -H "Stripe-Version: 2026-05-27.preview" \ --json '{ "contact_email": "jenny.rosen@example.com", "display_name": "Jenny Rosen", "configuration": { "customer": {} }, "include": [ "configuration.customer" ] }' ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/customers \ -u "<>:" \ -d "name=Jenny Rosen" \ --data-urlencode "email=jenny.rosen@example.com" ``` ## 创建并确认 PaymentIntent [服务器端] [PaymentIntent](https://docs.stripe.com/api/payment_intents/object.md) 是一个对象,代表您向客户收款的意图,用于跟踪支付流程在各个阶段的生命周期。在服务器端创建并确认 `PaymentIntent`,并指定待收款的金额与币种。您还必须在 `PaymentIntent` 创建请求中填写 [customer](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-customer) 或 [customer_account](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-customer_account) 参数。对于未关联客户的 `PaymentIntents`,不支持银行转账。 #### 从管理平台管理支付方式 创建 Payment Intent 之前,请确保在管理平台的[支付方式设置](https://dashboard.stripe.com/settings/payment_methods)页面中开启**银行转账**。 > 借助[动态支付方式](https://docs.stripe.com/payments/payment-methods/dynamic-payment-methods.md),Stripe 会根据交易金额、货币和支付流程等因素返回符合条件的支付方式。 #### Accounts v2 #### 美国 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d currency=usd \ -d "automatic_payment_methods[enabled]=true" \ --data-urlencode "return_url=https://example.com/return_url" \ -d "payment_method_data[type]=customer_balance" \ -d confirm=true ``` #### 英国 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d currency=gbp \ -d "automatic_payment_methods[enabled]=true" \ --data-urlencode "return_url=https://example.com/return_url" \ -d "payment_method_data[type]=customer_balance" \ -d confirm=true ``` #### 欧盟 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d currency=eur \ -d "automatic_payment_methods[enabled]=true" \ --data-urlencode "return_url=https://example.com/return_url" \ -d "payment_method_data[type]=customer_balance" \ -d confirm=true ``` 要本地化向客户显示的 IBAN,请设置 [`identity.individual.address`](https://docs.stripe.com/api/v2/core/accounts/object.md#v2_account_object-identity-individual-address) 属性或[在管理平台中编辑账户](https://docs.stripe.com/invoicing/customer.md#edit-a-customer)。 我们支持 的 IBAN 本地化: - 如您尚未为客户配置国家/地区,或其所在国家/地区不支持 IBAN 本地化,系统将回退至您的 Stripe 账户所在国家/地区。 - 如果您的 Stripe 账户所在的国家不支持 IBAN 本地化,我们将返回 `IE`。 > 目前不能为西班牙 (ES) 创建新的本地化虚拟银行账号。请改用其他 EU VBAN 国家/地区。 #### 日本 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=19000 \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d currency=jpy \ -d "automatic_payment_methods[enabled]=true" \ --data-urlencode "return_url=https://example.com/return_url" \ -d "payment_method_data[type]=customer_balance" \ -d confirm=true ``` #### 墨西哥 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d currency=mxn \ -d "automatic_payment_methods[enabled]=true" \ --data-urlencode "return_url=https://example.com/return_url" \ -d "payment_method_data[type]=customer_balance" \ -d confirm=true ``` #### Customers v1 #### 美国 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d "customer={{CUSTOMER_ID}}" \ -d currency=usd \ -d "automatic_payment_methods[enabled]=true" \ --data-urlencode "return_url=https://example.com/return_url" \ -d "payment_method_data[type]=customer_balance" \ -d confirm=true ``` #### 英国 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d "customer={{CUSTOMER_ID}}" \ -d currency=gbp \ -d "automatic_payment_methods[enabled]=true" \ --data-urlencode "return_url=https://example.com/return_url" \ -d "payment_method_data[type]=customer_balance" \ -d confirm=true ``` #### 欧盟 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d "customer={{CUSTOMER_ID}}" \ -d currency=eur \ -d "automatic_payment_methods[enabled]=true" \ --data-urlencode "return_url=https://example.com/return_url" \ -d "payment_method_data[type]=customer_balance" \ -d confirm=true ``` 要以本地方式向客户显示 IBAN,您可以通过设置 [`address.country`](https://docs.stripe.com/api/customers/object.md#customer_object-address-country) 属性或[在管理平台中编辑客户](https://docs.stripe.com/invoicing/customer.md#edit-a-customer)来配置客户的国家/地区。 我们支持 的 IBAN 本地化: - 如果尚未为您的客户配置国家/地区,或其所在国家/地区不支持 IBAN 本地化,系统将默认使用您的 Stripe 账户所属国家/地区。 - 如果您的 Stripe 账户所在的国家不支持 IBAN 本地化,我们将返回 `IE`。 > 目前不能为西班牙 (ES) 创建新的本地化虚拟银行账号。请改用其他 EU VBAN 国家/地区。 #### 日本 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=19000 \ -d "customer={{CUSTOMER_ID}}" \ -d currency=jpy \ -d "automatic_payment_methods[enabled]=true" \ --data-urlencode "return_url=https://example.com/return_url" \ -d "payment_method_data[type]=customer_balance" \ -d confirm=true ``` #### 墨西哥 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d "customer={{CUSTOMER_ID}}" \ -d currency=mxn \ -d "automatic_payment_methods[enabled]=true" \ --data-urlencode "return_url=https://example.com/return_url" \ -d "payment_method_data[type]=customer_balance" \ -d confirm=true ``` 在最新版的 API 中,可以选择性指定 `automatic_payment_methods` 参数,因为 Stripe 会默认开启其功能。 如果客户的余额足够高,足以完成付款,则 PaymentIntent 立即成功,显示 `succeeded` 状态。当客户不小心多付时,他们可以累算余额,这在银行转账中很常见。您必须要在[您所在地的特定时间段内确认客户余额](https://docs.stripe.com/payments/customer-balance/reconciliation.md)。 #### 手动列出支付方式 如需通过 API 手动指定支付方式,请将 `customer_balance` 添加到您的 `PaymentIntent` 的[支付方式类型](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_types)列表中。指定客户配置的 [Account](https://docs.stripe.com/api/v2/core/accounts/object.md#v2_account_object-id) 或 [Customer](https://docs.stripe.com/api/customers/object.md#customer_object-id) 的ID。 #### Accounts v2 #### 美国 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=usd \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d "payment_method_types[]=customer_balance" \ -d "payment_method_data[type]=customer_balance" \ -d "payment_method_options[customer_balance][funding_type]=bank_transfer" \ -d "payment_method_options[customer_balance][bank_transfer][type]=us_bank_transfer" \ -d confirm=true ``` 如果客户的余额足够高,足以完成付款,则 PaymentIntent 立即成功,显示 `succeeded` 状态。当客户不小心多付时,他们可以累算余额,这在银行转账中很常见。您必须要在[您所在地的特定时间段内确认客户余额](https://docs.stripe.com/payments/customer-balance/reconciliation.md)。 - 将 `bank_transfer` 用作 [funding_type](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_options-customer_balance-funding_type),指定客户余额不足以完成转账时该如何做。 - 将 `us_bank_transfer` 用作 [bank_transfer[type]](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_options-customer_balance-bank_transfer-type),指定可用于支付资金的银行转账类型。 #### 英国 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=gbp \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d "payment_method_types[]=customer_balance" \ -d "payment_method_data[type]=customer_balance" \ -d "payment_method_options[customer_balance][funding_type]=bank_transfer" \ -d "payment_method_options[customer_balance][bank_transfer][type]=gb_bank_transfer" \ -d confirm=true ``` 如果客户的余额足够高,足以完成付款,则 PaymentIntent 立即成功,显示 `succeeded` 状态。当客户不小心多付时,他们可以累算余额,这在银行转账中很常见。您必须要在[您所在地的特定时间段内确认客户余额](https://docs.stripe.com/payments/customer-balance/reconciliation.md)。 - 将 `bank_transfer` 用作 [funding_type](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_options-customer_balance-funding_type),指定客户余额不足以完成转账时该如何做。 - 将 `gb_bank_transfer` 用作 [bank_transfer[type]](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_options-customer_balance-bank_transfer-type),指定可用于支付资金的银行转账类型。 #### 欧盟 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=eur \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d "payment_method_types[]=customer_balance" \ -d "payment_method_data[type]=customer_balance" \ -d "payment_method_options[customer_balance][funding_type]=bank_transfer" \ -d "payment_method_options[customer_balance][bank_transfer][type]=eu_bank_transfer" \ -d "payment_method_options[customer_balance][bank_transfer][eu_bank_transfer][country]=FR" \ -d confirm=true ``` 如果客户的余额足够高,足以完成付款,则 PaymentIntent 立即成功,显示 `succeeded` 状态。当客户不小心多付时,他们可以累算余额,这在银行转账中很常见。您必须要在[您所在地的特定时间段内确认客户余额](https://docs.stripe.com/payments/customer-balance/reconciliation.md)。 - 将 `bank_transfer` 用作 [funding_type](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_options-customer_balance-funding_type),指定客户余额不足以完成转账时该如何做。 - 将 `eu_bank_transfer` 用作 [bank_transfer[type]](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_options-customer_balance-bank_transfer-type),指定可用于支付资金的银行转账类型。 - 将 [payment_method_options[customer_balance][bank_transfer][eu_bank_transfer][country]](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_options-customer_balance-bank_transfer-eu_bank_account-country) 设置为 中的某一个。向客户显示的 IBAN 会根据所选择的国家/地区进行本地化处理。 > 目前不能为西班牙 (ES) 创建新的本地化虚拟银行账号。请改用其他 EU VBAN 国家/地区。 #### 日本 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=19000 \ -d currency=jpy \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d "payment_method_types[]=customer_balance" \ -d "payment_method_data[type]=customer_balance" \ -d "payment_method_options[customer_balance][funding_type]=bank_transfer" \ -d "payment_method_options[customer_balance][bank_transfer][type]=jp_bank_transfer" \ -d confirm=true ``` 如果客户的余额足够高,足以完成付款,则 PaymentIntent 立即成功,显示 `succeeded` 状态。当客户不小心多付时,他们可以累算余额,这在银行转账中很常见。您必须要在[您所在地的特定时间段内确认客户余额](https://docs.stripe.com/payments/customer-balance/reconciliation.md)。 - 将 `bank_transfer` 用作 [funding_type](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_options-customer_balance-funding_type),指定客户余额不足以完成转账时该如何做。 - 将 `jp_bank_transfer` 用作 [bank_transfer[type]](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_options-customer_balance-bank_transfer-type),指定可用于支付资金的银行转账类型。 #### 墨西哥 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=mxn \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d "payment_method_types[]=customer_balance" \ -d "payment_method_data[type]=customer_balance" \ -d "payment_method_options[customer_balance][funding_type]=bank_transfer" \ -d "payment_method_options[customer_balance][bank_transfer][type]=mx_bank_transfer" \ -d confirm=true ``` 如果客户的余额足够高,足以完成付款,则 PaymentIntent 立即成功,显示 `succeeded` 状态。当客户不小心多付时,他们可以累算余额,这在银行转账中很常见。您必须要在[您所在地的特定时间段内确认客户余额](https://docs.stripe.com/payments/customer-balance/reconciliation.md)。 - 将 `bank_transfer` 用作 [funding_type](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_options-customer_balance-funding_type),指定客户余额不足以完成转账时该如何做。 - 将 `mx_bank_transfer` 用作 [bank_transfer[type]](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_options-customer_balance-bank_transfer-type),指定可用于支付资金的银行转账类型。 #### Customers v1 #### 美国 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=usd \ -d "customer={{CUSTOMER_ID}}" \ -d "payment_method_types[]=customer_balance" \ -d "payment_method_data[type]=customer_balance" \ -d "payment_method_options[customer_balance][funding_type]=bank_transfer" \ -d "payment_method_options[customer_balance][bank_transfer][type]=us_bank_transfer" \ -d confirm=true ``` 如果客户的余额足够高,足以完成付款,则 PaymentIntent 立即成功,显示 `succeeded` 状态。当客户不小心多付时,他们可以累算余额,这在银行转账中很常见。您必须要在[您所在地的特定时间段内确认客户余额](https://docs.stripe.com/payments/customer-balance/reconciliation.md)。 - 将 `bank_transfer` 用作 [funding_type](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_options-customer_balance-funding_type),指定客户余额不足以完成转账时该如何做。 - 将 `us_bank_transfer` 用作 [bank_transfer[type]](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_options-customer_balance-bank_transfer-type),指定可用于支付资金的银行转账类型。 #### 英国 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=gbp \ -d "customer={{CUSTOMER_ID}}" \ -d "payment_method_types[]=customer_balance" \ -d "payment_method_data[type]=customer_balance" \ -d "payment_method_options[customer_balance][funding_type]=bank_transfer" \ -d "payment_method_options[customer_balance][bank_transfer][type]=gb_bank_transfer" \ -d confirm=true ``` 如果客户的余额足够高,足以完成付款,则 PaymentIntent 立即成功,显示 `succeeded` 状态。当客户不小心多付时,他们可以累算余额,这在银行转账中很常见。您必须要在[您所在地的特定时间段内确认客户余额](https://docs.stripe.com/payments/customer-balance/reconciliation.md)。 - 将 `bank_transfer` 用作 [funding_type](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_options-customer_balance-funding_type),指定客户余额不足以完成转账时该如何做。 - 将 `gb_bank_transfer` 用作 [bank_transfer[type]](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_options-customer_balance-bank_transfer-type),指定可用于支付资金的银行转账类型。 #### 欧盟 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=eur \ -d "customer={{CUSTOMER_ID}}" \ -d "payment_method_types[]=customer_balance" \ -d "payment_method_data[type]=customer_balance" \ -d "payment_method_options[customer_balance][funding_type]=bank_transfer" \ -d "payment_method_options[customer_balance][bank_transfer][type]=eu_bank_transfer" \ -d "payment_method_options[customer_balance][bank_transfer][eu_bank_transfer][country]=FR" \ -d confirm=true ``` 如果客户的余额足够高,足以完成付款,则 PaymentIntent 立即成功,显示 `succeeded` 状态。当客户不小心多付时,他们可以累算余额,这在银行转账中很常见。您必须要在[您所在地的特定时间段内确认客户余额](https://docs.stripe.com/payments/customer-balance/reconciliation.md)。 - 将 `bank_transfer` 用作 [funding_type](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_options-customer_balance-funding_type),指定客户余额不足以完成转账时该如何做。 - 将 `eu_bank_transfer` 用作 [bank_transfer[type]](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_options-customer_balance-bank_transfer-type),指定可用于支付资金的银行转账类型。 - 将 [payment_method_options[customer_balance][bank_transfer][eu_bank_transfer][country]](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_options-customer_balance-bank_transfer-eu_bank_account-country) 设置为 中的某一个。向客户显示的 IBAN 会根据所选择的国家/地区进行本地化处理。 > 目前不能为西班牙 (ES) 创建新的本地化虚拟银行账号。请改用其他 EU VBAN 国家/地区。 #### 日本 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=19000 \ -d currency=jpy \ -d "customer={{CUSTOMER_ID}}" \ -d "payment_method_types[]=customer_balance" \ -d "payment_method_data[type]=customer_balance" \ -d "payment_method_options[customer_balance][funding_type]=bank_transfer" \ -d "payment_method_options[customer_balance][bank_transfer][type]=jp_bank_transfer" \ -d confirm=true ``` 如果客户的余额足够高,足以完成付款,则 PaymentIntent 立即成功,显示 `succeeded` 状态。当客户不小心多付时,他们可以累算余额,这在银行转账中很常见。您必须要在[您所在地的特定时间段内确认客户余额](https://docs.stripe.com/payments/customer-balance/reconciliation.md)。 - 将 `bank_transfer` 用作 [funding_type](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_options-customer_balance-funding_type),指定客户余额不足以完成转账时该如何做。 - 将 `jp_bank_transfer` 用作 [bank_transfer[type]](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_options-customer_balance-bank_transfer-type),指定可用于支付资金的银行转账类型。 #### 墨西哥 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=mxn \ -d "customer={{CUSTOMER_ID}}" \ -d "payment_method_types[]=customer_balance" \ -d "payment_method_data[type]=customer_balance" \ -d "payment_method_options[customer_balance][funding_type]=bank_transfer" \ -d "payment_method_options[customer_balance][bank_transfer][type]=mx_bank_transfer" \ -d confirm=true ``` 如果客户的余额足够高,足以完成付款,则 PaymentIntent 立即成功,显示 `succeeded` 状态。当客户不小心多付时,他们可以累算余额,这在银行转账中很常见。您必须要在[您所在地的特定时间段内确认客户余额](https://docs.stripe.com/payments/customer-balance/reconciliation.md)。 - 将 `bank_transfer` 用作 [funding_type](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_options-customer_balance-funding_type),指定客户余额不足以完成转账时该如何做。 - 将 `mx_bank_transfer` 用作 [bank_transfer[type]](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_options-customer_balance-bank_transfer-type),指定可用于支付资金的银行转账类型。 > 创建付款时始终要指定 `payment_method_types`。您不能将 `customer_balance` 用于[未来的付款](https://docs.stripe.com/payments/save-and-reuse.md)。 ## Optional: 发送付款说明邮件 您可以从[管理平台](https://dashboard.stripe.com/settings/emails)启用银行转账付款说明邮件。启用付款说明邮件后,当以下情况发生时,Stripe 会给客户发送邮件: - PaymentIntent 已确认,但客户余额不足。 - 客户发送了银行转账,但资金不足,无法完成付款。 银行转账付款说明邮件包含应付金额、用于转账的银行信息以及到 Stripe 托管说明页面的链接。 > 在沙盒中,付款说明邮件只会发送到 Stripe 账户关联的邮件地址。 ## 引导客户完成银行转账 [客户端] 如果客户的余额不足以支付请求的金额,则 PaymentIntent 显示 `requires_action` 状态。响应中有一个 `next_action` 字段,包含 `display_bank_transfer_instructions` 的一个 `type` 值。`next_action[display_bank_transfer_instructions]` 散列中包含向客户显示的信息,以便其完成银行转账。为确保资金结算,请指示您的客户使用所提供的确切信息,特别是账户名和账号(如果适用)。 > 在*真实模式* (Use this mode when you’re ready to launch your app. Card networks or payment providers process payments)下,Stripe 为每个客户提供唯一一套银行转账信息。相反,在测试环境中,Stripe 向所有客户提供的都是无效的银行转账详情。与真实模式不同,这些无效的详情可能并不总是唯一。 #### 美国 | 字段 | 描述 | | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | | [类型](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-type) | 使用的银行转账类型。美国的类型必须为 `us_bank_transfer`。 | | [参考](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-reference) | 识别银行转账的唯一参考代码。引导客户在其银行转账的参考字段中包含此代码。 | | [amount_remaining](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-amount_remaining) | 完成付款所需转的剩余金额。引导客户转此金额。如果客户余额中之前存在的资金已应用到 PaymentIntent 或如果客户少付了,则此金额可能不同于 PaymentIntent 金额。 | | [货币](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-currency) | 剩余金额的币种。 | | [financial_addresses](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions) | 美国银行账户金融地址列表。类型包含 `aba` 和 `swift`。查看下方详情。 | | [hosted_instructions_url](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-hosted_instructions_url) | 一个指向托管页面的链接,引导客户完成转账。 | #### aba 散列 `aba` 散列示例: ```json { "aba": { "account_number": "111222333444", "bank_name": "Wells Fargo Bank, NA", "routing_number": "444555666" }, "supported_networks": [ "ach", "domestic_wire_us" ], "type": "aba" } ``` | 字段 | 值 | 描述 | | -------------------- | ------------------------------ | ------------ | | `type` | `aba` | 金融机构地址类型。 | | `supported_networks` | - `ach` - `domestic_wire_us` | 该地址支持的卡组织列表。 | | `aba.account_number` | 111222333444 | ABA 账号。 | | `aba.routing_number` | 444555666 | ABA 路径号码。 | | `aba.bank_name` | Wells Fargo Bank, NA | 银行名称。 | #### swift 散列 `swift` 散列示例: ```json { "swift": { "account_number": "111222333444", "bank_name": "Wells Fargo Bank, NA", "swift_code": "AAAA-BB-CC-123" }, "supported_networks": [ "swift" ], "type": "swift" } ``` | 字段 | 值 | 描述 | | ---------------------- | -------------------- | ------------ | | `type` | `swift` | 金融机构地址类型。 | | `supported_networks` | - `swift` | 该地址支持的卡组织列表。 | | `swift.account_number` | 111222333444 | SWIFT 账号。 | | `swift.swift_code` | AAAA-BB-CC-123 | SWIFT 代码。 | | `swift.bank_name` | Wells Fargo Bank, NA | 银行名称。 | #### 结算时间 在引导您的客户用您提供的信息在其银行发起转账后,可能需要长达 5 天才能完成转账。结算时间取决于转账到达 Stripe 的银行通道: - ACH 转账为 1-3 个工作日到账。 - 国内电汇 (Fedwire) 当天到账(取决于转账是否是在银行下班前发出)。 - 国际电汇 (SWIFT) 为 1-5 个工作日到账。 #### 英国 | 字段 | 描述 | | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | | [类型](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-type) | 使用的银行转账类型。英国的类型必须为 `gb_bank_transfer`。 | | [参考](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-reference) | 识别银行转账的唯一参考代码。引导客户在其银行转账的参考字段中包含此代码。 | | [amount_remaining](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-amount_remaining) | 完成付款所需转的剩余金额。引导客户转此金额。如果客户余额中之前存在的资金已应用到 PaymentIntent 或如果客户少付了,则此金额可能不同于 PaymentIntent 金额。 | | [货币](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-currency) | 剩余金额的币种。 | | [financial_addresses](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions) | 英国银行账户金融地址列表。类型包含 `sort_code`。查看下方详情。 | | [hosted_instructions_url](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-hosted_instructions_url) | 一个指向托管页面的链接,引导客户完成转账。 | ### sort_code 散列 `sort_code` 散列示例: ```json { "sort_code": { "account_holder_name": "Demo Test Inc.", "account_number": "98765432", "sort_code": "200000" }, "supported_networks": [ "bacs", "fps" ], "type": "sort_code" } ``` | 字段 | 值 | 描述 | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ----------------- | | [类型](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-financial_addresses-type) | `sort_code` | 金融机构地址类型。 | | [supported_networks](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-financial_addresses-supported_networks) | - `bacs` - `fps` | 该地址支持的卡组织列表。 | | [sort_code.account_number](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-financial_addresses-sort_code-account_number) | 98765432 | 5 位数账号。 | | [sort_code.sort_code](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-financial_addresses-sort_code-sort_code) | 200000 | 6 位数分类代码。 | | [sort_code.account_holder_name](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-financial_addresses-sort_code-account_holder_name) | Demo Test Inc. | 拥有该银行账户的个人或公司的名称。 | #### 结算时间 在引导您的客户用您提供的信息在其银行发起转账后,可能需要长达 5 天才能完成转账。结算时间取决于转账到达 Stripe 的银行通道: - FPS 转账在 15 分钟内。 - BACS 转账 5 天内到账。 > 目前不支持通过 [CHAPS](https://www.bankofengland.co.uk/payment-and-settlement/chaps) 支付组织发送银行转账。 #### 欧盟 | 字段 | 描述 | | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | | [类型](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-type) | 使用的银行转账类型。欧盟的类型必须为 `eu_bank_transfer`。 | | [参考](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-reference) | 识别银行转账的唯一参考代码。引导客户在其银行转账的参考字段中包含此代码。 | | [amount_remaining](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-amount_remaining) | 完成付款所需转的剩余金额。引导客户转此金额。如果客户余额中之前存在的资金已应用到 PaymentIntent 或如果客户少付了,则此金额可能不同于 PaymentIntent 金额。 | | [货币](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-currency) | 剩余金额的币种。 | | [financial_addresses](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions) | 欧盟银行账户金融地址列表。类型包含 `iban`。查看下方详情。 | | [hosted_instructions_url](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-hosted_instructions_url) | 一个指向托管页面的链接,引导客户完成转账。 | ### iban 散列 `iban` 散列示例: ```json { "iban": { "account_holder_name": "Demo Test Inc.", "bic": "CITINL2XXXX", "country": "NL", "iban": "NL40CITI7000799556 " }, "supported_networks": [ "sepa" ], "type": "iban" } ``` | 字段 | 值 | 描述 | | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | [类型](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-financial_addresses-type) | `iban` | 金融机构地址类型。 | | [supported_networks](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-financial_addresses-supported_networks) | - `sepa` | 该地址支持的卡组织列表。 | | [iban.iban](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-financial_addresses-iban-iban) | NL40CITI7000799556 | 客户需要付款到的 IBAN。 如果您从[管理平台](https://dashboard.stripe.com/settings/payment_methods)中管理支付方式,则根据客户[国家](https://docs.stripe.com/api/customers/object.md#customer_object-country)或您的 Stripe 账户的国家选择 IBAN 的国家/地区。 如果您用 [payment_method_types](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_types) 参数手动列出支付方式,则根据请求中传递的[国家](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_options-customer_balance-bank_transfer-eu_bank_transfer-country)参数选择 IBAN 的国家。 | | [iban.bic](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-financial_addresses-iban-bic) | CITINL2XXXX | 此 IBAN 的 BIC。 | | [iban.country](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-financial_addresses-iban-country) | `NL` | 资金要转往的银行账户的两字母国家代码。 | | [iban.account_holder_name](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-financial_addresses-iban-account_holder_name) | Demo Test Inc. | 拥有该银行账户的个人或公司的名称。 | #### 结算时间 对于国内转账,请让您的客户使用您提供的详细信息发起欧洲单一欧元支付区 (SEPA) 即时转账(在可用的情况下)。资金通常在数秒内到账,最迟 30 分钟内到账。若在周末、银行假日转账,或发送方银行无法通过即时转账系统处理支付,则结算时间可能会延长。在这些情况下,转账将作为标准的 SEPA 支付进行处理。 > 目前,接收国际欧元转账功能处于预览阶段。如需获取早期访问权限,请联系 [sepa-bank-transfers-beta@stripe.com](mailto:sepa-bank-transfers-beta@stripe.com)。 #### 日本 | 字段 | 描述 | | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | | [类型](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-type) | 使用的银行转账类型。日本的类型必须为 `jp_bank_transfer`。 | | [参考](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-reference) | 此字段未使用。 | | [amount_remaining](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-amount_remaining) | 完成付款所需转的剩余金额。引导客户转此金额。如果客户余额中之前存在的资金已应用到 PaymentIntent 或如果客户少付了,则此金额可能不同于 PaymentIntent 金额。 | | [货币](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-currency) | 剩余金额的币种。 | | [financial_addresses](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-financial_addresses) | 日本银行账户金融地址列表。类型包含 `zengin`。查看下方详情。 | | [hosted_instructions_url](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-hosted_instructions_url) | 一个指向托管页面的链接,引导客户完成转账。 | ### zengin 散列 `zengin` 散列示例: ```json { "zengin": { "account_holder_name": "ストライプジャパン(カ シュウノウダイコウ", "account_number": "1234567", "account_type": "futsu", "bank_code": "0009", "bank_name": "三井住友銀行", "branch_code": "950", "branch_name": "東京第二" }, "supported_networks": [ "zengin" ], "type": "zengin" } ``` | 字段 | 值 | 描述 | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ------------ | | [类型](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-financial_addresses-type) | `zengin` | 金融机构地址类型。 | | [supported_networks](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-financial_addresses-supported_networks) | - `zengin` | 该地址支持的卡组织列表。 | | [zengin.bank_code](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-financial_addresses-zengin-bank_code) | 0009 | 4 位数银行代码。 | | [zengin.bank_name](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-financial_addresses-zengin-bank_name) | 三井住友銀行 | 银行名称。 | | [zengin.branch_code](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-financial_addresses-zengin-branch_code) | 950 | 3 位数分行代码。 | | [zengin.branch_name](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-financial_addresses-zengin-branch_name) | 東京第二 | 分行名称。 | | [zengin.account_type](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-financial_addresses-zengin-account_type) | `futsu`, `toza` | 账户类型。 | | [zengin.account_holder_name](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-financial_addresses-zengin-account_holder_name) | ストライプジャパン(カ シュウノウダイコウ | 账户持有人姓名。 | | [zengin.account_number](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-financial_addresses-zengin-account_number) | 1234567 | 7 位数账号。 | #### 结算时间 引导您的客户用您提供的信息在其银行发起转账。 在营业时间内进行的转账将在当天到账。营业时间以外进行的转账将在下一工作日到账。 #### MX | 字段 | 描述 | | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | | [类型](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-type) | 使用的银行转账类型。墨西哥的类型必须为 `mx_bank_transfer`。 | | [参考](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-reference) | 识别银行转账的唯一参考代码。引导客户在其银行转账的参考字段中包含此代码。 | | [amount_remaining](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-amount_remaining) | 完成付款所需转的剩余金额。引导客户转此金额。如果客户余额中之前存在的资金已应用到 PaymentIntent 或如果客户少付了,则此金额可能不同于 PaymentIntent 金额。 | | [货币](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-currency) | 剩余金额的币种。 | | [financial_addresses](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions) | 墨西哥银行账户金融地址列表。类型包括 `spei`。查看下方详情。 | | [hosted_instructions_url](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-hosted_instructions_url) | 一个指向托管页面的链接,引导客户完成转账。 | ### spei 散列 `spei` 散列示例: ```json { "spei": { "bank_code": "002", "bank_name": "BANAMEX", "clabe": "002180650612345670" }, "supported_networks": [ "spei" ], "type": "spei" } ``` | 字段 | 值 | 描述 | | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | -------------- | | [类型](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-financial_addresses-type) | `spei` | 金融机构地址类型。 | | [supported_networks](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-financial_addresses-supported_networks) | - `spei` | 该地址支持的卡组织列表。 | | [spei.clabe](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-financial_addresses-spei-clabe) | 002180650612345670 | 18 位 CLABE 账号。 | | [spei.bank_code](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-financial_addresses-spei-bank_code) | 002 | 3 位数银行代码。 | | [spei.bank_name](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-display_bank_transfer_instructions-financial_addresses-spei-bank_name) | BANAMEX | 银行机构的简短名称 | 引导您的客户用您提供的信息在其银行发起转账。 无论是否为银行工作日,大多数付款预计均会在 10 分钟内到账。 ## 确认 PaymentIntent 成功 PaymentIntent 保持在 `requires_action` 状态,直至资金到达银行账户。资金就位后,PaymentIntent 的状态从 `requires_action` 更新为 `succeeded`。 需设置您的 *webhook* (A webhook is a real-time push notification sent to your application as a JSON payload through HTTPS requests) 端点后才能开始接收 `payment_intent.partially_funded` 事件。 您可以[从管理平台添加 webhook](https://dashboard.stripe.com/webhooks/create)。 或者,您可以用 [Webhook Endpoints API](https://docs.stripe.com/api/webhook_endpoints.md) 开始接收 [payment_intent.partially_funded](https://docs.stripe.com/api/events/types.md#event_types-payment_intent.partially_funded) 事件。 当我们更新 PaymentIntent 时,Stripe 会在支付流程过程中发送以下事件。 | 事件 | 描述 | 后续步骤 | | --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | | `payment_intent.requires_action` | 在确认过程中,若客户余额资金不足,无法结清 PaymentIntent,则 PaymentIntent 会转为 `requires_action` 状态。如果在确认时客户现金余额已自动应用于该 PaymentIntent,但金额不足以完全覆盖 PaymentIntent 的 `amount`,Stripe 会触发此事件,并附带准确的 `amount_remaining`。 | 引导客户发送一笔金额为 `amount_remaining` 的银行转账。 | | `payment_intent.partially_funded` | 客户发送了一笔银行转账,该转账已应用于 PaymentIntent,但金额不足以完成付款。如果客户在您确认 `PaymentIntent` 后转账金额不足,就会发生这种情况。这可能是由于少付或客户银行收取的费用。部分出资的 PaymentIntent 在付款完成前不会反映在您的账户余额中。 | 引导您的客户用新的 `amount_remaining` 再发送一笔银行转账,从而完成付款。如果想通过部分应用资金来完成付款,可以更新 `amount` 并再次[确认](https://docs.stripe.com/api/payment_intents/confirm.md) PaymentIntent。 | | `payment_intent.succeeded` | 客户付款成功。 | 履行客户购买的商品或服务。 | 如需监听所有与部分付款相关的事件,请同时监听 `requires_action` 和 `partially_funded`。当确认后仍需资金时,Stripe 会触发 `requires_action`。当后续收到客户支付的额外资金,但该资金仍不足以完全覆盖剩余金额时,我们会触发 `partially_funded`。 > 当您更改有部分资金的 PaymentIntent 的金额时,资金将返回到客户余额。如果有其他未完成的 PaymentIntent,则 Stripe 自动提供这些资金。如果客户配置的是手动对账,则您需要再次[应用资金](https://docs.stripe.com/api/payment_intents/apply_customer_balance.md)。 我们建议[用 Webhooks](https://docs.stripe.com/payments/payment-intents/verifying-status.md#webhooks) 来确认成功收款操作,并通知客户付款已完成。 ### 示例代码 #### Ruby ```ruby require 'json' # Using Sinatra post '/webhook' do payload = request.body.read event = nil begin event = Stripe::Event.construct_from( JSON.parse(payload, symbolize_names: true) ) rescue JSON::ParserError => e # Invalid payload status 400 return end # Handle the event case event.type when 'payment_intent.requires_action' payment_intent = event.data.object # contains a Stripe::PaymentIntent # The payment intent was not fully funded due to insufficient funds # on the customer balance. Define and call a method to handle the payment intent. # handle_payment_intent_requires_action(payment_intent) when 'payment_intent.partially_funded' payment_intent = event.data.object # contains a Stripe::PaymentIntent # Then define and call a method to handle the payment intent being partially funded. # handle_payment_intent_partially_funded(payment_intent) when 'payment_intent.succeeded' payment_intent = event.data.object # contains a Stripe::PaymentIntent # Then define and call a method to handle the successful payment intent. # handle_payment_intent_succeeded(payment_intent) else puts "Unhandled event type: #{event.type}" end status 200 end ``` ### 在管理平台查看待处理的付款 您可以通过将**等待资金**筛选器应用到**状态**来在[管理平台](https://dashboard.stripe.com/payments)中查看所有待处理的银行转账 PaymentIntents。 ## 测试您的集成 您可以通过在管理平台中或通过 HTTP 请求模拟传入银行转账来测试您的集成。 ### 使用管理平台 要在*沙盒* (A sandbox is an isolated test environment that allows you to test Stripe functionality in your account without affecting your live integration. Use sandboxes to safely experiment with new features and changes)中使用管理平台模拟银行转账,请转到管理平台中的客户页面。在**支付方式**下,单击**添加**,然后选择**资金现金余额(仅限测试)**。 ### 使用 Stripe API 您可以发起一个 API 调用来模拟一笔银行转账。 #### 美国 ```curl curl https://api.stripe.com/v1/test_helpers/customers/cus_xxxxxxxxx/fund_cash_balance \ -u "<>:" \ -d amount=1000 \ -d currency=usd \ -d reference=REF-4242 ``` 您可以通过在 `reference` 参数前添加 `reversal_`(如 `reversal_123`)来模拟撤销。 #### 英国 ```curl curl https://api.stripe.com/v1/test_helpers/customers/cus_xxxxxxxxx/fund_cash_balance \ -u "<>:" \ -d amount=1000 \ -d currency=gbp \ -d reference=REF-4242 ``` #### 欧盟 ```curl curl https://api.stripe.com/v1/test_helpers/customers/cus_xxxx/fund_cash_balance \ -u "<>:" \ -d amount=1000 \ -d currency=eur \ -d reference=REF-4242 ``` #### 日本 ```curl curl https://api.stripe.com/v1/test_helpers/customers/cus_xxxx/fund_cash_balance \ -u "<>:" \ -d amount=10000 \ -d currency=jpy ``` #### MX ```curl curl https://api.stripe.com/v1/test_helpers/customers/cus_xxxx/fund_cash_balance \ -u "<>:" \ -d amount=1000 \ -d currency=mxn \ -d reference=123456 ``` ## 处理临时性的可用性问题 以下错误代码表明支付方式的可用性出现了临时性的问题: | 代码 | 描述 | 处理 | | ------------------------------------ | --------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- | | `payment_method_rate_limit_exceeded` | 该支付方式的连续请求太多,其限制比 [API 范围的速率限制](https://docs.stripe.com/rate-limits.md)更严格。 | 当您的许多客户在同一时段试图使用相同的支付方式时(例如,您的网站进行持续销售期间),多个 API 请求可能会持续发生这些错误。这种情况下,请让您的客户选择另外的支付方式。 | > 如果您预计一般情况下会用量激增或有即将要举行的大型活动,请在知道后立即联系我们。 ## Optional: 从客户那里收集支付方式选项 如果需要,在您的网站上收集客户的首选充值类型,并用 [Stripe.js](https://docs.stripe.com/js.md) 的 [confirmCustomerBalancePayment](https://docs.stripe.com/js/payment_intents/confirm_customer_balance_payment) 方式确认付款意图。 显示一个 HTML 表单,以收集客户首选的银行转账充值详情。用该输入信息生成 `payment_method_options`。 查看 [JS 参考文档](https://docs.stripe.com/js/payment_intents/confirm_customer_balance_payment)中可用的 `payment_method_options` parameters for `confirmCustomerBalancePayment` 的完整列表。 请看此用例:如果您是爱尔兰商家,不确定客户是哪个国家的,则可以创建一个 `PaymentIntent`,先将 `payment_method_options[customer_balance][bank_transfer][eu_bank_transfer][country]` 设置为 ‘IE’。然后用 [confirmCustomerBalancePayment](https://docs.stripe.com/js/payment_intents/confirm_customer_balance_payment) 方式,根据用户输入更新国家。 ### 示例代码 ```javascript const {paymentIntent, error} = await stripe.confirmCustomerBalancePayment( '{PAYMENT_INTENT_CLIENT_SECRET}', { payment_method: { customer_balance: { }, }, payment_method_options: { customer_balance: { funding_type: 'bank_transfer', bank_transfer: { type: 'eu_bank_transfer', eu_bank_transfer: { country: 'FR', } }, }, }, }, { handleActions: false, } ); if (error) { // Inform the customer that there was an error. } else if (paymentIntent.status === 'requires_payment_method') { // If `payment_method_options.funding_type` wasn't set this // is where you would need to handle the insufficient customer // balance state. } else if (paymentIntent.status === 'requires_action') { // If the current customer balance is insufficient to cover // the amount, and you've passed // `payment_method_options.funding_type` for funding the // customer balance, you can display the bank transfer // instructions to your user. if (paymentIntent.next_action.type === 'display_bank_transfer_instructions') { // Bank transfer details can be found under: // paymentIntent.next_action.display_bank_transfer_instructions } } ```