【问题标题】:How to set default card when creating payment intent创建付款意图时如何设置默认卡
【发布时间】:2020-12-25 10:02:00
【问题描述】:

我可以向用户收费并保存该卡以备将来收费。为我正在做的用户设置默认卡Stripe::Customer.update(见下文)

def new
  @payment_intent = Stripe::PaymentIntent.create(amount: 100, 
                                                 currency: 'usd', 
                                                 customer: current_user.stripe_id, 
                                                 setup_future_usage: 'off_session')
end

def create
  @payment_intent = Stripe::PaymentIntent.retrieve({id: params[:payment_intent_id])
  if @payment_intent.status == "succeeded"
    Stripe::Customer.update(current_user.stripe_id, invoice_settings: { default_payment_method: @payment_intent.payment_method })
        
    #do stuff
  else
    render :new
  end
end

有没有办法在创建支付意图时指定正在使用的卡应该是用户的默认卡(而不是使用 Stripe::Customer.update 再次调用 Stripe)?

【问题讨论】:

    标签: stripe-payments


    【解决方案1】:

    没有带有 PaymentIntents 的“默认”PaymentMethod 的概念。使用已保存的卡创建新的 PaymentIntent 时,您必须同时指定客户 ID 和附加到客户的 PaymentMethod 的 ID:https://stripe.com/docs/payments/save-during-payment#web-create-payment-intent-off-session

    【讨论】:

      猜你喜欢
      • 2016-06-04
      • 2013-04-04
      • 1970-01-01
      • 2020-03-14
      • 2022-01-08
      • 2022-06-10
      • 2018-01-06
      • 2021-02-14
      • 2022-01-01
      相关资源
      最近更新 更多