我们的志愿者还没有将这篇文章翻译为 中文 (简体)。加入我们帮助完成翻译!
您也可以阅读此文章的English (US)版。
Secure context
This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.
The BasicCardRequest
dictionary (related to the Payment Request API, although defined in the Basic Card Payment spec) defines an object structure for containing payment request details such as card type.
Properties
BasicCardRequest.supportedNetworks
Secure context- Contains an array of
DOMString
s representing the card networks that the retailer supports (e.g.amex
,mastercard
). BasicCardRequest.supportedTypes
Secure context- Contains an array of
DOMString
s representing the card types that the retailer supports (e.g.credit
,debit
,prepaid
).
Examples
In the following example, the PaymentRequest()
constructor is used to create a new payment request, which takes three objects as parameters — one containing details of the payment methods that can be used for the payment, one containing details of the actual order (such as items bought and shipping options), and an optional object containing further options.
The first of these three (supportedInstruments
in the example below) contains a data
property that has to conform to the structure defined by the BasicCardRequest
dictionary.
var supportedInstruments = [{
supportedMethods: 'basic-card',
data: {
supportedNetworks: ['visa', 'mastercard', 'amex', 'jcb',
'diners', 'discover', 'mir', 'unionpay'],
supportedTypes: ['credit', 'debit']
}
}];
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.
}
Once the payment flow has been triggered using PaymentRequest.show()
and the promise resolves successfully, the PaymentResponse
object available inside the fulfilled promise (instrumentResponse
above) will have a PaymentResponse.details
property that will contain response details. This has to conform to the structure defined by the BasicCardResponse
dictionary, and may look something like this:
{ "cardNumber' : '9999999999999999", "cardholderName' : 'Mr Dick Straw", "cardSecurityCode" : "999", "expiryMonth" : "07", "expiryYear" : "2021", "billingAddress" : { "country" : "GB", // etc. billing address is a PaymentAddress object } }
Specifications
Specification | Status | Comment |
---|---|---|
Unknown The definition of 'BasicCardRequest' in that specification. |
Unknown | Initial definition. |
Browser Compatibility
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | No support[1] | ? | ? | ? |
Feature | Android Webview | Chrome for Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | (Yes) | No support[1] | ? | ? | ? |
[1] Supported since 56 but disabled on all versions. Hidden behind the dom.payments.request.enabled
pref.