English | 简体中文
A simple, easy-to-use, framework-agnostic payment panel component.
npm install pypjsOr use other package managers (pnpm, yarn, etc.)
ES Module:
import pypjs from 'pypjs'Script Tag:
<script src="./dist/index.js"></script>// Open/close panel
pypjs.open(99.99) // Supports number or string
pypjs.close()
// Set amount
pypjs.setAmount(199.0) // Supports number or stringpypjs.setPaymentMethods([
{ id: 1, name: 'WeChat Pay', desc: 'Recommended', icon: '💳' },
{ id: 2, name: 'Alipay', desc: 'Secure & Convenient', icon: '💰' }
], {
titleField: 'name',
subtitleField: 'desc',
iconField: 'icon',
valueField: 'id'
})
// Two-level grouping
pypjs.setPaymentMethods([
{
name: 'Online Payment',
children: [
{ id: 1, name: 'WeChat Pay', icon: '💳' },
{ id: 2, name: 'Alipay', icon: '💰' }
]
}
], { titleField: 'name', valueField: 'id' })pypjs.setConfig({
allowSwipeToClose: false,
closeOnOverlayClick: false,
enablePassword: true,
passwordLength: 6,
language: 'zh',
themeMode: 'auto',
keyboardMapping: ['!', '@', '#', '$', '%', '^', '&', '*', '(', ')'],
theme: {
primaryColor: '#ff4d4f',
panelBgLight: '#ffffff',
panelBgDark: '#2d2d2d'
}
})pypjs.on('confirm', (e) => {
const { method, amount, password } = e.detail
console.log('Payment:', method, amount, password)
})
pypjs.on('close', () => {
console.log('Panel closed')
})- i18n: Supports zh, en, ja, ru with partial override
- Theme:
light|dark|auto(follow system), customizable colors and gradients - Keyboard Mapping: Map digits 0-9 to custom characters (keyboard displays digits, input uses mapped values)
- Icon Display:
always|never|auto, supports image URL, emoji, or default SVG - Amount Alignment:
left|center|rightwith custom fonts
pypjs.open(amount?: number | string)- Open payment panel, optionally with amountpypjs.close()- Close payment panelpypjs.setAmount(amount: number | string)- Set payment amount
pypjs.setPaymentMethods(methods?, fieldMapping?)- Set payment methods listmethods: Payment methods array (optional)fieldMapping: Optional field mapping configurationtitleField: Title field name (default 'title' or 'name')subtitleField: Subtitle field name (default 'subtitle' or 'desc')iconField: Icon field name (default 'icon')valueField: Value field name (default 'value' or 'id')
pypjs.getSelectedMethod()- Get currently selected payment method
pypjs.setConfig(config: PaymentPanelConfig)- Configure all options
Config Options:
allowSwipeToClose?: boolean- Allow swipe to close (default true)closeOnOverlayClick?: boolean- Close on overlay click (default true)enablePassword?: boolean- Enable password input (default false)passwordLength?: number- Password length (default 6, range 4-12)headerTitle?: string- Header title (optional, defaults to i18n)amountLabel?: string- Amount label (optional, defaults to i18n)iconDisplay?: 'always' | 'never' | 'auto'- Icon display mode (default 'always')closeThreshold?: number- Close distance threshold in pixels (default 100)closeThresholdPercent?: number- Close distance threshold percentage 0-1 (default 0.3)velocityThreshold?: number- Velocity threshold pixels/ms (default 0.5)allowConfirmWithoutMethods?: boolean- Allow confirm without payment methods (default true)hidePaymentMethods?: boolean- Hide payment methods section (default false)amountAlign?: 'left' | 'center' | 'right'- Amount alignment (default 'left')amountFont?: string- Amount font familytextFont?: string- Text font familylanguage?: 'zh' | 'en' | 'ja' | 'ru'- Language setting (default 'en')i18n?: Partial<I18nTexts>- Custom i18n texts (partial override)themeMode?: 'light' | 'dark' | 'auto'- Theme mode (default 'auto')keyboardMapping?: string[]- Keyboard character mapping, array of 10 strings for digits 0-9theme?: ThemeConfig- Theme configurationprimaryColor?: string- Primary color (default "#238636")primaryHoverColor?: string- Primary hover color (default "#2ea043")overlayColor?: string- Overlay color (default "rgba(0, 0, 0, 0.5)")panelBgLight?: string- Panel background in light mode (default "#ffffff", supports gradients)panelBgDark?: string- Panel background in dark mode (default "#2d2d2d", supports gradients)textPrimaryLight?: string- Primary text color in light mode (default "#24292f")textPrimaryDark?: string- Primary text color in dark mode (default "#e0e0e0")textSecondaryLight?: string- Secondary text color in light mode (default "#57606a")textSecondaryDark?: string- Secondary text color in dark mode (default "#999999")
pypjs.setHeaderTitle(title?: string)- Set header titlepypjs.setAmountLabel(label?: string)- Set amount labelpypjs.setCloseThreshold(threshold: number)- Set close threshold (pixels)pypjs.setCloseThresholdPercent(percent: number)- Set close threshold (percentage 0-1)pypjs.setVelocityThreshold(threshold: number)- Set velocity thresholdpypjs.setCloseOnOverlayClick(close: boolean)- Set close on overlay clickpypjs.setEnablePassword(enable: boolean)- Set enable password inputpypjs.setPasswordLength(length: number)- Set password length (4-12)pypjs.setKeyboardMapping(mapping: string[])- Set keyboard character mappingpypjs.setAllowConfirmWithoutMethods(allow: boolean)- Set allow confirm without methodspypjs.setHidePaymentMethods(hide: boolean)- Set hide payment methodspypjs.setAmountAlign(align: 'left' | 'center' | 'right')- Set amount alignmentpypjs.setAmountFont(font: string)- Set amount fontpypjs.setTextFont(font: string)- Set text fontpypjs.setLanguage(lang: 'zh' | 'en' | 'ja' | 'ru')- Set languagepypjs.setI18n(i18n: Partial<I18nTexts>)- Set custom i18n textspypjs.setThemeMode(mode: 'light' | 'dark' | 'auto')- Set theme modepypjs.setTheme(theme: ThemeConfig)- Set theme configurationpypjs.getTheme()- Get current theme configuration
pypjs.on('confirm', handler)- Listen to payment confirm event- Event detail:
{ method, amount, password, methodData }
- Event detail:
pypjs.on('close', handler)- Listen to panel close eventpypjs.off(event, handler)- Remove event listenerpypjs.removeAllListeners(event?)- Remove all event listeners
Modern browsers (Chrome, Firefox, Safari, Edge) and mobile browsers.
MIT