w3c / payment-request

Payment Request API
https://www.w3.org/TR/payment-request/
Other
488 stars 135 forks source link

Teach retry() about payerErrors #716

Closed marcoscaceres closed 6 years ago

marcoscaceres commented 6 years ago

BUILD ON #715 - This is part 2. It adds:

The following tasks have been completed:

Implementation commitment:

Impact on Payment Handler spec?

Example

Via payerErrors, the user now knows what's actually wrong with the payment... however, there is no eventing model, so validation of user input cannot be done incrementally: That's part 3.

async function doPaymentRequest() {
  const request = new PaymentRequest(methodData, details, options);
  const response = await request.show();
  try {
    await recursiveValidate(request, response);
  } catch (err) { // retry aborted.
    console.error(err);
    return;
  }
  await response.complete("success");
}

async function recursiveValidate(request, response) {
  const promisesToFixThings = [];
  const payerErrors = await validatePayerInput(response);
  if (!payerErrors) {
    return;
  }
  await response.retry({ payerErrors });
  return recursiveValidate(request, response);
}

doPaymentRequest();

Preview | Diff