[英]No attached payment source for Stripe subscription creation
I'm currently migrating my app from using the Stripe Charges API to use the Stripe PaymentIntents API, in order to comply with SCA regulations. 我目前正在将我的应用程序从使用Stripe Charges API迁移到使用Stripe PaymentIntents API,以符合SCA法规。
My subscription creation code roughly looks like this: 我的订阅创建代码大致如下所示:
Map<String, Object> srchOpts = new HashMap<>();
srchOpts.put("email", userEmail);
List<Customer> matchingCustomers = Customer.list(srchOpts).getData();
Customer customer = null;
Subscription subscription = null;
if ( matchingCustomers.isEmpty() ){
Map<String, Object> params = new HashMap<String, Object>();
params.put("email", userEmail);
params.put("payment_token", stripeToken);
customer = Customer.create(params);
}
else if (matchingCustomers.size() == 1) {
customer = matchingCustomers.get(0);
Map<String, Object> params = new HashMap<String, Object>();
params.put("source", stripeToken);
PaymentSourceCollection paymentSources = customer.getSources();
paymentSources.create(params);
}
Map<String, Object> item = new HashMap<String, Object>();
item.put("plan", planId); // e.g. my-pro-plan (no trial days)
Map<String, Object> items = new HashMap<String, Object>();
items.put("0", item);
Map<String, Object> params = new HashMap<String, Object>();
params.put("items", items);
params.put("customer", customer.getId());
params.put("off_session", false);
subscription = Subscription.create(params);
I can see on the Stripe dashboard (in test mode) that the customer is created and has the card which I specified, but the Subscription.create call fails with: 我可以在Stripe仪表板(处于测试模式)上看到已创建客户并拥有我指定的卡,但是Subscription.create调用失败并显示:
com.stripe.exception.InvalidRequestException: This customer has no attached payment source;
com.stripe.exception.InvalidRequestException:该客户没有附加的付款来源; code: resource_missing
代码:resource_missing
The customer has a card set (there is only 1 so it has to be the default card), the customer creation call happens before the subscription creation call and the customer ID is being passed to the sub creation call. 客户有一个卡套(只有1张,所以它必须是默认卡),客户创建呼叫发生在订阅创建呼叫之前,并且客户ID传递到了子创建呼叫。 Is there some other parameter I need to pass in?
我还需要传递其他参数吗?
I've tried setting Customer.invoice_settings.default_payment_method
when the customer is being created, and that gets me past the subscription creation. 我已经尝试在创建
Customer.invoice_settings.default_payment_method
时设置Customer.invoice_settings.default_payment_method
,这使我无法进行订阅创建。 Everything looks fine from the Stripe dashboard, except that I'm testing with an SCA test card, so the transaction is incomplete until the customer has authenticated further. 从Stripe仪表板看一切正常,除了我正在使用SCA测试卡进行测试外,因此在客户进一步进行身份验证之前,交易是不完整的。
I need the client secret token from the response to continue, and I thought that I would get it from #Subscription.getLatestInvoiceObject().getPaymentIntentObject().getClientSecret()
but the getLatestInvoiceObject()
call is returning null
. 我需要响应中的客户端秘密令牌才能继续,并且我认为我可以从
#Subscription.getLatestInvoiceObject().getPaymentIntentObject().getClientSecret()
获取它,但是getLatestInvoiceObject()
调用返回的是null
。
I'm not setting collection_method
on the Subscription object which defaults to charge_automatically
. 我没有在默认设置为
charge_automatically
的Subscription对象上设置collection_method
。 This is what I want because the customer is on-session and so the Invoice
being null
probably makes sense, but how do I get the client secret to pass back to the frontend? 这就是我想要的,因为客户处于
Invoice
状态,因此Invoice
为null
可能很有意义,但是如何获取客户机密以传递回前端? The SetupIntent
object returned by the subscription response exposes a client secret, but that object is null
too. 订阅响应返回的
SetupIntent
对象公开了客户端机密,但该对象也为null
。
Subscription Invoices
will use whichever of these three payment options are available (in order of preference): 订阅
Invoices
将使用以下三种付款方式中的任何一种(按优先顺序排列):
Subscription
's default_payment_method
( reference ) or default_source
( reference ) Subscription
的default_payment_method
( 参考 )或default_source
( 参考 ) Customer
's invoice_settings.default_payment_method
( reference ) Customer
的invoice_settings.default_payment_method
( 参考 ) Customer
's default_source
(note: there is no concept of a default PaymentMethod on Customers) Customer
的default_source
(注意: Customer
上没有默认的PaymentMethod的概念) Also worth noting is that PaymentMethods and Sources are two distinct resources. 还值得注意的是PaymentMethods和Sources是两个不同的资源。 Cards (objects with ids prefixed with
card_
) can be used as either type. 卡(ID为前缀
card_
对象)可以用作这两种类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.