KEMBAR78
Add PaymentResponse.prototype.onpayerdetailchange by marcoscaceres · Pull Request #724 · w3c/payment-request · GitHub
Skip to content

Conversation

marcoscaceres
Copy link
Member

@marcoscaceres marcoscaceres commented Jun 12, 2018

part 4 of #705 - define eventing model for "payerdetailchange".

The following tasks have been completed:

Implementation commitment:

Impact on Payment Handler spec?


Preview | Diff

@ianbjacobs
Copy link
Collaborator

@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?

@marcoscaceres
Copy link
Member Author

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);
   }
}

@marcoscaceres
Copy link
Member Author

marcoscaceres commented Jun 14, 2018

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?

@stpeter
Copy link

stpeter commented Jun 14, 2018

@marcoscaceres What would the separate events be?

@marcoscaceres
Copy link
Member Author

onpayeremailchange, onpayerphonechange, and onpayernamechange.

@stpeter
Copy link

stpeter commented Jun 14, 2018

That's what I was afraid of, but I see why we might need it...

@marcoscaceres
Copy link
Member Author

The problem is that if UI autofills the three fields at the same time, we get into a race condition.

@ianbjacobs
Copy link
Collaborator

Ah, I had not thought about the autofill scenario; I was only imagining independent manual interaction.

@marcoscaceres
Copy link
Member Author

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").

@marcoscaceres
Copy link
Member Author

marcoscaceres commented Jun 14, 2018

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);
  }
};

@DannyRussellWP
Copy link

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

@ianbjacobs
Copy link
Collaborator

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

@marcoscaceres
Copy link
Member Author

Excellent, thanks for the update @ianbjacobs.

@wanli
Copy link

wanli commented Jun 25, 2018

@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

@marcoscaceres
Copy link
Member Author

Appreciate the feedback @wanli!

@marcoscaceres marcoscaceres force-pushed the retry_request_events branch from e6f78f9 to f448712 Compare June 25, 2018 23:42
@marcoscaceres marcoscaceres force-pushed the retry_request_events branch from f448712 to 1dfd596 Compare June 26, 2018 20:58
@marcoscaceres marcoscaceres requested a review from domenic June 26, 2018 20:59
@marcoscaceres marcoscaceres changed the title Add PaymentResponse.onpayerdetailchange Add paymentResponse.prototype.onpayerdetailchange Jun 26, 2018
@marcoscaceres marcoscaceres changed the title Add paymentResponse.prototype.onpayerdetailchange Add PaymentResponse.prototype.onpayerdetailchange Jun 26, 2018
Copy link
Collaborator

@domenic domenic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little hard to review due to the switched headings... let's get that fixed.

index.html Outdated
"DOM#event-target">target</a> is an instance of
<a>PaymentResponse</a>, let <var>request</var> be
<var>event</var>'s <a data-cite=
"DOM#event-target">target</a><a>[[\request]]</a>.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing dot

index.html Outdated
<li>Let <var>request</var> be the <a>PaymentRequest</a> object that
the user is interacting with.
</li>
<li>If <var>request</var><a>[[\response]]</a> is null, terminate this
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing dot

Use "return" instead of "terminate this algorithm"

index.html Outdated
algorithm.
</li>
<li>Let <var>response</var> be
<var>request</var><a>[[\response]]</a>.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing dot

Move this step up so that you can check if response is null.

index.html Outdated
<li>If <var>payer name</var> changed:
<ol>
<li data-link-for="PaymentOptions">Assert:
<var>request</var><a>[[\options]]</a>.<a>requestPayerName</a>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Search for </var><a>[[, so many missing dots...

with:
</p>
<ol class="algorithm">
<li>Let <var>request</var> be the <a>PaymentRequest</a> object that
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The algorithms seem to be switched; this is the payment details changed algorithm.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argh, oops... screwed up the merge/

@marcoscaceres
Copy link
Member Author

@domenic, hopefully less bad now 🤞

Copy link
Collaborator

@domenic domenic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

index.html Outdated
with:
</p>
<ol class="algorithm">
<ol class="algorithm">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whitspace change seems bad

index.html Outdated
the user is interacting with.
</li>
<li>If <var>request</var>.<a>[[\response]]</a> is null, terminate
this algorithm.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"terminate this algorithm" -> "return"

index.html Outdated
<li data-link-for="PaymentRequestUpdateEvent">If
<var>event</var>.<a>[[\waitForUpdate]]</a> is true, disable any
part of the user interface that could cause another update event
to be fired.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is "another update event" appropriate here? Maybe "another change to the payer details"?

@marcoscaceres
Copy link
Member Author

Added Gecko tracking bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1472026

@marcoscaceres
Copy link
Member Author

@marcoscaceres
Copy link
Member Author

marcoscaceres commented Jul 3, 2018

Added tests web-platform-tests/wpt#11772

@marcoscaceres marcoscaceres merged commit d27cc16 into gh-pages Jul 3, 2018
@marcoscaceres marcoscaceres deleted the retry_request_events branch July 3, 2018 17:02
@marcoscaceres
Copy link
Member Author

Firefox implementation underway.

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Sep 5, 2018
The event handler is triggered when the user changes payer information
such as payer name, payer email, or payer phone in the user interface.

Related spec change:
  w3c/payment-request#724

Test:
  payment-request/payment-response/onpayerdetailchange-attribute.https.html
  payment-request/payment-response/onpayerdetailchange-attribute.manual.https.html

Bug: 861704
Change-Id: Ia5d63f53874abd7c76014bf35379a71a0eead622
marcoscaceres pushed a commit to web-platform-tests/wpt that referenced this pull request Sep 6, 2018
…2846)

The event handler is triggered when the user changes payer information
such as payer name, payer email, or payer phone in the user interface.

Related spec change:
  w3c/payment-request#724

Test:
  payment-request/payment-response/onpayerdetailchange-attribute.https.html
  payment-request/payment-response/onpayerdetailchange-attribute.manual.https.html

Bug: 861704
Change-Id: Ia5d63f53874abd7c76014bf35379a71a0eead622
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Sep 10, 2018
…e.payerdetailchange event, a=testonly

Automatic update from web-platform-testsPaymentRequest: Implement PaymentResponse.payerdetailchange event (#12846)

The event handler is triggered when the user changes payer information
such as payer name, payer email, or payer phone in the user interface.

Related spec change:
  w3c/payment-request#724

Test:
  payment-request/payment-response/onpayerdetailchange-attribute.https.html
  payment-request/payment-response/onpayerdetailchange-attribute.manual.https.html

Bug: 861704
Change-Id: Ia5d63f53874abd7c76014bf35379a71a0eead622
--

wpt-commits: 3c6c9350988f98c8fac94fab8174bc4729cd6755
wpt-pr: 12846
jankeromnes pushed a commit to jankeromnes/gecko that referenced this pull request Sep 10, 2018
…e.payerdetailchange event, a=testonly

Automatic update from web-platform-testsPaymentRequest: Implement PaymentResponse.payerdetailchange event (#12846)

The event handler is triggered when the user changes payer information
such as payer name, payer email, or payer phone in the user interface.

Related spec change:
  w3c/payment-request#724

Test:
  payment-request/payment-response/onpayerdetailchange-attribute.https.html
  payment-request/payment-response/onpayerdetailchange-attribute.manual.https.html

Bug: 861704
Change-Id: Ia5d63f53874abd7c76014bf35379a71a0eead622
--

wpt-commits: 3c6c9350988f98c8fac94fab8174bc4729cd6755
wpt-pr: 12846
aarongable pushed a commit to chromium/chromium that referenced this pull request Sep 13, 2018
The event handler is triggered when the user changes payer information
such as payer name, payer email, or payer phone in the user interface.

Unlike other PaymentRequestUpdateEvent(e.g. shippingaddresschange), this
event can fire only after the website calls retry() with validation
errors in the payer contact information.

This feature is still behind runtime flag(PaymentRetry).

Intent to implement:
  https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/wayZGnuBkrI

Related spec change:
  w3c/payment-request#724

Test:
  payment-request/payment-response/onpayerdetailchange-attribute.https.html
  payment-request/payment-response/onpayerdetailchange-attribute.manual.https.html

Bug: 861704
Change-Id: Ia5d63f53874abd7c76014bf35379a71a0eead622
Reviewed-on: https://chromium-review.googlesource.com/1206750
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Reviewed-by: Rouslan Solomakhin <rouslan@chromium.org>
Commit-Queue: Jinho Bang <jinho.bang@samsung.com>
Cr-Commit-Position: refs/heads/master@{#590961}
@aestes
Copy link
Collaborator

aestes commented Nov 2, 2018

WebKit tracking bug: https://bugs.webkit.org/show_bug.cgi?id=189249

@marcoscaceres
Copy link
Member Author

@romandev, any news on this one (PaymentResponse.prototype.onpayerdetailchange) from the Chrome side?

@romandev
Copy link
Member

romandev commented Nov 5, 2018

Ah, I didn't create a new separate bug but it's already finished here:
https://chromium-review.googlesource.com/c/chromium/src/+/1206750

@romandev
Copy link
Member

romandev commented Nov 5, 2018

Chrome tracking bug: https://bugs.chromium.org/p/chromium/issues/detail?id=901710

@marcoscaceres
Copy link
Member Author

Awesome. Looks like I need to do another run of WTP to update the implementation report.

aarongable pushed a commit to chromium/chromium that referenced this pull request Feb 28, 2019
The event handler is triggered when the user changes payer information
such as payer name, payer email, or payer phone in the user interface.
Unlike other PaymentRequestUpdateEvent(e.g. shippingaddresschange), this
event can fire only after the website calls retry() with validation
errors in the payer contact information.

This feature is still behind runtime flag(PaymentRetry).
FYI, we've already had a desktop implementation in crrev.com/c/1206750.

Intent to implement:
  https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/wayZGnuBkrI

Related spec change:
  w3c/payment-request#724

Test:
  chrome/android/javatests/src/org/chromium/chrome/browser/payments/PaymentRequestRetryTest.java
  payment-request/payment-response/onpayerdetailchange-attribute.https.html
  payment-request/payment-response/onpayerdetailchange-attribute.manual.https.html

Bug: 861704
Change-Id: If9d01e4696b0ed8e415a76313c70da4d6ec230f6
Reviewed-on: https://chromium-review.googlesource.com/c/1477610
Commit-Queue: Jinho Bang <jinho.bang@samsung.com>
Reviewed-by: Rouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#636489}
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this pull request Oct 3, 2019
…e.payerdetailchange event, a=testonly

Automatic update from web-platform-testsPaymentRequest: Implement PaymentResponse.payerdetailchange event (#12846)

The event handler is triggered when the user changes payer information
such as payer name, payer email, or payer phone in the user interface.

Related spec change:
  w3c/payment-request#724

Test:
  payment-request/payment-response/onpayerdetailchange-attribute.https.html
  payment-request/payment-response/onpayerdetailchange-attribute.manual.https.html

Bug: 861704
Change-Id: Ia5d63f53874abd7c76014bf35379a71a0eead622
--

wpt-commits: 3c6c9350988f98c8fac94fab8174bc4729cd6755
wpt-pr: 12846

UltraBlame original commit: 9d6bcd31919749a8a6cb9fe5d2ca3fa37a6a28ba
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request Oct 3, 2019
…e.payerdetailchange event, a=testonly

Automatic update from web-platform-testsPaymentRequest: Implement PaymentResponse.payerdetailchange event (#12846)

The event handler is triggered when the user changes payer information
such as payer name, payer email, or payer phone in the user interface.

Related spec change:
  w3c/payment-request#724

Test:
  payment-request/payment-response/onpayerdetailchange-attribute.https.html
  payment-request/payment-response/onpayerdetailchange-attribute.manual.https.html

Bug: 861704
Change-Id: Ia5d63f53874abd7c76014bf35379a71a0eead622
--

wpt-commits: 3c6c9350988f98c8fac94fab8174bc4729cd6755
wpt-pr: 12846

UltraBlame original commit: 9d6bcd31919749a8a6cb9fe5d2ca3fa37a6a28ba
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this pull request Oct 3, 2019
…e.payerdetailchange event, a=testonly

Automatic update from web-platform-testsPaymentRequest: Implement PaymentResponse.payerdetailchange event (#12846)

The event handler is triggered when the user changes payer information
such as payer name, payer email, or payer phone in the user interface.

Related spec change:
  w3c/payment-request#724

Test:
  payment-request/payment-response/onpayerdetailchange-attribute.https.html
  payment-request/payment-response/onpayerdetailchange-attribute.manual.https.html

Bug: 861704
Change-Id: Ia5d63f53874abd7c76014bf35379a71a0eead622
--

wpt-commits: 3c6c9350988f98c8fac94fab8174bc4729cd6755
wpt-pr: 12846

UltraBlame original commit: 9d6bcd31919749a8a6cb9fe5d2ca3fa37a6a28ba
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants