Secure context
This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
The PaymentRequest
method complete()
of the Payment Request API notifies the user agent that the user interaction is over, and causes any remaining user interface to be closed. This method must be called after the user accepts the payment request and the Promise
returned by the PaymentRequest.show()
method is resolved.
completePromise = paymentRequest.complete(result);
result
Optional
A DOMString
indicating the state of the payment operation upon completion. It must be one of the following:
success
fail
unknown
Note: In older versions of the specification, an empty string, ""
, was used instead of unknown
to indicate a completion without a known result state. See the Browser compatibility section below for details.
A Promise
which resolves with no input value once the payment interface has been fully closed. If an error occurs, the promise instead rejects, returning one of the exceptions listed below.
AbortError
InvalidStateError
complete()
was called while a request to retry the payment is pending. You can't treat a payment as complete after requesting that the payment be tried again.The following example sends payment information to a secure server using the Fetch API. It calls complete()
with an answer appropriate to the status in the response.
// Initialization of PaymentRequest arguments are excerpted for the // sake of brevity. var payment = new PaymentRequest(supportedInstruments, details, options); payment.show().then(function(paymentResponse) { var fetchOptions = { method: 'POST', credentials: include, body: JSON.stringify(paymentResponse) }; var serverPaymentRequest = new Request('secure/payment/endpoint'); fetch(serverPaymentRequest, fetchOptions).then( response => { if (response.status < 400) { paymentResponse.complete("success"); } else { paymentResponse.complete("fail"); }; }).catch( reason => { paymentResponse.complete("fail"); }); }).catch(function(err) { console.error("Uh oh, something bad happened", err.message); });
Specification | Status | Comment |
---|---|---|
Payment Request API The definition of 'PaymentResponse: complete' in that specification. | Candidate Recommendation | Initial definition. |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 61
|
15 | 56
|
No | No | ? |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | No | 53
|
Yes | 56
|
No | ? | 6.0 |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/PaymentResponse/complete