Helpers
Configuration, display, validation, and currency helper functions exported by @flopay/shared.
configureFlopay
Configure the FloPay SDK globally. Call once at app startup to set the environment.
| Parameter | Type | Required | Description |
|---|---|---|---|
config.environment | 'staging' | 'production' | Yes | The environment to use. |
resolveBillingApiUrl
Resolves the billing API URL from available configuration.
| Parameter | Type | Required | Description |
|---|---|---|---|
billingApiUrl | string | No | Explicit override (highest priority). |
Resolution priority:
- Explicit
billingApiUrlparameter configureFlopay()global environment- Fallback: staging
buildCheckoutDisplayData
Builds display data from a CheckoutSession for rendering an order summary. Matches the display logic used in checkout/CheckoutModal.
| Parameter | Type | Required | Description |
|---|---|---|---|
session | CheckoutSession | Yes | The checkout session (from useCheckout() or PaymentAPI). |
Returns: CheckoutDisplayData with computed items, totals, discounts, and currency.
How prices are resolved
totalAmountis the original/base priceoverrideAmount(when > 0) is the discounted priceoverrideAmountof0ornullfalls through tototalAmount(e.g., a $1 trial withoverrideAmount: 0shows $1, not $0)
All amounts are in major currency units (dollars, not cents).
CheckoutDisplayData
| Field | Type | Description |
|---|---|---|
items | DisplayLineItem[] | Individual items/subscriptions with names, prices, and quantities. |
currency | string | ISO 4217 currency code (uppercase). |
total | number | Total amount due after discounts (major units). |
originalTotal | number | Sum of original prices before discounts (major units). |
totalSave | number | Total savings (originalTotal - total), clamped to >= 0. |
discountPercent | number | Discount percentage (0--100). |
DisplayLineItem
| Field | Type | Description |
|---|---|---|
name | string | Item or subscription name. |
quantity | number | Quantity purchased. |
price | number | Price per unit after discount (major units). |
originalPrice | number | Original price per unit before discount (major units). |
Example: order summary
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.
| Parameter | Type | Required | Description |
|---|---|---|---|
countryCode | string | Yes | ISO 3166-1 alpha-2 country code (case-insensitive). |
Returns: CurrencyInfo -- the currency info for the given country, or DEFAULT_CURRENCY (USD) if not found.
AVS Helpers
resolveAVSConfig
Normalizes the enableAVS prop value into a concrete AVSFieldConfig object (or null when AVS is disabled).
| Input | Output |
|---|---|
false / undefined | null |
true | { country: true, postal_code: true } (the legacy default) |
AVSFieldConfig | The same object, returned as-is |
isAVSFieldVisible
Returns true if a given field should be visible for the given country, given a per-field rule.
Country codes are normalized (case- and whitespace-insensitive), so ['us', ' ca '] matches 'US', 'CA', 'us', etc.
isAVSEnabled
Returns true if any AVS field is meaningfully configured. Use this to derive the avsCheck analytics boolean from a raw enableAVS prop value.
getStateOptions
Returns the list of states/provinces for a country, or null for countries that should fall back to a free-text input.
StateOption is { code: string; name: string }. Currently returns US_STATES for 'US' and CA_PROVINCES for 'CA'; all other country codes return null.
getStateLabel
Returns the user-facing label for the state/province field based on country.
| Country | Label |
|---|---|
US | 'State' |
CA | 'Province' |
GB | 'County' |
AU | 'State / Territory' |
| All others | 'State / Province / Region' |
getStateFromPostalCode
Resolves a state / province code from a postal code for the given country.
| Country | Resolution |
|---|---|
US | 5-digit ZIP → 2-letter USPS state code via the 3-digit SCF prefix table. Handles ZIP+4 format. |
CA | A1A 1A1 → 2-letter ISO 3166-2:CA province code via the FSA first letter. X resolves to NT (shared with NU). |
| Others | Returns null |
Used by SplitCardForm to populate billing_details.address.state when the form collects address_line_1 and postal_code but hides the state input. See the AVS guide for the trigger condition.
getPostalCodeLabel
Returns the user-facing label for the postal code field based on country.
| Country | Label |
|---|---|
US | 'ZIP Code' |
GB, AU, NZ | 'Postcode' |
CA | 'Postal Code' |
IE | 'Eircode' |
| All others | 'Postal Code' |
getCountryByCode
Look up a country option by ISO 3166-1 alpha-2 code. Returns undefined if not found.
isValidPublishableKey
Returns true if the string matches the format of a Stripe publishable key.
| Parameter | Type | Required | Description |
|---|---|---|---|
key | string | Yes | The key to validate. |
Returns: boolean -- true if the key matches /^pk_(test|live)_[A-Za-z0-9]+$/.
isValidSecretKey
Returns true if the string matches the format of a Stripe secret key.
| Parameter | Type | Required | Description |
|---|---|---|---|
key | string | Yes | The key to validate. |
Returns: boolean -- true if the key matches /^sk_(test|live)_[A-Za-z0-9]+$/.