@payment-kit-js/vanilla 0.5.10 → 0.5.11

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.
@@ -108,7 +108,8 @@ var AirwallexGooglePayAdapter = class {
108
108
  signatures: ["MOCK_SIGNATURE"]
109
109
  },
110
110
  signedMessage: "MOCK_SIGNED_MESSAGE"
111
- }
111
+ },
112
+ payerEmail: "mock@example.com"
112
113
  };
113
114
  }
114
115
  if (this.mockScenario === AirwallexGooglePayMockScenario.Cancelled) {
@@ -137,12 +138,15 @@ var AirwallexGooglePayAdapter = class {
137
138
  totalPrice,
138
139
  currencyCode: this.config.currency.toUpperCase(),
139
140
  countryCode: this.config.country.toUpperCase()
140
- }
141
+ },
142
+ emailRequired: true
141
143
  };
142
- const tokenString = (await this.client.loadPaymentData(request)).paymentMethodData.tokenizationData.token;
144
+ const paymentData = await this.client.loadPaymentData(request);
145
+ const tokenString = paymentData.paymentMethodData.tokenizationData.token;
143
146
  return {
144
147
  success: true,
145
- token: JSON.parse(tokenString)
148
+ token: JSON.parse(tokenString),
149
+ payerEmail: paymentData.email
146
150
  };
147
151
  } catch (error) {
148
152
  if (error instanceof Error && error.message?.includes("CANCELED")) return {
@@ -164,4 +168,4 @@ var AirwallexGooglePayAdapter = class {
164
168
 
165
169
  //#endregion
166
170
  export { AirwallexGooglePayMockScenario as n, AirwallexGooglePayAdapter as t };
167
- //# sourceMappingURL=airwallex-google-pay-adapter-CHol_8f2.mjs.map
171
+ //# sourceMappingURL=airwallex-google-pay-adapter-B5xmg7b8.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"airwallex-google-pay-adapter-B5xmg7b8.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 emailRequired?: boolean;\n}\n\ninterface PaymentData {\n email?: string;\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; payerEmail?: string }\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, payerEmail: \"mock@example.com\" };\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 emailRequired: true,\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, payerEmail: paymentData.email };\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;;;AA4GF,IAAa,4BAAb,MAAuC;CACrC,AAAQ,SAAsC;CAC9C,AAAQ,SAA0C;CAClD,AAAQ;CAER,YAAY,cAA+C;AACzD,OAAK,eAAe,gBAAgB,+BA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  };
73
+ emailRequired?: boolean;
73
74
  }
74
75
  interface PaymentData {
76
+ email?: string;
75
77
  paymentMethodData: {
76
78
  type: string;
77
79
  tokenizationData: {
@@ -105,6 +107,7 @@ interface AirwallexGooglePayConfig {
105
107
  type AirwallexShowPaymentResult = {
106
108
  success: true;
107
109
  token: GooglePayEncryptedToken;
110
+ payerEmail?: string;
108
111
  } | {
109
112
  success: false;
110
113
  cancelled: true;
@@ -137,4 +140,4 @@ declare class AirwallexGooglePayAdapter {
137
140
  }
138
141
  //#endregion
139
142
  export { GooglePayEncryptedToken as a, AirwallexShowPaymentResult as i, AirwallexGooglePayConfig as n, AirwallexGooglePayMockScenario as r, AirwallexGooglePayAdapter as t };
140
- //# sourceMappingURL=airwallex-google-pay-adapter-CY379Rre.d.mts.map
143
+ //# sourceMappingURL=airwallex-google-pay-adapter-DvEB6t5i.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"airwallex-google-pay-adapter-DvEB6t5i.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;IAcA,MAAA,CAAA,EAAA;MAgBO,QAAA,EAAA;QAUA,GAAA,EAAA;UAUL,cAA0B,EAAA,KAAA,MACV,EA9FW,qBA8FY,EAAA,GA9Fc,oBA8Fd;QAItC,CAAA;MAKgB,CAAA;IAQR,CAAA;EAqDK;;UA7JhB,qBAAA,CA0LkB;EAAO,WAAA,EAAA,MAAA,GAAA,YAAA;;UAtLzB,oBAAA;wBACc,sBAAsB,QAAQ;2BAC3B,qBAAqB,QAAQ;;UAG9C,mBAAA;;;yBAGe;;UAGf,oBAAA;;;UAIA,oBAAA;;;;;;8BAMoB;;UAGpB,yBAAA;;;;;;;UAQA,kBAAA,SAA2B;;;;;;;;;;;;;UAc3B,WAAA;;;;;;;;;;;;;;UAgBO,uBAAA;;;;;;;;;UAUA,wBAAA;;;;;;;;;KAUL,0BAAA;;SACgB;;;;;;;;;cAIf,yBAAA;;;;6BAKgB;;;;;qBAQR;;;;;;;;oBAqDK;;;;sBA6BE,QAAQ"}
@@ -1,5 +1,5 @@
1
1
  /**
2
- * PaymentKit.js v0.5.10
2
+ * PaymentKit.js v0.5.11
3
3
  * https://paymentkit.com
4
4
  *
5
5
  * @license MIT
@@ -42,7 +42,7 @@ var PaymentKit = (() => {
42
42
  });
43
43
 
44
44
  // package.json
45
- var version = "0.5.10";
45
+ var version = "0.5.11";
46
46
 
47
47
  // src/analytics/mock-adapter.ts
48
48
  var MockAnalyticsAdapter = class {
@@ -8563,7 +8563,7 @@ var PaymentKit = (() => {
8563
8563
  },
8564
8564
  signedMessage: "MOCK_SIGNED_MESSAGE"
8565
8565
  };
8566
- return { success: true, token: mockToken };
8566
+ return { success: true, token: mockToken, payerEmail: "mock@example.com" };
8567
8567
  }
8568
8568
  if (this.mockScenario === "cancelled" /* Cancelled */) {
8569
8569
  console.log("[MockGooglePay:Airwallex] showPaymentSheet: returning mock cancelled");
@@ -8589,12 +8589,13 @@ var PaymentKit = (() => {
8589
8589
  totalPrice,
8590
8590
  currencyCode: this.config.currency.toUpperCase(),
8591
8591
  countryCode: this.config.country.toUpperCase()
8592
- }
8592
+ },
8593
+ emailRequired: true
8593
8594
  };
8594
8595
  const paymentData = await this.client.loadPaymentData(request);
8595
8596
  const tokenString = paymentData.paymentMethodData.tokenizationData.token;
8596
8597
  const token = JSON.parse(tokenString);
8597
- return { success: true, token };
8598
+ return { success: true, token, payerEmail: paymentData.email };
8598
8599
  } catch (error) {
8599
8600
  if (error instanceof Error && error.message?.includes("CANCELED")) {
8600
8601
  return { success: false, cancelled: true };
@@ -8890,7 +8891,7 @@ var PaymentKit = (() => {
8890
8891
  const errorMessage = "error" in paymentResult ? paymentResult.error : "Unknown error";
8891
8892
  return { success: false, error: errorMessage };
8892
8893
  }
8893
- return { success: true, token: paymentResult.token };
8894
+ return { success: true, token: paymentResult.token, payerEmail: paymentResult.payerEmail };
8894
8895
  }
8895
8896
  async function callConfirmEndpoint(apiBaseUrl, secureToken, googlePayToken, mockScenarioStr, checkoutRequestId, payerEmail) {
8896
8897
  const requestBody = {
@@ -8982,9 +8983,16 @@ var PaymentKit = (() => {
8982
8983
  return toGooglePayResult(response, secureToken);
8983
8984
  }
8984
8985
  var MAX_USER_ACTIONS2 = 5;
8985
- async function confirmAirwallexGooglePay(apiBaseUrl, secureToken, googlePayToken, mockScenarioStr, checkoutRequestId) {
8986
+ async function confirmAirwallexGooglePay(apiBaseUrl, secureToken, googlePayToken, mockScenarioStr, checkoutRequestId, payerEmail) {
8986
8987
  let userActionCount = 0;
8987
- let response = await callConfirmEndpoint(apiBaseUrl, secureToken, googlePayToken, mockScenarioStr, checkoutRequestId);
8988
+ let response = await callConfirmEndpoint(
8989
+ apiBaseUrl,
8990
+ secureToken,
8991
+ googlePayToken,
8992
+ mockScenarioStr,
8993
+ checkoutRequestId,
8994
+ payerEmail
8995
+ );
8988
8996
  while (response.charge_status === "pending" && response.next_action && userActionCount < MAX_USER_ACTIONS2) {
8989
8997
  userActionCount++;
8990
8998
  const actionResult = await handleNextAction(response.next_action);
@@ -9059,7 +9067,8 @@ var PaymentKit = (() => {
9059
9067
  secureToken,
9060
9068
  airwallexResult.token,
9061
9069
  mockScenarioStr,
9062
- checkoutRequestId
9070
+ checkoutRequestId,
9071
+ airwallexResult.payerEmail
9063
9072
  );
9064
9073
  }
9065
9074
  return { errors: { google_pay: `Unsupported processor: ${startData.processor}` } };