Re: [w3c/payment-request] Support requesting billing address (#749)

Ok, updated based on recent discussions. This is how it works in theory (it's a bit ugly, but because `paymentMethodErrors` 🤷🏽‍♂️):

```JS
const options = {
  requestBillingAddress: true,
};
const request = new PaymentRequest(methods, details, options);

request.onpaymentmethodchange = ev => {
  // get billing address
  const { billingAddress } = ev.methodDetails;
  // get new total
  const updatedTotalPromise = asynCalcNewTotal(billingAddress);
  ev.updateWith(updatedTotalPromise);
};

const response = await request.show();
await validAddresses(response);

async function validAddresses(response) {
  const {
    shippingAddress,
    details: { billingAddress },
  } = response;
  const [shipping, billingErrors] = await Promise.all([
    validateShippingAddress(shippingAddress),
    validateShippingAddress(billingAddress),
  ]);
  const billing = billingErrors
    ? { paymentMethodErrors: { billing: billingErrors } }
    : undefined;
  const errors = { shipping, billing };
  if (Object.getOwnPropertyNames(errors).length) {
    await response.retry(errors);
  }
  return validAddresses(response);
}
```



-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/payment-request/pull/749#issuecomment-415663572

Received on Friday, 24 August 2018 06:24:02 UTC