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.
complete()
complete(result)
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.
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.
const payment = new PaymentRequest(supportedInstruments, details, options);
payment
.show()
.then((paymentResponse) => {
const fetchOptions = {
method: "POST",
credentials: include,
body: JSON.stringify(paymentResponse),
};
const 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((err) => {
console.error("Uh oh, something bad happened", err.message);
});