不进行银行验证的银行卡付款
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.
这个集成的原理是什么?
它相比于全球性集成怎样?
增长中的企业或全球性企业应使用 Stripe 的全球集成来支持银行的双重验证请求,并允许客户用更多支付方式付款。
构建结账表单客户端
Elements 是 Stripe.js 的一部分,提供了一个用于从客户收集银行卡详情的临时 UI 组件。它们由 Stripe 托管,以 iframe 形式放入您的支付表单,这样客户的银行卡详情永远不会触碰您的代码。
设置 Stripe服务器端
用官方库请求从您的应用程序访问 Stripe API:
付款服务器端
在您的服务器上设置一个端点,用以接收来自客户的请求。
Stripe 用一个 PaymentIntent 对象来表示您从客户收款的意图,跟踪收款尝试及整个过程中付款状态的变化情况。
始终在服务器端决定扣款金额,这是一个可信的环境,客户端不行。这样可防止客户自己选择价格。
创建一个 HTTP 端点,响应第 1 步的 AJAX 请求。在这个端点,应决定对客户的扣款金额。创建付款时,用第 1 步的 PaymentMethod ID 创建一个 PaymentIntent,使用以下代码:
警告
如果您在确认付款时将 error_on_requires_action 设置为 true
,则如果 Stripe 要求用户进行双重验证,则付款将自动失败。
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://stripe.com/docs/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://stripe.com/docs/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_funds 。 | |
要求验证,这个集成中会失败,显示拒付代码 authentication_not_handled 。 |
查看完整的测试卡列表。
将集成升级以处理银行卡验证
恭喜!您已完成一个基本的支付集成,可以进行基本的银行卡收款了。注意,这个集成会拒绝支付过程中要求验证的银行卡。
如果您开始在管理平台中见到被列入 Failed
类别的付款,那么是时候升级您的集成了。Stripe 的全局集成会处理这些付款,而非自动拒绝。