安全上下文
此特征只可用于
安全上下文
(HTTPS),在某些或所有
支持浏览器
.
PaymentRequest()
构造函数创建新
PaymentRequest
object which will be used to handle the process of generating, validating, and submitting a payment request.
var paymentRequest = new PaymentRequest(methodData, details, [options]);
methodData
supportedMethods
DOMString
, and the meaning of the
data
parameter changes with the
supportedMethods
. For example, the basic card payment method is selected by specifying the string
basic-card
这里。
data
supportedMethods
. For basic credit card services, this structure should match the
BasicCardRequest
字典。
details
total
The total amount of the payment request.
id
可选
A free-form identifier for this payment request. If a value is not supplied, the browser will construct one.
displayItems
An array of optional line items for the payment request that the user agent may display, such as product details, tax, and shipping.
shippingOptions
The shipping options the user may choose from. If this sequence is blank, it indicates the merchant cannot ship to the current shipping address. The default shipping option may be indicated in this sequence.
modifiers
additionalDisplayItems
details.displayItems
property. This property is commonly used to add a discount or surcharge line item indicating the different amount in
details.modifiers.total
.
data
BasicCardRequest
字典。
total
details.modifiers.additionalItems
adds a discount or a surchase to the request.
选项
可选
Lets you set options that control the behavior of the user agent. This parameter contains the following fields:
requestPayerName
false
.
requestPayerEmail
false
.
requestPayerPhone
false
.
requestShipping
shippingType
。默认为
false
.
shippingType
"shipping"
,
"delivery"
,和
"pickup"
. Quotation marks must be included. The default value is
"shipping"
.
新的
PaymentRequest
object, configured for use as configured by the input parameters.
The following example shows minimal functionality and focuses instead on showing the complete context of instantiating a
PaymentRequest
对象。
var supportedInstruments = [{
supportedMethods: 'basic-card',
data: {
supportedNetworks: ['visa', 'mastercard', 'amex', 'jcb',
'diners', 'discover', 'mir', 'unionpay']
}
}];
var details = {
total: {label: 'Donation', amount: {currency: 'USD', value: '65.00'}},
displayItems: [
{
label: 'Original donation amount',
amount: {currency: 'USD', value: '65.00'}
}
],
shippingOptions: [
{
id: 'standard',
label: 'Standard shipping',
amount: {currency: 'USD', value: '0.00'},
selected: true
}
]
};
var options = {requestShipping: true};
try {
var request = new PaymentRequest(supportedInstruments, details, options);
// Add event listeners here.
// Call show() to trigger the browser's payment flow.
request.show().then(function(instrumentResponse) {
// Do something with the response from the UI.
})
.catch(function(err) {
// Do something with the error from request.show().
});
} catch (e) {
// Catch any other errors.
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
支付请求 API
The definition of 'PaymentRequest() constructor' in that specification. |
候选推荐 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
PaymentRequest()
构造函数
|
Chrome 61 | Edge ≤18 |
Firefox
55
注意事项
Disabled
|
IE 不支持 No | Opera 不支持 No | Safari 11.1 | WebView Android 不支持 No | Chrome Android 53 |
Firefox Android
55
注意事项
Disabled
|
Opera Android 不支持 No | Safari iOS 11.3 | Samsung Internet Android 6.0 |
完整支持
不支持
见实现注意事项。
用户必须明确启用此特征。
PaymentRequest
PaymentRequest()