PaymentResponse.complete()

Secure context
This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The PaymentRequest.complete() method of the PaymentRequest 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.

Syntax

PaymentRequest.complete([result])
   .then(function() { ... } )
   .catch( function(error) { ... } )

Returns

A Promise.

Parameters

result Optional
A string with one of the following values:
  • "success": Indicates the payment was successfully processed. The user agent may or may not indicate success to the user.
  • "fail": Indicates the payment was not successfully processed. The user agent may or may not indicate failure to the user.
  • "unknown": The web page did not indicate success or failure and the user agent should not display a UI indicating success or failure.  This is the default.
  • "" (empty string): The web page did not indicate success or failure and the user agent should not display a UI indicating success or failure. This value has been replaced by "unknown". See browser compatibility for details.

Note: The value passed to this method must include the quotation marks.

Examples

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);
});

Specifications

Specification Status Comment
Payment Request API
The definition of 'PaymentResponse: complete' in that specification.
Candidate Recommendation Initial definition.

Browser Compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic support
Experimental
Chrome Full support 61
Disabled
Full support 61
Disabled
Disabled From version 61: this feature is behind the #web-payments preference (needs to be set to Enabled). To change preferences in Chrome, visit chrome://flags.
Edge Full support 15Firefox Full support 56
Disabled
Full support 56
Disabled
Disabled From version 56: this feature is behind the dom.payments.request.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
IE No support NoOpera No support NoSafari ? WebView Android No support NoChrome Android Full support 53
Disabled
Full support 53
Disabled
Disabled From version 53: this feature is behind the #web-payments preference (needs to be set to Enabled). To change preferences in Chrome, visit chrome://flags.
Edge Mobile Full support YesFirefox Android Full support 56
Disabled
Full support 56
Disabled
Disabled From version 56: this feature is behind the dom.payments.request.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
Opera Android No support NoSafari iOS ? Samsung Internet Android Full support 6.0

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
User must explicitly enable this feature.
User must explicitly enable this feature.

Document Tags and Contributors

Last updated by: sideshowbarker,