Restricting wallet cards by issuing country (Google Pay)

You can use an optional allowedCountries array on the data you pass in to filter cards.

Google Pay's wallet module accepts an optional allowedCountries array on the payment data you pass in. The array filters the wallet sheet to only offer cards issued in those countries listed in Google's allowedIssuerCountryCodes in CardParameters

Rules

  • Optional. Omit the array or pass undefined and the payment request is unchanged.
  • Non-empty array of ISO 3166-1 alpha-2 codes when supplied. [ ], ['GBR'], '['G'], or non-strings reject.
  • Case-insensitive - 'gb' is normalised to 'GB' before reaching the wallet.
  • Filters by card issuing country, not billing or shipping address.
  • The wallet enforces it: a customer with no eligible card can't complete that wallet flow so ensure you offer a fallback payment method.

Using the array

Add allowedCountries to the object passed to startPaymentJourney:

function getPaymentData() {
  return {
    totalPriceStatus: 'FINAL',
    totalPrice: '1.00',
    currencyCode: 'GBP',
    countryCode: 'GB',
    allowedCountries: ['GB', 'IE'] // remove for no restriction
  };
}

googlePayClient.startPaymentJourney(getPaymentData())
  .then(function (response) {
    // BAU
  })
  .catch(function (err) {
    if (err.code === 'CLIENT_GOOGLE_PAY_INVALID_ALLOWED_COUNTRIES') {
      // the SDK throws a ComcardeError if allowedCountries fails validation
    }
  });

Under the hood the SDK clones your payment data into transactionInfo (stripping allowedCountries) and sets allowedIssuerCountryCodes on the CARD payment method's parameters — your other allowedPaymentMethods are untouched.

Errors

All errors are ComcardeError with type: MERCHANT — they indicate that your integration is wrong, not a customer problem. They are promise rejections, so handle them in .catch.

CodeTrigger
CLIENT_APPLE_PAY_INVALID_ALLOWED_COUNTRIESallowedCountries isn't a non-empty array of 2-letter strings
CLIENT_APPLE_PAY_ALLOWED_COUNTRIES_UNSUPPORTED_VERSIONallowedCountries supplied with sdkVersion < 3
CLIENT_GOOGLE_PAY_INVALID_ALLOWED_COUNTRIESSame invalid-shape check as Apple Pay

Quick reference

allowedCountries: ['GB', 'IE']  // valid
allowedCountries: ['gb', 'ie']  // valid — normalised to uppercase
allowedCountries: []            // rejects — must be non-empty
allowedCountries: 'GB,IE'       // rejects — must be an array
// property omitted entirely    // valid — no restriction

Did this page help you?