安全上下文
此特征只可用于
安全上下文
(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.
未知
注意:
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
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. |
候选推荐 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
complete()
|
Chrome 61 | Edge 15 |
Firefox
56
注意事项
Disabled
|
IE 不支持 No | Opera 不支持 No | Safari Yes | WebView Android 不支持 No | Chrome Android 56 |
Firefox Android
56
注意事项
Disabled
|
Opera Android 不支持 No | Safari iOS Yes | Samsung Internet Android 6.0 |
完整支持
不支持
见实现注意事项。
用户必须明确启用此特征。
PaymentResponse
complete()
retry()