调至内容部分
创建账户
或
登录
Stripe 文档徽标
/
询问人工智能
创建账户
登录
开始
付款
Revenue
平台和交易市场
资金管理
开发人员工具
概览
关于 Stripe 支付
升级您的集成
支付分析
线上付款
概览查找您的用例Managed Payments
使用 Payment Link
构建结账页面
构建高级集成
构建应用内集成
支付方式
添加支付方式
    概览
    支付方式集成选项
    在管理平台中管理默认支付方式
    支付方式类型
    银行卡
    使用 Stripe 余额支付
    银行借记
    银行重定向
    银行转账
      收款
      客户余额
      退款
    贷记转账(来源)
    先买后付
    实时付款
    付款凭单
    钱包
    按国家启用本地支付方式
    自定义支付方式
管理支付方式
用 Link 更快结账
支付接口
Payment Links
结账
Web Elements
应用内 Element
支付场景
自定义支付流程
灵活收单
编排
线下支付
Terminal
其他 Stripe 产品
Financial Connections
加密货币
Climate
首页付款Add payment methodsBank transfers

接受银行转账

用 Payment Intents API 接受银行转账付款。

复制页面

当您第一次接受客户的银行转账付款时,Stripe 会为他们生成一个虚拟银行账户,然后您可以直接分享给他们。今后来自该客户的所有银行转账付款都会发到此银行账户。在一些国家,Stripe 还为您提供一个独特的转账参考码,您的客户每次转账时都需包含此号码,以更方便地进行对账。在某些国家,可以免费创建的虚拟银行账号数量是有限制的。

下图概括介绍了接受银行转账付款时的常用步骤:

处理少付和多付

使用银行转账方式付款,客户给您发送的可能会多于或少于预期金额。如果客户少发,则 Stripe 会向未付的付款意图中注入部分资金。账单是不能部分支付的,仍会保持开启状态,直到全额资金流入。

如果客户发送的金额超过预期,则 Stripe 会根据未付的付款核对入账资金,并将多出的金额保留在客户的现金余额中。年您可以在我们文档的对账部分找到有关 Stripe 如何处理对账的更多信息。

客户少付时:

客户多付时:

多个开启付款或账单的处理

您可能有多个开启的付款或账单,可通过银行转账来支付。在默认设置中,Stripe 会尝试用诸如转账的参考码或转账金额来自动对账银行转账。

您可以禁用自动对账,然后自行手动对账付款和账单。可单独覆盖掉对某个客户的自动对账行为,方法是将对账模式设置为手动模式。

设置 Stripe
服务器端

首先,您需要有 Stripe 账户。立即注册。

用我们的官方库从您的应用程序访问 Stripe API:

Command Line
Ruby
# Available as a gem sudo gem install stripe
Gemfile
Ruby
# If you use bundler, you can add this line to your Gemfile gem 'stripe'

创建或检索 Customer
服务器端

要核对每笔银行转账付款,您必须关联一个 Customer 对象。如果您有现成的 Customer 对象,则可以跳过这一步。否则,创建一个新的 Customer 对象。

Command Line
cURL
curl -X POST https://api.stripe.com/v1/customers \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"

创建 PaymentIntent
服务器端

PaymentIntent 是一个用来表示您从客户收款意图的对象,并可用于跟踪整个付款流程中各个阶段的情况。在服务器上创建一个 PaymentIntent,指定想要收取的金额和货币。您还必须填充 PaymentIntent 创建请求的 customer parameter。没有客户时,不能在 PaymentIntent 上使用银行转账。

创建 Payment Intent 之前,请确保在管理平台的支付方式设置页面中开启银行转账。

注意

借助动态支付方式,Stripe 会根据交易金额、货币和支付流程等因素返回符合条件的支付方式。

Command Line
cURL
curl https://api.stripe.com/v1/payment_intents \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"
\ -d amount=1099 \ -d customer=
{{CUSTOMER_ID}}
\ -d currency=usd \ -d "automatic_payment_methods[enabled]"=true

在最新版的 API 中,可以选择性指定 automatic_payment_methods 参数,因为 Stripe 会默认开启其功能。

如果客户的余额足够高,足以完成付款,则 PaymentIntent 立即成功,显示 succeeded 状态。当客户不小心多付时,他们可以累算余额,这在银行转账中很常见。您必须要在您所在地的特定时间段内确认客户余额。

收集付款详情
客户端

用 Payment Element 在客户端收集支付信息。Payment Element 是一个预构建的 UI 组件,它简化了多种支付方式的收集支付详情的流程。

Payment Element 中包含一个 iframe,它通过一个 HTTPS 连接安全地将支付信息发送到 Stripe。避免将 Payment Element 放在另一个 iframe 中,因为有些支付方式需要重定向到另一个页面进行付款确认。

结账页面上的地址也必须以 https:// 开头,不能是 http://,否则您的集成不能工作。您可以在不使用 HTTPS 的情况下测试您的集成,准备好进行真实收款时将它启用。

设置 Stripe.js

Payment Element 自动可以获取,这是 Stripe.js 的功能。在您的结账页面包含 Stripe.js 脚本,方法是将它添加到您的 HTML 文件的 head 部分。为保持 PCI 合规,始终从 js.stripe.com 加载 Stripe.js。不要把脚本打包或自行保留副本。

checkout.html
<head> <title>Checkout</title> <script src="https://js.stripe.com/v3/"></script> </head>

用下面的 JavaScript 在您的结账页面创建一个 Stripe 实例:

checkout.js
// Set your publishable key: remember to change this to your live publishable key in production // See your keys here: https://dashboard.stripe.com/apikeys const stripe = Stripe(
'pk_test_TYooMQauvdEDq54NiTphI7jx'
);

将 Payment Element 添加到您的支付页面

Payment Element 需要存在于您的支付页面的某个地方。用您的支付表单中的唯一 ID 创建一个空的 DOM 节点(容器):

checkout.html
<form id="payment-form"> <div id="payment-element"> <!-- Elements will create form elements here --> </div> <button id="submit">Submit</button> <div id="error-message"> <!-- Display error message to your customers here --> </div> </form>

加载了之前的表单后,创建一个 Payment Element 实例,并将它放入容器的 DOM 节点。创建 Elements 实例时,将上一步的 client secret 传入 options:

认真处理客户端私钥,因为它会完成收款。不要记录它,而是把它嵌入到 URL,或显示给除客户以外的所有人。

checkout.js
const options = { clientSecret: '{{CLIENT_SECRET}}', // Fully customizable with appearance API. appearance: {/*...*/}, }; // Set up Stripe.js and Elements to use in checkout form, passing the client secret obtained in a previous step const elements = stripe.elements(options); // Create and mount the Payment Element const paymentElementOptions = { layout: 'accordion'}; const paymentElement = elements.create('payment', paymentElementOptions); paymentElement.mount('#payment-element');

浏览 Stripe Elements

Stripe Element 是嵌入式 UI 组件的集合。要进一步定制您的表单,或收集其他客户信息,请浏览 Element 文档。

Payment Element 呈现一个动态表单,您的客户可在这里选择一个支付方式。对于每个支付方式,表单会自动请求客户填写必要的支付详情。

自定义外观

您可以自定义 Payment Element,使其匹配您网站的设计风格,方法是在创建 Elements 提供程序时向 options 传递外观对象。

收集地址

默认情况下,Payment Element 仅收集必要的账单地址信息。收集客户完整的账单地址(例如,计算数字商品和服务的税额)或收货地址时,使用 Address Element。

一经确认,Stripe 会自动打开一个模态,向客户显示银行转账的详情。

向 Stripe 提交付款
客户端

使用 stripe.confirmPayment,用来自 Payment Element 的详情完成付款。为该函数提供一个 return_url,告诉 Stripe 在用户完成付款后将他们重定向到哪里。您的用户可能会先被重定向到一个中间站点,如银行授权页面,然后才被重定向到 return_url。付款成功时,银行卡付款将立即重定向到 return_url。

如果您不想在完成付款后对银行卡付款重定向,可以将重定向设置到 if_required。这样就会只重定向使用基于重定向的支付方式结账的客户。

checkout.js
const form = document.getElementById('payment-form'); form.addEventListener('submit', async (event) => { event.preventDefault(); const {error} = await stripe.confirmPayment({ //`Elements` instance that was used to create the Payment Element elements, confirmParams: { return_url: 'https://example.com/order/123/complete', }, }); if (error) { // This point will only be reached if there is an immediate error when // confirming the payment. Show error to your customer (for example, payment // details incomplete) const messageContainer = document.querySelector('#error-message'); messageContainer.textContent = error.message; } else { // Your customer will be redirected to your `return_url`. For some payment // methods like iDEAL, your customer will be redirected to an intermediate // site first to authorize the payment, then redirected to the `return_url`. } });

确保 return_url 对应于您网站上显示付款状态的一个页面。Stripe 将客户重定向到 return_url 时,我们会提供以下 URL 查询参数。

参数描述
payment_intentPaymentIntent 的唯一标识符。
payment_intent_client_secretPaymentIntent 对象的 client secret。

注意

如果您有可以用来跟踪客户浏览器会话的工具,则您可能需要将 stripe.com 域名添加到推荐人列表。重定向会导致一些工具创建新的会话,从而阻止您跟踪完整的会话。

用以下某个查询参数检索 PaymentIntent。检查 PaymentIntent 的状态,以决定向客户显示的内容。您还可以在提供 return_url 时附加自己的查询参数,它们会在重定向过程中持续存在。

status.js
// Initialize Stripe.js using your publishable key const stripe = Stripe(
'pk_test_TYooMQauvdEDq54NiTphI7jx'
); // Retrieve the "payment_intent_client_secret" query parameter appended to // your return_url by Stripe.js const clientSecret = new URLSearchParams(window.location.search).get( 'payment_intent_client_secret' ); // Retrieve the PaymentIntent stripe.retrievePaymentIntent(clientSecret).then(({paymentIntent}) => { const message = document.querySelector('#message') // Inspect the PaymentIntent `status` to indicate the status of the payment // to your customer. // // Some payment methods will [immediately succeed or fail][0] upon // confirmation, while others will first enter a `processing` state. // // [0]: https://stripe.com/docs/payments/payment-methods#payment-notification switch (paymentIntent.status) { case 'succeeded': message.innerText = 'Success! Payment received.'; break; case 'processing': message.innerText = "Payment processing. We'll update you when payment is received."; break; case 'requires_payment_method': message.innerText = 'Payment failed. Please try another payment method.'; // Redirect your user back to your payment page to attempt collecting // payment again break; default: message.innerText = 'Something went wrong.'; break; } });

可选发送付款说明邮件

确认 PaymentIntent 成功

PaymentIntent 保持在 requires_action 状态,直至资金到达银行账户。资金就位后,PaymentIntent 的状态从 requires_action 更新为 succeeded。

需设置您的 webhook 端点后才能开始接收 payment_intent.partially_funded 事件。当给 PaymentIntent 部分资金后,状态仍会是 requires_action。

您可以从管理平台添加 webhook。

或者,您可以用 Webhook Endpoints API 开始接收 payment_intent.partially_funded 事件。

注意

Stripe CLI 不支持触发 Beta API 版本的事件,例如 payment_intent.partially_funded。

PaymentIntent 被更新时,付款的充值流程中会发送以下事件:

活动描述后续步骤
payment_intent.requires_action客户余额资金不足,不能补齐 PaymentIntent 时,在确认过程中发送,PaymentIntent 变为 requires_action。引导客户发送一笔金额为 amount_remaining 的银行转账。
payment_intent.partially_funded客户发送了银行转账,并且应用到了 PaymentIntent,但不足以完成付款。客户转账金额不足(由于错误地少付或其银行从中扣留了费用)或剩余的客户余额已应用到此 PaymentIntent 时就可能发生这种情况。部分注入资金的 PaymentIntents 不会提现在您的账户余额上,直至付款完成。引导您的客户用一个新的 amount_remaining 再发送一笔银行转账,从而完成付款。如果想通过部分应用资金来完成付款,可以更新 amount 并再次 confirm PaymentIntent。
payment_intent.succeeded客户付款成功。履行客户购买的商品或服务。

注意

当您更改有部分资金的 PaymentIntent 的金额时,资金将返回到客户余额。如果有其他未完成的 PaymentIntents,则 Stripe 自动提供这些资金。如果客户配置的是手动对账,那么您需要再次 apply the funds。

建议用 Webhook 来确认成功收款操作,并通知客户付款已完成。

示例代码

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)

在管理平台查看待处理的付款

您可以通过将等待资金筛选器应用到状态来在管理平台中查看所有待处理的银行转账 PaymentIntents。

测试您的集成

可以通过用 API、管理平台或一个 Stripe CLI 的 Beta 版本号模拟一笔传入银行转账来测试您的集成。

要在沙盒中用管理平台模拟银行转账,请导航到管理平台中的客户页面。在支付方式下方,点击添加然后选择现金余额充值(仅测试)。

处理临时性的可用性问题

以下错误代码表明支付方式的可用性出现了临时性的问题:

代码描述处理
payment_method_rate_limit_exceeded该支付方式的连续请求太多,其限制比 API 范围的速率限制更严格。当您的许多客户在同一时段试图使用相同的支付方式时(例如,您的网站进行持续销售期间),多个 API 请求可能会持续发生这些错误。这种情况下,请让您的客户选择另外的支付方式。

注意

如果您预计一般情况下会用量激增或有即将要举行的大型活动,请在知道后立即联系我们。

此页面的内容有帮助吗?
是否
需要帮助?联系支持。
加入我们的早期使用计划。
查看我们的更改日志。
有问题?联系销售。
LLM? Read llms.txt.
Powered by Markdoc