安全上下文
此特征只可用于 安全上下文 (HTTPS),在某些或所有 支持浏览器 .

PaymentRequest 方法 complete() 支付请求 API notifies the 用户代理 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 返回通过 PaymentRequest.show() method is resolved.

句法

completePromise = paymentRequest.complete(result);
					

参数

result 可选

A DOMString indicating the state of the payment operation upon completion. It must be one of the following:

success

The payment was successfully processed. The user agent may or may not present some form of "payment successful" indication to the user.

fail

The payment was not successfully processed. The failure may or may not be announced to the user by the user agent, depending on its design.

未知
The success or failure status of the transaction is unknown or irrelevant, and the user agent should not present any notification, even if it normally would. This is the default value.

注意: In older versions of the specification, an empty string, "" , was used instead of 未知 to indicate a completion without a known result state. See the 浏览器兼容性 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

The document in which the payment request is taking place became inactive while the user interface was shown.

InvalidStateError
The payment has already completed, or 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 抓取 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);
});
						

规范

规范 状态 注释
支付请求 API
The definition of 'PaymentResponse: complete' in that specification.
候选推荐 初始定义。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
complete() Chrome 61 Edge 15 Firefox 56 注意事项 Disabled
56 注意事项 Disabled
Available only in nightly builds.
Disabled ). To change preferences in Firefox, visit about:config.
IE 不支持 No Opera 不支持 No Safari Yes WebView Android 不支持 No Chrome Android 56 Firefox Android 56 注意事项 Disabled
56 注意事项 Disabled
Available only in nightly builds.
Disabled ). To change preferences in Firefox, visit about:config.
Opera Android 不支持 No Safari iOS Yes Samsung Internet Android 6.0

图例

完整支持

完整支持

不支持

不支持

见实现注意事项。

用户必须明确启用此特征。

用户必须明确启用此特征。

元数据

  • 最后修改: