Secure context
This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The BasicCardResponse
dictionary (related to the Payment Request 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
Read only Secure context
BasicCardResponse.cardholderName
Read only Secure context Optional
BasicCardResponse.cardSecurityCode
Read only Secure context Optional
BasicCardResponse.expiryMonth
Read only Secure context Optional
BasicCardResponse.expiryYear
Read only Secure context Optional
BasicCardResponse.billingAddress
Read only Secure context Optional
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 } }
Specification | Status | Comment |
---|---|---|
Basic Card Payment The definition of 'BasicCardResponse' in that specification. | Working Draft | Initial definition. |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | No | Yes | 56
|
No | No | ? |
cardNumber
|
No | Yes | 56
|
No | No | ? |
cardholderName
|
No | Yes | 56
|
No | No | ? |
cardSecurityCode
|
No | Yes | 56
|
No | No | ? |
expiryMonth
|
No | Yes | 56
|
No | No | ? |
expiryYear
|
No | Yes | 56
|
No | No | ? |
billingAddress
|
No | Yes | 56
|
No | No | ? |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | No | 57 | Yes | 56
|
No | ? | 7.0 |
cardNumber
|
No | 57 | Yes | 56
|
No | ? | 7.0 |
cardholderName
|
No | 57 | Yes | 56
|
No | ? | 7.0 |
cardSecurityCode
|
No | 57 | Yes | 56
|
No | ? | 7.0 |
expiryMonth
|
No | 57 | Yes | 56
|
No | ? | 7.0 |
expiryYear
|
No | 57 | Yes | 56
|
No | ? | 7.0 |
billingAddress
|
No | 57 | Yes | 56
|
No | ? | 7.0 |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/BasicCardResponse