防止 Stripe API 向客户保存重复的卡

Vin*_*mie 5 javascript stripe-payments

我允许用户在结账时添加新卡。发生的情况是 paymentIntent 使用“setup_future_usage”选项,该选项会自动将付款方式附加到客户。

await stripe.paymentIntents.create({
        customer: customer_id,
        setup_future_usage: 'off_session',
        amount: calculateOrderAmount(items),
        currency: items.currency.toLowerCase()
      })
Run Code Online (Sandbox Code Playgroud)

这样做的问题是,这意味着用户可以多次输入同一张卡,而 stripe 会将它们作为单独的卡附加给用户。我尝试取消“setup_future_usage”,但在尝试确认付款时出现错误,表示付款未附加到客户。有谁知道 Javascript SDK 中有一种方法可以使 Stripe 不会在每个客户的基础上保存重复的卡吗?

JR *_*rne 0

我选择了一种不复杂的方法来解决这个问题 - 进行 API 调用来“分离”除刚刚设置的新支付方式之外的所有支付方式。

https://stripe.com/docs/api/ payment_methods/detach

我不知道您是否可以在使用 Elements API 在 Stripe 中创建卡片之前有效地预先匹配卡片数据。也许有可能,但这种基本方法对我有用。