FloPay Class
The main FloPay SDK instance providing element management, payment confirmation, and session retrieval.
FloPay
The main FloPay SDK instance. Created via loadFloPay(publishableKey).
class FloPay {
constructor(provider: PaymentProviderAdapter, config: FloPayConfig)
}elements
Creates a new FloPayElements group for mounting payment fields. Only one elements group is active at a time -- creating a new one destroys the previous group.
elements(options?: ElementOptions): FloPayElements| Parameter | Type | Required | Description |
|---|---|---|---|
options | ElementOptions | No | Configuration for the elements group. |
Returns: FloPayElements
const elements = flopay.elements({
appearance: { theme: 'flat' },
clientSecret: 'pi_xxx_secret_xxx',
});submitElements
Submit elements for validation.
async submitElements(): Promise<{ error?: FloPayError }>Returns: Promise<{ error?: FloPayError }> -- an object with an optional error if validation fails.
createPaymentMethod
Create a payment method from the current elements (tokenize card fields).
async createPaymentMethod(): Promise<CreatePaymentMethodResult>Returns: Promise<CreatePaymentMethodResult> -- contains paymentMethodId on success or error on failure.
const { paymentMethodId, error } = await flopay.createPaymentMethod();
if (error) {
console.error(error.message);
} else {
console.log('Payment method:', paymentMethodId);
}confirmCardPayment
Confirm a card payment with a known client secret and payment method ID.
async confirmCardPayment(params: ConfirmCardPaymentParams): Promise<ConfirmCardPaymentResult>| Parameter | Type | Required | Description |
|---|---|---|---|
params.clientSecret | string | Yes | Client secret of the PaymentIntent. |
params.paymentMethodId | string | Yes | Payment method ID to confirm with. |
Returns: Promise<ConfirmCardPaymentResult>
const result = await flopay.confirmCardPayment({
clientSecret: 'pi_xxx_secret_xxx',
paymentMethodId: 'pm_xxx',
});confirmPayPalPayment
Confirm a PayPal payment: creates a PaymentMethod, creates a PaymentIntent via the billing API, and confirms with redirect if needed.
async confirmPayPalPayment(params: {
billingApiUrl: string;
sessionId: string;
email: string;
returnUrl: string;
}): Promise<ConfirmCardPaymentResult>| Parameter | Type | Required | Description |
|---|---|---|---|
params.billingApiUrl | string | Yes | Billing API base URL. |
params.sessionId | string | Yes | Checkout session ID. |
params.email | string | Yes | User's email. |
params.returnUrl | string | Yes | URL to return to after PayPal redirect. |
Returns: Promise<ConfirmCardPaymentResult>
resumePayPalPayment
Resume a PayPal payment after redirect return. Checks URL parameters for payment_intent and redirect_status.
async resumePayPalPayment(): Promise<ConfirmCardPaymentResult | null>Returns: Promise<ConfirmCardPaymentResult | null> -- null if no PayPal parameters are found in the URL.
confirmPayment
Confirms a payment using the mounted elements.
async confirmPayment(params: ConfirmPaymentParams): Promise<PaymentResult>| Parameter | Type | Required | Description |
|---|---|---|---|
params.clientSecret | string | Yes | Client secret of the PaymentIntent or SetupIntent. |
params.returnUrl | string | No | Redirect URL after 3-D Secure or wallet authentication. |
Returns: Promise<PaymentResult>
const result = await flopay.confirmPayment({
clientSecret: 'pi_xxx_secret_xxx',
returnUrl: 'https://example.com/return',
});retrieveSession
Retrieves a checkout session by ID via the billing API. Returns the normalized CheckoutSession.
async retrieveSession(
sessionId: string,
billingApiUrl?: string
): Promise<CheckoutSession>| Parameter | Type | Required | Description |
|---|---|---|---|
sessionId | string | Yes | Checkout session UUID. |
billingApiUrl | string | No | Billing API URL. Falls back to the URL set in loadFloPay(). |
Returns: Promise<CheckoutSession>
Throws: FloPayError if sessionId or billingApiUrl is missing, or if the session is not found.
const session = await flopay.retrieveSession('uuid-xxx');
console.log(session.amount, session.currency);retrieveUnifiedSession
Retrieves and normalizes a checkout session, including provider-specific data (Stripe clientSecret/publishableKey, Chargebee site, etc.).
async retrieveUnifiedSession(
sessionId: string,
billingApiUrl?: string
): Promise<NormalizedCheckoutSession>| Parameter | Type | Required | Description |
|---|---|---|---|
sessionId | string | Yes | Checkout session UUID. |
billingApiUrl | string | No | Billing API URL. Falls back to the URL set in loadFloPay(). |
Returns: Promise<NormalizedCheckoutSession>
getRawProvider
Returns the raw underlying provider instance (e.g. the Stripe object). Used internally by components that need direct provider access.
getRawProvider(): unknownReturns: unknown -- the raw provider instance.
destroy
Tears down the SDK instance, destroys all elements, and releases resources.
destroy(): void