Web/API/BasicCardRequest

From Get docs

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


The BasicCardRequest dictionary is a JavaScript object-structure that can be used in the Payment Request API. The properties of BasicCardRequest are defined in the Basic Card Payment spec).

Properties

BasicCardRequest.supportedNetworks Optional Secure context
An optional array of DOMStrings representing the card networks that the retailer supports (e.g. "amex", "mastercard"); see Card network identifiers for a complete list. If the property is missing, it implies that all networks are supported.

Obsolete properties

These properties have been removed from the Payment Method: Basic Card specification and should no longer be used.

BasicCardRequest.supportedTypes ' Optional Secure context
This obsolete property was used to provide an optional array of DOMStrings representing the card types that the retailer supports (e.g. credit, debit, prepaid). If the property is missing, it implies that all the card types are supported. Instead of using this property, it is up to the server to check support for the card given the information coded into the account number.

Card network identifiers

The W3C maintains an official list of approved card network identifier strings, which may be used in the supportedNetworks list. Those are:

  • amex
  • cartebancaire
  • diners
  • discover
  • jcb
  • mastercard
  • mir
  • unionpay
  • visa


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 that describes what data is needed to fullfil the payment (e.g., a shipping address).

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']
  }
}];

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
Basic Card PaymentThe definition of 'BasicCardRequest' in that specification. Working Draft Initial definition.

Browser compatibility

Update compatibility data on 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
BasicCardRequest Chrome

No support No

Edge

No support ≤18 — 79

Firefox Full support 56

Notes' Disabled'

Full support 56

Notes' Disabled'

Notes' 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 support No

Opera

No support No

Safari

?

WebView Android

No support No

Chrome Android

Full support 57

Firefox Android Full support 56

Notes' Disabled'

Full support 56

Notes' Disabled'

Notes' 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 support No

Safari iOS

?

Samsung Internet Android

Full support 7.0

supportedNetworks Chrome

No support No

Edge

No support ≤18 — 79

Firefox Full support 56

Notes' Disabled'

Full support 56

Notes' Disabled'

Notes' 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 support No

Opera

No support No

Safari

?

WebView Android

No support No

Chrome Android

Full support 57

Firefox Android Full support 56

Notes' Disabled'

Full support 56

Notes' Disabled'

Notes' 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 support No

Safari iOS

?

Samsung Internet Android

Full support 7.0

supportedTypes

Deprecated'

Chrome

No support No

Edge

No support ≤18 — 79

Firefox No support 56 — 65

Notes' Disabled'

No support 56 — 65

Notes' Disabled'

Notes' It's now up to the payment processor to determine the type of card used, when necessary. Available only in nightly builds. Disabled' From version 56 until version 65 (exclusive): 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 support No

Opera

No support No

Safari

?

WebView Android

No support No

Chrome Android

Full support 57

Firefox Android No support 56 — 65

Notes' Disabled'

No support 56 — 65

Notes' Disabled'

Notes' It's now up to the payment processor to determine the type of card used, when necessary. Available only in nightly builds. Disabled' From version 56 until version 65 (exclusive): 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 support No

Safari iOS

?

Samsung Internet Android

Full support 7.0

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Deprecated. Not for use in new websites.'
Deprecated. Not for use in new websites.
See implementation notes.'
See implementation notes.
User must explicitly enable this feature.'
User must explicitly enable this feature.