@payment-kit-js/vanilla 0.5.10 → 0.5.12
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-google-pay-adapter-CHol_8f2.mjs → airwallex-google-pay-adapter-B5xmg7b8.mjs} +9 -5
- package/dist/airwallex-google-pay-adapter-B5xmg7b8.mjs.map +1 -0
- package/dist/{airwallex-google-pay-adapter-CY379Rre.d.mts → airwallex-google-pay-adapter-DvEB6t5i.d.mts} +4 -1
- package/dist/airwallex-google-pay-adapter-DvEB6t5i.d.mts.map +1 -0
- package/dist/cdn/paymentkit.js +64 -11
- package/dist/cdn/paymentkit.js.map +2 -2
- package/dist/cdn/paymentkit.min.js +6 -6
- package/dist/cdn/paymentkit.min.js.map +3 -3
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +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 +1 -0
- package/dist/payment-methods/apple-pay.d.mts.map +1 -1
- package/dist/payment-methods/apple-pay.mjs +45 -2
- package/dist/payment-methods/apple-pay.mjs.map +1 -1
- package/dist/payment-methods/google-pay.d.mts +1 -1
- package/dist/payment-methods/google-pay.d.mts.map +1 -1
- package/dist/payment-methods/google-pay.mjs +6 -5
- package/dist/payment-methods/google-pay.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/airwallex-google-pay-adapter-CHol_8f2.mjs.map +0 -1
- package/dist/airwallex-google-pay-adapter-CY379Rre.d.mts.map +0 -1
package/dist/{airwallex-google-pay-adapter-CHol_8f2.mjs → airwallex-google-pay-adapter-B5xmg7b8.mjs}
RENAMED
|
@@ -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
|
|
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-
|
|
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":"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"}
|
|
@@ -70,8 +70,10 @@ interface PaymentDataRequest extends IsReadyToPayRequest {
|
|
|
70
70
|
currencyCode: string;
|
|
71
71
|
countryCode: string;
|
|
72
72
|
};
|
|
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-
|
|
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"}
|
package/dist/cdn/paymentkit.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* PaymentKit.js v0.5.
|
|
2
|
+
* PaymentKit.js v0.5.12
|
|
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.
|
|
45
|
+
var version = "0.5.12";
|
|
46
46
|
|
|
47
47
|
// src/analytics/mock-adapter.ts
|
|
48
48
|
var MockAnalyticsAdapter = class {
|
|
@@ -7299,6 +7299,7 @@ var PaymentKit = (() => {
|
|
|
7299
7299
|
|
|
7300
7300
|
// src/payment-methods/apple-pay.ts
|
|
7301
7301
|
var preparedStripeState = null;
|
|
7302
|
+
var preparedAirwallexState = null;
|
|
7302
7303
|
async function apiCall(url, options, checkoutRequestId) {
|
|
7303
7304
|
const headers = new Headers(options.headers);
|
|
7304
7305
|
if (checkoutRequestId) {
|
|
@@ -7321,6 +7322,9 @@ var PaymentKit = (() => {
|
|
|
7321
7322
|
if (!options?.processorId) {
|
|
7322
7323
|
return { processor_id: "Processor ID is required" };
|
|
7323
7324
|
}
|
|
7325
|
+
if (options.processorType === "airwallex" && !options.country && !preparedAirwallexState?.country) {
|
|
7326
|
+
return { country: "Country is required for Airwallex Apple Pay" };
|
|
7327
|
+
}
|
|
7324
7328
|
return null;
|
|
7325
7329
|
}
|
|
7326
7330
|
function getMockScenarioStr(mockScenario) {
|
|
@@ -7405,7 +7409,23 @@ var PaymentKit = (() => {
|
|
|
7405
7409
|
const checkoutRequestId = getOrCreateCheckoutRequestId(environment);
|
|
7406
7410
|
console.log(`[ApplePay] Using checkout_request_id: ${checkoutRequestId}`);
|
|
7407
7411
|
if (options.processorType === "airwallex") {
|
|
7408
|
-
console.log("[ApplePay] Airwallex processor -
|
|
7412
|
+
console.log("[ApplePay] Airwallex processor - fetching session info for amount");
|
|
7413
|
+
const sessionInfoResult = await callAirwallexSessionInfoEndpoint(apiBaseUrl, secureToken, checkoutRequestId);
|
|
7414
|
+
if (sessionInfoResult.error || !sessionInfoResult.data) {
|
|
7415
|
+
console.error("[ApplePay] Failed to fetch session info:", sessionInfoResult.error);
|
|
7416
|
+
return { success: false, error: sessionInfoResult.error || "Failed to fetch Apple Pay session info" };
|
|
7417
|
+
}
|
|
7418
|
+
console.log("[ApplePay] Got session info:", sessionInfoResult.data);
|
|
7419
|
+
const resolvedAmount = sessionInfoResult.data.amount;
|
|
7420
|
+
const resolvedCurrency = sessionInfoResult.data.currency;
|
|
7421
|
+
const resolvedCountry = options.country || sessionInfoResult.data.country;
|
|
7422
|
+
preparedAirwallexState = {
|
|
7423
|
+
country: resolvedCountry,
|
|
7424
|
+
currency: resolvedCurrency,
|
|
7425
|
+
amount: resolvedAmount,
|
|
7426
|
+
merchantName: options.merchantName
|
|
7427
|
+
};
|
|
7428
|
+
console.log("[ApplePay] Airwallex prepared state:", preparedAirwallexState);
|
|
7409
7429
|
return { success: true, applePay: true };
|
|
7410
7430
|
}
|
|
7411
7431
|
const startResult = await callStripeStartEndpoint(
|
|
@@ -7463,6 +7483,17 @@ var PaymentKit = (() => {
|
|
|
7463
7483
|
preparedStripeState.adapter.clearPrepared();
|
|
7464
7484
|
}
|
|
7465
7485
|
preparedStripeState = null;
|
|
7486
|
+
preparedAirwallexState = null;
|
|
7487
|
+
}
|
|
7488
|
+
async function callAirwallexSessionInfoEndpoint(apiBaseUrl, secureToken, checkoutRequestId) {
|
|
7489
|
+
return apiCall(
|
|
7490
|
+
`${apiBaseUrl}/api/checkout/${secureToken}/airwallex/apple-pay/session-info`,
|
|
7491
|
+
{
|
|
7492
|
+
method: "GET",
|
|
7493
|
+
headers: { "Content-Type": "application/json" }
|
|
7494
|
+
},
|
|
7495
|
+
checkoutRequestId
|
|
7496
|
+
);
|
|
7466
7497
|
}
|
|
7467
7498
|
async function callAirwallexStartEndpoint(apiBaseUrl, secureToken, options, validationUrl, initiativeContext, mockScenarioStr, checkoutRequestId) {
|
|
7468
7499
|
return apiCall(
|
|
@@ -7563,6 +7594,9 @@ var PaymentKit = (() => {
|
|
|
7563
7594
|
} else if (options.mockScenario === "cancelled" /* Cancelled */) {
|
|
7564
7595
|
airwallexMockScenario = "cancelled" /* Cancelled */;
|
|
7565
7596
|
}
|
|
7597
|
+
if (!options.country) {
|
|
7598
|
+
return { errors: { apple_pay: "Country is required for Airwallex Apple Pay" } };
|
|
7599
|
+
}
|
|
7566
7600
|
const adapter = new AirwallexApplePayAdapter(airwallexMockScenario);
|
|
7567
7601
|
const config = {
|
|
7568
7602
|
amount: options.amount || 0,
|
|
@@ -7701,7 +7735,17 @@ var PaymentKit = (() => {
|
|
|
7701
7735
|
}
|
|
7702
7736
|
if (applePayOptions.processorType === "airwallex") {
|
|
7703
7737
|
console.log("[ApplePay] Running Airwallex flow (processorType=airwallex)");
|
|
7704
|
-
|
|
7738
|
+
if (preparedAirwallexState) {
|
|
7739
|
+
if (applePayOptions.country == null) applePayOptions.country = preparedAirwallexState.country;
|
|
7740
|
+
if (applePayOptions.currency == null) applePayOptions.currency = preparedAirwallexState.currency;
|
|
7741
|
+
if (applePayOptions.amount == null) applePayOptions.amount = preparedAirwallexState.amount;
|
|
7742
|
+
if (applePayOptions.merchantName == null) applePayOptions.merchantName = preparedAirwallexState.merchantName;
|
|
7743
|
+
}
|
|
7744
|
+
try {
|
|
7745
|
+
return await runAirwallexFlow(apiBaseUrl, secureToken, applePayOptions, mockScenarioStr, checkoutRequestId);
|
|
7746
|
+
} finally {
|
|
7747
|
+
preparedAirwallexState = null;
|
|
7748
|
+
}
|
|
7705
7749
|
}
|
|
7706
7750
|
const startResult = await callStripeStartEndpoint(
|
|
7707
7751
|
apiBaseUrl,
|
|
@@ -8563,7 +8607,7 @@ var PaymentKit = (() => {
|
|
|
8563
8607
|
},
|
|
8564
8608
|
signedMessage: "MOCK_SIGNED_MESSAGE"
|
|
8565
8609
|
};
|
|
8566
|
-
return { success: true, token: mockToken };
|
|
8610
|
+
return { success: true, token: mockToken, payerEmail: "mock@example.com" };
|
|
8567
8611
|
}
|
|
8568
8612
|
if (this.mockScenario === "cancelled" /* Cancelled */) {
|
|
8569
8613
|
console.log("[MockGooglePay:Airwallex] showPaymentSheet: returning mock cancelled");
|
|
@@ -8589,12 +8633,13 @@ var PaymentKit = (() => {
|
|
|
8589
8633
|
totalPrice,
|
|
8590
8634
|
currencyCode: this.config.currency.toUpperCase(),
|
|
8591
8635
|
countryCode: this.config.country.toUpperCase()
|
|
8592
|
-
}
|
|
8636
|
+
},
|
|
8637
|
+
emailRequired: true
|
|
8593
8638
|
};
|
|
8594
8639
|
const paymentData = await this.client.loadPaymentData(request);
|
|
8595
8640
|
const tokenString = paymentData.paymentMethodData.tokenizationData.token;
|
|
8596
8641
|
const token = JSON.parse(tokenString);
|
|
8597
|
-
return { success: true, token };
|
|
8642
|
+
return { success: true, token, payerEmail: paymentData.email };
|
|
8598
8643
|
} catch (error) {
|
|
8599
8644
|
if (error instanceof Error && error.message?.includes("CANCELED")) {
|
|
8600
8645
|
return { success: false, cancelled: true };
|
|
@@ -8890,7 +8935,7 @@ var PaymentKit = (() => {
|
|
|
8890
8935
|
const errorMessage = "error" in paymentResult ? paymentResult.error : "Unknown error";
|
|
8891
8936
|
return { success: false, error: errorMessage };
|
|
8892
8937
|
}
|
|
8893
|
-
return { success: true, token: paymentResult.token };
|
|
8938
|
+
return { success: true, token: paymentResult.token, payerEmail: paymentResult.payerEmail };
|
|
8894
8939
|
}
|
|
8895
8940
|
async function callConfirmEndpoint(apiBaseUrl, secureToken, googlePayToken, mockScenarioStr, checkoutRequestId, payerEmail) {
|
|
8896
8941
|
const requestBody = {
|
|
@@ -8982,9 +9027,16 @@ var PaymentKit = (() => {
|
|
|
8982
9027
|
return toGooglePayResult(response, secureToken);
|
|
8983
9028
|
}
|
|
8984
9029
|
var MAX_USER_ACTIONS2 = 5;
|
|
8985
|
-
async function confirmAirwallexGooglePay(apiBaseUrl, secureToken, googlePayToken, mockScenarioStr, checkoutRequestId) {
|
|
9030
|
+
async function confirmAirwallexGooglePay(apiBaseUrl, secureToken, googlePayToken, mockScenarioStr, checkoutRequestId, payerEmail) {
|
|
8986
9031
|
let userActionCount = 0;
|
|
8987
|
-
let response = await callConfirmEndpoint(
|
|
9032
|
+
let response = await callConfirmEndpoint(
|
|
9033
|
+
apiBaseUrl,
|
|
9034
|
+
secureToken,
|
|
9035
|
+
googlePayToken,
|
|
9036
|
+
mockScenarioStr,
|
|
9037
|
+
checkoutRequestId,
|
|
9038
|
+
payerEmail
|
|
9039
|
+
);
|
|
8988
9040
|
while (response.charge_status === "pending" && response.next_action && userActionCount < MAX_USER_ACTIONS2) {
|
|
8989
9041
|
userActionCount++;
|
|
8990
9042
|
const actionResult = await handleNextAction(response.next_action);
|
|
@@ -9059,7 +9111,8 @@ var PaymentKit = (() => {
|
|
|
9059
9111
|
secureToken,
|
|
9060
9112
|
airwallexResult.token,
|
|
9061
9113
|
mockScenarioStr,
|
|
9062
|
-
checkoutRequestId
|
|
9114
|
+
checkoutRequestId,
|
|
9115
|
+
airwallexResult.payerEmail
|
|
9063
9116
|
);
|
|
9064
9117
|
}
|
|
9065
9118
|
return { errors: { google_pay: `Unsupported processor: ${startData.processor}` } };
|