Custom events for payment methods

Hi folks,

In Apple Pay JS, there are two events that do not have equivalents in the Payment Request API (validatemerchant and paymentmethodselected). A PaymentRequest implementation that supports Apple Pay needs to account for these events, and I can think of two ways to do this:

1. Make the “data” object in the PaymentMethodData dictionary be an event target for Apple Pay. Unfortunately the spec requires this object to be JSON-stringified then re-parsed before being passed to the payment handler, but I suppose an implementation could keep around a reference to the original object for the purposes of firing events. If the spec didn’t require JSON round-tripping for all payment method objects, this is unquestionably the option I’d choose.

2. Fire payment method-specific events on the PaymentRequest object with prefixed names (e.g. applepayvalidatemerchant and applepaypaymentmethodselected). This seems distasteful, but simpler.

I’m wondering if anyone else has encountered this issue when implementing a payment method, and if so, how they went about solving it. Is there a recommended way for extending PaymentRequest with payment method-specific events?

Thanks,
Andy

Received on Wednesday, 4 October 2017 19:45:22 UTC