0

I want know how can i get a billing address and set in session in stripe page, i try use address in customer, but i cannot use. My:

onst stripeCustomer = await stripe.customers.create({
        email: decoded.ds_email,
        // address: {
        //     city: 'city',
        //     country: 'country',
        //     line1: 'line1',
        //     line2: null,
        //     state: 'state',
        //     postal_code: xxxxxxxx
        // }
    })
const stripeCheckoutSession = await stripe.checkout.sessions.create({
        customer: stripeCustomer.id,
        // customerAddress: stripeCustomer.address,
        payment_method_types: ['card'],
        // payment_intent: stripePaymentIntent.id,
        billing_address_collection: 'required',
        line_items: [
            { price: stripePrice.id, quantity: 1 }
        ],
        mode: 'payment',
        allow_promotion_codes: false,
        success_url: `http://localhost:3000`,
        cancel_url: `http://localhost:3000/#/order`
    })

1 Answers1

0

I've managed to do so by adding this parameter

const COUNTRY_CODE_ARRAY = ['UK','ES','US']
shipping_address_collection:{allowed_countries:COUNTRY_CODE_ARRAY },

const stripeCheckoutSession = await stripe.checkout.sessions.create({
        customer: stripeCustomer.id,
        // customerAddress: stripeCustomer.address,
        payment_method_types: ['card'],
        // payment_intent: stripePaymentIntent.id,
        billing_address_collection: 'required',
        line_items: [
            { price: stripePrice.id, quantity: 1 }
        ],
        mode: 'payment',
        allow_promotion_codes: false,
        success_url: `http://localhost:3000`,
        cancel_url: `http://localhost:3000/#/order`,

        shipping_address_collection:{allowed_countries:COUNTRY_CODE_ARRAY },

    })

This will show textfields for shipping address, using the customer shipping address.

One thing I noted, if customer edit it, checkout session will save edited shipping address, but in customer info, shipping address will be the same as before editing.

Navox
  • 11
  • 1
  • 2