我正在与 Stripe 客户、订阅和卡
合作。
现在,我有一个场景,客户可以拥有多张卡。
现在,客户添加了一张新卡。我必须将新添加的卡标记为 default_source
。
所以我正在做的是
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);
这段代码正在更新客户并将当前卡标记为default_source
,这符合预期。
但是,如果客户已经拥有卡,则会用新卡覆盖旧卡。因此,旧卡已从该客户中删除。
现在我想要的是,如果客户已经拥有该卡,那么我想将该卡标记为辅助卡,然后添加新卡并将其标记为 default_source
。
那么我该怎么做呢?
最佳答案
你会想要https://stripe.com/docs/api/sources/attach?lang=java和 https://stripe.com/docs/api/customers/update?lang=java#update_customer-default_source :
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);
关于java - Stripe : Add default card and do not override old card,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53496606/