Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve Billing Address from Stripe checkout session?

I am creating a checkout session in Node like so. https://stripe.com/docs/api/checkout/sessions/create

I've set the billing_address_collection parameter to required and am now wondering if I can retrieve the billing address collected from the checkout.completed webhook that is triggered.

I'm not finding a good way to retrieve the billing address from a checkout session.

Is there a way to do this? Or should I just gather this information before sending the user to a checkout session?

like image 952
Zachery C Gentry Avatar asked Apr 06 '20 17:04

Zachery C Gentry


People also ask

Does Stripe collect billing address?

When a card payment is submitted to a card network for authorization, Stripe provides the CVC, postal code, and billing street address for them to verify (if you collected these from the customer in your checkout flow).

How do I collect my address on Stripe?

Shipping address collection You can collect a customer's shipping address in Checkout by setting shipping_address_collection when you create a Checkout session.

What is Checkout session in Stripe?

The Checkout Session provides a URL that redirects customers to a Stripe-hosted payment page. Customers enter their payment details on the payment page and complete the transaction. After the transaction, a webhook fulfills the order using the checkout. session.

How long does Stripe Checkout session last?

Checkout Sessions expire 24 hours after creation. After creating a Checkout Session, redirect your customer to the URL returned in the response.


1 Answers

Billing address can be collected via Checkout. It won't live on the CheckoutSession object though but instead on the PaymentMethod object.

When you get the checkout.session.completed event, it has a payment_intent field with the PaymentIntent object ID. The PaymentIntent object in turn has the PaymentMethod that you need. So you need to go from CheckoutSession -> PaymentIntent -> PaymentMethod to get the billing details.

How to do this: In your webhook event handler, retrieve [0] the PaymentIntent and expand the PaymentMethod (by passing expand: ['payment_method']).

The PaymentMethod has the billing details under the billing_details hash [2]

[0] https://stripe.com/docs/api/payment_intents/retrieve

[1]https://stripe.com/docs/api/expanding_objects

[2] https://stripe.com/docs/api/payment_methods/object#payment_method_object-billing_details

like image 113
hmunoz Avatar answered Nov 15 '22 14:11

hmunoz