@paypercut/checkout-js 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +5 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +5 -19
- package/dist/index.mjs.map +1 -1
- package/dist/paypercut-checkout.iife.min.js +1 -1
- package/dist/paypercut-checkout.iife.min.js.map +1 -1
- package/package.json +1 -1
- package/dist/paypercut-checkout-dev.iife.min.js +0 -2
- package/dist/paypercut-checkout-dev.iife.min.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -83,26 +83,16 @@ class Emitter {
|
|
|
83
83
|
/**
|
|
84
84
|
* Production configuration (for merchants)
|
|
85
85
|
*/
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
*/
|
|
89
|
-
const internalConfig = {
|
|
90
|
-
version: "1.0.0",
|
|
86
|
+
const productionConfig = {
|
|
87
|
+
version: "1.0.1",
|
|
91
88
|
defaultCheckoutOrigin: 'https://buy.paypercut.io',
|
|
92
89
|
allowedOrigins: [
|
|
93
|
-
'https://buy.paypercut.io'
|
|
94
|
-
|
|
95
|
-
'http://localhost:3001',
|
|
96
|
-
'http://127.0.0.1:3000',
|
|
97
|
-
'http://127.0.0.1:3001'
|
|
98
|
-
],
|
|
99
|
-
allowOriginOverride: true // ← Team CAN override for testing
|
|
100
|
-
};
|
|
90
|
+
'https://buy.paypercut.io'
|
|
91
|
+
]};
|
|
101
92
|
/**
|
|
102
93
|
* Active configuration (selected at build time)
|
|
103
94
|
*/
|
|
104
|
-
const config =
|
|
105
|
-
;
|
|
95
|
+
const config = productionConfig;
|
|
106
96
|
/**
|
|
107
97
|
* Helper to check if origin is allowed
|
|
108
98
|
*/
|
|
@@ -113,10 +103,6 @@ function isOriginAllowed(origin) {
|
|
|
113
103
|
* Get the checkout origin (with optional override for internal builds)
|
|
114
104
|
*/
|
|
115
105
|
function getCheckoutOrigin(override) {
|
|
116
|
-
// Only allow override in internal builds
|
|
117
|
-
if (override && config.allowOriginOverride) {
|
|
118
|
-
return override;
|
|
119
|
-
}
|
|
120
106
|
return config.defaultCheckoutOrigin;
|
|
121
107
|
}
|
|
122
108
|
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/utils/emitter.ts","../src/config.ts","../src/types/locales.ts","../src/types/checkout.ts","../src/index.ts"],"sourcesContent":["/**\n * Simple event emitter for handling checkout events\n * Supports subscribing, unsubscribing, and emitting events\n */\nexport class Emitter<T extends string = string> {\n private handlers = new Map<T, Set<Function>>();\n\n /**\n * Subscribe to an event\n * @param event - Event name to listen to\n * @param handler - Callback function to execute when event is emitted\n * @returns Unsubscribe function\n */\n on(event: T, handler: Function): () => void {\n if (!this.handlers.has(event)) {\n this.handlers.set(event, new Set());\n }\n this.handlers.get(event)!.add(handler);\n\n // Return unsubscribe function\n return () => this.off(event, handler);\n }\n\n /**\n * Subscribe to an event that auto-unsubscribes after first emission\n *\n * Common use case: waiting for 'loaded' event or handling first 'success'.\n * Without this helper, developers would need to manually unsubscribe inside\n * their handler, which is error-prone and leads to memory leaks if forgotten.\n *\n * @param event - Event name to listen to\n * @param handler - Callback function to execute when event is emitted\n * @returns Unsubscribe function\n */\n once(event: T, handler: Function): () => void {\n const wrappedHandler = (...args: any[]) => {\n handler(...args);\n this.off(event, wrappedHandler);\n };\n return this.on(event, wrappedHandler);\n }\n\n /**\n * Unsubscribe from an event\n * @param event - Event name to stop listening to\n * @param handler - Callback function to remove\n */\n off(event: T, handler: Function): void {\n this.handlers.get(event)?.delete(handler);\n }\n\n /**\n * Emit an event with optional arguments\n * @param event - Event name to emit\n * @param args - Arguments to pass to event handlers\n */\n emit(event: T, ...args: any[]): void {\n this.handlers.get(event)?.forEach(h => {\n try {\n h(...args);\n } catch (err) {\n console.error(`[Emitter] Error in ${event} handler:`, err);\n }\n });\n }\n\n /**\n * Clear all event handlers\n */\n clear(): void {\n this.handlers.clear();\n }\n}\n\n","/**\n * Build-time configuration\n * \n * This file is processed at build time with different values for:\n * - Production build (for merchants)\n * - Internal build (for team development)\n */\n\n/**\n * Build mode - replaced at build time\n */\ndeclare const __BUILD_MODE__: 'production' | 'internal';\n\n/**\n * SDK version - replaced at build time\n */\ndeclare const __VERSION__: string;\n\n/**\n * Configuration interface\n */\nexport interface BuildConfig {\n /** SDK version */\n version: string;\n \n /** Build mode */\n mode: 'production' | 'internal';\n \n /** Default checkout origin (production URL) */\n defaultCheckoutOrigin: string;\n \n /** Allowed origins for postMessage validation */\n allowedOrigins: string[];\n \n /** Whether hostedCheckoutUrl override is allowed */\n allowOriginOverride: boolean;\n}\n\n/**\n * Production configuration (for merchants)\n */\nconst productionConfig: BuildConfig = {\n version: __VERSION__,\n mode: 'production',\n defaultCheckoutOrigin: 'https://buy.paypercut.io',\n allowedOrigins: [\n 'https://buy.paypercut.io'\n ],\n allowOriginOverride: false // ← Merchants CANNOT override\n};\n\n/**\n * Internal configuration (for team development)\n */\nconst internalConfig: BuildConfig = {\n version: __VERSION__,\n mode: 'internal',\n defaultCheckoutOrigin: 'https://buy.paypercut.io',\n allowedOrigins: [\n 'https://buy.paypercut.io',\n 'http://localhost:3000',\n 'http://localhost:3001',\n 'http://127.0.0.1:3000',\n 'http://127.0.0.1:3001'\n ],\n allowOriginOverride: true // ← Team CAN override for testing\n};\n\n/**\n * Active configuration (selected at build time)\n */\nexport const config: BuildConfig = __BUILD_MODE__ === 'internal' \n ? internalConfig \n : productionConfig;\n\n/**\n * Helper to check if origin is allowed\n */\nexport function isOriginAllowed(origin: string): boolean {\n return config.allowedOrigins.includes(origin);\n}\n\n/**\n * Get the checkout origin (with optional override for internal builds)\n */\nexport function getCheckoutOrigin(override?: string): string {\n // Only allow override in internal builds\n if (override && config.allowOriginOverride) {\n return override;\n }\n \n return config.defaultCheckoutOrigin;\n}\n\n","/**\n * Supported locales for Paypercut Checkout\n * \n * @remarks\n * Single source of truth for all supported locale codes.\n * \n * Supported languages:\n * - Bulgarian: 'bg', 'bg-BG'\n * - English: 'en', 'en-GB'\n * - Greek: 'el', 'el-GR'\n * - Romanian: 'ro', 'ro-RO'\n * - Croatian: 'hr', 'hr-HR'\n * - Polish: 'pl', 'pl-PL'\n * - Czech: 'cs', 'cs-CZ'\n * - Slovenian: 'sl', 'sl-SI'\n * - Slovak: 'sk', 'sk-SK'\n * \n * @example\n * ```typescript\n * const checkout = PaypercutCheckout({\n * locale: 'bg' // or 'bg-BG', 'en', 'en-GB', etc.\n * });\n * ```\n */\nexport const LOCALES = [\n 'bg', 'bg-BG',\n 'en', 'en-GB',\n 'el', 'el-GR',\n 'ro', 'ro-RO',\n 'hr', 'hr-HR',\n 'pl', 'pl-PL',\n 'cs', 'cs-CZ',\n 'sl', 'sl-SI',\n 'sk', 'sk-SK',\n] as const;\n\n/**\n * Locale type - union of all supported locale codes plus 'auto'\n * @example\n * ```typescript\n * const locale: Locale = 'bg';\n * const autoLocale: Locale = 'auto';\n * ```\n */\nexport type Locale = typeof LOCALES[number] | 'auto';\n\n/**\n * Fast runtime check using Set for O(1) lookup\n * @internal\n */\nconst LOCALE_SET: ReadonlySet<string> = new Set(LOCALES);\n\n/**\n * Normalize and validate locale\n * \n * @param locale - Locale code to normalize\n * @returns Normalized locale code or 'en' as fallback\n * \n * @remarks\n * - 'auto' or empty → 'en'\n * - Unsupported locale → 'en' with console warning\n * - Supported locale → original value\n * \n * @example\n * ```typescript\n * normalizeLocale('auto') // → 'en'\n * normalizeLocale('bg') // → 'bg'\n * normalizeLocale('de') // → 'en' (with warning)\n * ```\n */\nexport function normalizeLocale(locale: string | Locale): typeof LOCALES[number] | 'en' {\n if (!locale || locale === 'auto') return 'en';\n if (LOCALE_SET.has(locale)) return locale as typeof LOCALES[number];\n console.warn(`[PaypercutCheckout] Locale \"${locale}\" is not supported. Falling back to \"en\".`);\n return 'en';\n}\n\n","import { Locale } from './locales';\n\n/**\n * UI mode for checkout\n */\nexport enum UIMode {\n /** Custom UI mode - merchant provides their own submit button */\n CUSTOM = 'custom',\n /** Embedded mode - checkout embedded in merchant page */\n EMBEDDED = 'embedded',\n /** Hosted mode - full-page checkout experience */\n HOSTED = 'hosted',\n}\n\n/**\n * Type guard for UIMode\n */\nexport function isValidUIMode(value: string): value is UIMode {\n return Object.values(UIMode).includes(value as UIMode);\n}\n\n/**\n * Payment method types\n */\nexport enum PaymentMethod {\n /** Card payment (credit/debit) */\n CARD = 'card',\n}\n\n/**\n * Type guard for PaymentMethod\n */\nexport function isValidPaymentMethod(value: string): value is PaymentMethod {\n return Object.values(PaymentMethod).includes(value as PaymentMethod);\n}\n\n/**\n * Wallet options for digital wallets\n */\nexport enum WalletOption {\n /** Apple Pay */\n APPLE_PAY = 'apple_pay',\n /** Google Pay */\n GOOGLE_PAY = 'google_pay',\n}\n\n/**\n * Type guard for WalletOption\n */\nexport function isValidWalletOption(value: string): value is WalletOption {\n return Object.values(WalletOption).includes(value as WalletOption);\n}\n\n/**\n * Validate payment methods array\n */\nexport function validatePaymentMethods(methods: string[]): PaymentMethod[] {\n const validated: PaymentMethod[] = [];\n \n for (const method of methods) {\n if (isValidPaymentMethod(method)) {\n validated.push(method as PaymentMethod);\n } else {\n console.warn(`[PaypercutCheckout] Invalid payment method: \"${method}\". Skipping.`);\n }\n }\n \n // Default to card if no valid methods\n if (validated.length === 0) {\n console.warn('[PaypercutCheckout] No valid payment methods provided. Defaulting to \"card\".');\n validated.push(PaymentMethod.CARD);\n }\n \n return validated;\n}\n\n/**\n * Validate wallet options array\n */\nexport function validateWalletOptions(options: string[]): WalletOption[] {\n const validated: WalletOption[] = [];\n \n for (const option of options) {\n if (isValidWalletOption(option)) {\n validated.push(option as WalletOption);\n } else {\n console.warn(`[PaypercutCheckout] Invalid wallet option: \"${option}\". Skipping.`);\n }\n }\n \n return validated;\n}\n\n/**\n * Validate UI mode\n */\nexport function validateUIMode(mode: string | undefined): UIMode | undefined {\n if (!mode) {\n return undefined;\n }\n \n if (isValidUIMode(mode)) {\n return mode as UIMode;\n }\n \n console.warn(`[PaypercutCheckout] Invalid ui_mode: \"${mode}\". Valid options: ${Object.values(UIMode).join(', ')}`);\n return undefined;\n}\n\n/**\n * Configuration options for PaypercutCheckout\n */\nexport interface PaypercutCheckoutOptions {\n /** Checkout session identifier (e.g., 'CHK_12345') */\n id: string;\n\n /** CSS selector or HTMLElement where iframe mounts (required) */\n containerId: string | HTMLElement;\n\n /**\n * Optional: Custom hosted checkout URL (only available in internal builds)\n * Production builds will ignore this option for security\n */\n hostedCheckoutUrl?: string;\n\n /**\n * Optional: Locale for checkout UI\n * @default 'en'\n */\n locale?: Locale | string;\n\n /**\n * Optional: UI mode for checkout\n */\n ui_mode?: UIMode | `${UIMode}`;\n\n /**\n * Optional: Payment methods to enable\n * @default ['card']\n */\n payment_methods?: (PaymentMethod | `${PaymentMethod}`)[];\n\n /**\n * Optional: Digital wallet options\n * Can include both or just one\n */\n wallet_options?: (WalletOption | `${WalletOption}`)[];\n\n /**\n * Optional: Show only the payment form without header/footer\n * @default false\n */\n form_only?: boolean;\n}\n\n/**\n * Event names that can be emitted by the checkout\n */\nexport type EventName =\n | 'loaded' // iframe finished loading\n | 'success' // payment successful\n | 'error'; // payment or system error\n\n/**\n * Checkout instance interface\n */\nexport interface CheckoutInstance {\n /** Mount and render the iframe into the container */\n render(): void;\n\n /** Submit payment - sends message to hosted checkout to confirm payment */\n submit(): void;\n\n /** Destroy instance and cleanup all listeners */\n destroy(): void;\n\n /** Subscribe to events. Returns unsubscribe function */\n on(event: EventName, handler: (...args: any[]) => void): () => void;\n\n /** Subscribe to event that auto-unsubscribes after first emission */\n once(event: EventName, handler: (...args: any[]) => void): () => void;\n\n /** Unsubscribe from events */\n off(event: EventName, handler: (...args: any[]) => void): void;\n\n /** Check if checkout is currently mounted */\n isMounted(): boolean;\n}\n\n/**\n * PaypercutCheckout static interface (callable and constructable)\n */\nexport interface PaypercutCheckoutStatic {\n /** Callable factory function */\n (options: PaypercutCheckoutOptions): CheckoutInstance;\n\n /** Constructor support */\n new (options: PaypercutCheckoutOptions): CheckoutInstance;\n\n /** SDK version */\n version: string;\n}\n\n","import { Emitter } from './utils/emitter';\nimport { config, isOriginAllowed, getCheckoutOrigin } from './config';\n\nimport {\n PaypercutCheckoutOptions,\n CheckoutInstance,\n PaypercutCheckoutStatic,\n EventName,\n validatePaymentMethods,\n validateWalletOptions,\n validateUIMode,\n} from './types';\nimport {normalizeLocale} from \"./types\";\n\n// Re-export types and enums for consumers\nexport type {\n PaypercutCheckoutOptions,\n CheckoutInstance,\n PaypercutCheckoutStatic,\n EventName,\n};\n\nexport {\n UIMode,\n PaymentMethod,\n WalletOption,\n} from './types/checkout';\n\nexport type { Locale } from './types/locales';\nexport { LOCALES } from './types/locales';\n\n/**\n * Internal implementation of CheckoutInstance\n */\nclass CheckoutImpl implements CheckoutInstance {\n private emitter = new Emitter<EventName>();\n private mounted = false;\n private destroyed = false;\n private iframe: HTMLIFrameElement | null = null;\n private messageHandler: (evt: MessageEvent) => void;\n\n constructor(private options: PaypercutCheckoutOptions) {\n // Bind message handler\n this.messageHandler = this.onMessage.bind(this);\n window.addEventListener('message', this.messageHandler);\n }\n\n /**\n * Build the iframe source URL with query parameters\n */\n private buildSrc(): string {\n const baseUrl = getCheckoutOrigin(this.options.hostedCheckoutUrl);\n const url = new URL(`/c/${this.options.id}`, baseUrl);\n\n // Add locale parameter\n if (this.options.locale) {\n const normalizedLocale = normalizeLocale(this.options.locale);\n url.searchParams.set('locale', normalizedLocale);\n }\n\n // Add ui_mode parameter\n if (this.options.ui_mode) {\n const validatedUIMode = validateUIMode(this.options.ui_mode);\n if (validatedUIMode) {\n url.searchParams.set('ui_mode', validatedUIMode);\n }\n }\n\n // Add payment_methods parameters (repeated for each method)\n if (this.options.payment_methods && this.options.payment_methods.length > 0) {\n const validatedMethods = validatePaymentMethods(this.options.payment_methods as string[]);\n validatedMethods.forEach(method => {\n url.searchParams.append('payment_methods', method);\n });\n }\n\n // Add wallet_options parameters (repeated for each wallet)\n if (this.options.wallet_options && this.options.wallet_options.length > 0) {\n const validatedWallets = validateWalletOptions(this.options.wallet_options as string[]);\n validatedWallets.forEach(wallet => {\n url.searchParams.append('wallet_options', wallet);\n });\n }\n\n console.log('this.options', this.options);\n\n if (this.options.form_only !== undefined) {\n url.searchParams.set('form_only', String(this.options.form_only));\n }\n\n return url.toString();\n }\n\n /**\n * Get the container element from selector or HTMLElement\n */\n private getContainer(): HTMLElement {\n const container = typeof this.options.containerId === 'string'\n ? document.querySelector(this.options.containerId)\n : this.options.containerId;\n\n if (!container) {\n throw new Error(`Container not found: ${this.options.containerId}`);\n }\n\n return container as HTMLElement;\n }\n\n /**\n * Handle incoming postMessage events from iframe\n */\n private onMessage(evt: MessageEvent): void {\n // Validate origin against allowed origins (build-time whitelist)\n if (!isOriginAllowed(evt.origin)) {\n console.warn('[PaypercutCheckout] Rejected message from unauthorized origin:', evt.origin, 'Allowed:', config.allowedOrigins);\n return;\n }\n\n // Validate structure\n const data = evt.data;\n if (!data || typeof data !== 'object' || !('type' in data)) {\n return;\n }\n\n // Filter messages by checkout session ID to prevent cross-instance message handling\n // This ensures each checkout instance only processes its own messages\n if (data.checkoutId && data.checkoutId !== this.options.id) {\n return; // Message is for a different checkout instance\n }\n\n // Handle specific events\n switch (data.type) {\n case 'CHECKOUT_LOADED':\n this.emitter.emit('loaded');\n break;\n case 'CHECKOUT_SUCCESS':\n this.emitter.emit('success');\n break;\n case 'CHECKOUT_ERROR':\n this.emitter.emit('error');\n break;\n }\n }\n\n /**\n * Render the checkout iframe into the container\n */\n render(): void {\n if (this.mounted) {\n console.warn('[PaypercutCheckout] Already mounted');\n return;\n }\n\n try {\n const container = this.getContainer();\n\n // Create iframe\n this.iframe = document.createElement('iframe');\n this.iframe.id = 'paypercut-checkout-iframe';\n this.iframe.src = this.buildSrc();\n this.iframe.allow = 'payment *; clipboard-write';\n this.iframe.setAttribute('frameborder', '0');\n\n // Apply default styles - just construct URL and assign to iframe\n Object.assign(this.iframe.style, {\n width: '100%',\n height: '100%',\n border: 'none',\n display: 'block'\n });\n\n // Listen for iframe load event (fallback)\n // This ensures 'loaded' event is always emitted even if hosted checkout\n // doesn't send CHECKOUT_LOADED message\n /*this.iframe.addEventListener('load', () => {\n this.emitter.emit('loaded');\n });*/\n\n container.appendChild(this.iframe);\n this.mounted = true;\n } catch (err) {\n console.error('[PaypercutCheckout] Failed to render:', err);\n throw err;\n }\n }\n\n /**\n * Submit payment - sends message to hosted checkout to confirm payment\n */\n submit(): void {\n if (!this.mounted) {\n console.warn('[PaypercutCheckout] Cannot submit: checkout not mounted');\n return;\n }\n\n try {\n this.postToIframe({\n type: 'START_PROCESSING',\n checkoutId: this.options.id,\n });\n console.log('[PaypercutCheckout] Submit payment message sent');\n } catch (err) {\n console.error('[PaypercutCheckout] Failed to submit payment:', err);\n throw err;\n }\n }\n\n /**\n * Send message to iframe - used for submit and other commands\n */\n private postToIframe(message: any): void {\n if (!this.iframe?.contentWindow) {\n console.error('[PaypercutCheckout] Cannot post message: iframe not mounted');\n return;\n }\n\n const checkoutOrigin = getCheckoutOrigin(this.options.hostedCheckoutUrl);\n this.iframe.contentWindow.postMessage(message, checkoutOrigin);\n }\n\n /**\n * Destroy the checkout instance and cleanup (idempotent)\n */\n destroy(): void {\n // Early return if already destroyed\n if (this.destroyed) {\n return;\n }\n\n // Remove iframe from DOM\n if (this.iframe) {\n try {\n this.iframe.remove();\n this.iframe = null;\n } catch (err) {\n console.error('[PaypercutCheckout] Error removing iframe:', err);\n }\n }\n\n // Only set mounted = false after successful DOM removal\n this.mounted = false;\n this.destroyed = true;\n\n // Cleanup event listeners\n window.removeEventListener('message', this.messageHandler);\n this.emitter.clear();\n }\n\n /**\n * Subscribe to an event\n */\n on(event: EventName, handler: (...args: any[]) => void): () => void {\n return this.emitter.on(event, handler);\n }\n\n /**\n * Subscribe to event that auto-unsubscribes after first emission\n */\n once(event: EventName, handler: (...args: any[]) => void): () => void {\n return this.emitter.once(event, handler);\n }\n\n /**\n * Unsubscribe from an event\n */\n off(event: EventName, handler: (...args: any[]) => void): void {\n this.emitter.off(event, handler);\n }\n\n /**\n * Check if checkout is currently mounted\n */\n isMounted(): boolean {\n return this.mounted;\n }\n}\n\n/**\n * Factory function that works both as callable and constructable.\n * Always returns a new CheckoutImpl instance - no prototype manipulation needed.\n */\nconst PaypercutCheckout: PaypercutCheckoutStatic = function (\n this: unknown,\n options: PaypercutCheckoutOptions\n): CheckoutInstance {\n // Always return a new instance, regardless of how it's called\n return new CheckoutImpl(options);\n} as unknown as PaypercutCheckoutStatic;\n\n// Add static version property\n(PaypercutCheckout as any).version = config.version;\n\n// Export as default and named\nexport default PaypercutCheckout;\nexport { PaypercutCheckout };\n\n"],"names":["UIMode","PaymentMethod","WalletOption"],"mappings":";;;;AAAA;;;AAGG;MACU,OAAO,CAAA;AAApB,IAAA,WAAA,GAAA;AACU,QAAA,IAAA,CAAA,QAAQ,GAAG,IAAI,GAAG,EAAoB;IAmEhD;AAjEE;;;;;AAKG;IACH,EAAE,CAAC,KAAQ,EAAE,OAAiB,EAAA;QAC5B,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;YAC7B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,GAAG,EAAE,CAAC;QACrC;AACA,QAAA,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAE,CAAC,GAAG,CAAC,OAAO,CAAC;;QAGtC,OAAO,MAAM,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC;IACvC;AAEA;;;;;;;;;;AAUG;IACH,IAAI,CAAC,KAAQ,EAAE,OAAiB,EAAA;AAC9B,QAAA,MAAM,cAAc,GAAG,CAAC,GAAG,IAAW,KAAI;AACxC,YAAA,OAAO,CAAC,GAAG,IAAI,CAAC;AAChB,YAAA,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,cAAc,CAAC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AAG,KAAK;AACpB,QAAA,IAAI,CAAC,SAAS,GAAG,IAAI;;QAGrB,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,cAAc,CAAC;AAC1D,QAAA,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE;IACtB;AAEA;;AAEG;IACH,EAAE,CAAC,KAAgB,EAAE,OAAiC,EAAA;QACpD,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC;IACxC;AAEA;;AAEG;IACH,IAAI,CAAC,KAAgB,EAAE,OAAiC,EAAA;QACtD,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC;IAC1C;AAEA;;AAEG;IACH,GAAG,CAAC,KAAgB,EAAE,OAAiC,EAAA;QACrD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC;IAClC;AAEA;;AAEG;IACH,SAAS,GAAA;QACP,OAAO,IAAI,CAAC,OAAO;IACrB;AACD;AAED;;;AAGG;AACH,MAAM,iBAAiB,GAA4B,UAEjD,OAAiC,EAAA;;AAGjC,IAAA,OAAO,IAAI,YAAY,CAAC,OAAO,CAAC;AAClC;AAEA;AACC,iBAAyB,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/utils/emitter.ts","../src/config.ts","../src/types/locales.ts","../src/types/checkout.ts","../src/index.ts"],"sourcesContent":["/**\n * Simple event emitter for handling checkout events\n * Supports subscribing, unsubscribing, and emitting events\n */\nexport class Emitter<T extends string = string> {\n private handlers = new Map<T, Set<Function>>();\n\n /**\n * Subscribe to an event\n * @param event - Event name to listen to\n * @param handler - Callback function to execute when event is emitted\n * @returns Unsubscribe function\n */\n on(event: T, handler: Function): () => void {\n if (!this.handlers.has(event)) {\n this.handlers.set(event, new Set());\n }\n this.handlers.get(event)!.add(handler);\n\n // Return unsubscribe function\n return () => this.off(event, handler);\n }\n\n /**\n * Subscribe to an event that auto-unsubscribes after first emission\n *\n * Common use case: waiting for 'loaded' event or handling first 'success'.\n * Without this helper, developers would need to manually unsubscribe inside\n * their handler, which is error-prone and leads to memory leaks if forgotten.\n *\n * @param event - Event name to listen to\n * @param handler - Callback function to execute when event is emitted\n * @returns Unsubscribe function\n */\n once(event: T, handler: Function): () => void {\n const wrappedHandler = (...args: any[]) => {\n handler(...args);\n this.off(event, wrappedHandler);\n };\n return this.on(event, wrappedHandler);\n }\n\n /**\n * Unsubscribe from an event\n * @param event - Event name to stop listening to\n * @param handler - Callback function to remove\n */\n off(event: T, handler: Function): void {\n this.handlers.get(event)?.delete(handler);\n }\n\n /**\n * Emit an event with optional arguments\n * @param event - Event name to emit\n * @param args - Arguments to pass to event handlers\n */\n emit(event: T, ...args: any[]): void {\n this.handlers.get(event)?.forEach(h => {\n try {\n h(...args);\n } catch (err) {\n console.error(`[Emitter] Error in ${event} handler:`, err);\n }\n });\n }\n\n /**\n * Clear all event handlers\n */\n clear(): void {\n this.handlers.clear();\n }\n}\n\n","/**\n * Build-time configuration\n * \n * This file is processed at build time with different values for:\n * - Production build (for merchants)\n * - Internal build (for team development)\n */\n\n/**\n * Build mode - replaced at build time\n */\ndeclare const __BUILD_MODE__: 'production' | 'internal';\n\n/**\n * SDK version - replaced at build time\n */\ndeclare const __VERSION__: string;\n\n/**\n * Configuration interface\n */\nexport interface BuildConfig {\n /** SDK version */\n version: string;\n \n /** Build mode */\n mode: 'production' | 'internal';\n \n /** Default checkout origin (production URL) */\n defaultCheckoutOrigin: string;\n \n /** Allowed origins for postMessage validation */\n allowedOrigins: string[];\n \n /** Whether hostedCheckoutUrl override is allowed */\n allowOriginOverride: boolean;\n}\n\n/**\n * Production configuration (for merchants)\n */\nconst productionConfig: BuildConfig = {\n version: __VERSION__,\n mode: 'production',\n defaultCheckoutOrigin: 'https://buy.paypercut.io',\n allowedOrigins: [\n 'https://buy.paypercut.io'\n ],\n allowOriginOverride: false // ← Merchants CANNOT override\n};\n\n/**\n * Internal configuration (for team development)\n */\nconst internalConfig: BuildConfig = {\n version: __VERSION__,\n mode: 'internal',\n defaultCheckoutOrigin: 'https://buy.paypercut.io',\n allowedOrigins: [\n 'https://buy.paypercut.io',\n 'http://localhost:3000',\n 'http://localhost:3001',\n 'http://127.0.0.1:3000',\n 'http://127.0.0.1:3001'\n ],\n allowOriginOverride: true // ← Team CAN override for testing\n};\n\n/**\n * Active configuration (selected at build time)\n */\nexport const config: BuildConfig = __BUILD_MODE__ === 'internal' \n ? internalConfig \n : productionConfig;\n\n/**\n * Helper to check if origin is allowed\n */\nexport function isOriginAllowed(origin: string): boolean {\n return config.allowedOrigins.includes(origin);\n}\n\n/**\n * Get the checkout origin (with optional override for internal builds)\n */\nexport function getCheckoutOrigin(override?: string): string {\n // Only allow override in internal builds\n if (override && config.allowOriginOverride) {\n return override;\n }\n \n return config.defaultCheckoutOrigin;\n}\n\n","/**\n * Supported locales for Paypercut Checkout\n * \n * @remarks\n * Single source of truth for all supported locale codes.\n * \n * Supported languages:\n * - Bulgarian: 'bg', 'bg-BG'\n * - English: 'en', 'en-GB'\n * - Greek: 'el', 'el-GR'\n * - Romanian: 'ro', 'ro-RO'\n * - Croatian: 'hr', 'hr-HR'\n * - Polish: 'pl', 'pl-PL'\n * - Czech: 'cs', 'cs-CZ'\n * - Slovenian: 'sl', 'sl-SI'\n * - Slovak: 'sk', 'sk-SK'\n * \n * @example\n * ```typescript\n * const checkout = PaypercutCheckout({\n * locale: 'bg' // or 'bg-BG', 'en', 'en-GB', etc.\n * });\n * ```\n */\nexport const LOCALES = [\n 'bg', 'bg-BG',\n 'en', 'en-GB',\n 'el', 'el-GR',\n 'ro', 'ro-RO',\n 'hr', 'hr-HR',\n 'pl', 'pl-PL',\n 'cs', 'cs-CZ',\n 'sl', 'sl-SI',\n 'sk', 'sk-SK',\n] as const;\n\n/**\n * Locale type - union of all supported locale codes plus 'auto'\n * @example\n * ```typescript\n * const locale: Locale = 'bg';\n * const autoLocale: Locale = 'auto';\n * ```\n */\nexport type Locale = typeof LOCALES[number] | 'auto';\n\n/**\n * Fast runtime check using Set for O(1) lookup\n * @internal\n */\nconst LOCALE_SET: ReadonlySet<string> = new Set(LOCALES);\n\n/**\n * Normalize and validate locale\n * \n * @param locale - Locale code to normalize\n * @returns Normalized locale code or 'en' as fallback\n * \n * @remarks\n * - 'auto' or empty → 'en'\n * - Unsupported locale → 'en' with console warning\n * - Supported locale → original value\n * \n * @example\n * ```typescript\n * normalizeLocale('auto') // → 'en'\n * normalizeLocale('bg') // → 'bg'\n * normalizeLocale('de') // → 'en' (with warning)\n * ```\n */\nexport function normalizeLocale(locale: string | Locale): typeof LOCALES[number] | 'en' {\n if (!locale || locale === 'auto') return 'en';\n if (LOCALE_SET.has(locale)) return locale as typeof LOCALES[number];\n console.warn(`[PaypercutCheckout] Locale \"${locale}\" is not supported. Falling back to \"en\".`);\n return 'en';\n}\n\n","import { Locale } from './locales';\n\n/**\n * UI mode for checkout\n */\nexport enum UIMode {\n /** Custom UI mode - merchant provides their own submit button */\n CUSTOM = 'custom',\n /** Embedded mode - checkout embedded in merchant page */\n EMBEDDED = 'embedded',\n /** Hosted mode - full-page checkout experience */\n HOSTED = 'hosted',\n}\n\n/**\n * Type guard for UIMode\n */\nexport function isValidUIMode(value: string): value is UIMode {\n return Object.values(UIMode).includes(value as UIMode);\n}\n\n/**\n * Payment method types\n */\nexport enum PaymentMethod {\n /** Card payment (credit/debit) */\n CARD = 'card',\n}\n\n/**\n * Type guard for PaymentMethod\n */\nexport function isValidPaymentMethod(value: string): value is PaymentMethod {\n return Object.values(PaymentMethod).includes(value as PaymentMethod);\n}\n\n/**\n * Wallet options for digital wallets\n */\nexport enum WalletOption {\n /** Apple Pay */\n APPLE_PAY = 'apple_pay',\n /** Google Pay */\n GOOGLE_PAY = 'google_pay',\n}\n\n/**\n * Type guard for WalletOption\n */\nexport function isValidWalletOption(value: string): value is WalletOption {\n return Object.values(WalletOption).includes(value as WalletOption);\n}\n\n/**\n * Validate payment methods array\n */\nexport function validatePaymentMethods(methods: string[]): PaymentMethod[] {\n const validated: PaymentMethod[] = [];\n \n for (const method of methods) {\n if (isValidPaymentMethod(method)) {\n validated.push(method as PaymentMethod);\n } else {\n console.warn(`[PaypercutCheckout] Invalid payment method: \"${method}\". Skipping.`);\n }\n }\n \n // Default to card if no valid methods\n if (validated.length === 0) {\n console.warn('[PaypercutCheckout] No valid payment methods provided. Defaulting to \"card\".');\n validated.push(PaymentMethod.CARD);\n }\n \n return validated;\n}\n\n/**\n * Validate wallet options array\n */\nexport function validateWalletOptions(options: string[]): WalletOption[] {\n const validated: WalletOption[] = [];\n \n for (const option of options) {\n if (isValidWalletOption(option)) {\n validated.push(option as WalletOption);\n } else {\n console.warn(`[PaypercutCheckout] Invalid wallet option: \"${option}\". Skipping.`);\n }\n }\n \n return validated;\n}\n\n/**\n * Validate UI mode\n */\nexport function validateUIMode(mode: string | undefined): UIMode | undefined {\n if (!mode) {\n return undefined;\n }\n \n if (isValidUIMode(mode)) {\n return mode as UIMode;\n }\n \n console.warn(`[PaypercutCheckout] Invalid ui_mode: \"${mode}\". Valid options: ${Object.values(UIMode).join(', ')}`);\n return undefined;\n}\n\n/**\n * Configuration options for PaypercutCheckout\n */\nexport interface PaypercutCheckoutOptions {\n /** Checkout session identifier (e.g., 'CHK_12345') */\n id: string;\n\n /** CSS selector or HTMLElement where iframe mounts (required) */\n containerId: string | HTMLElement;\n\n /**\n * Optional: Custom hosted checkout URL (only available in internal builds)\n * Production builds will ignore this option for security\n */\n hostedCheckoutUrl?: string;\n\n /**\n * Optional: Locale for checkout UI\n * @default 'en'\n */\n locale?: Locale | string;\n\n /**\n * Optional: UI mode for checkout\n */\n ui_mode?: UIMode | `${UIMode}`;\n\n /**\n * Optional: Payment methods to enable\n * @default ['card']\n */\n payment_methods?: (PaymentMethod | `${PaymentMethod}`)[];\n\n /**\n * Optional: Digital wallet options\n * Can include both or just one\n */\n wallet_options?: (WalletOption | `${WalletOption}`)[];\n\n /**\n * Optional: Show only the payment form without header/footer\n * @default false\n */\n form_only?: boolean;\n}\n\n/**\n * Event names that can be emitted by the checkout\n */\nexport type EventName =\n | 'loaded' // iframe finished loading\n | 'success' // payment successful\n | 'error'; // payment or system error\n\n/**\n * Checkout instance interface\n */\nexport interface CheckoutInstance {\n /** Mount and render the iframe into the container */\n render(): void;\n\n /** Submit payment - sends message to hosted checkout to confirm payment */\n submit(): void;\n\n /** Destroy instance and cleanup all listeners */\n destroy(): void;\n\n /** Subscribe to events. Returns unsubscribe function */\n on(event: EventName, handler: (...args: any[]) => void): () => void;\n\n /** Subscribe to event that auto-unsubscribes after first emission */\n once(event: EventName, handler: (...args: any[]) => void): () => void;\n\n /** Unsubscribe from events */\n off(event: EventName, handler: (...args: any[]) => void): void;\n\n /** Check if checkout is currently mounted */\n isMounted(): boolean;\n}\n\n/**\n * PaypercutCheckout static interface (callable and constructable)\n */\nexport interface PaypercutCheckoutStatic {\n /** Callable factory function */\n (options: PaypercutCheckoutOptions): CheckoutInstance;\n\n /** Constructor support */\n new (options: PaypercutCheckoutOptions): CheckoutInstance;\n\n /** SDK version */\n version: string;\n}\n\n","import { Emitter } from './utils/emitter';\nimport { config, isOriginAllowed, getCheckoutOrigin } from './config';\n\nimport {\n PaypercutCheckoutOptions,\n CheckoutInstance,\n PaypercutCheckoutStatic,\n EventName,\n validatePaymentMethods,\n validateWalletOptions,\n validateUIMode,\n} from './types';\nimport {normalizeLocale} from \"./types\";\n\n// Re-export types and enums for consumers\nexport type {\n PaypercutCheckoutOptions,\n CheckoutInstance,\n PaypercutCheckoutStatic,\n EventName,\n};\n\nexport {\n UIMode,\n PaymentMethod,\n WalletOption,\n} from './types/checkout';\n\nexport type { Locale } from './types/locales';\nexport { LOCALES } from './types/locales';\n\n/**\n * Internal implementation of CheckoutInstance\n */\nclass CheckoutImpl implements CheckoutInstance {\n private emitter = new Emitter<EventName>();\n private mounted = false;\n private destroyed = false;\n private iframe: HTMLIFrameElement | null = null;\n private messageHandler: (evt: MessageEvent) => void;\n\n constructor(private options: PaypercutCheckoutOptions) {\n // Bind message handler\n this.messageHandler = this.onMessage.bind(this);\n window.addEventListener('message', this.messageHandler);\n }\n\n /**\n * Build the iframe source URL with query parameters\n */\n private buildSrc(): string {\n const baseUrl = getCheckoutOrigin(this.options.hostedCheckoutUrl);\n const url = new URL(`/c/${this.options.id}`, baseUrl);\n\n // Add locale parameter\n if (this.options.locale) {\n const normalizedLocale = normalizeLocale(this.options.locale);\n url.searchParams.set('locale', normalizedLocale);\n }\n\n // Add ui_mode parameter\n if (this.options.ui_mode) {\n const validatedUIMode = validateUIMode(this.options.ui_mode);\n if (validatedUIMode) {\n url.searchParams.set('ui_mode', validatedUIMode);\n }\n }\n\n // Add payment_methods parameters (repeated for each method)\n if (this.options.payment_methods && this.options.payment_methods.length > 0) {\n const validatedMethods = validatePaymentMethods(this.options.payment_methods as string[]);\n validatedMethods.forEach(method => {\n url.searchParams.append('payment_methods', method);\n });\n }\n\n // Add wallet_options parameters (repeated for each wallet)\n if (this.options.wallet_options && this.options.wallet_options.length > 0) {\n const validatedWallets = validateWalletOptions(this.options.wallet_options as string[]);\n validatedWallets.forEach(wallet => {\n url.searchParams.append('wallet_options', wallet);\n });\n }\n\n console.log('this.options', this.options);\n\n if (this.options.form_only !== undefined) {\n url.searchParams.set('form_only', String(this.options.form_only));\n }\n\n return url.toString();\n }\n\n /**\n * Get the container element from selector or HTMLElement\n */\n private getContainer(): HTMLElement {\n const container = typeof this.options.containerId === 'string'\n ? document.querySelector(this.options.containerId)\n : this.options.containerId;\n\n if (!container) {\n throw new Error(`Container not found: ${this.options.containerId}`);\n }\n\n return container as HTMLElement;\n }\n\n /**\n * Handle incoming postMessage events from iframe\n */\n private onMessage(evt: MessageEvent): void {\n // Validate origin against allowed origins (build-time whitelist)\n if (!isOriginAllowed(evt.origin)) {\n console.warn('[PaypercutCheckout] Rejected message from unauthorized origin:', evt.origin, 'Allowed:', config.allowedOrigins);\n return;\n }\n\n // Validate structure\n const data = evt.data;\n if (!data || typeof data !== 'object' || !('type' in data)) {\n return;\n }\n\n // Filter messages by checkout session ID to prevent cross-instance message handling\n // This ensures each checkout instance only processes its own messages\n if (data.checkoutId && data.checkoutId !== this.options.id) {\n return; // Message is for a different checkout instance\n }\n\n // Handle specific events\n switch (data.type) {\n case 'CHECKOUT_LOADED':\n this.emitter.emit('loaded');\n break;\n case 'CHECKOUT_SUCCESS':\n this.emitter.emit('success');\n break;\n case 'CHECKOUT_ERROR':\n this.emitter.emit('error');\n break;\n }\n }\n\n /**\n * Render the checkout iframe into the container\n */\n render(): void {\n if (this.mounted) {\n console.warn('[PaypercutCheckout] Already mounted');\n return;\n }\n\n try {\n const container = this.getContainer();\n\n // Create iframe\n this.iframe = document.createElement('iframe');\n this.iframe.id = 'paypercut-checkout-iframe';\n this.iframe.src = this.buildSrc();\n this.iframe.allow = 'payment *; clipboard-write';\n this.iframe.setAttribute('frameborder', '0');\n\n // Apply default styles - just construct URL and assign to iframe\n Object.assign(this.iframe.style, {\n width: '100%',\n height: '100%',\n border: 'none',\n display: 'block'\n });\n\n // Listen for iframe load event (fallback)\n // This ensures 'loaded' event is always emitted even if hosted checkout\n // doesn't send CHECKOUT_LOADED message\n /*this.iframe.addEventListener('load', () => {\n this.emitter.emit('loaded');\n });*/\n\n container.appendChild(this.iframe);\n this.mounted = true;\n } catch (err) {\n console.error('[PaypercutCheckout] Failed to render:', err);\n throw err;\n }\n }\n\n /**\n * Submit payment - sends message to hosted checkout to confirm payment\n */\n submit(): void {\n if (!this.mounted) {\n console.warn('[PaypercutCheckout] Cannot submit: checkout not mounted');\n return;\n }\n\n try {\n this.postToIframe({\n type: 'START_PROCESSING',\n checkoutId: this.options.id,\n });\n console.log('[PaypercutCheckout] Submit payment message sent');\n } catch (err) {\n console.error('[PaypercutCheckout] Failed to submit payment:', err);\n throw err;\n }\n }\n\n /**\n * Send message to iframe - used for submit and other commands\n */\n private postToIframe(message: any): void {\n if (!this.iframe?.contentWindow) {\n console.error('[PaypercutCheckout] Cannot post message: iframe not mounted');\n return;\n }\n\n const checkoutOrigin = getCheckoutOrigin(this.options.hostedCheckoutUrl);\n this.iframe.contentWindow.postMessage(message, checkoutOrigin);\n }\n\n /**\n * Destroy the checkout instance and cleanup (idempotent)\n */\n destroy(): void {\n // Early return if already destroyed\n if (this.destroyed) {\n return;\n }\n\n // Remove iframe from DOM\n if (this.iframe) {\n try {\n this.iframe.remove();\n this.iframe = null;\n } catch (err) {\n console.error('[PaypercutCheckout] Error removing iframe:', err);\n }\n }\n\n // Only set mounted = false after successful DOM removal\n this.mounted = false;\n this.destroyed = true;\n\n // Cleanup event listeners\n window.removeEventListener('message', this.messageHandler);\n this.emitter.clear();\n }\n\n /**\n * Subscribe to an event\n */\n on(event: EventName, handler: (...args: any[]) => void): () => void {\n return this.emitter.on(event, handler);\n }\n\n /**\n * Subscribe to event that auto-unsubscribes after first emission\n */\n once(event: EventName, handler: (...args: any[]) => void): () => void {\n return this.emitter.once(event, handler);\n }\n\n /**\n * Unsubscribe from an event\n */\n off(event: EventName, handler: (...args: any[]) => void): void {\n this.emitter.off(event, handler);\n }\n\n /**\n * Check if checkout is currently mounted\n */\n isMounted(): boolean {\n return this.mounted;\n }\n}\n\n/**\n * Factory function that works both as callable and constructable.\n * Always returns a new CheckoutImpl instance - no prototype manipulation needed.\n */\nconst PaypercutCheckout: PaypercutCheckoutStatic = function (\n this: unknown,\n options: PaypercutCheckoutOptions\n): CheckoutInstance {\n // Always return a new instance, regardless of how it's called\n return new CheckoutImpl(options);\n} as unknown as PaypercutCheckoutStatic;\n\n// Add static version property\n(PaypercutCheckout as any).version = config.version;\n\n// Export as default and named\nexport default PaypercutCheckout;\nexport { PaypercutCheckout };\n\n"],"names":["UIMode","PaymentMethod","WalletOption"],"mappings":";;;;AAAA;;;AAGG;MACU,OAAO,CAAA;AAApB,IAAA,WAAA,GAAA;AACU,QAAA,IAAA,CAAA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EA;AACC,iBAAyB,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO;;;;;;"}
|
package/dist/index.mjs
CHANGED
|
@@ -79,26 +79,16 @@ class Emitter {
|
|
|
79
79
|
/**
|
|
80
80
|
* Production configuration (for merchants)
|
|
81
81
|
*/
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
*/
|
|
85
|
-
const internalConfig = {
|
|
86
|
-
version: "1.0.0",
|
|
82
|
+
const productionConfig = {
|
|
83
|
+
version: "1.0.1",
|
|
87
84
|
defaultCheckoutOrigin: 'https://buy.paypercut.io',
|
|
88
85
|
allowedOrigins: [
|
|
89
|
-
'https://buy.paypercut.io'
|
|
90
|
-
|
|
91
|
-
'http://localhost:3001',
|
|
92
|
-
'http://127.0.0.1:3000',
|
|
93
|
-
'http://127.0.0.1:3001'
|
|
94
|
-
],
|
|
95
|
-
allowOriginOverride: true // ← Team CAN override for testing
|
|
96
|
-
};
|
|
86
|
+
'https://buy.paypercut.io'
|
|
87
|
+
]};
|
|
97
88
|
/**
|
|
98
89
|
* Active configuration (selected at build time)
|
|
99
90
|
*/
|
|
100
|
-
const config =
|
|
101
|
-
;
|
|
91
|
+
const config = productionConfig;
|
|
102
92
|
/**
|
|
103
93
|
* Helper to check if origin is allowed
|
|
104
94
|
*/
|
|
@@ -109,10 +99,6 @@ function isOriginAllowed(origin) {
|
|
|
109
99
|
* Get the checkout origin (with optional override for internal builds)
|
|
110
100
|
*/
|
|
111
101
|
function getCheckoutOrigin(override) {
|
|
112
|
-
// Only allow override in internal builds
|
|
113
|
-
if (override && config.allowOriginOverride) {
|
|
114
|
-
return override;
|
|
115
|
-
}
|
|
116
102
|
return config.defaultCheckoutOrigin;
|
|
117
103
|
}
|
|
118
104
|
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/utils/emitter.ts","../src/config.ts","../src/types/locales.ts","../src/types/checkout.ts","../src/index.ts"],"sourcesContent":["/**\n * Simple event emitter for handling checkout events\n * Supports subscribing, unsubscribing, and emitting events\n */\nexport class Emitter<T extends string = string> {\n private handlers = new Map<T, Set<Function>>();\n\n /**\n * Subscribe to an event\n * @param event - Event name to listen to\n * @param handler - Callback function to execute when event is emitted\n * @returns Unsubscribe function\n */\n on(event: T, handler: Function): () => void {\n if (!this.handlers.has(event)) {\n this.handlers.set(event, new Set());\n }\n this.handlers.get(event)!.add(handler);\n\n // Return unsubscribe function\n return () => this.off(event, handler);\n }\n\n /**\n * Subscribe to an event that auto-unsubscribes after first emission\n *\n * Common use case: waiting for 'loaded' event or handling first 'success'.\n * Without this helper, developers would need to manually unsubscribe inside\n * their handler, which is error-prone and leads to memory leaks if forgotten.\n *\n * @param event - Event name to listen to\n * @param handler - Callback function to execute when event is emitted\n * @returns Unsubscribe function\n */\n once(event: T, handler: Function): () => void {\n const wrappedHandler = (...args: any[]) => {\n handler(...args);\n this.off(event, wrappedHandler);\n };\n return this.on(event, wrappedHandler);\n }\n\n /**\n * Unsubscribe from an event\n * @param event - Event name to stop listening to\n * @param handler - Callback function to remove\n */\n off(event: T, handler: Function): void {\n this.handlers.get(event)?.delete(handler);\n }\n\n /**\n * Emit an event with optional arguments\n * @param event - Event name to emit\n * @param args - Arguments to pass to event handlers\n */\n emit(event: T, ...args: any[]): void {\n this.handlers.get(event)?.forEach(h => {\n try {\n h(...args);\n } catch (err) {\n console.error(`[Emitter] Error in ${event} handler:`, err);\n }\n });\n }\n\n /**\n * Clear all event handlers\n */\n clear(): void {\n this.handlers.clear();\n }\n}\n\n","/**\n * Build-time configuration\n * \n * This file is processed at build time with different values for:\n * - Production build (for merchants)\n * - Internal build (for team development)\n */\n\n/**\n * Build mode - replaced at build time\n */\ndeclare const __BUILD_MODE__: 'production' | 'internal';\n\n/**\n * SDK version - replaced at build time\n */\ndeclare const __VERSION__: string;\n\n/**\n * Configuration interface\n */\nexport interface BuildConfig {\n /** SDK version */\n version: string;\n \n /** Build mode */\n mode: 'production' | 'internal';\n \n /** Default checkout origin (production URL) */\n defaultCheckoutOrigin: string;\n \n /** Allowed origins for postMessage validation */\n allowedOrigins: string[];\n \n /** Whether hostedCheckoutUrl override is allowed */\n allowOriginOverride: boolean;\n}\n\n/**\n * Production configuration (for merchants)\n */\nconst productionConfig: BuildConfig = {\n version: __VERSION__,\n mode: 'production',\n defaultCheckoutOrigin: 'https://buy.paypercut.io',\n allowedOrigins: [\n 'https://buy.paypercut.io'\n ],\n allowOriginOverride: false // ← Merchants CANNOT override\n};\n\n/**\n * Internal configuration (for team development)\n */\nconst internalConfig: BuildConfig = {\n version: __VERSION__,\n mode: 'internal',\n defaultCheckoutOrigin: 'https://buy.paypercut.io',\n allowedOrigins: [\n 'https://buy.paypercut.io',\n 'http://localhost:3000',\n 'http://localhost:3001',\n 'http://127.0.0.1:3000',\n 'http://127.0.0.1:3001'\n ],\n allowOriginOverride: true // ← Team CAN override for testing\n};\n\n/**\n * Active configuration (selected at build time)\n */\nexport const config: BuildConfig = __BUILD_MODE__ === 'internal' \n ? internalConfig \n : productionConfig;\n\n/**\n * Helper to check if origin is allowed\n */\nexport function isOriginAllowed(origin: string): boolean {\n return config.allowedOrigins.includes(origin);\n}\n\n/**\n * Get the checkout origin (with optional override for internal builds)\n */\nexport function getCheckoutOrigin(override?: string): string {\n // Only allow override in internal builds\n if (override && config.allowOriginOverride) {\n return override;\n }\n \n return config.defaultCheckoutOrigin;\n}\n\n","/**\n * Supported locales for Paypercut Checkout\n * \n * @remarks\n * Single source of truth for all supported locale codes.\n * \n * Supported languages:\n * - Bulgarian: 'bg', 'bg-BG'\n * - English: 'en', 'en-GB'\n * - Greek: 'el', 'el-GR'\n * - Romanian: 'ro', 'ro-RO'\n * - Croatian: 'hr', 'hr-HR'\n * - Polish: 'pl', 'pl-PL'\n * - Czech: 'cs', 'cs-CZ'\n * - Slovenian: 'sl', 'sl-SI'\n * - Slovak: 'sk', 'sk-SK'\n * \n * @example\n * ```typescript\n * const checkout = PaypercutCheckout({\n * locale: 'bg' // or 'bg-BG', 'en', 'en-GB', etc.\n * });\n * ```\n */\nexport const LOCALES = [\n 'bg', 'bg-BG',\n 'en', 'en-GB',\n 'el', 'el-GR',\n 'ro', 'ro-RO',\n 'hr', 'hr-HR',\n 'pl', 'pl-PL',\n 'cs', 'cs-CZ',\n 'sl', 'sl-SI',\n 'sk', 'sk-SK',\n] as const;\n\n/**\n * Locale type - union of all supported locale codes plus 'auto'\n * @example\n * ```typescript\n * const locale: Locale = 'bg';\n * const autoLocale: Locale = 'auto';\n * ```\n */\nexport type Locale = typeof LOCALES[number] | 'auto';\n\n/**\n * Fast runtime check using Set for O(1) lookup\n * @internal\n */\nconst LOCALE_SET: ReadonlySet<string> = new Set(LOCALES);\n\n/**\n * Normalize and validate locale\n * \n * @param locale - Locale code to normalize\n * @returns Normalized locale code or 'en' as fallback\n * \n * @remarks\n * - 'auto' or empty → 'en'\n * - Unsupported locale → 'en' with console warning\n * - Supported locale → original value\n * \n * @example\n * ```typescript\n * normalizeLocale('auto') // → 'en'\n * normalizeLocale('bg') // → 'bg'\n * normalizeLocale('de') // → 'en' (with warning)\n * ```\n */\nexport function normalizeLocale(locale: string | Locale): typeof LOCALES[number] | 'en' {\n if (!locale || locale === 'auto') return 'en';\n if (LOCALE_SET.has(locale)) return locale as typeof LOCALES[number];\n console.warn(`[PaypercutCheckout] Locale \"${locale}\" is not supported. Falling back to \"en\".`);\n return 'en';\n}\n\n","import { Locale } from './locales';\n\n/**\n * UI mode for checkout\n */\nexport enum UIMode {\n /** Custom UI mode - merchant provides their own submit button */\n CUSTOM = 'custom',\n /** Embedded mode - checkout embedded in merchant page */\n EMBEDDED = 'embedded',\n /** Hosted mode - full-page checkout experience */\n HOSTED = 'hosted',\n}\n\n/**\n * Type guard for UIMode\n */\nexport function isValidUIMode(value: string): value is UIMode {\n return Object.values(UIMode).includes(value as UIMode);\n}\n\n/**\n * Payment method types\n */\nexport enum PaymentMethod {\n /** Card payment (credit/debit) */\n CARD = 'card',\n}\n\n/**\n * Type guard for PaymentMethod\n */\nexport function isValidPaymentMethod(value: string): value is PaymentMethod {\n return Object.values(PaymentMethod).includes(value as PaymentMethod);\n}\n\n/**\n * Wallet options for digital wallets\n */\nexport enum WalletOption {\n /** Apple Pay */\n APPLE_PAY = 'apple_pay',\n /** Google Pay */\n GOOGLE_PAY = 'google_pay',\n}\n\n/**\n * Type guard for WalletOption\n */\nexport function isValidWalletOption(value: string): value is WalletOption {\n return Object.values(WalletOption).includes(value as WalletOption);\n}\n\n/**\n * Validate payment methods array\n */\nexport function validatePaymentMethods(methods: string[]): PaymentMethod[] {\n const validated: PaymentMethod[] = [];\n \n for (const method of methods) {\n if (isValidPaymentMethod(method)) {\n validated.push(method as PaymentMethod);\n } else {\n console.warn(`[PaypercutCheckout] Invalid payment method: \"${method}\". Skipping.`);\n }\n }\n \n // Default to card if no valid methods\n if (validated.length === 0) {\n console.warn('[PaypercutCheckout] No valid payment methods provided. Defaulting to \"card\".');\n validated.push(PaymentMethod.CARD);\n }\n \n return validated;\n}\n\n/**\n * Validate wallet options array\n */\nexport function validateWalletOptions(options: string[]): WalletOption[] {\n const validated: WalletOption[] = [];\n \n for (const option of options) {\n if (isValidWalletOption(option)) {\n validated.push(option as WalletOption);\n } else {\n console.warn(`[PaypercutCheckout] Invalid wallet option: \"${option}\". Skipping.`);\n }\n }\n \n return validated;\n}\n\n/**\n * Validate UI mode\n */\nexport function validateUIMode(mode: string | undefined): UIMode | undefined {\n if (!mode) {\n return undefined;\n }\n \n if (isValidUIMode(mode)) {\n return mode as UIMode;\n }\n \n console.warn(`[PaypercutCheckout] Invalid ui_mode: \"${mode}\". Valid options: ${Object.values(UIMode).join(', ')}`);\n return undefined;\n}\n\n/**\n * Configuration options for PaypercutCheckout\n */\nexport interface PaypercutCheckoutOptions {\n /** Checkout session identifier (e.g., 'CHK_12345') */\n id: string;\n\n /** CSS selector or HTMLElement where iframe mounts (required) */\n containerId: string | HTMLElement;\n\n /**\n * Optional: Custom hosted checkout URL (only available in internal builds)\n * Production builds will ignore this option for security\n */\n hostedCheckoutUrl?: string;\n\n /**\n * Optional: Locale for checkout UI\n * @default 'en'\n */\n locale?: Locale | string;\n\n /**\n * Optional: UI mode for checkout\n */\n ui_mode?: UIMode | `${UIMode}`;\n\n /**\n * Optional: Payment methods to enable\n * @default ['card']\n */\n payment_methods?: (PaymentMethod | `${PaymentMethod}`)[];\n\n /**\n * Optional: Digital wallet options\n * Can include both or just one\n */\n wallet_options?: (WalletOption | `${WalletOption}`)[];\n\n /**\n * Optional: Show only the payment form without header/footer\n * @default false\n */\n form_only?: boolean;\n}\n\n/**\n * Event names that can be emitted by the checkout\n */\nexport type EventName =\n | 'loaded' // iframe finished loading\n | 'success' // payment successful\n | 'error'; // payment or system error\n\n/**\n * Checkout instance interface\n */\nexport interface CheckoutInstance {\n /** Mount and render the iframe into the container */\n render(): void;\n\n /** Submit payment - sends message to hosted checkout to confirm payment */\n submit(): void;\n\n /** Destroy instance and cleanup all listeners */\n destroy(): void;\n\n /** Subscribe to events. Returns unsubscribe function */\n on(event: EventName, handler: (...args: any[]) => void): () => void;\n\n /** Subscribe to event that auto-unsubscribes after first emission */\n once(event: EventName, handler: (...args: any[]) => void): () => void;\n\n /** Unsubscribe from events */\n off(event: EventName, handler: (...args: any[]) => void): void;\n\n /** Check if checkout is currently mounted */\n isMounted(): boolean;\n}\n\n/**\n * PaypercutCheckout static interface (callable and constructable)\n */\nexport interface PaypercutCheckoutStatic {\n /** Callable factory function */\n (options: PaypercutCheckoutOptions): CheckoutInstance;\n\n /** Constructor support */\n new (options: PaypercutCheckoutOptions): CheckoutInstance;\n\n /** SDK version */\n version: string;\n}\n\n","import { Emitter } from './utils/emitter';\nimport { config, isOriginAllowed, getCheckoutOrigin } from './config';\n\nimport {\n PaypercutCheckoutOptions,\n CheckoutInstance,\n PaypercutCheckoutStatic,\n EventName,\n validatePaymentMethods,\n validateWalletOptions,\n validateUIMode,\n} from './types';\nimport {normalizeLocale} from \"./types\";\n\n// Re-export types and enums for consumers\nexport type {\n PaypercutCheckoutOptions,\n CheckoutInstance,\n PaypercutCheckoutStatic,\n EventName,\n};\n\nexport {\n UIMode,\n PaymentMethod,\n WalletOption,\n} from './types/checkout';\n\nexport type { Locale } from './types/locales';\nexport { LOCALES } from './types/locales';\n\n/**\n * Internal implementation of CheckoutInstance\n */\nclass CheckoutImpl implements CheckoutInstance {\n private emitter = new Emitter<EventName>();\n private mounted = false;\n private destroyed = false;\n private iframe: HTMLIFrameElement | null = null;\n private messageHandler: (evt: MessageEvent) => void;\n\n constructor(private options: PaypercutCheckoutOptions) {\n // Bind message handler\n this.messageHandler = this.onMessage.bind(this);\n window.addEventListener('message', this.messageHandler);\n }\n\n /**\n * Build the iframe source URL with query parameters\n */\n private buildSrc(): string {\n const baseUrl = getCheckoutOrigin(this.options.hostedCheckoutUrl);\n const url = new URL(`/c/${this.options.id}`, baseUrl);\n\n // Add locale parameter\n if (this.options.locale) {\n const normalizedLocale = normalizeLocale(this.options.locale);\n url.searchParams.set('locale', normalizedLocale);\n }\n\n // Add ui_mode parameter\n if (this.options.ui_mode) {\n const validatedUIMode = validateUIMode(this.options.ui_mode);\n if (validatedUIMode) {\n url.searchParams.set('ui_mode', validatedUIMode);\n }\n }\n\n // Add payment_methods parameters (repeated for each method)\n if (this.options.payment_methods && this.options.payment_methods.length > 0) {\n const validatedMethods = validatePaymentMethods(this.options.payment_methods as string[]);\n validatedMethods.forEach(method => {\n url.searchParams.append('payment_methods', method);\n });\n }\n\n // Add wallet_options parameters (repeated for each wallet)\n if (this.options.wallet_options && this.options.wallet_options.length > 0) {\n const validatedWallets = validateWalletOptions(this.options.wallet_options as string[]);\n validatedWallets.forEach(wallet => {\n url.searchParams.append('wallet_options', wallet);\n });\n }\n\n console.log('this.options', this.options);\n\n if (this.options.form_only !== undefined) {\n url.searchParams.set('form_only', String(this.options.form_only));\n }\n\n return url.toString();\n }\n\n /**\n * Get the container element from selector or HTMLElement\n */\n private getContainer(): HTMLElement {\n const container = typeof this.options.containerId === 'string'\n ? document.querySelector(this.options.containerId)\n : this.options.containerId;\n\n if (!container) {\n throw new Error(`Container not found: ${this.options.containerId}`);\n }\n\n return container as HTMLElement;\n }\n\n /**\n * Handle incoming postMessage events from iframe\n */\n private onMessage(evt: MessageEvent): void {\n // Validate origin against allowed origins (build-time whitelist)\n if (!isOriginAllowed(evt.origin)) {\n console.warn('[PaypercutCheckout] Rejected message from unauthorized origin:', evt.origin, 'Allowed:', config.allowedOrigins);\n return;\n }\n\n // Validate structure\n const data = evt.data;\n if (!data || typeof data !== 'object' || !('type' in data)) {\n return;\n }\n\n // Filter messages by checkout session ID to prevent cross-instance message handling\n // This ensures each checkout instance only processes its own messages\n if (data.checkoutId && data.checkoutId !== this.options.id) {\n return; // Message is for a different checkout instance\n }\n\n // Handle specific events\n switch (data.type) {\n case 'CHECKOUT_LOADED':\n this.emitter.emit('loaded');\n break;\n case 'CHECKOUT_SUCCESS':\n this.emitter.emit('success');\n break;\n case 'CHECKOUT_ERROR':\n this.emitter.emit('error');\n break;\n }\n }\n\n /**\n * Render the checkout iframe into the container\n */\n render(): void {\n if (this.mounted) {\n console.warn('[PaypercutCheckout] Already mounted');\n return;\n }\n\n try {\n const container = this.getContainer();\n\n // Create iframe\n this.iframe = document.createElement('iframe');\n this.iframe.id = 'paypercut-checkout-iframe';\n this.iframe.src = this.buildSrc();\n this.iframe.allow = 'payment *; clipboard-write';\n this.iframe.setAttribute('frameborder', '0');\n\n // Apply default styles - just construct URL and assign to iframe\n Object.assign(this.iframe.style, {\n width: '100%',\n height: '100%',\n border: 'none',\n display: 'block'\n });\n\n // Listen for iframe load event (fallback)\n // This ensures 'loaded' event is always emitted even if hosted checkout\n // doesn't send CHECKOUT_LOADED message\n /*this.iframe.addEventListener('load', () => {\n this.emitter.emit('loaded');\n });*/\n\n container.appendChild(this.iframe);\n this.mounted = true;\n } catch (err) {\n console.error('[PaypercutCheckout] Failed to render:', err);\n throw err;\n }\n }\n\n /**\n * Submit payment - sends message to hosted checkout to confirm payment\n */\n submit(): void {\n if (!this.mounted) {\n console.warn('[PaypercutCheckout] Cannot submit: checkout not mounted');\n return;\n }\n\n try {\n this.postToIframe({\n type: 'START_PROCESSING',\n checkoutId: this.options.id,\n });\n console.log('[PaypercutCheckout] Submit payment message sent');\n } catch (err) {\n console.error('[PaypercutCheckout] Failed to submit payment:', err);\n throw err;\n }\n }\n\n /**\n * Send message to iframe - used for submit and other commands\n */\n private postToIframe(message: any): void {\n if (!this.iframe?.contentWindow) {\n console.error('[PaypercutCheckout] Cannot post message: iframe not mounted');\n return;\n }\n\n const checkoutOrigin = getCheckoutOrigin(this.options.hostedCheckoutUrl);\n this.iframe.contentWindow.postMessage(message, checkoutOrigin);\n }\n\n /**\n * Destroy the checkout instance and cleanup (idempotent)\n */\n destroy(): void {\n // Early return if already destroyed\n if (this.destroyed) {\n return;\n }\n\n // Remove iframe from DOM\n if (this.iframe) {\n try {\n this.iframe.remove();\n this.iframe = null;\n } catch (err) {\n console.error('[PaypercutCheckout] Error removing iframe:', err);\n }\n }\n\n // Only set mounted = false after successful DOM removal\n this.mounted = false;\n this.destroyed = true;\n\n // Cleanup event listeners\n window.removeEventListener('message', this.messageHandler);\n this.emitter.clear();\n }\n\n /**\n * Subscribe to an event\n */\n on(event: EventName, handler: (...args: any[]) => void): () => void {\n return this.emitter.on(event, handler);\n }\n\n /**\n * Subscribe to event that auto-unsubscribes after first emission\n */\n once(event: EventName, handler: (...args: any[]) => void): () => void {\n return this.emitter.once(event, handler);\n }\n\n /**\n * Unsubscribe from an event\n */\n off(event: EventName, handler: (...args: any[]) => void): void {\n this.emitter.off(event, handler);\n }\n\n /**\n * Check if checkout is currently mounted\n */\n isMounted(): boolean {\n return this.mounted;\n }\n}\n\n/**\n * Factory function that works both as callable and constructable.\n * Always returns a new CheckoutImpl instance - no prototype manipulation needed.\n */\nconst PaypercutCheckout: PaypercutCheckoutStatic = function (\n this: unknown,\n options: PaypercutCheckoutOptions\n): CheckoutInstance {\n // Always return a new instance, regardless of how it's called\n return new CheckoutImpl(options);\n} as unknown as PaypercutCheckoutStatic;\n\n// Add static version property\n(PaypercutCheckout as any).version = config.version;\n\n// Export as default and named\nexport default PaypercutCheckout;\nexport { PaypercutCheckout };\n\n"],"names":[],"mappings":"AAAA;;;AAGG;MACU,OAAO,CAAA;AAApB,IAAA,WAAA,GAAA;AACU,QAAA,IAAA,CAAA,QAAQ,GAAG,IAAI,GAAG,EAAoB;IAmEhD;AAjEE;;;;;AAKG;IACH,EAAE,CAAC,KAAQ,EAAE,OAAiB,EAAA;QAC5B,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;YAC7B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,GAAG,EAAE,CAAC;QACrC;AACA,QAAA,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAE,CAAC,GAAG,CAAC,OAAO,CAAC;;QAGtC,OAAO,MAAM,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC;IACvC;AAEA;;;;;;;;;;AAUG;IACH,IAAI,CAAC,KAAQ,EAAE,OAAiB,EAAA;AAC9B,QAAA,MAAM,cAAc,GAAG,CAAC,GAAG,IAAW,KAAI;AACxC,YAAA,OAAO,CAAC,GAAG,IAAI,CAAC;AAChB,YAAA,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,cAAc,CAAC;AACjC,QAAA,CAAC;QACD,OAAO,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,CAAC;IACvC;AAEA;;;;AAIG;IACH,GAAG,CAAC,KAAQ,EAAE,OAAiB,EAAA;AAC7B,QAAA,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC;IAC3C;AAEA;;;;AAIG;AACH,IAAA,IAAI,CAAC,KAAQ,EAAE,GAAG,IAAW,EAAA;AAC3B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I,CAAC,KAAgB,EAAE,OAAiC,EAAA;QACtD,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC;IAC1C;AAEA;;AAEG;IACH,GAAG,CAAC,KAAgB,EAAE,OAAiC,EAAA;QACrD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC;IAClC;AAEA;;AAEG;IACH,SAAS,GAAA;QACP,OAAO,IAAI,CAAC,OAAO;IACrB;AACD;AAED;;;AAGG;AACH,MAAM,iBAAiB,GAA4B,UAEjD,OAAiC,EAAA;;AAGjC,IAAA,OAAO,IAAI,YAAY,CAAC,OAAO,CAAC;AAClC;AAEA;AACC,iBAAyB,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO;;;;"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/utils/emitter.ts","../src/config.ts","../src/types/locales.ts","../src/types/checkout.ts","../src/index.ts"],"sourcesContent":["/**\n * Simple event emitter for handling checkout events\n * Supports subscribing, unsubscribing, and emitting events\n */\nexport class Emitter<T extends string = string> {\n private handlers = new Map<T, Set<Function>>();\n\n /**\n * Subscribe to an event\n * @param event - Event name to listen to\n * @param handler - Callback function to execute when event is emitted\n * @returns Unsubscribe function\n */\n on(event: T, handler: Function): () => void {\n if (!this.handlers.has(event)) {\n this.handlers.set(event, new Set());\n }\n this.handlers.get(event)!.add(handler);\n\n // Return unsubscribe function\n return () => this.off(event, handler);\n }\n\n /**\n * Subscribe to an event that auto-unsubscribes after first emission\n *\n * Common use case: waiting for 'loaded' event or handling first 'success'.\n * Without this helper, developers would need to manually unsubscribe inside\n * their handler, which is error-prone and leads to memory leaks if forgotten.\n *\n * @param event - Event name to listen to\n * @param handler - Callback function to execute when event is emitted\n * @returns Unsubscribe function\n */\n once(event: T, handler: Function): () => void {\n const wrappedHandler = (...args: any[]) => {\n handler(...args);\n this.off(event, wrappedHandler);\n };\n return this.on(event, wrappedHandler);\n }\n\n /**\n * Unsubscribe from an event\n * @param event - Event name to stop listening to\n * @param handler - Callback function to remove\n */\n off(event: T, handler: Function): void {\n this.handlers.get(event)?.delete(handler);\n }\n\n /**\n * Emit an event with optional arguments\n * @param event - Event name to emit\n * @param args - Arguments to pass to event handlers\n */\n emit(event: T, ...args: any[]): void {\n this.handlers.get(event)?.forEach(h => {\n try {\n h(...args);\n } catch (err) {\n console.error(`[Emitter] Error in ${event} handler:`, err);\n }\n });\n }\n\n /**\n * Clear all event handlers\n */\n clear(): void {\n this.handlers.clear();\n }\n}\n\n","/**\n * Build-time configuration\n * \n * This file is processed at build time with different values for:\n * - Production build (for merchants)\n * - Internal build (for team development)\n */\n\n/**\n * Build mode - replaced at build time\n */\ndeclare const __BUILD_MODE__: 'production' | 'internal';\n\n/**\n * SDK version - replaced at build time\n */\ndeclare const __VERSION__: string;\n\n/**\n * Configuration interface\n */\nexport interface BuildConfig {\n /** SDK version */\n version: string;\n \n /** Build mode */\n mode: 'production' | 'internal';\n \n /** Default checkout origin (production URL) */\n defaultCheckoutOrigin: string;\n \n /** Allowed origins for postMessage validation */\n allowedOrigins: string[];\n \n /** Whether hostedCheckoutUrl override is allowed */\n allowOriginOverride: boolean;\n}\n\n/**\n * Production configuration (for merchants)\n */\nconst productionConfig: BuildConfig = {\n version: __VERSION__,\n mode: 'production',\n defaultCheckoutOrigin: 'https://buy.paypercut.io',\n allowedOrigins: [\n 'https://buy.paypercut.io'\n ],\n allowOriginOverride: false // ← Merchants CANNOT override\n};\n\n/**\n * Internal configuration (for team development)\n */\nconst internalConfig: BuildConfig = {\n version: __VERSION__,\n mode: 'internal',\n defaultCheckoutOrigin: 'https://buy.paypercut.io',\n allowedOrigins: [\n 'https://buy.paypercut.io',\n 'http://localhost:3000',\n 'http://localhost:3001',\n 'http://127.0.0.1:3000',\n 'http://127.0.0.1:3001'\n ],\n allowOriginOverride: true // ← Team CAN override for testing\n};\n\n/**\n * Active configuration (selected at build time)\n */\nexport const config: BuildConfig = __BUILD_MODE__ === 'internal' \n ? internalConfig \n : productionConfig;\n\n/**\n * Helper to check if origin is allowed\n */\nexport function isOriginAllowed(origin: string): boolean {\n return config.allowedOrigins.includes(origin);\n}\n\n/**\n * Get the checkout origin (with optional override for internal builds)\n */\nexport function getCheckoutOrigin(override?: string): string {\n // Only allow override in internal builds\n if (override && config.allowOriginOverride) {\n return override;\n }\n \n return config.defaultCheckoutOrigin;\n}\n\n","/**\n * Supported locales for Paypercut Checkout\n * \n * @remarks\n * Single source of truth for all supported locale codes.\n * \n * Supported languages:\n * - Bulgarian: 'bg', 'bg-BG'\n * - English: 'en', 'en-GB'\n * - Greek: 'el', 'el-GR'\n * - Romanian: 'ro', 'ro-RO'\n * - Croatian: 'hr', 'hr-HR'\n * - Polish: 'pl', 'pl-PL'\n * - Czech: 'cs', 'cs-CZ'\n * - Slovenian: 'sl', 'sl-SI'\n * - Slovak: 'sk', 'sk-SK'\n * \n * @example\n * ```typescript\n * const checkout = PaypercutCheckout({\n * locale: 'bg' // or 'bg-BG', 'en', 'en-GB', etc.\n * });\n * ```\n */\nexport const LOCALES = [\n 'bg', 'bg-BG',\n 'en', 'en-GB',\n 'el', 'el-GR',\n 'ro', 'ro-RO',\n 'hr', 'hr-HR',\n 'pl', 'pl-PL',\n 'cs', 'cs-CZ',\n 'sl', 'sl-SI',\n 'sk', 'sk-SK',\n] as const;\n\n/**\n * Locale type - union of all supported locale codes plus 'auto'\n * @example\n * ```typescript\n * const locale: Locale = 'bg';\n * const autoLocale: Locale = 'auto';\n * ```\n */\nexport type Locale = typeof LOCALES[number] | 'auto';\n\n/**\n * Fast runtime check using Set for O(1) lookup\n * @internal\n */\nconst LOCALE_SET: ReadonlySet<string> = new Set(LOCALES);\n\n/**\n * Normalize and validate locale\n * \n * @param locale - Locale code to normalize\n * @returns Normalized locale code or 'en' as fallback\n * \n * @remarks\n * - 'auto' or empty → 'en'\n * - Unsupported locale → 'en' with console warning\n * - Supported locale → original value\n * \n * @example\n * ```typescript\n * normalizeLocale('auto') // → 'en'\n * normalizeLocale('bg') // → 'bg'\n * normalizeLocale('de') // → 'en' (with warning)\n * ```\n */\nexport function normalizeLocale(locale: string | Locale): typeof LOCALES[number] | 'en' {\n if (!locale || locale === 'auto') return 'en';\n if (LOCALE_SET.has(locale)) return locale as typeof LOCALES[number];\n console.warn(`[PaypercutCheckout] Locale \"${locale}\" is not supported. Falling back to \"en\".`);\n return 'en';\n}\n\n","import { Locale } from './locales';\n\n/**\n * UI mode for checkout\n */\nexport enum UIMode {\n /** Custom UI mode - merchant provides their own submit button */\n CUSTOM = 'custom',\n /** Embedded mode - checkout embedded in merchant page */\n EMBEDDED = 'embedded',\n /** Hosted mode - full-page checkout experience */\n HOSTED = 'hosted',\n}\n\n/**\n * Type guard for UIMode\n */\nexport function isValidUIMode(value: string): value is UIMode {\n return Object.values(UIMode).includes(value as UIMode);\n}\n\n/**\n * Payment method types\n */\nexport enum PaymentMethod {\n /** Card payment (credit/debit) */\n CARD = 'card',\n}\n\n/**\n * Type guard for PaymentMethod\n */\nexport function isValidPaymentMethod(value: string): value is PaymentMethod {\n return Object.values(PaymentMethod).includes(value as PaymentMethod);\n}\n\n/**\n * Wallet options for digital wallets\n */\nexport enum WalletOption {\n /** Apple Pay */\n APPLE_PAY = 'apple_pay',\n /** Google Pay */\n GOOGLE_PAY = 'google_pay',\n}\n\n/**\n * Type guard for WalletOption\n */\nexport function isValidWalletOption(value: string): value is WalletOption {\n return Object.values(WalletOption).includes(value as WalletOption);\n}\n\n/**\n * Validate payment methods array\n */\nexport function validatePaymentMethods(methods: string[]): PaymentMethod[] {\n const validated: PaymentMethod[] = [];\n \n for (const method of methods) {\n if (isValidPaymentMethod(method)) {\n validated.push(method as PaymentMethod);\n } else {\n console.warn(`[PaypercutCheckout] Invalid payment method: \"${method}\". Skipping.`);\n }\n }\n \n // Default to card if no valid methods\n if (validated.length === 0) {\n console.warn('[PaypercutCheckout] No valid payment methods provided. Defaulting to \"card\".');\n validated.push(PaymentMethod.CARD);\n }\n \n return validated;\n}\n\n/**\n * Validate wallet options array\n */\nexport function validateWalletOptions(options: string[]): WalletOption[] {\n const validated: WalletOption[] = [];\n \n for (const option of options) {\n if (isValidWalletOption(option)) {\n validated.push(option as WalletOption);\n } else {\n console.warn(`[PaypercutCheckout] Invalid wallet option: \"${option}\". Skipping.`);\n }\n }\n \n return validated;\n}\n\n/**\n * Validate UI mode\n */\nexport function validateUIMode(mode: string | undefined): UIMode | undefined {\n if (!mode) {\n return undefined;\n }\n \n if (isValidUIMode(mode)) {\n return mode as UIMode;\n }\n \n console.warn(`[PaypercutCheckout] Invalid ui_mode: \"${mode}\". Valid options: ${Object.values(UIMode).join(', ')}`);\n return undefined;\n}\n\n/**\n * Configuration options for PaypercutCheckout\n */\nexport interface PaypercutCheckoutOptions {\n /** Checkout session identifier (e.g., 'CHK_12345') */\n id: string;\n\n /** CSS selector or HTMLElement where iframe mounts (required) */\n containerId: string | HTMLElement;\n\n /**\n * Optional: Custom hosted checkout URL (only available in internal builds)\n * Production builds will ignore this option for security\n */\n hostedCheckoutUrl?: string;\n\n /**\n * Optional: Locale for checkout UI\n * @default 'en'\n */\n locale?: Locale | string;\n\n /**\n * Optional: UI mode for checkout\n */\n ui_mode?: UIMode | `${UIMode}`;\n\n /**\n * Optional: Payment methods to enable\n * @default ['card']\n */\n payment_methods?: (PaymentMethod | `${PaymentMethod}`)[];\n\n /**\n * Optional: Digital wallet options\n * Can include both or just one\n */\n wallet_options?: (WalletOption | `${WalletOption}`)[];\n\n /**\n * Optional: Show only the payment form without header/footer\n * @default false\n */\n form_only?: boolean;\n}\n\n/**\n * Event names that can be emitted by the checkout\n */\nexport type EventName =\n | 'loaded' // iframe finished loading\n | 'success' // payment successful\n | 'error'; // payment or system error\n\n/**\n * Checkout instance interface\n */\nexport interface CheckoutInstance {\n /** Mount and render the iframe into the container */\n render(): void;\n\n /** Submit payment - sends message to hosted checkout to confirm payment */\n submit(): void;\n\n /** Destroy instance and cleanup all listeners */\n destroy(): void;\n\n /** Subscribe to events. Returns unsubscribe function */\n on(event: EventName, handler: (...args: any[]) => void): () => void;\n\n /** Subscribe to event that auto-unsubscribes after first emission */\n once(event: EventName, handler: (...args: any[]) => void): () => void;\n\n /** Unsubscribe from events */\n off(event: EventName, handler: (...args: any[]) => void): void;\n\n /** Check if checkout is currently mounted */\n isMounted(): boolean;\n}\n\n/**\n * PaypercutCheckout static interface (callable and constructable)\n */\nexport interface PaypercutCheckoutStatic {\n /** Callable factory function */\n (options: PaypercutCheckoutOptions): CheckoutInstance;\n\n /** Constructor support */\n new (options: PaypercutCheckoutOptions): CheckoutInstance;\n\n /** SDK version */\n version: string;\n}\n\n","import { Emitter } from './utils/emitter';\nimport { config, isOriginAllowed, getCheckoutOrigin } from './config';\n\nimport {\n PaypercutCheckoutOptions,\n CheckoutInstance,\n PaypercutCheckoutStatic,\n EventName,\n validatePaymentMethods,\n validateWalletOptions,\n validateUIMode,\n} from './types';\nimport {normalizeLocale} from \"./types\";\n\n// Re-export types and enums for consumers\nexport type {\n PaypercutCheckoutOptions,\n CheckoutInstance,\n PaypercutCheckoutStatic,\n EventName,\n};\n\nexport {\n UIMode,\n PaymentMethod,\n WalletOption,\n} from './types/checkout';\n\nexport type { Locale } from './types/locales';\nexport { LOCALES } from './types/locales';\n\n/**\n * Internal implementation of CheckoutInstance\n */\nclass CheckoutImpl implements CheckoutInstance {\n private emitter = new Emitter<EventName>();\n private mounted = false;\n private destroyed = false;\n private iframe: HTMLIFrameElement | null = null;\n private messageHandler: (evt: MessageEvent) => void;\n\n constructor(private options: PaypercutCheckoutOptions) {\n // Bind message handler\n this.messageHandler = this.onMessage.bind(this);\n window.addEventListener('message', this.messageHandler);\n }\n\n /**\n * Build the iframe source URL with query parameters\n */\n private buildSrc(): string {\n const baseUrl = getCheckoutOrigin(this.options.hostedCheckoutUrl);\n const url = new URL(`/c/${this.options.id}`, baseUrl);\n\n // Add locale parameter\n if (this.options.locale) {\n const normalizedLocale = normalizeLocale(this.options.locale);\n url.searchParams.set('locale', normalizedLocale);\n }\n\n // Add ui_mode parameter\n if (this.options.ui_mode) {\n const validatedUIMode = validateUIMode(this.options.ui_mode);\n if (validatedUIMode) {\n url.searchParams.set('ui_mode', validatedUIMode);\n }\n }\n\n // Add payment_methods parameters (repeated for each method)\n if (this.options.payment_methods && this.options.payment_methods.length > 0) {\n const validatedMethods = validatePaymentMethods(this.options.payment_methods as string[]);\n validatedMethods.forEach(method => {\n url.searchParams.append('payment_methods', method);\n });\n }\n\n // Add wallet_options parameters (repeated for each wallet)\n if (this.options.wallet_options && this.options.wallet_options.length > 0) {\n const validatedWallets = validateWalletOptions(this.options.wallet_options as string[]);\n validatedWallets.forEach(wallet => {\n url.searchParams.append('wallet_options', wallet);\n });\n }\n\n console.log('this.options', this.options);\n\n if (this.options.form_only !== undefined) {\n url.searchParams.set('form_only', String(this.options.form_only));\n }\n\n return url.toString();\n }\n\n /**\n * Get the container element from selector or HTMLElement\n */\n private getContainer(): HTMLElement {\n const container = typeof this.options.containerId === 'string'\n ? document.querySelector(this.options.containerId)\n : this.options.containerId;\n\n if (!container) {\n throw new Error(`Container not found: ${this.options.containerId}`);\n }\n\n return container as HTMLElement;\n }\n\n /**\n * Handle incoming postMessage events from iframe\n */\n private onMessage(evt: MessageEvent): void {\n // Validate origin against allowed origins (build-time whitelist)\n if (!isOriginAllowed(evt.origin)) {\n console.warn('[PaypercutCheckout] Rejected message from unauthorized origin:', evt.origin, 'Allowed:', config.allowedOrigins);\n return;\n }\n\n // Validate structure\n const data = evt.data;\n if (!data || typeof data !== 'object' || !('type' in data)) {\n return;\n }\n\n // Filter messages by checkout session ID to prevent cross-instance message handling\n // This ensures each checkout instance only processes its own messages\n if (data.checkoutId && data.checkoutId !== this.options.id) {\n return; // Message is for a different checkout instance\n }\n\n // Handle specific events\n switch (data.type) {\n case 'CHECKOUT_LOADED':\n this.emitter.emit('loaded');\n break;\n case 'CHECKOUT_SUCCESS':\n this.emitter.emit('success');\n break;\n case 'CHECKOUT_ERROR':\n this.emitter.emit('error');\n break;\n }\n }\n\n /**\n * Render the checkout iframe into the container\n */\n render(): void {\n if (this.mounted) {\n console.warn('[PaypercutCheckout] Already mounted');\n return;\n }\n\n try {\n const container = this.getContainer();\n\n // Create iframe\n this.iframe = document.createElement('iframe');\n this.iframe.id = 'paypercut-checkout-iframe';\n this.iframe.src = this.buildSrc();\n this.iframe.allow = 'payment *; clipboard-write';\n this.iframe.setAttribute('frameborder', '0');\n\n // Apply default styles - just construct URL and assign to iframe\n Object.assign(this.iframe.style, {\n width: '100%',\n height: '100%',\n border: 'none',\n display: 'block'\n });\n\n // Listen for iframe load event (fallback)\n // This ensures 'loaded' event is always emitted even if hosted checkout\n // doesn't send CHECKOUT_LOADED message\n /*this.iframe.addEventListener('load', () => {\n this.emitter.emit('loaded');\n });*/\n\n container.appendChild(this.iframe);\n this.mounted = true;\n } catch (err) {\n console.error('[PaypercutCheckout] Failed to render:', err);\n throw err;\n }\n }\n\n /**\n * Submit payment - sends message to hosted checkout to confirm payment\n */\n submit(): void {\n if (!this.mounted) {\n console.warn('[PaypercutCheckout] Cannot submit: checkout not mounted');\n return;\n }\n\n try {\n this.postToIframe({\n type: 'START_PROCESSING',\n checkoutId: this.options.id,\n });\n console.log('[PaypercutCheckout] Submit payment message sent');\n } catch (err) {\n console.error('[PaypercutCheckout] Failed to submit payment:', err);\n throw err;\n }\n }\n\n /**\n * Send message to iframe - used for submit and other commands\n */\n private postToIframe(message: any): void {\n if (!this.iframe?.contentWindow) {\n console.error('[PaypercutCheckout] Cannot post message: iframe not mounted');\n return;\n }\n\n const checkoutOrigin = getCheckoutOrigin(this.options.hostedCheckoutUrl);\n this.iframe.contentWindow.postMessage(message, checkoutOrigin);\n }\n\n /**\n * Destroy the checkout instance and cleanup (idempotent)\n */\n destroy(): void {\n // Early return if already destroyed\n if (this.destroyed) {\n return;\n }\n\n // Remove iframe from DOM\n if (this.iframe) {\n try {\n this.iframe.remove();\n this.iframe = null;\n } catch (err) {\n console.error('[PaypercutCheckout] Error removing iframe:', err);\n }\n }\n\n // Only set mounted = false after successful DOM removal\n this.mounted = false;\n this.destroyed = true;\n\n // Cleanup event listeners\n window.removeEventListener('message', this.messageHandler);\n this.emitter.clear();\n }\n\n /**\n * Subscribe to an event\n */\n on(event: EventName, handler: (...args: any[]) => void): () => void {\n return this.emitter.on(event, handler);\n }\n\n /**\n * Subscribe to event that auto-unsubscribes after first emission\n */\n once(event: EventName, handler: (...args: any[]) => void): () => void {\n return this.emitter.once(event, handler);\n }\n\n /**\n * Unsubscribe from an event\n */\n off(event: EventName, handler: (...args: any[]) => void): void {\n this.emitter.off(event, handler);\n }\n\n /**\n * Check if checkout is currently mounted\n */\n isMounted(): boolean {\n return this.mounted;\n }\n}\n\n/**\n * Factory function that works both as callable and constructable.\n * Always returns a new CheckoutImpl instance - no prototype manipulation needed.\n */\nconst PaypercutCheckout: PaypercutCheckoutStatic = function (\n this: unknown,\n options: PaypercutCheckoutOptions\n): CheckoutInstance {\n // Always return a new instance, regardless of how it's called\n return new CheckoutImpl(options);\n} as unknown as PaypercutCheckoutStatic;\n\n// Add static version property\n(PaypercutCheckout as any).version = config.version;\n\n// Export as default and named\nexport default PaypercutCheckout;\nexport { PaypercutCheckout };\n\n"],"names":[],"mappings":"AAAA;;;AAGG;MACU,OAAO,CAAA;AAApB,IAAA,WAAA,GAAA;AACU,QAAA,IAAA,CAAA,QAAQ,GAAG,IAAI,GAAG,EAAoB;IAmEhD;AAjEE;;;;;AAKG;IACH,EAAE,CAAC,KAAQ,EAAE,OAAiB,EAAA;QAC5B,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;YAC7B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,GAAG,EAAE,CAAC;QACrC;AACA,QAAA,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAE,CAAC,GAAG,CAAC,OAAO,CAAC;;QAGtC,O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,KAAK,CAAC,4CAA4C,EAAE,GAAG,CAAC;YAClE;QACF;;AAGA,QAAA,IAAI,CAAC,OAAO,GAAG,KAAK;AACpB,QAAA,IAAI,CAAC,SAAS,GAAG,IAAI;;QAGrB,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,cAAc,CAAC;AAC1D,QAAA,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE;IACtB;AAEA;;AAEG;IACH,EAAE,CAAC,KAAgB,EAAE,OAAiC,EAAA;QACpD,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC;IACxC;AAEA;;AAEG;IACH,IAAI,CAAC,KAAgB,EAAE,OAAiC,EAAA;QACtD,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC;IAC1C;AAEA;;AAEG;IACH,GAAG,CAAC,KAAgB,EAAE,OAAiC,EAAA;QACrD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC;IAClC;AAEA;;AAEG;IACH,SAAS,GAAA;QACP,OAAO,IAAI,CAAC,OAAO;IACrB;AACD;AAED;;;AAGG;AACH,MAAM,iBAAiB,GAA4B,UAEjD,OAAiC,EAAA;;AAGjC,IAAA,OAAO,IAAI,YAAY,CAAC,OAAO,CAAC;AAClC;AAEA;AACC,iBAAyB,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var PaypercutCheckout=function(){"use strict";class
|
|
1
|
+
var PaypercutCheckout=function(){"use strict";class t{constructor(){this.handlers=new Map}on(t,e){return this.handlers.has(t)||this.handlers.set(t,new Set),this.handlers.get(t).add(e),()=>this.off(t,e)}once(t,e){const o=(...s)=>{e(...s),this.off(t,o)};return this.on(t,o)}off(t,e){this.handlers.get(t)?.delete(e)}emit(t,...e){this.handlers.get(t)?.forEach(o=>{try{o(...e)}catch(e){console.error(`[Emitter] Error in ${t} handler:`,e)}})}clear(){this.handlers.clear()}}const e={version:"1.0.1",defaultCheckoutOrigin:"https://buy.paypercut.io",allowedOrigins:["https://buy.paypercut.io"]};function o(t){return e.defaultCheckoutOrigin}const s=new Set(["bg","bg-BG","en","en-GB","el","el-GR","ro","ro-RO","hr","hr-HR","pl","pl-PL","cs","cs-CZ","sl","sl-SI","sk","sk-SK"]);var i,n,r;function a(t){return Object.values(n).includes(t)}function c(t){return Object.values(r).includes(t)}function h(t){var e;if(t)return e=t,Object.values(i).includes(e)?t:void console.warn(`[PaypercutCheckout] Invalid ui_mode: "${t}". Valid options: ${Object.values(i).join(", ")}`)}!function(t){t.CUSTOM="custom",t.EMBEDDED="embedded",t.HOSTED="hosted"}(i||(i={})),function(t){t.CARD="card"}(n||(n={})),function(t){t.APPLE_PAY="apple_pay",t.GOOGLE_PAY="google_pay"}(r||(r={}));class u{constructor(e){this.options=e,this.emitter=new t,this.mounted=!1,this.destroyed=!1,this.iframe=null,this.messageHandler=this.onMessage.bind(this),window.addEventListener("message",this.messageHandler)}buildSrc(){const t=o(this.options.hostedCheckoutUrl),e=new URL(`/c/${this.options.id}`,t);if(this.options.locale){const t=(i=this.options.locale)&&"auto"!==i?s.has(i)?i:(console.warn(`[PaypercutCheckout] Locale "${i}" is not supported. Falling back to "en".`),"en"):"en";e.searchParams.set("locale",t)}var i;if(this.options.ui_mode){const t=h(this.options.ui_mode);t&&e.searchParams.set("ui_mode",t)}if(this.options.payment_methods&&this.options.payment_methods.length>0){(function(t){const e=[];for(const o of t)a(o)?e.push(o):console.warn(`[PaypercutCheckout] Invalid payment method: "${o}". Skipping.`);return 0===e.length&&(console.warn('[PaypercutCheckout] No valid payment methods provided. Defaulting to "card".'),e.push(n.CARD)),e})(this.options.payment_methods).forEach(t=>{e.searchParams.append("payment_methods",t)})}if(this.options.wallet_options&&this.options.wallet_options.length>0){(function(t){const e=[];for(const o of t)c(o)?e.push(o):console.warn(`[PaypercutCheckout] Invalid wallet option: "${o}". Skipping.`);return e})(this.options.wallet_options).forEach(t=>{e.searchParams.append("wallet_options",t)})}return console.log("this.options",this.options),void 0!==this.options.form_only&&e.searchParams.set("form_only",String(this.options.form_only)),e.toString()}getContainer(){const t="string"==typeof this.options.containerId?document.querySelector(this.options.containerId):this.options.containerId;if(!t)throw new Error(`Container not found: ${this.options.containerId}`);return t}onMessage(t){if(o=t.origin,!e.allowedOrigins.includes(o))return void console.warn("[PaypercutCheckout] Rejected message from unauthorized origin:",t.origin,"Allowed:",e.allowedOrigins);var o;const s=t.data;if(s&&"object"==typeof s&&"type"in s&&(!s.checkoutId||s.checkoutId===this.options.id))switch(s.type){case"CHECKOUT_LOADED":this.emitter.emit("loaded");break;case"CHECKOUT_SUCCESS":this.emitter.emit("success");break;case"CHECKOUT_ERROR":this.emitter.emit("error")}}render(){if(this.mounted)console.warn("[PaypercutCheckout] Already mounted");else try{const t=this.getContainer();this.iframe=document.createElement("iframe"),this.iframe.id="paypercut-checkout-iframe",this.iframe.src=this.buildSrc(),this.iframe.allow="payment *; clipboard-write",this.iframe.setAttribute("frameborder","0"),Object.assign(this.iframe.style,{width:"100%",height:"100%",border:"none",display:"block"}),t.appendChild(this.iframe),this.mounted=!0}catch(t){throw console.error("[PaypercutCheckout] Failed to render:",t),t}}submit(){if(this.mounted)try{this.postToIframe({type:"START_PROCESSING",checkoutId:this.options.id}),console.log("[PaypercutCheckout] Submit payment message sent")}catch(t){throw console.error("[PaypercutCheckout] Failed to submit payment:",t),t}else console.warn("[PaypercutCheckout] Cannot submit: checkout not mounted")}postToIframe(t){if(!this.iframe?.contentWindow)return void console.error("[PaypercutCheckout] Cannot post message: iframe not mounted");const e=o(this.options.hostedCheckoutUrl);this.iframe.contentWindow.postMessage(t,e)}destroy(){if(!this.destroyed){if(this.iframe)try{this.iframe.remove(),this.iframe=null}catch(t){console.error("[PaypercutCheckout] Error removing iframe:",t)}this.mounted=!1,this.destroyed=!0,window.removeEventListener("message",this.messageHandler),this.emitter.clear()}}on(t,e){return this.emitter.on(t,e)}once(t,e){return this.emitter.once(t,e)}off(t,e){this.emitter.off(t,e)}isMounted(){return this.mounted}}const l=function(t){return new u(t)};return l.version=e.version,l}();
|
|
2
2
|
//# sourceMappingURL=paypercut-checkout.iife.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paypercut-checkout.iife.min.js","sources":["../src/utils/emitter.ts","../src/config.ts","../src/types/locales.ts","../src/types/checkout.ts","../src/index.ts"],"sourcesContent":["/**\n * Simple event emitter for handling checkout events\n * Supports subscribing, unsubscribing, and emitting events\n */\nexport class Emitter<T extends string = string> {\n private handlers = new Map<T, Set<Function>>();\n\n /**\n * Subscribe to an event\n * @param event - Event name to listen to\n * @param handler - Callback function to execute when event is emitted\n * @returns Unsubscribe function\n */\n on(event: T, handler: Function): () => void {\n if (!this.handlers.has(event)) {\n this.handlers.set(event, new Set());\n }\n this.handlers.get(event)!.add(handler);\n\n // Return unsubscribe function\n return () => this.off(event, handler);\n }\n\n /**\n * Subscribe to an event that auto-unsubscribes after first emission\n *\n * Common use case: waiting for 'loaded' event or handling first 'success'.\n * Without this helper, developers would need to manually unsubscribe inside\n * their handler, which is error-prone and leads to memory leaks if forgotten.\n *\n * @param event - Event name to listen to\n * @param handler - Callback function to execute when event is emitted\n * @returns Unsubscribe function\n */\n once(event: T, handler: Function): () => void {\n const wrappedHandler = (...args: any[]) => {\n handler(...args);\n this.off(event, wrappedHandler);\n };\n return this.on(event, wrappedHandler);\n }\n\n /**\n * Unsubscribe from an event\n * @param event - Event name to stop listening to\n * @param handler - Callback function to remove\n */\n off(event: T, handler: Function): void {\n this.handlers.get(event)?.delete(handler);\n }\n\n /**\n * Emit an event with optional arguments\n * @param event - Event name to emit\n * @param args - Arguments to pass to event handlers\n */\n emit(event: T, ...args: any[]): void {\n this.handlers.get(event)?.forEach(h => {\n try {\n h(...args);\n } catch (err) {\n console.error(`[Emitter] Error in ${event} handler:`, err);\n }\n });\n }\n\n /**\n * Clear all event handlers\n */\n clear(): void {\n this.handlers.clear();\n }\n}\n\n","/**\n * Build-time configuration\n * \n * This file is processed at build time with different values for:\n * - Production build (for merchants)\n * - Internal build (for team development)\n */\n\n/**\n * Build mode - replaced at build time\n */\ndeclare const __BUILD_MODE__: 'production' | 'internal';\n\n/**\n * SDK version - replaced at build time\n */\ndeclare const __VERSION__: string;\n\n/**\n * Configuration interface\n */\nexport interface BuildConfig {\n /** SDK version */\n version: string;\n \n /** Build mode */\n mode: 'production' | 'internal';\n \n /** Default checkout origin (production URL) */\n defaultCheckoutOrigin: string;\n \n /** Allowed origins for postMessage validation */\n allowedOrigins: string[];\n \n /** Whether hostedCheckoutUrl override is allowed */\n allowOriginOverride: boolean;\n}\n\n/**\n * Production configuration (for merchants)\n */\nconst productionConfig: BuildConfig = {\n version: __VERSION__,\n mode: 'production',\n defaultCheckoutOrigin: 'https://buy.paypercut.io',\n allowedOrigins: [\n 'https://buy.paypercut.io'\n ],\n allowOriginOverride: false // ← Merchants CANNOT override\n};\n\n/**\n * Internal configuration (for team development)\n */\nconst internalConfig: BuildConfig = {\n version: __VERSION__,\n mode: 'internal',\n defaultCheckoutOrigin: 'https://buy.paypercut.io',\n allowedOrigins: [\n 'https://buy.paypercut.io',\n 'http://localhost:3000',\n 'http://localhost:3001',\n 'http://127.0.0.1:3000',\n 'http://127.0.0.1:3001'\n ],\n allowOriginOverride: true // ← Team CAN override for testing\n};\n\n/**\n * Active configuration (selected at build time)\n */\nexport const config: BuildConfig = __BUILD_MODE__ === 'internal' \n ? internalConfig \n : productionConfig;\n\n/**\n * Helper to check if origin is allowed\n */\nexport function isOriginAllowed(origin: string): boolean {\n return config.allowedOrigins.includes(origin);\n}\n\n/**\n * Get the checkout origin (with optional override for internal builds)\n */\nexport function getCheckoutOrigin(override?: string): string {\n // Only allow override in internal builds\n if (override && config.allowOriginOverride) {\n return override;\n }\n \n return config.defaultCheckoutOrigin;\n}\n\n","/**\n * Locale configuration with support status\n */\nexport interface LocaleConfig {\n /** Locale code (e.g., 'en-US', 'bg-BG') */\n code: string;\n /** Country/region name */\n name: string;\n /** Whether this locale is currently supported */\n supported: boolean;\n}\n\n/**\n * Comprehensive list of locales with support status\n * Currently supported: 'bg', 'bg-BG', 'en', 'en-GB'\n * All others fallback to 'en'\n */\nexport const LOCALES: Record<string, LocaleConfig> = {\n // Supported locales\n 'bg': { code: 'bg', name: 'Bulgarian', supported: true },\n 'bg-BG': { code: 'bg-BG', name: 'Bulgarian (Bulgaria)', supported: true },\n 'en': { code: 'en', name: 'English', supported: true },\n 'en-GB': { code: 'en-GB', name: 'English (United Kingdom)', supported: true },\n \n // Common locales (not yet supported - fallback to 'en')\n 'en-US': { code: 'en-US', name: 'English (United States)', supported: false },\n 'en-CA': { code: 'en-CA', name: 'English (Canada)', supported: false },\n 'en-AU': { code: 'en-AU', name: 'English (Australia)', supported: false },\n 'en-NZ': { code: 'en-NZ', name: 'English (New Zealand)', supported: false },\n 'en-IE': { code: 'en-IE', name: 'English (Ireland)', supported: false },\n \n // European locales\n 'de': { code: 'de', name: 'German', supported: false },\n 'de-DE': { code: 'de-DE', name: 'German (Germany)', supported: false },\n 'de-AT': { code: 'de-AT', name: 'German (Austria)', supported: false },\n 'de-CH': { code: 'de-CH', name: 'German (Switzerland)', supported: false },\n 'fr': { code: 'fr', name: 'French', supported: false },\n 'fr-FR': { code: 'fr-FR', name: 'French (France)', supported: false },\n 'fr-BE': { code: 'fr-BE', name: 'French (Belgium)', supported: false },\n 'fr-CH': { code: 'fr-CH', name: 'French (Switzerland)', supported: false },\n 'fr-CA': { code: 'fr-CA', name: 'French (Canada)', supported: false },\n 'es': { code: 'es', name: 'Spanish', supported: false },\n 'es-ES': { code: 'es-ES', name: 'Spanish (Spain)', supported: false },\n 'es-MX': { code: 'es-MX', name: 'Spanish (Mexico)', supported: false },\n 'es-AR': { code: 'es-AR', name: 'Spanish (Argentina)', supported: false },\n 'es-CO': { code: 'es-CO', name: 'Spanish (Colombia)', supported: false },\n 'it': { code: 'it', name: 'Italian', supported: false },\n 'it-IT': { code: 'it-IT', name: 'Italian (Italy)', supported: false },\n 'it-CH': { code: 'it-CH', name: 'Italian (Switzerland)', supported: false },\n 'pt': { code: 'pt', name: 'Portuguese', supported: false },\n 'pt-PT': { code: 'pt-PT', name: 'Portuguese (Portugal)', supported: false },\n 'pt-BR': { code: 'pt-BR', name: 'Portuguese (Brazil)', supported: false },\n 'nl': { code: 'nl', name: 'Dutch', supported: false },\n 'nl-NL': { code: 'nl-NL', name: 'Dutch (Netherlands)', supported: false },\n 'nl-BE': { code: 'nl-BE', name: 'Dutch (Belgium)', supported: false },\n 'pl': { code: 'pl', name: 'Polish', supported: false },\n 'pl-PL': { code: 'pl-PL', name: 'Polish (Poland)', supported: false },\n 'ro': { code: 'ro', name: 'Romanian', supported: false },\n 'ro-RO': { code: 'ro-RO', name: 'Romanian (Romania)', supported: false },\n 'cs': { code: 'cs', name: 'Czech', supported: false },\n 'cs-CZ': { code: 'cs-CZ', name: 'Czech (Czech Republic)', supported: false },\n 'hu': { code: 'hu', name: 'Hungarian', supported: false },\n 'hu-HU': { code: 'hu-HU', name: 'Hungarian (Hungary)', supported: false },\n 'el': { code: 'el', name: 'Greek', supported: false },\n 'el-GR': { code: 'el-GR', name: 'Greek (Greece)', supported: false },\n 'sv': { code: 'sv', name: 'Swedish', supported: false },\n 'sv-SE': { code: 'sv-SE', name: 'Swedish (Sweden)', supported: false },\n 'da': { code: 'da', name: 'Danish', supported: false },\n 'da-DK': { code: 'da-DK', name: 'Danish (Denmark)', supported: false },\n 'fi': { code: 'fi', name: 'Finnish', supported: false },\n 'fi-FI': { code: 'fi-FI', name: 'Finnish (Finland)', supported: false },\n 'no': { code: 'no', name: 'Norwegian', supported: false },\n 'nb-NO': { code: 'nb-NO', name: 'Norwegian Bokmål (Norway)', supported: false },\n 'nn-NO': { code: 'nn-NO', name: 'Norwegian Nynorsk (Norway)', supported: false },\n \n // Slavic locales\n 'ru': { code: 'ru', name: 'Russian', supported: false },\n 'ru-RU': { code: 'ru-RU', name: 'Russian (Russia)', supported: false },\n 'uk': { code: 'uk', name: 'Ukrainian', supported: false },\n 'uk-UA': { code: 'uk-UA', name: 'Ukrainian (Ukraine)', supported: false },\n 'sr': { code: 'sr', name: 'Serbian', supported: false },\n 'sr-RS': { code: 'sr-RS', name: 'Serbian (Serbia)', supported: false },\n 'hr': { code: 'hr', name: 'Croatian', supported: false },\n 'hr-HR': { code: 'hr-HR', name: 'Croatian (Croatia)', supported: false },\n 'sk': { code: 'sk', name: 'Slovak', supported: false },\n 'sk-SK': { code: 'sk-SK', name: 'Slovak (Slovakia)', supported: false },\n 'sl': { code: 'sl', name: 'Slovenian', supported: false },\n 'sl-SI': { code: 'sl-SI', name: 'Slovenian (Slovenia)', supported: false },\n \n // Asian locales\n 'zh': { code: 'zh', name: 'Chinese', supported: false },\n 'zh-CN': { code: 'zh-CN', name: 'Chinese (Simplified, China)', supported: false },\n 'zh-TW': { code: 'zh-TW', name: 'Chinese (Traditional, Taiwan)', supported: false },\n 'zh-HK': { code: 'zh-HK', name: 'Chinese (Traditional, Hong Kong)', supported: false },\n 'ja': { code: 'ja', name: 'Japanese', supported: false },\n 'ja-JP': { code: 'ja-JP', name: 'Japanese (Japan)', supported: false },\n 'ko': { code: 'ko', name: 'Korean', supported: false },\n 'ko-KR': { code: 'ko-KR', name: 'Korean (South Korea)', supported: false },\n 'th': { code: 'th', name: 'Thai', supported: false },\n 'th-TH': { code: 'th-TH', name: 'Thai (Thailand)', supported: false },\n 'vi': { code: 'vi', name: 'Vietnamese', supported: false },\n 'vi-VN': { code: 'vi-VN', name: 'Vietnamese (Vietnam)', supported: false },\n 'id': { code: 'id', name: 'Indonesian', supported: false },\n 'id-ID': { code: 'id-ID', name: 'Indonesian (Indonesia)', supported: false },\n 'ms': { code: 'ms', name: 'Malay', supported: false },\n 'ms-MY': { code: 'ms-MY', name: 'Malay (Malaysia)', supported: false },\n 'hi': { code: 'hi', name: 'Hindi', supported: false },\n 'hi-IN': { code: 'hi-IN', name: 'Hindi (India)', supported: false },\n \n // Middle Eastern locales\n 'ar': { code: 'ar', name: 'Arabic', supported: false },\n 'ar-SA': { code: 'ar-SA', name: 'Arabic (Saudi Arabia)', supported: false },\n 'ar-AE': { code: 'ar-AE', name: 'Arabic (United Arab Emirates)', supported: false },\n 'ar-EG': { code: 'ar-EG', name: 'Arabic (Egypt)', supported: false },\n 'he': { code: 'he', name: 'Hebrew', supported: false },\n 'he-IL': { code: 'he-IL', name: 'Hebrew (Israel)', supported: false },\n 'tr': { code: 'tr', name: 'Turkish', supported: false },\n 'tr-TR': { code: 'tr-TR', name: 'Turkish (Turkey)', supported: false },\n \n // Other locales\n 'af': { code: 'af', name: 'Afrikaans', supported: false },\n 'af-ZA': { code: 'af-ZA', name: 'Afrikaans (South Africa)', supported: false },\n 'sq': { code: 'sq', name: 'Albanian', supported: false },\n 'sq-AL': { code: 'sq-AL', name: 'Albanian (Albania)', supported: false },\n 'et': { code: 'et', name: 'Estonian', supported: false },\n 'et-EE': { code: 'et-EE', name: 'Estonian (Estonia)', supported: false },\n 'lv': { code: 'lv', name: 'Latvian', supported: false },\n 'lv-LV': { code: 'lv-LV', name: 'Latvian (Latvia)', supported: false },\n 'lt': { code: 'lt', name: 'Lithuanian', supported: false },\n 'lt-LT': { code: 'lt-LT', name: 'Lithuanian (Lithuania)', supported: false },\n 'mk': { code: 'mk', name: 'Macedonian', supported: false },\n 'mk-MK': { code: 'mk-MK', name: 'Macedonian (North Macedonia)', supported: false },\n} as const;\n\n/**\n * Type for locale codes\n */\nexport type LocaleCode = keyof typeof LOCALES | 'auto';\n\n/**\n * Normalize and validate locale\n * - 'auto' → 'en'\n * - Unsupported locale → 'en'\n * - Supported locale → original value\n */\nexport function normalizeLocale(locale: LocaleCode | string): string {\n // Handle 'auto'\n if (locale === 'auto') {\n return 'en';\n }\n\n // Check if locale exists and is supported\n const localeConfig = LOCALES[locale as keyof typeof LOCALES];\n \n if (!localeConfig) {\n console.warn(`[PaypercutCheckout] Unsupported locale: \"${locale}\". Falling back to \"en\".`);\n return 'en';\n }\n\n if (!localeConfig.supported) {\n console.warn(`[PaypercutCheckout] Locale \"${locale}\" is not yet supported. Falling back to \"en\".`);\n return 'en';\n }\n\n return localeConfig.code;\n}\n\n/**\n * Get list of supported locales\n */\nexport function getSupportedLocales(): LocaleConfig[] {\n return Object.values(LOCALES).filter(locale => locale.supported);\n}\n\n","import { LocaleCode } from './locales';\n\n/**\n * UI mode for checkout\n */\nexport enum UIMode {\n /** Custom UI mode - merchant provides their own submit button */\n CUSTOM = 'custom',\n /** Embedded mode - checkout embedded in merchant page */\n EMBEDDED = 'embedded',\n /** Hosted mode - full-page checkout experience */\n HOSTED = 'hosted',\n}\n\n/**\n * Type guard for UIMode\n */\nexport function isValidUIMode(value: string): value is UIMode {\n return Object.values(UIMode).includes(value as UIMode);\n}\n\n/**\n * Payment method types\n */\nexport enum PaymentMethod {\n /** Card payment (credit/debit) */\n CARD = 'card',\n}\n\n/**\n * Type guard for PaymentMethod\n */\nexport function isValidPaymentMethod(value: string): value is PaymentMethod {\n return Object.values(PaymentMethod).includes(value as PaymentMethod);\n}\n\n/**\n * Wallet options for digital wallets\n */\nexport enum WalletOption {\n /** Apple Pay */\n APPLE_PAY = 'apple_pay',\n /** Google Pay */\n GOOGLE_PAY = 'google_pay',\n}\n\n/**\n * Type guard for WalletOption\n */\nexport function isValidWalletOption(value: string): value is WalletOption {\n return Object.values(WalletOption).includes(value as WalletOption);\n}\n\n/**\n * Validate payment methods array\n */\nexport function validatePaymentMethods(methods: string[]): PaymentMethod[] {\n const validated: PaymentMethod[] = [];\n \n for (const method of methods) {\n if (isValidPaymentMethod(method)) {\n validated.push(method as PaymentMethod);\n } else {\n console.warn(`[PaypercutCheckout] Invalid payment method: \"${method}\". Skipping.`);\n }\n }\n \n // Default to card if no valid methods\n if (validated.length === 0) {\n console.warn('[PaypercutCheckout] No valid payment methods provided. Defaulting to \"card\".');\n validated.push(PaymentMethod.CARD);\n }\n \n return validated;\n}\n\n/**\n * Validate wallet options array\n */\nexport function validateWalletOptions(options: string[]): WalletOption[] {\n const validated: WalletOption[] = [];\n \n for (const option of options) {\n if (isValidWalletOption(option)) {\n validated.push(option as WalletOption);\n } else {\n console.warn(`[PaypercutCheckout] Invalid wallet option: \"${option}\". Skipping.`);\n }\n }\n \n return validated;\n}\n\n/**\n * Validate UI mode\n */\nexport function validateUIMode(mode: string | undefined): UIMode | undefined {\n if (!mode) {\n return undefined;\n }\n \n if (isValidUIMode(mode)) {\n return mode as UIMode;\n }\n \n console.warn(`[PaypercutCheckout] Invalid ui_mode: \"${mode}\". Valid options: ${Object.values(UIMode).join(', ')}`);\n return undefined;\n}\n\n/**\n * Configuration options for PaypercutCheckout\n */\nexport interface PaypercutCheckoutOptions {\n /** Checkout session identifier (e.g., 'CHK_12345') */\n id: string;\n\n /** CSS selector or HTMLElement where iframe mounts (required) */\n containerId: string | HTMLElement;\n\n /**\n * Optional: Custom hosted checkout URL (only available in internal builds)\n * Production builds will ignore this option for security\n */\n hostedCheckoutUrl?: string;\n\n /**\n * Optional: Locale for checkout UI\n * - 'auto' - Auto-detect (falls back to 'en')\n * - 'bg', 'bg-BG' - Bulgarian (supported)\n * - 'en', 'en-GB' - English (supported)\n * - Other locales - Falls back to 'en'\n * @default 'en'\n */\n locale?: LocaleCode | string;\n\n /**\n * Optional: UI mode for checkout\n * - 'custom' - Merchant provides submit button\n * - 'embedded' - Embedded in merchant page\n * - 'hosted' - Full-page checkout\n */\n ui_mode?: UIMode | `${UIMode}`;\n\n /**\n * Optional: Payment methods to enable\n * Currently only 'card' is supported\n * @default ['card']\n */\n payment_methods?: (PaymentMethod | `${PaymentMethod}`)[];\n\n /**\n * Optional: Digital wallet options\n * - 'apple_pay' - Apple Pay\n * - 'google_pay' - Google Pay\n * Can include both or just one\n */\n wallet_options?: (WalletOption | `${WalletOption}`)[];\n}\n\n/**\n * Event names that can be emitted by the checkout\n */\nexport type EventName =\n | 'loaded' // iframe finished loading\n | 'success' // payment successful\n | 'error'; // payment or system error\n\n/**\n * Checkout instance interface\n */\nexport interface CheckoutInstance {\n /** Mount and render the iframe into the container */\n render(): void;\n\n /** Destroy instance and cleanup all listeners */\n destroy(): void;\n\n /** Subscribe to events. Returns unsubscribe function */\n on(event: EventName, handler: (...args: any[]) => void): () => void;\n\n /** Subscribe to event that auto-unsubscribes after first emission */\n once(event: EventName, handler: (...args: any[]) => void): () => void;\n\n /** Unsubscribe from events */\n off(event: EventName, handler: (...args: any[]) => void): void;\n\n /** Check if checkout is currently mounted */\n isMounted(): boolean;\n}\n\n/**\n * PaypercutCheckout static interface (callable and constructable)\n */\nexport interface PaypercutCheckoutStatic {\n /** Callable factory function */\n (options: PaypercutCheckoutOptions): CheckoutInstance;\n\n /** Constructor support */\n new (options: PaypercutCheckoutOptions): CheckoutInstance;\n\n /** SDK version */\n version: string;\n}\n\n","import { Emitter } from './utils/emitter';\nimport { config, isOriginAllowed, getCheckoutOrigin } from './config';\nimport { normalizeLocale } from './types/locales';\nimport {\n PaypercutCheckoutOptions,\n CheckoutInstance,\n PaypercutCheckoutStatic,\n EventName,\n validatePaymentMethods,\n validateWalletOptions,\n validateUIMode,\n} from './types/checkout';\n\n// Re-export types and enums for consumers\nexport type {\n PaypercutCheckoutOptions,\n CheckoutInstance,\n PaypercutCheckoutStatic,\n EventName,\n};\n\nexport {\n UIMode,\n PaymentMethod,\n WalletOption,\n} from './types/checkout';\n\nexport type { LocaleCode, LocaleConfig } from './types/locales';\nexport { LOCALES, getSupportedLocales } from './types/locales';\n\n/**\n * Internal implementation of CheckoutInstance\n */\nclass CheckoutImpl implements CheckoutInstance {\n private emitter = new Emitter<EventName>();\n private mounted = false;\n private destroyed = false;\n private iframe: HTMLIFrameElement | null = null;\n private messageHandler: (evt: MessageEvent) => void;\n\n constructor(private options: PaypercutCheckoutOptions) {\n // Bind message handler\n this.messageHandler = this.onMessage.bind(this);\n window.addEventListener('message', this.messageHandler);\n }\n\n /**\n * Build the iframe source URL with query parameters\n */\n private buildSrc(): string {\n const baseUrl = getCheckoutOrigin(this.options.hostedCheckoutUrl);\n const url = new URL(`/c/${this.options.id}`, baseUrl);\n\n // Add locale parameter\n if (this.options.locale) {\n const normalizedLocale = normalizeLocale(this.options.locale);\n url.searchParams.set('locale', normalizedLocale);\n }\n\n // Add ui_mode parameter\n if (this.options.ui_mode) {\n const validatedUIMode = validateUIMode(this.options.ui_mode);\n if (validatedUIMode) {\n url.searchParams.set('ui_mode', validatedUIMode);\n }\n }\n\n // Add payment_methods parameter\n if (this.options.payment_methods && this.options.payment_methods.length > 0) {\n const validatedMethods = validatePaymentMethods(this.options.payment_methods as string[]);\n url.searchParams.set('payment_methods', validatedMethods.join(','));\n }\n\n // Add wallet_options parameter\n if (this.options.wallet_options && this.options.wallet_options.length > 0) {\n const validatedWallets = validateWalletOptions(this.options.wallet_options as string[]);\n if (validatedWallets.length > 0) {\n url.searchParams.set('wallet_options', validatedWallets.join(','));\n }\n }\n\n return url.toString();\n }\n\n /**\n * Get the container element from selector or HTMLElement\n */\n private getContainer(): HTMLElement {\n const container = typeof this.options.containerId === 'string'\n ? document.querySelector(this.options.containerId)\n : this.options.containerId;\n\n if (!container) {\n throw new Error(`Container not found: ${this.options.containerId}`);\n }\n\n return container as HTMLElement;\n }\n\n /**\n * Handle incoming postMessage events from iframe\n */\n private onMessage(evt: MessageEvent): void {\n // Validate origin against allowed origins (build-time whitelist)\n if (!isOriginAllowed(evt.origin)) {\n console.warn('[PaypercutCheckout] Rejected message from unauthorized origin:', evt.origin, 'Allowed:', config.allowedOrigins);\n return;\n }\n\n // Validate structure\n const data = evt.data;\n if (!data || typeof data !== 'object' || !('type' in data)) {\n return;\n }\n\n // Filter messages by checkout session ID to prevent cross-instance message handling\n // This ensures each checkout instance only processes its own messages\n if (data.checkoutId && data.checkoutId !== this.options.id) {\n return; // Message is for a different checkout instance\n }\n\n // Handle specific events\n switch (data.type) {\n case 'CHECKOUT_LOADED':\n this.emitter.emit('loaded');\n break;\n case 'CHECKOUT_SUCCESS':\n this.emitter.emit('success');\n break;\n case 'CHECKOUT_ERROR':\n this.emitter.emit('error');\n break;\n }\n }\n\n /**\n * Send message to iframe (for future use) SUBMIT FORM if checkout is with custom button\n */\n // private postToIframe(message: any): void {\n // if (!this.iframe?.contentWindow) {\n // console.error('[PaypercutCheckout] Cannot post message: iframe not mounted');\n // return;\n // }\n //\n // const checkoutOrigin = getCheckoutOrigin(this.options.hostedCheckoutUrl);\n // this.iframe.contentWindow.postMessage(message, checkoutOrigin);\n // }\n\n /**\n * Render the checkout iframe into the container\n */\n render(): void {\n if (this.mounted) {\n console.warn('[PaypercutCheckout] Already mounted');\n return;\n }\n\n try {\n const container = this.getContainer();\n\n // Create iframe\n this.iframe = document.createElement('iframe');\n this.iframe.id = 'paypercut-checkout-iframe';\n this.iframe.src = this.buildSrc();\n this.iframe.allow = 'payment *; clipboard-write';\n this.iframe.setAttribute('frameborder', '0');\n\n // Apply default styles - just construct URL and assign to iframe\n Object.assign(this.iframe.style, {\n width: '100%',\n height: '100%',\n border: 'none',\n display: 'block'\n });\n\n // Listen for iframe load event (fallback)\n // This ensures 'loaded' event is always emitted even if hosted checkout\n // doesn't send CHECKOUT_LOADED message\n /*this.iframe.addEventListener('load', () => {\n this.emitter.emit('loaded');\n });*/\n\n container.appendChild(this.iframe);\n this.mounted = true;\n } catch (err) {\n console.error('[PaypercutCheckout] Failed to render:', err);\n throw err;\n }\n }\n\n /**\n * Destroy the checkout instance and cleanup (idempotent)\n */\n destroy(): void {\n // Early return if already destroyed\n if (this.destroyed) {\n return;\n }\n\n // Remove iframe from DOM\n if (this.iframe) {\n try {\n this.iframe.remove();\n this.iframe = null;\n } catch (err) {\n console.error('[PaypercutCheckout] Error removing iframe:', err);\n }\n }\n\n // Only set mounted = false after successful DOM removal\n this.mounted = false;\n this.destroyed = true;\n\n // Cleanup event listeners\n window.removeEventListener('message', this.messageHandler);\n this.emitter.clear();\n }\n\n /**\n * Subscribe to an event\n */\n on(event: EventName, handler: (...args: any[]) => void): () => void {\n return this.emitter.on(event, handler);\n }\n\n /**\n * Subscribe to event that auto-unsubscribes after first emission\n */\n once(event: EventName, handler: (...args: any[]) => void): () => void {\n return this.emitter.once(event, handler);\n }\n\n /**\n * Unsubscribe from an event\n */\n off(event: EventName, handler: (...args: any[]) => void): void {\n this.emitter.off(event, handler);\n }\n\n /**\n * Check if checkout is currently mounted\n */\n isMounted(): boolean {\n return this.mounted;\n }\n}\n\n/**\n * Factory function that works both as callable and constructable.\n * Always returns a new CheckoutImpl instance - no prototype manipulation needed.\n */\nconst PaypercutCheckout: PaypercutCheckoutStatic = function (\n this: unknown,\n options: PaypercutCheckoutOptions\n): CheckoutInstance {\n // Always return a new instance, regardless of how it's called\n return new CheckoutImpl(options);\n} as unknown as PaypercutCheckoutStatic;\n\n// Add static version property\n(PaypercutCheckout as any).version = config.version;\n\n// Export as default and named\nexport default PaypercutCheckout;\nexport { PaypercutCheckout };\n\n"],"names":["Emitter","constructor","this","handlers","Map","on","event","handler","has","set","Set","get","add","off","once","wrappedHandler","args","delete","emit","forEach","h","err","console","error","clear","config","version","defaultCheckoutOrigin","allowedOrigins","LOCALES","bg","code","name","supported","en","de","fr","es","it","pt","nl","pl","ro","cs","hu","el","sv","da","fi","no","ru","uk","sr","hr","sk","sl","zh","ja","ko","th","vi","id","ms","hi","ar","he","tr","af","sq","et","lv","lt","mk","UIMode","PaymentMethod","WalletOption","isValidPaymentMethod","value","Object","values","includes","isValidWalletOption","validateUIMode","mode","warn","join","CheckoutImpl","options","emitter","mounted","destroyed","iframe","messageHandler","onMessage","bind","window","addEventListener","buildSrc","baseUrl","hostedCheckoutUrl","url","URL","locale","normalizedLocale","localeConfig","normalizeLocale","searchParams","ui_mode","validatedUIMode","payment_methods","length","validatedMethods","methods","validated","method","push","CARD","validatePaymentMethods","wallet_options","validatedWallets","option","validateWalletOptions","toString","getContainer","container","containerId","document","querySelector","Error","evt","origin","data","checkoutId","type","render","createElement","src","allow","setAttribute","assign","style","width","height","border","display","appendChild","destroy","remove","removeEventListener","isMounted","PaypercutCheckout"],"mappings":"oDAIaA,EAAb,WAAAC,GACUC,KAAAC,SAAW,IAAIC,GAmEzB,CA3DE,EAAAC,CAAGC,EAAUC,GAOX,OANKL,KAAKC,SAASK,IAAIF,IACrBJ,KAAKC,SAASM,IAAIH,EAAO,IAAII,KAE/BR,KAAKC,SAASQ,IAAIL,GAAQM,IAAIL,GAGvB,IAAML,KAAKW,IAAIP,EAAOC,EAC/B,CAaA,IAAAO,CAAKR,EAAUC,GACb,MAAMQ,EAAiB,IAAIC,KACzBT,KAAWS,GACXd,KAAKW,IAAIP,EAAOS,IAElB,OAAOb,KAAKG,GAAGC,EAAOS,EACxB,CAOA,GAAAF,CAAIP,EAAUC,GACZL,KAAKC,SAASQ,IAAIL,IAAQW,OAAOV,EACnC,CAOA,IAAAW,CAAKZ,KAAaU,GAChBd,KAAKC,SAASQ,IAAIL,IAAQa,QAAQC,IAChC,IACEA,KAAKJ,EACP,CAAE,MAAOK,GACPC,QAAQC,MAAM,sBAAsBjB,aAAkBe,EACxD,GAEJ,CAKA,KAAAG,GACEtB,KAAKC,SAASqB,OAChB,EC9BF,MA8BaC,EA9ByB,CACpCC,QAAS,QAETC,sBAAuB,2BACvBC,eAAgB,CACd,6BC7BG,MAAMC,EAAwC,CAEnDC,GAAM,CAAEC,KAAM,KAAMC,KAAM,YAAaC,WAAW,GAClD,QAAS,CAAEF,KAAM,QAASC,KAAM,uBAAwBC,WAAW,GACnEC,GAAM,CAAEH,KAAM,KAAMC,KAAM,UAAWC,WAAW,GAChD,QAAS,CAAEF,KAAM,QAASC,KAAM,2BAA4BC,WAAW,GAGvE,QAAS,CAAEF,KAAM,QAASC,KAAM,0BAA2BC,WAAW,GACtE,QAAS,CAAEF,KAAM,QAASC,KAAM,mBAAoBC,WAAW,GAC/D,QAAS,CAAEF,KAAM,QAASC,KAAM,sBAAuBC,WAAW,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EE,IAAIhJ,KAAKwF,UAAT,CAKA,GAAIxF,KAAKyF,OACP,IACEzF,KAAKyF,OAAOwD,SACZjJ,KAAKyF,OAAS,IAChB,CAAE,MAAOtE,GACPC,QAAQC,MAAM,6CAA8CF,EAC9D,CAIFnB,KAAKuF,SAAU,EACfvF,KAAKwF,WAAY,EAGjBK,OAAOqD,oBAAoB,UAAWlJ,KAAK0F,gBAC3C1F,KAAKsF,QAAQhE,OAlBb,CAmBF,CAKA,EAAAnB,CAAGC,EAAkBC,GACnB,OAAOL,KAAKsF,QAAQnF,GAAGC,EAAOC,EAChC,CAKA,IAAAO,CAAKR,EAAkBC,GACrB,OAAOL,KAAKsF,QAAQ1E,KAAKR,EAAOC,EAClC,CAKA,GAAAM,CAAIP,EAAkBC,GACpBL,KAAKsF,QAAQ3E,IAAIP,EAAOC,EAC1B,CAKA,SAAA8I,GACE,OAAOnJ,KAAKuF,OACd,EAOF,MAAM6D,EAA6C,SAEjD/D,GAGA,OAAO,IAAID,EAAaC,EAC1B,SAGC+D,EAA0B5H,QAAUD,EAAOC"}
|
|
1
|
+
{"version":3,"file":"paypercut-checkout.iife.min.js","sources":["../src/utils/emitter.ts","../src/config.ts","../src/types/locales.ts","../src/types/checkout.ts","../src/index.ts"],"sourcesContent":["/**\n * Simple event emitter for handling checkout events\n * Supports subscribing, unsubscribing, and emitting events\n */\nexport class Emitter<T extends string = string> {\n private handlers = new Map<T, Set<Function>>();\n\n /**\n * Subscribe to an event\n * @param event - Event name to listen to\n * @param handler - Callback function to execute when event is emitted\n * @returns Unsubscribe function\n */\n on(event: T, handler: Function): () => void {\n if (!this.handlers.has(event)) {\n this.handlers.set(event, new Set());\n }\n this.handlers.get(event)!.add(handler);\n\n // Return unsubscribe function\n return () => this.off(event, handler);\n }\n\n /**\n * Subscribe to an event that auto-unsubscribes after first emission\n *\n * Common use case: waiting for 'loaded' event or handling first 'success'.\n * Without this helper, developers would need to manually unsubscribe inside\n * their handler, which is error-prone and leads to memory leaks if forgotten.\n *\n * @param event - Event name to listen to\n * @param handler - Callback function to execute when event is emitted\n * @returns Unsubscribe function\n */\n once(event: T, handler: Function): () => void {\n const wrappedHandler = (...args: any[]) => {\n handler(...args);\n this.off(event, wrappedHandler);\n };\n return this.on(event, wrappedHandler);\n }\n\n /**\n * Unsubscribe from an event\n * @param event - Event name to stop listening to\n * @param handler - Callback function to remove\n */\n off(event: T, handler: Function): void {\n this.handlers.get(event)?.delete(handler);\n }\n\n /**\n * Emit an event with optional arguments\n * @param event - Event name to emit\n * @param args - Arguments to pass to event handlers\n */\n emit(event: T, ...args: any[]): void {\n this.handlers.get(event)?.forEach(h => {\n try {\n h(...args);\n } catch (err) {\n console.error(`[Emitter] Error in ${event} handler:`, err);\n }\n });\n }\n\n /**\n * Clear all event handlers\n */\n clear(): void {\n this.handlers.clear();\n }\n}\n\n","/**\n * Build-time configuration\n * \n * This file is processed at build time with different values for:\n * - Production build (for merchants)\n * - Internal build (for team development)\n */\n\n/**\n * Build mode - replaced at build time\n */\ndeclare const __BUILD_MODE__: 'production' | 'internal';\n\n/**\n * SDK version - replaced at build time\n */\ndeclare const __VERSION__: string;\n\n/**\n * Configuration interface\n */\nexport interface BuildConfig {\n /** SDK version */\n version: string;\n \n /** Build mode */\n mode: 'production' | 'internal';\n \n /** Default checkout origin (production URL) */\n defaultCheckoutOrigin: string;\n \n /** Allowed origins for postMessage validation */\n allowedOrigins: string[];\n \n /** Whether hostedCheckoutUrl override is allowed */\n allowOriginOverride: boolean;\n}\n\n/**\n * Production configuration (for merchants)\n */\nconst productionConfig: BuildConfig = {\n version: __VERSION__,\n mode: 'production',\n defaultCheckoutOrigin: 'https://buy.paypercut.io',\n allowedOrigins: [\n 'https://buy.paypercut.io'\n ],\n allowOriginOverride: false // ← Merchants CANNOT override\n};\n\n/**\n * Internal configuration (for team development)\n */\nconst internalConfig: BuildConfig = {\n version: __VERSION__,\n mode: 'internal',\n defaultCheckoutOrigin: 'https://buy.paypercut.io',\n allowedOrigins: [\n 'https://buy.paypercut.io',\n 'http://localhost:3000',\n 'http://localhost:3001',\n 'http://127.0.0.1:3000',\n 'http://127.0.0.1:3001'\n ],\n allowOriginOverride: true // ← Team CAN override for testing\n};\n\n/**\n * Active configuration (selected at build time)\n */\nexport const config: BuildConfig = __BUILD_MODE__ === 'internal' \n ? internalConfig \n : productionConfig;\n\n/**\n * Helper to check if origin is allowed\n */\nexport function isOriginAllowed(origin: string): boolean {\n return config.allowedOrigins.includes(origin);\n}\n\n/**\n * Get the checkout origin (with optional override for internal builds)\n */\nexport function getCheckoutOrigin(override?: string): string {\n // Only allow override in internal builds\n if (override && config.allowOriginOverride) {\n return override;\n }\n \n return config.defaultCheckoutOrigin;\n}\n\n","/**\n * Supported locales for Paypercut Checkout\n * \n * @remarks\n * Single source of truth for all supported locale codes.\n * \n * Supported languages:\n * - Bulgarian: 'bg', 'bg-BG'\n * - English: 'en', 'en-GB'\n * - Greek: 'el', 'el-GR'\n * - Romanian: 'ro', 'ro-RO'\n * - Croatian: 'hr', 'hr-HR'\n * - Polish: 'pl', 'pl-PL'\n * - Czech: 'cs', 'cs-CZ'\n * - Slovenian: 'sl', 'sl-SI'\n * - Slovak: 'sk', 'sk-SK'\n * \n * @example\n * ```typescript\n * const checkout = PaypercutCheckout({\n * locale: 'bg' // or 'bg-BG', 'en', 'en-GB', etc.\n * });\n * ```\n */\nexport const LOCALES = [\n 'bg', 'bg-BG',\n 'en', 'en-GB',\n 'el', 'el-GR',\n 'ro', 'ro-RO',\n 'hr', 'hr-HR',\n 'pl', 'pl-PL',\n 'cs', 'cs-CZ',\n 'sl', 'sl-SI',\n 'sk', 'sk-SK',\n] as const;\n\n/**\n * Locale type - union of all supported locale codes plus 'auto'\n * @example\n * ```typescript\n * const locale: Locale = 'bg';\n * const autoLocale: Locale = 'auto';\n * ```\n */\nexport type Locale = typeof LOCALES[number] | 'auto';\n\n/**\n * Fast runtime check using Set for O(1) lookup\n * @internal\n */\nconst LOCALE_SET: ReadonlySet<string> = new Set(LOCALES);\n\n/**\n * Normalize and validate locale\n * \n * @param locale - Locale code to normalize\n * @returns Normalized locale code or 'en' as fallback\n * \n * @remarks\n * - 'auto' or empty → 'en'\n * - Unsupported locale → 'en' with console warning\n * - Supported locale → original value\n * \n * @example\n * ```typescript\n * normalizeLocale('auto') // → 'en'\n * normalizeLocale('bg') // → 'bg'\n * normalizeLocale('de') // → 'en' (with warning)\n * ```\n */\nexport function normalizeLocale(locale: string | Locale): typeof LOCALES[number] | 'en' {\n if (!locale || locale === 'auto') return 'en';\n if (LOCALE_SET.has(locale)) return locale as typeof LOCALES[number];\n console.warn(`[PaypercutCheckout] Locale \"${locale}\" is not supported. Falling back to \"en\".`);\n return 'en';\n}\n\n","import { Locale } from './locales';\n\n/**\n * UI mode for checkout\n */\nexport enum UIMode {\n /** Custom UI mode - merchant provides their own submit button */\n CUSTOM = 'custom',\n /** Embedded mode - checkout embedded in merchant page */\n EMBEDDED = 'embedded',\n /** Hosted mode - full-page checkout experience */\n HOSTED = 'hosted',\n}\n\n/**\n * Type guard for UIMode\n */\nexport function isValidUIMode(value: string): value is UIMode {\n return Object.values(UIMode).includes(value as UIMode);\n}\n\n/**\n * Payment method types\n */\nexport enum PaymentMethod {\n /** Card payment (credit/debit) */\n CARD = 'card',\n}\n\n/**\n * Type guard for PaymentMethod\n */\nexport function isValidPaymentMethod(value: string): value is PaymentMethod {\n return Object.values(PaymentMethod).includes(value as PaymentMethod);\n}\n\n/**\n * Wallet options for digital wallets\n */\nexport enum WalletOption {\n /** Apple Pay */\n APPLE_PAY = 'apple_pay',\n /** Google Pay */\n GOOGLE_PAY = 'google_pay',\n}\n\n/**\n * Type guard for WalletOption\n */\nexport function isValidWalletOption(value: string): value is WalletOption {\n return Object.values(WalletOption).includes(value as WalletOption);\n}\n\n/**\n * Validate payment methods array\n */\nexport function validatePaymentMethods(methods: string[]): PaymentMethod[] {\n const validated: PaymentMethod[] = [];\n \n for (const method of methods) {\n if (isValidPaymentMethod(method)) {\n validated.push(method as PaymentMethod);\n } else {\n console.warn(`[PaypercutCheckout] Invalid payment method: \"${method}\". Skipping.`);\n }\n }\n \n // Default to card if no valid methods\n if (validated.length === 0) {\n console.warn('[PaypercutCheckout] No valid payment methods provided. Defaulting to \"card\".');\n validated.push(PaymentMethod.CARD);\n }\n \n return validated;\n}\n\n/**\n * Validate wallet options array\n */\nexport function validateWalletOptions(options: string[]): WalletOption[] {\n const validated: WalletOption[] = [];\n \n for (const option of options) {\n if (isValidWalletOption(option)) {\n validated.push(option as WalletOption);\n } else {\n console.warn(`[PaypercutCheckout] Invalid wallet option: \"${option}\". Skipping.`);\n }\n }\n \n return validated;\n}\n\n/**\n * Validate UI mode\n */\nexport function validateUIMode(mode: string | undefined): UIMode | undefined {\n if (!mode) {\n return undefined;\n }\n \n if (isValidUIMode(mode)) {\n return mode as UIMode;\n }\n \n console.warn(`[PaypercutCheckout] Invalid ui_mode: \"${mode}\". Valid options: ${Object.values(UIMode).join(', ')}`);\n return undefined;\n}\n\n/**\n * Configuration options for PaypercutCheckout\n */\nexport interface PaypercutCheckoutOptions {\n /** Checkout session identifier (e.g., 'CHK_12345') */\n id: string;\n\n /** CSS selector or HTMLElement where iframe mounts (required) */\n containerId: string | HTMLElement;\n\n /**\n * Optional: Custom hosted checkout URL (only available in internal builds)\n * Production builds will ignore this option for security\n */\n hostedCheckoutUrl?: string;\n\n /**\n * Optional: Locale for checkout UI\n * @default 'en'\n */\n locale?: Locale | string;\n\n /**\n * Optional: UI mode for checkout\n */\n ui_mode?: UIMode | `${UIMode}`;\n\n /**\n * Optional: Payment methods to enable\n * @default ['card']\n */\n payment_methods?: (PaymentMethod | `${PaymentMethod}`)[];\n\n /**\n * Optional: Digital wallet options\n * Can include both or just one\n */\n wallet_options?: (WalletOption | `${WalletOption}`)[];\n\n /**\n * Optional: Show only the payment form without header/footer\n * @default false\n */\n form_only?: boolean;\n}\n\n/**\n * Event names that can be emitted by the checkout\n */\nexport type EventName =\n | 'loaded' // iframe finished loading\n | 'success' // payment successful\n | 'error'; // payment or system error\n\n/**\n * Checkout instance interface\n */\nexport interface CheckoutInstance {\n /** Mount and render the iframe into the container */\n render(): void;\n\n /** Submit payment - sends message to hosted checkout to confirm payment */\n submit(): void;\n\n /** Destroy instance and cleanup all listeners */\n destroy(): void;\n\n /** Subscribe to events. Returns unsubscribe function */\n on(event: EventName, handler: (...args: any[]) => void): () => void;\n\n /** Subscribe to event that auto-unsubscribes after first emission */\n once(event: EventName, handler: (...args: any[]) => void): () => void;\n\n /** Unsubscribe from events */\n off(event: EventName, handler: (...args: any[]) => void): void;\n\n /** Check if checkout is currently mounted */\n isMounted(): boolean;\n}\n\n/**\n * PaypercutCheckout static interface (callable and constructable)\n */\nexport interface PaypercutCheckoutStatic {\n /** Callable factory function */\n (options: PaypercutCheckoutOptions): CheckoutInstance;\n\n /** Constructor support */\n new (options: PaypercutCheckoutOptions): CheckoutInstance;\n\n /** SDK version */\n version: string;\n}\n\n","import { Emitter } from './utils/emitter';\nimport { config, isOriginAllowed, getCheckoutOrigin } from './config';\n\nimport {\n PaypercutCheckoutOptions,\n CheckoutInstance,\n PaypercutCheckoutStatic,\n EventName,\n validatePaymentMethods,\n validateWalletOptions,\n validateUIMode,\n} from './types';\nimport {normalizeLocale} from \"./types\";\n\n// Re-export types and enums for consumers\nexport type {\n PaypercutCheckoutOptions,\n CheckoutInstance,\n PaypercutCheckoutStatic,\n EventName,\n};\n\nexport {\n UIMode,\n PaymentMethod,\n WalletOption,\n} from './types/checkout';\n\nexport type { Locale } from './types/locales';\nexport { LOCALES } from './types/locales';\n\n/**\n * Internal implementation of CheckoutInstance\n */\nclass CheckoutImpl implements CheckoutInstance {\n private emitter = new Emitter<EventName>();\n private mounted = false;\n private destroyed = false;\n private iframe: HTMLIFrameElement | null = null;\n private messageHandler: (evt: MessageEvent) => void;\n\n constructor(private options: PaypercutCheckoutOptions) {\n // Bind message handler\n this.messageHandler = this.onMessage.bind(this);\n window.addEventListener('message', this.messageHandler);\n }\n\n /**\n * Build the iframe source URL with query parameters\n */\n private buildSrc(): string {\n const baseUrl = getCheckoutOrigin(this.options.hostedCheckoutUrl);\n const url = new URL(`/c/${this.options.id}`, baseUrl);\n\n // Add locale parameter\n if (this.options.locale) {\n const normalizedLocale = normalizeLocale(this.options.locale);\n url.searchParams.set('locale', normalizedLocale);\n }\n\n // Add ui_mode parameter\n if (this.options.ui_mode) {\n const validatedUIMode = validateUIMode(this.options.ui_mode);\n if (validatedUIMode) {\n url.searchParams.set('ui_mode', validatedUIMode);\n }\n }\n\n // Add payment_methods parameters (repeated for each method)\n if (this.options.payment_methods && this.options.payment_methods.length > 0) {\n const validatedMethods = validatePaymentMethods(this.options.payment_methods as string[]);\n validatedMethods.forEach(method => {\n url.searchParams.append('payment_methods', method);\n });\n }\n\n // Add wallet_options parameters (repeated for each wallet)\n if (this.options.wallet_options && this.options.wallet_options.length > 0) {\n const validatedWallets = validateWalletOptions(this.options.wallet_options as string[]);\n validatedWallets.forEach(wallet => {\n url.searchParams.append('wallet_options', wallet);\n });\n }\n\n console.log('this.options', this.options);\n\n if (this.options.form_only !== undefined) {\n url.searchParams.set('form_only', String(this.options.form_only));\n }\n\n return url.toString();\n }\n\n /**\n * Get the container element from selector or HTMLElement\n */\n private getContainer(): HTMLElement {\n const container = typeof this.options.containerId === 'string'\n ? document.querySelector(this.options.containerId)\n : this.options.containerId;\n\n if (!container) {\n throw new Error(`Container not found: ${this.options.containerId}`);\n }\n\n return container as HTMLElement;\n }\n\n /**\n * Handle incoming postMessage events from iframe\n */\n private onMessage(evt: MessageEvent): void {\n // Validate origin against allowed origins (build-time whitelist)\n if (!isOriginAllowed(evt.origin)) {\n console.warn('[PaypercutCheckout] Rejected message from unauthorized origin:', evt.origin, 'Allowed:', config.allowedOrigins);\n return;\n }\n\n // Validate structure\n const data = evt.data;\n if (!data || typeof data !== 'object' || !('type' in data)) {\n return;\n }\n\n // Filter messages by checkout session ID to prevent cross-instance message handling\n // This ensures each checkout instance only processes its own messages\n if (data.checkoutId && data.checkoutId !== this.options.id) {\n return; // Message is for a different checkout instance\n }\n\n // Handle specific events\n switch (data.type) {\n case 'CHECKOUT_LOADED':\n this.emitter.emit('loaded');\n break;\n case 'CHECKOUT_SUCCESS':\n this.emitter.emit('success');\n break;\n case 'CHECKOUT_ERROR':\n this.emitter.emit('error');\n break;\n }\n }\n\n /**\n * Render the checkout iframe into the container\n */\n render(): void {\n if (this.mounted) {\n console.warn('[PaypercutCheckout] Already mounted');\n return;\n }\n\n try {\n const container = this.getContainer();\n\n // Create iframe\n this.iframe = document.createElement('iframe');\n this.iframe.id = 'paypercut-checkout-iframe';\n this.iframe.src = this.buildSrc();\n this.iframe.allow = 'payment *; clipboard-write';\n this.iframe.setAttribute('frameborder', '0');\n\n // Apply default styles - just construct URL and assign to iframe\n Object.assign(this.iframe.style, {\n width: '100%',\n height: '100%',\n border: 'none',\n display: 'block'\n });\n\n // Listen for iframe load event (fallback)\n // This ensures 'loaded' event is always emitted even if hosted checkout\n // doesn't send CHECKOUT_LOADED message\n /*this.iframe.addEventListener('load', () => {\n this.emitter.emit('loaded');\n });*/\n\n container.appendChild(this.iframe);\n this.mounted = true;\n } catch (err) {\n console.error('[PaypercutCheckout] Failed to render:', err);\n throw err;\n }\n }\n\n /**\n * Submit payment - sends message to hosted checkout to confirm payment\n */\n submit(): void {\n if (!this.mounted) {\n console.warn('[PaypercutCheckout] Cannot submit: checkout not mounted');\n return;\n }\n\n try {\n this.postToIframe({\n type: 'START_PROCESSING',\n checkoutId: this.options.id,\n });\n console.log('[PaypercutCheckout] Submit payment message sent');\n } catch (err) {\n console.error('[PaypercutCheckout] Failed to submit payment:', err);\n throw err;\n }\n }\n\n /**\n * Send message to iframe - used for submit and other commands\n */\n private postToIframe(message: any): void {\n if (!this.iframe?.contentWindow) {\n console.error('[PaypercutCheckout] Cannot post message: iframe not mounted');\n return;\n }\n\n const checkoutOrigin = getCheckoutOrigin(this.options.hostedCheckoutUrl);\n this.iframe.contentWindow.postMessage(message, checkoutOrigin);\n }\n\n /**\n * Destroy the checkout instance and cleanup (idempotent)\n */\n destroy(): void {\n // Early return if already destroyed\n if (this.destroyed) {\n return;\n }\n\n // Remove iframe from DOM\n if (this.iframe) {\n try {\n this.iframe.remove();\n this.iframe = null;\n } catch (err) {\n console.error('[PaypercutCheckout] Error removing iframe:', err);\n }\n }\n\n // Only set mounted = false after successful DOM removal\n this.mounted = false;\n this.destroyed = true;\n\n // Cleanup event listeners\n window.removeEventListener('message', this.messageHandler);\n this.emitter.clear();\n }\n\n /**\n * Subscribe to an event\n */\n on(event: EventName, handler: (...args: any[]) => void): () => void {\n return this.emitter.on(event, handler);\n }\n\n /**\n * Subscribe to event that auto-unsubscribes after first emission\n */\n once(event: EventName, handler: (...args: any[]) => void): () => void {\n return this.emitter.once(event, handler);\n }\n\n /**\n * Unsubscribe from an event\n */\n off(event: EventName, handler: (...args: any[]) => void): void {\n this.emitter.off(event, handler);\n }\n\n /**\n * Check if checkout is currently mounted\n */\n isMounted(): boolean {\n return this.mounted;\n }\n}\n\n/**\n * Factory function that works both as callable and constructable.\n * Always returns a new CheckoutImpl instance - no prototype manipulation needed.\n */\nconst PaypercutCheckout: PaypercutCheckoutStatic = function (\n this: unknown,\n options: PaypercutCheckoutOptions\n): CheckoutInstance {\n // Always return a new instance, regardless of how it's called\n return new CheckoutImpl(options);\n} as unknown as PaypercutCheckoutStatic;\n\n// Add static version property\n(PaypercutCheckout as any).version = config.version;\n\n// Export as default and named\nexport default PaypercutCheckout;\nexport { PaypercutCheckout };\n\n"],"names":["Emitter","constructor","this","handlers","Map","on","event","handler","has","set","Set","get","add","off","once","wrappedHandler","args","delete","emit","forEach","h","err","console","error","clear","config","version","defaultCheckoutOrigin","allowedOrigins","getCheckoutOrigin","override","LOCALE_SET","UIMode","PaymentMethod","WalletOption","isValidPaymentMethod","value","Object","values","includes","isValidWalletOption","validateUIMode","mode","warn","join","CheckoutImpl","options","emitter","mounted","destroyed","iframe","messageHandler","onMessage","bind","window","addEventListener","buildSrc","baseUrl","hostedCheckoutUrl","url","URL","id","locale","normalizedLocale","searchParams","ui_mode","validatedUIMode","payment_methods","length","methods","validated","method","push","CARD","validatePaymentMethods","append","wallet_options","option","validateWalletOptions","wallet","log","undefined","form_only","String","toString","getContainer","container","containerId","document","querySelector","Error","evt","origin","data","checkoutId","type","render","createElement","src","allow","setAttribute","assign","style","width","height","border","display","appendChild","submit","postToIframe","message","contentWindow","checkoutOrigin","postMessage","destroy","remove","removeEventListener","isMounted","PaypercutCheckout"],"mappings":"oDAIaA,EAAb,WAAAC,GACUC,KAAAC,SAAW,IAAIC,GAmEzB,CA3DE,EAAAC,CAAGC,EAAUC,GAOX,OANKL,KAAKC,SAASK,IAAIF,IACrBJ,KAAKC,SAASM,IAAIH,EAAO,IAAII,KAE/BR,KAAKC,SAASQ,IAAIL,GAAQM,IAAIL,GAGvB,IAAML,KAAKW,IAAIP,EAAOC,EAC/B,CAaA,IAAAO,CAAKR,EAAUC,GACb,MAAMQ,EAAiB,IAAIC,KACzBT,KAAWS,GACXd,KAAKW,IAAIP,EAAOS,IAElB,OAAOb,KAAKG,GAAGC,EAAOS,EACxB,CAOA,GAAAF,CAAIP,EAAUC,GACZL,KAAKC,SAASQ,IAAIL,IAAQW,OAAOV,EACnC,CAOA,IAAAW,CAAKZ,KAAaU,GAChBd,KAAKC,SAASQ,IAAIL,IAAQa,QAAQC,IAChC,IACEA,KAAKJ,EACP,CAAE,MAAOK,GACPC,QAAQC,MAAM,sBAAsBjB,aAAkBe,EACxD,GAEJ,CAKA,KAAAG,GACEtB,KAAKC,SAASqB,OAChB,EC9BF,MA8BaC,EA9ByB,CACpCC,QAAS,QAETC,sBAAuB,2BACvBC,eAAgB,CACd,6BAuCE,SAAUC,EAAkBC,GAMhC,OAAOL,EAAOE,qBAChB,CCpEO,MA0BDI,EAAkC,IAAIrB,IA1BrB,CACrB,KAAM,QACN,KAAM,QACN,KAAM,QACN,KAAM,QACN,KAAM,QACN,KAA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D,GAEP,MADAC,QAAQC,MAAM,gDAAiDF,GACzDA,CACR,MAbEC,QAAQqB,KAAK,0DAcjB,CAKQ,YAAAkE,CAAaC,GACnB,IAAK5G,KAAKgD,QAAQ6D,cAEhB,YADAzF,QAAQC,MAAM,+DAIhB,MAAMyF,EAAiBnF,EAAkB3B,KAAK4C,QAAQY,mBACtDxD,KAAKgD,OAAO6D,cAAcE,YAAYH,EAASE,EACjD,CAKA,OAAAE,GAEE,IAAIhH,KAAK+C,UAAT,CAKA,GAAI/C,KAAKgD,OACP,IACEhD,KAAKgD,OAAOiE,SACZjH,KAAKgD,OAAS,IAChB,CAAE,MAAO7B,GACPC,QAAQC,MAAM,6CAA8CF,EAC9D,CAIFnB,KAAK8C,SAAU,EACf9C,KAAK+C,WAAY,EAGjBK,OAAO8D,oBAAoB,UAAWlH,KAAKiD,gBAC3CjD,KAAK6C,QAAQvB,OAlBb,CAmBF,CAKA,EAAAnB,CAAGC,EAAkBC,GACnB,OAAOL,KAAK6C,QAAQ1C,GAAGC,EAAOC,EAChC,CAKA,IAAAO,CAAKR,EAAkBC,GACrB,OAAOL,KAAK6C,QAAQjC,KAAKR,EAAOC,EAClC,CAKA,GAAAM,CAAIP,EAAkBC,GACpBL,KAAK6C,QAAQlC,IAAIP,EAAOC,EAC1B,CAKA,SAAA8G,GACE,OAAOnH,KAAK8C,OACd,EAOF,MAAMsE,EAA6C,SAEjDxE,GAGA,OAAO,IAAID,EAAaC,EAC1B,SAGCwE,EAA0B5F,QAAUD,EAAOC"}
|
package/package.json
CHANGED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
var PaypercutCheckout=function(){"use strict";class t{constructor(){this.handlers=new Map}on(t,e){return this.handlers.has(t)||this.handlers.set(t,new Set),this.handlers.get(t).add(e),()=>this.off(t,e)}once(t,e){const o=(...n)=>{e(...n),this.off(t,o)};return this.on(t,o)}off(t,e){this.handlers.get(t)?.delete(e)}emit(t,...e){this.handlers.get(t)?.forEach(o=>{try{o(...e)}catch(e){console.error(`[Emitter] Error in ${t} handler:`,e)}})}clear(){this.handlers.clear()}}const e={version:"1.0.0",mode:"internal",defaultCheckoutOrigin:"https://buy.paypercut.io",allowedOrigins:["https://buy.paypercut.io","http://localhost:3000","http://localhost:3001","http://127.0.0.1:3000","http://127.0.0.1:3001"],allowOriginOverride:!0};function o(t){return t&&e.allowOriginOverride?t:e.defaultCheckoutOrigin}const n=new Set(["bg","bg-BG","en","en-GB","el","el-GR","ro","ro-RO","hr","hr-HR","pl","pl-PL","cs","cs-CZ","sl","sl-SI","sk","sk-SK"]);var s,i,r;function a(t){return Object.values(i).includes(t)}function c(t){return Object.values(r).includes(t)}function h(t){var e;if(t)return e=t,Object.values(s).includes(e)?t:void console.warn(`[PaypercutCheckout] Invalid ui_mode: "${t}". Valid options: ${Object.values(s).join(", ")}`)}!function(t){t.CUSTOM="custom",t.EMBEDDED="embedded",t.HOSTED="hosted"}(s||(s={})),function(t){t.CARD="card"}(i||(i={})),function(t){t.APPLE_PAY="apple_pay",t.GOOGLE_PAY="google_pay"}(r||(r={}));class l{constructor(e){this.options=e,this.emitter=new t,this.mounted=!1,this.destroyed=!1,this.iframe=null,this.messageHandler=this.onMessage.bind(this),window.addEventListener("message",this.messageHandler)}buildSrc(){const t=o(this.options.hostedCheckoutUrl),e=new URL(`/c/${this.options.id}`,t);if(this.options.locale){const t=(s=this.options.locale)&&"auto"!==s?n.has(s)?s:(console.warn(`[PaypercutCheckout] Locale "${s}" is not supported. Falling back to "en".`),"en"):"en";e.searchParams.set("locale",t)}var s;if(this.options.ui_mode){const t=h(this.options.ui_mode);t&&e.searchParams.set("ui_mode",t)}if(this.options.payment_methods&&this.options.payment_methods.length>0){(function(t){const e=[];for(const o of t)a(o)?e.push(o):console.warn(`[PaypercutCheckout] Invalid payment method: "${o}". Skipping.`);return 0===e.length&&(console.warn('[PaypercutCheckout] No valid payment methods provided. Defaulting to "card".'),e.push(i.CARD)),e})(this.options.payment_methods).forEach(t=>{e.searchParams.append("payment_methods",t)})}if(this.options.wallet_options&&this.options.wallet_options.length>0){(function(t){const e=[];for(const o of t)c(o)?e.push(o):console.warn(`[PaypercutCheckout] Invalid wallet option: "${o}". Skipping.`);return e})(this.options.wallet_options).forEach(t=>{e.searchParams.append("wallet_options",t)})}return console.log("this.options",this.options),void 0!==this.options.form_only&&e.searchParams.set("form_only",String(this.options.form_only)),e.toString()}getContainer(){const t="string"==typeof this.options.containerId?document.querySelector(this.options.containerId):this.options.containerId;if(!t)throw new Error(`Container not found: ${this.options.containerId}`);return t}onMessage(t){if(o=t.origin,!e.allowedOrigins.includes(o))return void console.warn("[PaypercutCheckout] Rejected message from unauthorized origin:",t.origin,"Allowed:",e.allowedOrigins);var o;const n=t.data;if(n&&"object"==typeof n&&"type"in n&&(!n.checkoutId||n.checkoutId===this.options.id))switch(n.type){case"CHECKOUT_LOADED":this.emitter.emit("loaded");break;case"CHECKOUT_SUCCESS":this.emitter.emit("success");break;case"CHECKOUT_ERROR":this.emitter.emit("error")}}render(){if(this.mounted)console.warn("[PaypercutCheckout] Already mounted");else try{const t=this.getContainer();this.iframe=document.createElement("iframe"),this.iframe.id="paypercut-checkout-iframe",this.iframe.src=this.buildSrc(),this.iframe.allow="payment *; clipboard-write",this.iframe.setAttribute("frameborder","0"),Object.assign(this.iframe.style,{width:"100%",height:"100%",border:"none",display:"block"}),t.appendChild(this.iframe),this.mounted=!0}catch(t){throw console.error("[PaypercutCheckout] Failed to render:",t),t}}submit(){if(this.mounted)try{this.postToIframe({type:"START_PROCESSING",checkoutId:this.options.id}),console.log("[PaypercutCheckout] Submit payment message sent")}catch(t){throw console.error("[PaypercutCheckout] Failed to submit payment:",t),t}else console.warn("[PaypercutCheckout] Cannot submit: checkout not mounted")}postToIframe(t){if(!this.iframe?.contentWindow)return void console.error("[PaypercutCheckout] Cannot post message: iframe not mounted");const e=o(this.options.hostedCheckoutUrl);this.iframe.contentWindow.postMessage(t,e)}destroy(){if(!this.destroyed){if(this.iframe)try{this.iframe.remove(),this.iframe=null}catch(t){console.error("[PaypercutCheckout] Error removing iframe:",t)}this.mounted=!1,this.destroyed=!0,window.removeEventListener("message",this.messageHandler),this.emitter.clear()}}on(t,e){return this.emitter.on(t,e)}once(t,e){return this.emitter.once(t,e)}off(t,e){this.emitter.off(t,e)}isMounted(){return this.mounted}}const d=function(t){return new l(t)};return d.version=e.version,console.warn(`\n╔═══════════════════════════════════════════════════════════════╗\n║ ⚠️ PAYPERCUT CHECKOUT SDK - INTERNAL BUILD ║\n╚═══════════════════════════════════════════════════════════════╝\n\nThis is an INTERNAL development build with relaxed security settings.\n\n⚠️ DO NOT USE IN PRODUCTION!\n\nThis build:\n • Allows localhost origins for development\n • Enables hostedCheckoutUrl override\n • Has verbose logging enabled\n\nFor production use, install the latest version:\n npm install @paypercut/checkout-js@latest\n\nVersion: ${e.version}\nMode: ${e.mode}\nAllowed origins: ${e.allowedOrigins.join(", ")}\n `),d}();
|
|
2
|
-
//# sourceMappingURL=paypercut-checkout-dev.iife.min.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"paypercut-checkout-dev.iife.min.js","sources":["../src/utils/emitter.ts","../src/config.ts","../src/types/locales.ts","../src/types/checkout.ts","../src/index.ts","../src/iife.ts"],"sourcesContent":["/**\n * Simple event emitter for handling checkout events\n * Supports subscribing, unsubscribing, and emitting events\n */\nexport class Emitter<T extends string = string> {\n private handlers = new Map<T, Set<Function>>();\n\n /**\n * Subscribe to an event\n * @param event - Event name to listen to\n * @param handler - Callback function to execute when event is emitted\n * @returns Unsubscribe function\n */\n on(event: T, handler: Function): () => void {\n if (!this.handlers.has(event)) {\n this.handlers.set(event, new Set());\n }\n this.handlers.get(event)!.add(handler);\n\n // Return unsubscribe function\n return () => this.off(event, handler);\n }\n\n /**\n * Subscribe to an event that auto-unsubscribes after first emission\n *\n * Common use case: waiting for 'loaded' event or handling first 'success'.\n * Without this helper, developers would need to manually unsubscribe inside\n * their handler, which is error-prone and leads to memory leaks if forgotten.\n *\n * @param event - Event name to listen to\n * @param handler - Callback function to execute when event is emitted\n * @returns Unsubscribe function\n */\n once(event: T, handler: Function): () => void {\n const wrappedHandler = (...args: any[]) => {\n handler(...args);\n this.off(event, wrappedHandler);\n };\n return this.on(event, wrappedHandler);\n }\n\n /**\n * Unsubscribe from an event\n * @param event - Event name to stop listening to\n * @param handler - Callback function to remove\n */\n off(event: T, handler: Function): void {\n this.handlers.get(event)?.delete(handler);\n }\n\n /**\n * Emit an event with optional arguments\n * @param event - Event name to emit\n * @param args - Arguments to pass to event handlers\n */\n emit(event: T, ...args: any[]): void {\n this.handlers.get(event)?.forEach(h => {\n try {\n h(...args);\n } catch (err) {\n console.error(`[Emitter] Error in ${event} handler:`, err);\n }\n });\n }\n\n /**\n * Clear all event handlers\n */\n clear(): void {\n this.handlers.clear();\n }\n}\n\n","/**\n * Build-time configuration\n * \n * This file is processed at build time with different values for:\n * - Production build (for merchants)\n * - Internal build (for team development)\n */\n\n/**\n * Build mode - replaced at build time\n */\ndeclare const __BUILD_MODE__: 'production' | 'internal';\n\n/**\n * SDK version - replaced at build time\n */\ndeclare const __VERSION__: string;\n\n/**\n * Configuration interface\n */\nexport interface BuildConfig {\n /** SDK version */\n version: string;\n \n /** Build mode */\n mode: 'production' | 'internal';\n \n /** Default checkout origin (production URL) */\n defaultCheckoutOrigin: string;\n \n /** Allowed origins for postMessage validation */\n allowedOrigins: string[];\n \n /** Whether hostedCheckoutUrl override is allowed */\n allowOriginOverride: boolean;\n}\n\n/**\n * Production configuration (for merchants)\n */\nconst productionConfig: BuildConfig = {\n version: __VERSION__,\n mode: 'production',\n defaultCheckoutOrigin: 'https://buy.paypercut.io',\n allowedOrigins: [\n 'https://buy.paypercut.io'\n ],\n allowOriginOverride: false // ← Merchants CANNOT override\n};\n\n/**\n * Internal configuration (for team development)\n */\nconst internalConfig: BuildConfig = {\n version: __VERSION__,\n mode: 'internal',\n defaultCheckoutOrigin: 'https://buy.paypercut.io',\n allowedOrigins: [\n 'https://buy.paypercut.io',\n 'http://localhost:3000',\n 'http://localhost:3001',\n 'http://127.0.0.1:3000',\n 'http://127.0.0.1:3001'\n ],\n allowOriginOverride: true // ← Team CAN override for testing\n};\n\n/**\n * Active configuration (selected at build time)\n */\nexport const config: BuildConfig = __BUILD_MODE__ === 'internal' \n ? internalConfig \n : productionConfig;\n\n/**\n * Helper to check if origin is allowed\n */\nexport function isOriginAllowed(origin: string): boolean {\n return config.allowedOrigins.includes(origin);\n}\n\n/**\n * Get the checkout origin (with optional override for internal builds)\n */\nexport function getCheckoutOrigin(override?: string): string {\n // Only allow override in internal builds\n if (override && config.allowOriginOverride) {\n return override;\n }\n \n return config.defaultCheckoutOrigin;\n}\n\n","/**\n * Supported locales for Paypercut Checkout\n * \n * @remarks\n * Single source of truth for all supported locale codes.\n * \n * Supported languages:\n * - Bulgarian: 'bg', 'bg-BG'\n * - English: 'en', 'en-GB'\n * - Greek: 'el', 'el-GR'\n * - Romanian: 'ro', 'ro-RO'\n * - Croatian: 'hr', 'hr-HR'\n * - Polish: 'pl', 'pl-PL'\n * - Czech: 'cs', 'cs-CZ'\n * - Slovenian: 'sl', 'sl-SI'\n * - Slovak: 'sk', 'sk-SK'\n * \n * @example\n * ```typescript\n * const checkout = PaypercutCheckout({\n * locale: 'bg' // or 'bg-BG', 'en', 'en-GB', etc.\n * });\n * ```\n */\nexport const LOCALES = [\n 'bg', 'bg-BG',\n 'en', 'en-GB',\n 'el', 'el-GR',\n 'ro', 'ro-RO',\n 'hr', 'hr-HR',\n 'pl', 'pl-PL',\n 'cs', 'cs-CZ',\n 'sl', 'sl-SI',\n 'sk', 'sk-SK',\n] as const;\n\n/**\n * Locale type - union of all supported locale codes plus 'auto'\n * @example\n * ```typescript\n * const locale: Locale = 'bg';\n * const autoLocale: Locale = 'auto';\n * ```\n */\nexport type Locale = typeof LOCALES[number] | 'auto';\n\n/**\n * Fast runtime check using Set for O(1) lookup\n * @internal\n */\nconst LOCALE_SET: ReadonlySet<string> = new Set(LOCALES);\n\n/**\n * Normalize and validate locale\n * \n * @param locale - Locale code to normalize\n * @returns Normalized locale code or 'en' as fallback\n * \n * @remarks\n * - 'auto' or empty → 'en'\n * - Unsupported locale → 'en' with console warning\n * - Supported locale → original value\n * \n * @example\n * ```typescript\n * normalizeLocale('auto') // → 'en'\n * normalizeLocale('bg') // → 'bg'\n * normalizeLocale('de') // → 'en' (with warning)\n * ```\n */\nexport function normalizeLocale(locale: string | Locale): typeof LOCALES[number] | 'en' {\n if (!locale || locale === 'auto') return 'en';\n if (LOCALE_SET.has(locale)) return locale as typeof LOCALES[number];\n console.warn(`[PaypercutCheckout] Locale \"${locale}\" is not supported. Falling back to \"en\".`);\n return 'en';\n}\n\n","import { Locale } from './locales';\n\n/**\n * UI mode for checkout\n */\nexport enum UIMode {\n /** Custom UI mode - merchant provides their own submit button */\n CUSTOM = 'custom',\n /** Embedded mode - checkout embedded in merchant page */\n EMBEDDED = 'embedded',\n /** Hosted mode - full-page checkout experience */\n HOSTED = 'hosted',\n}\n\n/**\n * Type guard for UIMode\n */\nexport function isValidUIMode(value: string): value is UIMode {\n return Object.values(UIMode).includes(value as UIMode);\n}\n\n/**\n * Payment method types\n */\nexport enum PaymentMethod {\n /** Card payment (credit/debit) */\n CARD = 'card',\n}\n\n/**\n * Type guard for PaymentMethod\n */\nexport function isValidPaymentMethod(value: string): value is PaymentMethod {\n return Object.values(PaymentMethod).includes(value as PaymentMethod);\n}\n\n/**\n * Wallet options for digital wallets\n */\nexport enum WalletOption {\n /** Apple Pay */\n APPLE_PAY = 'apple_pay',\n /** Google Pay */\n GOOGLE_PAY = 'google_pay',\n}\n\n/**\n * Type guard for WalletOption\n */\nexport function isValidWalletOption(value: string): value is WalletOption {\n return Object.values(WalletOption).includes(value as WalletOption);\n}\n\n/**\n * Validate payment methods array\n */\nexport function validatePaymentMethods(methods: string[]): PaymentMethod[] {\n const validated: PaymentMethod[] = [];\n \n for (const method of methods) {\n if (isValidPaymentMethod(method)) {\n validated.push(method as PaymentMethod);\n } else {\n console.warn(`[PaypercutCheckout] Invalid payment method: \"${method}\". Skipping.`);\n }\n }\n \n // Default to card if no valid methods\n if (validated.length === 0) {\n console.warn('[PaypercutCheckout] No valid payment methods provided. Defaulting to \"card\".');\n validated.push(PaymentMethod.CARD);\n }\n \n return validated;\n}\n\n/**\n * Validate wallet options array\n */\nexport function validateWalletOptions(options: string[]): WalletOption[] {\n const validated: WalletOption[] = [];\n \n for (const option of options) {\n if (isValidWalletOption(option)) {\n validated.push(option as WalletOption);\n } else {\n console.warn(`[PaypercutCheckout] Invalid wallet option: \"${option}\". Skipping.`);\n }\n }\n \n return validated;\n}\n\n/**\n * Validate UI mode\n */\nexport function validateUIMode(mode: string | undefined): UIMode | undefined {\n if (!mode) {\n return undefined;\n }\n \n if (isValidUIMode(mode)) {\n return mode as UIMode;\n }\n \n console.warn(`[PaypercutCheckout] Invalid ui_mode: \"${mode}\". Valid options: ${Object.values(UIMode).join(', ')}`);\n return undefined;\n}\n\n/**\n * Configuration options for PaypercutCheckout\n */\nexport interface PaypercutCheckoutOptions {\n /** Checkout session identifier (e.g., 'CHK_12345') */\n id: string;\n\n /** CSS selector or HTMLElement where iframe mounts (required) */\n containerId: string | HTMLElement;\n\n /**\n * Optional: Custom hosted checkout URL (only available in internal builds)\n * Production builds will ignore this option for security\n */\n hostedCheckoutUrl?: string;\n\n /**\n * Optional: Locale for checkout UI\n * @default 'en'\n */\n locale?: Locale | string;\n\n /**\n * Optional: UI mode for checkout\n */\n ui_mode?: UIMode | `${UIMode}`;\n\n /**\n * Optional: Payment methods to enable\n * @default ['card']\n */\n payment_methods?: (PaymentMethod | `${PaymentMethod}`)[];\n\n /**\n * Optional: Digital wallet options\n * Can include both or just one\n */\n wallet_options?: (WalletOption | `${WalletOption}`)[];\n\n /**\n * Optional: Show only the payment form without header/footer\n * @default false\n */\n form_only?: boolean;\n}\n\n/**\n * Event names that can be emitted by the checkout\n */\nexport type EventName =\n | 'loaded' // iframe finished loading\n | 'success' // payment successful\n | 'error'; // payment or system error\n\n/**\n * Checkout instance interface\n */\nexport interface CheckoutInstance {\n /** Mount and render the iframe into the container */\n render(): void;\n\n /** Submit payment - sends message to hosted checkout to confirm payment */\n submit(): void;\n\n /** Destroy instance and cleanup all listeners */\n destroy(): void;\n\n /** Subscribe to events. Returns unsubscribe function */\n on(event: EventName, handler: (...args: any[]) => void): () => void;\n\n /** Subscribe to event that auto-unsubscribes after first emission */\n once(event: EventName, handler: (...args: any[]) => void): () => void;\n\n /** Unsubscribe from events */\n off(event: EventName, handler: (...args: any[]) => void): void;\n\n /** Check if checkout is currently mounted */\n isMounted(): boolean;\n}\n\n/**\n * PaypercutCheckout static interface (callable and constructable)\n */\nexport interface PaypercutCheckoutStatic {\n /** Callable factory function */\n (options: PaypercutCheckoutOptions): CheckoutInstance;\n\n /** Constructor support */\n new (options: PaypercutCheckoutOptions): CheckoutInstance;\n\n /** SDK version */\n version: string;\n}\n\n","import { Emitter } from './utils/emitter';\nimport { config, isOriginAllowed, getCheckoutOrigin } from './config';\n\nimport {\n PaypercutCheckoutOptions,\n CheckoutInstance,\n PaypercutCheckoutStatic,\n EventName,\n validatePaymentMethods,\n validateWalletOptions,\n validateUIMode,\n} from './types';\nimport {normalizeLocale} from \"./types\";\n\n// Re-export types and enums for consumers\nexport type {\n PaypercutCheckoutOptions,\n CheckoutInstance,\n PaypercutCheckoutStatic,\n EventName,\n};\n\nexport {\n UIMode,\n PaymentMethod,\n WalletOption,\n} from './types/checkout';\n\nexport type { Locale } from './types/locales';\nexport { LOCALES } from './types/locales';\n\n/**\n * Internal implementation of CheckoutInstance\n */\nclass CheckoutImpl implements CheckoutInstance {\n private emitter = new Emitter<EventName>();\n private mounted = false;\n private destroyed = false;\n private iframe: HTMLIFrameElement | null = null;\n private messageHandler: (evt: MessageEvent) => void;\n\n constructor(private options: PaypercutCheckoutOptions) {\n // Bind message handler\n this.messageHandler = this.onMessage.bind(this);\n window.addEventListener('message', this.messageHandler);\n }\n\n /**\n * Build the iframe source URL with query parameters\n */\n private buildSrc(): string {\n const baseUrl = getCheckoutOrigin(this.options.hostedCheckoutUrl);\n const url = new URL(`/c/${this.options.id}`, baseUrl);\n\n // Add locale parameter\n if (this.options.locale) {\n const normalizedLocale = normalizeLocale(this.options.locale);\n url.searchParams.set('locale', normalizedLocale);\n }\n\n // Add ui_mode parameter\n if (this.options.ui_mode) {\n const validatedUIMode = validateUIMode(this.options.ui_mode);\n if (validatedUIMode) {\n url.searchParams.set('ui_mode', validatedUIMode);\n }\n }\n\n // Add payment_methods parameters (repeated for each method)\n if (this.options.payment_methods && this.options.payment_methods.length > 0) {\n const validatedMethods = validatePaymentMethods(this.options.payment_methods as string[]);\n validatedMethods.forEach(method => {\n url.searchParams.append('payment_methods', method);\n });\n }\n\n // Add wallet_options parameters (repeated for each wallet)\n if (this.options.wallet_options && this.options.wallet_options.length > 0) {\n const validatedWallets = validateWalletOptions(this.options.wallet_options as string[]);\n validatedWallets.forEach(wallet => {\n url.searchParams.append('wallet_options', wallet);\n });\n }\n\n console.log('this.options', this.options);\n\n if (this.options.form_only !== undefined) {\n url.searchParams.set('form_only', String(this.options.form_only));\n }\n\n return url.toString();\n }\n\n /**\n * Get the container element from selector or HTMLElement\n */\n private getContainer(): HTMLElement {\n const container = typeof this.options.containerId === 'string'\n ? document.querySelector(this.options.containerId)\n : this.options.containerId;\n\n if (!container) {\n throw new Error(`Container not found: ${this.options.containerId}`);\n }\n\n return container as HTMLElement;\n }\n\n /**\n * Handle incoming postMessage events from iframe\n */\n private onMessage(evt: MessageEvent): void {\n // Validate origin against allowed origins (build-time whitelist)\n if (!isOriginAllowed(evt.origin)) {\n console.warn('[PaypercutCheckout] Rejected message from unauthorized origin:', evt.origin, 'Allowed:', config.allowedOrigins);\n return;\n }\n\n // Validate structure\n const data = evt.data;\n if (!data || typeof data !== 'object' || !('type' in data)) {\n return;\n }\n\n // Filter messages by checkout session ID to prevent cross-instance message handling\n // This ensures each checkout instance only processes its own messages\n if (data.checkoutId && data.checkoutId !== this.options.id) {\n return; // Message is for a different checkout instance\n }\n\n // Handle specific events\n switch (data.type) {\n case 'CHECKOUT_LOADED':\n this.emitter.emit('loaded');\n break;\n case 'CHECKOUT_SUCCESS':\n this.emitter.emit('success');\n break;\n case 'CHECKOUT_ERROR':\n this.emitter.emit('error');\n break;\n }\n }\n\n /**\n * Render the checkout iframe into the container\n */\n render(): void {\n if (this.mounted) {\n console.warn('[PaypercutCheckout] Already mounted');\n return;\n }\n\n try {\n const container = this.getContainer();\n\n // Create iframe\n this.iframe = document.createElement('iframe');\n this.iframe.id = 'paypercut-checkout-iframe';\n this.iframe.src = this.buildSrc();\n this.iframe.allow = 'payment *; clipboard-write';\n this.iframe.setAttribute('frameborder', '0');\n\n // Apply default styles - just construct URL and assign to iframe\n Object.assign(this.iframe.style, {\n width: '100%',\n height: '100%',\n border: 'none',\n display: 'block'\n });\n\n // Listen for iframe load event (fallback)\n // This ensures 'loaded' event is always emitted even if hosted checkout\n // doesn't send CHECKOUT_LOADED message\n /*this.iframe.addEventListener('load', () => {\n this.emitter.emit('loaded');\n });*/\n\n container.appendChild(this.iframe);\n this.mounted = true;\n } catch (err) {\n console.error('[PaypercutCheckout] Failed to render:', err);\n throw err;\n }\n }\n\n /**\n * Submit payment - sends message to hosted checkout to confirm payment\n */\n submit(): void {\n if (!this.mounted) {\n console.warn('[PaypercutCheckout] Cannot submit: checkout not mounted');\n return;\n }\n\n try {\n this.postToIframe({\n type: 'START_PROCESSING',\n checkoutId: this.options.id,\n });\n console.log('[PaypercutCheckout] Submit payment message sent');\n } catch (err) {\n console.error('[PaypercutCheckout] Failed to submit payment:', err);\n throw err;\n }\n }\n\n /**\n * Send message to iframe - used for submit and other commands\n */\n private postToIframe(message: any): void {\n if (!this.iframe?.contentWindow) {\n console.error('[PaypercutCheckout] Cannot post message: iframe not mounted');\n return;\n }\n\n const checkoutOrigin = getCheckoutOrigin(this.options.hostedCheckoutUrl);\n this.iframe.contentWindow.postMessage(message, checkoutOrigin);\n }\n\n /**\n * Destroy the checkout instance and cleanup (idempotent)\n */\n destroy(): void {\n // Early return if already destroyed\n if (this.destroyed) {\n return;\n }\n\n // Remove iframe from DOM\n if (this.iframe) {\n try {\n this.iframe.remove();\n this.iframe = null;\n } catch (err) {\n console.error('[PaypercutCheckout] Error removing iframe:', err);\n }\n }\n\n // Only set mounted = false after successful DOM removal\n this.mounted = false;\n this.destroyed = true;\n\n // Cleanup event listeners\n window.removeEventListener('message', this.messageHandler);\n this.emitter.clear();\n }\n\n /**\n * Subscribe to an event\n */\n on(event: EventName, handler: (...args: any[]) => void): () => void {\n return this.emitter.on(event, handler);\n }\n\n /**\n * Subscribe to event that auto-unsubscribes after first emission\n */\n once(event: EventName, handler: (...args: any[]) => void): () => void {\n return this.emitter.once(event, handler);\n }\n\n /**\n * Unsubscribe from an event\n */\n off(event: EventName, handler: (...args: any[]) => void): void {\n this.emitter.off(event, handler);\n }\n\n /**\n * Check if checkout is currently mounted\n */\n isMounted(): boolean {\n return this.mounted;\n }\n}\n\n/**\n * Factory function that works both as callable and constructable.\n * Always returns a new CheckoutImpl instance - no prototype manipulation needed.\n */\nconst PaypercutCheckout: PaypercutCheckoutStatic = function (\n this: unknown,\n options: PaypercutCheckoutOptions\n): CheckoutInstance {\n // Always return a new instance, regardless of how it's called\n return new CheckoutImpl(options);\n} as unknown as PaypercutCheckoutStatic;\n\n// Add static version property\n(PaypercutCheckout as any).version = config.version;\n\n// Export as default and named\nexport default PaypercutCheckout;\nexport { PaypercutCheckout };\n\n","/**\n * IIFE entry point - exports only the default for clean global assignment\n */\nimport PaypercutCheckout from './index';\nimport { config } from './config';\n\n// Log build mode in development\nif (config.mode === 'internal') {\n console.warn(`\n╔═══════════════════════════════════════════════════════════════╗\n║ ⚠️ PAYPERCUT CHECKOUT SDK - INTERNAL BUILD ║\n╚═══════════════════════════════════════════════════════════════╝\n\nThis is an INTERNAL development build with relaxed security settings.\n\n⚠️ DO NOT USE IN PRODUCTION!\n\nThis build:\n • Allows localhost origins for development\n • Enables hostedCheckoutUrl override\n • Has verbose logging enabled\n\nFor production use, install the latest version:\n npm install @paypercut/checkout-js@latest\n\nVersion: ${config.version}\nMode: ${config.mode}\nAllowed origins: ${config.allowedOrigins.join(', ')}\n `);\n}\n\nexport default PaypercutCheckout;\n\n"],"names":["Emitter","constructor","this","handlers","Map","on","event","handler","has","set","Set","get","add","off","once","wrappedHandler","args","delete","emit","forEach","h","err","console","error","clear","config","version","mode","defaultCheckoutOrigin","allowedOrigins","allowOriginOverride","getCheckoutOrigin","override","LOCALE_SET","UIMode","PaymentMethod","WalletOption","isValidPaymentMethod","value","Object","values","includes","isValidWalletOption","validateUIMode","warn","join","CheckoutImpl","options","emitter","mounted","destroyed","iframe","messageHandler","onMessage","bind","window","addEventListener","buildSrc","baseUrl","hostedCheckoutUrl","url","URL","id","locale","normalizedLocale","searchParams","ui_mode","validatedUIMode","payment_methods","length","methods","validated","method","push","CARD","validatePaymentMethods","append","wallet_options","option","validateWalletOptions","wallet","log","undefined","form_only","String","toString","getContainer","container","containerId","document","querySelector","Error","evt","origin","data","checkoutId","type","render","createElement","src","allow","setAttribute","assign","style","width","height","border","display","appendChild","submit","postToIframe","message","contentWindow","checkoutOrigin","postMessage","destroy","remove","removeEventListener","isMounted","PaypercutCheckout"],"mappings":"oDAIaA,EAAb,WAAAC,GACUC,KAAAC,SAAW,IAAIC,GAmEzB,CA3DE,EAAAC,CAAGC,EAAUC,GAOX,OANKL,KAAKC,SAASK,IAAIF,IACrBJ,KAAKC,SAASM,IAAIH,EAAO,IAAII,KAE/BR,KAAKC,SAASQ,IAAIL,GAAQM,IAAIL,GAGvB,IAAML,KAAKW,IAAIP,EAAOC,EAC/B,CAaA,IAAAO,CAAKR,EAAUC,GACb,MAAMQ,EAAiB,IAAIC,KACzBT,KAAWS,GACXd,KAAKW,IAAIP,EAAOS,IAElB,OAAOb,KAAKG,GAAGC,EAAOS,EACxB,CAOA,GAAAF,CAAIP,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