Handling Stripe Subscriptions

Enabling or disabling address collection in Stripe Checkout

Enabling or disabling address collection in Stripe Checkout

Stripe Checkout can be customized in various ways. We can customize the look and feel of Checkout, show policies and contact information, localize the language of the Checkout page. To get more understanding on customization refer Stripe documentation.

We have already discussed Stripe Checkout in this chapter. In this, we will discuss how we can enable or disable address collection in Checkout.

Here is the API request we are sending to create a checkout session in our application.

1$ curl https://api.stripe.com/v1/checkout/sessions \
2> -u sk_test_51IUPamDdkrcdQOlhs2b...VV2OQeFjRe1004Oahe9N3: \
3> -d "payment_method_types[]"="card" \
4> -d "line_items[][quantity]"=1 \
5> -d mode=subscription \
6> -d success_url="https://example.com/success" \
7> -d cancel_url="https://example.com/cancel"

Now, the question is how we can enable or disable address collection?

Stripe Session Checkout create API supports parameter billing_address_collection, its default value is auto, and it means that Checkout will only collect the billing address when necessary.

Let's say the above API request is sent without billing_address_collection parameter. Now, when a Checkout page is rendered we will only see the country or region field as shown below:

Checkout Session Without Address Field

To enable address collection of customer's billing address we will need to pass billing_address_collection parameter with value required as shown below:

1$ curl https://api.stripe.com/v1/checkout/sessions \
2> -u sk_test_51IUPamDdkrcdQOlhs2b...VV2OQeFjRe1004Oahe9N3: \
3> -d "payment_method_types[]"="card" \
4> -d "billing_address_collection"="required" \
5> -d "line_items[][quantity]"=1 \
6> -d mode=subscription \
7> -d success_url="https://example.com/success" \
8> -d cancel_url="https://example.com/cancel"

When a checkout session page is rendered we can see the address field as shown below:

Checkout Session With Address Field

To disable address collection we will either need to pass billing_address_collection parameter with value auto or send API request without it.

Limitations

Stripe restricts enabling or disabling of the address collection based on our Stripe account country. We can see our account details via Dashboard settings as shown below:

Account Settings

Let's assume Stripe account's country is India. When customer checkouts to the session page, collection of address details is mandatory which means even if we pass billing_address_collection with the value auto, then also a customer will ask to enter billing address details.

⌘K
    to navigateEnterto select Escto close
    Previous
    Next