UNPKG

@payos-inc/payos-js

Version:

PayOS JavaScript SDK for browser-based checkout and wallet onboarding

99 lines (98 loc) 2.87 kB
/** * PayOS.js - Client-side JavaScript SDK for PayOS * Combines checkout and wallet onboarding functionality */ import { CheckoutClient, PayOSConfig } from './checkout/CheckoutClient'; import { WalletOnboardClient } from './wallet-onboard/WalletOnboardClient'; export * from './types'; interface SimpleWalletOptions { token: string; mode?: "popup" | "redirect"; environment?: "sandbox" | "production"; merchantName?: string; returnUrl?: string; onSuccess?: (walletUserId?: string) => void; onClose?: () => void; onError?: (error: Error) => void; } export interface PayOSWalletOnboardInstance { close: () => void; } /** * Main PayOS.js class * Provides checkout and wallet onboarding functionality */ export declare class PayOS { private _checkout; private _walletOnboard; constructor(config?: PayOSConfig); /** * Checkout module for payment authentication * Opens hosted checkout UI with a token from your backend * * @example * ```javascript * // Get token from your backend * const { token } = await fetch('/api/create-checkout-token', {...}); * * // Open checkout * payos.checkout.open({ * token: token, * mode: 'iframe', * onComplete: (result) => console.log('Payment complete', result) * }); * ``` */ get checkout(): CheckoutClient; /** * Wallet Onboard module for adding payment methods * Opens hosted wallet onboard UI with a token from your backend * * @example * ```javascript * // Get token from your backend * const { token } = await fetch('/api/create-onboard-token', {...}); * * // Open wallet onboard * payos.walletOnboard.open({ * token: token, * mode: 'iframe', * onComplete: (result) => console.log('Card added', result) * }); * ``` */ get walletOnboard(): WalletOnboardClient; /** * Initialize PayOS Wallet Onboard * * @example * ```javascript * // Simple: init with just token * payos.walletOnboard.init('token'); * * // With options * payos.walletOnboard.init({ token: 'token', mode: 'popup' }); * ``` */ static walletOnboard: { init: typeof initWalletOnboard; }; /** * Static method to check if PayOS.js is loaded */ static isLoaded(): boolean; /** * Version of the SDK */ static get version(): string; } /** * Initialize PayOS Wallet Onboard using popup or redirect mode * Supports multiple usage patterns: * * 1. Simple: init('token') * 2. With options: init({ token: 'token', ...options }) */ declare function initWalletOnboard(tokenOrOptions: string | SimpleWalletOptions): PayOSWalletOnboardInstance; export { CheckoutClient, WalletOnboardClient, PayOSConfig }; export default PayOS;