Closed marcoscaceres closed 6 years ago
@marcoscaceres, it has been pointed out that the proposal as written (if I read the code correctly) requires the developer to query all the fields to find out which thing changed. What would be your suggested good practice for figuring out which thing changed?
What would be your suggested good practice for figuring out which thing changed?
There is not way to detect which changed, just revalidate. So the question is mostly around validation of these values...
response.onpayerdetailchange = ev => {
const errors = {};
const { payerName, payerEmail, payerPhone } = response;
object.assign(
errors, validateEmail(payerEmail), validateName(payerName), validatePhone(payerPhone)
);
if(Object.getOwnPropertyNames(x).length){
response.retry(errors);
}
}
actually, to be safe, maybe the should be separate events 🧐... if each of those requires a network lookup for validation, then this could get a little bit sad. Question is, is anyone doing this validation over the network?
@marcoscaceres What would the separate events be?
onpayeremailchange
, onpayerphonechange
, and onpayernamechange
.
That's what I was afraid of, but I see why we might need it...
The problem is that if UI autofills the three fields at the same time, we get into a race condition.
Ah, I had not thought about the autofill scenario; I was only imagining independent manual interaction.
Discussed with our UI folks too. The single event is better for us, because it gives us more flexibility as to when we fire the event (e.g., clicking "next").
so, this is how one would handle having the single event:
let {
payerName: oldPayerName,
payerEmail: oldPayerEmail,
payerPhone: oldPayerPhone,
} = response;
response.onpayerdetailchange = async ev => {
const promisesToValidate = [];
const { payerName, payerEmail, payerPhone } = response;
if (oldPayerName !== payerName) {
promisesToValidate.push(validateName(payerName));
oldPayerName = payerName;
}
if (oldPayerEmail !== payerEmail) {
promisesToValidate.push(validateEmail(payerEmail));
oldPayerEmail = payerEmail;
}
if (oldPayerPhone !== payerPhone) {
promisesToValidate.push(validatePhone(payerPhone));
oldPayerPhone = payerPhone;
}
const errors = await Promise.all(promisesToValidate).then(results =>
results.reduce((errors, result), Object.assign(errors, result))
);
if (Object.getOwnPropertyNames(errors).length) {
await response.retry(errors);
}
};
Based on my experience of implementing payments request on multiple demo's for worldpay now. I would echo the recommendation of marco's ui guys and leave the single event. While a complicated handler is not perfect I admit it does keep the code a lot clearer than having a lot of separate event handlers
Hi @marcoscaceres,
I have been asking around for views on the question of "one event" v. "multiple events". You can see that @DannyRussellWP supported a single event. I've heard back similarly from two other payments companies as well.
Ian
Excellent, thanks for the update @ianbjacobs.
@marcoscaceres @ianbjacobs - The preference from Airbnb is that one event handler would suffice.
I asked internally and have updated this action regarding this: https://www.w3.org/Payments/WG/track/actions/97
Appreciate the feedback @wanli!
@domenic, hopefully less bad now 🤞
Added Gecko tracking bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1472026
Firefox implementation underway.
WebKit tracking bug: https://bugs.webkit.org/show_bug.cgi?id=189249
@romandev, any news on this one (PaymentResponse.prototype.onpayerdetailchange
) from the Chrome side?
Ah, I didn't create a new separate bug but it's already finished here: https://chromium-review.googlesource.com/c/chromium/src/+/1206750
Chrome tracking bug: https://bugs.chromium.org/p/chromium/issues/detail?id=901710
Awesome. Looks like I need to do another run of WTP to update the implementation report.
part 4 of #705 - define eventing model for "payerdetailchange".
The following tasks have been completed:
Implementation commitment:
Impact on Payment Handler spec?
Preview | Diff