Re: [w3c/payment-request] Need short example of serializing response (#576)

FYI, I have sample code for this on https://emerald-eon.appspot.com/. Here's a simplified snippet:

```javascript
let payment = new PaymentRequest(...);
payment.show()
  .then(function(instrument) {
    fetch('/buy', {
      method: 'POST',
      headers: new Headers({'Content-Type': 'application/json'}),
      body: JSON.stringify(instrument, undefined, 2),
    })
    .then(function(buyResult) {
      if (buyResult.ok) {
        return buyResult.json();
      }
      complete(instrument, 'fail', 'Error sending instrument to server.');
    }).then(function(buyResultJson) {
      complete(instrument, buyResultJson.status, buyResultJson.message);
    });
  })
  .catch(function(error) {
    console.log('Could not charge user. ' + error);
  });

function complete(instrument, result, msg) {
  instrument.complete(result).then(function() {
    console.log(msg);
  }).catch(function(error) {
    console.log(error);
  });
}
```

-- 
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/576#issuecomment-322282505

Received on Monday, 14 August 2017 19:16:19 UTC