Skip to main content

Overview

The guide below will help you configure co-badged cards with Headless Checkout.
We’ve introduced a new way to integrate our Checkout for Web.Learn how to build a fully customizable checkout using modular components in our documentation here: Primer Checkout (Web Components)

Example projects

Feel free to use these example projects to get started quicker:

Pre-requisites

This guide assumes that you have already integrated a card form with Headless Checkout. Make sure to follow the “Get Started with Headless Checkout” first.

Step 1. Set the list of supported card networks in the client session

When creating a client session, it is recommended to pass the list of the card networks supported for this particular session. This ensures that the customer is not asked to choose a card network that you do not accept. The card network should be sorted in order of preference. This enables us to identify the default card network to consider if the user enters a co-badged card.
JSON
// POST /client-session
{
	"paymentMethod": {
		"orderedAllowedCardNetworks": ["VISA", "CARTES_BANCAIRES", "MASTERCARD"]
	}
}
With the example above:
  • If the user enters a “Visa & Cartes Bancaires” card, the default network will be Visa
  • If the user enters a “Mastercard & Cartes Bancaires” card, the default network will be Cartes Bancaires
Learn more about orderedAllowedCardNetworks in the API Reference.

Step 2. Detect the card networks

On Web, the card form is implemented using PCI-compliant hosted fields that can be put anywhere on the web page.When the customer enters their card number, Headless Checkout retrieves the list of card networks available on the card. The list of card networks is passed to the developers through a callback called onBinDataAvailable.
The previous onCardNetworksChange callback remains available for backwards compatibility, but we recommend using onBinDataAvailable for new integrations as it provides richer data including issuer information and card attributes.
Typescript
const cardManager = await headless.createPaymentMethodManager('PAYMENT_CARD',
{
  onBinDataAvailable({
    status,
    preferred,
    alternatives
  }) {
    // Handle the detected card networks
  }
})
This callback returns the following data:
  • status
    The status of the BIN data retrieval.
    • partial if the card networks come from the SDK, usually by leveraging the first few digits, or if Primer’s server fails to be reached.
    • complete if the card networks come from Primer’s server with full BIN data.
  • alternatives
    The list of all the detected card networks, including the ones that are not allowed.
  • preferred
    The recommended card network based on orderedAllowedCardNetworks. Can be undefined if the user entered a card that is not allowed.
To get the list of selectable networks for co-badged cards, use:
Typescript
const selectableNetworks = [preferred, ...alternatives].filter(n => n?.allowed)
The card networks returned by onBinDataAvailable are objects that contain the network id, its display name, a flag allowed stating if the card network is in orderedAllowedCardNetworks, and additional issuer information when available.
Learn more about onBinDataAvailable in the API reference.

Less than 8 digits

If the user enters less than 8 digits, Headless Checkout cannot detect co-badged cards. Instead, Headless Checkout tries to detect major card networks using data available locally.In this case:
  • status is set to partial
  • preferred contains the card network you should present to the user
  • alternatives contains all the detected card networks
  • Selectable networks will have only one allowed network (no co-badge selection needed)

8 digits or more

If the user enters 8 digits or more, Headless Checkout attempts to make a request to Primer to retrieve the list of card networks available on the card using our BIN data.In this case:
  • status is set to complete
  • For co-badged cards where multiple networks are allowed, you should present the selectable networks to the user
If Headless Checkout fails to contact Primer, Headless Checkout falls back to a local detection (similar to when less than 8 digits are entered). In this case, status is set to partial.
Let’s say orderedAllowedCardNetworks is ["CARTES_BANCAIRES", "VISA", "MASTERCARD"]If the user enters a card that is co-badged Visa and Cartes Bancaires:
  • alternatives contains CARTES_BANCAIRES and VISA
  • preferred is CARTES_BANCAIRES
  • Selectable networks: CARTES_BANCAIRES and VISA (both allowed)
If the user enters a card that is only Visa:
  • alternatives contains only VISA
  • preferred is VISA
  • Selectable networks: only VISA (no co-badge selection needed)
If the user enters an Amex card (not allowed for this session):
  • alternatives contains only AMEX
  • preferred is undefined
  • Selectable networks: empty (card not allowed)

Example

Typescript
const cardManager = await headless.createPaymentMethodManager("PAYMENT_CARD", {
  onBinDataAvailable({
    status,
    preferred,
    alternatives,
  }) {
    if (status === "partial") {
      // BIN data may be incomplete - could be less than 8 digits or network failure
      console.info("Using local card network detection");
    }

    // Get networks that the user can select from
    const selectableNetworks = [preferred, ...alternatives].filter(n => n?.allowed);

    if (selectableNetworks.length > 1) {
      // Co-badged card detected - ask the user to select a card network
      // You can use `preferred` to pre-select the recommended network
      return showCardNetworkSelect(selectableNetworks);
    }

    // Show the detected card network (or preferred if available)
    showAllowedCardNetwork(preferred || alternatives[0]);
  },
});

Step 3. Present the list of card networks and handle the selection

It is now your responsibility to present the list of card networks to the customer and enable them to choose the network they want to pay with.To support you, Headless Checkout exposes the logos and human readable names of each card network via the AssetsManager.
Typescript
// After headless checkout is started
const assetsManager = headless.createAssetsManager();

const { cardUrl } = await assetsManager.getCardNetworkAsset('CARTES_BANCAIRES')
Learn more about getCardNetworkAsset in the API Reference.

Step 4. Create a payment with the selected card network

When the user clicks on “Pay”, call the submit function with the selected card network to let us know which card network the customer chose.
Typescript
cardManager.submit({
  cardNetwork: "CARTES_BANCAIRES"
});
If cardNetwork is not present, Primer follows the order of preference given by the option orderedAllowedCardNetworks passed in the client session API.

Step 5. (Optional) Show the list of the supported card networks

We highly recommend you to present the list of allowed card networks close to the card form.You can retrieve orderedAllowedCardNetworks on the Web SDK by listening to onClientSessionUpdate. After that, you can use
Typescript
const primer = await Primer.createHeadless(clientToken, {
  // Other options and callbacks
  onClientSessionUpdate({ paymentMethod: { orderedAllowedCardNetworks } }) {
    showCardNetworks(orderedAllowedCardNetworks)
  },
})
Learn more about onClientSessionUpdate in the API Reference.

Notes

Slow and unreliable internet connection

When the customer’s network connection is slow or unreliable, it is possible that the customer finishes entering their card details before Universal Checkout retrieves the card networks. In order to keep the friction low, it is important to note that Universal Checkout does not block the creation of a payment while the card networks are being retrieved or if the card networks could not be retrieved at all. This means that, if a co-badged card is entered, the customer is not guaranteed to be presented a card choice before they submit their card details.

Selected card network on the payment method data

In the case of a card payment, you can get the selected network by looking at paymentMethodData.network.
We recommend against using paymentMethodData.binData.network as it only contains the international card network.