【问题标题】:Stripe: Add default card and do not override old card条纹:添加默认卡并且不覆盖旧卡
【发布时间】:2018-11-27 17:54:29
【问题描述】:

我正在使用 Stripe Customers, Subscription and Cards

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

现在,客户添加了一张新卡。我必须将新添加的卡片标记为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

那我该怎么做呢?

【问题讨论】:

    标签: java stripe-payments


    【解决方案1】:

    你会想要 https://stripe.com/docs/api/sources/attach?lang=javahttps://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);
    

    【讨论】:

      猜你喜欢
      • 2018-06-13
      • 2011-05-04
      • 2023-03-05
      • 2016-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多