@economist/web-apple-pay 0.1.3-beta.15 → 0.1.3-beta.17

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/index.js CHANGED
@@ -1065,25 +1065,20 @@ var isAppleDeviceOrSafari = () => {
1065
1065
  var bypassApplePayChecks = () => new URLSearchParams(window.location.search).get("BYPASS_APPLE_PAY_CHECKS") !== null && getApplePayConfig()?.debugBypassEnabled === true;
1066
1066
  var isApplePayAvailable = async () => {
1067
1067
  if (bypassApplePayChecks()) {
1068
- console.debug("[web-apple-pay] isApplePayAvailable: bypass enabled, returning true");
1069
1068
  return true;
1070
1069
  }
1071
1070
  if (!isAppleDeviceOrSafari()) {
1072
- console.debug("[web-apple-pay] isApplePayAvailable: not an Apple device or Safari", { userAgent: navigator.userAgent });
1073
1071
  return false;
1074
1072
  }
1075
1073
  const applePaySession = window.ApplePaySession;
1076
1074
  if (!applePaySession) {
1077
- console.debug("[web-apple-pay] isApplePayAvailable: ApplePaySession not present on window");
1078
1075
  return false;
1079
1076
  }
1080
1077
  try {
1081
1078
  if (typeof applePaySession.canMakePayments !== "function") {
1082
- console.debug("[web-apple-pay] isApplePayAvailable: canMakePayments is not a function");
1083
1079
  return false;
1084
1080
  }
1085
1081
  if (!applePaySession.canMakePayments()) {
1086
- console.debug("[web-apple-pay] isApplePayAvailable: canMakePayments() returned false");
1087
1082
  return false;
1088
1083
  }
1089
1084
  const merchantId = getApplePayConfig()?.merchantId;
@@ -1094,7 +1089,6 @@ var isApplePayAvailable = async () => {
1094
1089
  return false;
1095
1090
  }
1096
1091
  const hasActiveCard = await applePaySession.canMakePaymentsWithActiveCard(merchantId);
1097
- console.debug("[web-apple-pay] isApplePayAvailable: canMakePaymentsWithActiveCard =", hasActiveCard, { merchantId });
1098
1092
  return hasActiveCard;
1099
1093
  } catch (error) {
1100
1094
  console.error("Error checking Apple Pay active card status:", error);
@@ -1213,14 +1207,20 @@ var redirectToCheckoutComplete = (params) => {
1213
1207
  return url.pathname + url.search;
1214
1208
  };
1215
1209
  var redirectToCheckoutFallback = (params) => {
1210
+ const decodedOffer = decodeSku(params.skuId);
1211
+ console.log("[web-apple-pay] redirectToCheckoutFallback", {
1212
+ rawSkuId: params.skuId,
1213
+ decodedOffer
1214
+ });
1216
1215
  const url = new URL(window.location.href);
1217
1216
  url.pathname = "/checkout";
1218
- url.searchParams.set("lmo_offer", params.skuId);
1217
+ url.searchParams.set("lmo_offer", decodedOffer);
1219
1218
  if (params.inlineError)
1220
1219
  url.searchParams.set("inlineError", params.inlineError);
1221
1220
  if (params.email) url.searchParams.set("email", params.email);
1222
1221
  if (params.emailError) url.searchParams.set("emailError", params.emailError);
1223
1222
  url.searchParams.set("returnUrl", params.returnUrl);
1223
+ console.log("[web-apple-pay] fallback redirect URL", url.pathname + url.search);
1224
1224
  return url.pathname + url.search;
1225
1225
  };
1226
1226
 
@@ -1318,11 +1318,9 @@ function redirectToFallbackCheckout(config) {
1318
1318
  });
1319
1319
  }
1320
1320
  async function handleMerchantValidation(event, session, config) {
1321
- console.debug("[web-apple-pay] onvalidatemerchant: validating", { validationURL: event.validationURL });
1322
1321
  try {
1323
1322
  const validationHost = new URL(event.validationURL).host;
1324
1323
  if (!validationHost.endsWith("apple.com")) {
1325
- console.debug("[web-apple-pay] onvalidatemerchant: invalid host, aborting", { validationHost });
1326
1324
  session.abort();
1327
1325
  redirectToFallbackCheckout(config);
1328
1326
  return;
@@ -1333,12 +1331,10 @@ async function handleMerchantValidation(event, session, config) {
1333
1331
  recaptchaToken
1334
1332
  });
1335
1333
  if (!response?.merchantSession) {
1336
- console.debug("[web-apple-pay] onvalidatemerchant: no merchantSession in response, aborting");
1337
1334
  session.abort();
1338
1335
  redirectToFallbackCheckout(config);
1339
1336
  return;
1340
1337
  }
1341
- console.debug("[web-apple-pay] onvalidatemerchant: merchant validated successfully");
1342
1338
  session.completeMerchantValidation(response.merchantSession);
1343
1339
  } catch (err) {
1344
1340
  console.error("[web-apple-pay] onvalidatemerchant: error during validation", err);
@@ -1347,14 +1343,6 @@ async function handleMerchantValidation(event, session, config) {
1347
1343
  }
1348
1344
  }
1349
1345
  function startApplePaySession(config) {
1350
- console.debug("[web-apple-pay] startApplePaySession: starting session", {
1351
- skuId: config.skuId,
1352
- countryCode: config.countryCode,
1353
- currencyCode: config.currencyCode,
1354
- supportedNetworks: config.supportedNetworks,
1355
- totalAmount: config.totalAmount,
1356
- userLoggedIn: config.userLoggedIn
1357
- });
1358
1346
  const paymentRequest = {
1359
1347
  countryCode: config.countryCode,
1360
1348
  currencyCode: config.currencyCode,
@@ -1374,15 +1362,12 @@ function startApplePaySession(config) {
1374
1362
  await handleMerchantValidation(event, session, config);
1375
1363
  };
1376
1364
  session.onpaymentauthorized = (event) => {
1377
- console.debug("[web-apple-pay] onpaymentauthorized: payment authorised");
1378
1365
  trackWalletPaymentAuthorised(config.skuId);
1379
1366
  config.onPaymentAuthorized(event, session);
1380
1367
  };
1381
1368
  session.oncancel = () => {
1382
- console.debug("[web-apple-pay] oncancel: user cancelled Apple Pay sheet");
1383
1369
  config.onCancel?.();
1384
1370
  };
1385
- console.debug("[web-apple-pay] startApplePaySession: session.begin()");
1386
1371
  trackWalletPaymentSheetOpen(config.skuId);
1387
1372
  session.begin();
1388
1373
  } catch (err) {
@@ -1995,7 +1980,6 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
1995
1980
  }
1996
1981
  // ─── Render pipeline ────────────────────────────────────────────────────────
1997
1982
  async #run() {
1998
- console.debug("[web-apple-pay] #run: start");
1999
1983
  try {
2000
1984
  if (await this.#checkAvailability()) return;
2001
1985
  if (this.#checkOffer()) return;
@@ -2017,11 +2001,9 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2017
2001
  async #checkAvailability() {
2018
2002
  const available = await isApplePayAvailable();
2019
2003
  if (!available) {
2020
- console.debug("[web-apple-pay] #checkAvailability: not available on this device/browser");
2021
2004
  this.style.display = "none";
2022
2005
  return true;
2023
2006
  }
2024
- console.debug("[web-apple-pay] #checkAvailability: ok");
2025
2007
  return false;
2026
2008
  }
2027
2009
  /**
@@ -2030,24 +2012,19 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2030
2012
  */
2031
2013
  async #checkSession() {
2032
2014
  this.#sessionData = await this.#fetchSession();
2033
- console.debug("[web-apple-pay] #checkSession: session data", { loggedIn: this.#sessionData?.loggedIn, userType: this.#sessionData?.userType });
2034
2015
  if (this.#sessionData?.loggedIn && (this.#sessionData.userType === "active-subscription" || this.#sessionData.userType === "b2b-user")) {
2035
- console.debug("[web-apple-pay] #checkSession: ineligible user, hiding button", { userType: this.#sessionData.userType });
2036
2016
  this.style.display = "none";
2037
2017
  this.querySelector(SEL_CONTAINER)?.remove();
2038
2018
  return true;
2039
2019
  }
2040
- console.debug("[web-apple-pay] #checkSession: ok");
2041
2020
  return false;
2042
2021
  }
2043
2022
  /** Returns `true` (hide) when no offer has been set before mount. */
2044
2023
  #checkOffer() {
2045
2024
  if (!this.#offer) {
2046
- console.debug("[web-apple-pay] #checkOffer: no offer set, hiding button");
2047
2025
  this.style.display = "none";
2048
2026
  return true;
2049
2027
  }
2050
- console.debug("[web-apple-pay] #checkOffer: ok", { skuId: this.#offer.sku_id });
2051
2028
  return false;
2052
2029
  }
2053
2030
  /** Captures the current page URL once at mount for reuse across the session lifetime. */
@@ -2071,19 +2048,15 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2071
2048
  */
2072
2049
  async #fetchAndCacheOptions() {
2073
2050
  this.#paymentOptions = await this.#fetchPaymentOptions();
2074
- console.debug("[web-apple-pay] #fetchAndCacheOptions: payment options", this.#paymentOptions);
2075
2051
  if (!this.#paymentOptions?.options?.apple_pay) {
2076
- console.debug("[web-apple-pay] #fetchAndCacheOptions: apple_pay absent in options, hiding button");
2077
2052
  this.style.display = "none";
2078
2053
  this.querySelector(SEL_CONTAINER)?.remove();
2079
2054
  return true;
2080
2055
  }
2081
- console.debug("[web-apple-pay] #fetchAndCacheOptions: ok", this.#paymentOptions.options.apple_pay);
2082
2056
  return false;
2083
2057
  }
2084
2058
  /** Injects the button template and wires click and confirm event listeners. */
2085
2059
  #renderTemplate() {
2086
- console.debug("[web-apple-pay] #renderTemplate: injecting button template");
2087
2060
  this.style.removeProperty("display");
2088
2061
  ensureApplePayLogoSymbol();
2089
2062
  const template = document.createElement("template");
@@ -2100,7 +2073,6 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2100
2073
  });
2101
2074
  }
2102
2075
  #finishLoading() {
2103
- console.debug("[web-apple-pay] #finishLoading: all checks passed, enabling button");
2104
2076
  const button = this.querySelector(SEL_BUTTON);
2105
2077
  if (button) {
2106
2078
  button.classList.remove("wap-loading");
@@ -1060,25 +1060,20 @@ var isAppleDeviceOrSafari = () => {
1060
1060
  var bypassApplePayChecks = () => new URLSearchParams(window.location.search).get("BYPASS_APPLE_PAY_CHECKS") !== null && getApplePayConfig()?.debugBypassEnabled === true;
1061
1061
  var isApplePayAvailable = async () => {
1062
1062
  if (bypassApplePayChecks()) {
1063
- console.debug("[web-apple-pay] isApplePayAvailable: bypass enabled, returning true");
1064
1063
  return true;
1065
1064
  }
1066
1065
  if (!isAppleDeviceOrSafari()) {
1067
- console.debug("[web-apple-pay] isApplePayAvailable: not an Apple device or Safari", { userAgent: navigator.userAgent });
1068
1066
  return false;
1069
1067
  }
1070
1068
  const applePaySession = window.ApplePaySession;
1071
1069
  if (!applePaySession) {
1072
- console.debug("[web-apple-pay] isApplePayAvailable: ApplePaySession not present on window");
1073
1070
  return false;
1074
1071
  }
1075
1072
  try {
1076
1073
  if (typeof applePaySession.canMakePayments !== "function") {
1077
- console.debug("[web-apple-pay] isApplePayAvailable: canMakePayments is not a function");
1078
1074
  return false;
1079
1075
  }
1080
1076
  if (!applePaySession.canMakePayments()) {
1081
- console.debug("[web-apple-pay] isApplePayAvailable: canMakePayments() returned false");
1082
1077
  return false;
1083
1078
  }
1084
1079
  const merchantId = getApplePayConfig()?.merchantId;
@@ -1089,7 +1084,6 @@ var isApplePayAvailable = async () => {
1089
1084
  return false;
1090
1085
  }
1091
1086
  const hasActiveCard = await applePaySession.canMakePaymentsWithActiveCard(merchantId);
1092
- console.debug("[web-apple-pay] isApplePayAvailable: canMakePaymentsWithActiveCard =", hasActiveCard, { merchantId });
1093
1087
  return hasActiveCard;
1094
1088
  } catch (error) {
1095
1089
  console.error("Error checking Apple Pay active card status:", error);
@@ -1208,14 +1202,20 @@ var redirectToCheckoutComplete = (params) => {
1208
1202
  return url.pathname + url.search;
1209
1203
  };
1210
1204
  var redirectToCheckoutFallback = (params) => {
1205
+ const decodedOffer = decodeSku(params.skuId);
1206
+ console.log("[web-apple-pay] redirectToCheckoutFallback", {
1207
+ rawSkuId: params.skuId,
1208
+ decodedOffer
1209
+ });
1211
1210
  const url = new URL(window.location.href);
1212
1211
  url.pathname = "/checkout";
1213
- url.searchParams.set("lmo_offer", params.skuId);
1212
+ url.searchParams.set("lmo_offer", decodedOffer);
1214
1213
  if (params.inlineError)
1215
1214
  url.searchParams.set("inlineError", params.inlineError);
1216
1215
  if (params.email) url.searchParams.set("email", params.email);
1217
1216
  if (params.emailError) url.searchParams.set("emailError", params.emailError);
1218
1217
  url.searchParams.set("returnUrl", params.returnUrl);
1218
+ console.log("[web-apple-pay] fallback redirect URL", url.pathname + url.search);
1219
1219
  return url.pathname + url.search;
1220
1220
  };
1221
1221
 
@@ -1313,11 +1313,9 @@ function redirectToFallbackCheckout(config) {
1313
1313
  });
1314
1314
  }
1315
1315
  async function handleMerchantValidation(event, session, config) {
1316
- console.debug("[web-apple-pay] onvalidatemerchant: validating", { validationURL: event.validationURL });
1317
1316
  try {
1318
1317
  const validationHost = new URL(event.validationURL).host;
1319
1318
  if (!validationHost.endsWith("apple.com")) {
1320
- console.debug("[web-apple-pay] onvalidatemerchant: invalid host, aborting", { validationHost });
1321
1319
  session.abort();
1322
1320
  redirectToFallbackCheckout(config);
1323
1321
  return;
@@ -1328,12 +1326,10 @@ async function handleMerchantValidation(event, session, config) {
1328
1326
  recaptchaToken
1329
1327
  });
1330
1328
  if (!response?.merchantSession) {
1331
- console.debug("[web-apple-pay] onvalidatemerchant: no merchantSession in response, aborting");
1332
1329
  session.abort();
1333
1330
  redirectToFallbackCheckout(config);
1334
1331
  return;
1335
1332
  }
1336
- console.debug("[web-apple-pay] onvalidatemerchant: merchant validated successfully");
1337
1333
  session.completeMerchantValidation(response.merchantSession);
1338
1334
  } catch (err) {
1339
1335
  console.error("[web-apple-pay] onvalidatemerchant: error during validation", err);
@@ -1342,14 +1338,6 @@ async function handleMerchantValidation(event, session, config) {
1342
1338
  }
1343
1339
  }
1344
1340
  function startApplePaySession(config) {
1345
- console.debug("[web-apple-pay] startApplePaySession: starting session", {
1346
- skuId: config.skuId,
1347
- countryCode: config.countryCode,
1348
- currencyCode: config.currencyCode,
1349
- supportedNetworks: config.supportedNetworks,
1350
- totalAmount: config.totalAmount,
1351
- userLoggedIn: config.userLoggedIn
1352
- });
1353
1341
  const paymentRequest = {
1354
1342
  countryCode: config.countryCode,
1355
1343
  currencyCode: config.currencyCode,
@@ -1369,15 +1357,12 @@ function startApplePaySession(config) {
1369
1357
  await handleMerchantValidation(event, session, config);
1370
1358
  };
1371
1359
  session.onpaymentauthorized = (event) => {
1372
- console.debug("[web-apple-pay] onpaymentauthorized: payment authorised");
1373
1360
  trackWalletPaymentAuthorised(config.skuId);
1374
1361
  config.onPaymentAuthorized(event, session);
1375
1362
  };
1376
1363
  session.oncancel = () => {
1377
- console.debug("[web-apple-pay] oncancel: user cancelled Apple Pay sheet");
1378
1364
  config.onCancel?.();
1379
1365
  };
1380
- console.debug("[web-apple-pay] startApplePaySession: session.begin()");
1381
1366
  trackWalletPaymentSheetOpen(config.skuId);
1382
1367
  session.begin();
1383
1368
  } catch (err) {
@@ -1990,7 +1975,6 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
1990
1975
  }
1991
1976
  // ─── Render pipeline ────────────────────────────────────────────────────────
1992
1977
  async #run() {
1993
- console.debug("[web-apple-pay] #run: start");
1994
1978
  try {
1995
1979
  if (await this.#checkAvailability()) return;
1996
1980
  if (this.#checkOffer()) return;
@@ -2012,11 +1996,9 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2012
1996
  async #checkAvailability() {
2013
1997
  const available = await isApplePayAvailable();
2014
1998
  if (!available) {
2015
- console.debug("[web-apple-pay] #checkAvailability: not available on this device/browser");
2016
1999
  this.style.display = "none";
2017
2000
  return true;
2018
2001
  }
2019
- console.debug("[web-apple-pay] #checkAvailability: ok");
2020
2002
  return false;
2021
2003
  }
2022
2004
  /**
@@ -2025,24 +2007,19 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2025
2007
  */
2026
2008
  async #checkSession() {
2027
2009
  this.#sessionData = await this.#fetchSession();
2028
- console.debug("[web-apple-pay] #checkSession: session data", { loggedIn: this.#sessionData?.loggedIn, userType: this.#sessionData?.userType });
2029
2010
  if (this.#sessionData?.loggedIn && (this.#sessionData.userType === "active-subscription" || this.#sessionData.userType === "b2b-user")) {
2030
- console.debug("[web-apple-pay] #checkSession: ineligible user, hiding button", { userType: this.#sessionData.userType });
2031
2011
  this.style.display = "none";
2032
2012
  this.querySelector(SEL_CONTAINER)?.remove();
2033
2013
  return true;
2034
2014
  }
2035
- console.debug("[web-apple-pay] #checkSession: ok");
2036
2015
  return false;
2037
2016
  }
2038
2017
  /** Returns `true` (hide) when no offer has been set before mount. */
2039
2018
  #checkOffer() {
2040
2019
  if (!this.#offer) {
2041
- console.debug("[web-apple-pay] #checkOffer: no offer set, hiding button");
2042
2020
  this.style.display = "none";
2043
2021
  return true;
2044
2022
  }
2045
- console.debug("[web-apple-pay] #checkOffer: ok", { skuId: this.#offer.sku_id });
2046
2023
  return false;
2047
2024
  }
2048
2025
  /** Captures the current page URL once at mount for reuse across the session lifetime. */
@@ -2066,19 +2043,15 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2066
2043
  */
2067
2044
  async #fetchAndCacheOptions() {
2068
2045
  this.#paymentOptions = await this.#fetchPaymentOptions();
2069
- console.debug("[web-apple-pay] #fetchAndCacheOptions: payment options", this.#paymentOptions);
2070
2046
  if (!this.#paymentOptions?.options?.apple_pay) {
2071
- console.debug("[web-apple-pay] #fetchAndCacheOptions: apple_pay absent in options, hiding button");
2072
2047
  this.style.display = "none";
2073
2048
  this.querySelector(SEL_CONTAINER)?.remove();
2074
2049
  return true;
2075
2050
  }
2076
- console.debug("[web-apple-pay] #fetchAndCacheOptions: ok", this.#paymentOptions.options.apple_pay);
2077
2051
  return false;
2078
2052
  }
2079
2053
  /** Injects the button template and wires click and confirm event listeners. */
2080
2054
  #renderTemplate() {
2081
- console.debug("[web-apple-pay] #renderTemplate: injecting button template");
2082
2055
  this.style.removeProperty("display");
2083
2056
  ensureApplePayLogoSymbol();
2084
2057
  const template = document.createElement("template");
@@ -2095,7 +2068,6 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2095
2068
  });
2096
2069
  }
2097
2070
  #finishLoading() {
2098
- console.debug("[web-apple-pay] #finishLoading: all checks passed, enabling button");
2099
2071
  const button = this.querySelector(SEL_BUTTON);
2100
2072
  if (button) {
2101
2073
  button.classList.remove("wap-loading");
@@ -1068,25 +1068,20 @@ var isAppleDeviceOrSafari = () => {
1068
1068
  var bypassApplePayChecks = () => new URLSearchParams(window.location.search).get("BYPASS_APPLE_PAY_CHECKS") !== null && getApplePayConfig()?.debugBypassEnabled === true;
1069
1069
  var isApplePayAvailable = async () => {
1070
1070
  if (bypassApplePayChecks()) {
1071
- console.debug("[web-apple-pay] isApplePayAvailable: bypass enabled, returning true");
1072
1071
  return true;
1073
1072
  }
1074
1073
  if (!isAppleDeviceOrSafari()) {
1075
- console.debug("[web-apple-pay] isApplePayAvailable: not an Apple device or Safari", { userAgent: navigator.userAgent });
1076
1074
  return false;
1077
1075
  }
1078
1076
  const applePaySession = window.ApplePaySession;
1079
1077
  if (!applePaySession) {
1080
- console.debug("[web-apple-pay] isApplePayAvailable: ApplePaySession not present on window");
1081
1078
  return false;
1082
1079
  }
1083
1080
  try {
1084
1081
  if (typeof applePaySession.canMakePayments !== "function") {
1085
- console.debug("[web-apple-pay] isApplePayAvailable: canMakePayments is not a function");
1086
1082
  return false;
1087
1083
  }
1088
1084
  if (!applePaySession.canMakePayments()) {
1089
- console.debug("[web-apple-pay] isApplePayAvailable: canMakePayments() returned false");
1090
1085
  return false;
1091
1086
  }
1092
1087
  const merchantId = getApplePayConfig()?.merchantId;
@@ -1097,7 +1092,6 @@ var isApplePayAvailable = async () => {
1097
1092
  return false;
1098
1093
  }
1099
1094
  const hasActiveCard = await applePaySession.canMakePaymentsWithActiveCard(merchantId);
1100
- console.debug("[web-apple-pay] isApplePayAvailable: canMakePaymentsWithActiveCard =", hasActiveCard, { merchantId });
1101
1095
  return hasActiveCard;
1102
1096
  } catch (error) {
1103
1097
  console.error("Error checking Apple Pay active card status:", error);
@@ -1216,14 +1210,20 @@ var redirectToCheckoutComplete = (params) => {
1216
1210
  return url.pathname + url.search;
1217
1211
  };
1218
1212
  var redirectToCheckoutFallback = (params) => {
1213
+ const decodedOffer = decodeSku(params.skuId);
1214
+ console.log("[web-apple-pay] redirectToCheckoutFallback", {
1215
+ rawSkuId: params.skuId,
1216
+ decodedOffer
1217
+ });
1219
1218
  const url = new URL(window.location.href);
1220
1219
  url.pathname = "/checkout";
1221
- url.searchParams.set("lmo_offer", params.skuId);
1220
+ url.searchParams.set("lmo_offer", decodedOffer);
1222
1221
  if (params.inlineError)
1223
1222
  url.searchParams.set("inlineError", params.inlineError);
1224
1223
  if (params.email) url.searchParams.set("email", params.email);
1225
1224
  if (params.emailError) url.searchParams.set("emailError", params.emailError);
1226
1225
  url.searchParams.set("returnUrl", params.returnUrl);
1226
+ console.log("[web-apple-pay] fallback redirect URL", url.pathname + url.search);
1227
1227
  return url.pathname + url.search;
1228
1228
  };
1229
1229
 
@@ -1321,11 +1321,9 @@ function redirectToFallbackCheckout(config) {
1321
1321
  });
1322
1322
  }
1323
1323
  async function handleMerchantValidation(event, session, config) {
1324
- console.debug("[web-apple-pay] onvalidatemerchant: validating", { validationURL: event.validationURL });
1325
1324
  try {
1326
1325
  const validationHost = new URL(event.validationURL).host;
1327
1326
  if (!validationHost.endsWith("apple.com")) {
1328
- console.debug("[web-apple-pay] onvalidatemerchant: invalid host, aborting", { validationHost });
1329
1327
  session.abort();
1330
1328
  redirectToFallbackCheckout(config);
1331
1329
  return;
@@ -1336,12 +1334,10 @@ async function handleMerchantValidation(event, session, config) {
1336
1334
  recaptchaToken
1337
1335
  });
1338
1336
  if (!response?.merchantSession) {
1339
- console.debug("[web-apple-pay] onvalidatemerchant: no merchantSession in response, aborting");
1340
1337
  session.abort();
1341
1338
  redirectToFallbackCheckout(config);
1342
1339
  return;
1343
1340
  }
1344
- console.debug("[web-apple-pay] onvalidatemerchant: merchant validated successfully");
1345
1341
  session.completeMerchantValidation(response.merchantSession);
1346
1342
  } catch (err) {
1347
1343
  console.error("[web-apple-pay] onvalidatemerchant: error during validation", err);
@@ -1350,14 +1346,6 @@ async function handleMerchantValidation(event, session, config) {
1350
1346
  }
1351
1347
  }
1352
1348
  function startApplePaySession(config) {
1353
- console.debug("[web-apple-pay] startApplePaySession: starting session", {
1354
- skuId: config.skuId,
1355
- countryCode: config.countryCode,
1356
- currencyCode: config.currencyCode,
1357
- supportedNetworks: config.supportedNetworks,
1358
- totalAmount: config.totalAmount,
1359
- userLoggedIn: config.userLoggedIn
1360
- });
1361
1349
  const paymentRequest = {
1362
1350
  countryCode: config.countryCode,
1363
1351
  currencyCode: config.currencyCode,
@@ -1377,15 +1365,12 @@ function startApplePaySession(config) {
1377
1365
  await handleMerchantValidation(event, session, config);
1378
1366
  };
1379
1367
  session.onpaymentauthorized = (event) => {
1380
- console.debug("[web-apple-pay] onpaymentauthorized: payment authorised");
1381
1368
  trackWalletPaymentAuthorised(config.skuId);
1382
1369
  config.onPaymentAuthorized(event, session);
1383
1370
  };
1384
1371
  session.oncancel = () => {
1385
- console.debug("[web-apple-pay] oncancel: user cancelled Apple Pay sheet");
1386
1372
  config.onCancel?.();
1387
1373
  };
1388
- console.debug("[web-apple-pay] startApplePaySession: session.begin()");
1389
1374
  trackWalletPaymentSheetOpen(config.skuId);
1390
1375
  session.begin();
1391
1376
  } catch (err) {
@@ -1998,7 +1983,6 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
1998
1983
  }
1999
1984
  // ─── Render pipeline ────────────────────────────────────────────────────────
2000
1985
  async #run() {
2001
- console.debug("[web-apple-pay] #run: start");
2002
1986
  try {
2003
1987
  if (await this.#checkAvailability()) return;
2004
1988
  if (this.#checkOffer()) return;
@@ -2020,11 +2004,9 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2020
2004
  async #checkAvailability() {
2021
2005
  const available = await isApplePayAvailable();
2022
2006
  if (!available) {
2023
- console.debug("[web-apple-pay] #checkAvailability: not available on this device/browser");
2024
2007
  this.style.display = "none";
2025
2008
  return true;
2026
2009
  }
2027
- console.debug("[web-apple-pay] #checkAvailability: ok");
2028
2010
  return false;
2029
2011
  }
2030
2012
  /**
@@ -2033,24 +2015,19 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2033
2015
  */
2034
2016
  async #checkSession() {
2035
2017
  this.#sessionData = await this.#fetchSession();
2036
- console.debug("[web-apple-pay] #checkSession: session data", { loggedIn: this.#sessionData?.loggedIn, userType: this.#sessionData?.userType });
2037
2018
  if (this.#sessionData?.loggedIn && (this.#sessionData.userType === "active-subscription" || this.#sessionData.userType === "b2b-user")) {
2038
- console.debug("[web-apple-pay] #checkSession: ineligible user, hiding button", { userType: this.#sessionData.userType });
2039
2019
  this.style.display = "none";
2040
2020
  this.querySelector(SEL_CONTAINER)?.remove();
2041
2021
  return true;
2042
2022
  }
2043
- console.debug("[web-apple-pay] #checkSession: ok");
2044
2023
  return false;
2045
2024
  }
2046
2025
  /** Returns `true` (hide) when no offer has been set before mount. */
2047
2026
  #checkOffer() {
2048
2027
  if (!this.#offer) {
2049
- console.debug("[web-apple-pay] #checkOffer: no offer set, hiding button");
2050
2028
  this.style.display = "none";
2051
2029
  return true;
2052
2030
  }
2053
- console.debug("[web-apple-pay] #checkOffer: ok", { skuId: this.#offer.sku_id });
2054
2031
  return false;
2055
2032
  }
2056
2033
  /** Captures the current page URL once at mount for reuse across the session lifetime. */
@@ -2074,19 +2051,15 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2074
2051
  */
2075
2052
  async #fetchAndCacheOptions() {
2076
2053
  this.#paymentOptions = await this.#fetchPaymentOptions();
2077
- console.debug("[web-apple-pay] #fetchAndCacheOptions: payment options", this.#paymentOptions);
2078
2054
  if (!this.#paymentOptions?.options?.apple_pay) {
2079
- console.debug("[web-apple-pay] #fetchAndCacheOptions: apple_pay absent in options, hiding button");
2080
2055
  this.style.display = "none";
2081
2056
  this.querySelector(SEL_CONTAINER)?.remove();
2082
2057
  return true;
2083
2058
  }
2084
- console.debug("[web-apple-pay] #fetchAndCacheOptions: ok", this.#paymentOptions.options.apple_pay);
2085
2059
  return false;
2086
2060
  }
2087
2061
  /** Injects the button template and wires click and confirm event listeners. */
2088
2062
  #renderTemplate() {
2089
- console.debug("[web-apple-pay] #renderTemplate: injecting button template");
2090
2063
  this.style.removeProperty("display");
2091
2064
  ensureApplePayLogoSymbol();
2092
2065
  const template = document.createElement("template");
@@ -2103,7 +2076,6 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2103
2076
  });
2104
2077
  }
2105
2078
  #finishLoading() {
2106
- console.debug("[web-apple-pay] #finishLoading: all checks passed, enabling button");
2107
2079
  const button = this.querySelector(SEL_BUTTON);
2108
2080
  if (button) {
2109
2081
  button.classList.remove("wap-loading");
@@ -1060,25 +1060,20 @@ var isAppleDeviceOrSafari = () => {
1060
1060
  var bypassApplePayChecks = () => new URLSearchParams(window.location.search).get("BYPASS_APPLE_PAY_CHECKS") !== null && getApplePayConfig()?.debugBypassEnabled === true;
1061
1061
  var isApplePayAvailable = async () => {
1062
1062
  if (bypassApplePayChecks()) {
1063
- console.debug("[web-apple-pay] isApplePayAvailable: bypass enabled, returning true");
1064
1063
  return true;
1065
1064
  }
1066
1065
  if (!isAppleDeviceOrSafari()) {
1067
- console.debug("[web-apple-pay] isApplePayAvailable: not an Apple device or Safari", { userAgent: navigator.userAgent });
1068
1066
  return false;
1069
1067
  }
1070
1068
  const applePaySession = window.ApplePaySession;
1071
1069
  if (!applePaySession) {
1072
- console.debug("[web-apple-pay] isApplePayAvailable: ApplePaySession not present on window");
1073
1070
  return false;
1074
1071
  }
1075
1072
  try {
1076
1073
  if (typeof applePaySession.canMakePayments !== "function") {
1077
- console.debug("[web-apple-pay] isApplePayAvailable: canMakePayments is not a function");
1078
1074
  return false;
1079
1075
  }
1080
1076
  if (!applePaySession.canMakePayments()) {
1081
- console.debug("[web-apple-pay] isApplePayAvailable: canMakePayments() returned false");
1082
1077
  return false;
1083
1078
  }
1084
1079
  const merchantId = getApplePayConfig()?.merchantId;
@@ -1089,7 +1084,6 @@ var isApplePayAvailable = async () => {
1089
1084
  return false;
1090
1085
  }
1091
1086
  const hasActiveCard = await applePaySession.canMakePaymentsWithActiveCard(merchantId);
1092
- console.debug("[web-apple-pay] isApplePayAvailable: canMakePaymentsWithActiveCard =", hasActiveCard, { merchantId });
1093
1087
  return hasActiveCard;
1094
1088
  } catch (error) {
1095
1089
  console.error("Error checking Apple Pay active card status:", error);
@@ -1208,14 +1202,20 @@ var redirectToCheckoutComplete = (params) => {
1208
1202
  return url.pathname + url.search;
1209
1203
  };
1210
1204
  var redirectToCheckoutFallback = (params) => {
1205
+ const decodedOffer = decodeSku(params.skuId);
1206
+ console.log("[web-apple-pay] redirectToCheckoutFallback", {
1207
+ rawSkuId: params.skuId,
1208
+ decodedOffer
1209
+ });
1211
1210
  const url = new URL(window.location.href);
1212
1211
  url.pathname = "/checkout";
1213
- url.searchParams.set("lmo_offer", params.skuId);
1212
+ url.searchParams.set("lmo_offer", decodedOffer);
1214
1213
  if (params.inlineError)
1215
1214
  url.searchParams.set("inlineError", params.inlineError);
1216
1215
  if (params.email) url.searchParams.set("email", params.email);
1217
1216
  if (params.emailError) url.searchParams.set("emailError", params.emailError);
1218
1217
  url.searchParams.set("returnUrl", params.returnUrl);
1218
+ console.log("[web-apple-pay] fallback redirect URL", url.pathname + url.search);
1219
1219
  return url.pathname + url.search;
1220
1220
  };
1221
1221
 
@@ -1313,11 +1313,9 @@ function redirectToFallbackCheckout(config) {
1313
1313
  });
1314
1314
  }
1315
1315
  async function handleMerchantValidation(event, session, config) {
1316
- console.debug("[web-apple-pay] onvalidatemerchant: validating", { validationURL: event.validationURL });
1317
1316
  try {
1318
1317
  const validationHost = new URL(event.validationURL).host;
1319
1318
  if (!validationHost.endsWith("apple.com")) {
1320
- console.debug("[web-apple-pay] onvalidatemerchant: invalid host, aborting", { validationHost });
1321
1319
  session.abort();
1322
1320
  redirectToFallbackCheckout(config);
1323
1321
  return;
@@ -1328,12 +1326,10 @@ async function handleMerchantValidation(event, session, config) {
1328
1326
  recaptchaToken
1329
1327
  });
1330
1328
  if (!response?.merchantSession) {
1331
- console.debug("[web-apple-pay] onvalidatemerchant: no merchantSession in response, aborting");
1332
1329
  session.abort();
1333
1330
  redirectToFallbackCheckout(config);
1334
1331
  return;
1335
1332
  }
1336
- console.debug("[web-apple-pay] onvalidatemerchant: merchant validated successfully");
1337
1333
  session.completeMerchantValidation(response.merchantSession);
1338
1334
  } catch (err) {
1339
1335
  console.error("[web-apple-pay] onvalidatemerchant: error during validation", err);
@@ -1342,14 +1338,6 @@ async function handleMerchantValidation(event, session, config) {
1342
1338
  }
1343
1339
  }
1344
1340
  function startApplePaySession(config) {
1345
- console.debug("[web-apple-pay] startApplePaySession: starting session", {
1346
- skuId: config.skuId,
1347
- countryCode: config.countryCode,
1348
- currencyCode: config.currencyCode,
1349
- supportedNetworks: config.supportedNetworks,
1350
- totalAmount: config.totalAmount,
1351
- userLoggedIn: config.userLoggedIn
1352
- });
1353
1341
  const paymentRequest = {
1354
1342
  countryCode: config.countryCode,
1355
1343
  currencyCode: config.currencyCode,
@@ -1369,15 +1357,12 @@ function startApplePaySession(config) {
1369
1357
  await handleMerchantValidation(event, session, config);
1370
1358
  };
1371
1359
  session.onpaymentauthorized = (event) => {
1372
- console.debug("[web-apple-pay] onpaymentauthorized: payment authorised");
1373
1360
  trackWalletPaymentAuthorised(config.skuId);
1374
1361
  config.onPaymentAuthorized(event, session);
1375
1362
  };
1376
1363
  session.oncancel = () => {
1377
- console.debug("[web-apple-pay] oncancel: user cancelled Apple Pay sheet");
1378
1364
  config.onCancel?.();
1379
1365
  };
1380
- console.debug("[web-apple-pay] startApplePaySession: session.begin()");
1381
1366
  trackWalletPaymentSheetOpen(config.skuId);
1382
1367
  session.begin();
1383
1368
  } catch (err) {
@@ -1990,7 +1975,6 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
1990
1975
  }
1991
1976
  // ─── Render pipeline ────────────────────────────────────────────────────────
1992
1977
  async #run() {
1993
- console.debug("[web-apple-pay] #run: start");
1994
1978
  try {
1995
1979
  if (await this.#checkAvailability()) return;
1996
1980
  if (this.#checkOffer()) return;
@@ -2012,11 +1996,9 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2012
1996
  async #checkAvailability() {
2013
1997
  const available = await isApplePayAvailable();
2014
1998
  if (!available) {
2015
- console.debug("[web-apple-pay] #checkAvailability: not available on this device/browser");
2016
1999
  this.style.display = "none";
2017
2000
  return true;
2018
2001
  }
2019
- console.debug("[web-apple-pay] #checkAvailability: ok");
2020
2002
  return false;
2021
2003
  }
2022
2004
  /**
@@ -2025,24 +2007,19 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2025
2007
  */
2026
2008
  async #checkSession() {
2027
2009
  this.#sessionData = await this.#fetchSession();
2028
- console.debug("[web-apple-pay] #checkSession: session data", { loggedIn: this.#sessionData?.loggedIn, userType: this.#sessionData?.userType });
2029
2010
  if (this.#sessionData?.loggedIn && (this.#sessionData.userType === "active-subscription" || this.#sessionData.userType === "b2b-user")) {
2030
- console.debug("[web-apple-pay] #checkSession: ineligible user, hiding button", { userType: this.#sessionData.userType });
2031
2011
  this.style.display = "none";
2032
2012
  this.querySelector(SEL_CONTAINER)?.remove();
2033
2013
  return true;
2034
2014
  }
2035
- console.debug("[web-apple-pay] #checkSession: ok");
2036
2015
  return false;
2037
2016
  }
2038
2017
  /** Returns `true` (hide) when no offer has been set before mount. */
2039
2018
  #checkOffer() {
2040
2019
  if (!this.#offer) {
2041
- console.debug("[web-apple-pay] #checkOffer: no offer set, hiding button");
2042
2020
  this.style.display = "none";
2043
2021
  return true;
2044
2022
  }
2045
- console.debug("[web-apple-pay] #checkOffer: ok", { skuId: this.#offer.sku_id });
2046
2023
  return false;
2047
2024
  }
2048
2025
  /** Captures the current page URL once at mount for reuse across the session lifetime. */
@@ -2066,19 +2043,15 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2066
2043
  */
2067
2044
  async #fetchAndCacheOptions() {
2068
2045
  this.#paymentOptions = await this.#fetchPaymentOptions();
2069
- console.debug("[web-apple-pay] #fetchAndCacheOptions: payment options", this.#paymentOptions);
2070
2046
  if (!this.#paymentOptions?.options?.apple_pay) {
2071
- console.debug("[web-apple-pay] #fetchAndCacheOptions: apple_pay absent in options, hiding button");
2072
2047
  this.style.display = "none";
2073
2048
  this.querySelector(SEL_CONTAINER)?.remove();
2074
2049
  return true;
2075
2050
  }
2076
- console.debug("[web-apple-pay] #fetchAndCacheOptions: ok", this.#paymentOptions.options.apple_pay);
2077
2051
  return false;
2078
2052
  }
2079
2053
  /** Injects the button template and wires click and confirm event listeners. */
2080
2054
  #renderTemplate() {
2081
- console.debug("[web-apple-pay] #renderTemplate: injecting button template");
2082
2055
  this.style.removeProperty("display");
2083
2056
  ensureApplePayLogoSymbol();
2084
2057
  const template = document.createElement("template");
@@ -2095,7 +2068,6 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2095
2068
  });
2096
2069
  }
2097
2070
  #finishLoading() {
2098
- console.debug("[web-apple-pay] #finishLoading: all checks passed, enabling button");
2099
2071
  const button = this.querySelector(SEL_BUTTON);
2100
2072
  if (button) {
2101
2073
  button.classList.remove("wap-loading");
@@ -62,15 +62,28 @@ var validateAppleMerchant = (data) => {
62
62
  };
63
63
 
64
64
  // src/utils/expressCheckoutRedirect.ts
65
+ var decodeSku = (sku) => {
66
+ try {
67
+ return atob(sku.substring(sku.indexOf("-") + 1));
68
+ } catch {
69
+ return sku;
70
+ }
71
+ };
65
72
  var redirectToCheckoutFallback = (params) => {
73
+ const decodedOffer = decodeSku(params.skuId);
74
+ console.log("[web-apple-pay] redirectToCheckoutFallback", {
75
+ rawSkuId: params.skuId,
76
+ decodedOffer
77
+ });
66
78
  const url = new URL(window.location.href);
67
79
  url.pathname = "/checkout";
68
- url.searchParams.set("lmo_offer", params.skuId);
80
+ url.searchParams.set("lmo_offer", decodedOffer);
69
81
  if (params.inlineError)
70
82
  url.searchParams.set("inlineError", params.inlineError);
71
83
  if (params.email) url.searchParams.set("email", params.email);
72
84
  if (params.emailError) url.searchParams.set("emailError", params.emailError);
73
85
  url.searchParams.set("returnUrl", params.returnUrl);
86
+ console.log("[web-apple-pay] fallback redirect URL", url.pathname + url.search);
74
87
  return url.pathname + url.search;
75
88
  };
76
89
 
@@ -167,11 +180,9 @@ function redirectToFallbackCheckout(config) {
167
180
  });
168
181
  }
169
182
  async function handleMerchantValidation(event, session, config) {
170
- console.debug("[web-apple-pay] onvalidatemerchant: validating", { validationURL: event.validationURL });
171
183
  try {
172
184
  const validationHost = new URL(event.validationURL).host;
173
185
  if (!validationHost.endsWith("apple.com")) {
174
- console.debug("[web-apple-pay] onvalidatemerchant: invalid host, aborting", { validationHost });
175
186
  session.abort();
176
187
  redirectToFallbackCheckout(config);
177
188
  return;
@@ -182,12 +193,10 @@ async function handleMerchantValidation(event, session, config) {
182
193
  recaptchaToken
183
194
  });
184
195
  if (!response?.merchantSession) {
185
- console.debug("[web-apple-pay] onvalidatemerchant: no merchantSession in response, aborting");
186
196
  session.abort();
187
197
  redirectToFallbackCheckout(config);
188
198
  return;
189
199
  }
190
- console.debug("[web-apple-pay] onvalidatemerchant: merchant validated successfully");
191
200
  session.completeMerchantValidation(response.merchantSession);
192
201
  } catch (err) {
193
202
  console.error("[web-apple-pay] onvalidatemerchant: error during validation", err);
@@ -196,14 +205,6 @@ async function handleMerchantValidation(event, session, config) {
196
205
  }
197
206
  }
198
207
  function startApplePaySession(config) {
199
- console.debug("[web-apple-pay] startApplePaySession: starting session", {
200
- skuId: config.skuId,
201
- countryCode: config.countryCode,
202
- currencyCode: config.currencyCode,
203
- supportedNetworks: config.supportedNetworks,
204
- totalAmount: config.totalAmount,
205
- userLoggedIn: config.userLoggedIn
206
- });
207
208
  const paymentRequest = {
208
209
  countryCode: config.countryCode,
209
210
  currencyCode: config.currencyCode,
@@ -223,15 +224,12 @@ function startApplePaySession(config) {
223
224
  await handleMerchantValidation(event, session, config);
224
225
  };
225
226
  session.onpaymentauthorized = (event) => {
226
- console.debug("[web-apple-pay] onpaymentauthorized: payment authorised");
227
227
  trackWalletPaymentAuthorised(config.skuId);
228
228
  config.onPaymentAuthorized(event, session);
229
229
  };
230
230
  session.oncancel = () => {
231
- console.debug("[web-apple-pay] oncancel: user cancelled Apple Pay sheet");
232
231
  config.onCancel?.();
233
232
  };
234
- console.debug("[web-apple-pay] startApplePaySession: session.begin()");
235
233
  trackWalletPaymentSheetOpen(config.skuId);
236
234
  session.begin();
237
235
  } catch (err) {
@@ -11,25 +11,20 @@ var isAppleDeviceOrSafari = () => {
11
11
  var bypassApplePayChecks = () => new URLSearchParams(window.location.search).get("BYPASS_APPLE_PAY_CHECKS") !== null && getApplePayConfig()?.debugBypassEnabled === true;
12
12
  var isApplePayAvailable = async () => {
13
13
  if (bypassApplePayChecks()) {
14
- console.debug("[web-apple-pay] isApplePayAvailable: bypass enabled, returning true");
15
14
  return true;
16
15
  }
17
16
  if (!isAppleDeviceOrSafari()) {
18
- console.debug("[web-apple-pay] isApplePayAvailable: not an Apple device or Safari", { userAgent: navigator.userAgent });
19
17
  return false;
20
18
  }
21
19
  const applePaySession = window.ApplePaySession;
22
20
  if (!applePaySession) {
23
- console.debug("[web-apple-pay] isApplePayAvailable: ApplePaySession not present on window");
24
21
  return false;
25
22
  }
26
23
  try {
27
24
  if (typeof applePaySession.canMakePayments !== "function") {
28
- console.debug("[web-apple-pay] isApplePayAvailable: canMakePayments is not a function");
29
25
  return false;
30
26
  }
31
27
  if (!applePaySession.canMakePayments()) {
32
- console.debug("[web-apple-pay] isApplePayAvailable: canMakePayments() returned false");
33
28
  return false;
34
29
  }
35
30
  const merchantId = getApplePayConfig()?.merchantId;
@@ -40,7 +35,6 @@ var isApplePayAvailable = async () => {
40
35
  return false;
41
36
  }
42
37
  const hasActiveCard = await applePaySession.canMakePaymentsWithActiveCard(merchantId);
43
- console.debug("[web-apple-pay] isApplePayAvailable: canMakePaymentsWithActiveCard =", hasActiveCard, { merchantId });
44
38
  return hasActiveCard;
45
39
  } catch (error) {
46
40
  console.error("Error checking Apple Pay active card status:", error);
@@ -260,14 +260,20 @@ var redirectToCheckoutComplete = (params) => {
260
260
  return url.pathname + url.search;
261
261
  };
262
262
  var redirectToCheckoutFallback = (params) => {
263
+ const decodedOffer = decodeSku(params.skuId);
264
+ console.log("[web-apple-pay] redirectToCheckoutFallback", {
265
+ rawSkuId: params.skuId,
266
+ decodedOffer
267
+ });
263
268
  const url = new URL(window.location.href);
264
269
  url.pathname = "/checkout";
265
- url.searchParams.set("lmo_offer", params.skuId);
270
+ url.searchParams.set("lmo_offer", decodedOffer);
266
271
  if (params.inlineError)
267
272
  url.searchParams.set("inlineError", params.inlineError);
268
273
  if (params.email) url.searchParams.set("email", params.email);
269
274
  if (params.emailError) url.searchParams.set("emailError", params.emailError);
270
275
  url.searchParams.set("returnUrl", params.returnUrl);
276
+ console.log("[web-apple-pay] fallback redirect URL", url.pathname + url.search);
271
277
  return url.pathname + url.search;
272
278
  };
273
279
 
package/dist/src/index.js CHANGED
@@ -1065,25 +1065,20 @@ var isAppleDeviceOrSafari = () => {
1065
1065
  var bypassApplePayChecks = () => new URLSearchParams(window.location.search).get("BYPASS_APPLE_PAY_CHECKS") !== null && getApplePayConfig()?.debugBypassEnabled === true;
1066
1066
  var isApplePayAvailable = async () => {
1067
1067
  if (bypassApplePayChecks()) {
1068
- console.debug("[web-apple-pay] isApplePayAvailable: bypass enabled, returning true");
1069
1068
  return true;
1070
1069
  }
1071
1070
  if (!isAppleDeviceOrSafari()) {
1072
- console.debug("[web-apple-pay] isApplePayAvailable: not an Apple device or Safari", { userAgent: navigator.userAgent });
1073
1071
  return false;
1074
1072
  }
1075
1073
  const applePaySession = window.ApplePaySession;
1076
1074
  if (!applePaySession) {
1077
- console.debug("[web-apple-pay] isApplePayAvailable: ApplePaySession not present on window");
1078
1075
  return false;
1079
1076
  }
1080
1077
  try {
1081
1078
  if (typeof applePaySession.canMakePayments !== "function") {
1082
- console.debug("[web-apple-pay] isApplePayAvailable: canMakePayments is not a function");
1083
1079
  return false;
1084
1080
  }
1085
1081
  if (!applePaySession.canMakePayments()) {
1086
- console.debug("[web-apple-pay] isApplePayAvailable: canMakePayments() returned false");
1087
1082
  return false;
1088
1083
  }
1089
1084
  const merchantId = getApplePayConfig()?.merchantId;
@@ -1094,7 +1089,6 @@ var isApplePayAvailable = async () => {
1094
1089
  return false;
1095
1090
  }
1096
1091
  const hasActiveCard = await applePaySession.canMakePaymentsWithActiveCard(merchantId);
1097
- console.debug("[web-apple-pay] isApplePayAvailable: canMakePaymentsWithActiveCard =", hasActiveCard, { merchantId });
1098
1092
  return hasActiveCard;
1099
1093
  } catch (error) {
1100
1094
  console.error("Error checking Apple Pay active card status:", error);
@@ -1213,14 +1207,20 @@ var redirectToCheckoutComplete = (params) => {
1213
1207
  return url.pathname + url.search;
1214
1208
  };
1215
1209
  var redirectToCheckoutFallback = (params) => {
1210
+ const decodedOffer = decodeSku(params.skuId);
1211
+ console.log("[web-apple-pay] redirectToCheckoutFallback", {
1212
+ rawSkuId: params.skuId,
1213
+ decodedOffer
1214
+ });
1216
1215
  const url = new URL(window.location.href);
1217
1216
  url.pathname = "/checkout";
1218
- url.searchParams.set("lmo_offer", params.skuId);
1217
+ url.searchParams.set("lmo_offer", decodedOffer);
1219
1218
  if (params.inlineError)
1220
1219
  url.searchParams.set("inlineError", params.inlineError);
1221
1220
  if (params.email) url.searchParams.set("email", params.email);
1222
1221
  if (params.emailError) url.searchParams.set("emailError", params.emailError);
1223
1222
  url.searchParams.set("returnUrl", params.returnUrl);
1223
+ console.log("[web-apple-pay] fallback redirect URL", url.pathname + url.search);
1224
1224
  return url.pathname + url.search;
1225
1225
  };
1226
1226
 
@@ -1318,11 +1318,9 @@ function redirectToFallbackCheckout(config) {
1318
1318
  });
1319
1319
  }
1320
1320
  async function handleMerchantValidation(event, session, config) {
1321
- console.debug("[web-apple-pay] onvalidatemerchant: validating", { validationURL: event.validationURL });
1322
1321
  try {
1323
1322
  const validationHost = new URL(event.validationURL).host;
1324
1323
  if (!validationHost.endsWith("apple.com")) {
1325
- console.debug("[web-apple-pay] onvalidatemerchant: invalid host, aborting", { validationHost });
1326
1324
  session.abort();
1327
1325
  redirectToFallbackCheckout(config);
1328
1326
  return;
@@ -1333,12 +1331,10 @@ async function handleMerchantValidation(event, session, config) {
1333
1331
  recaptchaToken
1334
1332
  });
1335
1333
  if (!response?.merchantSession) {
1336
- console.debug("[web-apple-pay] onvalidatemerchant: no merchantSession in response, aborting");
1337
1334
  session.abort();
1338
1335
  redirectToFallbackCheckout(config);
1339
1336
  return;
1340
1337
  }
1341
- console.debug("[web-apple-pay] onvalidatemerchant: merchant validated successfully");
1342
1338
  session.completeMerchantValidation(response.merchantSession);
1343
1339
  } catch (err) {
1344
1340
  console.error("[web-apple-pay] onvalidatemerchant: error during validation", err);
@@ -1347,14 +1343,6 @@ async function handleMerchantValidation(event, session, config) {
1347
1343
  }
1348
1344
  }
1349
1345
  function startApplePaySession(config) {
1350
- console.debug("[web-apple-pay] startApplePaySession: starting session", {
1351
- skuId: config.skuId,
1352
- countryCode: config.countryCode,
1353
- currencyCode: config.currencyCode,
1354
- supportedNetworks: config.supportedNetworks,
1355
- totalAmount: config.totalAmount,
1356
- userLoggedIn: config.userLoggedIn
1357
- });
1358
1346
  const paymentRequest = {
1359
1347
  countryCode: config.countryCode,
1360
1348
  currencyCode: config.currencyCode,
@@ -1374,15 +1362,12 @@ function startApplePaySession(config) {
1374
1362
  await handleMerchantValidation(event, session, config);
1375
1363
  };
1376
1364
  session.onpaymentauthorized = (event) => {
1377
- console.debug("[web-apple-pay] onpaymentauthorized: payment authorised");
1378
1365
  trackWalletPaymentAuthorised(config.skuId);
1379
1366
  config.onPaymentAuthorized(event, session);
1380
1367
  };
1381
1368
  session.oncancel = () => {
1382
- console.debug("[web-apple-pay] oncancel: user cancelled Apple Pay sheet");
1383
1369
  config.onCancel?.();
1384
1370
  };
1385
- console.debug("[web-apple-pay] startApplePaySession: session.begin()");
1386
1371
  trackWalletPaymentSheetOpen(config.skuId);
1387
1372
  session.begin();
1388
1373
  } catch (err) {
@@ -1995,7 +1980,6 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
1995
1980
  }
1996
1981
  // ─── Render pipeline ────────────────────────────────────────────────────────
1997
1982
  async #run() {
1998
- console.debug("[web-apple-pay] #run: start");
1999
1983
  try {
2000
1984
  if (await this.#checkAvailability()) return;
2001
1985
  if (this.#checkOffer()) return;
@@ -2017,11 +2001,9 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2017
2001
  async #checkAvailability() {
2018
2002
  const available = await isApplePayAvailable();
2019
2003
  if (!available) {
2020
- console.debug("[web-apple-pay] #checkAvailability: not available on this device/browser");
2021
2004
  this.style.display = "none";
2022
2005
  return true;
2023
2006
  }
2024
- console.debug("[web-apple-pay] #checkAvailability: ok");
2025
2007
  return false;
2026
2008
  }
2027
2009
  /**
@@ -2030,24 +2012,19 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2030
2012
  */
2031
2013
  async #checkSession() {
2032
2014
  this.#sessionData = await this.#fetchSession();
2033
- console.debug("[web-apple-pay] #checkSession: session data", { loggedIn: this.#sessionData?.loggedIn, userType: this.#sessionData?.userType });
2034
2015
  if (this.#sessionData?.loggedIn && (this.#sessionData.userType === "active-subscription" || this.#sessionData.userType === "b2b-user")) {
2035
- console.debug("[web-apple-pay] #checkSession: ineligible user, hiding button", { userType: this.#sessionData.userType });
2036
2016
  this.style.display = "none";
2037
2017
  this.querySelector(SEL_CONTAINER)?.remove();
2038
2018
  return true;
2039
2019
  }
2040
- console.debug("[web-apple-pay] #checkSession: ok");
2041
2020
  return false;
2042
2021
  }
2043
2022
  /** Returns `true` (hide) when no offer has been set before mount. */
2044
2023
  #checkOffer() {
2045
2024
  if (!this.#offer) {
2046
- console.debug("[web-apple-pay] #checkOffer: no offer set, hiding button");
2047
2025
  this.style.display = "none";
2048
2026
  return true;
2049
2027
  }
2050
- console.debug("[web-apple-pay] #checkOffer: ok", { skuId: this.#offer.sku_id });
2051
2028
  return false;
2052
2029
  }
2053
2030
  /** Captures the current page URL once at mount for reuse across the session lifetime. */
@@ -2071,19 +2048,15 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2071
2048
  */
2072
2049
  async #fetchAndCacheOptions() {
2073
2050
  this.#paymentOptions = await this.#fetchPaymentOptions();
2074
- console.debug("[web-apple-pay] #fetchAndCacheOptions: payment options", this.#paymentOptions);
2075
2051
  if (!this.#paymentOptions?.options?.apple_pay) {
2076
- console.debug("[web-apple-pay] #fetchAndCacheOptions: apple_pay absent in options, hiding button");
2077
2052
  this.style.display = "none";
2078
2053
  this.querySelector(SEL_CONTAINER)?.remove();
2079
2054
  return true;
2080
2055
  }
2081
- console.debug("[web-apple-pay] #fetchAndCacheOptions: ok", this.#paymentOptions.options.apple_pay);
2082
2056
  return false;
2083
2057
  }
2084
2058
  /** Injects the button template and wires click and confirm event listeners. */
2085
2059
  #renderTemplate() {
2086
- console.debug("[web-apple-pay] #renderTemplate: injecting button template");
2087
2060
  this.style.removeProperty("display");
2088
2061
  ensureApplePayLogoSymbol();
2089
2062
  const template = document.createElement("template");
@@ -2100,7 +2073,6 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2100
2073
  });
2101
2074
  }
2102
2075
  #finishLoading() {
2103
- console.debug("[web-apple-pay] #finishLoading: all checks passed, enabling button");
2104
2076
  const button = this.querySelector(SEL_BUTTON);
2105
2077
  if (button) {
2106
2078
  button.classList.remove("wap-loading");
@@ -27,14 +27,20 @@ var redirectToCheckoutComplete = (params) => {
27
27
  return url.pathname + url.search;
28
28
  };
29
29
  var redirectToCheckoutFallback = (params) => {
30
+ const decodedOffer = decodeSku(params.skuId);
31
+ console.log("[web-apple-pay] redirectToCheckoutFallback", {
32
+ rawSkuId: params.skuId,
33
+ decodedOffer
34
+ });
30
35
  const url = new URL(window.location.href);
31
36
  url.pathname = "/checkout";
32
- url.searchParams.set("lmo_offer", params.skuId);
37
+ url.searchParams.set("lmo_offer", decodedOffer);
33
38
  if (params.inlineError)
34
39
  url.searchParams.set("inlineError", params.inlineError);
35
40
  if (params.email) url.searchParams.set("email", params.email);
36
41
  if (params.emailError) url.searchParams.set("emailError", params.emailError);
37
42
  url.searchParams.set("returnUrl", params.returnUrl);
43
+ console.log("[web-apple-pay] fallback redirect URL", url.pathname + url.search);
38
44
  return url.pathname + url.search;
39
45
  };
40
46
  export {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@economist/web-apple-pay",
3
3
  "description": "Web component package for Apple Pay checkout UI",
4
- "version": "0.1.3-beta.15",
4
+ "version": "0.1.3-beta.17",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",