- From: Domenic Denicola <notifications@github.com>
- Date: Tue, 15 Aug 2017 18:03:56 +0000 (UTC)
- To: w3c/payment-request <payment-request@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <w3c/payment-request/pull/583/review/56419282@github.com>
domenic approved this pull request. LGTM with potential improvements > + It's expected that data in a <a>PaymentResponse</a> will be POSTed + back to a server for processing. To make this as easy as possible, + <a>PaymentResponse</a> provides a <a>toJSON()</a> method that + serializes the object directly into JSON. This makes it trivial to + POST the resulting JSON back to a server using the <a data-cite= + "fetch">Fetch API</a>: + </p> + <pre class="example"> + async function doPaymentRequest() { + const payRequest = new PaymentRequest(methodData, details, options); + const payResponse = await payRequest.show(); + let result = "unknown"; + try { + const httpResponse = await fetch("/process-payment", { + method: "POST", + headers: new Headers({ "Content-Type": "application/json" }), `new Headers` is not necessary; you can pass the object literal directly. > + "fetch">Fetch API</a>: + </p> + <pre class="example"> + async function doPaymentRequest() { + const payRequest = new PaymentRequest(methodData, details, options); + const payResponse = await payRequest.show(); + let result = "unknown"; + try { + const httpResponse = await fetch("/process-payment", { + method: "POST", + headers: new Headers({ "Content-Type": "application/json" }), + body: payResponse.toJSON(), + }); + result = httpResponse.ok ? "success" : "fail"; + } catch (err) { + console.error(err); Should this set result = "fail"? -- 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/pull/583#pullrequestreview-56419282
Received on Tuesday, 15 August 2017 18:04:19 UTC