Re: [w3c/payment-request] fine grained error recovery for fields (#647)

@aestes, @michelle-stripe, @jenan-stripe, @rsolomakhin and I discussed fine grained error recovery for fields during the F2F, including the ability to "retry" the payment.  

Rough proposal is to add `AddressField`:

```IDL
 enum AddressField {
  "addressLine",
  "city",
  "country",
  "dependentLocality",
  "languageCode",
  "organization",
  "phone",
  "postalCode",
  "recipient",
  "region",
  "sortingCode"
};
```

Define `PaymentError` interface, somewhat matching [ApplePayError](https://developer.apple.com/documentation/applepayjs/applepayerror):

```IDL
enum PaymentErrorCode {
   "invalidShippingAddress",
   "invalidBillingAddress",
   // Do we need need "unknown" and "unserviceableAddress" ?  
};

[Constructor(PaymentErrorCode code, optional AddressField? field, optional DOMString message = "")]
interface PaymentError {
   readonly attribute PaymentErrorCode type;
   readonly attribute AddressField? AddressField; 
   readonly attribute DOMString message;
};
```

And add the following member to `PaymentDetailsUpdate`:

```IDL
   sequence<PaymentError> errorFields; 
``` 

Thus, "onshippingaddresschange":

```IDL
const errorField = [
   new PaymentError("invalidShippingAddress", "country", "We don't ship to your country."),
   new PaymentError("invalidShippingAddress", "postCode", "This postcode isn't valid."),
];
 ev.updateWith({
      ...details,
      error: "Couple of issues with the shipping address.", 
      errorFields,
});
```

Add lastly, we add `response.retry(...errors)`, which returns a promise that resolves with undefined... waits for user to try hit "Pay" again: 

```JS
let errors = [
   new PaymentError("invalidShippingAddress", "addressLine", "I can't ship to PO boxes."),
   new PaymentError("invalidBillingAddress", null, "Srsly? that's an abandoned house."),
];
await response.retry(...errors);
errors = checkResponse(response);
if(errors.length){
   // try again... this would be recursive... 
   await response.retry(...errors);
} else {
  const status = processPayment(response);
  await response.complete(status);  
}
 ```

 

-- 
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/issues/647#issuecomment-349837761

Received on Thursday, 7 December 2017 02:00:50 UTC