Re: [w3c/browser-payment-api] canMakePayment() might be in the wrong place? (#403)

Hello guys,

Sorry to dig up this issue and apologize in advance if this is the wrong place to ask; 
I'm questioning the value of `canMakePayment`  method on an instance of PaymentRequest in a real world situation.
All code examples of `canMakePayment` assumes that we have the checkout data (total amount, currency …) as soon as the page loads.
In most cases I believe this can't be realistic and we would have to wait for an action from the user (i.e click on a checkout button) in order to spin up an instance of paymentRequest.

If one wanted to determine whether a user can make payment before having the checkout data, that would mean he would have to create a first instance of PaymentRequest with dummy data; and then   recreate an other instance when the user clicks on the checkout button.

```js
// Page loads, one has to determine if user can make payment
const data = {displayItems: [], total: {label: '', amount: {currency: 'USD', value: '1.00'}}}; // dummy data
const request = new window.PaymentRequest(instruments, data);
request.canMakePayment().then((result) => {
  // Perform some logic (display an extra button, hijack the regular checkout button ...)
})


// User clicks on the checkout button, request goes to the backend to create a checkout and retrieve the real data
const request = new window.PaymentRequest(instruments);
request.show().then(() => …)

-- 
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/browser-payment-api/issues/403#issuecomment-297537813

Received on Wednesday, 26 April 2017 20:53:38 UTC