FloPay
API Reference@flopay/shared

Helpers

Validation and currency helper functions exported by @flopay/shared.

getCurrencyByCountry

Look up currency information by ISO 3166-1 alpha-2 country code. Falls back to USD when the country is not in the map.

function getCurrencyByCountry(countryCode: string): CurrencyInfo
ParameterTypeRequiredDescription
countryCodestringYesISO 3166-1 alpha-2 country code (case-insensitive).

Returns: CurrencyInfo -- the currency info for the given country, or DEFAULT_CURRENCY (USD) if not found.

import { getCurrencyByCountry } from '@flopay/shared';
 
getCurrencyByCountry('DE');
// { currency: 'EUR', symbol: '\u20ac', country: 'Germany', countryCode: 'DE', tax: 1 }
 
getCurrencyByCountry('US');
// { currency: 'USD', symbol: '$', country: 'United States', countryCode: 'US', tax: 0 }
 
getCurrencyByCountry('XX');
// Falls back to DEFAULT_CURRENCY (USD)

isValidPublishableKey

Returns true if the string matches the format of a Stripe publishable key.

function isValidPublishableKey(key: string): boolean
ParameterTypeRequiredDescription
keystringYesThe key to validate.

Returns: boolean -- true if the key matches /^pk_(test|live)_[A-Za-z0-9]+$/.

import { isValidPublishableKey } from '@flopay/shared';
 
isValidPublishableKey('pk_test_abc123');  // true
isValidPublishableKey('pk_live_XYZ789'); // true
isValidPublishableKey('sk_test_abc123'); // false
isValidPublishableKey('invalid');        // false

isValidSecretKey

Returns true if the string matches the format of a Stripe secret key.

function isValidSecretKey(key: string): boolean
ParameterTypeRequiredDescription
keystringYesThe key to validate.

Returns: boolean -- true if the key matches /^sk_(test|live)_[A-Za-z0-9]+$/.

import { isValidSecretKey } from '@flopay/shared';
 
isValidSecretKey('sk_test_abc123');  // true
isValidSecretKey('sk_live_XYZ789'); // true
isValidSecretKey('pk_test_abc123'); // false

On this page