Types
TypeScript type definitions for the FunnelFox Payments Web SDK
The FunnelFox Payments Web SDK ships with TypeScript type definitions for all methods, options, and objects. They catch errors early and give you autocompletion in your code editor.
Import types from @funnelfox/billing, or from @funnelfox/billing/types
if you only need the types.
Imports
Section titled “Imports”These names are available as named imports:
- Methods:
configure,createCheckout,createClientSession,getAvailablePaymentMethods. - Namespace:
Billing(also the default export). - Enum:
PaymentMethod. - Constants:
EVENTS,CHECKOUT_STATES,ERROR_CODES,DEFAULTS,SDK_VERSION. - Error classes:
FunnefoxSDKError,APIError,NetworkError,PrimerError,CheckoutError,ValidationError,ConfigurationError.
Main types
Section titled “Main types”| Type | Describes |
|---|---|
CreateCheckoutOptions |
Options for createCheckout() |
CheckoutInstance |
The checkout object createCheckout() returns |
CheckoutState |
A checkout state |
CheckoutStatus |
The result of getStatus() |
PaymentResult |
Data of the success event |
InitMethodOptions |
Options for Billing.initMethod(), including callbacks |
PaymentMethodInterface |
The object Billing.initMethod() returns |
PaymentMethod |
Enum: PAYMENT_CARD, PAYPAL, GOOGLE_PAY, APPLE_PAY |
StripeCardFormOptions |
Options for Billing.stripe.createCardForm() |
StripeCardForm |
The { submit() } handle the card form returns |
StripeWalletOptions |
Options for Billing.stripe.purchaseWallet() |
CreateClientSessionOptions |
Options for createClientSession() |
ClientSessionData |
The session createClientSession() returns |
TaxInfo |
Data passed to onTaxChange |
TaxBehavior |
'inclusive' or 'exclusive' |
TaxBreakdownEntry |
One jurisdiction in TaxInfo.taxBreakdown |
PaymentFailure |
An Error with decline code fields |
DeclineCodeSource |
'primer', 'stripe', 'adyen', or another provider name |
ApplePayButtonType |
An Apple Pay button type |
BillingCardOptions |
The card option: cardholder name and email fields |
SDKConfig |
Options for configure() |
APIConfig |
The apiConfig option: baseUrl and region |
TypeScript notes
Section titled “TypeScript notes”orgIdincreateCheckout(): The options type requiresorgId, even after you callconfigure().- Error classes: The type definitions declare them as interfaces, so
instanceofdoesn’t compile. Narrow errors byerror.nameinstead. Learn more in Error handling. - Events beyond the core four:
on()accepts'success','error','status-change', and'destroy'as strings. For other events, such aspurchase-failure, pass theEVENTSconstant and cast the handler argument. Learn more about purchase-failure. - Tax callbacks:
onTaxChangereceives a typedTaxInfo. Use the callbacks rather than events for tax updates.
Example
Section titled “Example”import { configure, createCheckout, PaymentMethod } from '@funnelfox/billing';import type { CheckoutInstance, PaymentResult, TaxInfo,} from '@funnelfox/billing';
configure({ orgId: 'your-org-id',});
const checkout: CheckoutInstance = await createCheckout({ orgId: 'your-org-id', priceId: 'price_123', customer: { externalId: 'user_456', email: 'user@example.com', countryCode: 'US', }, container: '#checkout', clientMetadata: { source: 'web', campaign: 'summer-sale', }, paymentMethodOrder: [ PaymentMethod.PAYPAL, PaymentMethod.PAYMENT_CARD, PaymentMethod.GOOGLE_PAY, PaymentMethod.APPLE_PAY, ], onTaxChange: (info: TaxInfo) => { console.log('Total:', info.amountTotal, info.currency); },});
checkout.on('success', (result: PaymentResult) => { console.log('Order:', result.orderId); console.log('Status:', result.status);});