@aestes, I would prefer to make this method generic, so that payment handlers have the option of firing the `merchantvalidation` event as well. The code in the payment handler would look like this:
```javascript
const VALIDATION_URL = '...';
const SESSION_ID = '...';
self.addEventListener('canmakepayment', (c) => {
c.validateMerchant(VALIDATION_URL).then((b) => {
c.respondWith(b == SESSION_ID);
});
});
```
The code on the merchant website would look like this:
```javascript
const MERCHANT_SERVER = '...';
paymentRequest.addEventListener('merchantvalidation', (v) => {
v.complete(new Promise(async resolve => {
const b = await fetch(MERCHANT_SERVER +
encodeURIComponent(v.validationUrl)).then(r => r.text());
resolve(b);
});
});
```
The overall flow would work like this:
![Generic merchant validation](https://i.imgur.com/6EzrU8f.png)
What do you think? I'm open to suggestions and persuasion: we don't *have* to have a generic merchant validation mechanism if you feel that's right.
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/payment-request/issues/646#issuecomment-352265102