Search code examples
javascriptstripe-paymentsapplepayapplepayjs

Apple Pay: How can I get `shippingAddress` before show the order information?


I'm using Apple Pay integration with Stripe and I need to get the shippingAddress from Apple Pay before shown the order information because I need to calculate taxes and shipment cost based on the address.

Currently, I can get the shipmentAddress but after show the window with the information.

I'm sending this payload:

    var paymentRequest = {
      requiredShippingContactFields: ['postalAddress','email', 'phone'],
      countryCode: 'US',
      currencyCode: 'USD',
      lineItems: this.buildLineItems(lineItems),
      total: this.buildTotal(lineItems)
    };

There's a way to get the shipment information before show the window or update the window based on the information that I get?

Source:

Thanks


Solution

  • In order to get the shipment information you need to listen for onshippingcontactselected

    session.onshippingcontactselected = (event) => {
      // You can do work asynchronously here; just call
      // session.completeShippingMethodSelection when you're done.
    }
    

    Documentation

    https://stripe.com/docs/stripe-js/reference#payment-request-on

    https://developer.apple.com/documentation/apple_pay_on_the_web/applepaysession/1778009-onshippingcontactselected?language=javascript