w3c / payment-request

Payment Request API
https://www.w3.org/TR/payment-request-1.1/
Other
482 stars 183 forks source link

Clarification: onshippingaddresschange in case of autofill/pre-filled fields #887

Closed crowgames closed 4 years ago

crowgames commented 4 years ago

Should onshippingaddresschange be triggered through auto-filled/pre-filled values?

Context: To allow for an easy and fast checkout, browsers (e.g. Chrome) pre-fill inputs such as the shipping address with the last observed address. This currently does not trigger an onshippingaddresschange-event though. But if I as a merchant want to calculate shipping costs based on the selected address, I have to rely on this event.

The spec describes relevant events as:

The user provides a new shipping address.

In terms of the specification what would be the intended behavior? Since this is a very common use-case, I think this might need clarification in the spec.

rsolomakhin commented 4 years ago

Hi @crowgames . You can accomplish this by specifying an empty set of shippingOptions initially. The browser will ask the user to explicitly select their shipping address, at which point the 'shippingaddresschange' update will be fired with redacted address that is sufficient for shipping price caclulations. Please proceed to populate the shippingOptions field in the response to the shippingaddresschange event. Ideally you would also designate one of the shipping options selected: true, which reduces the number of actions that the user has to perform during checkout. Please see a demo at https://rsolomakhin.github.io/pr/us/

rsolomakhin commented 4 years ago

Some relevant docs here: https://developers.google.com/web/fundamentals/payments/merchant-guide/deep-dive-into-payment-request#shipping_in_payment_request_api