Java 没有用于创建条带订阅的附加支付源
我目前正在将我的应用程序从使用Stripe Charges API迁移到使用Stripe PaymentIntents API,以遵守SCA法规 我的订阅创建代码大致如下所示:Java 没有用于创建条带订阅的附加支付源,java,stripe-payments,Java,Stripe Payments,我目前正在将我的应用程序从使用Stripe Charges API迁移到使用Stripe PaymentIntents API,以遵守SCA法规 我的订阅创建代码大致如下所示: Map<String, Object> srchOpts = new HashMap<>(); srchOpts.put("email", userEmail); List<Customer> matchingCustomers = Customer.list(srchOpts
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);
Map srchOpts=newhashmap();
srchOpts.put(“电子邮件”,userEmail);
List matchingCustomers=Customer.List(srchOpts.getData();
客户=空;
订阅=null;
if(matchingCustomers.isEmpty()){
Map params=新的HashMap();
参数put(“电子邮件”,用户电子邮件);
参数put(“支付令牌”,stripeToken);
customer=customer.create(参数);
}
else if(匹配customers.size()==1){
客户=匹配客户。获取(0);
Map params=新的HashMap();
参数put(“源”,stripeToken);
PaymentSourceCollection paymentSources=customer.getSources();
paymentSources.create(参数);
}
Map item=newhashmap();
项目。放置(“平面”,平面ID);//e、 g.我的专业计划(无试用日)
Map items=newhashmap();
项目。放入(“0”,项目);
Map params=新的HashMap();
参数put(“项目”,项目);
参数put(“customer”,customer.getId());
参数延迟(“关闭会话”,false);
订阅=订阅。创建(参数);
我可以在Stripe仪表板上(在测试模式下)看到客户已创建,并且拥有我指定的卡,但Subscription.create调用失败,原因是:
com.stripe.exception.InvalidRequestException:该客户没有附加的付款来源;代码:缺少资源
客户有一个卡集(只有1个,因此它必须是默认卡),客户创建调用发生在订阅创建调用之前,并且客户ID被传递给子创建调用。是否需要传入其他参数
我尝试在创建客户时设置
Customer.invoice\u settings.default\u payment\u method
,这使我通过了订阅创建。从Stripe仪表板上看,一切都很好,只是我正在使用SCA测试卡进行测试,因此在客户进一步验证之前,事务是不完整的
我需要响应中的客户端密码令牌才能继续,我想我可以从订阅.getLatestInvoiceObject().getPaymentIntentObject().getClientSecret()中获得它,但是getLatestInvoiceObject()
调用返回null
我没有在订阅对象上设置默认为自动收费的
collection\u方法
。这正是我想要的,因为客户正在进行会话,因此发票为null
可能是有意义的,但是如何将客户机密传回前端呢?订阅响应返回的SetupIntent
对象公开了客户端机密,但该对象也是null
订阅发票
将使用这三种付款选项中的任何一种(按优先顺序):
订阅
的默认付款方法
()或默认来源
()
客户的发票设置。默认付款方式()
Customer
的default\u源代码(注意:客户没有默认付款方式的概念)
另外值得注意的是,支付方法和来源是两种不同的资源。卡(ID前缀为卡的对象
)可以用作任何一种类型。那么,这是否意味着我必须在通过客户更新呼叫创建新创建的客户后立即显式设置发票设置。默认付款方法
或默认来源
?如果是这样的话,在客户创建调用期间是否无法指定默认值?您可以(无论是src_
还是card_
对象)。在我开始API更新之前,我的客户创建代码用于使用前端从Stripe.js收到的令牌设置source
参数,例如Stripe.createToken
,但是现在它已更改为Stripe.createPaymentMethod,并且我传递到后端的令牌导致了一个错误,您不能将PaymentMethod ID作为“source”参数提供。。。我的代币现在看起来像“pm_u…”,它是我在创建客户时拥有的卡付款的唯一表示形式。我可以使用它吗?您可能希望将pm\u
对象设置为Subscription.default\u payment\u method
或Customer.invoice\u settings.default\u payment\u method
确定,并且我是否需要在以后为所有这些客户设置新创建的客户default\u source
使用该卡付款,或者只需设置invoice\u设置就足够了。客户的默认付款方法
?