Skip to main content

Overview

Manages authentication and creates payout elements. The PayoutsSession handles token management, element creation, and provides convenience methods for showing elements in modals.

Examples

Basic usage

const session = whopElements.createPayoutsSession({
  token: async () => {
    const response = await fetch("/api/token");
    const data = await response.json();
    return data.token;
  },
  companyId: "your-company-id",
  redirectUrl: "https://yourapp.com/callback",
});

session.on("ready", () => {
  console.log("Session is ready");
});

Creating elements

const balanceElement = session.createElement("balance-element", {});
balanceElement.mount("#balance-container");

const withdrawButton = session.createElement("withdraw-button-element", {
  onWithdraw: () => console.log("Withdrawal initiated"),
});
withdrawButton.mount("#withdraw-button");

Using modal methods

// With options object
session.showWithdrawModal({
  onWithdraw: () => console.log("Withdrawal submitted"),
  onClose: () => console.log("Modal closed"),
});

// With callback for modal reference
session.showWithdrawModal((modal) => ({
  onWithdraw: () => {
    console.log("Withdrawal submitted");
    modal.close();
  },
  onClose: () => modal.close(),
}));

Options

PropertyTypeRequiredDefaultDescription
tokenstring | Promise<string | null> | GetToken | nullYes-The token to use for the session. If a function is provided, it will be called and awaited to get the token. When a function is provided, the token will be refreshed automatically before it expires. if a string is provided, it will be used as the token and not refreshed automatically. However you can update the token at runtime by calling ‘updateOptions’ with a new token.
currencystring | undefinedNo”USD”The currency to use in the Elements
companyIdstringYes-The company ID to use in the Elements
redirectUrlstringYes-URL to redirect to after identity verification is completed. This must be an absolute URL (e.g., “https://yourapp.com/callback”). Localhost URLs will not work - use ngrok for local development.

Events

Events emitted by the PayoutsSession. Listen to these events using the on() method.

optionsUpdated

Emitted when the session options are updated via updateOptions(). Callback signature: (options: ExpandedPayoutsSessionOptions) => void

tokenRefreshed

Emitted when the authentication token is refreshed. Callback signature: (token: string) => void

tokenRefreshError

Emitted when token refresh fails. Callback signature: (error: unknown) => void

error

Emitted when an error occurs during session operation. Callback signature: (error: unknown) => void

ready

Emitted when the session is ready and authenticated. Callback signature: (void) => void

Methods

createElement(type, options)

Create a new element instance.
ParameterTypeDescription
typeT | { type: T; }The element type (e.g., “balance-element”, “withdraw-button-element”)
optionsPayoutsSessionElements[T][0]Element-specific configuration options
Returns: PayoutsSessionElements[T][1]
const element = session.createElement("balance-element", {
  onReady: () => console.log("Element ready"),
});
element.mount("#container");

updateOptions(options)

Update the session options after initialization. Changes will be propagated to all active elements.
ParameterTypeDescription
optionsPartial<PayoutsSessionOptions>Partial options object with the values to update

destroy()

Destroy the session and clean up all mounted elements. Call this when you no longer need the session to free up resources.

showWithdrawModal(options, force)

Show the withdraw element in a modal overlay.
ParameterTypeDescription
optionsWithdrawElementOptions | ((modal: ModalContainer) => WithdrawElementOptions)Element options or a callback that receives the modal container
forceForce | undefined-
Returns: Force extends true ? ModalContainer : ModalContainer | undefined

showAddPayoutMethodModal(options, force)

Show the add payout method element in a modal overlay.
ParameterTypeDescription
optionsAddPayoutMethodElementOptions | ((modal: ModalContainer) => AddPayoutMethodElementOptions)Element options or a callback that receives the modal container
forceForce | undefined-
Returns: Force extends true ? ModalContainer : ModalContainer | undefined

showAutomaticWithdrawModal(options, force)

Show the automatic withdraw settings element in a modal overlay.
ParameterTypeDescription
optionsAutomaticWithdrawElementOptions | ((modal: ModalContainer) => AutomaticWithdrawElementOptions)Element options or a callback that receives the modal container
forceForce | undefined-
Returns: Force extends true ? ModalContainer : ModalContainer | undefined

showVerifyModal(options, force)

Show the identity verification element in a modal overlay.
ParameterTypeDescription
optionsVerifyElementOptions | ((modal: ModalContainer) => VerifyElementOptions)Element options or a callback that receives the modal container
forceForce | undefined-
Returns: Force extends true ? ModalContainer : ModalContainer | undefined

showWithdrawalBreakdownModal(options, force)

Show the withdrawal breakdown element in a modal overlay.
ParameterTypeDescription
optionsWithdrawalBreakdownElementOptions | ((modal: ModalContainer) => WithdrawalBreakdownElementOptions)Element options or a callback that receives the modal container
forceForce | undefined-
Returns: Force extends true ? ModalContainer : ModalContainer | undefined

showChangeAccountCountryModal(options, force)

Show the change account country element in a modal overlay.
ParameterTypeDescription
optionsChangeAccountCountryElementOptions | ((modal: ModalContainer) => ChangeAccountCountryElementOptions)Element options or a callback that receives the modal container
forceForce | undefined-
Returns: Force extends true ? ModalContainer : ModalContainer | undefined

showResetAccountModal(options, force)

Show the reset account element in a modal overlay.
ParameterTypeDescription
optionsResetAccountElementOptions | ((modal: ModalContainer) => ResetAccountElementOptions)Element options or a callback that receives the modal container
forceForce | undefined-
Returns: Force extends true ? ModalContainer : ModalContainer | undefined

showTotalBalanceBreakdownModal(options, force)

Show the total balance breakdown element in a modal overlay.
ParameterTypeDescription
optionsTotalBalanceBreakdownElementOptions | ((modal: ModalContainer) => TotalBalanceBreakdownElementOptions)Element options or a callback that receives the modal container
forceForce | undefined-
Returns: Force extends true ? ModalContainer : ModalContainer | undefined

showRegularReserveBalanceBreakdownModal(options, force)

Show the regular reserve balance breakdown element in a modal overlay.
ParameterTypeDescription
optionsRegularReserveBalanceBreakdownElementOptions | ((modal: ModalContainer) => RegularReserveBalanceBreakdownElementOptions)Element options or a callback that receives the modal container
forceForce | undefined-
Returns: Force extends true ? ModalContainer : ModalContainer | undefined

showBnplReserveBalanceBreakdownModal(options, force)

Show the BNPL reserve balance breakdown element in a modal overlay.
ParameterTypeDescription
optionsBnplReserveBalanceBreakdownElementOptions | ((modal: ModalContainer) => BnplReserveBalanceBreakdownElementOptions)Element options or a callback that receives the modal container
forceForce | undefined-
Returns: Force extends true ? ModalContainer : ModalContainer | undefined

showGenerateWithdrawalReceiptModal(options, force)

Show the generate withdrawal receipt element in a modal overlay.
ParameterTypeDescription
optionsGenerateWithdrawalReceiptElementOptions | ((modal: ModalContainer) => GenerateWithdrawalReceiptElementOptions)Element options or a callback that receives the modal container
forceForce | undefined-
Returns: Force extends true ? ModalContainer : ModalContainer | undefined