Stripe - Pay order error : Cannot charge a customer that has no active card
Stripe - Pay order error : Cannot charge a customer that has no active card
我正在使用 Stripe 的 API 支付订单。
我的计划大致如下:
使用 Stripe 元素创建支付表单
通过使用 PaymentIntent 然后创建 PaymentMethod 进行卡身份验证(3d 安全 SCA)。
创建客户对象,我将付款方式附加到该对象,并将其定义为默认值
$customer = $this->stripeConnector->updateCustomer($customer->id, [
'invoice_settings' => [
'default_payment_method' => $paymentMethod->id,
],
]);
- 创建订阅或单次付款。
通常它工作正常。
但不适用于 订单。
我根据文档创建了 Order Object:https://stripe.com/docs/api/orders/create 包含订单项和关联的 Customer
我按照以下文件付款https://stripe.com/docs/api/orders/pay
因此,只需传递 Order id(因为客户已经关联到订单)。
但出现以下错误:无法向没有有效卡的客户收费
为什么?我怎样才能'activate'客户卡?
这是我拥有的客户数据示例:
{
"id": "cus_JocNLLNhqHuOD6",
"object": "customer",
"address": {
"city": "paris",
"country": "FR",
"line1": "5 rue pompidou",
"line2": null,
"postal_code": "75000",
"state": null
},
"balance": 0,
"created": 1625758082,
"currency": null,
"default_source": null,
"delinquent": false,
"description": null,
"discount": null,
"email": "admin@mail.fr",
"invoice_prefix": "D46F6A15",
"invoice_settings": {
"custom_fields": null,
"default_payment_method": "pm_1JAz8uGgCQgXBLKX2hoxLQHr",
"footer": null
},
"livemode": false,
"metadata": {
},
"name": "admin admin",
"next_invoice_sequence": 1,
"phone": null,
"preferred_locales": [
"fr"
],
"shipping": null,
"tax_exempt": "none"
}
我的 PaymentMethod 响应:
{
"id": "pm_1JAz8uGgCQgXBLKX2hoxLQHr",
"object": "payment_method",
"billing_details": {
"address": {
"city": null,
"country": null,
"line1": null,
"line2": null,
"postal_code": null,
"state": null
},
"email": null,
"name": "qsvsf",
"phone": null
},
"card": {
"brand": "visa",
"checks": {
"address_line1_check": null,
"address_postal_code_check": null,
"cvc_check": "pass"
},
"country": "US",
"exp_month": 5,
"exp_year": 2025,
"fingerprint": "oV7uH07M2JEz7jQm",
"funding": "credit",
"generated_from": null,
"last4": "4242",
"networks": {
"available": [
"visa"
],
"preferred": null
},
"three_d_secure_usage": {
"supported": true
},
"wallet": null
},
"created": 1625758080,
"customer": "cus_JocNLLNhqHuOD6",
"livemode": false,
"metadata": {
},
"type": "card"
}
查看有关 Order 对象付款的文档,我想知道我是否应该改为使用 'source' 选项,因此使用 Source 对象而不是 PaymentMethod。但问题是,源对象已被弃用,取而代之的是支持 3d 安全的 PaymentMethod,所以我必须使用它。
Orders 是一个长期弃用的 Stripe API,所以我建议远离它,转向 PaymentIntents 或一次性发票。
因为它是遗留的 API,它只适用于 Cards/Sources 而不是 PaymentMethods。
现在您的集成正在将 PaymentMethod 附加到您的客户。
Orders 不会查找客户的 PaymentMethods,而是查找客户的 sources:
参数。
订单也不支持 SCA,因此如果付款需要身份验证,那只会表现为拒绝,而不会为您提供 PaymentIntents 为您提供的身份验证生命周期功能。
这就是为什么它像你所说的那样工作,当你在客户的 source:
下保存一个“源”对象时。
正确的方法是放弃使用已弃用的 Card/Source 对象和订单 API,并集成 PaymentMethods(您已经集成)和 PaymentIntents 或 Invoices 或 CheckoutSessions。
我正在使用 Stripe 的 API 支付订单。
我的计划大致如下:
使用 Stripe 元素创建支付表单
通过使用 PaymentIntent 然后创建 PaymentMethod 进行卡身份验证(3d 安全 SCA)。
创建客户对象,我将付款方式附加到该对象,并将其定义为默认值
$customer = $this->stripeConnector->updateCustomer($customer->id, [
'invoice_settings' => [
'default_payment_method' => $paymentMethod->id,
],
]);
- 创建订阅或单次付款。
通常它工作正常。
但不适用于 订单。 我根据文档创建了 Order Object:https://stripe.com/docs/api/orders/create 包含订单项和关联的 Customer
我按照以下文件付款https://stripe.com/docs/api/orders/pay
因此,只需传递 Order id(因为客户已经关联到订单)。
但出现以下错误:无法向没有有效卡的客户收费
为什么?我怎样才能'activate'客户卡?
这是我拥有的客户数据示例:
{
"id": "cus_JocNLLNhqHuOD6",
"object": "customer",
"address": {
"city": "paris",
"country": "FR",
"line1": "5 rue pompidou",
"line2": null,
"postal_code": "75000",
"state": null
},
"balance": 0,
"created": 1625758082,
"currency": null,
"default_source": null,
"delinquent": false,
"description": null,
"discount": null,
"email": "admin@mail.fr",
"invoice_prefix": "D46F6A15",
"invoice_settings": {
"custom_fields": null,
"default_payment_method": "pm_1JAz8uGgCQgXBLKX2hoxLQHr",
"footer": null
},
"livemode": false,
"metadata": {
},
"name": "admin admin",
"next_invoice_sequence": 1,
"phone": null,
"preferred_locales": [
"fr"
],
"shipping": null,
"tax_exempt": "none"
}
我的 PaymentMethod 响应:
{
"id": "pm_1JAz8uGgCQgXBLKX2hoxLQHr",
"object": "payment_method",
"billing_details": {
"address": {
"city": null,
"country": null,
"line1": null,
"line2": null,
"postal_code": null,
"state": null
},
"email": null,
"name": "qsvsf",
"phone": null
},
"card": {
"brand": "visa",
"checks": {
"address_line1_check": null,
"address_postal_code_check": null,
"cvc_check": "pass"
},
"country": "US",
"exp_month": 5,
"exp_year": 2025,
"fingerprint": "oV7uH07M2JEz7jQm",
"funding": "credit",
"generated_from": null,
"last4": "4242",
"networks": {
"available": [
"visa"
],
"preferred": null
},
"three_d_secure_usage": {
"supported": true
},
"wallet": null
},
"created": 1625758080,
"customer": "cus_JocNLLNhqHuOD6",
"livemode": false,
"metadata": {
},
"type": "card"
}
查看有关 Order 对象付款的文档,我想知道我是否应该改为使用 'source' 选项,因此使用 Source 对象而不是 PaymentMethod。但问题是,源对象已被弃用,取而代之的是支持 3d 安全的 PaymentMethod,所以我必须使用它。
Orders 是一个长期弃用的 Stripe API,所以我建议远离它,转向 PaymentIntents 或一次性发票。
因为它是遗留的 API,它只适用于 Cards/Sources 而不是 PaymentMethods。
现在您的集成正在将 PaymentMethod 附加到您的客户。
Orders 不会查找客户的 PaymentMethods,而是查找客户的 sources:
参数。
订单也不支持 SCA,因此如果付款需要身份验证,那只会表现为拒绝,而不会为您提供 PaymentIntents 为您提供的身份验证生命周期功能。
这就是为什么它像你所说的那样工作,当你在客户的 source:
下保存一个“源”对象时。
正确的方法是放弃使用已弃用的 Card/Source 对象和订单 API,并集成 PaymentMethods(您已经集成)和 PaymentIntents 或 Invoices 或 CheckoutSessions。