stripe / react-stripe-js

React components for Stripe.js and Stripe Elements
https://stripe.com/docs/stripe-js/react
MIT License
1.75k stars 267 forks source link

It's not possible to get the billing address in shipping mode #494

Closed IgorNoskov closed 5 months ago

IgorNoskov commented 5 months ago

What happened?

I use AddressElement with shipping mode and PaymentElement. In such case there is Billing is same as shipping information checkbox. When I uncheck it, two fields appear, country and postal code. But there is no way to get the billing address.

Screenshot 2024-04-16 at 10 16 13 PM

On AddressElement change it returns this object:

{
    "elementType": "address",
    "elementMode": "shipping",
    "value": {
        "name": "",
        "phone": "",
        "address": {
            "line1": "",
            "line2": null,
            "city": "",
            "country": "US",
            "postal_code": "",
            "state": ""
        },
        "firstName": "",
        "lastName": ""
    },
    "empty": false,
    "complete": false,
    "isNewAddress": true
}

On PaymentElement change it returns this object:

{
    "elementType": "payment",
    "collapsed": false,
    "empty": false,
    "complete": true,
    "value": {
        "type": "card"
    }
}

Environment

No response

Reproduction

No response

brendanm-stripe commented 5 months ago

The billing details collected by the Payment Element will be on the Payment Method attached to the Payment Intent after the payment is confirmed.

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

IgorNoskov commented 5 months ago

The billing details collected by the Payment Element will be on the Payment Method attached to the Payment Intent after the payment is confirmed.

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

@bredmond-stripe, thank you for your answer, I've checked stripe.confirmPayment and stripe.retrievePaymentIntent methods return Payment Intent but without attached Payment Method, I see only payment method string id there.

Screenshot 2024-04-17 at 5 51 27 PM

Documentation says:

Screenshot 2024-04-17 at 5 50 14 PM

I didn't find a way to get Payment Method object.

brendanm-stripe commented 5 months ago

You can use expansion to have the payment_method returned as the object instead of the string ID: https://docs.stripe.com/js/payment_intents/confirm_payment#confirm_payment_intent-options-confirmParams-expand

stripe.confirmPayment({
  elements,
  confirmParams: {
    expand: ['payment_method'],
    return_url: 'https://example.com',
  },
})
IgorNoskov commented 5 months ago

expand: ['payment_method'],

@brendanm-stripe, thank you so much! It works!