KEMBAR78
add paymentmethodchange event by marcoscaceres · Pull Request #695 · w3c/payment-request · GitHub
Skip to content

Conversation

marcoscaceres
Copy link
Member

@marcoscaceres marcoscaceres commented Mar 22, 2018

closes #662

The following tasks have been completed:

Implementation commitment:


Preview | Diff

Copy link
Collaborator

@rsolomakhin rsolomakhin left a comment

Choose a reason for hiding this comment

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

Does this change affect ShippingAddressUpdateEvent and ShippingOptionUpdateEvent?

@marcoscaceres
Copy link
Member Author

Only indirectly and in a backwards compatibile way. I hope to have a draft ready for review tomorrow.

@rsolomakhin
Copy link
Collaborator

No rush! Just checking.

@marcoscaceres marcoscaceres requested a review from aestes April 19, 2018 07:47
@marcoscaceres marcoscaceres requested a review from domenic April 30, 2018 05:51
@marcoscaceres
Copy link
Member Author

Basic card integration w3c/payment-method-basic-card#53

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.

Some issues, in particular confusion about which payment handler is being referenced.

index.html Outdated
<li>Let <var>methodDetails</var> be null.
</li>
<li>If <var>request</var>'s <a>payment handler</a> defines a <a>user
changes payment method</a> algorithm, set <var>methodDetails</var> be
Copy link
Collaborator

Choose a reason for hiding this comment

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

This link is not going anywhere in the output. It should probably be a <dfn>?

index.html Outdated
changes payment method</a> algorithm, set <var>methodDetails</var> be
a <a data-cite="!WEBIDL#idl-dictionary">dictionary</a> or
<a data-cite="!WEBIDL#idl-object">object</a> resulting the user
selecting a different <a>payment method</a>.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this be "resulting from running that algorithm"?

index.html Outdated
selecting a different <a>payment method</a>.
</li>
<li>Let <var>methodName</var> be the <a>payment method identifier</a>
of the <a>payment handler</a> the user is interacting with.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is "the payment handler the user is interacting with" different from "request's payment handler"?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, given that the user is potentially switching payment handlers, is the original or the new one "request's payment handler"? Is the original or the new one "the payment handler the user is interacting with"?

index.html Outdated
Promise&lt;boolean&gt; canMakePayment();

readonly attribute DOMString id;
readonly attribute object? methodDetails;
Copy link
Collaborator

Choose a reason for hiding this comment

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

A good test to write will be that pr.methodDetails === pr.methodDetails. The spec makes this requirement clear but it's something implementers sometimes miss.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will need to test this with Basic Card.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added the test you suggested:
https://github.com/w3c/web-platform-
tests/pull/10912/commits/29a384b326fc514da854a9041cdfbde13e0eee54

@marcoscaceres
Copy link
Member Author

Sent tests for review web-platform-tests/wpt#10912

@marcoscaceres marcoscaceres changed the title WIP: add paymentmethodchanged event add paymentmethodchanged event May 10, 2018
@marcoscaceres marcoscaceres changed the title add paymentmethodchanged event add paymentmethodchange event May 10, 2018
@marcoscaceres marcoscaceres force-pushed the paymentmethodchanged branch 2 times, most recently from 134fd66 to a863d31 Compare May 10, 2018 04:58
@marcoscaceres
Copy link
Member Author

Realized that when other events fire (e.g., onshippingaddresschange) or generally things happen on the user interaction task source (e.g., user aborts, request.abort()), the methodDetails needs to be reset to null... same with methodName.

@marcoscaceres marcoscaceres force-pushed the paymentmethodchanged branch from d00e49b to edb52f8 Compare May 10, 2018 06:45
@marcoscaceres
Copy link
Member Author

marcoscaceres commented May 10, 2018

Hmmm... having spec'ed this out, now I don't know if I like this design anymore 😓 Doesn't feel right that the only thing that changes .methodName and .methodData is this event.

Maybe this should switch back to having special event for this, as per #662 (comment)

The name paymentmethodchange is also super ambiguous tho, because it's really a "Instrument change" of a payment method. So, I I'm kind thinking "instrumentchange" is more appropriate as an event name.

I think I'd like to change this to:

PaymentMethodChangeEvent : PaymentRequestUpdateEvent {
   readonly attribute DOMString methodName;
   readonly attribute object? methodDetails;
}

So that:

request.oninstrumentchange = ev => {
  const { type: cardType } = ev.methodDetails;
  if (ev.methodName === "https://apple.com/apple-pay") {
    switch (cardType) {
      case "store":
        // do Apple Pay specific handling for store card...
        break;
    }
  }
  // finally...
  ev.updateWith(newStuff);
};

@aestes wdyt?

@marcoscaceres
Copy link
Member Author

Updated this to match #695 (comment)

@marcoscaceres
Copy link
Member Author

Updated WPTests to match updated spec.

marcoscaceres added a commit to web-platform-tests/wpt that referenced this pull request May 23, 2018
@marcoscaceres marcoscaceres force-pushed the paymentmethodchanged branch from a520c57 to 87f22bd Compare May 31, 2018 02:11
@marcoscaceres
Copy link
Member Author

@domenic, this one too should now be good to go (🤞).

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.

Confused how the payment method change steps are supposed to be implemented...

index.html Outdated
</h2>
<p>
The user agent MUST run the <dfn>payment method changed
algorithm</dfn> runs when the user changes <a>payment method</a>. The
Copy link
Collaborator

Choose a reason for hiding this comment

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

extra word "runs"

index.html Outdated
<a data-cite="!WEBIDL#idl-object">object</a> or null, and a
<var>methodName</var>, which is a DOMString that represents the
<a>payment method identifier</a> of the <a>payment handler</a> the
user is interacting with:
Copy link
Collaborator

Choose a reason for hiding this comment

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

How does the user agent determine methodName and methodDetails?

Copy link
Member Author

Choose a reason for hiding this comment

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

Will rephrase this, as it's actually the Payment Handler that needs to invoke this. From discussions over in Basic Card, we are going to make this optional... so Basic Card won't fire this, but Apply Pay will.

index.html Outdated
further action. The <a>user agent</a> user interface SHOULD
ensure that this never occurs.
</li>
<li data-link-for="PaymentMethodChangeEvent">Fire an event
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ideally "fire an event" should be linked

};
</pre>
<section>
<h2>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Soooo I know it goes against all previous advice and good sense, but currently for events we don't use internal slots :(. Instead we use the old-style, terrible, "When getting, returns the value it was initialized with". I think making this less terrible is mostly tracked by whatwg/dom#364, /cc @annevk. But in the end we do want to end up in a world that doesn't require people to explicitly define slots and return them for every event property, so I would take the slots out for now. Especially since nothing in this spec sets them.

Copy link
Member Author

Choose a reason for hiding this comment

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

Um, ok... um... we kinda added internal slots PaymentRequestUpdateEvent also.

I guess I should remove and rephrase those too?

Copy link
Collaborator

Choose a reason for hiding this comment

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

No, that one makes sense, as its not exposed. It's the ones that are 1:1 with public properties that are less-good.

Copy link
Member Author

Choose a reason for hiding this comment

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

ah, got it. Ok :)

@marcoscaceres marcoscaceres force-pushed the paymentmethodchanged branch from 5801ded to 47db0ee Compare June 6, 2018 02:19
@marcoscaceres
Copy link
Member Author

@domenic, I think I've addressed all the feedback 🤞

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 with nits

index.html Outdated
</h2>
<p data-link-for="PaymentMethodChangeEventInit">
When getting, returns the value it was initialized with. See
<a>methodDetails</a> member for more information.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here and below, "member of PaymentMethodChangeEventInit" perhaps? Otherwise before you click on it it looks like it'll just link to itself.

index.html Outdated
ensure that this never occurs.
</li>
<li data-link-for="PaymentMethodChangeEvent">
<a>Fire an event</a> "<a>paymentmethodchange</a>" at
Copy link
Collaborator

Choose a reason for hiding this comment

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

Fire an event named

@marcoscaceres marcoscaceres force-pushed the paymentmethodchanged branch from 47db0ee to 6a79bfb Compare June 12, 2018 16:41
@marcoscaceres
Copy link
Member Author

Added link to Firefox tracking bug.

marcoscaceres added a commit to web-platform-tests/wpt that referenced this pull request Jun 12, 2018
@marcoscaceres
Copy link
Member Author

Added developer documentation. Please review. https://developer.mozilla.org/en-US/docs/Web/API/PaymentRequest/onpaymentmethodchange

@marcoscaceres marcoscaceres merged commit b336891 into gh-pages Jun 21, 2018
@marcoscaceres marcoscaceres deleted the paymentmethodchanged branch June 21, 2018 15:55
@marcoscaceres
Copy link
Member Author

PaymentMethodChangeEvent is now in Firefox Nightly behind a pref. We don't currently have any plans to fire it for Basic Card, but other payment handlers could theoretically make use of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add equivalent of applepaypaymentmethodchanged

3 participants