【问题标题】:How can I make the card as the default payment method during checkout flow如何在结帐流程中将卡设为默认付款方式
【发布时间】:2022-01-01 14:34:53
【问题描述】:

我正在使用 Stripe 结账来收集卡详细信息和客户地址,如下所示

 const session = await stripe.checkout.sessions.create({
  payment_method_types: ['card'],
  mode: 'setup',
  customer: req.subscription.customerId,
  client_reference_id: email,
  metadata: {'plan': 'basic'},
  billing_address_collection: 'required',
  success_url: req.protocol + '://' + req.get('host') + '/payment/middle?'+queryParams,
  cancel_url: req.protocol + '://' + req.get('host') + '/payment/failure',
});

如何在结账流程中将卡设为默认付款方式?

【问题讨论】:

    标签: javascript node.js stripe-payments


    【解决方案1】:

    结帐会话会自动将新的付款方式附加给客户。如果您想将此付款方式设置为订阅付款的默认方式,则需要手动更新客户对象的invoice_settings.default_payment_method 属性。

    我建议收听checkout.session.completed webhook 并执行以下操作:

    // The checkout session object sent by the webhook
    const session = event.data.object;
    
    // Retrieve the associated setup intent (we need it to get the payment_method just after)
    const setupIntent = await stripe.setupIntents.retrieve(
        session.setup_intent
    );
      
    // Update the default payment method for the customer
    const customer = await stripe.customers.update(session.customer, {
        invoice_settings: {
          default_payment_method: setupIntent.payment_method,
        },
    });
    

    您可以通过阅读 Stripe 文档中的this page 了解更多信息。

    【讨论】:

    • 上面写着{ Error: You can not pass `payment_intent_data` in `setup` mode.
    • @Rajan 对不起,我读你的问题太快了,我的回答是错误的。我刚刚更新了我的回复。
    猜你喜欢
    • 2022-06-10
    • 2015-11-05
    • 2013-04-04
    • 1970-01-01
    • 2017-12-01
    • 1970-01-01
    • 2022-01-09
    • 2021-03-29
    • 2020-12-25
    相关资源
    最近更新 更多