Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 条带:添加默认卡,不覆盖旧卡_Java_Stripe Payments - Fatal编程技术网

Java 条带:添加默认卡,不覆盖旧卡

Java 条带:添加默认卡,不覆盖旧卡,java,stripe-payments,Java,Stripe Payments,我正在与Stripe客户、订阅和卡合作 现在,我有一个场景,客户可以有多张卡 现在,客户添加了一张新卡。我必须将新添加的卡标记为默认源 所以我现在做的是 Map<String, Object> params = new HashMap<String, Object>(); params.put("source", token.getId()); Customer customer = Customer.retrieve(user.getStripeId()); custo

我正在与Stripe客户、订阅和卡合作

现在,我有一个场景,客户可以有多张卡

现在,客户添加了一张新卡。我必须将新添加的卡标记为默认源

所以我现在做的是

Map<String, Object> params = new HashMap<String, Object>();
params.put("source", token.getId());
Customer customer = Customer.retrieve(user.getStripeId());
customerId = customer.getId();
Customer updatedCustomer = customer.update(params);
这段代码正在更新客户并将当前卡标记为默认源,这与预期一致

但是,如果客户已经有卡,那么它会用新卡覆盖旧卡。因此,从该客户处删除旧卡

现在我想要的是,如果客户已经有了卡,那么我想将该卡标记为辅助卡,然后添加新卡并将其标记为默认来源

那么我该怎么做呢?

您需要并且:

Customer customer = Customer.retrieve(user.getStripeId());
// add a new payment source to the customer
Map<String, Object> params = new HashMap<String, Object>();
params.put("source", token.getId());
Source source = customer.getSources().create(params);

// make it the default
Map<String, Object> updateParams = new HashMap<String, Object>();
updateParams.put("default_source", source.getId());
customer.update(updateParams);