You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
And add the following member to PaymentDetailsUpdate:
sequence<PaymentError> errorFields;
Thus, "onshippingaddresschange":
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:
leterrors=[newPaymentError("invalidShippingAddress","addressLine","I can't ship to PO boxes."),newPaymentError("invalidBillingAddress",null,"Srsly? that's an abandoned house."),];awaitresponse.retry(...errors);errors=checkResponse(response);if(errors.length){// try again... this would be recursive... awaitresponse.retry(...errors);}else{conststatus=processPayment(response);awaitresponse.complete(status);}
It might be a bit of a UX problem for UAs to have to render multiple errors that aren't AddressField-specific. e.g. with error set to a string and/or multiple PaymentError with a null AddressField. The UA won't know how to combine them appropriately.
Here is an implementation showing how it could work with .retry(...errors) .
asyncfunctiondoPaymentRequest(){constrequest=newPaymentRequest(methods,details,options);constresponse=awaitrequest.show();try{awaitretryUntilGood(response);conststatus=awaitprocessPayment(response);awaitresponse.complete(status);}catch(err){// AbortError? user got bored retrying. }}asyncfunctionretryUntilGood(response){consterrors=awaitvalidateResponse(response);if(errors.length){awaitresponse.retry(...errors);// Can throw AbortErrorawaitretryUntilGood(response);}}
An alternative approach to allowing the user to retry a payment without introducing a new method would be to use an event like Apple Pay's onpaymentauthorized but implementing the PaymentRequestAuthorizedEvent interface:
errorFields would still be added to PaymentDetailsUpdate to be used by onpaymentauthorized's updateWith method to specify errors (field-specific and otherwise) with the same PaymentError interface as previous proposal.
An author responds to onpaymentauthorized with either an updateWith to allow the user to retry with some errors or by calling response.complete() to close the request UI.
This approach feels more natural to me than getting a new Promise from each .retry(…) and provides a single way to provide PaymentErrors, rather than updateWith + retry.
Just my two cents.
Third alternative - from @rsolomakhin's notes from the F2F meeting.
PaymentResponse.complete() gets a new "retry" enum value for correcting payment errors. Merchant would specify an enum value like “billing addressing zip code is not correct” or “card declined,” for example. Then the user can attempt to fix the error and retry the payment. The payment handler should be able to specify whether a retry is possible, so push-payments can work correctly.
constresponse=awaitpr.show();asyncfunctionvalidateResponse(response){constbadThings=awaitgetInvalidThings(response);if(!badThings){return;// yay, it’s all good!}// Oh noes, let’s get the user to fix bad thingsawaitresponse.complete("retry",badThings);returnvalidateResponse(response);}awaitvalidateResponse(response);
Regrettably, @mnoorenberghe's proposal would have been great if we were not already returning response from .show() (i.e., if we would have designed the API like that initially).
However, introducing the event leaves const response = await request.show(); in a strange place, specially when you try to wire everything up. We effectively end up with two sources for the response, and it means developers would need to wrap the request.onpaymentauthorized in a promise that guards against premature completion (as below, I am personally not a big fan):
constrequest=newPaymentRequest();constcanContinue=newPromise(resolve=>{request.onpaymentauthorized=event=>{consterrorFields=checkResponse(event.response);if(errorFields.length){event.updateWith({
details,
errorFields,});return;}resolve();};});// This is somewhat messy// because now I'm holding promises instead of awaiting them :(constshowPromise=request.show();awaitcanContinue;constresponse=awaitshowPromise;conststatus=processPayment(response);response.complete(status);
Definitely, could make the above leaner by doing what @mnoorenberghe does in his example above (do the .compete() logic in the handler itself)... but, as I said, I think we missed that opportunity with the current design that returns response from await request.show().
Other cons would be having to introduce a new EventHandler interface type, as well as an attribute. While .retry() only adds a single method and could work well with the existing state machine.
Now, API design aside, a larger problem when retrying will be figuring out the restrictions on what can actually be fixed... If the shippingAddress is not serviceable, then what does picking a new one do (specially because it could change the total, and now the request is in a "close" state - so effectively dead)? Does the request again wake up and get put into an "interactive" state?
Need to think more about the above, or see how ApplePay is handling it.
@marcoscaceres, IMHO, shouldn't .retry() be for billing issues only? Shipping address validation happens before user authorizes the payment, if the merchant needs to validate it, I thought.
Well, depends on #648 and if addressLine should be redacted. But ideally you are correct: then user can only change or update the payment instrument (and associated billing address) at this stage. This doesn’t quite match what ApplePay allows, but that might be workable nonetheless.
Looking back over the discussion, I think having a PaymentError interface might be confusing and a bit heavyweight: Confusing, in that it's not an Error in the JS/DOM sense (has no stack, for example). Heavyweight, in that it simply models a triple, but provides no other utilities.
As an alternative, I think we can just use dictionaries to achieve the same result:
Note: AddressErrors could be reused for billing address errors, once the Payment Request API actually supports billing addresses properly (#27 and #550).
Note: Errors for redacted fields could be ignored by the UA (e.g., complaining about shipping address' phone during the "payment request" phase would be ignored, but would be honored when retrying the payment response).
Usage example
pr.onshippingaddresschange=ev=>{constshippingAddressErrors={"city": "FarmVille is not a real place.","postalCode": "Doesn't match a known zip code for your country.",};event.updateWith({ shippingAddressErrors });}
Payer-related errors
The next class of errors deals specifically with payer related errors (name, email, phone):
constpayerErrors={email: "The domain name is invalid",phone: "Invalid format",};// We don't have a means to use this object yet... that will be `retry()`.
This design seems reasonable from a spec/IDL perspective. Pretty nice and simple; just an extension of the existing "error" option in PaymentDetailsUpdate.
I'm not sure any UAs plan to expose the underlying languageCode so I'm not sure how useful an error message for it would be but I think it's fine to be consistent and support errors on all fields in the shipping address.
Tangent: I'd rather we fixed the misnomer of addressLine => addressLines everywhere rather than continuing to propagate it e.g. support both in the code already shipped in UAs treating the old name as an alias to the new name.
I'm not sure any UAs plan to expose the underlying languageCode so I'm not sure how useful an error message for it would be but I think it's fine to be consistent and support errors on all fields in the shipping address.
Agree.
Tangent: I'd rather we fixed the misnomer of addressLine => addressLines everywhere rather than continuing to propagate it
I'm thinking it might be too late... consider what happened already when we changed supportedMethods to a string. I think we are still dealing with the fallout.
support both in the code already shipped in UAs treating the old name as an alias to the new name.
I personally think this will cause confusion, as people might think they can set one or the other, but then one will trash the other, etc. Naming things is hard 😢
That reminds me, nevertheless, that maybe addressLine needs special treatment, because it's a sequence of lines.
So, maybe we actually need:
(DOMStringorsequence<DOMString?>)addressLine;
We could say that:
When it's a DOMString - the whole address is bad.
When it's a sequence, the UA can match the errors to particular lines.
So:
// The whole address is bad!constaddressErrors.addressLine="Look, buddy, I can't ship to a PO Box!";// Address is partially bad!constaddressErrors.addressLine=[null,"the second line is bad!",null,"the fourth line is bad!"];
Activity
marcoscaceres commentedon Dec 7, 2017
@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:enum AddressField { "addressLine", "city", "country", "dependentLocality", "languageCode", "organization", "phone", "postalCode", "recipient", "region", "sortingCode" };Define
PaymentErrorinterface, somewhat matching ApplePayError:enum PaymentErrorCode { "invalidShippingAddress", "invalidBillingAddress", "unknown", "badAddress" // "unserviceable" so hard to spell }; [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:Thus, "onshippingaddresschange":
Add lastly, we add
response.retry(...errors), which returns a promise that resolves with undefined... waits for user to try hit "Pay" again:mnoorenberghe commentedon Dec 7, 2017
It might be a bit of a UX problem for UAs to have to render multiple errors that aren't
AddressField-specific. e.g. witherrorset to a string and/or multiplePaymentErrorwith a nullAddressField. The UA won't know how to combine them appropriately.marcoscaceres commentedon Dec 7, 2017
Yeah, we need to say last one wins in the case of duplicates.
marcoscaceres commentedon Dec 7, 2017
Here is an implementation showing how it could work with
.retry(...errors).marcoscaceres commentedon Dec 7, 2017
Fixed typo above.
mnoorenberghe commentedon Dec 7, 2017
An alternative approach to allowing the user to retry a payment without introducing a new method would be to use an event like Apple Pay's
onpaymentauthorizedbut implementing thePaymentRequestAuthorizedEventinterface:errorFieldswould still be added toPaymentDetailsUpdateto be used byonpaymentauthorized'supdateWithmethod to specify errors (field-specific and otherwise) with the samePaymentErrorinterface as previous proposal.An author responds to
onpaymentauthorizedwith either anupdateWithto allow the user to retry with some errors or by callingresponse.complete()to close the request UI.This approach feels more natural to me than getting a new
Promisefrom each.retry(…)and provides a single way to providePaymentErrors, rather thanupdateWith+retry.Just my two cents.
marcoscaceres commentedon Dec 7, 2017
Third alternative - from @rsolomakhin's notes from the F2F meeting.
PaymentResponse.complete()gets a new "retry" enum value for correcting payment errors. Merchant would specify an enum value like “billing addressing zip code is not correct” or “card declined,” for example. Then the user can attempt to fix the error and retry the payment. The payment handler should be able to specify whether a retry is possible, so push-payments can work correctly.rsolomakhin commentedon Dec 7, 2017
The method
response.retry(errors)will be easy to feature-detect for early adopters. I would prefer this one, if that's OK.marcoscaceres commentedon Dec 8, 2017
Regrettably, @mnoorenberghe's proposal would have been great if we were not already returning
responsefrom.show()(i.e., if we would have designed the API like that initially).However, introducing the event leaves
const response = await request.show();in a strange place, specially when you try to wire everything up. We effectively end up with two sources for theresponse, and it means developers would need to wrap therequest.onpaymentauthorizedin a promise that guards against premature completion (as below, I am personally not a big fan):Definitely, could make the above leaner by doing what @mnoorenberghe does in his example above (do the
.compete()logic in the handler itself)... but, as I said, I think we missed that opportunity with the current design that returnsresponsefromawait request.show().Other cons would be having to introduce a new EventHandler interface type, as well as an attribute. While
.retry()only adds a single method and could work well with the existing state machine.Now, API design aside, a larger problem when retrying will be figuring out the restrictions on what can actually be fixed... If the
shippingAddressis not serviceable, then what does picking a new one do (specially because it could change the total, and now therequestis in a "close" state - so effectively dead)? Does therequestagain wake up and get put into an "interactive" state?Need to think more about the above, or see how ApplePay is handling it.
rsolomakhin commentedon Dec 8, 2017
@marcoscaceres, IMHO, shouldn't
.retry()be for billing issues only? Shipping address validation happens before user authorizes the payment, if the merchant needs to validate it, I thought.marcoscaceres commentedon Dec 8, 2017
Well, depends on #648 and if
addressLineshould be redacted. But ideally you are correct: then user can only change or update the payment instrument (and associated billing address) at this stage. This doesn’t quite match what ApplePay allows, but that might be workable nonetheless.marcoscaceres commentedon Dec 8, 2017
To be clear, redacted when the “shippingaddresschange” event fires.
[-]fine grained error recovery for fields[/-][+]retry and fine grained error recovery for fields[/+]marcoscaceres commentedon Apr 19, 2018
Consider supporting email, phoneNumber, etc. for retry.
marcoscaceres commentedon May 2, 2018
Seeking input:
ApplePayError)?Shipping address errors
Looking back over the discussion, I think having a
PaymentErrorinterface might be confusing and a bit heavyweight: Confusing, in that it's not anErrorin the JS/DOM sense (has no stack, for example). Heavyweight, in that it simply models a triple, but provides no other utilities.As an alternative, I think we can just use dictionaries to achieve the same result:
Note:
AddressErrorscould be reused for billing address errors, once the Payment Request API actually supports billing addresses properly (#27 and #550).Note: Errors for redacted fields could be ignored by the UA (e.g., complaining about shipping address'
phoneduring the "payment request" phase would be ignored, but would be honored when retrying the payment response).Usage example
Payer-related errors
The next class of errors deals specifically with payer related errors (name, email, phone):
Example
Thoughts, before I spec it up?
[-]retry and fine grained error recovery for fields[/-][+]Fine grained error recovery for fields[/+]stpeter commentedon May 2, 2018
@marcoscaceres I like this approach - clean and lightweight. Thanks for the concrete proposal!
domenic commentedon May 2, 2018
This design seems reasonable from a spec/IDL perspective. Pretty nice and simple; just an extension of the existing "error" option in PaymentDetailsUpdate.
mnoorenberghe commentedon May 2, 2018
LGTM! Thanks for getting back to this so quickly!
I only have two nits:
languageCodeso I'm not sure how useful an error message for it would be but I think it's fine to be consistent and support errors on all fields in the shipping address.addressLine=>addressLineseverywhere rather than continuing to propagate it e.g. support both in the code already shipped in UAs treating the old name as an alias to the new name.marcoscaceres commentedon May 3, 2018
Agree.
I'm thinking it might be too late... consider what happened already when we changed
supportedMethodsto a string. I think we are still dealing with the fallout.I personally think this will cause confusion, as people might think they can set one or the other, but then one will trash the other, etc. Naming things is hard 😢
That reminds me, nevertheless, that maybe
addressLineneeds special treatment, because it's a sequence of lines.So, maybe we actually need:
We could say that:
So:
Or is that overkill?
mnoorenberghe commentedon May 3, 2018
Sounds like overkill to me
marcoscaceres commentedon May 3, 2018
Ok, let's see how we go with
DOMString addressLine;.I'll wait a few days for others to chime in, but can start drafting things up behind the scenes.