admin管理员组

文章数量:1426894

I'm using stripe checkout. I already collect some userdata and I don't want customers to fill in their name twice. How can I autofill or disable the name field?

const session = await stripe.checkout.sessions.create({
        customer_email: !customerFound ? data.email : undefined,
        customer: customerFound ? customer.id : undefined,
        customer_update: customerFound
          ? {
              address: 'auto',
              name: 'auto',
            }
          : undefined,
        line_items: lineItems,
        client_reference_id: data.userId,
        payment_method_types: ['card', 'bancontact'],
        mode: 'payment',
        success_url: `${domain}/betaling-gelukt?session_id={CHECKOUT_SESSION_ID}`,
        cancel_url: `${domain}/betaling-mislukt`,
        locale: 'nl',
        billing_address_collection: 'auto',
        metadata: {
          reservation: data.reservatieId,
        },
      });

I'm using stripe checkout. I already collect some userdata and I don't want customers to fill in their name twice. How can I autofill or disable the name field?

const session = await stripe.checkout.sessions.create({
        customer_email: !customerFound ? data.email : undefined,
        customer: customerFound ? customer.id : undefined,
        customer_update: customerFound
          ? {
              address: 'auto',
              name: 'auto',
            }
          : undefined,
        line_items: lineItems,
        client_reference_id: data.userId,
        payment_method_types: ['card', 'bancontact'],
        mode: 'payment',
        success_url: `${domain}/betaling-gelukt?session_id={CHECKOUT_SESSION_ID}`,
        cancel_url: `${domain}/betaling-mislukt`,
        locale: 'nl',
        billing_address_collection: 'auto',
        metadata: {
          reservation: data.reservatieId,
        },
      });
Share Improve this question edited Mar 24, 2022 at 20:31 Ruben asked Dec 17, 2021 at 18:55 RubenRuben 9,19415 gold badges71 silver badges104 bronze badges 1
  • this is typescript though? – Ruben Commented Dec 18, 2021 at 16:36
Add a ment  | 

2 Answers 2

Reset to default 3 +50

As per the documentation:

In payment mode, the customer’s most recent card payment method will be used to prefill the email, name, card details, and billing address on the Checkout page.

In subscription mode, the customer’s default payment method will be used if it’s a card, and otherwise the most recent card will be used. A valid billing address is required for Checkout to prefill the customer’s card details.

This may or may not be ideal for your situation.


Alternatively, you could pletely cut out Stripe Checkout and use Stripe.js alongside the backend API that Stripe provides. This method has its pros/cons:

Pros:

  • Total control over the elements and the flows of the elements
  • Customise/style elements to your own choosing

Cons:

  • You have to create the backend and handle PaymentIntent and Subscription manually

We faced similar issues as yourself and though the initial change from Stripe Checkout to Stripe.js was a bit of learning curve it gave us much more control and allowed us to have payments without needing to redirect to an external site.

Note: I've intentionally left out code because the implementation of Stripe.js can vary based on your needs but if needed I can provide some examples.

Note that the name field of the Checkout Session is not necessarily your customer’s name, but the name on the Payment Method they are using.

It’s not possible to prefill this name field unless the customer already has a Payment Method attached that can be reused with ​​setup_future_usage.

  • For a bancontact Payment Method, this is not possible since it’s for one-time payment only.
  • For a card Payment Method, it’s possible. This would prefill the email, name, card details, and billing address as mentioned on the Stripe documentation.

In general I would remend to let Stripe Checkout collect all the information, and then update your system from that, not the other way around.

本文标签: javascriptStripe checkout autofill or disable customer nameStack Overflow