不进行银行验证的银行卡付款
构建一个带有区域限制的稍简单的集成。
This integration supports businesses accepting only US and Canadian cards. It’s simpler up front, but does not scale to support a global customer base.
此集成的原理是什么?
它相比于全球性集成怎样?
Growing or global businesses should use Stripe’s global integration to support bank requests for two-factor authentication and allow customers to pay with more payment methods.
构建结账表单客户端
Elements 是 Stripe.js 的一部分,它提供一个用于从客户收集银行卡详情的临时 UI 组件。它们由 Stripe 托管,以 iframe 形式放入您的支付表单,这样客户的银行卡详情永远不会触碰您的代码。
设置 Stripe服务器端
用官方库请求从您的应用程序访问 Stripe API:
付款服务器端
在您的服务器上设置一个端点,用以接收来自客户的请求。
Stripe 用一个 PaymentIntent 对象来表示您从客户收款的意图,跟踪扣款尝试及整个过程中付款状态的变化情况。
始终在服务器端决定扣款金额,这是一个可信的环境,客户端不行。这样可防止客户自己选择价格。
创建一个 HTTP 端点,响应第 1 步的 AJAX 请求。在此端点,应决定对客户的扣款金额。创建付款时,用第 1 步的 PaymentMethod ID 创建一个 PaymentIntent,使用以下代码:
警告
If you set error_on_requires_action to true
when confirming a payment, Stripe automatically fails the payment if it requires two-factor authentication from the user.
Payment Intents API 响应
在您用 API 进行付款时,响应中会包含 PaymentIntent 的状态。如果付款成功,则它的状态变为 succeeded
。
{ "id": "pi_0FdpcX589O8KAxCGR6tGNyWj", "object": "payment_intent", "amount": 1099, "charges": { "object": "list", "data": [ { "id": "ch_GA9w4aF29fYajT", "object": "charge", "amount": 1099, "refunded": false, "status": "succeeded", } ] }, "client_secret": "pi_0FdpcX589O8KAxCGR6tGNyWj_secret_e00tjcVrSv2tjjufYqPNZBKZc", "currency": "usd", "last_payment_error": null, "status": "succeeded", }
如果付款被拒绝,响应中会包含错误代码和错误消息。这里有一个由于要求对银行卡进行双重验证而付款失败的示例。
{ "error": { "code": "authentication_required", "decline_code": "authentication_not_handled", "doc_url": "https://docs.stripe.com/error-codes#authentication-required", "message": "This payment required an authentication action to complete, but `error_on_requires_action` was set. When you're ready, you can upgrade your integration to handle actions at https://stripe.com/docs/payments/payment-intents/upgrade-to-handle-actions.", "payment_intent": { "id": "pi_1G8JtxDpqHItWkFAnB32FhtI", "object": "payment_intent", "amount": 1099, "status": "requires_payment_method", "last_payment_error": { "code": "authentication_required", "decline_code": "authentication_not_handled", "doc_url": "https://docs.stripe.com/error-codes#authentication-required", "message": "This payment required an authentication action to complete, but `error_on_requires_action` was set. When you're ready, you can upgrade your integration to handle actions at https://stripe.com/docs/payments/payment-intents/upgrade-to-handle-actions.", "type": "card_error" }, }, "type": "card_error" } }
测试集成应用
我们为您提供了多张测试卡,供您在测试模式下使用,保证您的集成可顺利完成。使用时,CVC 卡安全码、邮编及未来的有效期可任意输入。
卡号 | 描述 |
---|---|
成功并且立即处理付款。 | |
始终会失败,显示拒付码 insufficient_ 。 | |
要求验证,此集成中会失败,显示拒付代码 authentication_ 。 |
查看完整的测试卡列表。
将集成升级以处理银行卡验证
恭喜!您已完成一个基本的支付集成,可以进行基本的银行卡收款了。注意,此集成会拒绝支付过程中要求验证的银行卡。
如果在管理平台中开始显示被列入 Failed
类别的付款,则需要升级您的集成。Stripe 的全局集成会处理这些付款,而非自动拒绝它们。