Concepts
Understand FloPay's architecture, adapter pattern, and package roles.
Concepts
Monorepo Structure
Package Roles
@flopay/shared
The foundation package. Contains TypeScript types (FloPayConfig, PaymentResult, TokenizedBody, etc.), the FloPayError class, theme constants (DEFAULT_APPEARANCE, FLAT_APPEARANCE, NIGHT_APPEARANCE), and element type definitions. All other packages depend on it.
@flopay/js
The core browser engine. Provides:
loadFloPay(publishableKey)-- initializes the payment provider adapter and returns aFloPayinstance (cached per key)FloPay-- the main SDK class with methods for creating elements, submitting, tokenizing, and confirming paymentsFloPayElements-- manages a group of payment input elements (mount, unmount, destroy)createCheckoutSession-- creates a session via the billing API and redirects to the hosted checkout pageStripeAdapter-- the adapter that translates FloPay calls into Stripe.js calls
@flopay/react
React bindings built on top of @flopay/js:
FloPayProvider-- context provider that initializes elements and makes the FloPay instance available via hooksCheckoutForm-- drop-in form using Stripe's combinedPaymentElementSplitCardForm-- split card fields (CardNumber + Expiry + CVC) with optional PayPal buttonuseFloPay()/useElements()-- hooks for accessing the SDK and elements from custom components
@flopay/node
Server-side SDK wrapping Stripe's Node library:
flopay.checkout.sessions-- create, retrieve, expire sessions; list line itemsflopay.webhooks-- verify and construct webhook eventsflopay.customers-- create, retrieve, update customers
Adapter Pattern
FloPay uses an adapter pattern to abstract the payment provider:
The PaymentProviderAdapter interface defines methods like initialize, createElement, submitElements, createPaymentMethod, confirmCardPayment, and confirmPayment. Currently only StripeAdapter implements this interface. Adding a new provider means implementing the adapter without changing consumer code.
Provider / Elements / Hooks Pattern
React integration follows a layered pattern:
- Provider --
FloPayProvideraccepts aFloPayinstance (or promise) and creates an elements group - Elements -- Components like
PaymentElement,CardNumberElementrender provider-specific input fields - Hooks --
useFloPay()returns theFloPayinstance;useElements()returns the currentFloPayElementsgroup
The paymentMethodCreation: 'manual' option is needed for card-based flows where you tokenize explicitly. PayPal requires a separate Elements instance without this option -- SplitCardForm handles this automatically.