@payment-kit-js/vanilla 0.4.1 → 0.5.2

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 (73) hide show
  1. package/dist/airwallex-apple-pay-adapter-BE15xREr.mjs +237 -0
  2. package/dist/airwallex-apple-pay-adapter-BE15xREr.mjs.map +1 -0
  3. package/dist/airwallex-apple-pay-adapter-I_pnNYdy.d.mts +98 -0
  4. package/dist/airwallex-apple-pay-adapter-I_pnNYdy.d.mts.map +1 -0
  5. package/dist/{airwallex-google-pay-adapter-BCmTZip5.mjs → airwallex-google-pay-adapter-CHol_8f2.mjs} +1 -1
  6. package/dist/{airwallex-google-pay-adapter-BCmTZip5.mjs.map → airwallex-google-pay-adapter-CHol_8f2.mjs.map} +1 -1
  7. package/dist/{airwallex-google-pay-adapter-Be2Af4N9.d.mts → airwallex-google-pay-adapter-CY379Rre.d.mts} +1 -1
  8. package/dist/{airwallex-google-pay-adapter-Be2Af4N9.d.mts.map → airwallex-google-pay-adapter-CY379Rre.d.mts.map} +1 -1
  9. package/dist/cdn/paymentkit.js +789 -420
  10. package/dist/cdn/paymentkit.js.map +4 -4
  11. package/dist/cdn/paymentkit.min.js +6 -6
  12. package/dist/cdn/paymentkit.min.js.map +4 -4
  13. package/dist/{connect-card-BrtCmsjz.mjs → connect-card-CMZkeppE.mjs} +1 -1
  14. package/dist/{connect-card-BrtCmsjz.mjs.map → connect-card-CMZkeppE.mjs.map} +1 -1
  15. package/dist/{connect-card-DTfXuTsW.d.mts → connect-card-Cxy51W6t.d.mts} +1 -1
  16. package/dist/{connect-card-DTfXuTsW.d.mts.map → connect-card-Cxy51W6t.d.mts.map} +1 -1
  17. package/dist/connect-tunnel-x-BhVAej5Q.mjs.map +1 -1
  18. package/dist/{connect-tunnel-x-Dxcg5Y7Y.d.mts → connect-tunnel-x-lv6Wtdme.d.mts} +6 -1
  19. package/dist/connect-tunnel-x-lv6Wtdme.d.mts.map +1 -0
  20. package/dist/index.d.mts +3 -3
  21. package/dist/index.d.mts.map +1 -1
  22. package/dist/index.mjs +76 -14
  23. package/dist/index.mjs.map +1 -1
  24. package/dist/{next-action-handlers-BZs04hYb.mjs → next-action-handlers-CTx8tRt0.mjs} +1 -1
  25. package/dist/{next-action-handlers-BZs04hYb.mjs.map → next-action-handlers-CTx8tRt0.mjs.map} +1 -1
  26. package/dist/payment-methods/airwallex-apple-pay-adapter.d.mts +2 -0
  27. package/dist/payment-methods/airwallex-apple-pay-adapter.mjs +3 -0
  28. package/dist/payment-methods/airwallex-google-pay-adapter.d.mts +1 -1
  29. package/dist/payment-methods/airwallex-google-pay-adapter.mjs +1 -1
  30. package/dist/payment-methods/apple-pay.d.mts +37 -17
  31. package/dist/payment-methods/apple-pay.d.mts.map +1 -1
  32. package/dist/payment-methods/apple-pay.mjs +203 -37
  33. package/dist/payment-methods/apple-pay.mjs.map +1 -1
  34. package/dist/payment-methods/card.d.mts +3 -3
  35. package/dist/payment-methods/card.d.mts.map +1 -1
  36. package/dist/payment-methods/card.mjs +208 -41
  37. package/dist/payment-methods/card.mjs.map +1 -1
  38. package/dist/payment-methods/google-pay.d.mts +5 -5
  39. package/dist/payment-methods/google-pay.d.mts.map +1 -1
  40. package/dist/payment-methods/google-pay.mjs +6 -7
  41. package/dist/payment-methods/google-pay.mjs.map +1 -1
  42. package/dist/payment-methods/next-action-handlers.mjs +1 -1
  43. package/dist/payment-methods/paypal.d.mts +3 -3
  44. package/dist/payment-methods/paypal.mjs +3 -3
  45. package/dist/payment-methods/paypal.mjs.map +1 -1
  46. package/dist/payment-methods/stripe-apple-pay-adapter.d.mts +1 -1
  47. package/dist/payment-methods/stripe-apple-pay-adapter.mjs +1 -1
  48. package/dist/payment-methods/stripe-google-pay-adapter.d.mts +1 -1
  49. package/dist/payment-methods/stripe-google-pay-adapter.mjs +1 -1
  50. package/dist/payment-methods/vgs-collect-loader.d.mts +28 -0
  51. package/dist/payment-methods/vgs-collect-loader.d.mts.map +1 -0
  52. package/dist/payment-methods/vgs-collect-loader.mjs +3 -0
  53. package/dist/penpal/connect-card.d.mts +1 -1
  54. package/dist/penpal/connect-card.mjs +1 -1
  55. package/dist/penpal/connect-tunnel-x.d.mts +1 -1
  56. package/dist/{stripe-apple-pay-adapter-Bg7nCy3P.mjs → stripe-apple-pay-adapter-Cd9LVNnp.mjs} +1 -1
  57. package/dist/{stripe-apple-pay-adapter-Bg7nCy3P.mjs.map → stripe-apple-pay-adapter-Cd9LVNnp.mjs.map} +1 -1
  58. package/dist/{stripe-apple-pay-adapter-Bq3f1mqv.d.mts → stripe-apple-pay-adapter-DhpGclW9.d.mts} +1 -1
  59. package/dist/{stripe-apple-pay-adapter-Bq3f1mqv.d.mts.map → stripe-apple-pay-adapter-DhpGclW9.d.mts.map} +1 -1
  60. package/dist/{stripe-google-pay-adapter-xktEycOD.d.mts → stripe-google-pay-adapter-C3NCBSO3.d.mts} +1 -1
  61. package/dist/{stripe-google-pay-adapter-xktEycOD.d.mts.map → stripe-google-pay-adapter-C3NCBSO3.d.mts.map} +1 -1
  62. package/dist/{stripe-google-pay-adapter-DjrgDYWe.mjs → stripe-google-pay-adapter-CqcUEoM3.mjs} +1 -1
  63. package/dist/{stripe-google-pay-adapter-DjrgDYWe.mjs.map → stripe-google-pay-adapter-CqcUEoM3.mjs.map} +1 -1
  64. package/dist/{types-CPuloCtF.d.mts → types-CZk3V0Qt.d.mts} +24 -6
  65. package/dist/types-CZk3V0Qt.d.mts.map +1 -0
  66. package/dist/{utils-Dgyk7RkM.mjs → utils-B70Y8YcZ.mjs} +20 -9
  67. package/dist/utils-B70Y8YcZ.mjs.map +1 -0
  68. package/dist/vgs-collect-loader-D3_xOA-G.mjs +93 -0
  69. package/dist/vgs-collect-loader-D3_xOA-G.mjs.map +1 -0
  70. package/package.json +4 -2
  71. package/dist/connect-tunnel-x-Dxcg5Y7Y.d.mts.map +0 -1
  72. package/dist/types-CPuloCtF.d.mts.map +0 -1
  73. package/dist/utils-Dgyk7RkM.mjs.map +0 -1
@@ -0,0 +1,237 @@
1
+ //#region src/payment-methods/airwallex-apple-pay-adapter.ts
2
+ /**
3
+ * Airwallex Apple Pay Adapter
4
+ *
5
+ * Uses native ApplePaySession API directly (not Stripe.js) to show the payment sheet
6
+ * and extract the encrypted payment token for Airwallex processing.
7
+ *
8
+ * Flow:
9
+ * 1. initialize() - Checks if ApplePaySession is available
10
+ * 2. canMakePayment() - Checks if user can pay with Apple Pay
11
+ * 3. showPaymentSheet() - Shows Apple Pay sheet with merchant validation callback
12
+ *
13
+ * The key difference from Stripe's approach is that we use the native
14
+ * ApplePaySession API and handle merchant validation via Airwallex's
15
+ * payment_session/start API which validates with Apple.
16
+ *
17
+ * Mock scenarios are supported for E2E testing without real Apple Pay.
18
+ */
19
+ let AirwallexApplePayMockScenario = /* @__PURE__ */ function(AirwallexApplePayMockScenario$1) {
20
+ AirwallexApplePayMockScenario$1["None"] = "none";
21
+ AirwallexApplePayMockScenario$1["Success"] = "success";
22
+ AirwallexApplePayMockScenario$1["Cancelled"] = "cancelled";
23
+ return AirwallexApplePayMockScenario$1;
24
+ }({});
25
+ var AirwallexApplePayAdapter = class {
26
+ config = null;
27
+ mockScenario;
28
+ constructor(mockScenario) {
29
+ this.mockScenario = mockScenario ?? AirwallexApplePayMockScenario.None;
30
+ }
31
+ /**
32
+ * Initialize the adapter with payment configuration.
33
+ * Returns true if Apple Pay is available on this device.
34
+ */
35
+ initialize(config) {
36
+ if (this.mockScenario !== AirwallexApplePayMockScenario.None) {
37
+ console.log("[MockApplePay:Airwallex] initialize called (mock mode)");
38
+ this.config = config;
39
+ return true;
40
+ }
41
+ if (typeof window === "undefined" || !window.ApplePaySession) {
42
+ console.error("[ApplePay:Airwallex] ApplePaySession not available (not Safari or unsupported device)");
43
+ return false;
44
+ }
45
+ this.config = config;
46
+ return true;
47
+ }
48
+ /**
49
+ * Check if the user can make a payment with Apple Pay.
50
+ * Returns true if Apple Pay is set up on this device.
51
+ */
52
+ async canMakePayment() {
53
+ if (this.mockScenario !== AirwallexApplePayMockScenario.None) {
54
+ console.log("[MockApplePay:Airwallex] canMakePayment: true (mock mode)");
55
+ return true;
56
+ }
57
+ if (!window.ApplePaySession) return false;
58
+ try {
59
+ const canMake = window.ApplePaySession.canMakePayments();
60
+ console.log("[ApplePay:Airwallex] canMakePayments:", canMake);
61
+ return canMake;
62
+ } catch (error) {
63
+ console.error("[ApplePay:Airwallex] canMakePayment error:", error);
64
+ return false;
65
+ }
66
+ }
67
+ /**
68
+ * Convert atomic units (cents) to display format for Apple Pay.
69
+ * Apple Pay expects a string like "10.00" for $10.00.
70
+ */
71
+ formatAmount(amountAtom, currency) {
72
+ if ([
73
+ "BIF",
74
+ "CLP",
75
+ "DJF",
76
+ "GNF",
77
+ "ISK",
78
+ "JPY",
79
+ "KMF",
80
+ "KRW",
81
+ "PYG",
82
+ "RWF",
83
+ "UGX",
84
+ "VND",
85
+ "VUV",
86
+ "XAF",
87
+ "XOF",
88
+ "XPF"
89
+ ].includes(currency.toUpperCase())) return amountAtom.toString();
90
+ return (amountAtom / 100).toFixed(2);
91
+ }
92
+ /**
93
+ * Show the Apple Pay payment sheet and return the encrypted token.
94
+ *
95
+ * This uses the native ApplePaySession API with a two-step flow:
96
+ * 1. onvalidatemerchant - Called by Apple to validate the merchant
97
+ * The callback should call our backend which calls Airwallex's payment_session/start
98
+ * 2. onpaymentauthorized - Called when user authorizes with Face ID/Touch ID
99
+ * Returns the encrypted token for processing
100
+ *
101
+ * @param onMerchantValidation - Callback to validate merchant with backend
102
+ * @returns Promise with token or error
103
+ */
104
+ async showPaymentSheet(onMerchantValidation) {
105
+ if (this.mockScenario === AirwallexApplePayMockScenario.Success) {
106
+ console.log("[MockApplePay:Airwallex] showPaymentSheet: returning mock success token");
107
+ return {
108
+ success: true,
109
+ token: {
110
+ paymentData: {
111
+ version: "EC_v1",
112
+ data: "MOCK_ENCRYPTED_DATA",
113
+ signature: "MOCK_SIGNATURE",
114
+ header: {
115
+ ephemeralPublicKey: "MOCK_PUBLIC_KEY",
116
+ publicKeyHash: "MOCK_HASH",
117
+ transactionId: "mock_txn_123"
118
+ }
119
+ },
120
+ paymentMethod: {
121
+ displayName: "Visa 4242",
122
+ network: "Visa",
123
+ type: "debit"
124
+ },
125
+ transactionIdentifier: "MOCK_TXN_ID"
126
+ },
127
+ complete: (status) => console.log(`[MockApplePay:Airwallex] complete: ${status}`)
128
+ };
129
+ }
130
+ if (this.mockScenario === AirwallexApplePayMockScenario.Cancelled) {
131
+ console.log("[MockApplePay:Airwallex] showPaymentSheet: returning mock cancelled");
132
+ return {
133
+ success: false,
134
+ cancelled: true
135
+ };
136
+ }
137
+ if (!this.config) return {
138
+ success: false,
139
+ error: "Apple Pay not initialized"
140
+ };
141
+ if (!window.ApplePaySession) return {
142
+ success: false,
143
+ error: "ApplePaySession not available"
144
+ };
145
+ const config = this.config;
146
+ const amount = this.formatAmount(config.amount, config.currency);
147
+ const paymentRequest = {
148
+ countryCode: config.country.toUpperCase(),
149
+ currencyCode: config.currency.toUpperCase(),
150
+ supportedNetworks: [
151
+ "visa",
152
+ "masterCard",
153
+ "amex",
154
+ "discover"
155
+ ],
156
+ merchantCapabilities: ["supports3DS"],
157
+ total: {
158
+ label: config.merchantName || "Total",
159
+ amount,
160
+ type: "final"
161
+ }
162
+ };
163
+ return new Promise((resolve) => {
164
+ try {
165
+ const session = new window.ApplePaySession(3, paymentRequest);
166
+ const STATUS_SUCCESS = window.ApplePaySession.STATUS_SUCCESS;
167
+ const STATUS_FAILURE = window.ApplePaySession.STATUS_FAILURE;
168
+ session.onvalidatemerchant = async (event) => {
169
+ console.log("[ApplePay:Airwallex] onvalidatemerchant called", event.validationURL);
170
+ try {
171
+ const validationResult = await onMerchantValidation(event.validationURL);
172
+ if (validationResult.error || !validationResult.merchantSession) {
173
+ console.error("[ApplePay:Airwallex] Merchant validation failed:", validationResult.error);
174
+ session.abort();
175
+ resolve({
176
+ success: false,
177
+ error: validationResult.error || "Merchant validation failed"
178
+ });
179
+ return;
180
+ }
181
+ session.completeMerchantValidation(validationResult.merchantSession);
182
+ console.log("[ApplePay:Airwallex] Merchant validation completed");
183
+ } catch (error) {
184
+ console.error("[ApplePay:Airwallex] Merchant validation error:", error);
185
+ session.abort();
186
+ resolve({
187
+ success: false,
188
+ error: `Merchant validation error: ${error}`
189
+ });
190
+ }
191
+ };
192
+ session.onpaymentauthorized = (event) => {
193
+ console.log("[ApplePay:Airwallex] onpaymentauthorized called");
194
+ const payment = event.payment;
195
+ const token = {
196
+ paymentData: payment.token.paymentData,
197
+ paymentMethod: {
198
+ displayName: payment.token.paymentMethod.displayName,
199
+ network: payment.token.paymentMethod.network,
200
+ type: payment.token.paymentMethod.type
201
+ },
202
+ transactionIdentifier: payment.token.transactionIdentifier
203
+ };
204
+ const complete = (status) => {
205
+ console.log("[ApplePay:Airwallex] completing session with status:", status);
206
+ const appleStatus = status === "success" ? STATUS_SUCCESS : STATUS_FAILURE;
207
+ session.completePayment({ status: appleStatus });
208
+ };
209
+ resolve({
210
+ success: true,
211
+ token,
212
+ complete
213
+ });
214
+ };
215
+ session.oncancel = () => {
216
+ console.log("[ApplePay:Airwallex] oncancel - user cancelled");
217
+ resolve({
218
+ success: false,
219
+ cancelled: true
220
+ });
221
+ };
222
+ console.log("[ApplePay:Airwallex] Starting Apple Pay session");
223
+ session.begin();
224
+ } catch (error) {
225
+ console.error("[ApplePay:Airwallex] Session creation error:", error);
226
+ resolve({
227
+ success: false,
228
+ error: `Failed to create Apple Pay session: ${error}`
229
+ });
230
+ }
231
+ });
232
+ }
233
+ };
234
+
235
+ //#endregion
236
+ export { AirwallexApplePayMockScenario as n, AirwallexApplePayAdapter as t };
237
+ //# sourceMappingURL=airwallex-apple-pay-adapter-BE15xREr.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"airwallex-apple-pay-adapter-BE15xREr.mjs","names":["paymentRequest: ApplePayJS.ApplePayPaymentRequest","token: ApplePayEncryptedToken"],"sources":["../src/payment-methods/airwallex-apple-pay-adapter.ts"],"sourcesContent":["/**\n * Airwallex Apple Pay Adapter\n *\n * Uses native ApplePaySession API directly (not Stripe.js) to show the payment sheet\n * and extract the encrypted payment token for Airwallex processing.\n *\n * Flow:\n * 1. initialize() - Checks if ApplePaySession is available\n * 2. canMakePayment() - Checks if user can pay with Apple Pay\n * 3. showPaymentSheet() - Shows Apple Pay sheet with merchant validation callback\n *\n * The key difference from Stripe's approach is that we use the native\n * ApplePaySession API and handle merchant validation via Airwallex's\n * payment_session/start API which validates with Apple.\n *\n * Mock scenarios are supported for E2E testing without real Apple Pay.\n */\n\n/// <reference types=\"@types/applepayjs\" />\n\nexport enum AirwallexApplePayMockScenario {\n None = \"none\",\n Success = \"success\",\n Cancelled = \"cancelled\",\n}\n\n// Apple Pay token structure from payment.token\nexport interface ApplePayEncryptedToken {\n paymentData: {\n version?: string;\n data: string;\n signature: string;\n header: {\n ephemeralPublicKey: string;\n publicKeyHash: string;\n transactionId: string;\n };\n };\n paymentMethod: {\n displayName: string;\n network: string;\n type: string;\n };\n transactionIdentifier: string;\n}\n\nexport interface AirwallexApplePayConfig {\n amount: number; // Amount in atomic units (cents)\n currency: string; // e.g., \"USD\"\n country: string; // e.g., \"US\"\n merchantName?: string; // Display name on Apple Pay sheet\n}\n\nexport type AirwallexApplePayShowResult =\n | { success: true; token: ApplePayEncryptedToken; complete: (status: \"success\" | \"fail\") => void }\n | { success: false; cancelled: true }\n | { success: false; error: string };\n\n// Merchant validation callback type - called during onvalidatemerchant\nexport type MerchantValidationCallback = (\n validationUrl: string,\n) => Promise<{ merchantSession?: object; error?: string }>;\n\nexport class AirwallexApplePayAdapter {\n private config: AirwallexApplePayConfig | null = null;\n private mockScenario: AirwallexApplePayMockScenario;\n\n constructor(mockScenario?: AirwallexApplePayMockScenario) {\n this.mockScenario = mockScenario ?? AirwallexApplePayMockScenario.None;\n }\n\n /**\n * Initialize the adapter with payment configuration.\n * Returns true if Apple Pay is available on this device.\n */\n initialize(config: AirwallexApplePayConfig): boolean {\n // Mock scenarios bypass real Apple Pay initialization\n if (this.mockScenario !== AirwallexApplePayMockScenario.None) {\n console.log(\"[MockApplePay:Airwallex] initialize called (mock mode)\");\n this.config = config;\n return true;\n }\n\n // Check if ApplePaySession is available (Safari on iOS/macOS only)\n if (typeof window === \"undefined\" || !window.ApplePaySession) {\n console.error(\"[ApplePay:Airwallex] ApplePaySession not available (not Safari or unsupported device)\");\n return false;\n }\n\n this.config = config;\n return true;\n }\n\n /**\n * Check if the user can make a payment with Apple Pay.\n * Returns true if Apple Pay is set up on this device.\n */\n async canMakePayment(): Promise<boolean> {\n // Mock scenarios always return true\n if (this.mockScenario !== AirwallexApplePayMockScenario.None) {\n console.log(\"[MockApplePay:Airwallex] canMakePayment: true (mock mode)\");\n return true;\n }\n\n if (!window.ApplePaySession) {\n return false;\n }\n\n try {\n const canMake = window.ApplePaySession.canMakePayments();\n console.log(\"[ApplePay:Airwallex] canMakePayments:\", canMake);\n return canMake;\n } catch (error) {\n console.error(\"[ApplePay:Airwallex] canMakePayment error:\", error);\n return false;\n }\n }\n\n /**\n * Convert atomic units (cents) to display format for Apple Pay.\n * Apple Pay expects a string like \"10.00\" for $10.00.\n */\n private formatAmount(amountAtom: number, currency: string): string {\n // Most currencies use 2 decimal places, some like JPY use 0\n const zeroDecimalCurrencies = [\n \"BIF\",\n \"CLP\",\n \"DJF\",\n \"GNF\",\n \"ISK\",\n \"JPY\",\n \"KMF\",\n \"KRW\",\n \"PYG\",\n \"RWF\",\n \"UGX\",\n \"VND\",\n \"VUV\",\n \"XAF\",\n \"XOF\",\n \"XPF\",\n ];\n const isZeroDecimal = zeroDecimalCurrencies.includes(currency.toUpperCase());\n\n if (isZeroDecimal) {\n return amountAtom.toString();\n }\n\n return (amountAtom / 100).toFixed(2);\n }\n\n /**\n * Show the Apple Pay payment sheet and return the encrypted token.\n *\n * This uses the native ApplePaySession API with a two-step flow:\n * 1. onvalidatemerchant - Called by Apple to validate the merchant\n * The callback should call our backend which calls Airwallex's payment_session/start\n * 2. onpaymentauthorized - Called when user authorizes with Face ID/Touch ID\n * Returns the encrypted token for processing\n *\n * @param onMerchantValidation - Callback to validate merchant with backend\n * @returns Promise with token or error\n */\n async showPaymentSheet(onMerchantValidation: MerchantValidationCallback): Promise<AirwallexApplePayShowResult> {\n // Handle mock scenarios\n if (this.mockScenario === AirwallexApplePayMockScenario.Success) {\n console.log(\"[MockApplePay:Airwallex] showPaymentSheet: returning mock success token\");\n const mockToken: ApplePayEncryptedToken = {\n paymentData: {\n version: \"EC_v1\",\n data: \"MOCK_ENCRYPTED_DATA\",\n signature: \"MOCK_SIGNATURE\",\n header: {\n ephemeralPublicKey: \"MOCK_PUBLIC_KEY\",\n publicKeyHash: \"MOCK_HASH\",\n transactionId: \"mock_txn_123\",\n },\n },\n paymentMethod: {\n displayName: \"Visa 4242\",\n network: \"Visa\",\n type: \"debit\",\n },\n transactionIdentifier: \"MOCK_TXN_ID\",\n };\n return {\n success: true,\n token: mockToken,\n complete: (status) => console.log(`[MockApplePay:Airwallex] complete: ${status}`),\n };\n }\n\n if (this.mockScenario === AirwallexApplePayMockScenario.Cancelled) {\n console.log(\"[MockApplePay:Airwallex] showPaymentSheet: returning mock cancelled\");\n return { success: false, cancelled: true };\n }\n\n // Real Apple Pay flow\n if (!this.config) {\n return { success: false, error: \"Apple Pay not initialized\" };\n }\n\n if (!window.ApplePaySession) {\n return { success: false, error: \"ApplePaySession not available\" };\n }\n\n const config = this.config;\n const amount = this.formatAmount(config.amount, config.currency);\n\n // Create the Apple Pay payment request\n const paymentRequest: ApplePayJS.ApplePayPaymentRequest = {\n countryCode: config.country.toUpperCase(),\n currencyCode: config.currency.toUpperCase(),\n supportedNetworks: [\"visa\", \"masterCard\", \"amex\", \"discover\"],\n merchantCapabilities: [\"supports3DS\"],\n total: {\n label: config.merchantName || \"Total\",\n amount: amount,\n type: \"final\",\n },\n };\n\n return new Promise((resolve) => {\n try {\n // Create ApplePaySession (version 3 is widely supported)\n // biome-ignore lint/style/noNonNullAssertion: ApplePaySession is guaranteed to exist (checked in canMakePayments)\n const session = new window.ApplePaySession!(3, paymentRequest);\n\n // Capture status constants at creation time (before optional chaining could yield undefined)\n // biome-ignore lint/style/noNonNullAssertion: ApplePaySession existence verified above\n const STATUS_SUCCESS = window.ApplePaySession!.STATUS_SUCCESS;\n // biome-ignore lint/style/noNonNullAssertion: ApplePaySession existence verified above\n const STATUS_FAILURE = window.ApplePaySession!.STATUS_FAILURE;\n\n // Handle merchant validation\n session.onvalidatemerchant = async (event: ApplePayJS.ApplePayValidateMerchantEvent) => {\n console.log(\"[ApplePay:Airwallex] onvalidatemerchant called\", event.validationURL);\n\n try {\n const validationResult = await onMerchantValidation(event.validationURL);\n\n if (validationResult.error || !validationResult.merchantSession) {\n console.error(\"[ApplePay:Airwallex] Merchant validation failed:\", validationResult.error);\n session.abort();\n resolve({\n success: false,\n error: validationResult.error || \"Merchant validation failed\",\n });\n return;\n }\n\n // Complete merchant validation with the session from Apple\n session.completeMerchantValidation(validationResult.merchantSession);\n console.log(\"[ApplePay:Airwallex] Merchant validation completed\");\n } catch (error) {\n console.error(\"[ApplePay:Airwallex] Merchant validation error:\", error);\n session.abort();\n resolve({\n success: false,\n error: `Merchant validation error: ${error}`,\n });\n }\n };\n\n // Handle payment authorization (user approved with Face ID/Touch ID)\n session.onpaymentauthorized = (event: ApplePayJS.ApplePayPaymentAuthorizedEvent) => {\n console.log(\"[ApplePay:Airwallex] onpaymentauthorized called\");\n\n // Extract the encrypted token\n const payment = event.payment;\n const token: ApplePayEncryptedToken = {\n paymentData: payment.token.paymentData as ApplePayEncryptedToken[\"paymentData\"],\n paymentMethod: {\n displayName: payment.token.paymentMethod.displayName,\n network: payment.token.paymentMethod.network,\n type: payment.token.paymentMethod.type,\n },\n transactionIdentifier: payment.token.transactionIdentifier,\n };\n\n // Create the complete callback that the caller will use after confirming\n const complete = (status: \"success\" | \"fail\") => {\n console.log(\"[ApplePay:Airwallex] completing session with status:\", status);\n const appleStatus = status === \"success\" ? STATUS_SUCCESS : STATUS_FAILURE;\n session.completePayment({ status: appleStatus });\n };\n\n resolve({\n success: true,\n token,\n complete,\n });\n };\n\n // Handle cancellation\n session.oncancel = () => {\n console.log(\"[ApplePay:Airwallex] oncancel - user cancelled\");\n resolve({ success: false, cancelled: true });\n };\n\n // Start the session - this shows the Apple Pay sheet\n console.log(\"[ApplePay:Airwallex] Starting Apple Pay session\");\n session.begin();\n } catch (error) {\n console.error(\"[ApplePay:Airwallex] Session creation error:\", error);\n resolve({\n success: false,\n error: `Failed to create Apple Pay session: ${error}`,\n });\n }\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAoBA,IAAY,0FAAL;AACL;AACA;AACA;;;AAwCF,IAAa,2BAAb,MAAsC;CACpC,AAAQ,SAAyC;CACjD,AAAQ;CAER,YAAY,cAA8C;AACxD,OAAK,eAAe,gBAAgB,8BAA8B;;;;;;CAOpE,WAAW,QAA0C;AAEnD,MAAI,KAAK,iBAAiB,8BAA8B,MAAM;AAC5D,WAAQ,IAAI,yDAAyD;AACrE,QAAK,SAAS;AACd,UAAO;;AAIT,MAAI,OAAO,WAAW,eAAe,CAAC,OAAO,iBAAiB;AAC5D,WAAQ,MAAM,wFAAwF;AACtG,UAAO;;AAGT,OAAK,SAAS;AACd,SAAO;;;;;;CAOT,MAAM,iBAAmC;AAEvC,MAAI,KAAK,iBAAiB,8BAA8B,MAAM;AAC5D,WAAQ,IAAI,4DAA4D;AACxE,UAAO;;AAGT,MAAI,CAAC,OAAO,gBACV,QAAO;AAGT,MAAI;GACF,MAAM,UAAU,OAAO,gBAAgB,iBAAiB;AACxD,WAAQ,IAAI,yCAAyC,QAAQ;AAC7D,UAAO;WACA,OAAO;AACd,WAAQ,MAAM,8CAA8C,MAAM;AAClE,UAAO;;;;;;;CAQX,AAAQ,aAAa,YAAoB,UAA0B;AAsBjE,MApB8B;GAC5B;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GAC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 +1,98 @@
1
+ //#region src/payment-methods/airwallex-apple-pay-adapter.d.ts
2
+ /**
3
+ * Airwallex Apple Pay Adapter
4
+ *
5
+ * Uses native ApplePaySession API directly (not Stripe.js) to show the payment sheet
6
+ * and extract the encrypted payment token for Airwallex processing.
7
+ *
8
+ * Flow:
9
+ * 1. initialize() - Checks if ApplePaySession is available
10
+ * 2. canMakePayment() - Checks if user can pay with Apple Pay
11
+ * 3. showPaymentSheet() - Shows Apple Pay sheet with merchant validation callback
12
+ *
13
+ * The key difference from Stripe's approach is that we use the native
14
+ * ApplePaySession API and handle merchant validation via Airwallex's
15
+ * payment_session/start API which validates with Apple.
16
+ *
17
+ * Mock scenarios are supported for E2E testing without real Apple Pay.
18
+ */
19
+ declare enum AirwallexApplePayMockScenario {
20
+ None = "none",
21
+ Success = "success",
22
+ Cancelled = "cancelled",
23
+ }
24
+ interface ApplePayEncryptedToken {
25
+ paymentData: {
26
+ version?: string;
27
+ data: string;
28
+ signature: string;
29
+ header: {
30
+ ephemeralPublicKey: string;
31
+ publicKeyHash: string;
32
+ transactionId: string;
33
+ };
34
+ };
35
+ paymentMethod: {
36
+ displayName: string;
37
+ network: string;
38
+ type: string;
39
+ };
40
+ transactionIdentifier: string;
41
+ }
42
+ interface AirwallexApplePayConfig {
43
+ amount: number;
44
+ currency: string;
45
+ country: string;
46
+ merchantName?: string;
47
+ }
48
+ type AirwallexApplePayShowResult = {
49
+ success: true;
50
+ token: ApplePayEncryptedToken;
51
+ complete: (status: "success" | "fail") => void;
52
+ } | {
53
+ success: false;
54
+ cancelled: true;
55
+ } | {
56
+ success: false;
57
+ error: string;
58
+ };
59
+ type MerchantValidationCallback = (validationUrl: string) => Promise<{
60
+ merchantSession?: object;
61
+ error?: string;
62
+ }>;
63
+ declare class AirwallexApplePayAdapter {
64
+ private config;
65
+ private mockScenario;
66
+ constructor(mockScenario?: AirwallexApplePayMockScenario);
67
+ /**
68
+ * Initialize the adapter with payment configuration.
69
+ * Returns true if Apple Pay is available on this device.
70
+ */
71
+ initialize(config: AirwallexApplePayConfig): boolean;
72
+ /**
73
+ * Check if the user can make a payment with Apple Pay.
74
+ * Returns true if Apple Pay is set up on this device.
75
+ */
76
+ canMakePayment(): Promise<boolean>;
77
+ /**
78
+ * Convert atomic units (cents) to display format for Apple Pay.
79
+ * Apple Pay expects a string like "10.00" for $10.00.
80
+ */
81
+ private formatAmount;
82
+ /**
83
+ * Show the Apple Pay payment sheet and return the encrypted token.
84
+ *
85
+ * This uses the native ApplePaySession API with a two-step flow:
86
+ * 1. onvalidatemerchant - Called by Apple to validate the merchant
87
+ * The callback should call our backend which calls Airwallex's payment_session/start
88
+ * 2. onpaymentauthorized - Called when user authorizes with Face ID/Touch ID
89
+ * Returns the encrypted token for processing
90
+ *
91
+ * @param onMerchantValidation - Callback to validate merchant with backend
92
+ * @returns Promise with token or error
93
+ */
94
+ showPaymentSheet(onMerchantValidation: MerchantValidationCallback): Promise<AirwallexApplePayShowResult>;
95
+ }
96
+ //#endregion
97
+ export { ApplePayEncryptedToken as a, AirwallexApplePayShowResult as i, AirwallexApplePayConfig as n, MerchantValidationCallback as o, AirwallexApplePayMockScenario as r, AirwallexApplePayAdapter as t };
98
+ //# sourceMappingURL=airwallex-apple-pay-adapter-I_pnNYdy.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"airwallex-apple-pay-adapter-I_pnNYdy.d.mts","names":[],"sources":["../src/payment-methods/airwallex-apple-pay-adapter.ts"],"sourcesContent":[],"mappings":";;AAoBA;AAOA;AAmBA;AAOA;AAMA;AAIA;;;;;;;;;;;aA3CY,6BAAA;;;;;UAOK,sBAAA;;;;;;;;;;;;;;;;;;UAmBA,uBAAA;;;;;;KAOL,2BAAA;;SACgB;;;;;;;;;KAKhB,0BAAA,8BAEP;;;;cAEQ,wBAAA;;;6BAIgB;;;;;qBAQR;;;;;oBAsBK;;;;;;;;;;;;;;;;;;yCAkEqB,6BAA6B,QAAQ"}
@@ -164,4 +164,4 @@ var AirwallexGooglePayAdapter = class {
164
164
 
165
165
  //#endregion
166
166
  export { AirwallexGooglePayMockScenario as n, AirwallexGooglePayAdapter as t };
167
- //# sourceMappingURL=airwallex-google-pay-adapter-BCmTZip5.mjs.map
167
+ //# sourceMappingURL=airwallex-google-pay-adapter-CHol_8f2.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"airwallex-google-pay-adapter-BCmTZip5.mjs","names":["baseMethod: AllowedPaymentMethod","request: IsReadyToPayRequest","request: PaymentDataRequest"],"sources":["../src/payment-methods/airwallex-google-pay-adapter.ts"],"sourcesContent":["/**\n * Airwallex Google Pay Adapter\n *\n * Uses Google Pay API directly (not Stripe.js) to show the payment sheet\n * and extract the encrypted payment token for Airwallex processing.\n *\n * Flow:\n * 1. initialize() - Checks if Google Pay API is available\n * 2. createPaymentDataRequest() - Configures the payment request\n * 3. canMakePayment() - Checks if user can pay with Google Pay\n * 4. showPaymentSheet() - Shows Google Pay sheet and returns encrypted token\n *\n * Mock scenarios are supported for E2E testing without real Google Pay.\n */\n\nexport enum AirwallexGooglePayMockScenario {\n None = \"none\",\n Success = \"success\",\n Cancelled = \"cancelled\",\n}\n\n// Google Pay API types\n// See: https://developers.google.com/pay/api/web/reference/request-objects\ndeclare global {\n interface Window {\n google?: {\n payments: {\n api: {\n PaymentsClient: new (config: GooglePayClientConfig) => GooglePaymentsClient;\n };\n };\n };\n }\n}\n\ninterface GooglePayClientConfig {\n environment: \"TEST\" | \"PRODUCTION\";\n}\n\ninterface GooglePaymentsClient {\n isReadyToPay(request: IsReadyToPayRequest): Promise<IsReadyToPayResponse>;\n loadPaymentData(request: PaymentDataRequest): Promise<PaymentData>;\n}\n\ninterface IsReadyToPayRequest {\n apiVersion: number;\n apiVersionMinor: number;\n allowedPaymentMethods: AllowedPaymentMethod[];\n}\n\ninterface IsReadyToPayResponse {\n result: boolean;\n}\n\ninterface AllowedPaymentMethod {\n type: \"CARD\";\n parameters: {\n allowedAuthMethods: (\"PAN_ONLY\" | \"CRYPTOGRAM_3DS\")[];\n allowedCardNetworks: (\"VISA\" | \"MASTERCARD\" | \"AMEX\" | \"DISCOVER\" | \"JCB\")[];\n };\n tokenizationSpecification?: TokenizationSpecification;\n}\n\ninterface TokenizationSpecification {\n type: \"PAYMENT_GATEWAY\";\n parameters: {\n gateway: string;\n gatewayMerchantId: string;\n };\n}\n\ninterface PaymentDataRequest extends IsReadyToPayRequest {\n merchantInfo: {\n merchantId?: string;\n merchantName: string;\n };\n transactionInfo: {\n totalPriceStatus: \"FINAL\" | \"ESTIMATED\";\n totalPrice: string;\n currencyCode: string;\n countryCode: string;\n };\n}\n\ninterface PaymentData {\n paymentMethodData: {\n type: string;\n tokenizationData: {\n type: string;\n token: string; // JSON string containing the encrypted payment token\n };\n info?: {\n cardNetwork: string;\n cardDetails: string;\n };\n };\n}\n\n// Google Pay encrypted token structure (what's inside tokenizationData.token)\nexport interface GooglePayEncryptedToken {\n protocolVersion: string;\n signature: string;\n intermediateSigningKey: {\n signedKey: string;\n signatures: string[];\n };\n signedMessage: string;\n}\n\nexport interface AirwallexGooglePayConfig {\n merchantId: string; // Business name for display\n gatewayMerchantId: string; // Airwallex account ID (acct_xxxx)\n amountDisplay: string; // Formatted amount for Google Pay (e.g., \"100.00\" for USD, \"1000\" for JPY)\n currency: string; // e.g., \"usd\"\n country: string; // e.g., \"US\"\n isProduction?: boolean; // Default: false (TEST environment)\n googleMerchantId?: string; // Google-assigned merchant ID for production (BCR2DN...)\n}\n\nexport type AirwallexShowPaymentResult =\n | { success: true; token: GooglePayEncryptedToken }\n | { success: false; cancelled: true }\n | { success: false; error: string };\n\nexport class AirwallexGooglePayAdapter {\n private client: GooglePaymentsClient | null = null;\n private config: AirwallexGooglePayConfig | null = null;\n private mockScenario: AirwallexGooglePayMockScenario;\n\n constructor(mockScenario?: AirwallexGooglePayMockScenario) {\n this.mockScenario = mockScenario ?? AirwallexGooglePayMockScenario.None;\n }\n\n /**\n * Initialize the Google Pay client.\n * Returns true if Google Pay API is available.\n */\n initialize(config: AirwallexGooglePayConfig): boolean {\n // Mock scenarios bypass real Google Pay initialization\n if (this.mockScenario !== AirwallexGooglePayMockScenario.None) {\n console.log(\"[MockGooglePay:Airwallex] initialize called (mock mode)\");\n this.config = config;\n return true;\n }\n\n if (!window.google?.payments?.api?.PaymentsClient) {\n console.error(\"[GooglePay:Airwallex] Google Pay API not loaded\");\n return false;\n }\n\n this.config = config;\n this.client = new window.google.payments.api.PaymentsClient({\n environment: config.isProduction ? \"PRODUCTION\" : \"TEST\",\n });\n\n return this.client !== null;\n }\n\n /**\n * Build the allowed payment methods configuration for Google Pay.\n */\n private getAllowedPaymentMethods(includeTokenization: boolean): AllowedPaymentMethod[] {\n if (!this.config) {\n throw new Error(\"Config not set. Call initialize() first.\");\n }\n\n const baseMethod: AllowedPaymentMethod = {\n type: \"CARD\",\n parameters: {\n allowedAuthMethods: [\"PAN_ONLY\", \"CRYPTOGRAM_3DS\"],\n allowedCardNetworks: [\"VISA\", \"MASTERCARD\", \"AMEX\", \"DISCOVER\", \"JCB\"],\n },\n };\n\n if (includeTokenization) {\n baseMethod.tokenizationSpecification = {\n type: \"PAYMENT_GATEWAY\",\n parameters: {\n gateway: \"airwallex\",\n gatewayMerchantId: this.config.gatewayMerchantId,\n },\n };\n }\n\n return [baseMethod];\n }\n\n /**\n * Check if the user can make a payment with Google Pay.\n */\n async canMakePayment(): Promise<boolean> {\n // Mock scenarios always return true\n if (this.mockScenario !== AirwallexGooglePayMockScenario.None) {\n console.log(\"[MockGooglePay:Airwallex] canMakePayment: true (mock mode)\");\n return true;\n }\n\n if (!this.client) {\n return false;\n }\n\n try {\n const request: IsReadyToPayRequest = {\n apiVersion: 2,\n apiVersionMinor: 0,\n allowedPaymentMethods: this.getAllowedPaymentMethods(false),\n };\n\n const response = await this.client.isReadyToPay(request);\n return response.result;\n } catch (error) {\n console.error(\"[GooglePay:Airwallex] canMakePayment error:\", error);\n return false;\n }\n }\n\n /**\n * Show the Google Pay payment sheet and return the encrypted token.\n */\n async showPaymentSheet(): Promise<AirwallexShowPaymentResult> {\n // Handle mock scenarios\n if (this.mockScenario === AirwallexGooglePayMockScenario.Success) {\n console.log(\"[MockGooglePay:Airwallex] showPaymentSheet: returning mock success token\");\n // Return a mock token that the backend will recognize as mock\n const mockToken: GooglePayEncryptedToken = {\n protocolVersion: \"ECv2\",\n signature: \"MOCK_SIGNATURE\",\n intermediateSigningKey: {\n signedKey: \"MOCK_SIGNED_KEY\",\n signatures: [\"MOCK_SIGNATURE\"],\n },\n signedMessage: \"MOCK_SIGNED_MESSAGE\",\n };\n return { success: true, token: mockToken };\n }\n\n if (this.mockScenario === AirwallexGooglePayMockScenario.Cancelled) {\n console.log(\"[MockGooglePay:Airwallex] showPaymentSheet: returning mock cancelled\");\n return { success: false, cancelled: true };\n }\n\n // Real Google Pay flow\n if (!this.client || !this.config) {\n return { success: false, error: \"Google Pay not initialized\" };\n }\n\n try {\n const totalPrice = this.config.amountDisplay;\n\n const request: PaymentDataRequest = {\n apiVersion: 2,\n apiVersionMinor: 0,\n allowedPaymentMethods: this.getAllowedPaymentMethods(true),\n merchantInfo: {\n merchantName: this.config.merchantId,\n // merchantId is required in PRODUCTION environment\n // It's the Google-assigned merchant ID from Google Pay Business Console\n ...(this.config.isProduction && this.config.googleMerchantId\n ? { merchantId: this.config.googleMerchantId }\n : {}),\n },\n transactionInfo: {\n totalPriceStatus: \"FINAL\",\n totalPrice: totalPrice,\n currencyCode: this.config.currency.toUpperCase(),\n countryCode: this.config.country.toUpperCase(),\n },\n };\n\n const paymentData = await this.client.loadPaymentData(request);\n\n // Parse the encrypted token from the response\n const tokenString = paymentData.paymentMethodData.tokenizationData.token;\n const token: GooglePayEncryptedToken = JSON.parse(tokenString);\n\n return { success: true, token };\n } catch (error) {\n // Google Pay API throws an error when user cancels\n if (error instanceof Error && error.message?.includes(\"CANCELED\")) {\n return { success: false, cancelled: true };\n }\n\n // Check for statusCode which indicates user cancelled\n const gpayError = error as { statusCode?: string };\n if (gpayError.statusCode === \"CANCELED\") {\n return { success: false, cancelled: true };\n }\n\n console.error(\"[GooglePay:Airwallex] Payment sheet error:\", error);\n const errorMessage = error instanceof Error ? error.message : \"Unknown error\";\n return { success: false, error: errorMessage };\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAeA,IAAY,4FAAL;AACL;AACA;AACA;;;AA0GF,IAAa,4BAAb,MAAuC;CACrC,AAAQ,SAAsC;CAC9C,AAAQ,SAA0C;CAClD,AAAQ;CAER,YAAY,cAA+C;AACzD,OAAK,eAAe,gBAAgB,+BAA+B;;;;;;CAOrE,WAAW,QAA2C;AAEpD,MAAI,KAAK,iBAAiB,+BAA+B,MAAM;AAC7D,WAAQ,IAAI,0DAA0D;AACtE,QAAK,SAAS;AACd,UAAO;;AAGT,MAAI,CAAC,OAAO,QAAQ,UAAU,KAAK,gBAAgB;AACjD,WAAQ,MAAM,kDAAkD;AAChE,UAAO;;AAGT,OAAK,SAAS;AACd,OAAK,SAAS,IAAI,OAAO,OAAO,SAAS,IAAI,eAAe,EAC1D,aAAa,OAAO,eAAe,eAAe,QACnD,CAAC;AAEF,SAAO,KAAK,WAAW;;;;;CAMzB,AAAQ,yBAAyB,qBAAsD;AACrF,MAAI,CAAC,KAAK,OACR,OAAM,IAAI,MAAM,2CAA2C;EAG7D,MAAMA,aAAmC;GACvC,MAAM;GACN,YAAY;IACV,oBAAoB,CAAC,YAAY,iBAAiB;IAClD,qBAAqB;KAAC;KAAQ;KAAc;KAAQ;KAAY;KAAM;IACvE;GACF;AAED,MAAI,oBACF,YAAW,4BAA4B;GACrC,MAAM;GACN,YAAY;IACV,SAAS;IACT,mBAAmB,KAAK,OAAO;IAChC;GACF;AAGH,SAAO,CAAC,WAAW;;;;;CAMrB,MAAM,iBAAmC;AAEvC,MAAI,KAAK,iBAAiB,+BAA+B,MAAM;AAC7D,WAAQ,IAAI,6DAA6D;AACzE,UAAO;;AAGT,MAAI,CAAC,KAAK,OACR,QAAO;AAGT,MAAI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IAAE,SAAS;IAAO,WAAW;IAAM;AAK5C,OADkB,MACJ,eAAe,WAC3B,QAAO;IAAE,SAAS;IAAO,WAAW;IAAM;AAG5C,WAAQ,MAAM,8CAA8C,MAAM;AAElE,UAAO;IAAE,SAAS;IAAO,OADJ,iBAAiB,QAAQ,MAAM,UAAU;IAChB"}
1
+ {"version":3,"file":"airwallex-google-pay-adapter-CHol_8f2.mjs","names":["baseMethod: AllowedPaymentMethod","request: IsReadyToPayRequest","request: PaymentDataRequest"],"sources":["../src/payment-methods/airwallex-google-pay-adapter.ts"],"sourcesContent":["/**\n * Airwallex Google Pay Adapter\n *\n * Uses Google Pay API directly (not Stripe.js) to show the payment sheet\n * and extract the encrypted payment token for Airwallex processing.\n *\n * Flow:\n * 1. initialize() - Checks if Google Pay API is available\n * 2. createPaymentDataRequest() - Configures the payment request\n * 3. canMakePayment() - Checks if user can pay with Google Pay\n * 4. showPaymentSheet() - Shows Google Pay sheet and returns encrypted token\n *\n * Mock scenarios are supported for E2E testing without real Google Pay.\n */\n\nexport enum AirwallexGooglePayMockScenario {\n None = \"none\",\n Success = \"success\",\n Cancelled = \"cancelled\",\n}\n\n// Google Pay API types\n// See: https://developers.google.com/pay/api/web/reference/request-objects\ndeclare global {\n interface Window {\n google?: {\n payments: {\n api: {\n PaymentsClient: new (config: GooglePayClientConfig) => GooglePaymentsClient;\n };\n };\n };\n }\n}\n\ninterface GooglePayClientConfig {\n environment: \"TEST\" | \"PRODUCTION\";\n}\n\ninterface GooglePaymentsClient {\n isReadyToPay(request: IsReadyToPayRequest): Promise<IsReadyToPayResponse>;\n loadPaymentData(request: PaymentDataRequest): Promise<PaymentData>;\n}\n\ninterface IsReadyToPayRequest {\n apiVersion: number;\n apiVersionMinor: number;\n allowedPaymentMethods: AllowedPaymentMethod[];\n}\n\ninterface IsReadyToPayResponse {\n result: boolean;\n}\n\ninterface AllowedPaymentMethod {\n type: \"CARD\";\n parameters: {\n allowedAuthMethods: (\"PAN_ONLY\" | \"CRYPTOGRAM_3DS\")[];\n allowedCardNetworks: (\"VISA\" | \"MASTERCARD\" | \"AMEX\" | \"DISCOVER\" | \"JCB\")[];\n };\n tokenizationSpecification?: TokenizationSpecification;\n}\n\ninterface TokenizationSpecification {\n type: \"PAYMENT_GATEWAY\";\n parameters: {\n gateway: string;\n gatewayMerchantId: string;\n };\n}\n\ninterface PaymentDataRequest extends IsReadyToPayRequest {\n merchantInfo: {\n merchantId?: string;\n merchantName: string;\n };\n transactionInfo: {\n totalPriceStatus: \"FINAL\" | \"ESTIMATED\";\n totalPrice: string;\n currencyCode: string;\n countryCode: string;\n };\n}\n\ninterface PaymentData {\n paymentMethodData: {\n type: string;\n tokenizationData: {\n type: string;\n token: string; // JSON string containing the encrypted payment token\n };\n info?: {\n cardNetwork: string;\n cardDetails: string;\n };\n };\n}\n\n// Google Pay encrypted token structure (what's inside tokenizationData.token)\nexport interface GooglePayEncryptedToken {\n protocolVersion: string;\n signature: string;\n intermediateSigningKey: {\n signedKey: string;\n signatures: string[];\n };\n signedMessage: string;\n}\n\nexport interface AirwallexGooglePayConfig {\n merchantId: string; // Business name for display\n gatewayMerchantId: string; // Airwallex account ID (acct_xxxx)\n amountDisplay: string; // Formatted amount for Google Pay (e.g., \"100.00\" for USD, \"1000\" for JPY)\n currency: string; // e.g., \"usd\"\n country: string; // e.g., \"US\"\n isProduction?: boolean; // Default: false (TEST environment)\n googleMerchantId?: string; // Google-assigned merchant ID for production (BCR2DN...)\n}\n\nexport type AirwallexShowPaymentResult =\n | { success: true; token: GooglePayEncryptedToken }\n | { success: false; cancelled: true }\n | { success: false; error: string };\n\nexport class AirwallexGooglePayAdapter {\n private client: GooglePaymentsClient | null = null;\n private config: AirwallexGooglePayConfig | null = null;\n private mockScenario: AirwallexGooglePayMockScenario;\n\n constructor(mockScenario?: AirwallexGooglePayMockScenario) {\n this.mockScenario = mockScenario ?? AirwallexGooglePayMockScenario.None;\n }\n\n /**\n * Initialize the Google Pay client.\n * Returns true if Google Pay API is available.\n */\n initialize(config: AirwallexGooglePayConfig): boolean {\n // Mock scenarios bypass real Google Pay initialization\n if (this.mockScenario !== AirwallexGooglePayMockScenario.None) {\n console.log(\"[MockGooglePay:Airwallex] initialize called (mock mode)\");\n this.config = config;\n return true;\n }\n\n if (!window.google?.payments?.api?.PaymentsClient) {\n console.error(\"[GooglePay:Airwallex] Google Pay API not loaded\");\n return false;\n }\n\n this.config = config;\n this.client = new window.google.payments.api.PaymentsClient({\n environment: config.isProduction ? \"PRODUCTION\" : \"TEST\",\n });\n\n return this.client !== null;\n }\n\n /**\n * Build the allowed payment methods configuration for Google Pay.\n */\n private getAllowedPaymentMethods(includeTokenization: boolean): AllowedPaymentMethod[] {\n if (!this.config) {\n throw new Error(\"Config not set. Call initialize() first.\");\n }\n\n const baseMethod: AllowedPaymentMethod = {\n type: \"CARD\",\n parameters: {\n allowedAuthMethods: [\"PAN_ONLY\", \"CRYPTOGRAM_3DS\"],\n allowedCardNetworks: [\"VISA\", \"MASTERCARD\", \"AMEX\", \"DISCOVER\", \"JCB\"],\n },\n };\n\n if (includeTokenization) {\n baseMethod.tokenizationSpecification = {\n type: \"PAYMENT_GATEWAY\",\n parameters: {\n gateway: \"airwallex\",\n gatewayMerchantId: this.config.gatewayMerchantId,\n },\n };\n }\n\n return [baseMethod];\n }\n\n /**\n * Check if the user can make a payment with Google Pay.\n */\n async canMakePayment(): Promise<boolean> {\n // Mock scenarios always return true\n if (this.mockScenario !== AirwallexGooglePayMockScenario.None) {\n console.log(\"[MockGooglePay:Airwallex] canMakePayment: true (mock mode)\");\n return true;\n }\n\n if (!this.client) {\n return false;\n }\n\n try {\n const request: IsReadyToPayRequest = {\n apiVersion: 2,\n apiVersionMinor: 0,\n allowedPaymentMethods: this.getAllowedPaymentMethods(false),\n };\n\n const response = await this.client.isReadyToPay(request);\n return response.result;\n } catch (error) {\n console.error(\"[GooglePay:Airwallex] canMakePayment error:\", error);\n return false;\n }\n }\n\n /**\n * Show the Google Pay payment sheet and return the encrypted token.\n */\n async showPaymentSheet(): Promise<AirwallexShowPaymentResult> {\n // Handle mock scenarios\n if (this.mockScenario === AirwallexGooglePayMockScenario.Success) {\n console.log(\"[MockGooglePay:Airwallex] showPaymentSheet: returning mock success token\");\n // Return a mock token that the backend will recognize as mock\n const mockToken: GooglePayEncryptedToken = {\n protocolVersion: \"ECv2\",\n signature: \"MOCK_SIGNATURE\",\n intermediateSigningKey: {\n signedKey: \"MOCK_SIGNED_KEY\",\n signatures: [\"MOCK_SIGNATURE\"],\n },\n signedMessage: \"MOCK_SIGNED_MESSAGE\",\n };\n return { success: true, token: mockToken };\n }\n\n if (this.mockScenario === AirwallexGooglePayMockScenario.Cancelled) {\n console.log(\"[MockGooglePay:Airwallex] showPaymentSheet: returning mock cancelled\");\n return { success: false, cancelled: true };\n }\n\n // Real Google Pay flow\n if (!this.client || !this.config) {\n return { success: false, error: \"Google Pay not initialized\" };\n }\n\n try {\n const totalPrice = this.config.amountDisplay;\n\n const request: PaymentDataRequest = {\n apiVersion: 2,\n apiVersionMinor: 0,\n allowedPaymentMethods: this.getAllowedPaymentMethods(true),\n merchantInfo: {\n merchantName: this.config.merchantId,\n // merchantId is required in PRODUCTION environment\n // It's the Google-assigned merchant ID from Google Pay Business Console\n ...(this.config.isProduction && this.config.googleMerchantId\n ? { merchantId: this.config.googleMerchantId }\n : {}),\n },\n transactionInfo: {\n totalPriceStatus: \"FINAL\",\n totalPrice: totalPrice,\n currencyCode: this.config.currency.toUpperCase(),\n countryCode: this.config.country.toUpperCase(),\n },\n };\n\n const paymentData = await this.client.loadPaymentData(request);\n\n // Parse the encrypted token from the response\n const tokenString = paymentData.paymentMethodData.tokenizationData.token;\n const token: GooglePayEncryptedToken = JSON.parse(tokenString);\n\n return { success: true, token };\n } catch (error) {\n // Google Pay API throws an error when user cancels\n if (error instanceof Error && error.message?.includes(\"CANCELED\")) {\n return { success: false, cancelled: true };\n }\n\n // Check for statusCode which indicates user cancelled\n const gpayError = error as { statusCode?: string };\n if (gpayError.statusCode === \"CANCELED\") {\n return { success: false, cancelled: true };\n }\n\n console.error(\"[GooglePay:Airwallex] Payment sheet error:\", error);\n const errorMessage = error instanceof Error ? error.message : \"Unknown error\";\n return { success: false, error: errorMessage };\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAeA,IAAY,4FAAL;AACL;AACA;AACA;;;AA0GF,IAAa,4BAAb,MAAuC;CACrC,AAAQ,SAAsC;CAC9C,AAAQ,SAA0C;CAClD,AAAQ;CAER,YAAY,cAA+C;AACzD,OAAK,eAAe,gBAAgB,+BAA+B;;;;;;CAOrE,WAAW,QAA2C;AAEpD,MAAI,KAAK,iBAAiB,+BAA+B,MAAM;AAC7D,WAAQ,IAAI,0DAA0D;AACtE,QAAK,SAAS;AACd,UAAO;;AAGT,MAAI,CAAC,OAAO,QAAQ,UAAU,KAAK,gBAAgB;AACjD,WAAQ,MAAM,kDAAkD;AAChE,UAAO;;AAGT,OAAK,SAAS;AACd,OAAK,SAAS,IAAI,OAAO,OAAO,SAAS,IAAI,eAAe,EAC1D,aAAa,OAAO,eAAe,eAAe,QACnD,CAAC;AAEF,SAAO,KAAK,WAAW;;;;;CAMzB,AAAQ,yBAAyB,qBAAsD;AACrF,MAAI,CAAC,KAAK,OACR,OAAM,IAAI,MAAM,2CAA2C;EAG7D,MAAMA,aAAmC;GACvC,MAAM;GACN,YAAY;IACV,oBAAoB,CAAC,YAAY,iBAAiB;IAClD,qBAAqB;KAAC;KAAQ;KAAc;KAAQ;KAAY;KAAM;IACvE;GACF;AAED,MAAI,oBACF,YAAW,4BAA4B;GACrC,MAAM;GACN,YAAY;IACV,SAAS;IACT,mBAAmB,KAAK,OAAO;IAChC;GACF;AAGH,SAAO,CAAC,WAAW;;;;;CAMrB,MAAM,iBAAmC;AAEvC,MAAI,KAAK,iBAAiB,+BAA+B,MAAM;AAC7D,WAAQ,IAAI,6DAA6D;AACzE,UAAO;;AAGT,MAAI,CAAC,KAAK,OACR,QAAO;AAGT,MAA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;IAAE,SAAS;IAAO,WAAW;IAAM;AAK5C,OADkB,MACJ,eAAe,WAC3B,QAAO;IAAE,SAAS;IAAO,WAAW;IAAM;AAG5C,WAAQ,MAAM,8CAA8C,MAAM;AAElE,UAAO;IAAE,SAAS;IAAO,OADJ,iBAAiB,QAAQ,MAAM,UAAU;IAChB"}
@@ -137,4 +137,4 @@ declare class AirwallexGooglePayAdapter {
137
137
  }
138
138
  //#endregion
139
139
  export { GooglePayEncryptedToken as a, AirwallexShowPaymentResult as i, AirwallexGooglePayConfig as n, AirwallexGooglePayMockScenario as r, AirwallexGooglePayAdapter as t };
140
- //# sourceMappingURL=airwallex-google-pay-adapter-Be2Af4N9.d.mts.map
140
+ //# sourceMappingURL=airwallex-google-pay-adapter-CY379Rre.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"airwallex-google-pay-adapter-Be2Af4N9.d.mts","names":[],"sources":["../src/payment-methods/airwallex-google-pay-adapter.ts"],"sourcesContent":[],"mappings":";;AAeA;AAIC;;;;;AASoF;AAOtD;;;;;;AAMiB,aA1BpC,8BAAA;EA0B2C,IAAA,GAAA,MAAA;EAG7C,OAAA,GAAA,SAAA;EAMA,SAAA,GAAA,WAAoB;AAAA;AAUyB,QAG7C,MAAA,CAAA;EAQA,UAAA,MAAA,CAAA;IAaA,MAAA,CAAA,EAAA;MAeO,QAAA,EAAA;QAUA,GAAA,EAAA;UAUL,cAA0B,EAAA,KAAA,MACV,EA5FW,qBA4FY,EAAA,GA5Fc,oBA4Fd;QAItC,CAAA;MAKgB,CAAA;IAQR,CAAA;EAqDK;;UA3JhB,qBAAA,CAwLkB;EAAO,WAAA,EAAA,MAAA,GAAA,YAAA;;UApLzB,oBAAA;wBACc,sBAAsB,QAAQ;2BAC3B,qBAAqB,QAAQ;;UAG9C,mBAAA;;;yBAGe;;UAGf,oBAAA;;;UAIA,oBAAA;;;;;;8BAMoB;;UAGpB,yBAAA;;;;;;;UAQA,kBAAA,SAA2B;;;;;;;;;;;;UAa3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