@payment-kit-js/vanilla 0.5.11 → 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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * PaymentKit.js v0.5.11
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.11";
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 - will use native ApplePaySession on submit");
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
- return await runAirwallexFlow(apiBaseUrl, secureToken, applePayOptions, mockScenarioStr, checkoutRequestId);
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,