@payment-kit-js/vanilla 0.5.12 → 0.5.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{airwallex-apple-pay-adapter-BCYt7Jzc.d.mts → airwallex-apple-pay-adapter-Bb0CreWN.d.mts} +1 -1
- package/dist/{airwallex-apple-pay-adapter-BCYt7Jzc.d.mts.map → airwallex-apple-pay-adapter-Bb0CreWN.d.mts.map} +1 -1
- package/dist/{airwallex-apple-pay-adapter-BFsoDoSf.mjs → airwallex-apple-pay-adapter-CHAnLP_x.mjs} +1 -1
- package/dist/{airwallex-apple-pay-adapter-BFsoDoSf.mjs.map → airwallex-apple-pay-adapter-CHAnLP_x.mjs.map} +1 -1
- package/dist/{airwallex-google-pay-adapter-B5xmg7b8.mjs → airwallex-google-pay-adapter-C8JTp01q.mjs} +1 -1
- package/dist/{airwallex-google-pay-adapter-B5xmg7b8.mjs.map → airwallex-google-pay-adapter-C8JTp01q.mjs.map} +1 -1
- package/dist/{airwallex-google-pay-adapter-DvEB6t5i.d.mts → airwallex-google-pay-adapter-adaDktQM.d.mts} +1 -1
- package/dist/{airwallex-google-pay-adapter-DvEB6t5i.d.mts.map → airwallex-google-pay-adapter-adaDktQM.d.mts.map} +1 -1
- package/dist/bnpl-shared-B-en2sPr.d.mts +64 -0
- package/dist/bnpl-shared-B-en2sPr.d.mts.map +1 -0
- package/dist/bnpl-shared-CEAXTL3Q.mjs +107 -0
- package/dist/bnpl-shared-CEAXTL3Q.mjs.map +1 -0
- package/dist/cdn/paymentkit.js +355 -15
- package/dist/cdn/paymentkit.js.map +4 -4
- package/dist/cdn/paymentkit.min.js +9 -9
- package/dist/cdn/paymentkit.min.js.map +4 -4
- package/dist/{connect-card-Cxy51W6t.d.mts → connect-card-Cra_F1cC.d.mts} +1 -1
- package/dist/{connect-card-Cxy51W6t.d.mts.map → connect-card-Cra_F1cC.d.mts.map} +1 -1
- package/dist/{connect-card-CMZkeppE.mjs → connect-card-D3Je4V7p.mjs} +1 -1
- package/dist/{connect-card-CMZkeppE.mjs.map → connect-card-D3Je4V7p.mjs.map} +1 -1
- package/dist/{connect-tunnel-x-lv6Wtdme.d.mts → connect-tunnel-x-Wh-JG1O5.d.mts} +1 -1
- package/dist/{connect-tunnel-x-lv6Wtdme.d.mts.map → connect-tunnel-x-Wh-JG1O5.d.mts.map} +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/{next-action-handlers-CTx8tRt0.mjs → next-action-handlers-BZs04hYb.mjs} +1 -1
- package/dist/{next-action-handlers-CTx8tRt0.mjs.map → next-action-handlers-BZs04hYb.mjs.map} +1 -1
- package/dist/payment-methods/affirm.d.mts +13 -0
- package/dist/payment-methods/affirm.d.mts.map +1 -0
- package/dist/payment-methods/affirm.mjs +14 -0
- package/dist/payment-methods/affirm.mjs.map +1 -0
- package/dist/payment-methods/afterpay.d.mts +13 -0
- package/dist/payment-methods/afterpay.d.mts.map +1 -0
- package/dist/payment-methods/afterpay.mjs +14 -0
- package/dist/payment-methods/afterpay.mjs.map +1 -0
- package/dist/payment-methods/airwallex-apple-pay-adapter.d.mts +1 -1
- package/dist/payment-methods/airwallex-apple-pay-adapter.mjs +1 -1
- package/dist/payment-methods/airwallex-google-pay-adapter.d.mts +1 -1
- package/dist/payment-methods/airwallex-google-pay-adapter.mjs +1 -1
- package/dist/payment-methods/apple-pay.d.mts +36 -7
- package/dist/payment-methods/apple-pay.d.mts.map +1 -1
- package/dist/payment-methods/apple-pay.mjs +162 -11
- package/dist/payment-methods/apple-pay.mjs.map +1 -1
- package/dist/payment-methods/bnpl-shared.d.mts +5 -0
- package/dist/payment-methods/bnpl-shared.mjs +4 -0
- package/dist/payment-methods/card.d.mts +3 -3
- package/dist/payment-methods/card.mjs +3 -3
- package/dist/payment-methods/google-pay.d.mts +5 -5
- package/dist/payment-methods/google-pay.mjs +3 -3
- package/dist/payment-methods/klarna.d.mts +13 -0
- package/dist/payment-methods/klarna.d.mts.map +1 -0
- package/dist/payment-methods/klarna.mjs +14 -0
- package/dist/payment-methods/klarna.mjs.map +1 -0
- package/dist/payment-methods/next-action-handlers.mjs +1 -1
- package/dist/payment-methods/paypal.d.mts +9 -3
- package/dist/payment-methods/paypal.d.mts.map +1 -1
- package/dist/payment-methods/paypal.mjs.map +1 -1
- package/dist/payment-methods/stripe-apple-pay-adapter.d.mts +1 -1
- package/dist/payment-methods/stripe-apple-pay-adapter.mjs +1 -1
- package/dist/payment-methods/stripe-google-pay-adapter.d.mts +1 -1
- package/dist/payment-methods/stripe-google-pay-adapter.mjs +1 -1
- package/dist/payment-methods/vgs-collect-loader.mjs +1 -1
- package/dist/penpal/connect-card.d.mts +1 -1
- package/dist/penpal/connect-card.mjs +1 -1
- package/dist/penpal/connect-tunnel-x.d.mts +1 -1
- package/dist/{stripe-apple-pay-adapter-Cd9LVNnp.mjs → stripe-apple-pay-adapter-BLRjqgDf.mjs} +1 -1
- package/dist/{stripe-apple-pay-adapter-Cd9LVNnp.mjs.map → stripe-apple-pay-adapter-BLRjqgDf.mjs.map} +1 -1
- package/dist/{stripe-apple-pay-adapter-DhpGclW9.d.mts → stripe-apple-pay-adapter-DcuGlQqQ.d.mts} +1 -1
- package/dist/{stripe-apple-pay-adapter-DhpGclW9.d.mts.map → stripe-apple-pay-adapter-DcuGlQqQ.d.mts.map} +1 -1
- package/dist/{stripe-google-pay-adapter-Bdox4xBq.d.mts → stripe-google-pay-adapter-BlQ2jVpE.d.mts} +1 -1
- package/dist/{stripe-google-pay-adapter-Bdox4xBq.d.mts.map → stripe-google-pay-adapter-BlQ2jVpE.d.mts.map} +1 -1
- package/dist/{stripe-google-pay-adapter-3cx0KNjK.mjs → stripe-google-pay-adapter-CIkgjhw8.mjs} +1 -1
- package/dist/{stripe-google-pay-adapter-3cx0KNjK.mjs.map → stripe-google-pay-adapter-CIkgjhw8.mjs.map} +1 -1
- package/dist/{types-D88-nhWu.d.mts → types-CQ8xbgoh.d.mts} +3 -3
- package/dist/{types-D88-nhWu.d.mts.map → types-CQ8xbgoh.d.mts.map} +1 -1
- package/dist/{vgs-collect-loader-BZj36d8r.mjs → vgs-collect-loader-l5_Pnmhz.mjs} +1 -1
- package/dist/{vgs-collect-loader-BZj36d8r.mjs.map → vgs-collect-loader-l5_Pnmhz.mjs.map} +1 -1
- package/package.json +6 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paypal.mjs","names":["submitPayment: TInternalFuncs[\"submitPayment\"]","localStates: PayPalStates"],"sources":["../../src/payment-methods/paypal.ts"],"sourcesContent":["import type { PaymentKitErrors, PaymentKitStates, TInternalFuncs } from \"../types\";\nimport { collectFraudMetadata, definePaymentMethod, getOrCreateCheckoutRequestId } from \"../utils\";\n\n// PayPal-specific types\nexport type PayPalCustomerInfo = {\n first_name: string;\n last_name: string;\n};\n\nexport type PayPalStartRequest = {\n processor_id: string;\n customer_info: PayPalCustomerInfo;\n fraud_metadata: {\n ipAddress?: string;\n browserInfo?: { [key: string]: unknown };\n processorFraudInfo?: { [key: string]: unknown };\n };\n};\n\nexport type PayPalStartResponse = {\n approval_url: string;\n popup_token: string;\n checkout_attempt_id: string;\n};\n\nexport type PayPalStatusResponse = {\n completed: boolean;\n status: \"success\" | \"failed\" | \"cancelled\";\n result?: unknown;\n error?: string;\n};\n\nexport type PayPalCheckoutResponse = {\n id: string;\n checkoutAttemptId: string;\n checkoutSessionId: string;\n state: string;\n};\n\nexport type PayPalSubmitOptions = {\n processorId: string;\n customerInfo: PayPalCustomerInfo;\n};\n\ntype PayPalStates = PaymentKitStates & {\n popup?: Window | null;\n pollInterval?: number;\n};\n\nconst defSubmitPayment = (states: PayPalStates) => {\n const submitPayment: TInternalFuncs[\"submitPayment\"] = async (_fields, options) => {\n const { apiBaseUrl, secureToken, environment } = states;\n const paypalOptions = options as PayPalSubmitOptions;\n\n if (!paypalOptions?.processorId) {\n return { errors: { processor_id: \"Processor ID is required\" } as PaymentKitErrors };\n }\n\n if (!paypalOptions?.customerInfo?.first_name || !paypalOptions?.customerInfo?.last_name) {\n return {\n errors: {\n customer_name: \"Customer first and last name are required\",\n } as PaymentKitErrors,\n };\n }\n\n try {\n // Get or create checkout request ID for correlating all API calls\n const checkoutRequestId = getOrCreateCheckoutRequestId(environment);\n console.log(`[PayPal] Using checkout_request_id: ${checkoutRequestId}`);\n\n // Step 1: Call PayPal start endpoint\n const startResponse = await fetch(`${apiBaseUrl}/api/checkout/${secureToken}/paypal/start`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-request-id\": checkoutRequestId,\n },\n body: JSON.stringify({\n processor_id: paypalOptions.processorId,\n customer_info: paypalOptions.customerInfo,\n fraud_metadata: collectFraudMetadata(),\n } as PayPalStartRequest),\n });\n\n if (!startResponse.ok) {\n let errorMessage = `Failed to start PayPal checkout (${startResponse.status})`;\n try {\n const errorData = await startResponse.json();\n errorMessage = errorData.detail || errorMessage;\n } catch {\n // Response body is not JSON, use status text\n errorMessage = startResponse.statusText || errorMessage;\n }\n return {\n errors: {\n paypal: errorMessage,\n } as PaymentKitErrors,\n };\n }\n\n const { approval_url, popup_token, checkout_attempt_id } = (await startResponse.json()) as PayPalStartResponse;\n\n // Step 2: Open PayPal popup\n const popup = window.open(approval_url, \"PayPal\", \"width=600,height=700\");\n\n if (!popup) {\n return {\n errors: {\n paypal: \"Failed to open PayPal popup. Please allow popups for this site.\",\n } as PaymentKitErrors,\n };\n }\n\n states.popup = popup;\n\n // Step 3: Poll for completion\n return new Promise((resolve) => {\n const pollInterval = setInterval(async () => {\n try {\n // Check status FIRST - popup might close after successful callback\n const statusResponse = await fetch(\n `${apiBaseUrl}/api/checkout/${secureToken}/popup/status?popup_token=${popup_token}`,\n );\n\n if (!statusResponse.ok) {\n clearInterval(pollInterval);\n popup.close();\n resolve({\n errors: {\n paypal: \"Failed to check PayPal status\",\n } as PaymentKitErrors,\n });\n return;\n }\n\n const statusResult = (await statusResponse.json()) as PayPalStatusResponse;\n\n if (statusResult.completed) {\n clearInterval(pollInterval);\n popup.close();\n\n if (statusResult.status === \"success\") {\n //
|
|
1
|
+
{"version":3,"file":"paypal.mjs","names":["submitPayment: TInternalFuncs[\"submitPayment\"]","localStates: PayPalStates"],"sources":["../../src/payment-methods/paypal.ts"],"sourcesContent":["import type { PaymentKitErrors, PaymentKitStates, TInternalFuncs } from \"../types\";\nimport { collectFraudMetadata, definePaymentMethod, getOrCreateCheckoutRequestId } from \"../utils\";\n\n// PayPal-specific types\nexport type PayPalCustomerInfo = {\n first_name: string;\n last_name: string;\n};\n\nexport type PayPalStartRequest = {\n processor_id: string;\n customer_info: PayPalCustomerInfo;\n fraud_metadata: {\n ipAddress?: string;\n browserInfo?: { [key: string]: unknown };\n processorFraudInfo?: { [key: string]: unknown };\n };\n};\n\nexport type PayPalStartResponse = {\n approval_url: string;\n popup_token: string;\n checkout_attempt_id: string;\n};\n\nexport type PayPalStatusResponse = {\n completed: boolean;\n status: \"success\" | \"failed\" | \"cancelled\";\n result?: unknown;\n error?: string;\n};\n\nexport type PayPalCheckoutResponse = {\n id: string;\n checkoutAttemptId: string;\n checkoutSessionId: string;\n state: string;\n customerId?: string;\n paymentMethodId?: string;\n processorUsed?: string;\n subscriptionId?: string;\n invoiceId?: string;\n invoiceNumber?: number;\n};\n\nexport type PayPalSubmitOptions = {\n processorId: string;\n customerInfo: PayPalCustomerInfo;\n};\n\ntype PayPalStates = PaymentKitStates & {\n popup?: Window | null;\n pollInterval?: number;\n};\n\nconst defSubmitPayment = (states: PayPalStates) => {\n const submitPayment: TInternalFuncs[\"submitPayment\"] = async (_fields, options) => {\n const { apiBaseUrl, secureToken, environment } = states;\n const paypalOptions = options as PayPalSubmitOptions;\n\n if (!paypalOptions?.processorId) {\n return { errors: { processor_id: \"Processor ID is required\" } as PaymentKitErrors };\n }\n\n if (!paypalOptions?.customerInfo?.first_name || !paypalOptions?.customerInfo?.last_name) {\n return {\n errors: {\n customer_name: \"Customer first and last name are required\",\n } as PaymentKitErrors,\n };\n }\n\n try {\n // Get or create checkout request ID for correlating all API calls\n const checkoutRequestId = getOrCreateCheckoutRequestId(environment);\n console.log(`[PayPal] Using checkout_request_id: ${checkoutRequestId}`);\n\n // Step 1: Call PayPal start endpoint\n const startResponse = await fetch(`${apiBaseUrl}/api/checkout/${secureToken}/paypal/start`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-request-id\": checkoutRequestId,\n },\n body: JSON.stringify({\n processor_id: paypalOptions.processorId,\n customer_info: paypalOptions.customerInfo,\n fraud_metadata: collectFraudMetadata(),\n } as PayPalStartRequest),\n });\n\n if (!startResponse.ok) {\n let errorMessage = `Failed to start PayPal checkout (${startResponse.status})`;\n try {\n const errorData = await startResponse.json();\n errorMessage = errorData.detail || errorMessage;\n } catch {\n // Response body is not JSON, use status text\n errorMessage = startResponse.statusText || errorMessage;\n }\n return {\n errors: {\n paypal: errorMessage,\n } as PaymentKitErrors,\n };\n }\n\n const { approval_url, popup_token, checkout_attempt_id } = (await startResponse.json()) as PayPalStartResponse;\n\n // Step 2: Open PayPal popup\n const popup = window.open(approval_url, \"PayPal\", \"width=600,height=700\");\n\n if (!popup) {\n return {\n errors: {\n paypal: \"Failed to open PayPal popup. Please allow popups for this site.\",\n } as PaymentKitErrors,\n };\n }\n\n states.popup = popup;\n\n // Step 3: Poll for completion\n return new Promise((resolve) => {\n const pollInterval = setInterval(async () => {\n try {\n // Check status FIRST - popup might close after successful callback\n const statusResponse = await fetch(\n `${apiBaseUrl}/api/checkout/${secureToken}/popup/status?popup_token=${popup_token}`,\n );\n\n if (!statusResponse.ok) {\n clearInterval(pollInterval);\n popup.close();\n resolve({\n errors: {\n paypal: \"Failed to check PayPal status\",\n } as PaymentKitErrors,\n });\n return;\n }\n\n const statusResult = (await statusResponse.json()) as PayPalStatusResponse;\n\n if (statusResult.completed) {\n clearInterval(pollInterval);\n popup.close();\n\n if (statusResult.status === \"success\") {\n // Result is returned directly from popup status endpoint\n const result = statusResult.result || {\n id: checkout_attempt_id,\n checkoutAttemptId: checkout_attempt_id,\n checkoutSessionId: secureToken,\n state: \"checkout_succeeded\",\n };\n\n resolve({ data: result });\n } else {\n resolve({\n errors: {\n paypal: statusResult.error || `PayPal checkout ${statusResult.status}`,\n } as PaymentKitErrors,\n });\n }\n return;\n }\n\n // Only check popup.closed AFTER confirming status is not completed\n // This avoids race condition where popup closes from successful callback\n if (popup.closed) {\n clearInterval(pollInterval);\n resolve({\n errors: {\n paypal: \"PayPal popup closed by user\",\n } as PaymentKitErrors,\n });\n return;\n }\n } catch (error) {\n clearInterval(pollInterval);\n popup.close();\n resolve({\n errors: {\n paypal: `Polling error: ${error}`,\n } as PaymentKitErrors,\n });\n }\n }, 2000); // Poll every 2 seconds\n\n states.pollInterval = pollInterval as unknown as number;\n });\n } catch (error) {\n return {\n errors: {\n paypal: `PayPal checkout error: ${error}`,\n } as PaymentKitErrors,\n };\n }\n };\n\n return submitPayment;\n};\n\nconst PayPalPaymentMethod = definePaymentMethod((paymentKitStates) => {\n const localStates: PayPalStates = { ...paymentKitStates };\n\n return {\n name: \"paypal\",\n externalFuncs: {\n // PayPal doesn't need createElement like card iframes\n },\n internalFuncs: {\n submitPayment: defSubmitPayment(localStates),\n cleanup: () => {\n // Clean up popup and polling interval if still active\n if (localStates.pollInterval) {\n clearInterval(localStates.pollInterval);\n }\n if (localStates.popup && !localStates.popup.closed) {\n localStates.popup.close();\n }\n },\n },\n };\n});\n\nexport default PayPalPaymentMethod;\n"],"mappings":";;;AAuDA,MAAM,oBAAoB,WAAyB;CACjD,MAAMA,gBAAiD,OAAO,SAAS,YAAY;EACjF,MAAM,EAAE,YAAY,aAAa,gBAAgB;EACjD,MAAM,gBAAgB;AAEtB,MAAI,CAAC,eAAe,YAClB,QAAO,EAAE,QAAQ,EAAE,cAAc,4BAA4B,EAAsB;AAGrF,MAAI,CAAC,eAAe,cAAc,cAAc,CAAC,eAAe,cAAc,UAC5E,QAA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BAAmB;QACnB,OAAO;QACR,EAEuB,CAAC;WAEzB,SAAQ,EACN,QAAQ,EACN,QAAQ,aAAa,SAAS,mBAAmB,aAAa,UAC/D,EACF,CAAC;AAEJ;;AAKF,UAAI,MAAM,QAAQ;AAChB,qBAAc,aAAa;AAC3B,eAAQ,EACN,QAAQ,EACN,QAAQ,+BACT,EACF,CAAC;AACF;;cAEK,OAAO;AACd,oBAAc,aAAa;AAC3B,YAAM,OAAO;AACb,cAAQ,EACN,QAAQ,EACN,QAAQ,kBAAkB,SAC3B,EACF,CAAC;;OAEH,IAAK;AAER,WAAO,eAAe;KACtB;WACK,OAAO;AACd,UAAO,EACL,QAAQ,EACN,QAAQ,0BAA0B,SACnC,EACF;;;AAIL,QAAO;;AAGT,MAAM,sBAAsB,qBAAqB,qBAAqB;CACpE,MAAMC,cAA4B,EAAE,GAAG,kBAAkB;AAEzD,QAAO;EACL,MAAM;EACN,eAAe,EAEd;EACD,eAAe;GACb,eAAe,iBAAiB,YAAY;GAC5C,eAAe;AAEb,QAAI,YAAY,aACd,eAAc,YAAY,aAAa;AAEzC,QAAI,YAAY,SAAS,CAAC,YAAY,MAAM,OAC1C,aAAY,MAAM,OAAO;;GAG9B;EACF;EACD;AAEF,qBAAe"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as StripeApplePayAdapter, i as ShowApplePaySheetResult, n as ApplePayPaymentRequestConfig, r as ConfirmResult, t as ApplePayMockScenario } from "../stripe-apple-pay-adapter-
|
|
1
|
+
import { a as StripeApplePayAdapter, i as ShowApplePaySheetResult, n as ApplePayPaymentRequestConfig, r as ConfirmResult, t as ApplePayMockScenario } from "../stripe-apple-pay-adapter-DcuGlQqQ.mjs";
|
|
2
2
|
export { ApplePayMockScenario, ApplePayPaymentRequestConfig, ConfirmResult, ShowApplePaySheetResult, StripeApplePayAdapter };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { n as StripeApplePayAdapter, t as ApplePayMockScenario } from "../stripe-apple-pay-adapter-
|
|
1
|
+
import { n as StripeApplePayAdapter, t as ApplePayMockScenario } from "../stripe-apple-pay-adapter-BLRjqgDf.mjs";
|
|
2
2
|
|
|
3
3
|
export { ApplePayMockScenario, StripeApplePayAdapter };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as StripeGooglePayAdapter, i as ShowPaymentSheetResult, n as GooglePayMockScenario, r as PaymentRequestConfig, t as ConfirmResult } from "../stripe-google-pay-adapter-
|
|
1
|
+
import { a as StripeGooglePayAdapter, i as ShowPaymentSheetResult, n as GooglePayMockScenario, r as PaymentRequestConfig, t as ConfirmResult } from "../stripe-google-pay-adapter-BlQ2jVpE.mjs";
|
|
2
2
|
export { ConfirmResult, GooglePayMockScenario, PaymentRequestConfig, ShowPaymentSheetResult, StripeGooglePayAdapter };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { n as StripeGooglePayAdapter, t as GooglePayMockScenario } from "../stripe-google-pay-adapter-
|
|
1
|
+
import { n as StripeGooglePayAdapter, t as GooglePayMockScenario } from "../stripe-google-pay-adapter-CIkgjhw8.mjs";
|
|
2
2
|
|
|
3
3
|
export { GooglePayMockScenario, StripeGooglePayAdapter };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { n as initVgsCollect, r as loadVgsCollectScript, t as createVgsCardFields } from "../vgs-collect-loader-
|
|
1
|
+
import { n as initVgsCollect, r as loadVgsCollectScript, t as createVgsCardFields } from "../vgs-collect-loader-l5_Pnmhz.mjs";
|
|
2
2
|
|
|
3
3
|
export { createVgsCardFields, initVgsCollect, loadVgsCollectScript };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as ParentConnection, i as IFrameConnection, n as CardInputType, o as connectToCardIframe, r as CheckoutResponse, s as connectToCardParent, t as CardErrorCode } from "../connect-card-
|
|
1
|
+
import { a as ParentConnection, i as IFrameConnection, n as CardInputType, o as connectToCardIframe, r as CheckoutResponse, s as connectToCardParent, t as CardErrorCode } from "../connect-card-Cra_F1cC.mjs";
|
|
2
2
|
export { CardErrorCode, CardInputType, CheckoutResponse, IFrameConnection, ParentConnection, connectToCardIframe, connectToCardParent };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import "../penpal-BFKeZTVz.mjs";
|
|
2
|
-
import { n as connectToCardParent, t as connectToCardIframe } from "../connect-card-
|
|
2
|
+
import { n as connectToCardParent, t as connectToCardIframe } from "../connect-card-D3Je4V7p.mjs";
|
|
3
3
|
|
|
4
4
|
export { connectToCardIframe, connectToCardParent };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as connectToTunnelXParent, i as connectToTunnelXIframe, n as TunnelXManager, r as TunnelXParentConnection, t as TunnelXIFrameConnection } from "../connect-tunnel-x-
|
|
1
|
+
import { a as connectToTunnelXParent, i as connectToTunnelXIframe, n as TunnelXManager, r as TunnelXParentConnection, t as TunnelXIFrameConnection } from "../connect-tunnel-x-Wh-JG1O5.mjs";
|
|
2
2
|
export { TunnelXIFrameConnection, TunnelXManager, TunnelXParentConnection, connectToTunnelXIframe, connectToTunnelXParent };
|
package/dist/{stripe-apple-pay-adapter-Cd9LVNnp.mjs.map → stripe-apple-pay-adapter-BLRjqgDf.mjs.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stripe-apple-pay-adapter-Cd9LVNnp.mjs","names":[],"sources":["../src/payment-methods/stripe-apple-pay-adapter.ts"],"sourcesContent":["/// <reference types=\"@types/applepayjs\" />\nimport type { PaymentRequest, PaymentRequestPaymentMethodEvent, Stripe, StripeConstructor } from \"@stripe/stripe-js\";\n\n// Stripe.js must be loaded via script tag for PCI compliance\ndeclare global {\n interface Window {\n Stripe?: StripeConstructor;\n ApplePaySession?: typeof ApplePaySession;\n }\n}\n\nexport interface ApplePayPaymentRequestConfig {\n country: string;\n currency: string;\n total: { label: string; amount: number }; // Amount in cents (atomic units)\n supportedNetworks?: string[];\n merchantCapabilities?: string[];\n}\n\nexport type ShowApplePaySheetResult =\n | {\n success: true;\n paymentMethodId: string;\n paymentMethodEvent: PaymentRequestPaymentMethodEvent;\n billingDetails?: {\n email?: string;\n name?: string;\n address?: {\n city?: string | null;\n country?: string | null;\n line1?: string | null;\n line2?: string | null;\n postal_code?: string | null;\n state?: string | null;\n } | null;\n };\n }\n | { success: false; cancelled: true }\n | { success: false; error: string };\n\nexport type ConfirmResult = { success: true } | { success: false; error: string };\n\nexport enum ApplePayMockScenario {\n None = \"none\",\n Success = \"success\",\n Cancelled = \"cancelled\",\n}\n\n/**\n * Stripe Apple Pay Adapter using Stripe's PaymentRequest API.\n *\n * This uses Stripe's PaymentRequest API instead of the native ApplePaySession API.\n * The key benefit is that Stripe handles merchant validation automatically,\n * which is required for Apple Pay to work correctly.\n *\n * IMPORTANT: To comply with browser security requirements, Apple Pay must be shown\n * synchronously from a user click. The flow is:\n *\n * 1. Call preparePaymentRequest() BEFORE user clicks (e.g., when page loads)\n * - This creates the PaymentRequest and calls canMakePayment()\n * 2. On user click, call showPreparedPaymentSheet()\n * - This calls show() on the pre-created PaymentRequest (no async!)\n * 3. Handle the paymentmethod event and call complete()\n */\nexport class StripeApplePayAdapter {\n private stripe: Stripe | null = null;\n private mockScenario: ApplePayMockScenario;\n private preparedPaymentRequest: PaymentRequest | null = null;\n\n constructor(mockScenario?: ApplePayMockScenario) {\n this.mockScenario = mockScenario ?? ApplePayMockScenario.None;\n }\n\n initialize(publishableKey: string): boolean {\n switch (this.mockScenario) {\n case ApplePayMockScenario.None: {\n console.log(\"[ApplePay] initialize called\");\n if (!window.Stripe) {\n console.log(\"[ApplePay] Stripe.js not loaded\");\n return false;\n }\n this.stripe = window.Stripe(publishableKey);\n const success = this.stripe !== null;\n console.log(\"[ApplePay] initialize result:\", success);\n return success;\n }\n case ApplePayMockScenario.Success:\n case ApplePayMockScenario.Cancelled: {\n console.log(\"[MockApplePay] initialize called\");\n console.log(\"[MockApplePay] initialize result:\", true);\n return true;\n }\n }\n }\n\n /**\n * Check if Apple Pay is available on this device/browser.\n * Uses Stripe's PaymentRequest.canMakePayment() which is more reliable\n * than checking ApplePaySession directly.\n */\n static isAvailable(): boolean {\n // Basic check - ApplePaySession must exist (Safari on iOS/macOS)\n if (typeof window === \"undefined\" || !window.ApplePaySession) {\n console.log(\"[ApplePay] ApplePaySession not available\");\n return false;\n }\n\n // Check if device supports Apple Pay\n const canMakePayments = window.ApplePaySession.canMakePayments();\n console.log(\"[ApplePay] canMakePayments:\", canMakePayments);\n return canMakePayments;\n }\n\n /**\n * Check availability using Stripe's PaymentRequest API.\n * This is more accurate as it checks Stripe's configuration too.\n */\n async canMakePayment(): Promise<{ applePay: boolean; googlePay: boolean } | null> {\n if (!this.stripe) {\n console.log(\"[ApplePay] Stripe not initialized\");\n return null;\n }\n\n // Create a temporary payment request to check availability\n const pr = this.stripe.paymentRequest({\n country: \"US\",\n currency: \"usd\",\n total: { label: \"Check\", amount: 100 },\n });\n\n const result = await pr.canMakePayment();\n console.log(\"[ApplePay] canMakePayment result:\", result);\n\n if (!result) {\n return null;\n }\n\n // Map Stripe's result to our expected format\n return {\n applePay: result.applePay ?? false,\n googlePay: result.googlePay ?? false,\n };\n }\n\n /**\n * Prepare a PaymentRequest for later use. Call this BEFORE the user clicks.\n * This creates the PaymentRequest and calls canMakePayment() to validate.\n *\n * @returns Promise with success status and whether Apple Pay is available\n */\n async preparePaymentRequest(config: ApplePayPaymentRequestConfig): Promise<{\n success: boolean;\n applePay?: boolean;\n googlePay?: boolean;\n error?: string;\n }> {\n if (this.mockScenario !== ApplePayMockScenario.None) {\n console.log(\"[MockApplePay] preparePaymentRequest called\");\n this.preparedConfig = config;\n return { success: true, applePay: true, googlePay: false };\n }\n\n console.log(\"[ApplePay] preparePaymentRequest called\", config);\n\n if (!this.stripe) {\n return { success: false, error: \"Stripe not initialized\" };\n }\n\n // Create the PaymentRequest\n const paymentRequest = this.stripe.paymentRequest({\n country: config.country,\n currency: config.currency.toLowerCase(),\n total: {\n label: config.total.label,\n amount: config.total.amount,\n },\n requestPayerName: true,\n requestPayerEmail: true,\n });\n\n // Check availability - this MUST be called before show()\n const canMakePaymentResult = await paymentRequest.canMakePayment();\n console.log(\"[ApplePay] preparePaymentRequest canMakePayment:\", canMakePaymentResult);\n\n if (!canMakePaymentResult) {\n return {\n success: false,\n error: \"Payment methods not available on this device/browser\",\n applePay: false,\n googlePay: false,\n };\n }\n\n // Store the prepared PaymentRequest for later use\n this.preparedPaymentRequest = paymentRequest;\n this.preparedConfig = config;\n\n return {\n success: true,\n applePay: canMakePaymentResult.applePay ?? false,\n googlePay: canMakePaymentResult.googlePay ?? false,\n };\n }\n\n /**\n * Check if a PaymentRequest has been prepared and is ready to show.\n */\n isPrepared(): boolean {\n return this.preparedPaymentRequest !== null || this.mockScenario !== ApplePayMockScenario.None;\n }\n\n /**\n * Clear the prepared PaymentRequest.\n */\n clearPrepared(): void {\n this.preparedPaymentRequest = null;\n this.preparedConfig = null;\n }\n\n /**\n * Show the prepared Apple Pay payment sheet.\n * MUST be called synchronously from a user click handler.\n * Call preparePaymentRequest() before the click to set up the PaymentRequest.\n */\n showPreparedPaymentSheet(): Promise<ShowApplePaySheetResult> {\n switch (this.mockScenario) {\n case ApplePayMockScenario.None: {\n console.log(\"[ApplePay] showPreparedPaymentSheet called\");\n\n if (!this.preparedPaymentRequest) {\n console.error(\"[ApplePay] No prepared PaymentRequest! Call preparePaymentRequest() first.\");\n return Promise.resolve({\n success: false,\n error: \"PaymentRequest not prepared. Call preparePaymentRequest() before showing the sheet.\",\n });\n }\n\n const paymentRequest = this.preparedPaymentRequest;\n\n // Return a promise that resolves when the user completes or cancels\n return new Promise((resolve) => {\n // Handle successful payment method creation\n paymentRequest.on(\"paymentmethod\", (evt: PaymentRequestPaymentMethodEvent) => {\n console.log(\"[ApplePay] paymentmethod event received\", {\n paymentMethodId: evt.paymentMethod.id,\n payerEmail: evt.payerEmail,\n payerName: evt.payerName,\n });\n\n // Clear the prepared request after use\n this.preparedPaymentRequest = null;\n\n resolve({\n success: true,\n paymentMethodId: evt.paymentMethod.id,\n paymentMethodEvent: evt,\n billingDetails: {\n email: evt.payerEmail ?? undefined,\n name: evt.payerName ?? undefined,\n address: evt.paymentMethod.billing_details?.address ?? undefined,\n },\n });\n });\n\n // Handle cancellation\n paymentRequest.on(\"cancel\", () => {\n console.log(\"[ApplePay] cancel event - user cancelled\");\n // Clear the prepared request after cancellation\n this.preparedPaymentRequest = null;\n resolve({ success: false, cancelled: true });\n });\n\n // Show the payment sheet immediately (no async operations before this!)\n console.log(\"[ApplePay] showing payment sheet\");\n paymentRequest.show();\n });\n }\n\n case ApplePayMockScenario.Success: {\n console.log(\"[MockApplePay] showPreparedPaymentSheet: success\");\n return new Promise((resolve) => {\n setTimeout(() => {\n resolve({\n success: true,\n paymentMethodId: \"pm_mock_apple_pay_test\",\n paymentMethodEvent: {\n complete: (status: string) => console.log(`[MockApplePay] complete: ${status}`),\n paymentMethod: {\n id: \"pm_mock_apple_pay_test\",\n object: \"payment_method\",\n type: \"card\",\n card: {\n brand: \"visa\",\n last4: \"4242\",\n exp_month: 12,\n exp_year: 2030,\n },\n billing_details: {\n email: \"test@example.com\",\n name: \"Test User\",\n },\n },\n payerEmail: \"test@example.com\",\n payerName: \"Test User\",\n } as unknown as PaymentRequestPaymentMethodEvent,\n billingDetails: {\n email: \"test@example.com\",\n name: \"Test User\",\n },\n });\n }, 500);\n });\n }\n\n case ApplePayMockScenario.Cancelled: {\n console.log(\"[MockApplePay] showPreparedPaymentSheet: cancelled\");\n return new Promise((resolve) => {\n setTimeout(() => {\n resolve({ success: false, cancelled: true });\n }, 500);\n });\n }\n }\n }\n\n /**\n * @deprecated Use preparePaymentRequest() + showPreparedPaymentSheet() instead.\n * This method creates a new PaymentRequest and shows it, which doesn't work\n * with browser security requirements (show() must be called synchronously).\n */\n async showPaymentSheet(config: ApplePayPaymentRequestConfig): Promise<ShowApplePaySheetResult> {\n console.warn(\n \"[ApplePay] showPaymentSheet is deprecated. Use preparePaymentRequest() + showPreparedPaymentSheet() instead.\",\n );\n\n // Try to prepare and show in one go (will likely fail due to user gesture requirement)\n const prepareResult = await this.preparePaymentRequest(config);\n if (!prepareResult.success) {\n return { success: false, error: prepareResult.error ?? \"Failed to prepare payment request\" };\n }\n\n return this.showPreparedPaymentSheet();\n }\n\n /**\n * Complete the payment flow in the Apple Pay sheet.\n * Call this after confirming the payment on the server.\n *\n * @param evt - The PaymentRequestPaymentMethodEvent from showPaymentSheet\n * @param status - 'success' or 'fail'\n */\n completePayment(evt: PaymentRequestPaymentMethodEvent, status: \"success\" | \"fail\"): void {\n console.log(\"[ApplePay] completePayment:\", status);\n evt.complete(status);\n }\n\n /**\n * Confirm PaymentIntent with the PaymentMethod.\n * This is called after showPaymentSheet to finalize the payment.\n *\n * @deprecated - Server-side confirmation is preferred. The backend should\n * call stripe.PaymentIntent.confirm() with the payment_method_id.\n */\n async confirmPaymentIntent(clientSecret: string, paymentMethodId: string): Promise<ConfirmResult> {\n switch (this.mockScenario) {\n case ApplePayMockScenario.None: {\n console.log(\"[ApplePay] confirmPaymentIntent called\", {\n clientSecret: `${clientSecret.slice(0, 20)}...`,\n paymentMethodId,\n });\n if (!this.stripe) {\n console.log(\"[ApplePay] confirmPaymentIntent: Stripe not initialized\");\n return { success: false, error: \"Stripe not initialized\" };\n }\n\n const { error } = await this.stripe.confirmCardPayment(clientSecret, {\n payment_method: paymentMethodId,\n });\n\n if (error) {\n console.log(\"[ApplePay] confirmPaymentIntent error:\", error);\n return { success: false, error: error.message ?? \"Payment failed\" };\n }\n\n console.log(\"[ApplePay] confirmPaymentIntent success\");\n return { success: true };\n }\n case ApplePayMockScenario.Success: {\n console.log(\"[MockApplePay] confirmPaymentIntent called\", { clientSecret, paymentMethodId });\n return { success: true };\n }\n case ApplePayMockScenario.Cancelled: {\n throw new Error(\"confirmPaymentIntent should not be called when scenario is Cancelled\");\n }\n }\n }\n}\n"],"mappings":";AA0CA,IAAY,wEAAL;AACL;AACA;AACA;;;;;;;;;;;;;;;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QAAkC;AACvF,UAAQ,IAAI,+BAA+B,OAAO;AAClD,MAAI,SAAS,OAAO;;;;;;;;;CAUtB,MAAM,qBAAqB,cAAsB,iBAAiD;AAChG,UAAQ,KAAK,cAAb;GACE,KAAK,qBAAqB,MAAM;AAC9B,YAAQ,IAAI,0CAA0C;KACpD,cAAc,GAAG,aAAa,MAAM,GAAG,GAAG,CAAC;KAC3C;KACD,CAAC;AACF,QAAI,CAAC,KAAK,QAAQ;AAChB,aAAQ,IAAI,0DAA0D;AACtE,YAAO;MAAE,SAAS;MAAO,OAAO;MAA0B;;IAG5D,MAAM,EAAE,UAAU,MAAM,KAAK,OAAO,mBAAmB,cAAc,EACnE,gBAAgB,iBACjB,CAAC;AAEF,QAAI,OAAO;AACT,aAAQ,IAAI,0CAA0C,MAAM;AAC5D,YAAO;MAAE,SAAS;MAAO,OAAO,MAAM,WAAW;MAAkB;;AAGrE,YAAQ,IAAI,0CAA0C;AACtD,WAAO,EAAE,SAAS,MAAM;;GAE1B,KAAK,qBAAqB;AACxB,YAAQ,IAAI,8CAA8C;KAAE;KAAc;KAAiB,CAAC;AAC5F,WAAO,EAAE,SAAS,MAAM;GAE1B,KAAK,qBAAqB,UACxB,OAAM,IAAI,MAAM,uEAAuE"}
|
|
1
|
+
{"version":3,"file":"stripe-apple-pay-adapter-BLRjqgDf.mjs","names":[],"sources":["../src/payment-methods/stripe-apple-pay-adapter.ts"],"sourcesContent":["/// <reference types=\"@types/applepayjs\" />\nimport type { PaymentRequest, PaymentRequestPaymentMethodEvent, Stripe, StripeConstructor } from \"@stripe/stripe-js\";\n\n// Stripe.js must be loaded via script tag for PCI compliance\ndeclare global {\n interface Window {\n Stripe?: StripeConstructor;\n ApplePaySession?: typeof ApplePaySession;\n }\n}\n\nexport interface ApplePayPaymentRequestConfig {\n country: string;\n currency: string;\n total: { label: string; amount: number }; // Amount in cents (atomic units)\n supportedNetworks?: string[];\n merchantCapabilities?: string[];\n}\n\nexport type ShowApplePaySheetResult =\n | {\n success: true;\n paymentMethodId: string;\n paymentMethodEvent: PaymentRequestPaymentMethodEvent;\n billingDetails?: {\n email?: string;\n name?: string;\n address?: {\n city?: string | null;\n country?: string | null;\n line1?: string | null;\n line2?: string | null;\n postal_code?: string | null;\n state?: string | null;\n } | null;\n };\n }\n | { success: false; cancelled: true }\n | { success: false; error: string };\n\nexport type ConfirmResult = { success: true } | { success: false; error: string };\n\nexport enum ApplePayMockScenario {\n None = \"none\",\n Success = \"success\",\n Cancelled = \"cancelled\",\n}\n\n/**\n * Stripe Apple Pay Adapter using Stripe's PaymentRequest API.\n *\n * This uses Stripe's PaymentRequest API instead of the native ApplePaySession API.\n * The key benefit is that Stripe handles merchant validation automatically,\n * which is required for Apple Pay to work correctly.\n *\n * IMPORTANT: To comply with browser security requirements, Apple Pay must be shown\n * synchronously from a user click. The flow is:\n *\n * 1. Call preparePaymentRequest() BEFORE user clicks (e.g., when page loads)\n * - This creates the PaymentRequest and calls canMakePayment()\n * 2. On user click, call showPreparedPaymentSheet()\n * - This calls show() on the pre-created PaymentRequest (no async!)\n * 3. Handle the paymentmethod event and call complete()\n */\nexport class StripeApplePayAdapter {\n private stripe: Stripe | null = null;\n private mockScenario: ApplePayMockScenario;\n private preparedPaymentRequest: PaymentRequest | null = null;\n\n constructor(mockScenario?: ApplePayMockScenario) {\n this.mockScenario = mockScenario ?? ApplePayMockScenario.None;\n }\n\n initialize(publishableKey: string): boolean {\n switch (this.mockScenario) {\n case ApplePayMockScenario.None: {\n console.log(\"[ApplePay] initialize called\");\n if (!window.Stripe) {\n console.log(\"[ApplePay] Stripe.js not loaded\");\n return false;\n }\n this.stripe = window.Stripe(publishableKey);\n const success = this.stripe !== null;\n console.log(\"[ApplePay] initialize result:\", success);\n return success;\n }\n case ApplePayMockScenario.Success:\n case ApplePayMockScenario.Cancelled: {\n console.log(\"[MockApplePay] initialize called\");\n console.log(\"[MockApplePay] initialize result:\", true);\n return true;\n }\n }\n }\n\n /**\n * Check if Apple Pay is available on this device/browser.\n * Uses Stripe's PaymentRequest.canMakePayment() which is more reliable\n * than checking ApplePaySession directly.\n */\n static isAvailable(): boolean {\n // Basic check - ApplePaySession must exist (Safari on iOS/macOS)\n if (typeof window === \"undefined\" || !window.ApplePaySession) {\n console.log(\"[ApplePay] ApplePaySession not available\");\n return false;\n }\n\n // Check if device supports Apple Pay\n const canMakePayments = window.ApplePaySession.canMakePayments();\n console.log(\"[ApplePay] canMakePayments:\", canMakePayments);\n return canMakePayments;\n }\n\n /**\n * Check availability using Stripe's PaymentRequest API.\n * This is more accurate as it checks Stripe's configuration too.\n */\n async canMakePayment(): Promise<{ applePay: boolean; googlePay: boolean } | null> {\n if (!this.stripe) {\n console.log(\"[ApplePay] Stripe not initialized\");\n return null;\n }\n\n // Create a temporary payment request to check availability\n const pr = this.stripe.paymentRequest({\n country: \"US\",\n currency: \"usd\",\n total: { label: \"Check\", amount: 100 },\n });\n\n const result = await pr.canMakePayment();\n console.log(\"[ApplePay] canMakePayment result:\", result);\n\n if (!result) {\n return null;\n }\n\n // Map Stripe's result to our expected format\n return {\n applePay: result.applePay ?? false,\n googlePay: result.googlePay ?? false,\n };\n }\n\n /**\n * Prepare a PaymentRequest for later use. Call this BEFORE the user clicks.\n * This creates the PaymentRequest and calls canMakePayment() to validate.\n *\n * @returns Promise with success status and whether Apple Pay is available\n */\n async preparePaymentRequest(config: ApplePayPaymentRequestConfig): Promise<{\n success: boolean;\n applePay?: boolean;\n googlePay?: boolean;\n error?: string;\n }> {\n if (this.mockScenario !== ApplePayMockScenario.None) {\n console.log(\"[MockApplePay] preparePaymentRequest called\");\n this.preparedConfig = config;\n return { success: true, applePay: true, googlePay: false };\n }\n\n console.log(\"[ApplePay] preparePaymentRequest called\", config);\n\n if (!this.stripe) {\n return { success: false, error: \"Stripe not initialized\" };\n }\n\n // Create the PaymentRequest\n const paymentRequest = this.stripe.paymentRequest({\n country: config.country,\n currency: config.currency.toLowerCase(),\n total: {\n label: config.total.label,\n amount: config.total.amount,\n },\n requestPayerName: true,\n requestPayerEmail: true,\n });\n\n // Check availability - this MUST be called before show()\n const canMakePaymentResult = await paymentRequest.canMakePayment();\n console.log(\"[ApplePay] preparePaymentRequest canMakePayment:\", canMakePaymentResult);\n\n if (!canMakePaymentResult) {\n return {\n success: false,\n error: \"Payment methods not available on this device/browser\",\n applePay: false,\n googlePay: false,\n };\n }\n\n // Store the prepared PaymentRequest for later use\n this.preparedPaymentRequest = paymentRequest;\n this.preparedConfig = config;\n\n return {\n success: true,\n applePay: canMakePaymentResult.applePay ?? false,\n googlePay: canMakePaymentResult.googlePay ?? false,\n };\n }\n\n /**\n * Check if a PaymentRequest has been prepared and is ready to show.\n */\n isPrepared(): boolean {\n return this.preparedPaymentRequest !== null || this.mockScenario !== ApplePayMockScenario.None;\n }\n\n /**\n * Clear the prepared PaymentRequest.\n */\n clearPrepared(): void {\n this.preparedPaymentRequest = null;\n this.preparedConfig = null;\n }\n\n /**\n * Show the prepared Apple Pay payment sheet.\n * MUST be called synchronously from a user click handler.\n * Call preparePaymentRequest() before the click to set up the PaymentRequest.\n */\n showPreparedPaymentSheet(): Promise<ShowApplePaySheetResult> {\n switch (this.mockScenario) {\n case ApplePayMockScenario.None: {\n console.log(\"[ApplePay] showPreparedPaymentSheet called\");\n\n if (!this.preparedPaymentRequest) {\n console.error(\"[ApplePay] No prepared PaymentRequest! Call preparePaymentRequest() first.\");\n return Promise.resolve({\n success: false,\n error: \"PaymentRequest not prepared. Call preparePaymentRequest() before showing the sheet.\",\n });\n }\n\n const paymentRequest = this.preparedPaymentRequest;\n\n // Return a promise that resolves when the user completes or cancels\n return new Promise((resolve) => {\n // Handle successful payment method creation\n paymentRequest.on(\"paymentmethod\", (evt: PaymentRequestPaymentMethodEvent) => {\n console.log(\"[ApplePay] paymentmethod event received\", {\n paymentMethodId: evt.paymentMethod.id,\n payerEmail: evt.payerEmail,\n payerName: evt.payerName,\n });\n\n // Clear the prepared request after use\n this.preparedPaymentRequest = null;\n\n resolve({\n success: true,\n paymentMethodId: evt.paymentMethod.id,\n paymentMethodEvent: evt,\n billingDetails: {\n email: evt.payerEmail ?? undefined,\n name: evt.payerName ?? undefined,\n address: evt.paymentMethod.billing_details?.address ?? undefined,\n },\n });\n });\n\n // Handle cancellation\n paymentRequest.on(\"cancel\", () => {\n console.log(\"[ApplePay] cancel event - user cancelled\");\n // Clear the prepared request after cancellation\n this.preparedPaymentRequest = null;\n resolve({ success: false, cancelled: true });\n });\n\n // Show the payment sheet immediately (no async operations before this!)\n console.log(\"[ApplePay] showing payment sheet\");\n paymentRequest.show();\n });\n }\n\n case ApplePayMockScenario.Success: {\n console.log(\"[MockApplePay] showPreparedPaymentSheet: success\");\n return new Promise((resolve) => {\n setTimeout(() => {\n resolve({\n success: true,\n paymentMethodId: \"pm_mock_apple_pay_test\",\n paymentMethodEvent: {\n complete: (status: string) => console.log(`[MockApplePay] complete: ${status}`),\n paymentMethod: {\n id: \"pm_mock_apple_pay_test\",\n object: \"payment_method\",\n type: \"card\",\n card: {\n brand: \"visa\",\n last4: \"4242\",\n exp_month: 12,\n exp_year: 2030,\n },\n billing_details: {\n email: \"test@example.com\",\n name: \"Test User\",\n },\n },\n payerEmail: \"test@example.com\",\n payerName: \"Test User\",\n } as unknown as PaymentRequestPaymentMethodEvent,\n billingDetails: {\n email: \"test@example.com\",\n name: \"Test User\",\n },\n });\n }, 500);\n });\n }\n\n case ApplePayMockScenario.Cancelled: {\n console.log(\"[MockApplePay] showPreparedPaymentSheet: cancelled\");\n return new Promise((resolve) => {\n setTimeout(() => {\n resolve({ success: false, cancelled: true });\n }, 500);\n });\n }\n }\n }\n\n /**\n * @deprecated Use preparePaymentRequest() + showPreparedPaymentSheet() instead.\n * This method creates a new PaymentRequest and shows it, which doesn't work\n * with browser security requirements (show() must be called synchronously).\n */\n async showPaymentSheet(config: ApplePayPaymentRequestConfig): Promise<ShowApplePaySheetResult> {\n console.warn(\n \"[ApplePay] showPaymentSheet is deprecated. Use preparePaymentRequest() + showPreparedPaymentSheet() instead.\",\n );\n\n // Try to prepare and show in one go (will likely fail due to user gesture requirement)\n const prepareResult = await this.preparePaymentRequest(config);\n if (!prepareResult.success) {\n return { success: false, error: prepareResult.error ?? \"Failed to prepare payment request\" };\n }\n\n return this.showPreparedPaymentSheet();\n }\n\n /**\n * Complete the payment flow in the Apple Pay sheet.\n * Call this after confirming the payment on the server.\n *\n * @param evt - The PaymentRequestPaymentMethodEvent from showPaymentSheet\n * @param status - 'success' or 'fail'\n */\n completePayment(evt: PaymentRequestPaymentMethodEvent, status: \"success\" | \"fail\"): void {\n console.log(\"[ApplePay] completePayment:\", status);\n evt.complete(status);\n }\n\n /**\n * Confirm PaymentIntent with the PaymentMethod.\n * This is called after showPaymentSheet to finalize the payment.\n *\n * @deprecated - Server-side confirmation is preferred. The backend should\n * call stripe.PaymentIntent.confirm() with the payment_method_id.\n */\n async confirmPaymentIntent(clientSecret: string, paymentMethodId: string): Promise<ConfirmResult> {\n switch (this.mockScenario) {\n case ApplePayMockScenario.None: {\n console.log(\"[ApplePay] confirmPaymentIntent called\", {\n clientSecret: `${clientSecret.slice(0, 20)}...`,\n paymentMethodId,\n });\n if (!this.stripe) {\n console.log(\"[ApplePay] confirmPaymentIntent: Stripe not initialized\");\n return { success: false, error: \"Stripe not initialized\" };\n }\n\n const { error } = await this.stripe.confirmCardPayment(clientSecret, {\n payment_method: paymentMethodId,\n });\n\n if (error) {\n console.log(\"[ApplePay] confirmPaymentIntent error:\", error);\n return { success: false, error: error.message ?? \"Payment failed\" };\n }\n\n console.log(\"[ApplePay] confirmPaymentIntent success\");\n return { success: true };\n }\n case ApplePayMockScenario.Success: {\n console.log(\"[MockApplePay] confirmPaymentIntent called\", { clientSecret, paymentMethodId });\n return { success: true };\n }\n case ApplePayMockScenario.Cancelled: {\n throw new Error(\"confirmPaymentIntent should not be called when scenario is Cancelled\");\n }\n }\n }\n}\n"],"mappings":";AA0CA,IAAY,wEAAL;AACL;AACA;AACA;;;;;;;;;;;;;;;;;;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kC;AACvF,UAAQ,IAAI,+BAA+B,OAAO;AAClD,MAAI,SAAS,OAAO;;;;;;;;;CAUtB,MAAM,qBAAqB,cAAsB,iBAAiD;AAChG,UAAQ,KAAK,cAAb;GACE,KAAK,qBAAqB,MAAM;AAC9B,YAAQ,IAAI,0CAA0C;KACpD,cAAc,GAAG,aAAa,MAAM,GAAG,GAAG,CAAC;KAC3C;KACD,CAAC;AACF,QAAI,CAAC,KAAK,QAAQ;AAChB,aAAQ,IAAI,0DAA0D;AACtE,YAAO;MAAE,SAAS;MAAO,OAAO;MAA0B;;IAG5D,MAAM,EAAE,UAAU,MAAM,KAAK,OAAO,mBAAmB,cAAc,EACnE,gBAAgB,iBACjB,CAAC;AAEF,QAAI,OAAO;AACT,aAAQ,IAAI,0CAA0C,MAAM;AAC5D,YAAO;MAAE,SAAS;MAAO,OAAO,MAAM,WAAW;MAAkB;;AAGrE,YAAQ,IAAI,0CAA0C;AACtD,WAAO,EAAE,SAAS,MAAM;;GAE1B,KAAK,qBAAqB;AACxB,YAAQ,IAAI,8CAA8C;KAAE;KAAc;KAAiB,CAAC;AAC5F,WAAO,EAAE,SAAS,MAAM;GAE1B,KAAK,qBAAqB,UACxB,OAAM,IAAI,MAAM,uEAAuE"}
|
package/dist/{stripe-apple-pay-adapter-DhpGclW9.d.mts → stripe-apple-pay-adapter-DcuGlQqQ.d.mts}
RENAMED
|
@@ -138,4 +138,4 @@ declare class StripeApplePayAdapter {
|
|
|
138
138
|
}
|
|
139
139
|
//#endregion
|
|
140
140
|
export { StripeApplePayAdapter as a, ShowApplePaySheetResult as i, ApplePayPaymentRequestConfig as n, ConfirmResult as r, ApplePayMockScenario as t };
|
|
141
|
-
//# sourceMappingURL=stripe-apple-pay-adapter-
|
|
141
|
+
//# sourceMappingURL=stripe-apple-pay-adapter-DcuGlQqQ.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stripe-apple-pay-adapter-
|
|
1
|
+
{"version":3,"file":"stripe-apple-pay-adapter-DcuGlQqQ.d.mts","names":[],"sources":["../src/payment-methods/stripe-apple-pay-adapter.ts"],"sourcesContent":[],"mappings":";;;;;IACqH,MAAA,CAAA,EAKxG,iBALwG;IAAA,eAAA,CAAA,EAAA,OAMxF,eANwF;;;AAMzE,UAI3B,4BAAA,CAJ2B;EAI3B,OAAA,EAAA,MAAA;EAQL,QAAA,EAAA,MAAA;EAqBA,KAAA,EAAA;IAEA,KAAA,EAAA,MAAA;IAsBC,MAAA,EAAA,MAAA;EAKgB,CAAA;EAgDH,iBAAA,CAAA,EAAA,MAAA,EAAA;EAiCY,oBAAA,CAAA,EAAA,MAAA,EAAA;;AA0EA,KA7M1B,uBAAA,GA6M0B;EAAR,OAAA,EAAA,IAAA;EA0GG,eAAA,EAAA,MAAA;EAAuC,kBAAA,EAnT9C,gCAmT8C;EAAR,cAAA,CAAA,EAAA;IAqBzC,KAAA,CAAA,EAAA,MAAA;IAY8D,IAAA,CAAA,EAAA,MAAA;IAAR,OAAA,CAAA,EAAA;MAAO,IAAA,CAAA,EAAA,MAAA,GAAA,IAAA;;;;;;;;;;;;;;;KAnUxE,aAAA;;;;;;aAEA,oBAAA;;;;;;;;;;;;;;;;;;;;;cAsBC,qBAAA;;;;6BAKgB;;;;;;;;;;;;oBAgDH;;;;;;;;;;gCAiCY,+BAA+B;;;;;;;;;;;;;;;;;;;8BA0EvC,QAAQ;;;;;;2BA0GL,+BAA+B,QAAQ;;;;;;;;uBAqBjD;;;;;;;;uEAYsD,QAAQ"}
|
package/dist/{stripe-google-pay-adapter-Bdox4xBq.d.mts → stripe-google-pay-adapter-BlQ2jVpE.d.mts}
RENAMED
|
@@ -52,4 +52,4 @@ declare class StripeGooglePayAdapter {
|
|
|
52
52
|
}
|
|
53
53
|
//#endregion
|
|
54
54
|
export { StripeGooglePayAdapter as a, ShowPaymentSheetResult as i, GooglePayMockScenario as n, PaymentRequestConfig as r, ConfirmResult as t };
|
|
55
|
-
//# sourceMappingURL=stripe-google-pay-adapter-
|
|
55
|
+
//# sourceMappingURL=stripe-google-pay-adapter-BlQ2jVpE.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stripe-google-pay-adapter-
|
|
1
|
+
{"version":3,"file":"stripe-google-pay-adapter-BlQ2jVpE.d.mts","names":[],"sources":["../src/payment-methods/stripe-google-pay-adapter.ts"],"sourcesContent":[],"mappings":";;;;;IAAqH,MAAA,CAAA,EAKxG,iBALwG;EAAA;;AAKvF,UAIb,oBAAA,CAJa;EAAA,OAAA,EAAA,MAAA;EAIb,QAAA,EAAA,MAAA;EAQL,KAAA,EAAA;IAUA,KAAA,EAAA,MAAa;IAEb,MAAA,EAAA,MAAA;EAMC,CAAA;EAKgB,gBAAA,EAAA,OAAA;EA0BE,iBAAA,EAAA,OAAA;;AAyCK,KA1FxB,sBAAA,GA0FwB;EAAR,OAAA,EAAA,IAAA;EAwDqD,eAAA,EAAA,MAAA;EAAR,UAAA,CAAA,EAAA,MAAA;EAAO,QAAA,EAAA,CAAA,MAAA,EAAA,SAAA,GAAA,MAAA,EAAA,GAAA,IAAA;;;;;;;;KAxIpE,aAAA;;;;;;aAEA,qBAAA;;;;;cAMC,sBAAA;;;;6BAKgB;;+BA0BE;oBAmBL;sBAsBE,QAAQ;mEAwDqC,QAAQ"}
|
package/dist/{stripe-google-pay-adapter-3cx0KNjK.mjs → stripe-google-pay-adapter-CIkgjhw8.mjs}
RENAMED
|
@@ -165,4 +165,4 @@ var StripeGooglePayAdapter = class {
|
|
|
165
165
|
|
|
166
166
|
//#endregion
|
|
167
167
|
export { StripeGooglePayAdapter as n, GooglePayMockScenario as t };
|
|
168
|
-
//# sourceMappingURL=stripe-google-pay-adapter-
|
|
168
|
+
//# sourceMappingURL=stripe-google-pay-adapter-CIkgjhw8.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stripe-google-pay-adapter-3cx0KNjK.mjs","names":[],"sources":["../src/payment-methods/stripe-google-pay-adapter.ts"],"sourcesContent":["import type { PaymentRequest, PaymentRequestPaymentMethodEvent, Stripe, StripeConstructor } from \"@stripe/stripe-js\";\n\n// Stripe.js must be loaded via script tag for PCI compliance\ndeclare global {\n interface Window {\n Stripe?: StripeConstructor;\n }\n}\n\nexport interface PaymentRequestConfig {\n country: string;\n currency: string;\n total: { label: string; amount: number };\n requestPayerName: boolean;\n requestPayerEmail: boolean;\n}\n\nexport type ShowPaymentSheetResult =\n | {\n success: true;\n paymentMethodId: string;\n payerEmail?: string;\n complete: (status: \"success\" | \"fail\") => void;\n }\n | { success: false; cancelled: true }\n | { success: false; error: string };\n\nexport type ConfirmResult = { success: true } | { success: false; error: string };\n\nexport enum GooglePayMockScenario {\n None = \"none\",\n Success = \"success\",\n Cancelled = \"cancelled\",\n}\n\nexport class StripeGooglePayAdapter {\n private stripe: Stripe | null = null;\n private paymentRequest: PaymentRequest | null = null;\n private mockScenario: GooglePayMockScenario;\n\n constructor(mockScenario?: GooglePayMockScenario) {\n this.mockScenario = mockScenario ?? GooglePayMockScenario.None;\n }\n\n initialize(publishableKey: string): boolean {\n switch (this.mockScenario) {\n case GooglePayMockScenario.None: {\n console.log(\"[GooglePay] initialize called\");\n if (!window.Stripe) {\n console.log(\"[GooglePay] Stripe.js not loaded\");\n return false;\n }\n this.stripe = window.Stripe(publishableKey);\n const success = this.stripe !== null;\n console.log(\"[GooglePay] initialize result:\", success);\n return success;\n }\n case GooglePayMockScenario.Success:\n case GooglePayMockScenario.Cancelled: {\n console.log(\"[MockGooglePay] initialize called\");\n console.log(\"[MockGooglePay] initialize result:\", true);\n return true;\n }\n }\n }\n\n createPaymentRequest(config: PaymentRequestConfig): void {\n switch (this.mockScenario) {\n case GooglePayMockScenario.None: {\n console.log(\"[GooglePay] createPaymentRequest called\", config);\n if (!this.stripe) {\n throw new Error(\"Stripe not initialized\");\n }\n this.paymentRequest = this.stripe.paymentRequest(config);\n console.log(\"[GooglePay] paymentRequest created\");\n return;\n }\n case GooglePayMockScenario.Success:\n case GooglePayMockScenario.Cancelled: {\n console.log(\"[MockGooglePay] createPaymentRequest called\", config);\n return;\n }\n }\n }\n\n async canMakePayment(): Promise<boolean> {\n switch (this.mockScenario) {\n case GooglePayMockScenario.None: {\n console.log(\"[GooglePay] canMakePayment called\");\n if (!this.paymentRequest) {\n console.log(\"[GooglePay] canMakePayment: no paymentRequest\");\n return false;\n }\n const result = await this.paymentRequest.canMakePayment();\n const isAvailable = result?.googlePay ?? false;\n console.log(\"[GooglePay] canMakePayment result:\", { result, isAvailable });\n return isAvailable;\n }\n case GooglePayMockScenario.Success:\n case GooglePayMockScenario.Cancelled: {\n console.log(\"[MockGooglePay] canMakePayment called\");\n console.log(\"[MockGooglePay] canMakePayment result:\", { result: { googlePay: true }, isAvailable: true });\n return true;\n }\n }\n }\n\n async showPaymentSheet(): Promise<ShowPaymentSheetResult> {\n switch (this.mockScenario) {\n case GooglePayMockScenario.None: {\n console.log(\"[GooglePay] showPaymentSheet called\");\n if (!this.paymentRequest) {\n console.log(\"[GooglePay] showPaymentSheet: no paymentRequest\");\n return { success: false, error: \"Payment request not created\" };\n }\n\n return new Promise((resolve) => {\n // biome-ignore lint/style/noNonNullAssertion: checked above\n this.paymentRequest!.on(\"paymentmethod\", (event: PaymentRequestPaymentMethodEvent) => {\n console.log(\"[GooglePay] showPaymentSheet: paymentmethod event\", {\n paymentMethodId: event.paymentMethod.id,\n payerEmail: event.payerEmail,\n });\n resolve({\n success: true,\n paymentMethodId: event.paymentMethod.id,\n payerEmail: event.payerEmail ?? undefined,\n complete: (status) => {\n console.log(\"[GooglePay] complete called:\", status);\n event.complete(status);\n },\n });\n });\n\n // biome-ignore lint/style/noNonNullAssertion: checked above\n this.paymentRequest!.on(\"cancel\", () => {\n console.log(\"[GooglePay] showPaymentSheet: cancelled by user\");\n resolve({ success: false, cancelled: true });\n });\n\n console.log(\"[GooglePay] showing payment sheet...\");\n // biome-ignore lint/style/noNonNullAssertion: checked above\n this.paymentRequest!.show();\n });\n }\n case GooglePayMockScenario.Success: {\n console.log(\"[MockGooglePay] showPaymentSheet: success\");\n await new Promise((resolve) => setTimeout(resolve, 500));\n return {\n success: true,\n paymentMethodId: \"pm_mock_123456789\",\n payerEmail: \"mock@example.com\",\n complete: (status) => console.log(`[MockGooglePay] complete: ${status}`),\n };\n }\n case GooglePayMockScenario.Cancelled: {\n console.log(\"[MockGooglePay] showPaymentSheet: cancelled\");\n await new Promise((resolve) => setTimeout(resolve, 500));\n return { success: false, cancelled: true };\n }\n }\n }\n\n async confirmCardSetup(clientSecret: string, paymentMethodId: string): Promise<ConfirmResult> {\n switch (this.mockScenario) {\n case GooglePayMockScenario.None: {\n console.log(\"[GooglePay] confirmCardSetup called\", {\n clientSecret: `${clientSecret.slice(0, 20)}...`,\n paymentMethodId,\n });\n if (!this.stripe) {\n console.log(\"[GooglePay] confirmCardSetup: Stripe not initialized\");\n return { success: false, error: \"Stripe not initialized\" };\n }\n\n const { error } = await this.stripe.confirmCardSetup(clientSecret, {\n payment_method: paymentMethodId,\n });\n\n if (error) {\n console.log(\"[GooglePay] confirmCardSetup error:\", error);\n return { success: false, error: error.message ?? \"Card setup failed\" };\n }\n\n console.log(\"[GooglePay] confirmCardSetup success\");\n return { success: true };\n }\n case GooglePayMockScenario.Success: {\n console.log(\"[MockGooglePay] confirmCardSetup called\", { clientSecret, paymentMethodId });\n return { success: true };\n }\n case GooglePayMockScenario.Cancelled: {\n throw new Error(\"confirmCardSetup should not be called when scenario is Cancelled\");\n }\n }\n }\n}\n"],"mappings":";AA6BA,IAAY,0EAAL;AACL;AACA;AACA;;;AAGF,IAAa,yBAAb,MAAoC;CAClC,AAAQ,SAAwB;CAChC,AAAQ,iBAAwC;CAChD,AAAQ;CAER,YAAY,cAAsC;AAChD,OAAK,eAAe,gBAAgB,sBAAsB;;CAG5D,WAAW,gBAAiC;AAC1C,UAAQ,KAAK,cAAb;GACE,KAAK,sBAAsB,MAAM;AAC/B,YAAQ,IAAI,gCAAgC;AAC5C,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UAAU,MAAM,KAAK,OAAO,iBAAiB,cAAc,EACjE,gBAAgB,iBACjB,CAAC;AAEF,QAAI,OAAO;AACT,aAAQ,IAAI,uCAAuC,MAAM;AACzD,YAAO;MAAE,SAAS;MAAO,OAAO,MAAM,WAAW;MAAqB;;AAGxE,YAAQ,IAAI,uCAAuC;AACnD,WAAO,EAAE,SAAS,MAAM;;GAE1B,KAAK,sBAAsB;AACzB,YAAQ,IAAI,2CAA2C;KAAE;KAAc;KAAiB,CAAC;AACzF,WAAO,EAAE,SAAS,MAAM;GAE1B,KAAK,sBAAsB,UACzB,OAAM,IAAI,MAAM,mEAAmE"}
|
|
1
|
+
{"version":3,"file":"stripe-google-pay-adapter-CIkgjhw8.mjs","names":[],"sources":["../src/payment-methods/stripe-google-pay-adapter.ts"],"sourcesContent":["import type { PaymentRequest, PaymentRequestPaymentMethodEvent, Stripe, StripeConstructor } from \"@stripe/stripe-js\";\n\n// Stripe.js must be loaded via script tag for PCI compliance\ndeclare global {\n interface Window {\n Stripe?: StripeConstructor;\n }\n}\n\nexport interface PaymentRequestConfig {\n country: string;\n currency: string;\n total: { label: string; amount: number };\n requestPayerName: boolean;\n requestPayerEmail: boolean;\n}\n\nexport type ShowPaymentSheetResult =\n | {\n success: true;\n paymentMethodId: string;\n payerEmail?: string;\n complete: (status: \"success\" | \"fail\") => void;\n }\n | { success: false; cancelled: true }\n | { success: false; error: string };\n\nexport type ConfirmResult = { success: true } | { success: false; error: string };\n\nexport enum GooglePayMockScenario {\n None = \"none\",\n Success = \"success\",\n Cancelled = \"cancelled\",\n}\n\nexport class StripeGooglePayAdapter {\n private stripe: Stripe | null = null;\n private paymentRequest: PaymentRequest | null = null;\n private mockScenario: GooglePayMockScenario;\n\n constructor(mockScenario?: GooglePayMockScenario) {\n this.mockScenario = mockScenario ?? GooglePayMockScenario.None;\n }\n\n initialize(publishableKey: string): boolean {\n switch (this.mockScenario) {\n case GooglePayMockScenario.None: {\n console.log(\"[GooglePay] initialize called\");\n if (!window.Stripe) {\n console.log(\"[GooglePay] Stripe.js not loaded\");\n return false;\n }\n this.stripe = window.Stripe(publishableKey);\n const success = this.stripe !== null;\n console.log(\"[GooglePay] initialize result:\", success);\n return success;\n }\n case GooglePayMockScenario.Success:\n case GooglePayMockScenario.Cancelled: {\n console.log(\"[MockGooglePay] initialize called\");\n console.log(\"[MockGooglePay] initialize result:\", true);\n return true;\n }\n }\n }\n\n createPaymentRequest(config: PaymentRequestConfig): void {\n switch (this.mockScenario) {\n case GooglePayMockScenario.None: {\n console.log(\"[GooglePay] createPaymentRequest called\", config);\n if (!this.stripe) {\n throw new Error(\"Stripe not initialized\");\n }\n this.paymentRequest = this.stripe.paymentRequest(config);\n console.log(\"[GooglePay] paymentRequest created\");\n return;\n }\n case GooglePayMockScenario.Success:\n case GooglePayMockScenario.Cancelled: {\n console.log(\"[MockGooglePay] createPaymentRequest called\", config);\n return;\n }\n }\n }\n\n async canMakePayment(): Promise<boolean> {\n switch (this.mockScenario) {\n case GooglePayMockScenario.None: {\n console.log(\"[GooglePay] canMakePayment called\");\n if (!this.paymentRequest) {\n console.log(\"[GooglePay] canMakePayment: no paymentRequest\");\n return false;\n }\n const result = await this.paymentRequest.canMakePayment();\n const isAvailable = result?.googlePay ?? false;\n console.log(\"[GooglePay] canMakePayment result:\", { result, isAvailable });\n return isAvailable;\n }\n case GooglePayMockScenario.Success:\n case GooglePayMockScenario.Cancelled: {\n console.log(\"[MockGooglePay] canMakePayment called\");\n console.log(\"[MockGooglePay] canMakePayment result:\", { result: { googlePay: true }, isAvailable: true });\n return true;\n }\n }\n }\n\n async showPaymentSheet(): Promise<ShowPaymentSheetResult> {\n switch (this.mockScenario) {\n case GooglePayMockScenario.None: {\n console.log(\"[GooglePay] showPaymentSheet called\");\n if (!this.paymentRequest) {\n console.log(\"[GooglePay] showPaymentSheet: no paymentRequest\");\n return { success: false, error: \"Payment request not created\" };\n }\n\n return new Promise((resolve) => {\n // biome-ignore lint/style/noNonNullAssertion: checked above\n this.paymentRequest!.on(\"paymentmethod\", (event: PaymentRequestPaymentMethodEvent) => {\n console.log(\"[GooglePay] showPaymentSheet: paymentmethod event\", {\n paymentMethodId: event.paymentMethod.id,\n payerEmail: event.payerEmail,\n });\n resolve({\n success: true,\n paymentMethodId: event.paymentMethod.id,\n payerEmail: event.payerEmail ?? undefined,\n complete: (status) => {\n console.log(\"[GooglePay] complete called:\", status);\n event.complete(status);\n },\n });\n });\n\n // biome-ignore lint/style/noNonNullAssertion: checked above\n this.paymentRequest!.on(\"cancel\", () => {\n console.log(\"[GooglePay] showPaymentSheet: cancelled by user\");\n resolve({ success: false, cancelled: true });\n });\n\n console.log(\"[GooglePay] showing payment sheet...\");\n // biome-ignore lint/style/noNonNullAssertion: checked above\n this.paymentRequest!.show();\n });\n }\n case GooglePayMockScenario.Success: {\n console.log(\"[MockGooglePay] showPaymentSheet: success\");\n await new Promise((resolve) => setTimeout(resolve, 500));\n return {\n success: true,\n paymentMethodId: \"pm_mock_123456789\",\n payerEmail: \"mock@example.com\",\n complete: (status) => console.log(`[MockGooglePay] complete: ${status}`),\n };\n }\n case GooglePayMockScenario.Cancelled: {\n console.log(\"[MockGooglePay] showPaymentSheet: cancelled\");\n await new Promise((resolve) => setTimeout(resolve, 500));\n return { success: false, cancelled: true };\n }\n }\n }\n\n async confirmCardSetup(clientSecret: string, paymentMethodId: string): Promise<ConfirmResult> {\n switch (this.mockScenario) {\n case GooglePayMockScenario.None: {\n console.log(\"[GooglePay] confirmCardSetup called\", {\n clientSecret: `${clientSecret.slice(0, 20)}...`,\n paymentMethodId,\n });\n if (!this.stripe) {\n console.log(\"[GooglePay] confirmCardSetup: Stripe not initialized\");\n return { success: false, error: \"Stripe not initialized\" };\n }\n\n const { error } = await this.stripe.confirmCardSetup(clientSecret, {\n payment_method: paymentMethodId,\n });\n\n if (error) {\n console.log(\"[GooglePay] confirmCardSetup error:\", error);\n return { success: false, error: error.message ?? \"Card setup failed\" };\n }\n\n console.log(\"[GooglePay] confirmCardSetup success\");\n return { success: true };\n }\n case GooglePayMockScenario.Success: {\n console.log(\"[MockGooglePay] confirmCardSetup called\", { clientSecret, paymentMethodId });\n return { success: true };\n }\n case GooglePayMockScenario.Cancelled: {\n throw new Error(\"confirmCardSetup should not be called when scenario is Cancelled\");\n }\n }\n }\n}\n"],"mappings":";AA6BA,IAAY,0EAAL;AACL;AACA;AACA;;;AAGF,IAAa,yBAAb,MAAoC;CAClC,AAAQ,SAAwB;CAChC,AAAQ,iBAAwC;CAChD,AAAQ;CAER,YAAY,cAAsC;AAChD,OAAK,eAAe,gBAAgB,sBAAsB;;CAG5D,WAAW,gBAAiC;AAC1C,UAAQ,KAAK,cAAb;GACE,KAAK,sBAAsB,MAAM;AAC/B,YAAQ,IAAI,gCAAgC;AAC5C,QAAI,CAAC,OAAO,QAAQ;AAClB,aAAQ,IAAI,mCAAmC;AAC/C,YAAO;;AAET,SAAK,SAAS,OAAO,OAAO,eAAe;IAC3C,MAAM,UAAU,KAAK,WAAW;AAChC,YAAQ,IAAI,kCAAkC,QAAQ;AACtD,WAAO;;GAET,KAAK,sBAAsB;GAC3B,KAAK,sBAAsB;AACzB,YAAQ,IAAI,oCAAoC;AAChD,YAAQ,IAAI,sCAAsC,KAAK;AACvD,WAAO;;;CAKb,qBAAqB,QAAoC;AACvD,UAAQ,KAAK,cAAb;GACE,KAAK,sBAAsB;AACzB,YAAQ,IAAI,2CAA2C,OAAO;AAC9D,QAAI,CAAC,KAAK,OACR,OAAM,IAAI,MAAM,yBAAyB;AAE3C,SAAK,iBAAiB,KAAK,OAAO,eAAe,OAAO;AACxD,YAAQ,IAAI,qCAAqC;AACjD;GAEF,KAAK,sBAAsB;GAC3B,KAAK,sBAAsB;AACzB,YAAQ,IAAI,+CAA+C,OAAO;AAClE;;;CAKN,MAAM,iBAAmC;AACvC,UAAQ,KAAK,cAAb;GACE,KAAK,sBAAsB,MAAM;AAC/B,YAAQ,IAAI,oCAAoC;AAChD,QAAI,CAAC,KAAK,gBAA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AQ,IAAI,6BAA6B,SAAS;KACzE;GAEH,KAAK,sBAAsB;AACzB,YAAQ,IAAI,8CAA8C;AAC1D,UAAM,IAAI,SAAS,YAAY,WAAW,SAAS,IAAI,CAAC;AACxD,WAAO;KAAE,SAAS;KAAO,WAAW;KAAM;;;CAKhD,MAAM,iBAAiB,cAAsB,iBAAiD;AAC5F,UAAQ,KAAK,cAAb;GACE,KAAK,sBAAsB,MAAM;AAC/B,YAAQ,IAAI,uCAAuC;KACjD,cAAc,GAAG,aAAa,MAAM,GAAG,GAAG,CAAC;KAC3C;KACD,CAAC;AACF,QAAI,CAAC,KAAK,QAAQ;AAChB,aAAQ,IAAI,uDAAuD;AACnE,YAAO;MAAE,SAAS;MAAO,OAAO;MAA0B;;IAG5D,MAAM,EAAE,UAAU,MAAM,KAAK,OAAO,iBAAiB,cAAc,EACjE,gBAAgB,iBACjB,CAAC;AAEF,QAAI,OAAO;AACT,aAAQ,IAAI,uCAAuC,MAAM;AACzD,YAAO;MAAE,SAAS;MAAO,OAAO,MAAM,WAAW;MAAqB;;AAGxE,YAAQ,IAAI,uCAAuC;AACnD,WAAO,EAAE,SAAS,MAAM;;GAE1B,KAAK,sBAAsB;AACzB,YAAQ,IAAI,2CAA2C;KAAE;KAAc;KAAiB,CAAC;AACzF,WAAO,EAAE,SAAS,MAAM;GAE1B,KAAK,sBAAsB,UACzB,OAAM,IAAI,MAAM,mEAAmE"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as CardErrorCode } from "./connect-card-
|
|
2
|
-
import { t as TunnelXIFrameConnection } from "./connect-tunnel-x-
|
|
1
|
+
import { t as CardErrorCode } from "./connect-card-Cra_F1cC.mjs";
|
|
2
|
+
import { t as TunnelXIFrameConnection } from "./connect-tunnel-x-Wh-JG1O5.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/analytics/checkout-timing.d.ts
|
|
5
5
|
|
|
@@ -147,4 +147,4 @@ type PaymentMethod<TExternalFuncs = unknown, TName = string> = (paymentKitStates
|
|
|
147
147
|
type ExternalFuncsMapByPm<T extends readonly PaymentMethod<unknown>[]> = { [K in T[number] as ReturnType<K>["name"]]: ReturnType<K>["externalFuncs"] };
|
|
148
148
|
//#endregion
|
|
149
149
|
export { PaymentKitFields as n, PaymentMethod as r, PaymentKit as t };
|
|
150
|
-
//# sourceMappingURL=types-
|
|
150
|
+
//# sourceMappingURL=types-CQ8xbgoh.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types-
|
|
1
|
+
{"version":3,"file":"types-CQ8xbgoh.d.mts","names":[],"sources":["../src/analytics/checkout-timing.ts","../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AAmBA;;;;AC0CC;AAoBD;AAEA;AAIA;;;;;;AAQY,cD5EC,qBAAA,CC4ES;EAAuB,eAAA,gBAAA;EAG3B,QAAA,SAAA;EASS,QAAA,iBAAA;EAArB,QAAA,SAAA;EAC4B,QAAA,iBAAA;EAAxB,WAAA,CAAA,iBAAA,EAAA,MAAA,EAAA,SAAA,EAAA,MAAA;EAAuB;AAE/B;;;;EAKgB,cAAA,CAAA,CAAA,EAAA,IAAA;EAAR;;;;AAOV;EAKqB,eAAA,CAAA,CAAA,EAAA,IAAA;EACJ;;;EAaL,WAAA,CAAA,CAAA,EAAA,IAAgB;EAEf;;;;;EAUiC,YAAA,CAAA,iBAAA,EAAA,MAAA,CAAA,EAAA,IAAA;EAElC;AAEZ;;;;;;EAMY,SAAA,CAAA,iBAAoB,EAAA,MAAA,GAAA,IAAA,EAAA,SAAA,EAAA,MAAA,GAAA,IAAA,EAAA,YAAA,EAAA,MAAA,GAAA,IAAA,CAAA,EAAA,IAAA;EAAoB;;;EAC/B,QAAA,YAAA;;;;;AAnFrB,KAlBK,cAAA,GAkBqB,eAAA,GAAA,gBAAA,GAAA,kBAAA,GAAA,mBAAA,GAAA,wBAAA,GAAA,wBAAA,GAAA,wBAAA,GAAA,eAAA,GAAA,gBAAA,GAAA,kBAAA,G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J,OAsCI,CAtCI,gBAsCJ,CAAA;EAAkB,aAAA,EArCf,CAqCe;EAAc,OAAA,CAAA,EAAA,OAAA;EAElC,OAAA,EAAA,CAAA,KAAA,EArCO,gBAqCsB,EAAA,GAAA,IAAA;EAE7B,SAAA,EAAA,CAAA,IAAa,EAAA;IAAgE,CAAA,GAAA,EAAA,MAAA,CAAA,EAAA,OAAA;EACjF,CAAA,EAAA,GAAA,IAAA;CACS,EAAA,GAAA,IAAA;AACA,KAtCL,gBAAA,GAsCK;EAAc,OAAA,EAAA,MAAA;EAGnB,UAAA,EAAA,MAAA;EAAwC,WAAA,EAAA,MAAA;EAC5C,WAAA,EAAA,MAAA;EAAwB,iBAAA,EArCX,uBAqCW;EAAX,aAAA,EApCJ,qBAoCI;EAAmC;EAAX,iBAAA,EAAA,MAAA;EAAU;;;;;;;wBA1B/B;;KAGZ,gBAAA;;aAEC;aACA;aACA;;;;;;;;cAQC,kBAAkB;KAEpB,gBAAA,aAA6B;KAE7B,6EAA6E;QACjF;iBACS;iBACA;;KAGL,wCAAwC,oCAC5C,aAAa,WAAW,aAAa,WAAW"}
|
|
@@ -154,4 +154,4 @@ function createVgsCardFields(form, mountPoints, css, onFocusChangeCallbacks, pla
|
|
|
154
154
|
|
|
155
155
|
//#endregion
|
|
156
156
|
export { initVgsCollect as n, loadVgsCollectScript as r, createVgsCardFields as t };
|
|
157
|
-
//# sourceMappingURL=vgs-collect-loader-
|
|
157
|
+
//# sourceMappingURL=vgs-collect-loader-l5_Pnmhz.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vgs-collect-loader-BZj36d8r.mjs","names":["loadPromise: Promise<void> | null","observers: MutationObserver[]","containers: Element[]","fieldMap: [VGSCollectField, string][]"],"sources":["../src/payment-methods/vgs-collect-loader.ts"],"sourcesContent":["const VGS_COLLECT_CDN = \"https://js.verygoodvault.com/vgs-collect/3.2.1/vgs-collect.js\";\n\nlet loadPromise: Promise<void> | null = null;\n\n/**\n * Loads VGS Collect JS from CDN. Idempotent — subsequent calls return the same promise.\n */\nexport function loadVgsCollectScript(): Promise<void> {\n if (loadPromise) {\n console.log(\"[PaymentKit] VGS Collect CDN load already in progress — reusing promise\");\n return loadPromise;\n }\n\n loadPromise = new Promise<void>((resolve, reject) => {\n if (typeof window !== \"undefined\" && window.VGSCollect) {\n console.log(\"[PaymentKit] VGS Collect JS already available on window\");\n resolve();\n return;\n }\n\n console.log(`[PaymentKit] Loading VGS Collect JS from CDN: ${VGS_COLLECT_CDN}`);\n const script = document.createElement(\"script\");\n script.src = VGS_COLLECT_CDN;\n script.async = true;\n script.onload = () => {\n console.log(\"[PaymentKit] VGS Collect JS loaded successfully from CDN\");\n resolve();\n };\n script.onerror = () => {\n console.error(`[PaymentKit] Failed to load VGS Collect JS from CDN: ${VGS_COLLECT_CDN}`);\n loadPromise = null;\n reject(new Error(\"Failed to load VGS Collect JS\"));\n };\n document.head.appendChild(script);\n });\n\n return loadPromise;\n}\n\n/**\n * Initializes a VGS Collect form instance.\n */\nexport function initVgsCollect(vaultId: string, environment: string): VGSCollectForm {\n if (!window.VGSCollect) {\n throw new Error(\"VGS Collect JS not loaded. Call loadVgsCollectScript() first.\");\n }\n return window.VGSCollect.create(vaultId, environment, () => {});\n}\n\n/**\n * Creates and mounts VGS Collect card fields using CMP-specific field methods.\n *\n * Uses cardNumberField(), cardExpirationDateField(), cardCVCField() which are\n * required for the CMP createCard() flow. After mounting, call form.createCard()\n * to create a card in the VGS vault, which returns aliases for PAN and CVC.\n *\n * @param form - VGS Collect form instance\n * @param mountPoints - CSS selectors for PAN, expiry, and CVC containers\n * @param css - Optional CSS to apply to VGS Collect iframe fields\n */\nexport function createVgsCardFields(\n form: VGSCollectForm,\n mountPoints: { pan: string; exp: string; cvc: string },\n css?: Record<string, string>,\n onFocusChangeCallbacks?: Partial<Record<string, (isFocused: boolean) => void>>,\n placeholders?: Partial<Record<string, string>>,\n): () => void {\n // Read container padding so the VGS input content matches the merchant's\n // visual intent. The iframe uses absolute positioning (inset: 0) to fill\n // the full container, so the input needs its own padding for alignment.\n const sampleContainer = document.querySelector(mountPoints.pan) as HTMLElement | null;\n const containerPadding = sampleContainer ? getComputedStyle(sampleContainer).padding : undefined;\n\n const baseCss = css ?? {\n \"font-size\": \"1rem\",\n color: \"#18181b\",\n \"font-family\": \"ui-sans-serif, system-ui, sans-serif\",\n };\n\n const fieldCss = {\n ...baseCss,\n height: \"100%\",\n \"box-sizing\": \"border-box\",\n ...(containerPadding && containerPadding !== \"0px\" ? { padding: containerPadding } : {}),\n };\n\n // Remove stale iframes from previous VGS form mounts to prevent overlap.\n // VGS's form.unmount() does not remove iframes from the DOM.\n // IMPORTANT: This must run BEFORE VGS field methods below, because VGS may\n // insert new iframes synchronously — removing after would destroy fresh iframes.\n for (const selector of [mountPoints.pan, mountPoints.exp, mountPoints.cvc]) {\n const container = document.querySelector(selector);\n if (!container) continue;\n const staleIframes = container.querySelectorAll(\"iframe\");\n for (const iframe of staleIframes) {\n iframe.remove();\n }\n }\n\n const panField = form.cardNumberField(mountPoints.pan, {\n placeholder: placeholders?.card_pan ?? \"Card number\",\n validations: [\"required\", \"validCardNumber\"],\n css: fieldCss,\n });\n\n const expField = form.field(mountPoints.exp, {\n type: \"card-expiration-date\",\n name: \"exp-date\",\n placeholder: placeholders?.card_exp ?? \"MM / YY\",\n yearLength: 2,\n serializers: [{ name: \"separate\", options: { monthName: \"month\", yearName: \"year\" } }],\n validations: [\"required\", \"validCardExpirationDate\"],\n css: fieldCss,\n });\n\n const cvcField = form.cardCVCField(mountPoints.cvc, {\n placeholder: placeholders?.card_cvc ?? \"123\",\n validations: [\"required\", \"validCardSecurityCode\"],\n css: fieldCss,\n });\n\n // Track observers for cleanup\n const observers: MutationObserver[] = [];\n const containers: Element[] = [];\n\n // VGS Collect doesn't set width/height on its iframes, so they may not\n // fill the merchant's container. Force them to stretch like direct-mode iframes.\n // Iframes may be inserted asynchronously, so use MutationObserver as a fallback.\n for (const selector of [mountPoints.pan, mountPoints.exp, mountPoints.cvc]) {\n const container = document.querySelector(selector);\n if (!container) continue;\n containers.push(container);\n\n const styleIframe = (iframe: HTMLIFrameElement) => {\n // Use absolute positioning so the iframe covers the full container\n // including any padding the merchant's CSS applies.\n const containerEl = container as HTMLElement;\n if (getComputedStyle(containerEl).position === \"static\") {\n containerEl.style.position = \"relative\";\n }\n iframe.style.position = \"absolute\";\n iframe.style.inset = \"0\";\n iframe.style.width = \"100%\";\n iframe.style.height = \"100%\";\n iframe.style.border = \"none\";\n };\n\n // Always set up a MutationObserver to catch asynchronously inserted iframes.\n // VGS inserts iframes after field creation, so we need the observer even if\n // no iframe exists yet.\n const observer = new MutationObserver(() => {\n const iframe = container.querySelector(\"iframe\") as HTMLIFrameElement | null;\n if (iframe && iframe.style.position !== \"absolute\") {\n styleIframe(iframe);\n }\n });\n observer.observe(container, { childList: true, subtree: true });\n observers.push(observer);\n\n // Style any iframe VGS may have inserted synchronously during field creation.\n // The MutationObserver only fires on future mutations, so this handles the\n // case where VGS inserts the iframe before the observer is attached.\n const existing = container.querySelector(\"iframe\") as HTMLIFrameElement | null;\n if (existing && existing.style.position !== \"absolute\") {\n styleIframe(existing);\n }\n }\n\n if (onFocusChangeCallbacks) {\n const fieldMap: [VGSCollectField, string][] = [\n [panField, \"card_pan\"],\n [expField, \"card_exp\"],\n [cvcField, \"card_cvc\"],\n ];\n for (const [field, key] of fieldMap) {\n const cb = onFocusChangeCallbacks[key];\n if (cb) {\n field.on(\"focus\", () => cb(true));\n field.on(\"blur\", () => cb(false));\n }\n }\n }\n\n // Return cleanup function to disconnect observers and remove iframes\n return () => {\n for (const observer of observers) {\n observer.disconnect();\n }\n for (const container of containers) {\n const iframes = container.querySelectorAll(\"iframe\");\n for (const iframe of iframes) {\n iframe.remove();\n }\n }\n };\n}\n"],"mappings":";AAAA,MAAM,kBAAkB;AAExB,IAAIA,cAAoC;;;;AAKxC,SAAgB,uBAAsC;AACpD,KAAI,aAAa;AACf,UAAQ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AwC;GAC5C,CAAC,UAAU,WAAW;GACtB,CAAC,UAAU,WAAW;GACtB,CAAC,UAAU,WAAW;GACvB;AACD,OAAK,MAAM,CAAC,OAAO,QAAQ,UAAU;GACnC,MAAM,KAAK,uBAAuB;AAClC,OAAI,IAAI;AACN,UAAM,GAAG,eAAe,GAAG,KAAK,CAAC;AACjC,UAAM,GAAG,cAAc,GAAG,MAAM,CAAC;;;;AAMvC,cAAa;AACX,OAAK,MAAM,YAAY,UACrB,UAAS,YAAY;AAEvB,OAAK,MAAM,aAAa,YAAY;GAClC,MAAM,UAAU,UAAU,iBAAiB,SAAS;AACpD,QAAK,MAAM,UAAU,QACnB,QAAO,QAAQ"}
|
|
1
|
+
{"version":3,"file":"vgs-collect-loader-l5_Pnmhz.mjs","names":["loadPromise: Promise<void> | null","observers: MutationObserver[]","containers: Element[]","fieldMap: [VGSCollectField, string][]"],"sources":["../src/payment-methods/vgs-collect-loader.ts"],"sourcesContent":["const VGS_COLLECT_CDN = \"https://js.verygoodvault.com/vgs-collect/3.2.1/vgs-collect.js\";\n\nlet loadPromise: Promise<void> | null = null;\n\n/**\n * Loads VGS Collect JS from CDN. Idempotent — subsequent calls return the same promise.\n */\nexport function loadVgsCollectScript(): Promise<void> {\n if (loadPromise) {\n console.log(\"[PaymentKit] VGS Collect CDN load already in progress — reusing promise\");\n return loadPromise;\n }\n\n loadPromise = new Promise<void>((resolve, reject) => {\n if (typeof window !== \"undefined\" && window.VGSCollect) {\n console.log(\"[PaymentKit] VGS Collect JS already available on window\");\n resolve();\n return;\n }\n\n console.log(`[PaymentKit] Loading VGS Collect JS from CDN: ${VGS_COLLECT_CDN}`);\n const script = document.createElement(\"script\");\n script.src = VGS_COLLECT_CDN;\n script.async = true;\n script.onload = () => {\n console.log(\"[PaymentKit] VGS Collect JS loaded successfully from CDN\");\n resolve();\n };\n script.onerror = () => {\n console.error(`[PaymentKit] Failed to load VGS Collect JS from CDN: ${VGS_COLLECT_CDN}`);\n loadPromise = null;\n reject(new Error(\"Failed to load VGS Collect JS\"));\n };\n document.head.appendChild(script);\n });\n\n return loadPromise;\n}\n\n/**\n * Initializes a VGS Collect form instance.\n */\nexport function initVgsCollect(vaultId: string, environment: string): VGSCollectForm {\n if (!window.VGSCollect) {\n throw new Error(\"VGS Collect JS not loaded. Call loadVgsCollectScript() first.\");\n }\n return window.VGSCollect.create(vaultId, environment, () => {});\n}\n\n/**\n * Creates and mounts VGS Collect card fields using CMP-specific field methods.\n *\n * Uses cardNumberField(), cardExpirationDateField(), cardCVCField() which are\n * required for the CMP createCard() flow. After mounting, call form.createCard()\n * to create a card in the VGS vault, which returns aliases for PAN and CVC.\n *\n * @param form - VGS Collect form instance\n * @param mountPoints - CSS selectors for PAN, expiry, and CVC containers\n * @param css - Optional CSS to apply to VGS Collect iframe fields\n */\nexport function createVgsCardFields(\n form: VGSCollectForm,\n mountPoints: { pan: string; exp: string; cvc: string },\n css?: Record<string, string>,\n onFocusChangeCallbacks?: Partial<Record<string, (isFocused: boolean) => void>>,\n placeholders?: Partial<Record<string, string>>,\n): () => void {\n // Read container padding so the VGS input content matches the merchant's\n // visual intent. The iframe uses absolute positioning (inset: 0) to fill\n // the full container, so the input needs its own padding for alignment.\n const sampleContainer = document.querySelector(mountPoints.pan) as HTMLElement | null;\n const containerPadding = sampleContainer ? getComputedStyle(sampleContainer).padding : undefined;\n\n const baseCss = css ?? {\n \"font-size\": \"1rem\",\n color: \"#18181b\",\n \"font-family\": \"ui-sans-serif, system-ui, sans-serif\",\n };\n\n const fieldCss = {\n ...baseCss,\n height: \"100%\",\n \"box-sizing\": \"border-box\",\n ...(containerPadding && containerPadding !== \"0px\" ? { padding: containerPadding } : {}),\n };\n\n // Remove stale iframes from previous VGS form mounts to prevent overlap.\n // VGS's form.unmount() does not remove iframes from the DOM.\n // IMPORTANT: This must run BEFORE VGS field methods below, because VGS may\n // insert new iframes synchronously — removing after would destroy fresh iframes.\n for (const selector of [mountPoints.pan, mountPoints.exp, mountPoints.cvc]) {\n const container = document.querySelector(selector);\n if (!container) continue;\n const staleIframes = container.querySelectorAll(\"iframe\");\n for (const iframe of staleIframes) {\n iframe.remove();\n }\n }\n\n const panField = form.cardNumberField(mountPoints.pan, {\n placeholder: placeholders?.card_pan ?? \"Card number\",\n validations: [\"required\", \"validCardNumber\"],\n css: fieldCss,\n });\n\n const expField = form.field(mountPoints.exp, {\n type: \"card-expiration-date\",\n name: \"exp-date\",\n placeholder: placeholders?.card_exp ?? \"MM / YY\",\n yearLength: 2,\n serializers: [{ name: \"separate\", options: { monthName: \"month\", yearName: \"year\" } }],\n validations: [\"required\", \"validCardExpirationDate\"],\n css: fieldCss,\n });\n\n const cvcField = form.cardCVCField(mountPoints.cvc, {\n placeholder: placeholders?.card_cvc ?? \"123\",\n validations: [\"required\", \"validCardSecurityCode\"],\n css: fieldCss,\n });\n\n // Track observers for cleanup\n const observers: MutationObserver[] = [];\n const containers: Element[] = [];\n\n // VGS Collect doesn't set width/height on its iframes, so they may not\n // fill the merchant's container. Force them to stretch like direct-mode iframes.\n // Iframes may be inserted asynchronously, so use MutationObserver as a fallback.\n for (const selector of [mountPoints.pan, mountPoints.exp, mountPoints.cvc]) {\n const container = document.querySelector(selector);\n if (!container) continue;\n containers.push(container);\n\n const styleIframe = (iframe: HTMLIFrameElement) => {\n // Use absolute positioning so the iframe covers the full container\n // including any padding the merchant's CSS applies.\n const containerEl = container as HTMLElement;\n if (getComputedStyle(containerEl).position === \"static\") {\n containerEl.style.position = \"relative\";\n }\n iframe.style.position = \"absolute\";\n iframe.style.inset = \"0\";\n iframe.style.width = \"100%\";\n iframe.style.height = \"100%\";\n iframe.style.border = \"none\";\n };\n\n // Always set up a MutationObserver to catch asynchronously inserted iframes.\n // VGS inserts iframes after field creation, so we need the observer even if\n // no iframe exists yet.\n const observer = new MutationObserver(() => {\n const iframe = container.querySelector(\"iframe\") as HTMLIFrameElement | null;\n if (iframe && iframe.style.position !== \"absolute\") {\n styleIframe(iframe);\n }\n });\n observer.observe(container, { childList: true, subtree: true });\n observers.push(observer);\n\n // Style any iframe VGS may have inserted synchronously during field creation.\n // The MutationObserver only fires on future mutations, so this handles the\n // case where VGS inserts the iframe before the observer is attached.\n const existing = container.querySelector(\"iframe\") as HTMLIFrameElement | null;\n if (existing && existing.style.position !== \"absolute\") {\n styleIframe(existing);\n }\n }\n\n if (onFocusChangeCallbacks) {\n const fieldMap: [VGSCollectField, string][] = [\n [panField, \"card_pan\"],\n [expField, \"card_exp\"],\n [cvcField, \"card_cvc\"],\n ];\n for (const [field, key] of fieldMap) {\n const cb = onFocusChangeCallbacks[key];\n if (cb) {\n field.on(\"focus\", () => cb(true));\n field.on(\"blur\", () => cb(false));\n }\n }\n }\n\n // Return cleanup function to disconnect observers and remove iframes\n return () => {\n for (const observer of observers) {\n observer.disconnect();\n }\n for (const container of containers) {\n const iframes = container.querySelectorAll(\"iframe\");\n for (const iframe of iframes) {\n iframe.remove();\n }\n }\n };\n}\n"],"mappings":";AAAA,MAAM,kBAAkB;AAExB,IAAIA,cAAoC;;;;AAKxC,SAAgB,uBAAsC;AACpD,KAAI,aAAa;AACf,UAAQ,IAAI,0EAA0E;AACtF,SAAO;;AAGT,eAAc,IAAI,SAAe,SAAS,WAAW;AACnD,MAAI,OAAO,WAAW,eAAe,OAAO,YAAY;AACtD,WAAQ,IAAI,0DAA0D;AACtE,YAAS;AACT;;AAGF,UAAQ,IAAI,iDAAiD,kBAAkB;EAC/E,MAAM,SAAS,SAAS,cAAc,SAAS;AAC/C,SAAO,MAAM;AACb,SAAO,QAAQ;AACf,SAAO,eAAe;AACpB,WAAQ,IAAI,2DAA2D;AACvE,YAAS;;AAEX,SAAO,gBAAgB;AACrB,WAAQ,MAAM,wDAAwD,kBAAkB;AACxF,iBAAc;AACd,0BAAO,IAAI,MAAM,gCAAgC,CAAC;;AAEpD,WAAS,KAAK,YAAY,OAAO;GACjC;AAEF,QAAO;;;;;AAMT,SAAgB,eAAe,SAAiB,aAAqC;AACnF,KAAI,CAAC,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.
|
|
3
|
+
"version": "0.5.14",
|
|
4
4
|
"main": "./dist/index.mjs",
|
|
5
5
|
"types": "./dist/index.d.mts",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./dist/index.mjs",
|
|
9
|
+
"./payment-methods/affirm": "./dist/payment-methods/affirm.mjs",
|
|
10
|
+
"./payment-methods/afterpay": "./dist/payment-methods/afterpay.mjs",
|
|
9
11
|
"./payment-methods/airwallex-apple-pay-adapter": "./dist/payment-methods/airwallex-apple-pay-adapter.mjs",
|
|
10
12
|
"./payment-methods/airwallex-google-pay-adapter": "./dist/payment-methods/airwallex-google-pay-adapter.mjs",
|
|
11
13
|
"./payment-methods/apple-pay": "./dist/payment-methods/apple-pay.mjs",
|
|
14
|
+
"./payment-methods/bnpl-shared": "./dist/payment-methods/bnpl-shared.mjs",
|
|
12
15
|
"./payment-methods/card": "./dist/payment-methods/card.mjs",
|
|
13
16
|
"./payment-methods/google-pay": "./dist/payment-methods/google-pay.mjs",
|
|
17
|
+
"./payment-methods/klarna": "./dist/payment-methods/klarna.mjs",
|
|
14
18
|
"./payment-methods/next-action-handlers": "./dist/payment-methods/next-action-handlers.mjs",
|
|
15
19
|
"./payment-methods/paypal": "./dist/payment-methods/paypal.mjs",
|
|
16
20
|
"./payment-methods/stripe-apple-pay-adapter": "./dist/payment-methods/stripe-apple-pay-adapter.mjs",
|
|
@@ -48,5 +52,5 @@
|
|
|
48
52
|
"tsdown": "^0.15.10",
|
|
49
53
|
"typescript": "^5.9.3"
|
|
50
54
|
},
|
|
51
|
-
"stableVersion": "0.5.
|
|
55
|
+
"stableVersion": "0.5.14"
|
|
52
56
|
}
|