@payment-kit-js/vanilla 0.5.15 → 0.5.17

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.
Files changed (82) hide show
  1. package/dist/{airwallex-apple-pay-adapter-Bs8AdQKY.mjs → airwallex-apple-pay-adapter-CPz54c9e.mjs} +1 -1
  2. package/dist/{airwallex-apple-pay-adapter-Bs8AdQKY.mjs.map → airwallex-apple-pay-adapter-CPz54c9e.mjs.map} +1 -1
  3. package/dist/{airwallex-apple-pay-adapter-D8enI9Vq.d.mts → airwallex-apple-pay-adapter-CnnZ7VL6.d.mts} +1 -1
  4. package/dist/{airwallex-apple-pay-adapter-D8enI9Vq.d.mts.map → airwallex-apple-pay-adapter-CnnZ7VL6.d.mts.map} +1 -1
  5. package/dist/{airwallex-google-pay-adapter-C8JTp01q.mjs → airwallex-google-pay-adapter-BvlROwj_.mjs} +1 -1
  6. package/dist/{airwallex-google-pay-adapter-C8JTp01q.mjs.map → airwallex-google-pay-adapter-BvlROwj_.mjs.map} +1 -1
  7. package/dist/{airwallex-google-pay-adapter-adaDktQM.d.mts → airwallex-google-pay-adapter-D-AxVLLq.d.mts} +1 -1
  8. package/dist/{airwallex-google-pay-adapter-adaDktQM.d.mts.map → airwallex-google-pay-adapter-D-AxVLLq.d.mts.map} +1 -1
  9. package/dist/analytics-Blvs2DW7.mjs +333 -0
  10. package/dist/analytics-Blvs2DW7.mjs.map +1 -0
  11. package/dist/{bnpl-shared-B-en2sPr.d.mts → bnpl-shared-BQwCBD45.d.mts} +2 -2
  12. package/dist/{bnpl-shared-B-en2sPr.d.mts.map → bnpl-shared-BQwCBD45.d.mts.map} +1 -1
  13. package/dist/{bnpl-shared-CEAXTL3Q.mjs → bnpl-shared-DGs1YzS9.mjs} +2 -2
  14. package/dist/{bnpl-shared-CEAXTL3Q.mjs.map → bnpl-shared-DGs1YzS9.mjs.map} +1 -1
  15. package/dist/cdn/paymentkit.js +75 -20
  16. package/dist/cdn/paymentkit.js.map +2 -2
  17. package/dist/cdn/paymentkit.min.js +5 -5
  18. package/dist/cdn/paymentkit.min.js.map +3 -3
  19. package/dist/{connect-card-Cra_F1cC.d.mts → connect-card-CZhzK_Tp.d.mts} +1 -1
  20. package/dist/{connect-card-Cra_F1cC.d.mts.map → connect-card-CZhzK_Tp.d.mts.map} +1 -1
  21. package/dist/{connect-card-D3Je4V7p.mjs → connect-card-kXLdSNTL.mjs} +2 -2
  22. package/dist/{connect-card-D3Je4V7p.mjs.map → connect-card-kXLdSNTL.mjs.map} +1 -1
  23. package/dist/{connect-tunnel-x-BhVAej5Q.mjs → connect-tunnel-x-5XOct5Tm.mjs} +2 -2
  24. package/dist/{connect-tunnel-x-BhVAej5Q.mjs.map → connect-tunnel-x-5XOct5Tm.mjs.map} +1 -1
  25. package/dist/{connect-tunnel-x-Wh-JG1O5.d.mts → connect-tunnel-x-BKtMfoGh.d.mts} +1 -1
  26. package/dist/{connect-tunnel-x-Wh-JG1O5.d.mts.map → connect-tunnel-x-BKtMfoGh.d.mts.map} +1 -1
  27. package/dist/index.d.mts +3 -3
  28. package/dist/index.mjs +5 -334
  29. package/dist/index.mjs.map +1 -1
  30. package/dist/{next-action-handlers-BZs04hYb.mjs → next-action-handlers-CLOt1wzO.mjs} +1 -1
  31. package/dist/{next-action-handlers-BZs04hYb.mjs.map → next-action-handlers-CLOt1wzO.mjs.map} +1 -1
  32. package/dist/payment-methods/affirm.d.mts +4 -4
  33. package/dist/payment-methods/affirm.mjs +2 -2
  34. package/dist/payment-methods/afterpay.d.mts +4 -4
  35. package/dist/payment-methods/afterpay.mjs +2 -2
  36. package/dist/payment-methods/airwallex-apple-pay-adapter.d.mts +1 -1
  37. package/dist/payment-methods/airwallex-apple-pay-adapter.mjs +1 -1
  38. package/dist/payment-methods/airwallex-google-pay-adapter.d.mts +1 -1
  39. package/dist/payment-methods/airwallex-google-pay-adapter.mjs +1 -1
  40. package/dist/payment-methods/apple-pay.d.mts +19 -10
  41. package/dist/payment-methods/apple-pay.d.mts.map +1 -1
  42. package/dist/payment-methods/apple-pay.mjs +14 -16
  43. package/dist/payment-methods/apple-pay.mjs.map +1 -1
  44. package/dist/payment-methods/bnpl-shared.d.mts +4 -4
  45. package/dist/payment-methods/bnpl-shared.mjs +2 -2
  46. package/dist/payment-methods/card.d.mts +3 -3
  47. package/dist/payment-methods/card.d.mts.map +1 -1
  48. package/dist/payment-methods/card.mjs +77 -18
  49. package/dist/payment-methods/card.mjs.map +1 -1
  50. package/dist/payment-methods/google-pay.d.mts +5 -5
  51. package/dist/payment-methods/google-pay.mjs +4 -4
  52. package/dist/payment-methods/klarna.d.mts +4 -4
  53. package/dist/payment-methods/klarna.mjs +2 -2
  54. package/dist/payment-methods/next-action-handlers.mjs +1 -1
  55. package/dist/payment-methods/paypal.d.mts +3 -3
  56. package/dist/payment-methods/paypal.mjs +1 -1
  57. package/dist/payment-methods/stripe-apple-pay-adapter.d.mts +1 -1
  58. package/dist/payment-methods/stripe-apple-pay-adapter.mjs +1 -1
  59. package/dist/payment-methods/stripe-google-pay-adapter.d.mts +1 -1
  60. package/dist/payment-methods/stripe-google-pay-adapter.mjs +1 -1
  61. package/dist/payment-methods/vgs-collect-loader.mjs +1 -1
  62. package/dist/penpal/connect-card.d.mts +1 -1
  63. package/dist/penpal/connect-card.mjs +2 -2
  64. package/dist/penpal/connect-tunnel-x.d.mts +1 -1
  65. package/dist/penpal/connect-tunnel-x.mjs +2 -2
  66. package/dist/{penpal-BFKeZTVz.mjs → penpal-CBrj43M5.mjs} +1 -1
  67. package/dist/{penpal-BFKeZTVz.mjs.map → penpal-CBrj43M5.mjs.map} +1 -1
  68. package/dist/{stripe-apple-pay-adapter-BLRjqgDf.mjs → stripe-apple-pay-adapter-7rF6xRIG.mjs} +1 -1
  69. package/dist/{stripe-apple-pay-adapter-BLRjqgDf.mjs.map → stripe-apple-pay-adapter-7rF6xRIG.mjs.map} +1 -1
  70. package/dist/{stripe-apple-pay-adapter-DcuGlQqQ.d.mts → stripe-apple-pay-adapter-D2OJRlAl.d.mts} +1 -1
  71. package/dist/{stripe-apple-pay-adapter-DcuGlQqQ.d.mts.map → stripe-apple-pay-adapter-D2OJRlAl.d.mts.map} +1 -1
  72. package/dist/{stripe-google-pay-adapter-BlQ2jVpE.d.mts → stripe-google-pay-adapter-B330fRiH.d.mts} +1 -1
  73. package/dist/{stripe-google-pay-adapter-BlQ2jVpE.d.mts.map → stripe-google-pay-adapter-B330fRiH.d.mts.map} +1 -1
  74. package/dist/{stripe-google-pay-adapter-CIkgjhw8.mjs → stripe-google-pay-adapter-B346KXt4.mjs} +1 -1
  75. package/dist/{stripe-google-pay-adapter-CIkgjhw8.mjs.map → stripe-google-pay-adapter-B346KXt4.mjs.map} +1 -1
  76. package/dist/{types-CQ8xbgoh.d.mts → types-B3mjYfOm.d.mts} +3 -3
  77. package/dist/{types-CQ8xbgoh.d.mts.map → types-B3mjYfOm.d.mts.map} +1 -1
  78. package/dist/{utils-B70Y8YcZ.mjs → utils-Dc6zwOe1.mjs} +1 -1
  79. package/dist/{utils-B70Y8YcZ.mjs.map → utils-Dc6zwOe1.mjs.map} +1 -1
  80. package/dist/{vgs-collect-loader-l5_Pnmhz.mjs → vgs-collect-loader-CTLSv4qv.mjs} +1 -1
  81. package/dist/{vgs-collect-loader-l5_Pnmhz.mjs.map → vgs-collect-loader-CTLSv4qv.mjs.map} +1 -1
  82. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"next-action-handlers-BZs04hYb.mjs","names":[],"sources":["../src/utils/3ds-iframe-modal.ts","../src/payment-methods/next-action-handlers.ts"],"sourcesContent":["/**\n * 3DS iframe modal for displaying authentication pages.\n *\n * This module provides an iframe modal used by payment processors\n * that need to display a 3DS authentication page.\n */\n\ntype IframeModalResult = { success: true; data: Record<string, unknown> } | { success: false; error: string };\n\ntype ThreeDSCompleteMessage = {\n type: \"3ds_complete\";\n processor: string | null;\n isSuccess: boolean;\n error?: string;\n};\n\ntype IframeModalMessageHandler = (\n event: MessageEvent<ThreeDSCompleteMessage>,\n) => { handled: true; result: IframeModalResult } | { handled: false };\n\ninterface IframeModalOptions {\n /** URL to load in the iframe */\n url: string;\n /** Size of the iframe in pixels */\n size: { width: number; height: number };\n /** Border radius for the iframe in pixels (default: 16) */\n radius?: number;\n /** Handler to process postMessage events from the iframe */\n onMessage: IframeModalMessageHandler;\n}\n\n/**\n * Shows an iframe modal and waits for a result via postMessage.\n *\n * Features:\n * - Close/cancel button positioned outside the iframe\n * - Responsive design (works on mobile)\n * - Keyboard accessibility (Escape to close, focus trap)\n * - Fade-in/fade-out animations\n * - Iframe load error handling\n *\n * @param options - Modal configuration options\n * @returns Promise that resolves with success/failure result\n *\n * @example\n * ```ts\n * const result = await show3DSIframeModal({\n * url: \"https://bank.com/3ds-auth\",\n * size: { width: 605, height: 500 },\n * radius: 6,\n * onMessage: (event) => {\n * if (event.data?.type === \"auth_complete\") {\n * return {\n * handled: true,\n * result: event.data.succeeded\n * ? { success: true, data: { id: event.data.id } }\n * : { success: false, error: event.data.error }\n * };\n * }\n * return { handled: false };\n * },\n * });\n * ```\n */\n\nexport default function show3DSIframeModal(options: IframeModalOptions): Promise<IframeModalResult> {\n const { url, size, radius = 6, onMessage } = options;\n\n return new Promise((resolve) => {\n let resolved = false;\n\n // Create modal overlay with fade-in animation\n const overlay = document.createElement(\"div\");\n overlay.id = \"pk-iframe-modal-overlay\";\n overlay.setAttribute(\"role\", \"dialog\");\n overlay.setAttribute(\"aria-modal\", \"true\");\n overlay.setAttribute(\"aria-label\", \"3D Secure Verification\");\n overlay.style.cssText = `\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background: rgba(0, 0, 0, 0);\n display: flex;\n align-items: center;\n justify-content: center;\n z-index: 10000;\n transition: background 0.25s cubic-bezier(0.4, 0, 0.2, 1);\n `;\n\n // Create container for iframe and close button\n const container = document.createElement(\"div\");\n container.style.cssText = `\n position: relative;\n width: ${size.width}px;\n height: ${size.height}px;\n max-width: calc(100vw - 32px);\n max-height: calc(100vh - 64px);\n overflow: visible;\n opacity: 0;\n transform: scale(0.95) translateY(10px);\n transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1), transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);\n `;\n\n // Create close button (positioned outside top-right of iframe)\n const closeButton = document.createElement(\"button\");\n closeButton.id = \"pk-iframe-modal-close\";\n closeButton.setAttribute(\"aria-label\", \"Cancel verification\");\n closeButton.setAttribute(\"type\", \"button\");\n closeButton.style.cssText = `\n position: absolute;\n top: -40px;\n right: 0;\n width: 32px;\n height: 32px;\n border: none;\n background: white;\n border-radius: 8px;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n z-index: 10;\n transition: background 0.15s ease;\n box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);\n `;\n closeButton.innerHTML = `\n <svg width=\"12\" height=\"12\" viewBox=\"0 0 14 14\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M1 1L13 13M1 13L13 1\" stroke=\"#666\" stroke-width=\"2\" stroke-linecap=\"round\"/>\n </svg>\n `;\n closeButton.onmouseenter = (): void => {\n closeButton.style.background = \"#f5f5f5\";\n };\n closeButton.onmouseleave = (): void => {\n closeButton.style.background = \"white\";\n };\n\n // Create iframe (hidden initially until loaded)\n const iframe = document.createElement(\"iframe\");\n iframe.src = url;\n iframe.setAttribute(\"title\", \"3D Secure Verification\");\n iframe.style.cssText = `\n width: 100%;\n height: 100%;\n border: none;\n opacity: 0;\n border-radius: ${radius}px;\n background: white;\n transition: opacity 0.2s ease;\n position: relative;\n z-index: 1;\n `;\n\n // Handle iframe load success\n iframe.onload = (): void => {\n iframe.style.opacity = \"1\";\n };\n\n // Handle iframe load error\n iframe.onerror = (): void => {\n if (!resolved) {\n console.error(\"[IframeModal] Failed to load iframe\");\n cleanupWithAnimation();\n resolve({ success: false, error: \"Failed to load verification page. Please try again.\" });\n }\n };\n\n container.appendChild(closeButton);\n container.appendChild(iframe);\n overlay.appendChild(container);\n document.body.appendChild(overlay);\n\n // Trigger fade-in animation\n requestAnimationFrame(() => {\n overlay.style.background = \"rgba(0, 0, 0, 0.5)\";\n container.style.opacity = \"1\";\n container.style.transform = \"scale(1) translateY(0)\";\n });\n\n // Cleanup with fade-out animation\n const cleanupWithAnimation = (): void => {\n if (resolved) return;\n resolved = true;\n\n window.removeEventListener(\"message\", handleMessage);\n window.removeEventListener(\"keydown\", handleKeydown);\n\n // Use requestAnimationFrame to ensure transition is applied\n requestAnimationFrame(() => {\n overlay.style.background = \"rgba(0, 0, 0, 0)\";\n container.style.opacity = \"0\";\n container.style.transform = \"scale(0.95) translateY(10px)\";\n\n setTimeout(() => {\n if (overlay.parentNode) {\n overlay.parentNode.removeChild(overlay);\n }\n }, 250);\n });\n };\n\n // Handle close button click\n const handleCancel = (): void => {\n if (!resolved) {\n console.log(\"[IframeModal] User cancelled\");\n cleanupWithAnimation();\n resolve({ success: false, error: \"Verification cancelled\" });\n }\n };\n\n closeButton.onclick = handleCancel;\n\n // Handle Escape key\n const handleKeydown = (event: KeyboardEvent): void => {\n if (event.key === \"Escape\") {\n handleCancel();\n }\n // Trap focus within modal (Tab key cycles through close button and iframe)\n if (event.key === \"Tab\") {\n event.preventDefault();\n if (document.activeElement === closeButton) {\n iframe.focus();\n } else {\n closeButton.focus();\n }\n }\n };\n\n window.addEventListener(\"keydown\", handleKeydown);\n\n // Set initial focus to close button for accessibility\n closeButton.focus();\n\n const handleMessage = (event: MessageEvent): void => {\n const messageResult = onMessage(event);\n if (messageResult.handled) {\n cleanupWithAnimation();\n resolve(messageResult.result);\n }\n };\n\n window.addEventListener(\"message\", handleMessage);\n });\n}\n","/**\n * Next action handlers for processor-specific user actions (e.g., 3DS authentication).\n *\n * This module abstracts processor-specific logic away from the generic card payment flow.\n * Each handler implements the logic needed for a specific next action type.\n */\n\nimport type { PublicCardCheckoutResponse } from \"@pkg/sdk/models\";\nimport type { Stripe } from \"@stripe/stripe-js\";\nimport show3DSIframeModal from \"../utils/3ds-iframe-modal\";\n\n// Helper to wait for a condition\nconst sleep = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms));\n\n// Check if Stripe.js is loaded via script tag\nconst isStripeJsPresent = (): boolean => \"Stripe\" in window;\n\n/**\n * Get the Stripe instance from the global window object.\n * Expects Stripe.js to be loaded via HTML script tag.\n * Polls for up to 5 seconds waiting for Stripe to be available.\n */\nconst getLoadedStripe = async (publishableKey: string): Promise<Stripe> => {\n // Poll for Stripe.js to be loaded (up to 5 seconds)\n for (let i = 0; i < 10; i++) {\n if (isStripeJsPresent()) {\n break;\n }\n await sleep(500);\n }\n\n if (!isStripeJsPresent()) {\n throw new Error(\n \"Stripe.js not loaded. Add this script tag to your HTML <head>:\\n\" +\n '<script src=\"https://js.stripe.com/v3/\"></script>',\n );\n }\n\n // @ts-expect-error Stripe is loaded globally via script tag\n const stripe: Stripe = new window.Stripe(publishableKey);\n return stripe;\n};\n\n/**\n * Result of handling a next action.\n */\nexport type NextActionResult = { success: true } | { success: false; error: string };\n\n/**\n * Handle Stripe 3DS authentication.\n */\nconst handleStripe3ds = async (\n nextAction: Extract<PublicCardCheckoutResponse[\"nextAction\"], { type: \"stripe_3ds\" }>,\n): Promise<NextActionResult> => {\n const { clientSecret, stripePk } = nextAction;\n\n const stripe = await getLoadedStripe(stripePk);\n\n // Show 3DS modal\n const { error: stripeError } = await stripe.confirmCardPayment(clientSecret);\n\n if (stripeError) {\n console.error(\"[3DS:Stripe] Authentication failed:\", stripeError.message);\n return { success: false, error: stripeError.message || \"3DS authentication failed\" };\n }\n\n return { success: true };\n};\n\n/**\n * Handle Airwallex 3DS authentication via iframe.\n *\n * Renders an iframe with the 3DS authentication URL. The iframe will redirect\n * to the 3DS callback page which sends a postMessage back to complete the flow.\n */\nconst handleAirwallex3ds = async (\n nextAction: Extract<PublicCardCheckoutResponse[\"nextAction\"], { type: \"airwallex_3ds\" }>,\n): Promise<NextActionResult> => {\n return show3DSIframeModal({\n url: nextAction.url,\n size: { width: 605, height: 550 },\n onMessage: (event) => {\n if (event.data.type !== \"3ds_complete\") {\n return { handled: false };\n }\n\n const { isSuccess, error } = event.data;\n\n if (isSuccess) {\n return { handled: true, result: { success: true, data: {} } };\n } else {\n console.error(\"[3DS:Airwallex] Authentication failed:\", error);\n return {\n handled: true,\n result: { success: false, error: error || \"3DS authentication failed\" },\n };\n }\n },\n });\n};\n\n/**\n * Handle a next action based on its type.\n * Routes to the appropriate processor-specific handler.\n *\n * @param nextAction - The next action from the checkout response\n * @returns Result indicating success or failure with error message\n */\nexport const handleNextAction = async (\n nextAction: NonNullable<PublicCardCheckoutResponse[\"nextAction\"]>,\n): Promise<NextActionResult> => {\n switch (nextAction.type) {\n case \"stripe_3ds\":\n return handleStripe3ds(nextAction);\n case \"airwallex_3ds\":\n return handleAirwallex3ds(nextAction);\n default:\n // TypeScript will catch if we miss a case when new action types are added\n return { success: false, error: `Unknown next action type: ${(nextAction as { type: string }).type}` };\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiEA,SAAwB,mBAAmB,SAAyD;CAClG,MAAM,EAAE,KAAK,MAAM,SAAS,GAAG,cAAc;AAE7C,QAAO,IAAI,SAAS,YAAY;EAC9B,IAAI,WAAW;EAGf,MAAM,UAAU,SAAS,cAAc,MAAM;AAC7C,UAAQ,KAAK;AACb,UAAQ,aAAa,QAAQ,SAAS;AACtC,UAAQ,aAAa,cAAc,OAAO;AAC1C,UAAQ,aAAa,cAAc,yBAAyB;AAC5D,UAAQ,MAAM,UAAU;;;;;;;;;;;;;EAexB,MAAM,YAAY,SAAS,cAAc,MAAM;AAC/C,YAAU,MAAM,UAAU;;eAEf,KAAK,MAAM;gBACV,KAAK,OAAO;;;;;;;;EAUxB,MAAM,cAAc,SAAS,cAAc,SAAS;AACpD,cAAY,KAAK;AACjB,cAAY,aAAa,cAAc,sBAAsB;AAC7D,cAAY,aAAa,QAAQ,SAAS;AAC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AS;IAAM,QAAQ;KAAE,SAAS;KAAM,MAAM,EAAE;KAAE;IAAE;QACxD;AACL,YAAQ,MAAM,0CAA0C,MAAM;AAC9D,WAAO;KACL,SAAS;KACT,QAAQ;MAAE,SAAS;MAAO,OAAO,SAAS;MAA6B;KACxE;;;EAGN,CAAC;;;;;;;;;AAUJ,MAAa,mBAAmB,OAC9B,eAC8B;AAC9B,SAAQ,WAAW,MAAnB;EACE,KAAK,aACH,QAAO,gBAAgB,WAAW;EACpC,KAAK,gBACH,QAAO,mBAAmB,WAAW;EACvC,QAEE,QAAO;GAAE,SAAS;GAAO,OAAO,6BAA8B,WAAgC;GAAQ"}
1
+ {"version":3,"file":"next-action-handlers-CLOt1wzO.mjs","names":[],"sources":["../src/utils/3ds-iframe-modal.ts","../src/payment-methods/next-action-handlers.ts"],"sourcesContent":["/**\n * 3DS iframe modal for displaying authentication pages.\n *\n * This module provides an iframe modal used by payment processors\n * that need to display a 3DS authentication page.\n */\n\ntype IframeModalResult = { success: true; data: Record<string, unknown> } | { success: false; error: string };\n\ntype ThreeDSCompleteMessage = {\n type: \"3ds_complete\";\n processor: string | null;\n isSuccess: boolean;\n error?: string;\n};\n\ntype IframeModalMessageHandler = (\n event: MessageEvent<ThreeDSCompleteMessage>,\n) => { handled: true; result: IframeModalResult } | { handled: false };\n\ninterface IframeModalOptions {\n /** URL to load in the iframe */\n url: string;\n /** Size of the iframe in pixels */\n size: { width: number; height: number };\n /** Border radius for the iframe in pixels (default: 16) */\n radius?: number;\n /** Handler to process postMessage events from the iframe */\n onMessage: IframeModalMessageHandler;\n}\n\n/**\n * Shows an iframe modal and waits for a result via postMessage.\n *\n * Features:\n * - Close/cancel button positioned outside the iframe\n * - Responsive design (works on mobile)\n * - Keyboard accessibility (Escape to close, focus trap)\n * - Fade-in/fade-out animations\n * - Iframe load error handling\n *\n * @param options - Modal configuration options\n * @returns Promise that resolves with success/failure result\n *\n * @example\n * ```ts\n * const result = await show3DSIframeModal({\n * url: \"https://bank.com/3ds-auth\",\n * size: { width: 605, height: 500 },\n * radius: 6,\n * onMessage: (event) => {\n * if (event.data?.type === \"auth_complete\") {\n * return {\n * handled: true,\n * result: event.data.succeeded\n * ? { success: true, data: { id: event.data.id } }\n * : { success: false, error: event.data.error }\n * };\n * }\n * return { handled: false };\n * },\n * });\n * ```\n */\n\nexport default function show3DSIframeModal(options: IframeModalOptions): Promise<IframeModalResult> {\n const { url, size, radius = 6, onMessage } = options;\n\n return new Promise((resolve) => {\n let resolved = false;\n\n // Create modal overlay with fade-in animation\n const overlay = document.createElement(\"div\");\n overlay.id = \"pk-iframe-modal-overlay\";\n overlay.setAttribute(\"role\", \"dialog\");\n overlay.setAttribute(\"aria-modal\", \"true\");\n overlay.setAttribute(\"aria-label\", \"3D Secure Verification\");\n overlay.style.cssText = `\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background: rgba(0, 0, 0, 0);\n display: flex;\n align-items: center;\n justify-content: center;\n z-index: 10000;\n transition: background 0.25s cubic-bezier(0.4, 0, 0.2, 1);\n `;\n\n // Create container for iframe and close button\n const container = document.createElement(\"div\");\n container.style.cssText = `\n position: relative;\n width: ${size.width}px;\n height: ${size.height}px;\n max-width: calc(100vw - 32px);\n max-height: calc(100vh - 64px);\n overflow: visible;\n opacity: 0;\n transform: scale(0.95) translateY(10px);\n transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1), transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);\n `;\n\n // Create close button (positioned outside top-right of iframe)\n const closeButton = document.createElement(\"button\");\n closeButton.id = \"pk-iframe-modal-close\";\n closeButton.setAttribute(\"aria-label\", \"Cancel verification\");\n closeButton.setAttribute(\"type\", \"button\");\n closeButton.style.cssText = `\n position: absolute;\n top: -40px;\n right: 0;\n width: 32px;\n height: 32px;\n border: none;\n background: white;\n border-radius: 8px;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n z-index: 10;\n transition: background 0.15s ease;\n box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);\n `;\n closeButton.innerHTML = `\n <svg width=\"12\" height=\"12\" viewBox=\"0 0 14 14\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M1 1L13 13M1 13L13 1\" stroke=\"#666\" stroke-width=\"2\" stroke-linecap=\"round\"/>\n </svg>\n `;\n closeButton.onmouseenter = (): void => {\n closeButton.style.background = \"#f5f5f5\";\n };\n closeButton.onmouseleave = (): void => {\n closeButton.style.background = \"white\";\n };\n\n // Create iframe (hidden initially until loaded)\n const iframe = document.createElement(\"iframe\");\n iframe.src = url;\n iframe.setAttribute(\"title\", \"3D Secure Verification\");\n iframe.style.cssText = `\n width: 100%;\n height: 100%;\n border: none;\n opacity: 0;\n border-radius: ${radius}px;\n background: white;\n transition: opacity 0.2s ease;\n position: relative;\n z-index: 1;\n `;\n\n // Handle iframe load success\n iframe.onload = (): void => {\n iframe.style.opacity = \"1\";\n };\n\n // Handle iframe load error\n iframe.onerror = (): void => {\n if (!resolved) {\n console.error(\"[IframeModal] Failed to load iframe\");\n cleanupWithAnimation();\n resolve({ success: false, error: \"Failed to load verification page. Please try again.\" });\n }\n };\n\n container.appendChild(closeButton);\n container.appendChild(iframe);\n overlay.appendChild(container);\n document.body.appendChild(overlay);\n\n // Trigger fade-in animation\n requestAnimationFrame(() => {\n overlay.style.background = \"rgba(0, 0, 0, 0.5)\";\n container.style.opacity = \"1\";\n container.style.transform = \"scale(1) translateY(0)\";\n });\n\n // Cleanup with fade-out animation\n const cleanupWithAnimation = (): void => {\n if (resolved) return;\n resolved = true;\n\n window.removeEventListener(\"message\", handleMessage);\n window.removeEventListener(\"keydown\", handleKeydown);\n\n // Use requestAnimationFrame to ensure transition is applied\n requestAnimationFrame(() => {\n overlay.style.background = \"rgba(0, 0, 0, 0)\";\n container.style.opacity = \"0\";\n container.style.transform = \"scale(0.95) translateY(10px)\";\n\n setTimeout(() => {\n if (overlay.parentNode) {\n overlay.parentNode.removeChild(overlay);\n }\n }, 250);\n });\n };\n\n // Handle close button click\n const handleCancel = (): void => {\n if (!resolved) {\n console.log(\"[IframeModal] User cancelled\");\n cleanupWithAnimation();\n resolve({ success: false, error: \"Verification cancelled\" });\n }\n };\n\n closeButton.onclick = handleCancel;\n\n // Handle Escape key\n const handleKeydown = (event: KeyboardEvent): void => {\n if (event.key === \"Escape\") {\n handleCancel();\n }\n // Trap focus within modal (Tab key cycles through close button and iframe)\n if (event.key === \"Tab\") {\n event.preventDefault();\n if (document.activeElement === closeButton) {\n iframe.focus();\n } else {\n closeButton.focus();\n }\n }\n };\n\n window.addEventListener(\"keydown\", handleKeydown);\n\n // Set initial focus to close button for accessibility\n closeButton.focus();\n\n const handleMessage = (event: MessageEvent): void => {\n const messageResult = onMessage(event);\n if (messageResult.handled) {\n cleanupWithAnimation();\n resolve(messageResult.result);\n }\n };\n\n window.addEventListener(\"message\", handleMessage);\n });\n}\n","/**\n * Next action handlers for processor-specific user actions (e.g., 3DS authentication).\n *\n * This module abstracts processor-specific logic away from the generic card payment flow.\n * Each handler implements the logic needed for a specific next action type.\n */\n\nimport type { PublicCardCheckoutResponse } from \"@pkg/sdk/models\";\nimport type { Stripe } from \"@stripe/stripe-js\";\nimport show3DSIframeModal from \"../utils/3ds-iframe-modal\";\n\n// Helper to wait for a condition\nconst sleep = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms));\n\n// Check if Stripe.js is loaded via script tag\nconst isStripeJsPresent = (): boolean => \"Stripe\" in window;\n\n/**\n * Get the Stripe instance from the global window object.\n * Expects Stripe.js to be loaded via HTML script tag.\n * Polls for up to 5 seconds waiting for Stripe to be available.\n */\nconst getLoadedStripe = async (publishableKey: string): Promise<Stripe> => {\n // Poll for Stripe.js to be loaded (up to 5 seconds)\n for (let i = 0; i < 10; i++) {\n if (isStripeJsPresent()) {\n break;\n }\n await sleep(500);\n }\n\n if (!isStripeJsPresent()) {\n throw new Error(\n \"Stripe.js not loaded. Add this script tag to your HTML <head>:\\n\" +\n '<script src=\"https://js.stripe.com/v3/\"></script>',\n );\n }\n\n // @ts-expect-error Stripe is loaded globally via script tag\n const stripe: Stripe = new window.Stripe(publishableKey);\n return stripe;\n};\n\n/**\n * Result of handling a next action.\n */\nexport type NextActionResult = { success: true } | { success: false; error: string };\n\n/**\n * Handle Stripe 3DS authentication.\n */\nconst handleStripe3ds = async (\n nextAction: Extract<PublicCardCheckoutResponse[\"nextAction\"], { type: \"stripe_3ds\" }>,\n): Promise<NextActionResult> => {\n const { clientSecret, stripePk } = nextAction;\n\n const stripe = await getLoadedStripe(stripePk);\n\n // Show 3DS modal\n const { error: stripeError } = await stripe.confirmCardPayment(clientSecret);\n\n if (stripeError) {\n console.error(\"[3DS:Stripe] Authentication failed:\", stripeError.message);\n return { success: false, error: stripeError.message || \"3DS authentication failed\" };\n }\n\n return { success: true };\n};\n\n/**\n * Handle Airwallex 3DS authentication via iframe.\n *\n * Renders an iframe with the 3DS authentication URL. The iframe will redirect\n * to the 3DS callback page which sends a postMessage back to complete the flow.\n */\nconst handleAirwallex3ds = async (\n nextAction: Extract<PublicCardCheckoutResponse[\"nextAction\"], { type: \"airwallex_3ds\" }>,\n): Promise<NextActionResult> => {\n return show3DSIframeModal({\n url: nextAction.url,\n size: { width: 605, height: 550 },\n onMessage: (event) => {\n if (event.data.type !== \"3ds_complete\") {\n return { handled: false };\n }\n\n const { isSuccess, error } = event.data;\n\n if (isSuccess) {\n return { handled: true, result: { success: true, data: {} } };\n } else {\n console.error(\"[3DS:Airwallex] Authentication failed:\", error);\n return {\n handled: true,\n result: { success: false, error: error || \"3DS authentication failed\" },\n };\n }\n },\n });\n};\n\n/**\n * Handle a next action based on its type.\n * Routes to the appropriate processor-specific handler.\n *\n * @param nextAction - The next action from the checkout response\n * @returns Result indicating success or failure with error message\n */\nexport const handleNextAction = async (\n nextAction: NonNullable<PublicCardCheckoutResponse[\"nextAction\"]>,\n): Promise<NextActionResult> => {\n switch (nextAction.type) {\n case \"stripe_3ds\":\n return handleStripe3ds(nextAction);\n case \"airwallex_3ds\":\n return handleAirwallex3ds(nextAction);\n default:\n // TypeScript will catch if we miss a case when new action types are added\n return { success: false, error: `Unknown next action type: ${(nextAction as { type: string }).type}` };\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiEA,SAAwB,mBAAmB,SAAyD;CAClG,MAAM,EAAE,KAAK,MAAM,SAAS,GAAG,cAAc;AAE7C,QAAO,IAAI,SAAS,YAAY;EAC9B,IAAI,WAAW;EAGf,MAAM,UAAU,SAAS,cAAc,MAAM;AAC7C,UAAQ,KAAK;AACb,UAAQ,aAAa,QAAQ,SAAS;AACtC,UAAQ,aAAa,cAAc,OAAO;AAC1C,UAAQ,aAAa,cAAc,yBAAyB;AAC5D,UAAQ,MAAM,UAAU;;;;;;;;;;;;;EAexB,MAAM,YAAY,SAAS,cAAc,MAAM;AAC/C,YAAU,MAAM,UAAU;;eAEf,KAAK,MAAM;gBACV,KAAK,OAAO;;;;;;;;EAUxB,MAAM,cAAc,SAAS,cAAc,SAAS;AACpD,cAAY,KAAK;AACjB,cAAY,aAAa,cAAc,sBAAsB;AAC7D,cAAY,aAAa,QAAQ,SAAS;AAC1C,cAAY,MAAM,UAAU;;;;;;;;;;;;;;;;;AAiB5B,cAAY,YAAY;;;;;AAKxB,cAAY,qBAA2B;AACrC,eAAY,MAAM,aAAa;;AAEjC,cAAY,qBAA2B;AACrC,eAAY,MAAM,aAAa;;EAIjC,MAAM,SAAS,SAAS,cAAc,SAAS;AAC/C,SAAO,MAAM;AACb,SAAO,aAAa,SAAS,yBAAyB;AACtD,SAAO,MAAM,UAAU;;;;;uBAKJ,OAAO;;;;;;AAQ1B,SAAO,eAAqB;AAC1B,UAAO,MAAM,UAAU;;AAIzB,SAAO,gBAAsB;AAC3B,OAAI,CAAC,UAAU;AACb,YAAQ,MAAM,sCAAsC;AACpD,0BAAsB;AACtB,YAAQ;KAAE,SAAS;KAAO,OAAO;KAAuD,CAAC;;;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F1cC.mjs";
3
- import "../connect-tunnel-x-Wh-JG1O5.mjs";
4
- import { n as BnplCustomerInfo, s as BnplSubmitOptions, t as BnplCheckoutResponse } from "../bnpl-shared-B-en2sPr.mjs";
1
+ import { r as PaymentMethod } from "../types-B3mjYfOm.mjs";
2
+ import "../connect-card-CZhzK_Tp.mjs";
3
+ import "../connect-tunnel-x-BKtMfoGh.mjs";
4
+ import { n as BnplCustomerInfo, s as BnplSubmitOptions, t as BnplCheckoutResponse } from "../bnpl-shared-BQwCBD45.mjs";
5
5
 
6
6
  //#region src/payment-methods/affirm.d.ts
7
7
  type AffirmCustomerInfo = BnplCustomerInfo;
@@ -1,5 +1,5 @@
1
- import "../utils-B70Y8YcZ.mjs";
2
- import { t as createBnplPaymentMethod } from "../bnpl-shared-CEAXTL3Q.mjs";
1
+ import "../utils-Dc6zwOe1.mjs";
2
+ import { t as createBnplPaymentMethod } from "../bnpl-shared-DGs1YzS9.mjs";
3
3
 
4
4
  //#region src/payment-methods/affirm.ts
5
5
  const AffirmPaymentMethod = createBnplPaymentMethod({
@@ -1,7 +1,7 @@
1
- import { r as PaymentMethod } from "../types-CQ8xbgoh.mjs";
2
- import "../connect-card-Cra_F1cC.mjs";
3
- import "../connect-tunnel-x-Wh-JG1O5.mjs";
4
- import { n as BnplCustomerInfo, s as BnplSubmitOptions, t as BnplCheckoutResponse } from "../bnpl-shared-B-en2sPr.mjs";
1
+ import { r as PaymentMethod } from "../types-B3mjYfOm.mjs";
2
+ import "../connect-card-CZhzK_Tp.mjs";
3
+ import "../connect-tunnel-x-BKtMfoGh.mjs";
4
+ import { n as BnplCustomerInfo, s as BnplSubmitOptions, t as BnplCheckoutResponse } from "../bnpl-shared-BQwCBD45.mjs";
5
5
 
6
6
  //#region src/payment-methods/afterpay.d.ts
7
7
  type AfterpayCustomerInfo = BnplCustomerInfo;
@@ -1,5 +1,5 @@
1
- import "../utils-B70Y8YcZ.mjs";
2
- import { t as createBnplPaymentMethod } from "../bnpl-shared-CEAXTL3Q.mjs";
1
+ import "../utils-Dc6zwOe1.mjs";
2
+ import { t as createBnplPaymentMethod } from "../bnpl-shared-DGs1YzS9.mjs";
3
3
 
4
4
  //#region src/payment-methods/afterpay.ts
5
5
  const AfterpayPaymentMethod = createBnplPaymentMethod({
@@ -1,2 +1,2 @@
1
- import { a as ApplePayEncryptedToken, i as AirwallexApplePayShowResult, n as AirwallexApplePayConfig, o as MerchantValidationCallback, r as AirwallexApplePayMockScenario, t as AirwallexApplePayAdapter } from "../airwallex-apple-pay-adapter-D8enI9Vq.mjs";
1
+ import { a as ApplePayEncryptedToken, i as AirwallexApplePayShowResult, n as AirwallexApplePayConfig, o as MerchantValidationCallback, r as AirwallexApplePayMockScenario, t as AirwallexApplePayAdapter } from "../airwallex-apple-pay-adapter-CnnZ7VL6.mjs";
2
2
  export { AirwallexApplePayAdapter, AirwallexApplePayConfig, AirwallexApplePayMockScenario, AirwallexApplePayShowResult, ApplePayEncryptedToken, MerchantValidationCallback };
@@ -1,3 +1,3 @@
1
- import { n as AirwallexApplePayMockScenario, t as AirwallexApplePayAdapter } from "../airwallex-apple-pay-adapter-Bs8AdQKY.mjs";
1
+ import { n as AirwallexApplePayMockScenario, t as AirwallexApplePayAdapter } from "../airwallex-apple-pay-adapter-CPz54c9e.mjs";
2
2
 
3
3
  export { AirwallexApplePayAdapter, AirwallexApplePayMockScenario };
@@ -1,2 +1,2 @@
1
- import { a as GooglePayEncryptedToken, i as AirwallexShowPaymentResult, n as AirwallexGooglePayConfig, r as AirwallexGooglePayMockScenario, t as AirwallexGooglePayAdapter } from "../airwallex-google-pay-adapter-adaDktQM.mjs";
1
+ import { a as GooglePayEncryptedToken, i as AirwallexShowPaymentResult, n as AirwallexGooglePayConfig, r as AirwallexGooglePayMockScenario, t as AirwallexGooglePayAdapter } from "../airwallex-google-pay-adapter-D-AxVLLq.mjs";
2
2
  export { AirwallexGooglePayAdapter, AirwallexGooglePayConfig, AirwallexGooglePayMockScenario, AirwallexShowPaymentResult, GooglePayEncryptedToken };
@@ -1,3 +1,3 @@
1
- import { n as AirwallexGooglePayMockScenario, t as AirwallexGooglePayAdapter } from "../airwallex-google-pay-adapter-C8JTp01q.mjs";
1
+ import { n as AirwallexGooglePayMockScenario, t as AirwallexGooglePayAdapter } from "../airwallex-google-pay-adapter-BvlROwj_.mjs";
2
2
 
3
3
  export { AirwallexGooglePayAdapter, AirwallexGooglePayMockScenario };
@@ -1,8 +1,8 @@
1
- import { r as PaymentMethod } from "../types-CQ8xbgoh.mjs";
2
- import "../connect-card-Cra_F1cC.mjs";
3
- import "../connect-tunnel-x-Wh-JG1O5.mjs";
4
- import { a as ApplePayEncryptedToken } from "../airwallex-apple-pay-adapter-D8enI9Vq.mjs";
5
- import { t as ApplePayMockScenario } from "../stripe-apple-pay-adapter-DcuGlQqQ.mjs";
1
+ import { r as PaymentMethod } from "../types-B3mjYfOm.mjs";
2
+ import "../connect-card-CZhzK_Tp.mjs";
3
+ import "../connect-tunnel-x-BKtMfoGh.mjs";
4
+ import { a as ApplePayEncryptedToken } from "../airwallex-apple-pay-adapter-CnnZ7VL6.mjs";
5
+ import { t as ApplePayMockScenario } from "../stripe-apple-pay-adapter-D2OJRlAl.mjs";
6
6
 
7
7
  //#region src/payment-methods/apple-pay.d.ts
8
8
  type ApplePayCustomerInfo = {
@@ -12,8 +12,8 @@ type ApplePayCustomerInfo = {
12
12
  };
13
13
  type ApplePayStartRequest = {
14
14
  processor_id: string;
15
- customer_info: ApplePayCustomerInfo;
16
- fraud_metadata: {
15
+ customer_info?: ApplePayCustomerInfo;
16
+ fraud_metadata?: {
17
17
  ipAddress?: string;
18
18
  browserInfo?: {
19
19
  [key: string]: unknown;
@@ -27,13 +27,11 @@ type ApplePayStartRequest = {
27
27
  initiative_context?: string;
28
28
  };
29
29
  type ApplePayStartResponse = {
30
- checkout_attempt_id: string;
31
30
  amount: number;
32
31
  currency: string;
33
32
  country: string;
34
- processor: "stripe" | "airwallex";
35
- client_secret?: string;
36
33
  stripe_pk?: string;
34
+ checkout_attempt_id?: string;
37
35
  merchant_session?: {
38
36
  [key: string]: unknown;
39
37
  };
@@ -43,6 +41,17 @@ type Airwallex3dsNextAction = {
43
41
  url: string;
44
42
  };
45
43
  type ApplePayConfirmRequest = {
44
+ processor_id?: string;
45
+ customer_info?: ApplePayCustomerInfo;
46
+ fraud_metadata?: {
47
+ ipAddress?: string;
48
+ browserInfo?: {
49
+ [key: string]: unknown;
50
+ };
51
+ processorFraudInfo?: {
52
+ [key: string]: unknown;
53
+ };
54
+ };
46
55
  payment_method_id?: string;
47
56
  apple_pay_token?: ApplePayEncryptedToken | {
48
57
  [key: string]: unknown;
@@ -1 +1 @@
1
- {"version":3,"file":"apple-pay.d.mts","names":[],"sources":["../../src/payment-methods/apple-pay.ts"],"sourcesContent":[],"mappings":";;;;;;;KAYY,oBAAA;;;;;AAAA,KAMA,oBAAA,GANoB;EAMpB,YAAA,EAAA,MAAA;EAcA,aAAA,EAZK,oBAYgB;EAkBrB,cAAA,EAAA;IAKA,SAAA,CAAA,EAAA,MAAA;IAaA,WAAA,CAAA,EAAA;MAsBA,CAAA,GAAA,EAAA,MAAA,CAAA,EAAA,OAAqB;IAgQX,CAAA;IAmIN,kBAAkB,CAAA,EAAA;MAOlB,CAAA,GAAA,EAAA,MAAA,CAAA,EAAA,OAAqB;IAyf/B,CAAA;EA4G2B,CAAA;EAAqB,aAAA,CAAA,EAAA,MAAA;EA2BvB,cAAA,CAAA,EAAA,MAAA;EAAO,kBAAA,CAAA,EAAA,MAAA;CAvIX;KA77Bf,qBAAA;;;;;;;;;;;;KAkBA,sBAAA;;;;KAKA,sBAAA;;oBAIQ;;;;;;;;KASR,uBAAA;;;;;;;;gBAQI;;;;;;;;;;;;;KAcJ,qBAAA;;;;gBAII;iBACC;;;;;;;;;;;;;;;;;iBA2PK,eAAA,mDAGX,6CAER;;;;;;;;iBA8Ha,kBAAA,CAAA;;;;iBAOA,qBAAA,CAAA;cAyfV,uBAuIgC;;;;;6BA3BL,0BAAqB;;;;;;;;;;;;;;;;;;;;;;;;6BA2BvB"}
1
+ {"version":3,"file":"apple-pay.d.mts","names":[],"sources":["../../src/payment-methods/apple-pay.ts"],"sourcesContent":[],"mappings":";;;;;;;KAYY,oBAAA;;;;;AAAA,KAMA,oBAAA,GANoB;EAMpB,YAAA,EAAA,MAAA;EAiBA,aAAA,CAAA,EAZM,oBAYe;EAerB,cAAA,CAAA,EAAA;IAKA,SAAA,CAAA,EAAA,MAAA;IAuBA,WAAA,CAAA,EAAA;MAsBA,CAAA,GAAA,EAAA,MAAA,CAAA,EAAA,OAAqB;IAsQX,CAAA;IAkIN,kBAAkB,CAAA,EAAA;MAOlB,CAAA,GAAA,EAAA,MAAA,CAAA,EAAA,OAAqB;IA0f/B,CAAA;EA4G2B,CAAA;EAAqB,aAAA,CAAA,EAAA,MAAA;EA2BvB,cAAA,CAAA,EAAA,MAAA;EAAO,kBAAA,CAAA,EAAA,MAAA;CAvIX;KA18Bf,qBAAA;;;;;;;;;;KAeA,sBAAA;;;;KAKA,sBAAA;;kBAKM;;;;;;;;;;;oBASE;;;;;;;;KASR,uBAAA;;;;;;;;gBAQI;;;;;;;;;;;;;KAcJ,qBAAA;;;;gBAII;iBACC;;;;;;;;;;;;;;;;;iBAiQK,eAAA,mDAGX,6CAER;;;;;;;;iBA6Ha,kBAAA,CAAA;;;;iBAOA,qBAAA,CAAA;cA0fV,uBAuIgC;;;;;6BA3BL,0BAAqB;;;;;;;;;;;;;;;;;;;;;;;;6BA2BvB"}
@@ -1,7 +1,7 @@
1
- import { i as definePaymentMethod, n as collectFraudMetadata, o as getOrCreateCheckoutRequestId } from "../utils-B70Y8YcZ.mjs";
2
- import { n as AirwallexApplePayMockScenario, t as AirwallexApplePayAdapter } from "../airwallex-apple-pay-adapter-Bs8AdQKY.mjs";
3
- import { t as handleNextAction } from "../next-action-handlers-BZs04hYb.mjs";
4
- import { n as StripeApplePayAdapter, t as ApplePayMockScenario } from "../stripe-apple-pay-adapter-BLRjqgDf.mjs";
1
+ import { i as definePaymentMethod, n as collectFraudMetadata, o as getOrCreateCheckoutRequestId } from "../utils-Dc6zwOe1.mjs";
2
+ import { n as AirwallexApplePayMockScenario, t as AirwallexApplePayAdapter } from "../airwallex-apple-pay-adapter-CPz54c9e.mjs";
3
+ import { t as handleNextAction } from "../next-action-handlers-CLOt1wzO.mjs";
4
+ import { n as StripeApplePayAdapter, t as ApplePayMockScenario } from "../stripe-apple-pay-adapter-7rF6xRIG.mjs";
5
5
 
6
6
  //#region src/payment-methods/apple-pay.ts
7
7
  let preparedStripeState = null;
@@ -52,16 +52,11 @@ function validateOptions(options) {
52
52
  function getMockScenarioStr(mockScenario) {
53
53
  return mockScenario && mockScenario !== ApplePayMockScenario.None ? mockScenario : void 0;
54
54
  }
55
- async function callStripeStartEndpoint(apiBaseUrl, secureToken, options, mockScenarioStr, checkoutRequestId) {
55
+ async function callStripeStartEndpoint(apiBaseUrl, secureToken, options, checkoutRequestId) {
56
56
  return apiCall(`${apiBaseUrl}/api/checkout/${secureToken}/apple-pay/start`, {
57
57
  method: "POST",
58
58
  headers: { "Content-Type": "application/json" },
59
- body: JSON.stringify({
60
- processor_id: options.processorId,
61
- customer_info: options.customerInfo,
62
- fraud_metadata: collectFraudMetadata(),
63
- mock_scenario: mockScenarioStr
64
- })
59
+ body: JSON.stringify({ processor_id: options.processorId })
65
60
  }, checkoutRequestId);
66
61
  }
67
62
  function initializeStripeAdapter(stripePk, mockScenario) {
@@ -69,11 +64,14 @@ function initializeStripeAdapter(stripePk, mockScenario) {
69
64
  if (!adapter.initialize(stripePk)) return { error: "Stripe.js not loaded. Add <script src=\"https://js.stripe.com/v3/\"><\/script> to your page." };
70
65
  return { adapter };
71
66
  }
72
- async function callStripeConfirmEndpoint(apiBaseUrl, secureToken, paymentMethodId, mockScenarioStr, checkoutRequestId, payerEmail) {
67
+ async function callStripeConfirmEndpoint(apiBaseUrl, secureToken, options, paymentMethodId, mockScenarioStr, checkoutRequestId, payerEmail) {
73
68
  const result = await apiCall(`${apiBaseUrl}/api/checkout/${secureToken}/apple-pay/confirm`, {
74
69
  method: "POST",
75
70
  headers: { "Content-Type": "application/json" },
76
71
  body: JSON.stringify({
72
+ processor_id: options.processorId,
73
+ customer_info: options.customerInfo,
74
+ fraud_metadata: collectFraudMetadata(),
77
75
  payment_method_id: paymentMethodId,
78
76
  payer_email: payerEmail,
79
77
  mock_scenario: mockScenarioStr
@@ -169,7 +167,7 @@ async function prepareApplePay(apiBaseUrl, secureToken, options, environment) {
169
167
  applePay: true
170
168
  };
171
169
  }
172
- const startResult = await callStripeStartEndpoint(apiBaseUrl, secureToken, options, mockScenarioStr, checkoutRequestId);
170
+ const startResult = await callStripeStartEndpoint(apiBaseUrl, secureToken, options, checkoutRequestId);
173
171
  if (startResult.error || !startResult.data) return {
174
172
  success: false,
175
173
  error: startResult.error || "Failed to start Apple Pay"
@@ -408,7 +406,7 @@ const defSubmitPayment = (states, getAutoPrepareConfig, onClearPrepared) => {
408
406
  return { errors: { apple_pay: "error" in paymentResult$1 ? paymentResult$1.error : "Unknown error" } };
409
407
  }
410
408
  const { paymentMethodId: paymentMethodId$1, paymentMethodEvent: paymentMethodEvent$1, billingDetails: billingDetails$1 } = paymentResult$1;
411
- const confirmResult$1 = await callStripeConfirmEndpoint(apiBaseUrl, secureToken, paymentMethodId$1, mockScenarioStr, preparedStripeState.checkoutRequestId, billingDetails$1?.email);
409
+ const confirmResult$1 = await callStripeConfirmEndpoint(apiBaseUrl, secureToken, applePayOptions, paymentMethodId$1, mockScenarioStr, preparedStripeState.checkoutRequestId, billingDetails$1?.email);
412
410
  if (confirmResult$1.data) {
413
411
  paymentMethodEvent$1.complete("success");
414
412
  clearPreparedApplePay();
@@ -433,7 +431,7 @@ const defSubmitPayment = (states, getAutoPrepareConfig, onClearPrepared) => {
433
431
  preparedAirwallexState = null;
434
432
  }
435
433
  }
436
- const startResult = await callStripeStartEndpoint(apiBaseUrl, secureToken, applePayOptions, mockScenarioStr, checkoutRequestId);
434
+ const startResult = await callStripeStartEndpoint(apiBaseUrl, secureToken, applePayOptions, checkoutRequestId);
437
435
  if (startResult.error || !startResult.data) return { errors: { apple_pay: startResult.error || "Failed to start Apple Pay" } };
438
436
  const startData = startResult.data;
439
437
  console.warn("[ApplePay] Stripe flow without prepared state - may fail due to user gesture requirements");
@@ -455,7 +453,7 @@ const defSubmitPayment = (states, getAutoPrepareConfig, onClearPrepared) => {
455
453
  return { errors: { apple_pay: "error" in paymentResult ? paymentResult.error : "Unknown error" } };
456
454
  }
457
455
  const { paymentMethodId, paymentMethodEvent, billingDetails } = paymentResult;
458
- const confirmResult = await callStripeConfirmEndpoint(apiBaseUrl, secureToken, paymentMethodId, mockScenarioStr, checkoutRequestId, billingDetails?.email);
456
+ const confirmResult = await callStripeConfirmEndpoint(apiBaseUrl, secureToken, applePayOptions, paymentMethodId, mockScenarioStr, checkoutRequestId, billingDetails?.email);
459
457
  if (confirmResult.data) {
460
458
  paymentMethodEvent.complete("success");
461
459
  return confirmResult;
@@ -1 +1 @@
1
- {"version":3,"file":"apple-pay.mjs","names":["preparedStripeState: PreparedStripeApplePayState | null","preparedAirwallexState: PreparedAirwallexState | null","applePayScriptLoadPromise: Promise<void> | null","airwallexMockScenario: AirwallexApplePayMockScenario","config: AirwallexApplePayConfig","submitPayment: TInternalFuncs[\"submitPayment\"]","paymentResult","confirmResult","paymentMethodId","billingDetails","autoPrepareConfig: AutoPrepareConfig | null","onApplePayReadyCallbacks: ((isReady: boolean) => void)[]","pendingAutoPrepareArgs: { apiBaseUrl: string; secureToken: string; environment: string } | null","pendingPrepareResolvers: (() => void)[]"],"sources":["../../src/payment-methods/apple-pay.ts"],"sourcesContent":["import type { PaymentKitErrors, PaymentKitStates, TInternalFuncs } from \"../types\";\nimport { collectFraudMetadata, definePaymentMethod, getOrCreateCheckoutRequestId } from \"../utils\";\nimport {\n AirwallexApplePayAdapter,\n type AirwallexApplePayConfig,\n AirwallexApplePayMockScenario,\n type ApplePayEncryptedToken,\n} from \"./airwallex-apple-pay-adapter\";\nimport { handleNextAction } from \"./next-action-handlers\";\nimport { ApplePayMockScenario, StripeApplePayAdapter } from \"./stripe-apple-pay-adapter\";\n\n// Apple Pay-specific types\nexport type ApplePayCustomerInfo = {\n first_name: string;\n last_name: string;\n email?: string;\n};\n\nexport type ApplePayStartRequest = {\n processor_id: string;\n customer_info: ApplePayCustomerInfo;\n fraud_metadata: {\n ipAddress?: string;\n browserInfo?: { [key: string]: unknown };\n processorFraudInfo?: { [key: string]: unknown };\n };\n mock_scenario?: string;\n // Airwallex-specific fields (sent on /start for merchant validation)\n validation_url?: string;\n initiative_context?: string;\n};\n\nexport type ApplePayStartResponse = {\n checkout_attempt_id: string;\n amount: number;\n currency: string;\n country: string;\n\n // Processor discriminator\n processor: \"stripe\" | \"airwallex\";\n\n // Stripe-specific fields (when processor=\"stripe\")\n client_secret?: string;\n stripe_pk?: string;\n\n // Airwallex-specific fields (when processor=\"airwallex\")\n merchant_session?: { [key: string]: unknown }; // Apple merchant session for completeMerchantValidation()\n};\n\n// Airwallex 3DS next action type (matches backend snake_case response)\nexport type Airwallex3dsNextAction = {\n type: \"airwallex_3ds\";\n url: string;\n};\n\nexport type ApplePayConfirmRequest = {\n // Stripe: Send PaymentMethod ID\n payment_method_id?: string;\n // Airwallex: Send encrypted Apple Pay token\n apple_pay_token?: ApplePayEncryptedToken | { [key: string]: unknown };\n // Email from payment sheet (Stripe Apple Pay) — used to fill missing customer email\n payer_email?: string;\n // Name from payment sheet — used to fill missing customer name\n payer_first_name?: string;\n payer_last_name?: string;\n mock_scenario?: string;\n};\n\nexport type ApplePayConfirmResponse = {\n charge_status: \"success\" | \"fail\" | \"pending\";\n transaction_id?: string;\n error_code?: string;\n error_message_for_customer?: string;\n error_message_for_debug?: string;\n checkout_attempt_id: string;\n checkout_session_id?: string;\n next_action?: Airwallex3dsNextAction; // Present when charge_status=\"pending\" for 3DS\n payment_intent_id?: string;\n customer_id?: string;\n payment_method_id?: string;\n processor_used?: string;\n subscription_id?: string;\n invoice_id?: string;\n invoice_number?: number;\n card_brand?: string;\n card_last4?: string;\n card_exp_month?: number;\n card_exp_year?: number;\n};\n\nexport type ApplePaySubmitOptions = {\n /** Processor external ID — optional when using auto-prepare (SDK fetches from checkout session) */\n processorId?: string;\n processorType?: \"stripe\" | \"airwallex\";\n customerInfo: ApplePayCustomerInfo;\n mockScenario?: ApplePayMockScenario;\n amount?: number; // Amount in atomic units (cents) for Apple Pay sheet display\n currency?: string; // Currency code (e.g., \"usd\")\n /** Country code — optional when using auto-prepare (fetched from backend) */\n country?: string;\n merchantName?: string; // Merchant display name on Apple Pay sheet\n};\n\ntype ApplePayResult =\n | { data: { [key: string]: unknown }; errors?: undefined }\n | { data?: undefined; errors: PaymentKitErrors };\n\n// =============================================================================\n// Prepared Payment State (for Stripe pre-fetching before click)\n// =============================================================================\n\ntype PreparedStripeApplePayState = {\n processor: \"stripe\";\n adapter: StripeApplePayAdapter;\n startData: ApplePayStartResponse;\n mockScenarioStr?: string;\n checkoutRequestId: string;\n};\n\n// Global state to store prepared Apple Pay data (Stripe only - Airwallex uses native session)\nlet preparedStripeState: PreparedStripeApplePayState | null = null;\n\n// Prepared Airwallex state — persists options from prepare call for use at submit time\n// The amount field is fetched from the session via /session-info endpoint to fix\n// the $0.00 bug where options.amount was undefined and defaulted to 0.\ntype PreparedAirwallexState = {\n country: string;\n currency?: string;\n amount?: number;\n merchantName?: string;\n};\nlet preparedAirwallexState: PreparedAirwallexState | null = null;\n\n// Response type for Airwallex Apple Pay session-info endpoint\ntype AirwallexSessionInfoResponse = {\n amount: number;\n currency: string;\n country: string;\n};\n\n// =============================================================================\n// Auto-Prepare State\n// =============================================================================\n\ntype AutoPrepareConfig = {\n processorId: string;\n processorType: \"airwallex\" | \"stripe\" | undefined;\n};\n\ntype CheckoutSessionConfig = {\n express_checkout_processor_id?: string | null;\n express_checkout_processor_type?: string | null;\n};\n\n// =============================================================================\n// Apple Pay SDK Loader\n// =============================================================================\n\n// Loads Apple's JS SDK, which makes window.ApplePaySession available in non-Safari\n// browsers (Chrome, Firefox, etc.) and enables the \"Scan Code with iPhone\" QR flow.\nlet applePayScriptLoadPromise: Promise<void> | null = null;\nasync function loadApplePayScript(): Promise<void> {\n if (typeof window === \"undefined\") return;\n if (window.ApplePaySession) return;\n if (document.getElementById(\"__pk_apple_pay_sdk\")) {\n // Tag exists — if we have a cached promise, wait for it; otherwise the tag\n // already resolved (e.g. after a module reload) so return immediately.\n return applePayScriptLoadPromise ?? Promise.resolve();\n }\n applePayScriptLoadPromise = new Promise<void>((resolve, reject) => {\n const script = document.createElement(\"script\");\n script.id = \"__pk_apple_pay_sdk\";\n script.src = \"https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js\";\n script.crossOrigin = \"anonymous\";\n // NOTE: Apple doesn't publish stable SRI hashes for the 1.latest pointer,\n // so integrity checking is omitted. CSP must allow script-src https://applepay.cdn-apple.com.\n script.onload = () => resolve();\n script.onerror = () => {\n // Clear cached state so the next prepareApplePay call can retry.\n applePayScriptLoadPromise = null;\n document.getElementById(\"__pk_apple_pay_sdk\")?.remove();\n reject(new Error(\"Failed to load Apple Pay SDK\"));\n };\n document.head.appendChild(script);\n });\n return applePayScriptLoadPromise;\n}\n\n// =============================================================================\n// Helper Functions\n// =============================================================================\n\nasync function apiCall<T>(\n url: string,\n options: RequestInit,\n checkoutRequestId?: string,\n): Promise<{ data?: T; error?: string }> {\n const headers = new Headers(options.headers);\n if (checkoutRequestId) {\n headers.set(\"x-request-id\", checkoutRequestId);\n }\n\n const response = await fetch(url, { ...options, headers });\n if (!response.ok) {\n let errorMessage = `Request failed (${response.status})`;\n try {\n const errorData = await response.json();\n errorMessage = errorData.detail || errorMessage;\n } catch {\n errorMessage = response.statusText || errorMessage;\n }\n return { error: errorMessage };\n }\n return { data: await response.json() };\n}\n\nfunction validateOptions(options: ApplePaySubmitOptions): PaymentKitErrors | null {\n if (!options?.processorId) {\n return { processor_id: \"Processor ID is required\" };\n }\n // For Airwallex, country is required (either directly or from prepared state)\n if (options.processorType === \"airwallex\" && !options.country && !preparedAirwallexState?.country) {\n return { country: \"Country is required for Airwallex Apple Pay\" };\n }\n return null;\n}\n\nfunction getMockScenarioStr(mockScenario?: ApplePayMockScenario): string | undefined {\n return mockScenario && mockScenario !== ApplePayMockScenario.None ? mockScenario : undefined;\n}\n\n// =============================================================================\n// Stripe Apple Pay Flow\n// =============================================================================\n\nasync function callStripeStartEndpoint(\n apiBaseUrl: string,\n secureToken: string,\n options: ApplePaySubmitOptions,\n mockScenarioStr?: string,\n checkoutRequestId?: string,\n): Promise<{ data?: ApplePayStartResponse; error?: string }> {\n return apiCall<ApplePayStartResponse>(\n `${apiBaseUrl}/api/checkout/${secureToken}/apple-pay/start`,\n {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n processor_id: options.processorId,\n customer_info: options.customerInfo,\n fraud_metadata: collectFraudMetadata(),\n mock_scenario: mockScenarioStr,\n } as ApplePayStartRequest),\n },\n checkoutRequestId,\n );\n}\n\nfunction initializeStripeAdapter(\n stripePk: string,\n mockScenario?: ApplePayMockScenario,\n): { adapter?: StripeApplePayAdapter; error?: string } {\n const adapter = new StripeApplePayAdapter(mockScenario);\n\n if (!adapter.initialize(stripePk)) {\n return { error: 'Stripe.js not loaded. Add <script src=\"https://js.stripe.com/v3/\"></script> to your page.' };\n }\n\n return { adapter };\n}\n\nasync function callStripeConfirmEndpoint(\n apiBaseUrl: string,\n secureToken: string,\n paymentMethodId: string,\n mockScenarioStr?: string,\n checkoutRequestId?: string,\n payerEmail?: string,\n): Promise<ApplePayResult> {\n const result = await apiCall<ApplePayConfirmResponse>(\n `${apiBaseUrl}/api/checkout/${secureToken}/apple-pay/confirm`,\n {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n payment_method_id: paymentMethodId,\n payer_email: payerEmail,\n mock_scenario: mockScenarioStr,\n } as ApplePayConfirmRequest),\n },\n checkoutRequestId,\n );\n\n if (result.error || !result.data) {\n return { errors: { apple_pay: result.error || \"Failed to confirm payment\" } };\n }\n\n const confirmData = result.data;\n\n if (confirmData.charge_status === \"success\") {\n return {\n data: {\n id: confirmData.transaction_id,\n checkoutAttemptId: confirmData.checkout_attempt_id,\n checkoutSessionId: confirmData.checkout_session_id ?? secureToken,\n state: \"checkout_succeeded\",\n paymentIntentId: confirmData.payment_intent_id,\n customerId: confirmData.customer_id,\n paymentMethodId: confirmData.payment_method_id,\n processorUsed: confirmData.processor_used,\n subscriptionId: confirmData.subscription_id,\n invoiceId: confirmData.invoice_id,\n invoiceNumber: confirmData.invoice_number,\n cardBrand: confirmData.card_brand,\n cardLast4: confirmData.card_last4,\n cardExpMonth: confirmData.card_exp_month,\n cardExpYear: confirmData.card_exp_year,\n errorCode: confirmData.error_code,\n errorMessageForCustomer: confirmData.error_message_for_customer,\n errorMessageForDebug: confirmData.error_message_for_debug,\n nextAction: confirmData.next_action,\n },\n };\n }\n\n return {\n errors: {\n apple_pay: confirmData.error_message_for_customer || confirmData.error_message_for_debug || \"Payment failed\",\n },\n };\n}\n\n// =============================================================================\n// Prepare Function (call BEFORE the click handler)\n// =============================================================================\n\n/**\n * Pre-fetch Apple Pay data and prepare the PaymentRequest.\n * Call this when the checkout page loads, NOT in the click handler.\n *\n * For Stripe: pre-fetches data and prepares PaymentRequest for immediate show.\n * For Airwallex: returns success with processor=\"airwallex\" so submit uses native ApplePaySession.\n *\n * @deprecated The SDK now calls this automatically on init. Use `onApplePayReady` to observe\n * readiness and `notifyAmountChanged` to trigger re-prepare after amount changes.\n */\nexport async function prepareApplePay(\n apiBaseUrl: string,\n secureToken: string,\n options: ApplePaySubmitOptions,\n environment: string,\n): Promise<{ success: boolean; error?: string; applePay?: boolean }> {\n console.log(\"[ApplePay] prepareApplePay called\");\n\n // Clear any previous state\n preparedStripeState = null;\n\n const mockScenarioStr = getMockScenarioStr(options.mockScenario);\n const checkoutRequestId = getOrCreateCheckoutRequestId(environment);\n console.log(`[ApplePay] Using checkout_request_id: ${checkoutRequestId}`);\n\n // Airwallex: Load Apple Pay SDK (enables QR code flow in non-Safari browsers),\n // then fetch session info to get the correct amount from line items.\n // This fixes the $0.00 bug where options.amount was undefined and defaulted to 0.\n if (options.processorType === \"airwallex\") {\n console.log(\"[ApplePay] Airwallex processor - loading Apple Pay SDK, fetching session info for amount\");\n\n // In mock mode, skip SDK loading and availability check (jsdom has no ApplePaySession)\n if (!mockScenarioStr) {\n try {\n await loadApplePayScript();\n } catch (err) {\n console.error(\"[ApplePay] Failed to load Apple Pay SDK:\", err);\n return { success: false, error: \"Failed to load Apple Pay\" };\n }\n\n let canMake = false;\n try {\n canMake = !!window.ApplePaySession?.canMakePayments();\n } catch {\n canMake = false;\n }\n if (!canMake) {\n console.log(\"[ApplePay] Apple Pay not available on this device/browser\");\n return { success: false, error: \"Apple Pay not available on this device\" };\n }\n }\n\n // Fetch session info (amount, currency, country) from backend\n const sessionInfoResult = await callAirwallexSessionInfoEndpoint(apiBaseUrl, secureToken, checkoutRequestId);\n\n if (sessionInfoResult.error || !sessionInfoResult.data) {\n console.error(\"[ApplePay] Failed to fetch session info:\", sessionInfoResult.error);\n return { success: false, error: sessionInfoResult.error || \"Failed to fetch Apple Pay session info\" };\n }\n\n console.log(\"[ApplePay] Got session info:\", sessionInfoResult.data);\n const resolvedAmount = sessionInfoResult.data.amount;\n const resolvedCurrency = sessionInfoResult.data.currency;\n const resolvedCountry = sessionInfoResult.data.country || options.country;\n\n preparedAirwallexState = {\n country: resolvedCountry,\n currency: resolvedCurrency,\n amount: resolvedAmount,\n merchantName: options.merchantName,\n };\n console.log(\"[ApplePay] Airwallex prepared state:\", preparedAirwallexState);\n return { success: true, applePay: true };\n }\n\n // Call Stripe start endpoint to get PaymentIntent details\n const startResult = await callStripeStartEndpoint(\n apiBaseUrl,\n secureToken,\n options,\n mockScenarioStr,\n checkoutRequestId,\n );\n if (startResult.error || !startResult.data) {\n return { success: false, error: startResult.error || \"Failed to start Apple Pay\" };\n }\n\n const startData = startResult.data;\n\n // Initialize Stripe adapter\n if (!startData.stripe_pk) {\n return { success: false, error: \"Stripe publishable key not provided\" };\n }\n\n const { adapter, error: adapterError } = initializeStripeAdapter(startData.stripe_pk, options.mockScenario);\n if (!adapter) {\n return { success: false, error: adapterError };\n }\n\n // Create PaymentRequest and call canMakePayment() (required before show())\n const prepareResult = await adapter.preparePaymentRequest({\n country: startData.country,\n currency: startData.currency.toLowerCase(),\n total: {\n label: \"Total\",\n amount: startData.amount,\n },\n });\n\n if (!prepareResult.success) {\n return {\n success: false,\n error: prepareResult.error || \"Failed to prepare payment request\",\n applePay: prepareResult.applePay,\n };\n }\n\n if (!prepareResult.applePay) {\n return {\n success: false,\n error: \"Apple Pay is not available on this device or Stripe account\",\n applePay: false,\n };\n }\n\n // Store the prepared state\n preparedStripeState = {\n processor: \"stripe\",\n adapter,\n startData,\n mockScenarioStr,\n checkoutRequestId,\n };\n\n console.log(\"[ApplePay] prepareApplePay success (Stripe), ready for click\");\n return { success: true, applePay: true };\n}\n\n/**\n * Check if Apple Pay has been prepared and is ready.\n */\nexport function isApplePayPrepared(): boolean {\n return (preparedStripeState?.adapter.isPrepared() ?? false) || preparedAirwallexState !== null;\n}\n\n/**\n * Clear prepared state (call on unmount or when checkout changes).\n */\nexport function clearPreparedApplePay(): void {\n if (preparedStripeState) {\n preparedStripeState.adapter.clearPrepared();\n }\n preparedStripeState = null;\n preparedAirwallexState = null;\n}\n\n// =============================================================================\n// Airwallex Apple Pay Flow\n// =============================================================================\n\n/**\n * Fetch session info (amount, currency, country) from the backend.\n * Called during prepareApplePay to get the correct amount BEFORE showing the payment sheet.\n * This fixes the $0.00 bug where options.amount was undefined and defaulted to 0.\n */\nasync function callAirwallexSessionInfoEndpoint(\n apiBaseUrl: string,\n secureToken: string,\n checkoutRequestId?: string,\n): Promise<{ data?: AirwallexSessionInfoResponse; error?: string }> {\n return apiCall<AirwallexSessionInfoResponse>(\n `${apiBaseUrl}/api/checkout/${secureToken}/airwallex/apple-pay/session-info`,\n {\n method: \"GET\",\n headers: { \"Content-Type\": \"application/json\" },\n },\n checkoutRequestId,\n );\n}\n\nasync function callAirwallexStartEndpoint(\n apiBaseUrl: string,\n secureToken: string,\n options: ApplePaySubmitOptions,\n validationUrl: string,\n initiativeContext: string,\n mockScenarioStr?: string,\n checkoutRequestId?: string,\n): Promise<{ data?: ApplePayStartResponse; error?: string }> {\n return apiCall<ApplePayStartResponse>(\n `${apiBaseUrl}/api/checkout/${secureToken}/airwallex/apple-pay/start`,\n {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n processor_id: options.processorId,\n customer_info: options.customerInfo,\n fraud_metadata: collectFraudMetadata(),\n validation_url: validationUrl,\n initiative_context: initiativeContext,\n mock_scenario: mockScenarioStr,\n } as ApplePayStartRequest),\n },\n checkoutRequestId,\n );\n}\n\nasync function callAirwallexConfirmEndpoint(\n apiBaseUrl: string,\n secureToken: string,\n applePayToken: ApplePayEncryptedToken,\n mockScenarioStr?: string,\n checkoutRequestId?: string,\n payerEmail?: string,\n payerFirstName?: string,\n payerLastName?: string,\n): Promise<ApplePayConfirmResponse> {\n const result = await apiCall<ApplePayConfirmResponse>(\n `${apiBaseUrl}/api/checkout/${secureToken}/airwallex/apple-pay/confirm`,\n {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n apple_pay_token: applePayToken,\n payer_email: payerEmail,\n payer_first_name: payerFirstName,\n payer_last_name: payerLastName,\n mock_scenario: mockScenarioStr,\n } as ApplePayConfirmRequest),\n },\n checkoutRequestId,\n );\n\n if (result.error || !result.data) {\n return {\n charge_status: \"fail\",\n error_message_for_debug: result.error || \"Failed to confirm payment\",\n checkout_attempt_id: \"\",\n };\n }\n\n return result.data;\n}\n\nasync function callAirwallexVerifyEndpoint(\n apiBaseUrl: string,\n secureToken: string,\n checkoutRequestId?: string,\n): Promise<ApplePayConfirmResponse> {\n const result = await apiCall<ApplePayConfirmResponse>(\n `${apiBaseUrl}/api/checkout/${secureToken}/airwallex/apple-pay/verify`,\n {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n },\n checkoutRequestId,\n );\n\n if (result.error || !result.data) {\n return {\n charge_status: \"fail\",\n error_message_for_debug: result.error || \"Failed to verify payment\",\n checkout_attempt_id: \"\",\n };\n }\n\n return result.data;\n}\n\nfunction toApplePayResult(response: ApplePayConfirmResponse, secureToken: string): ApplePayResult {\n if (response.charge_status === \"success\") {\n return {\n data: {\n id: response.transaction_id,\n checkoutAttemptId: response.checkout_attempt_id,\n checkoutSessionId: response.checkout_session_id ?? secureToken,\n state: \"checkout_succeeded\",\n paymentIntentId: response.payment_intent_id,\n customerId: response.customer_id,\n paymentMethodId: response.payment_method_id,\n processorUsed: response.processor_used,\n subscriptionId: response.subscription_id,\n invoiceId: response.invoice_id,\n invoiceNumber: response.invoice_number,\n cardBrand: response.card_brand,\n cardLast4: response.card_last4,\n cardExpMonth: response.card_exp_month,\n cardExpYear: response.card_exp_year,\n errorCode: response.error_code,\n errorMessageForCustomer: response.error_message_for_customer,\n errorMessageForDebug: response.error_message_for_debug,\n nextAction: response.next_action,\n },\n };\n }\n return {\n errors: {\n apple_pay: response.error_message_for_customer || response.error_message_for_debug || \"Payment failed\",\n },\n };\n}\n\nconst MAX_USER_ACTIONS = 5;\n\n/**\n * Run the Airwallex Apple Pay flow with 3DS loop support.\n *\n * Flow:\n * 1. Show native ApplePaySession, call /start for merchant validation\n * 2. On payment authorized, call /confirm with token\n * 3. If 3DS required, handle it and call /verify\n * 4. Loop if more 3DS needed\n */\nasync function runAirwallexFlow(\n apiBaseUrl: string,\n secureToken: string,\n options: ApplePaySubmitOptions,\n mockScenarioStr?: string,\n checkoutRequestId?: string,\n): Promise<ApplePayResult> {\n // Convert mock scenario\n let airwallexMockScenario: AirwallexApplePayMockScenario = AirwallexApplePayMockScenario.None;\n if (options.mockScenario === ApplePayMockScenario.Success) {\n airwallexMockScenario = AirwallexApplePayMockScenario.Success;\n } else if (options.mockScenario === ApplePayMockScenario.Cancelled) {\n airwallexMockScenario = AirwallexApplePayMockScenario.Cancelled;\n }\n\n // Defense-in-depth: validateOptions should catch this earlier, but guard against\n // future callers that bypass validation to avoid an unhandled TypeError on `.toUpperCase()`\n if (!options.country) {\n return { errors: { apple_pay: \"Country is required for Airwallex Apple Pay\" } };\n }\n\n // Auto-fetch amount from session if not provided (e.g. merchant didn't call prepareApplePay first)\n if (!options.amount) {\n const sessionInfoResult = await callAirwallexSessionInfoEndpoint(apiBaseUrl, secureToken, checkoutRequestId);\n if (sessionInfoResult.data) {\n options.amount = sessionInfoResult.data.amount;\n options.currency = options.currency || sessionInfoResult.data.currency;\n options.country = options.country || sessionInfoResult.data.country;\n }\n }\n\n // Initialize adapter\n const adapter = new AirwallexApplePayAdapter(airwallexMockScenario);\n\n const config: AirwallexApplePayConfig = {\n amount: options.amount || 0,\n currency: (options.currency || \"USD\").toUpperCase(),\n country: options.country.toUpperCase(),\n merchantName: options.merchantName || \"Total\",\n };\n\n if (!adapter.initialize(config)) {\n return { errors: { apple_pay: \"Apple Pay not available on this device\" } };\n }\n\n const canPay = await adapter.canMakePayment();\n if (!canPay) {\n return { errors: { apple_pay: \"Apple Pay not available on this device\" } };\n }\n\n // Get current domain for initiative_context\n const initiativeContext = typeof window !== \"undefined\" ? window.location.hostname : \"\";\n\n // In mock mode, call /start first to create checkout attempt (mock adapter skips merchant validation)\n if (airwallexMockScenario !== AirwallexApplePayMockScenario.None) {\n const startResult = await callAirwallexStartEndpoint(\n apiBaseUrl,\n secureToken,\n options,\n \"https://mock-apple-pay-gateway.example.com/paymentservices/startSession\",\n initiativeContext,\n mockScenarioStr,\n checkoutRequestId,\n );\n if (startResult.error || !startResult.data) {\n return { errors: { apple_pay: startResult.error || \"Failed to start mock checkout\" } };\n }\n }\n\n // Show Apple Pay sheet with merchant validation callback\n const paymentResult = await adapter.showPaymentSheet(async (validationUrl: string) => {\n // Call /start endpoint for merchant validation\n const startResult = await callAirwallexStartEndpoint(\n apiBaseUrl,\n secureToken,\n options,\n validationUrl,\n initiativeContext,\n mockScenarioStr,\n checkoutRequestId,\n );\n\n if (startResult.error || !startResult.data) {\n return { error: startResult.error || \"Merchant validation failed\" };\n }\n\n if (!startResult.data.merchant_session) {\n return { error: \"No merchant session returned from server\" };\n }\n\n return { merchantSession: startResult.data.merchant_session };\n });\n\n if (!paymentResult.success) {\n if (\"cancelled\" in paymentResult && paymentResult.cancelled) {\n return { errors: { apple_pay: \"Apple Pay cancelled by user\" } };\n }\n return { errors: { apple_pay: paymentResult.error || \"Apple Pay failed\" } };\n }\n\n const { token, complete, payerEmail, payerFirstName, payerLastName } = paymentResult;\n\n // Call /confirm with the token\n let response = await callAirwallexConfirmEndpoint(\n apiBaseUrl,\n secureToken,\n token,\n mockScenarioStr,\n checkoutRequestId,\n payerEmail,\n payerFirstName,\n payerLastName,\n );\n\n // Handle 3DS loop\n let userActionCount = 0;\n while (response.charge_status === \"pending\" && response.next_action && userActionCount < MAX_USER_ACTIONS) {\n userActionCount++;\n\n // Handle 3DS challenge — Airwallex3dsNextAction is structurally identical to SDK's Airwallex3dsAction\n const nextAction = response.next_action as Airwallex3dsNextAction;\n const actionResult = await handleNextAction({ type: nextAction.type, url: nextAction.url });\n\n // Call verify endpoint\n const verifyResponse = await callAirwallexVerifyEndpoint(apiBaseUrl, secureToken, checkoutRequestId);\n\n // Check if another 3DS action is required\n if (verifyResponse.charge_status === \"pending\" && verifyResponse.next_action) {\n if (!actionResult.success) {\n console.log(\"[ApplePay:Airwallex] 3DS failed but retry available, continuing loop...\");\n }\n response = verifyResponse;\n continue;\n }\n\n // No more actions - check final result\n if (!actionResult.success) {\n complete(\"fail\");\n return {\n errors: {\n apple_pay:\n verifyResponse.error_message_for_customer ||\n verifyResponse.error_message_for_debug ||\n actionResult.error ||\n \"3DS authentication failed\",\n },\n };\n }\n\n // 3DS succeeded\n complete(verifyResponse.charge_status === \"success\" ? \"success\" : \"fail\");\n return toApplePayResult(verifyResponse, secureToken);\n }\n\n // Check for max attempts exceeded\n if (userActionCount >= MAX_USER_ACTIONS) {\n complete(\"fail\");\n return { errors: { apple_pay: \"Too many authentication attempts. Please try again.\" } };\n }\n\n // No 3DS required - complete with result\n complete(response.charge_status === \"success\" ? \"success\" : \"fail\");\n return toApplePayResult(response, secureToken);\n}\n\n// =============================================================================\n// Main Submit Function\n// =============================================================================\n\nconst defSubmitPayment = (\n states: PaymentKitStates,\n getAutoPrepareConfig: () => AutoPrepareConfig | null,\n onClearPrepared: () => void,\n) => {\n const submitPayment: TInternalFuncs[\"submitPayment\"] = async (_fields, options) => {\n const { apiBaseUrl, secureToken, environment } = states;\n const applePayOptions = options as ApplePaySubmitOptions;\n\n // Fill in processorId/processorType from auto-prepare config if merchant didn't provide them\n const autoPrepareConfig = getAutoPrepareConfig();\n if (!applePayOptions.processorId && autoPrepareConfig?.processorId) {\n applePayOptions.processorId = autoPrepareConfig.processorId;\n }\n if (!applePayOptions.processorType && autoPrepareConfig?.processorType) {\n applePayOptions.processorType = autoPrepareConfig.processorType;\n }\n\n // Validate options\n const validationError = validateOptions(applePayOptions);\n if (validationError) {\n return { errors: validationError };\n }\n\n try {\n const mockScenarioStr = getMockScenarioStr(applePayOptions.mockScenario);\n const checkoutRequestId = getOrCreateCheckoutRequestId(environment);\n console.log(`[ApplePay] Using checkout_request_id: ${checkoutRequestId}`);\n\n // Check if we have prepared Stripe state\n if (preparedStripeState?.adapter.isPrepared()) {\n console.log(\"[ApplePay] Using prepared Stripe state for immediate sheet display\");\n\n // Show Apple Pay sheet IMMEDIATELY using the prepared PaymentRequest\n const paymentResultPromise = preparedStripeState.adapter.showPreparedPaymentSheet();\n const paymentResult = await paymentResultPromise;\n\n if (!paymentResult.success) {\n clearPreparedApplePay();\n\n if (\"cancelled\" in paymentResult && paymentResult.cancelled) {\n return { errors: { apple_pay: \"Apple Pay cancelled by user\" } };\n }\n const errorMessage = \"error\" in paymentResult ? paymentResult.error : \"Unknown error\";\n return { errors: { apple_pay: errorMessage } };\n }\n\n const { paymentMethodId, paymentMethodEvent, billingDetails } = paymentResult;\n\n // Confirm with backend using the PaymentMethod ID\n const confirmResult = await callStripeConfirmEndpoint(\n apiBaseUrl,\n secureToken,\n paymentMethodId,\n mockScenarioStr,\n preparedStripeState.checkoutRequestId,\n billingDetails?.email,\n );\n\n // Complete Apple Pay UI based on result\n if (confirmResult.data) {\n paymentMethodEvent.complete(\"success\");\n clearPreparedApplePay();\n return confirmResult;\n } else {\n paymentMethodEvent.complete(\"fail\");\n clearPreparedApplePay();\n return confirmResult;\n }\n }\n\n // Check if this is an Airwallex processor - route directly to Airwallex flow\n if (applePayOptions.processorType === \"airwallex\") {\n console.log(\"[ApplePay] Running Airwallex flow (processorType=airwallex)\");\n // Merge prepare-time state into submit options so country/currency/amount/merchantName\n // are available even if the merchant only provided them at prepare time\n if (preparedAirwallexState) {\n if (applePayOptions.country == null) applePayOptions.country = preparedAirwallexState.country;\n if (applePayOptions.currency == null) applePayOptions.currency = preparedAirwallexState.currency;\n if (applePayOptions.amount == null) applePayOptions.amount = preparedAirwallexState.amount;\n if (applePayOptions.merchantName == null) applePayOptions.merchantName = preparedAirwallexState.merchantName;\n }\n try {\n return await runAirwallexFlow(apiBaseUrl, secureToken, applePayOptions, mockScenarioStr, checkoutRequestId);\n } finally {\n preparedAirwallexState = null;\n }\n }\n\n // No prepared state for Stripe - call start endpoint\n const startResult = await callStripeStartEndpoint(\n apiBaseUrl,\n secureToken,\n applePayOptions,\n mockScenarioStr,\n checkoutRequestId,\n );\n\n if (startResult.error || !startResult.data) {\n return { errors: { apple_pay: startResult.error || \"Failed to start Apple Pay\" } };\n }\n\n const startData = startResult.data;\n\n // Stripe flow without prepared state - this may fail due to user gesture requirements\n console.warn(\"[ApplePay] Stripe flow without prepared state - may fail due to user gesture requirements\");\n\n if (!startData.stripe_pk) {\n return { errors: { apple_pay: \"Stripe publishable key not provided\" } };\n }\n\n const { adapter, error: adapterError } = initializeStripeAdapter(\n startData.stripe_pk,\n applePayOptions.mockScenario,\n );\n if (!adapter) {\n return { errors: { apple_pay: adapterError || \"Failed to initialize Stripe adapter\" } };\n }\n\n // This will likely fail due to user gesture requirements\n const prepareResult = await adapter.preparePaymentRequest({\n country: startData.country,\n currency: startData.currency.toLowerCase(),\n total: { label: \"Total\", amount: startData.amount },\n });\n\n if (!prepareResult.success || !prepareResult.applePay) {\n return { errors: { apple_pay: prepareResult.error || \"Apple Pay not available\" } };\n }\n\n const paymentResult = await adapter.showPreparedPaymentSheet();\n\n if (!paymentResult.success) {\n if (\"cancelled\" in paymentResult && paymentResult.cancelled) {\n return { errors: { apple_pay: \"Apple Pay cancelled by user\" } };\n }\n const errorMessage = \"error\" in paymentResult ? paymentResult.error : \"Unknown error\";\n return { errors: { apple_pay: errorMessage } };\n }\n\n const { paymentMethodId, paymentMethodEvent, billingDetails } = paymentResult;\n\n const confirmResult = await callStripeConfirmEndpoint(\n apiBaseUrl,\n secureToken,\n paymentMethodId,\n mockScenarioStr,\n checkoutRequestId,\n billingDetails?.email,\n );\n\n if (confirmResult.data) {\n paymentMethodEvent.complete(\"success\");\n return confirmResult;\n } else {\n paymentMethodEvent.complete(\"fail\");\n return confirmResult;\n }\n } catch (error) {\n onClearPrepared();\n return { errors: { apple_pay: `Apple Pay error: ${error}` } };\n }\n };\n\n return submitPayment;\n};\n\n// =============================================================================\n// Payment Method Definition\n// =============================================================================\n\nconst ApplePayPaymentMethod = definePaymentMethod((paymentKitStates) => {\n const { apiBaseUrl, secureToken, environment } = paymentKitStates;\n\n // Per-instance auto-prepare state — isolated from other ApplePayPaymentMethod instances.\n // Note: preparedStripeState and preparedAirwallexState remain module-level globals (pre-existing\n // architectural constraint shared across the file). Full per-instance isolation for those fields\n // would require threading them through prepareApplePay, runAirwallexFlow, validateOptions, and\n // defSubmitPayment — tracked as tech debt.\n let autoPrepareConfig: AutoPrepareConfig | null = null;\n let onApplePayReadyCallbacks: ((isReady: boolean) => void)[] = [];\n let isApplePayReadyState = false;\n let autoPrepareInProgress = false;\n // Incremented by cleanup() so that in-flight prepares can detect staleness and skip writes.\n let cleanupGeneration = 0;\n // Stores pending retry args when notifyAmountChanged is called while a prepare is in flight.\n let pendingAutoPrepareArgs: { apiBaseUrl: string; secureToken: string; environment: string } | null = null;\n // Resolvers waiting for a queued retry to complete (for correct notifyAmountChanged await).\n let pendingPrepareResolvers: (() => void)[] = [];\n\n function instanceSetApplePayReady(ready: boolean): void {\n isApplePayReadyState = ready;\n for (const cb of onApplePayReadyCallbacks) cb(ready);\n }\n\n function instanceClearPreparedApplePay(): void {\n clearPreparedApplePay();\n instanceSetApplePayReady(false);\n }\n\n async function instanceAutoPrepare(apBase: string, sToken: string, env: string): Promise<void> {\n if (autoPrepareInProgress) {\n // A prepare is already in flight; queue a retry and return a promise that resolves after it.\n pendingAutoPrepareArgs = { apiBaseUrl: apBase, secureToken: sToken, environment: env };\n return new Promise<void>((resolve) => pendingPrepareResolvers.push(resolve));\n }\n autoPrepareInProgress = true;\n // Capture generation so we can detect if cleanup() is called while we await.\n const capturedGeneration = cleanupGeneration;\n instanceSetApplePayReady(false);\n\n try {\n const result = await apiCall<CheckoutSessionConfig>(`${apBase}/api/checkout-sessions/token/${sToken}`, {\n method: \"GET\",\n });\n\n if (cleanupGeneration !== capturedGeneration) return;\n\n if (result.error || !result.data) {\n console.warn(\"[ApplePay] Auto-prepare: failed to fetch session config:\", result.error);\n return;\n }\n\n const processorId = result.data.express_checkout_processor_id;\n if (!processorId) {\n console.log(\"[ApplePay] Auto-prepare: no express checkout processor configured\");\n return;\n }\n\n const processorTypeRaw = result.data.express_checkout_processor_type;\n const processorType =\n processorTypeRaw === \"airwallex\" || processorTypeRaw === \"stripe\" ? processorTypeRaw : undefined;\n\n autoPrepareConfig = { processorId, processorType };\n\n const prepareResult = await prepareApplePay(\n apBase,\n sToken,\n { processorId, processorType, customerInfo: { first_name: \"\", last_name: \"\" } },\n env,\n );\n\n if (cleanupGeneration !== capturedGeneration) return;\n\n instanceSetApplePayReady(prepareResult.success && prepareResult.applePay === true);\n } catch (err) {\n if (cleanupGeneration === capturedGeneration) {\n console.error(\"[ApplePay] Auto-prepare failed:\", err);\n }\n } finally {\n autoPrepareInProgress = false;\n const stale = cleanupGeneration !== capturedGeneration;\n const pending = pendingAutoPrepareArgs;\n const resolvers = pendingPrepareResolvers.splice(0);\n if (!stale && pending) {\n pendingAutoPrepareArgs = null;\n // Run the retry and resolve all callers that were waiting for it.\n instanceAutoPrepare(pending.apiBaseUrl, pending.secureToken, pending.environment).then(() => {\n for (const r of resolvers) r();\n });\n } else {\n pendingAutoPrepareArgs = null;\n for (const r of resolvers) r();\n }\n }\n }\n\n // Start auto-prepare immediately so the button is ready before first user interaction.\n instanceAutoPrepare(apiBaseUrl, secureToken, environment).catch((err) =>\n console.error(\"[ApplePay] Unhandled init error:\", err),\n );\n\n return {\n name: \"apple_pay\",\n externalFuncs: {\n /**\n * @deprecated The SDK now prepares automatically on init. Use `onApplePayReady` to observe\n * readiness and `notifyAmountChanged` to trigger re-prepare after amount changes.\n */\n prepareApplePay: (options: ApplePaySubmitOptions) =>\n prepareApplePay(apiBaseUrl, secureToken, options, environment),\n\n /**\n * Register a callback to be notified when Apple Pay becomes ready (or stops being ready).\n * Fires immediately with the current state, then on every state change.\n * Multiple registrations are all notified — none are silently overwritten.\n *\n * @example\n * paymentKit.apple_pay.onApplePayReady((isReady) => {\n * applePayButton.disabled = !isReady;\n * });\n */\n onApplePayReady: (callback: (isReady: boolean) => void): void => {\n onApplePayReadyCallbacks.push(callback);\n // Fire immediately with current state so caller doesn't miss a completed prepare.\n callback(isApplePayReadyState);\n },\n\n /**\n * Notify the SDK that the payment amount has changed (e.g. coupon applied).\n * The SDK will disable Apple Pay, re-prepare with the new amount, then re-enable.\n * The returned promise resolves when re-prepare is fully complete.\n *\n * @example\n * await paymentKit.apple_pay.notifyAmountChanged();\n */\n notifyAmountChanged: (): Promise<void> => {\n instanceClearPreparedApplePay();\n autoPrepareConfig = null;\n return instanceAutoPrepare(apiBaseUrl, secureToken, environment);\n },\n },\n internalFuncs: {\n submitPayment: defSubmitPayment(paymentKitStates, () => autoPrepareConfig, instanceClearPreparedApplePay),\n cleanup: () => {\n cleanupGeneration++;\n onApplePayReadyCallbacks = [];\n isApplePayReadyState = false;\n autoPrepareConfig = null;\n pendingAutoPrepareArgs = null;\n pendingPrepareResolvers = [];\n autoPrepareInProgress = false;\n clearPreparedApplePay();\n },\n },\n };\n});\n\nexport { ApplePayMockScenario };\n\nexport default ApplePayPaymentMethod;\n"],"mappings":";;;;;;AAwHA,IAAIA,sBAA0D;AAW9D,IAAIC,yBAAwD;AA6B5D,IAAIC,4BAAkD;AACtD,eAAe,qBAAoC;AACjD,KAAI,OAAO,WAAW,YAAa;AACnC,KAAI,OAAO,gBAAiB;AAC5B,KAAI,SAAS,eAAe,qBAAqB,CAG/C,QAAO,6BAA6B,QAAQ,SAAS;AAEvD,6BAA4B,IAAI,SAAe,SAAS,WAAW;EACjE,MAAM,SAAS,SAAS,cAAc,SAAS;AAC/C,SAAO,KAAK;AACZ,SAAO,MAAM;AACb,SAAO,cAAc;AAGrB,SAAO,eAAe,SAAS;AAC/B,SAAO,gBAAgB;AAErB,+BAA4B;AAC5B,YAAS,eAAe,qBAAqB,EAAE,QAAQ;AACvD,0BAAO,IAAI,MAAM,+BAA+B,CAAC;;AAEnD,WAAS,KAAK,YAAY,OAAO;GACjC;AACF,QAAO;;AAOT,eAAe,QACb,KACA,SACA,mBACuC;CACvC,MAAM,UAAU,IAAI,QAAQ,QAAQ,QAAQ;AAC5C,KAAI,kBACF,SAAQ,IAAI,gBAAgB,kBAAkB;CAGhD,MAAM,WAAW,MAAM,MAAM,KAAK;EAAE,GAAG;EAAS;EAAS,CAAC;AAC1D,KAAI,CAAC,SAAS,IAAI;EAChB,IAAI,eAAe,mBAAmB,SAAS,OAAO;AACtD,MAAI;AAEF,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/C;AACR,2BAAwB;GACxB,MAAM,QAAQ,sBAAsB;GACpC,MAAM,UAAU;GAChB,MAAM,YAAY,wBAAwB,OAAO,EAAE;AACnD,OAAI,CAAC,SAAS,SAAS;AACrB,6BAAyB;AAEzB,wBAAoB,QAAQ,YAAY,QAAQ,aAAa,QAAQ,YAAY,CAAC,WAAW;AAC3F,UAAK,MAAM,KAAK,UAAW,IAAG;MAC9B;UACG;AACL,6BAAyB;AACzB,SAAK,MAAM,KAAK,UAAW,IAAG;;;;AAMpC,qBAAoB,YAAY,aAAa,YAAY,CAAC,OAAO,QAC/D,QAAQ,MAAM,oCAAoC,IAAI,CACvD;AAED,QAAO;EACL,MAAM;EACN,eAAe;GAKb,kBAAkB,YAChB,gBAAgB,YAAY,aAAa,SAAS,YAAY;GAYhE,kBAAkB,aAA+C;AAC/D,6BAAyB,KAAK,SAAS;AAEvC,aAAS,qBAAqB;;GAWhC,2BAA0C;AACxC,mCAA+B;AAC/B,wBAAoB;AACpB,WAAO,oBAAoB,YAAY,aAAa,YAAY;;GAEnE;EACD,eAAe;GACb,eAAe,iBAAiB,wBAAwB,mBAAmB,8BAA8B;GACzG,eAAe;AACb;AACA,+BAA2B,EAAE;AAC7B,2BAAuB;AACvB,wBAAoB;AACpB,6BAAyB;AACzB,8BAA0B,EAAE;AAC5B,4BAAwB;AACxB,2BAAuB;;GAE1B;EACF;EACD;AAIF,wBAAe"}
1
+ {"version":3,"file":"apple-pay.mjs","names":["preparedStripeState: PreparedStripeApplePayState | null","preparedAirwallexState: PreparedAirwallexState | null","applePayScriptLoadPromise: Promise<void> | null","airwallexMockScenario: AirwallexApplePayMockScenario","config: AirwallexApplePayConfig","submitPayment: TInternalFuncs[\"submitPayment\"]","paymentResult","confirmResult","paymentMethodId","billingDetails","autoPrepareConfig: AutoPrepareConfig | null","onApplePayReadyCallbacks: ((isReady: boolean) => void)[]","pendingAutoPrepareArgs: { apiBaseUrl: string; secureToken: string; environment: string } | null","pendingPrepareResolvers: (() => void)[]"],"sources":["../../src/payment-methods/apple-pay.ts"],"sourcesContent":["import type { PaymentKitErrors, PaymentKitStates, TInternalFuncs } from \"../types\";\nimport { collectFraudMetadata, definePaymentMethod, getOrCreateCheckoutRequestId } from \"../utils\";\nimport {\n AirwallexApplePayAdapter,\n type AirwallexApplePayConfig,\n AirwallexApplePayMockScenario,\n type ApplePayEncryptedToken,\n} from \"./airwallex-apple-pay-adapter\";\nimport { handleNextAction } from \"./next-action-handlers\";\nimport { ApplePayMockScenario, StripeApplePayAdapter } from \"./stripe-apple-pay-adapter\";\n\n// Apple Pay-specific types\nexport type ApplePayCustomerInfo = {\n first_name: string;\n last_name: string;\n email?: string;\n};\n\nexport type ApplePayStartRequest = {\n processor_id: string;\n // Airwallex-only fields. Stripe /apple-pay/start is a pure read and\n // ignores these — customer_info/fraud_metadata are sent to /apple-pay/confirm\n // instead, where the customer + checkout attempt + PaymentIntent are created.\n customer_info?: ApplePayCustomerInfo;\n fraud_metadata?: {\n ipAddress?: string;\n browserInfo?: { [key: string]: unknown };\n processorFraudInfo?: { [key: string]: unknown };\n };\n mock_scenario?: string;\n // Airwallex-specific fields (sent on /start for merchant validation)\n validation_url?: string;\n initiative_context?: string;\n};\n\nexport type ApplePayStartResponse = {\n amount: number;\n currency: string;\n country: string;\n\n // Stripe-specific (when calling /apple-pay/start)\n stripe_pk?: string;\n\n // Airwallex-specific (when calling /airwallex/apple-pay/start). Stripe's\n // /start does not create a checkout attempt — it's deferred to /confirm.\n checkout_attempt_id?: string;\n merchant_session?: { [key: string]: unknown }; // Apple merchant session for completeMerchantValidation()\n};\n\n// Airwallex 3DS next action type (matches backend snake_case response)\nexport type Airwallex3dsNextAction = {\n type: \"airwallex_3ds\";\n url: string;\n};\n\nexport type ApplePayConfirmRequest = {\n // Stripe-only: moved from /start (where they used to drive customer/PI\n // creation). At confirm time, the Stripe path creates the customer, checkout\n // attempt, and PaymentIntent in a single call.\n processor_id?: string;\n customer_info?: ApplePayCustomerInfo;\n fraud_metadata?: {\n ipAddress?: string;\n browserInfo?: { [key: string]: unknown };\n processorFraudInfo?: { [key: string]: unknown };\n };\n // Stripe: Send PaymentMethod ID\n payment_method_id?: string;\n // Airwallex: Send encrypted Apple Pay token\n apple_pay_token?: ApplePayEncryptedToken | { [key: string]: unknown };\n // Email from payment sheet (Stripe Apple Pay) — used to fill missing customer email\n payer_email?: string;\n // Name from payment sheet — used to fill missing customer name\n payer_first_name?: string;\n payer_last_name?: string;\n mock_scenario?: string;\n};\n\nexport type ApplePayConfirmResponse = {\n charge_status: \"success\" | \"fail\" | \"pending\";\n transaction_id?: string;\n error_code?: string;\n error_message_for_customer?: string;\n error_message_for_debug?: string;\n checkout_attempt_id: string;\n checkout_session_id?: string;\n next_action?: Airwallex3dsNextAction; // Present when charge_status=\"pending\" for 3DS\n payment_intent_id?: string;\n customer_id?: string;\n payment_method_id?: string;\n processor_used?: string;\n subscription_id?: string;\n invoice_id?: string;\n invoice_number?: number;\n card_brand?: string;\n card_last4?: string;\n card_exp_month?: number;\n card_exp_year?: number;\n};\n\nexport type ApplePaySubmitOptions = {\n /** Processor external ID — optional when using auto-prepare (SDK fetches from checkout session) */\n processorId?: string;\n processorType?: \"stripe\" | \"airwallex\";\n customerInfo: ApplePayCustomerInfo;\n mockScenario?: ApplePayMockScenario;\n amount?: number; // Amount in atomic units (cents) for Apple Pay sheet display\n currency?: string; // Currency code (e.g., \"usd\")\n /** Country code — optional when using auto-prepare (fetched from backend) */\n country?: string;\n merchantName?: string; // Merchant display name on Apple Pay sheet\n};\n\ntype ApplePayResult =\n | { data: { [key: string]: unknown }; errors?: undefined }\n | { data?: undefined; errors: PaymentKitErrors };\n\n// =============================================================================\n// Prepared Payment State (for Stripe pre-fetching before click)\n// =============================================================================\n\ntype PreparedStripeApplePayState = {\n processor: \"stripe\";\n adapter: StripeApplePayAdapter;\n startData: ApplePayStartResponse;\n mockScenarioStr?: string;\n checkoutRequestId: string;\n};\n\n// Global state to store prepared Apple Pay data (Stripe only - Airwallex uses native session)\nlet preparedStripeState: PreparedStripeApplePayState | null = null;\n\n// Prepared Airwallex state — persists options from prepare call for use at submit time\n// The amount field is fetched from the session via /session-info endpoint to fix\n// the $0.00 bug where options.amount was undefined and defaulted to 0.\ntype PreparedAirwallexState = {\n country: string;\n currency?: string;\n amount?: number;\n merchantName?: string;\n};\nlet preparedAirwallexState: PreparedAirwallexState | null = null;\n\n// Response type for Airwallex Apple Pay session-info endpoint\ntype AirwallexSessionInfoResponse = {\n amount: number;\n currency: string;\n country: string;\n};\n\n// =============================================================================\n// Auto-Prepare State\n// =============================================================================\n\ntype AutoPrepareConfig = {\n processorId: string;\n processorType: \"airwallex\" | \"stripe\" | undefined;\n};\n\ntype CheckoutSessionConfig = {\n express_checkout_processor_id?: string | null;\n express_checkout_processor_type?: string | null;\n};\n\n// =============================================================================\n// Apple Pay SDK Loader\n// =============================================================================\n\n// Loads Apple's JS SDK, which makes window.ApplePaySession available in non-Safari\n// browsers (Chrome, Firefox, etc.) and enables the \"Scan Code with iPhone\" QR flow.\nlet applePayScriptLoadPromise: Promise<void> | null = null;\nasync function loadApplePayScript(): Promise<void> {\n if (typeof window === \"undefined\") return;\n if (window.ApplePaySession) return;\n if (document.getElementById(\"__pk_apple_pay_sdk\")) {\n // Tag exists — if we have a cached promise, wait for it; otherwise the tag\n // already resolved (e.g. after a module reload) so return immediately.\n return applePayScriptLoadPromise ?? Promise.resolve();\n }\n applePayScriptLoadPromise = new Promise<void>((resolve, reject) => {\n const script = document.createElement(\"script\");\n script.id = \"__pk_apple_pay_sdk\";\n script.src = \"https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js\";\n script.crossOrigin = \"anonymous\";\n // NOTE: Apple doesn't publish stable SRI hashes for the 1.latest pointer,\n // so integrity checking is omitted. CSP must allow script-src https://applepay.cdn-apple.com.\n script.onload = () => resolve();\n script.onerror = () => {\n // Clear cached state so the next prepareApplePay call can retry.\n applePayScriptLoadPromise = null;\n document.getElementById(\"__pk_apple_pay_sdk\")?.remove();\n reject(new Error(\"Failed to load Apple Pay SDK\"));\n };\n document.head.appendChild(script);\n });\n return applePayScriptLoadPromise;\n}\n\n// =============================================================================\n// Helper Functions\n// =============================================================================\n\nasync function apiCall<T>(\n url: string,\n options: RequestInit,\n checkoutRequestId?: string,\n): Promise<{ data?: T; error?: string }> {\n const headers = new Headers(options.headers);\n if (checkoutRequestId) {\n headers.set(\"x-request-id\", checkoutRequestId);\n }\n\n const response = await fetch(url, { ...options, headers });\n if (!response.ok) {\n let errorMessage = `Request failed (${response.status})`;\n try {\n const errorData = await response.json();\n errorMessage = errorData.detail || errorMessage;\n } catch {\n errorMessage = response.statusText || errorMessage;\n }\n return { error: errorMessage };\n }\n return { data: await response.json() };\n}\n\nfunction validateOptions(options: ApplePaySubmitOptions): PaymentKitErrors | null {\n if (!options?.processorId) {\n return { processor_id: \"Processor ID is required\" };\n }\n // For Airwallex, country is required (either directly or from prepared state)\n if (options.processorType === \"airwallex\" && !options.country && !preparedAirwallexState?.country) {\n return { country: \"Country is required for Airwallex Apple Pay\" };\n }\n return null;\n}\n\nfunction getMockScenarioStr(mockScenario?: ApplePayMockScenario): string | undefined {\n return mockScenario && mockScenario !== ApplePayMockScenario.None ? mockScenario : undefined;\n}\n\n// =============================================================================\n// Stripe Apple Pay Flow\n// =============================================================================\n\nasync function callStripeStartEndpoint(\n apiBaseUrl: string,\n secureToken: string,\n options: ApplePaySubmitOptions,\n checkoutRequestId?: string,\n): Promise<{ data?: ApplePayStartResponse; error?: string }> {\n // /apple-pay/start is now a pure read: it returns stripe_pk + sheet data\n // (amount/currency/country). Customer/CheckoutAttempt/PaymentIntent are\n // created in /apple-pay/confirm once the user authorizes the sheet.\n return apiCall<ApplePayStartResponse>(\n `${apiBaseUrl}/api/checkout/${secureToken}/apple-pay/start`,\n {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n processor_id: options.processorId,\n } as ApplePayStartRequest),\n },\n checkoutRequestId,\n );\n}\n\nfunction initializeStripeAdapter(\n stripePk: string,\n mockScenario?: ApplePayMockScenario,\n): { adapter?: StripeApplePayAdapter; error?: string } {\n const adapter = new StripeApplePayAdapter(mockScenario);\n\n if (!adapter.initialize(stripePk)) {\n return { error: 'Stripe.js not loaded. Add <script src=\"https://js.stripe.com/v3/\"></script> to your page.' };\n }\n\n return { adapter };\n}\n\nasync function callStripeConfirmEndpoint(\n apiBaseUrl: string,\n secureToken: string,\n options: ApplePaySubmitOptions,\n paymentMethodId: string,\n mockScenarioStr?: string,\n checkoutRequestId?: string,\n payerEmail?: string,\n): Promise<ApplePayResult> {\n // /apple-pay/confirm now carries the fields that used to live on /start —\n // processor_id, customer_info, fraud_metadata — because the customer,\n // checkout attempt, and Stripe PaymentIntent are all created here.\n const result = await apiCall<ApplePayConfirmResponse>(\n `${apiBaseUrl}/api/checkout/${secureToken}/apple-pay/confirm`,\n {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n processor_id: options.processorId,\n customer_info: options.customerInfo,\n fraud_metadata: collectFraudMetadata(),\n payment_method_id: paymentMethodId,\n payer_email: payerEmail,\n mock_scenario: mockScenarioStr,\n } as ApplePayConfirmRequest),\n },\n checkoutRequestId,\n );\n\n if (result.error || !result.data) {\n return { errors: { apple_pay: result.error || \"Failed to confirm payment\" } };\n }\n\n const confirmData = result.data;\n\n if (confirmData.charge_status === \"success\") {\n return {\n data: {\n id: confirmData.transaction_id,\n checkoutAttemptId: confirmData.checkout_attempt_id,\n checkoutSessionId: confirmData.checkout_session_id ?? secureToken,\n state: \"checkout_succeeded\",\n paymentIntentId: confirmData.payment_intent_id,\n customerId: confirmData.customer_id,\n paymentMethodId: confirmData.payment_method_id,\n processorUsed: confirmData.processor_used,\n subscriptionId: confirmData.subscription_id,\n invoiceId: confirmData.invoice_id,\n invoiceNumber: confirmData.invoice_number,\n cardBrand: confirmData.card_brand,\n cardLast4: confirmData.card_last4,\n cardExpMonth: confirmData.card_exp_month,\n cardExpYear: confirmData.card_exp_year,\n errorCode: confirmData.error_code,\n errorMessageForCustomer: confirmData.error_message_for_customer,\n errorMessageForDebug: confirmData.error_message_for_debug,\n nextAction: confirmData.next_action,\n },\n };\n }\n\n return {\n errors: {\n apple_pay: confirmData.error_message_for_customer || confirmData.error_message_for_debug || \"Payment failed\",\n },\n };\n}\n\n// =============================================================================\n// Prepare Function (call BEFORE the click handler)\n// =============================================================================\n\n/**\n * Pre-fetch Apple Pay data and prepare the PaymentRequest.\n * Call this when the checkout page loads, NOT in the click handler.\n *\n * For Stripe: pre-fetches data and prepares PaymentRequest for immediate show.\n * For Airwallex: returns success with processor=\"airwallex\" so submit uses native ApplePaySession.\n *\n * @deprecated The SDK now calls this automatically on init. Use `onApplePayReady` to observe\n * readiness and `notifyAmountChanged` to trigger re-prepare after amount changes.\n */\nexport async function prepareApplePay(\n apiBaseUrl: string,\n secureToken: string,\n options: ApplePaySubmitOptions,\n environment: string,\n): Promise<{ success: boolean; error?: string; applePay?: boolean }> {\n console.log(\"[ApplePay] prepareApplePay called\");\n\n // Clear any previous state\n preparedStripeState = null;\n\n const mockScenarioStr = getMockScenarioStr(options.mockScenario);\n const checkoutRequestId = getOrCreateCheckoutRequestId(environment);\n console.log(`[ApplePay] Using checkout_request_id: ${checkoutRequestId}`);\n\n // Airwallex: Load Apple Pay SDK (enables QR code flow in non-Safari browsers),\n // then fetch session info to get the correct amount from line items.\n // This fixes the $0.00 bug where options.amount was undefined and defaulted to 0.\n if (options.processorType === \"airwallex\") {\n console.log(\"[ApplePay] Airwallex processor - loading Apple Pay SDK, fetching session info for amount\");\n\n // In mock mode, skip SDK loading and availability check (jsdom has no ApplePaySession)\n if (!mockScenarioStr) {\n try {\n await loadApplePayScript();\n } catch (err) {\n console.error(\"[ApplePay] Failed to load Apple Pay SDK:\", err);\n return { success: false, error: \"Failed to load Apple Pay\" };\n }\n\n let canMake = false;\n try {\n canMake = !!window.ApplePaySession?.canMakePayments();\n } catch {\n canMake = false;\n }\n if (!canMake) {\n console.log(\"[ApplePay] Apple Pay not available on this device/browser\");\n return { success: false, error: \"Apple Pay not available on this device\" };\n }\n }\n\n // Fetch session info (amount, currency, country) from backend\n const sessionInfoResult = await callAirwallexSessionInfoEndpoint(apiBaseUrl, secureToken, checkoutRequestId);\n\n if (sessionInfoResult.error || !sessionInfoResult.data) {\n console.error(\"[ApplePay] Failed to fetch session info:\", sessionInfoResult.error);\n return { success: false, error: sessionInfoResult.error || \"Failed to fetch Apple Pay session info\" };\n }\n\n console.log(\"[ApplePay] Got session info:\", sessionInfoResult.data);\n const resolvedAmount = sessionInfoResult.data.amount;\n const resolvedCurrency = sessionInfoResult.data.currency;\n const resolvedCountry = sessionInfoResult.data.country || options.country;\n\n preparedAirwallexState = {\n country: resolvedCountry,\n currency: resolvedCurrency,\n amount: resolvedAmount,\n merchantName: options.merchantName,\n };\n console.log(\"[ApplePay] Airwallex prepared state:\", preparedAirwallexState);\n return { success: true, applePay: true };\n }\n\n // Call Stripe start endpoint to fetch stripe_pk + sheet display data\n const startResult = await callStripeStartEndpoint(\n apiBaseUrl,\n secureToken,\n options,\n checkoutRequestId,\n );\n if (startResult.error || !startResult.data) {\n return { success: false, error: startResult.error || \"Failed to start Apple Pay\" };\n }\n\n const startData = startResult.data;\n\n // Initialize Stripe adapter\n if (!startData.stripe_pk) {\n return { success: false, error: \"Stripe publishable key not provided\" };\n }\n\n const { adapter, error: adapterError } = initializeStripeAdapter(startData.stripe_pk, options.mockScenario);\n if (!adapter) {\n return { success: false, error: adapterError };\n }\n\n // Create PaymentRequest and call canMakePayment() (required before show())\n const prepareResult = await adapter.preparePaymentRequest({\n country: startData.country,\n currency: startData.currency.toLowerCase(),\n total: {\n label: \"Total\",\n amount: startData.amount,\n },\n });\n\n if (!prepareResult.success) {\n return {\n success: false,\n error: prepareResult.error || \"Failed to prepare payment request\",\n applePay: prepareResult.applePay,\n };\n }\n\n if (!prepareResult.applePay) {\n return {\n success: false,\n error: \"Apple Pay is not available on this device or Stripe account\",\n applePay: false,\n };\n }\n\n // Store the prepared state\n preparedStripeState = {\n processor: \"stripe\",\n adapter,\n startData,\n mockScenarioStr,\n checkoutRequestId,\n };\n\n console.log(\"[ApplePay] prepareApplePay success (Stripe), ready for click\");\n return { success: true, applePay: true };\n}\n\n/**\n * Check if Apple Pay has been prepared and is ready.\n */\nexport function isApplePayPrepared(): boolean {\n return (preparedStripeState?.adapter.isPrepared() ?? false) || preparedAirwallexState !== null;\n}\n\n/**\n * Clear prepared state (call on unmount or when checkout changes).\n */\nexport function clearPreparedApplePay(): void {\n if (preparedStripeState) {\n preparedStripeState.adapter.clearPrepared();\n }\n preparedStripeState = null;\n preparedAirwallexState = null;\n}\n\n// =============================================================================\n// Airwallex Apple Pay Flow\n// =============================================================================\n\n/**\n * Fetch session info (amount, currency, country) from the backend.\n * Called during prepareApplePay to get the correct amount BEFORE showing the payment sheet.\n * This fixes the $0.00 bug where options.amount was undefined and defaulted to 0.\n */\nasync function callAirwallexSessionInfoEndpoint(\n apiBaseUrl: string,\n secureToken: string,\n checkoutRequestId?: string,\n): Promise<{ data?: AirwallexSessionInfoResponse; error?: string }> {\n return apiCall<AirwallexSessionInfoResponse>(\n `${apiBaseUrl}/api/checkout/${secureToken}/airwallex/apple-pay/session-info`,\n {\n method: \"GET\",\n headers: { \"Content-Type\": \"application/json\" },\n },\n checkoutRequestId,\n );\n}\n\nasync function callAirwallexStartEndpoint(\n apiBaseUrl: string,\n secureToken: string,\n options: ApplePaySubmitOptions,\n validationUrl: string,\n initiativeContext: string,\n mockScenarioStr?: string,\n checkoutRequestId?: string,\n): Promise<{ data?: ApplePayStartResponse; error?: string }> {\n return apiCall<ApplePayStartResponse>(\n `${apiBaseUrl}/api/checkout/${secureToken}/airwallex/apple-pay/start`,\n {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n processor_id: options.processorId,\n customer_info: options.customerInfo,\n fraud_metadata: collectFraudMetadata(),\n validation_url: validationUrl,\n initiative_context: initiativeContext,\n mock_scenario: mockScenarioStr,\n } as ApplePayStartRequest),\n },\n checkoutRequestId,\n );\n}\n\nasync function callAirwallexConfirmEndpoint(\n apiBaseUrl: string,\n secureToken: string,\n applePayToken: ApplePayEncryptedToken,\n mockScenarioStr?: string,\n checkoutRequestId?: string,\n payerEmail?: string,\n payerFirstName?: string,\n payerLastName?: string,\n): Promise<ApplePayConfirmResponse> {\n const result = await apiCall<ApplePayConfirmResponse>(\n `${apiBaseUrl}/api/checkout/${secureToken}/airwallex/apple-pay/confirm`,\n {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n apple_pay_token: applePayToken,\n payer_email: payerEmail,\n payer_first_name: payerFirstName,\n payer_last_name: payerLastName,\n mock_scenario: mockScenarioStr,\n } as ApplePayConfirmRequest),\n },\n checkoutRequestId,\n );\n\n if (result.error || !result.data) {\n return {\n charge_status: \"fail\",\n error_message_for_debug: result.error || \"Failed to confirm payment\",\n checkout_attempt_id: \"\",\n };\n }\n\n return result.data;\n}\n\nasync function callAirwallexVerifyEndpoint(\n apiBaseUrl: string,\n secureToken: string,\n checkoutRequestId?: string,\n): Promise<ApplePayConfirmResponse> {\n const result = await apiCall<ApplePayConfirmResponse>(\n `${apiBaseUrl}/api/checkout/${secureToken}/airwallex/apple-pay/verify`,\n {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n },\n checkoutRequestId,\n );\n\n if (result.error || !result.data) {\n return {\n charge_status: \"fail\",\n error_message_for_debug: result.error || \"Failed to verify payment\",\n checkout_attempt_id: \"\",\n };\n }\n\n return result.data;\n}\n\nfunction toApplePayResult(response: ApplePayConfirmResponse, secureToken: string): ApplePayResult {\n if (response.charge_status === \"success\") {\n return {\n data: {\n id: response.transaction_id,\n checkoutAttemptId: response.checkout_attempt_id,\n checkoutSessionId: response.checkout_session_id ?? secureToken,\n state: \"checkout_succeeded\",\n paymentIntentId: response.payment_intent_id,\n customerId: response.customer_id,\n paymentMethodId: response.payment_method_id,\n processorUsed: response.processor_used,\n subscriptionId: response.subscription_id,\n invoiceId: response.invoice_id,\n invoiceNumber: response.invoice_number,\n cardBrand: response.card_brand,\n cardLast4: response.card_last4,\n cardExpMonth: response.card_exp_month,\n cardExpYear: response.card_exp_year,\n errorCode: response.error_code,\n errorMessageForCustomer: response.error_message_for_customer,\n errorMessageForDebug: response.error_message_for_debug,\n nextAction: response.next_action,\n },\n };\n }\n return {\n errors: {\n apple_pay: response.error_message_for_customer || response.error_message_for_debug || \"Payment failed\",\n },\n };\n}\n\nconst MAX_USER_ACTIONS = 5;\n\n/**\n * Run the Airwallex Apple Pay flow with 3DS loop support.\n *\n * Flow:\n * 1. Show native ApplePaySession, call /start for merchant validation\n * 2. On payment authorized, call /confirm with token\n * 3. If 3DS required, handle it and call /verify\n * 4. Loop if more 3DS needed\n */\nasync function runAirwallexFlow(\n apiBaseUrl: string,\n secureToken: string,\n options: ApplePaySubmitOptions,\n mockScenarioStr?: string,\n checkoutRequestId?: string,\n): Promise<ApplePayResult> {\n // Convert mock scenario\n let airwallexMockScenario: AirwallexApplePayMockScenario = AirwallexApplePayMockScenario.None;\n if (options.mockScenario === ApplePayMockScenario.Success) {\n airwallexMockScenario = AirwallexApplePayMockScenario.Success;\n } else if (options.mockScenario === ApplePayMockScenario.Cancelled) {\n airwallexMockScenario = AirwallexApplePayMockScenario.Cancelled;\n }\n\n // Defense-in-depth: validateOptions should catch this earlier, but guard against\n // future callers that bypass validation to avoid an unhandled TypeError on `.toUpperCase()`\n if (!options.country) {\n return { errors: { apple_pay: \"Country is required for Airwallex Apple Pay\" } };\n }\n\n // Auto-fetch amount from session if not provided (e.g. merchant didn't call prepareApplePay first)\n if (!options.amount) {\n const sessionInfoResult = await callAirwallexSessionInfoEndpoint(apiBaseUrl, secureToken, checkoutRequestId);\n if (sessionInfoResult.data) {\n options.amount = sessionInfoResult.data.amount;\n options.currency = options.currency || sessionInfoResult.data.currency;\n options.country = options.country || sessionInfoResult.data.country;\n }\n }\n\n // Initialize adapter\n const adapter = new AirwallexApplePayAdapter(airwallexMockScenario);\n\n const config: AirwallexApplePayConfig = {\n amount: options.amount || 0,\n currency: (options.currency || \"USD\").toUpperCase(),\n country: options.country.toUpperCase(),\n merchantName: options.merchantName || \"Total\",\n };\n\n if (!adapter.initialize(config)) {\n return { errors: { apple_pay: \"Apple Pay not available on this device\" } };\n }\n\n const canPay = await adapter.canMakePayment();\n if (!canPay) {\n return { errors: { apple_pay: \"Apple Pay not available on this device\" } };\n }\n\n // Get current domain for initiative_context\n const initiativeContext = typeof window !== \"undefined\" ? window.location.hostname : \"\";\n\n // In mock mode, call /start first to create checkout attempt (mock adapter skips merchant validation)\n if (airwallexMockScenario !== AirwallexApplePayMockScenario.None) {\n const startResult = await callAirwallexStartEndpoint(\n apiBaseUrl,\n secureToken,\n options,\n \"https://mock-apple-pay-gateway.example.com/paymentservices/startSession\",\n initiativeContext,\n mockScenarioStr,\n checkoutRequestId,\n );\n if (startResult.error || !startResult.data) {\n return { errors: { apple_pay: startResult.error || \"Failed to start mock checkout\" } };\n }\n }\n\n // Show Apple Pay sheet with merchant validation callback\n const paymentResult = await adapter.showPaymentSheet(async (validationUrl: string) => {\n // Call /start endpoint for merchant validation\n const startResult = await callAirwallexStartEndpoint(\n apiBaseUrl,\n secureToken,\n options,\n validationUrl,\n initiativeContext,\n mockScenarioStr,\n checkoutRequestId,\n );\n\n if (startResult.error || !startResult.data) {\n return { error: startResult.error || \"Merchant validation failed\" };\n }\n\n if (!startResult.data.merchant_session) {\n return { error: \"No merchant session returned from server\" };\n }\n\n return { merchantSession: startResult.data.merchant_session };\n });\n\n if (!paymentResult.success) {\n if (\"cancelled\" in paymentResult && paymentResult.cancelled) {\n return { errors: { apple_pay: \"Apple Pay cancelled by user\" } };\n }\n return { errors: { apple_pay: paymentResult.error || \"Apple Pay failed\" } };\n }\n\n const { token, complete, payerEmail, payerFirstName, payerLastName } = paymentResult;\n\n // Call /confirm with the token\n let response = await callAirwallexConfirmEndpoint(\n apiBaseUrl,\n secureToken,\n token,\n mockScenarioStr,\n checkoutRequestId,\n payerEmail,\n payerFirstName,\n payerLastName,\n );\n\n // Handle 3DS loop\n let userActionCount = 0;\n while (response.charge_status === \"pending\" && response.next_action && userActionCount < MAX_USER_ACTIONS) {\n userActionCount++;\n\n // Handle 3DS challenge — Airwallex3dsNextAction is structurally identical to SDK's Airwallex3dsAction\n const nextAction = response.next_action as Airwallex3dsNextAction;\n const actionResult = await handleNextAction({ type: nextAction.type, url: nextAction.url });\n\n // Call verify endpoint\n const verifyResponse = await callAirwallexVerifyEndpoint(apiBaseUrl, secureToken, checkoutRequestId);\n\n // Check if another 3DS action is required\n if (verifyResponse.charge_status === \"pending\" && verifyResponse.next_action) {\n if (!actionResult.success) {\n console.log(\"[ApplePay:Airwallex] 3DS failed but retry available, continuing loop...\");\n }\n response = verifyResponse;\n continue;\n }\n\n // No more actions - check final result\n if (!actionResult.success) {\n complete(\"fail\");\n return {\n errors: {\n apple_pay:\n verifyResponse.error_message_for_customer ||\n verifyResponse.error_message_for_debug ||\n actionResult.error ||\n \"3DS authentication failed\",\n },\n };\n }\n\n // 3DS succeeded\n complete(verifyResponse.charge_status === \"success\" ? \"success\" : \"fail\");\n return toApplePayResult(verifyResponse, secureToken);\n }\n\n // Check for max attempts exceeded\n if (userActionCount >= MAX_USER_ACTIONS) {\n complete(\"fail\");\n return { errors: { apple_pay: \"Too many authentication attempts. Please try again.\" } };\n }\n\n // No 3DS required - complete with result\n complete(response.charge_status === \"success\" ? \"success\" : \"fail\");\n return toApplePayResult(response, secureToken);\n}\n\n// =============================================================================\n// Main Submit Function\n// =============================================================================\n\nconst defSubmitPayment = (\n states: PaymentKitStates,\n getAutoPrepareConfig: () => AutoPrepareConfig | null,\n onClearPrepared: () => void,\n) => {\n const submitPayment: TInternalFuncs[\"submitPayment\"] = async (_fields, options) => {\n const { apiBaseUrl, secureToken, environment } = states;\n const applePayOptions = options as ApplePaySubmitOptions;\n\n // Fill in processorId/processorType from auto-prepare config if merchant didn't provide them\n const autoPrepareConfig = getAutoPrepareConfig();\n if (!applePayOptions.processorId && autoPrepareConfig?.processorId) {\n applePayOptions.processorId = autoPrepareConfig.processorId;\n }\n if (!applePayOptions.processorType && autoPrepareConfig?.processorType) {\n applePayOptions.processorType = autoPrepareConfig.processorType;\n }\n\n // Validate options\n const validationError = validateOptions(applePayOptions);\n if (validationError) {\n return { errors: validationError };\n }\n\n try {\n const mockScenarioStr = getMockScenarioStr(applePayOptions.mockScenario);\n const checkoutRequestId = getOrCreateCheckoutRequestId(environment);\n console.log(`[ApplePay] Using checkout_request_id: ${checkoutRequestId}`);\n\n // Check if we have prepared Stripe state\n if (preparedStripeState?.adapter.isPrepared()) {\n console.log(\"[ApplePay] Using prepared Stripe state for immediate sheet display\");\n\n // Show Apple Pay sheet IMMEDIATELY using the prepared PaymentRequest\n const paymentResultPromise = preparedStripeState.adapter.showPreparedPaymentSheet();\n const paymentResult = await paymentResultPromise;\n\n if (!paymentResult.success) {\n clearPreparedApplePay();\n\n if (\"cancelled\" in paymentResult && paymentResult.cancelled) {\n return { errors: { apple_pay: \"Apple Pay cancelled by user\" } };\n }\n const errorMessage = \"error\" in paymentResult ? paymentResult.error : \"Unknown error\";\n return { errors: { apple_pay: errorMessage } };\n }\n\n const { paymentMethodId, paymentMethodEvent, billingDetails } = paymentResult;\n\n // Confirm with backend using the PaymentMethod ID\n const confirmResult = await callStripeConfirmEndpoint(\n apiBaseUrl,\n secureToken,\n applePayOptions,\n paymentMethodId,\n mockScenarioStr,\n preparedStripeState.checkoutRequestId,\n billingDetails?.email,\n );\n\n // Complete Apple Pay UI based on result\n if (confirmResult.data) {\n paymentMethodEvent.complete(\"success\");\n clearPreparedApplePay();\n return confirmResult;\n } else {\n paymentMethodEvent.complete(\"fail\");\n clearPreparedApplePay();\n return confirmResult;\n }\n }\n\n // Check if this is an Airwallex processor - route directly to Airwallex flow\n if (applePayOptions.processorType === \"airwallex\") {\n console.log(\"[ApplePay] Running Airwallex flow (processorType=airwallex)\");\n // Merge prepare-time state into submit options so country/currency/amount/merchantName\n // are available even if the merchant only provided them at prepare time\n if (preparedAirwallexState) {\n if (applePayOptions.country == null) applePayOptions.country = preparedAirwallexState.country;\n if (applePayOptions.currency == null) applePayOptions.currency = preparedAirwallexState.currency;\n if (applePayOptions.amount == null) applePayOptions.amount = preparedAirwallexState.amount;\n if (applePayOptions.merchantName == null) applePayOptions.merchantName = preparedAirwallexState.merchantName;\n }\n try {\n return await runAirwallexFlow(apiBaseUrl, secureToken, applePayOptions, mockScenarioStr, checkoutRequestId);\n } finally {\n preparedAirwallexState = null;\n }\n }\n\n // No prepared state for Stripe - call start endpoint\n const startResult = await callStripeStartEndpoint(\n apiBaseUrl,\n secureToken,\n applePayOptions,\n checkoutRequestId,\n );\n\n if (startResult.error || !startResult.data) {\n return { errors: { apple_pay: startResult.error || \"Failed to start Apple Pay\" } };\n }\n\n const startData = startResult.data;\n\n // Stripe flow without prepared state - this may fail due to user gesture requirements\n console.warn(\"[ApplePay] Stripe flow without prepared state - may fail due to user gesture requirements\");\n\n if (!startData.stripe_pk) {\n return { errors: { apple_pay: \"Stripe publishable key not provided\" } };\n }\n\n const { adapter, error: adapterError } = initializeStripeAdapter(\n startData.stripe_pk,\n applePayOptions.mockScenario,\n );\n if (!adapter) {\n return { errors: { apple_pay: adapterError || \"Failed to initialize Stripe adapter\" } };\n }\n\n // This will likely fail due to user gesture requirements\n const prepareResult = await adapter.preparePaymentRequest({\n country: startData.country,\n currency: startData.currency.toLowerCase(),\n total: { label: \"Total\", amount: startData.amount },\n });\n\n if (!prepareResult.success || !prepareResult.applePay) {\n return { errors: { apple_pay: prepareResult.error || \"Apple Pay not available\" } };\n }\n\n const paymentResult = await adapter.showPreparedPaymentSheet();\n\n if (!paymentResult.success) {\n if (\"cancelled\" in paymentResult && paymentResult.cancelled) {\n return { errors: { apple_pay: \"Apple Pay cancelled by user\" } };\n }\n const errorMessage = \"error\" in paymentResult ? paymentResult.error : \"Unknown error\";\n return { errors: { apple_pay: errorMessage } };\n }\n\n const { paymentMethodId, paymentMethodEvent, billingDetails } = paymentResult;\n\n const confirmResult = await callStripeConfirmEndpoint(\n apiBaseUrl,\n secureToken,\n applePayOptions,\n paymentMethodId,\n mockScenarioStr,\n checkoutRequestId,\n billingDetails?.email,\n );\n\n if (confirmResult.data) {\n paymentMethodEvent.complete(\"success\");\n return confirmResult;\n } else {\n paymentMethodEvent.complete(\"fail\");\n return confirmResult;\n }\n } catch (error) {\n onClearPrepared();\n return { errors: { apple_pay: `Apple Pay error: ${error}` } };\n }\n };\n\n return submitPayment;\n};\n\n// =============================================================================\n// Payment Method Definition\n// =============================================================================\n\nconst ApplePayPaymentMethod = definePaymentMethod((paymentKitStates) => {\n const { apiBaseUrl, secureToken, environment } = paymentKitStates;\n\n // Per-instance auto-prepare state — isolated from other ApplePayPaymentMethod instances.\n // Note: preparedStripeState and preparedAirwallexState remain module-level globals (pre-existing\n // architectural constraint shared across the file). Full per-instance isolation for those fields\n // would require threading them through prepareApplePay, runAirwallexFlow, validateOptions, and\n // defSubmitPayment — tracked as tech debt.\n let autoPrepareConfig: AutoPrepareConfig | null = null;\n let onApplePayReadyCallbacks: ((isReady: boolean) => void)[] = [];\n let isApplePayReadyState = false;\n let autoPrepareInProgress = false;\n // Incremented by cleanup() so that in-flight prepares can detect staleness and skip writes.\n let cleanupGeneration = 0;\n // Stores pending retry args when notifyAmountChanged is called while a prepare is in flight.\n let pendingAutoPrepareArgs: { apiBaseUrl: string; secureToken: string; environment: string } | null = null;\n // Resolvers waiting for a queued retry to complete (for correct notifyAmountChanged await).\n let pendingPrepareResolvers: (() => void)[] = [];\n\n function instanceSetApplePayReady(ready: boolean): void {\n isApplePayReadyState = ready;\n for (const cb of onApplePayReadyCallbacks) cb(ready);\n }\n\n function instanceClearPreparedApplePay(): void {\n clearPreparedApplePay();\n instanceSetApplePayReady(false);\n }\n\n async function instanceAutoPrepare(apBase: string, sToken: string, env: string): Promise<void> {\n if (autoPrepareInProgress) {\n // A prepare is already in flight; queue a retry and return a promise that resolves after it.\n pendingAutoPrepareArgs = { apiBaseUrl: apBase, secureToken: sToken, environment: env };\n return new Promise<void>((resolve) => pendingPrepareResolvers.push(resolve));\n }\n autoPrepareInProgress = true;\n // Capture generation so we can detect if cleanup() is called while we await.\n const capturedGeneration = cleanupGeneration;\n instanceSetApplePayReady(false);\n\n try {\n const result = await apiCall<CheckoutSessionConfig>(`${apBase}/api/checkout-sessions/token/${sToken}`, {\n method: \"GET\",\n });\n\n if (cleanupGeneration !== capturedGeneration) return;\n\n if (result.error || !result.data) {\n console.warn(\"[ApplePay] Auto-prepare: failed to fetch session config:\", result.error);\n return;\n }\n\n const processorId = result.data.express_checkout_processor_id;\n if (!processorId) {\n console.log(\"[ApplePay] Auto-prepare: no express checkout processor configured\");\n return;\n }\n\n const processorTypeRaw = result.data.express_checkout_processor_type;\n const processorType =\n processorTypeRaw === \"airwallex\" || processorTypeRaw === \"stripe\" ? processorTypeRaw : undefined;\n\n autoPrepareConfig = { processorId, processorType };\n\n const prepareResult = await prepareApplePay(\n apBase,\n sToken,\n { processorId, processorType, customerInfo: { first_name: \"\", last_name: \"\" } },\n env,\n );\n\n if (cleanupGeneration !== capturedGeneration) return;\n\n instanceSetApplePayReady(prepareResult.success && prepareResult.applePay === true);\n } catch (err) {\n if (cleanupGeneration === capturedGeneration) {\n console.error(\"[ApplePay] Auto-prepare failed:\", err);\n }\n } finally {\n autoPrepareInProgress = false;\n const stale = cleanupGeneration !== capturedGeneration;\n const pending = pendingAutoPrepareArgs;\n const resolvers = pendingPrepareResolvers.splice(0);\n if (!stale && pending) {\n pendingAutoPrepareArgs = null;\n // Run the retry and resolve all callers that were waiting for it.\n instanceAutoPrepare(pending.apiBaseUrl, pending.secureToken, pending.environment).then(() => {\n for (const r of resolvers) r();\n });\n } else {\n pendingAutoPrepareArgs = null;\n for (const r of resolvers) r();\n }\n }\n }\n\n // Start auto-prepare immediately so the button is ready before first user interaction.\n instanceAutoPrepare(apiBaseUrl, secureToken, environment).catch((err) =>\n console.error(\"[ApplePay] Unhandled init error:\", err),\n );\n\n return {\n name: \"apple_pay\",\n externalFuncs: {\n /**\n * @deprecated The SDK now prepares automatically on init. Use `onApplePayReady` to observe\n * readiness and `notifyAmountChanged` to trigger re-prepare after amount changes.\n */\n prepareApplePay: (options: ApplePaySubmitOptions) =>\n prepareApplePay(apiBaseUrl, secureToken, options, environment),\n\n /**\n * Register a callback to be notified when Apple Pay becomes ready (or stops being ready).\n * Fires immediately with the current state, then on every state change.\n * Multiple registrations are all notified — none are silently overwritten.\n *\n * @example\n * paymentKit.apple_pay.onApplePayReady((isReady) => {\n * applePayButton.disabled = !isReady;\n * });\n */\n onApplePayReady: (callback: (isReady: boolean) => void): void => {\n onApplePayReadyCallbacks.push(callback);\n // Fire immediately with current state so caller doesn't miss a completed prepare.\n callback(isApplePayReadyState);\n },\n\n /**\n * Notify the SDK that the payment amount has changed (e.g. coupon applied).\n * The SDK will disable Apple Pay, re-prepare with the new amount, then re-enable.\n * The returned promise resolves when re-prepare is fully complete.\n *\n * @example\n * await paymentKit.apple_pay.notifyAmountChanged();\n */\n notifyAmountChanged: (): Promise<void> => {\n instanceClearPreparedApplePay();\n autoPrepareConfig = null;\n return instanceAutoPrepare(apiBaseUrl, secureToken, environment);\n },\n },\n internalFuncs: {\n submitPayment: defSubmitPayment(paymentKitStates, () => autoPrepareConfig, instanceClearPreparedApplePay),\n cleanup: () => {\n cleanupGeneration++;\n onApplePayReadyCallbacks = [];\n isApplePayReadyState = false;\n autoPrepareConfig = null;\n pendingAutoPrepareArgs = null;\n pendingPrepareResolvers = [];\n autoPrepareInProgress = false;\n clearPreparedApplePay();\n },\n },\n };\n});\n\nexport { ApplePayMockScenario };\n\nexport default ApplePayPaymentMethod;\n"],"mappings":";;;;;;AAkIA,IAAIA,sBAA0D;AAW9D,IAAIC,yBAAwD;AA6B5D,IAAIC,4BAAkD;AACtD,e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,YAAY;GAYhE,kBAAkB,aAA+C;AAC/D,6BAAyB,KAAK,SAAS;AAEvC,aAAS,qBAAqB;;GAWhC,2BAA0C;AACxC,mCAA+B;AAC/B,wBAAoB;AACpB,WAAO,oBAAoB,YAAY,aAAa,YAAY;;GAEnE;EACD,eAAe;GACb,eAAe,iBAAiB,wBAAwB,mBAAmB,8BAA8B;GACzG,eAAe;AACb;AACA,+BAA2B,EAAE;AAC7B,2BAAuB;AACvB,wBAAoB;AACpB,6BAAyB;AACzB,8BAA0B,EAAE;AAC5B,4BAAwB;AACxB,2BAAuB;;GAE1B;EACF;EACD;AAIF,wBAAe"}
@@ -1,5 +1,5 @@
1
- import "../types-CQ8xbgoh.mjs";
2
- import "../connect-card-Cra_F1cC.mjs";
3
- import "../connect-tunnel-x-Wh-JG1O5.mjs";
4
- import { a as BnplStartResponse, c as createBnplPaymentMethod, i as BnplStartRequest, n as BnplCustomerInfo, o as BnplStatusResponse, r as BnplProviderConfig, s as BnplSubmitOptions, t as BnplCheckoutResponse } from "../bnpl-shared-B-en2sPr.mjs";
1
+ import "../types-B3mjYfOm.mjs";
2
+ import "../connect-card-CZhzK_Tp.mjs";
3
+ import "../connect-tunnel-x-BKtMfoGh.mjs";
4
+ import { a as BnplStartResponse, c as createBnplPaymentMethod, i as BnplStartRequest, n as BnplCustomerInfo, o as BnplStatusResponse, r as BnplProviderConfig, s as BnplSubmitOptions, t as BnplCheckoutResponse } from "../bnpl-shared-BQwCBD45.mjs";
5
5
  export { BnplCheckoutResponse, BnplCustomerInfo, BnplProviderConfig, BnplStartRequest, BnplStartResponse, BnplStatusResponse, BnplSubmitOptions, createBnplPaymentMethod };
@@ -1,4 +1,4 @@
1
- import "../utils-B70Y8YcZ.mjs";
2
- import { t as createBnplPaymentMethod } from "../bnpl-shared-CEAXTL3Q.mjs";
1
+ import "../utils-Dc6zwOe1.mjs";
2
+ import { t as createBnplPaymentMethod } from "../bnpl-shared-DGs1YzS9.mjs";
3
3
 
4
4
  export { createBnplPaymentMethod };
@@ -1,6 +1,6 @@
1
- import { r as PaymentMethod } from "../types-CQ8xbgoh.mjs";
2
- import { n as CardInputType$1, o as connectToCardIframe, r as CheckoutResponse$1 } from "../connect-card-Cra_F1cC.mjs";
3
- import "../connect-tunnel-x-Wh-JG1O5.mjs";
1
+ import { r as PaymentMethod } from "../types-B3mjYfOm.mjs";
2
+ import { n as CardInputType$1, o as connectToCardIframe, r as CheckoutResponse$1 } from "../connect-card-CZhzK_Tp.mjs";
3
+ import "../connect-tunnel-x-BKtMfoGh.mjs";
4
4
 
5
5
  //#region src/payment-methods/card.d.ts
6
6
  type CardInputType = CardInputType$1;