简体   繁体   English

在结帐时条纹默认卡

[英]Stripe default card in checkout

Is there a way to fill fields in a Stripe checkout page when customer comes back?有没有办法在客户回来时填写 Stripe 结帐页面中的字段? I've tried to set default payment method for customer with webhooks (payment_method.attached) but this default credit card won't show up during checkout.我尝试使用 webhook (payment_method.attached) 为客户设置默认付款方式,但此默认信用卡在结帐时不会显示。 Instead Stripe creates new payment method for the customer every time he pays.相反,Stripe 每次付款时都会为客户创建新的付款方式。 It's strange to have dozen of exactly the same credit cards in a Stripe dashboard.在 Stripe 仪表板中拥有数十张完全相同的信用卡是很奇怪的。 Here is my current code:这是我当前的代码:

const checkout = await stripe.checkout.sessions.create({
    cancel_url,
    success_url,
    payment_method_types: ["card"],
    mode: "payment",
    customer: stripeCustomer,
    client_reference_id: stripeCustomer,
    metadata: {
        //...
    },
    line_items: [{
        price_data: {
            currency: 'usd',
            product_data: {
            name: packetDisplayName,
            },
            unit_amount: packetPrice,
        },
        quantity: 1
    }]
})

I later use session id to redirect to checkout then perform few operations in a webhook endpoint我后来使用 session id 重定向到结帐,然后在 webhook 端点中执行一些操作

Thanks for taking the time to read my question, cheers感谢您花时间阅读我的问题,干杯

Checkout does not currently support using Payment Methods already attached to the provided Customer. Checkout 目前不支持使用已附加到提供的客户的付款方式。

More broadly, there is not a concept "default" payment method for one-time payments for a customer, only for invoices .更广泛地说,对于客户的一次性付款没有概念“默认”付款方式, 仅适用于发票

If you already have a known Customer and an attached payment method, you also have the option of creating the payment yourself , directly, using those details.如果您已经有一个已知的客户和附加的付款方式,您还可以选择使用这些详细信息直接自己创建付款

try its work for me in Node.JS在 Node.JS 中为我尝试它的工作

For add card in node js用于在节点 js 中添加卡片

let card = await stripe.customers.createSource(customerid, {
        source: token
    });

Make card as default card将卡片设为默认卡片

let updatecard = await stripe.customers.update(customerid, {
        default_source: card.id
      });

you can replace card.id if you just want update card only如果您只想更新卡,您可以替换 card.id

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM