BasicCardResponse

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

这是 实验性技术
检查 浏览器兼容性表格 在生产中使用这之前。

BasicCardResponse dictionary (related to the 支付请求 API , although defined in the Basic Card Payment spec ) defines an object structure for payment response details such as the number/expiry date of the card used to make the payment, and the billing address.

特性

BasicCardResponse.cardNumber 只读 Secure context
Contains the number of the card used to make the payment.
BasicCardResponse.cardholderName 只读 Secure context 可选
Contains the cardholder name of the card used to make the payment.
BasicCardResponse.cardSecurityCode 只读 Secure context 可选
Contains the security code of the card used to make the payment.
BasicCardResponse.expiryMonth 只读 Secure context 可选
Contains the expiry month of the card used to make the payment.
BasicCardResponse.expiryYear 只读 Secure context 可选
Contains the expiry year of the card used to make the payment.
BasicCardResponse.billingAddress 只读 Secure context 可选
Contains the billing address of the card used to make the payment.

范例

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

规范

规范 状态 Comment
Basic Card Payment
The definition of 'BasicCardResponse' in that specification.
工作草案 初始定义。

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
BasicCardResponse Chrome 不支持 No Edge 不支持 ≤18 — 79 Firefox 56
注意事项 Disabled
56
注意事项 Disabled
Available only in nightly builds.
Disabled From version 56: this feature is behind the dom.payments.request.enabled preference (needs to be set to true ) and the dom.payments.request.supportedRegions preference (needs to be set to A comma-delineated list of one or more 2-character ISO country codes indicating the countries in which to support payments (for example, US,CA . ). To change preferences in Firefox, visit about:config.
IE 不支持 No Opera 不支持 No Safari ? WebView Android 不支持 No Chrome Android 57 Firefox Android 56
注意事项 Disabled
56
注意事项 Disabled
Available only in nightly builds.
Disabled From version 56: this feature is behind the dom.payments.request.enabled preference (needs to be set to true ) and the dom.payments.request.supportedRegions preference (needs to be set to A comma-delineated list of one or more 2-character ISO country codes indicating the countries in which to support payments (for example, US,CA . ). To change preferences in Firefox, visit about:config.
Opera Android 不支持 No Safari iOS ? Samsung Internet Android 7.0
billingAddress Chrome 不支持 No Edge 不支持 ≤18 — 79 Firefox 56
注意事项 Disabled
56
注意事项 Disabled
Available only in nightly builds.
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 Opera 不支持 No Safari ? WebView Android 不支持 No Chrome Android 57 Firefox Android 56
注意事项 Disabled
56
注意事项 Disabled
Available only in nightly builds.
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 Safari iOS ? Samsung Internet Android 7.0
cardholderName Chrome 不支持 No Edge 不支持 ≤18 — 79 Firefox 56
注意事项 Disabled
56
注意事项 Disabled
Available only in nightly builds.
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 Opera 不支持 No Safari ? WebView Android 不支持 No Chrome Android 57 Firefox Android 56
注意事项 Disabled
56
注意事项 Disabled
Available only in nightly builds.
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 Safari iOS ? Samsung Internet Android 7.0
cardNumber Chrome 不支持 No Edge 不支持 ≤18 — 79 Firefox 56
注意事项 Disabled
56
注意事项 Disabled
Available only in nightly builds.
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 Opera 不支持 No Safari ? WebView Android 不支持 No Chrome Android 57 Firefox Android 56
注意事项 Disabled
56
注意事项 Disabled
Available only in nightly builds.
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 Safari iOS ? Samsung Internet Android 7.0
cardSecurityCode Chrome 不支持 No Edge 不支持 ≤18 — 79 Firefox 56
注意事项 Disabled
56
注意事项 Disabled
Available only in nightly builds.
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 Opera 不支持 No Safari ? WebView Android 不支持 No Chrome Android 57 Firefox Android 56
注意事项 Disabled
56
注意事项 Disabled
Available only in nightly builds.
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 Safari iOS ? Samsung Internet Android 7.0
expiryMonth Chrome 不支持 No Edge 不支持 ≤18 — 79 Firefox 56
注意事项 Disabled
56
注意事项 Disabled
Available only in nightly builds.
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 Opera 不支持 No Safari ? WebView Android 不支持 No Chrome Android 57 Firefox Android 56
注意事项 Disabled
56
注意事项 Disabled
Available only in nightly builds.
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 Safari iOS ? Samsung Internet Android 7.0
expiryYear Chrome 不支持 No Edge 不支持 ≤18 — 79 Firefox 56
注意事项 Disabled
56
注意事项 Disabled
Available only in nightly builds.
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 Opera 不支持 No Safari ? WebView Android 不支持 No Chrome Android 57 Firefox Android 56
注意事项 Disabled
56
注意事项 Disabled
Available only in nightly builds.
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 Safari iOS ? Samsung Internet Android 7.0

图例

完整支持
完整支持
不支持
不支持
兼容性未知
兼容性未知
见实现注意事项。
用户必须明确启用此特征。
用户必须明确启用此特征。