@economist/web-apple-pay 0.1.3-beta.31 → 0.1.3-beta.32

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
@@ -956,7 +956,6 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
956
956
  cta.removeAttribute("aria-busy");
957
957
  }
958
958
  }).catch(() => {
959
- console.error("[web-apple-pay] apple-pay-modal: failed to pre-fetch reCAPTCHA tokens; CTA remains disabled");
960
959
  if (cta) {
961
960
  cta.removeAttribute("aria-busy");
962
961
  }
@@ -1142,15 +1141,11 @@ var isApplePayAvailable = async () => {
1142
1141
  }
1143
1142
  const merchantId = getApplePayConfig()?.merchantId;
1144
1143
  if (!merchantId) {
1145
- console.warn(
1146
- "[web-apple-pay] Missing merchantId. Call configureApplePay({ merchantId, ... }) before rendering Apple Pay components."
1147
- );
1148
1144
  return false;
1149
1145
  }
1150
1146
  const hasActiveCard = await applePaySession.canMakePaymentsWithActiveCard(merchantId);
1151
1147
  return hasActiveCard;
1152
- } catch (error) {
1153
- console.error("Error checking Apple Pay active card status:", error);
1148
+ } catch {
1154
1149
  return false;
1155
1150
  }
1156
1151
  };
@@ -1397,8 +1392,7 @@ async function handleMerchantValidation(event, session, config) {
1397
1392
  return;
1398
1393
  }
1399
1394
  session.completeMerchantValidation(response.merchantSession);
1400
- } catch (err) {
1401
- console.error("[web-apple-pay] onvalidatemerchant: error during validation", err);
1395
+ } catch {
1402
1396
  session.abort();
1403
1397
  redirectToFallbackCheckout(config);
1404
1398
  }
@@ -1431,8 +1425,7 @@ function startApplePaySession(config) {
1431
1425
  };
1432
1426
  trackWalletPaymentSheetOpen(config.skuId);
1433
1427
  session.begin();
1434
- } catch (err) {
1435
- console.error("[web-apple-pay] startApplePaySession: failed to create session", err);
1428
+ } catch {
1436
1429
  redirectToFallbackCheckout(config);
1437
1430
  }
1438
1431
  }
@@ -1647,7 +1640,6 @@ async function handlePaymentAuthorized(event, session, sessionData, config) {
1647
1640
  failApplePaySession(session, err.errors);
1648
1641
  return;
1649
1642
  }
1650
- console.error("[web-apple-pay] onpaymentauthorized error", { skuId, err });
1651
1643
  const walletError = parseWalletApiError(err);
1652
1644
  trackWalletPaymentFailure(skuId, walletError?.errorType ?? "UNKNOWN");
1653
1645
  failApplePaySession(session);
@@ -1925,7 +1917,6 @@ var FEATURE_APPLE_PAY_EXPRESS_CHECKOUT = "FEATURE_APPLE_PAY_EXPRESS_CHECKOUT";
1925
1917
  var TOTAL_LABEL = "The Economist";
1926
1918
  var DEFAULT_CURRENCY = "USD";
1927
1919
  var DEFAULT_TOTAL = "0.00";
1928
- var ERROR_INITIATE = "Failed to initiate Apple Pay session:";
1929
1920
  var SEL_CONTAINER = ".apple-pay-container";
1930
1921
  var SEL_BUTTON = ".apple-pay-btn";
1931
1922
  var APPLE_PAY_EXCLUDED_VARIANTS = [
@@ -2049,19 +2040,203 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2049
2040
  // ─── Render pipeline ────────────────────────────────────────────────────────
2050
2041
  async #run() {
2051
2042
  try {
2043
+ console.log(
2044
+ "[ApplePayButton] #run start",
2045
+ JSON.stringify(
2046
+ {
2047
+ country: this.#country,
2048
+ offer_sku: this.#offer?.sku_id,
2049
+ entry_point: this.#entryPoint
2050
+ },
2051
+ null,
2052
+ 2
2053
+ )
2054
+ );
2052
2055
  this.#renderTemplate();
2053
- if (await this.#checkAvailability()) return;
2054
- if (this.#checkOffer()) return;
2055
- if (await this.#checkSession()) return;
2056
+ console.log(
2057
+ "[ApplePayButton] #renderTemplate done",
2058
+ JSON.stringify(
2059
+ {
2060
+ country: this.#country,
2061
+ offer_sku: this.#offer?.sku_id
2062
+ },
2063
+ null,
2064
+ 2
2065
+ )
2066
+ );
2067
+ const availabilityBlocked = await this.#checkAvailability();
2068
+ console.log(
2069
+ "[ApplePayButton] #checkAvailability result",
2070
+ JSON.stringify(
2071
+ {
2072
+ blocked: availabilityBlocked,
2073
+ country: this.#country,
2074
+ offer_sku: this.#offer?.sku_id
2075
+ },
2076
+ null,
2077
+ 2
2078
+ )
2079
+ );
2080
+ if (availabilityBlocked) {
2081
+ console.log(
2082
+ "[ApplePayButton] #run early return after #checkAvailability",
2083
+ JSON.stringify(
2084
+ {
2085
+ country: this.#country,
2086
+ offer_sku: this.#offer?.sku_id
2087
+ },
2088
+ null,
2089
+ 2
2090
+ )
2091
+ );
2092
+ return;
2093
+ }
2094
+ const offerMissing = this.#checkOffer();
2095
+ console.log(
2096
+ "[ApplePayButton] #checkOffer result",
2097
+ JSON.stringify(
2098
+ {
2099
+ blocked: offerMissing,
2100
+ country: this.#country,
2101
+ offer_sku: this.#offer?.sku_id
2102
+ },
2103
+ null,
2104
+ 2
2105
+ )
2106
+ );
2107
+ if (offerMissing) {
2108
+ console.log(
2109
+ "[ApplePayButton] #run early return after #checkOffer",
2110
+ JSON.stringify(
2111
+ {
2112
+ country: this.#country,
2113
+ offer_sku: this.#offer?.sku_id
2114
+ },
2115
+ null,
2116
+ 2
2117
+ )
2118
+ );
2119
+ return;
2120
+ }
2121
+ const sessionBlocked = await this.#checkSession();
2122
+ console.log(
2123
+ "[ApplePayButton] #checkSession result",
2124
+ JSON.stringify(
2125
+ {
2126
+ blocked: sessionBlocked,
2127
+ country: this.#country,
2128
+ offer_sku: this.#offer?.sku_id,
2129
+ session_user_type: this.#sessionData?.userType,
2130
+ session_logged_in: this.#sessionData?.loggedIn
2131
+ },
2132
+ null,
2133
+ 2
2134
+ )
2135
+ );
2136
+ if (sessionBlocked) {
2137
+ console.log(
2138
+ "[ApplePayButton] #run early return after #checkSession",
2139
+ JSON.stringify(
2140
+ {
2141
+ country: this.#country,
2142
+ offer_sku: this.#offer?.sku_id
2143
+ },
2144
+ null,
2145
+ 2
2146
+ )
2147
+ );
2148
+ return;
2149
+ }
2056
2150
  this.#captureReturnUrl();
2151
+ console.log(
2152
+ "[ApplePayButton] #captureReturnUrl done",
2153
+ JSON.stringify(
2154
+ {
2155
+ return_url: this.#returnUrl
2156
+ },
2157
+ null,
2158
+ 2
2159
+ )
2160
+ );
2057
2161
  this.#computeBillingCountries();
2058
- if (await this.#fetchAndCacheOptions()) return;
2162
+ console.log(
2163
+ "[ApplePayButton] #computeBillingCountries done",
2164
+ JSON.stringify(
2165
+ {
2166
+ supported_billing_countries: this.#supportedBillingCountries
2167
+ },
2168
+ null,
2169
+ 2
2170
+ )
2171
+ );
2172
+ const optionsBlocked = await this.#fetchAndCacheOptions();
2173
+ console.log(
2174
+ "[ApplePayButton] #fetchAndCacheOptions result",
2175
+ JSON.stringify(
2176
+ {
2177
+ blocked: optionsBlocked,
2178
+ has_apple_pay_option: Boolean(this.#paymentOptions?.options?.apple_pay)
2179
+ },
2180
+ null,
2181
+ 2
2182
+ )
2183
+ );
2184
+ if (optionsBlocked) {
2185
+ console.log(
2186
+ "[ApplePayButton] #run early return after #fetchAndCacheOptions",
2187
+ JSON.stringify(
2188
+ {
2189
+ country: this.#country,
2190
+ offer_sku: this.#offer?.sku_id
2191
+ },
2192
+ null,
2193
+ 2
2194
+ )
2195
+ );
2196
+ return;
2197
+ }
2059
2198
  this.#finishLoading();
2060
- } catch (err) {
2061
- console.error("[web-apple-pay] #run: unexpected error, hiding button", err);
2199
+ console.log(
2200
+ "[ApplePayButton] #finishLoading done",
2201
+ JSON.stringify(
2202
+ {
2203
+ country: this.#country,
2204
+ offer_sku: this.#offer?.sku_id
2205
+ },
2206
+ null,
2207
+ 2
2208
+ )
2209
+ );
2210
+ } catch (error) {
2211
+ console.log(
2212
+ "[ApplePayButton] #run failed",
2213
+ JSON.stringify(
2214
+ {
2215
+ country: this.#country,
2216
+ offer_sku: this.#offer?.sku_id,
2217
+ error: error instanceof Error ? {
2218
+ name: error.name,
2219
+ message: error.message,
2220
+ stack: error.stack
2221
+ } : error
2222
+ },
2223
+ null,
2224
+ 2
2225
+ )
2226
+ );
2062
2227
  this.style.display = "none";
2063
2228
  this.querySelector(SEL_CONTAINER)?.remove();
2064
2229
  } finally {
2230
+ console.log(
2231
+ "[ApplePayButton] #run finally",
2232
+ JSON.stringify(
2233
+ {
2234
+ rendering: this.#rendering
2235
+ },
2236
+ null,
2237
+ 2
2238
+ )
2239
+ );
2065
2240
  this.#rendering = false;
2066
2241
  }
2067
2242
  }
@@ -2199,8 +2374,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2199
2374
  */
2200
2375
  #scheduleRecaptchaTokens() {
2201
2376
  const attempt = getPurchaseRecaptchaTokens();
2202
- attempt.catch((err) => {
2203
- console.error("[web-apple-pay] reCAPTCHA token pre-fetch failed; will retry on modal open", err);
2377
+ attempt.catch(() => {
2204
2378
  if (this.#recaptchaTokensPromise === attempt) {
2205
2379
  this.#recaptchaTokensPromise = null;
2206
2380
  }
@@ -2261,8 +2435,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2261
2435
  recaptchaTokens
2262
2436
  )
2263
2437
  );
2264
- } catch (error) {
2265
- console.error(ERROR_INITIATE, error);
2438
+ } catch {
2266
2439
  }
2267
2440
  }
2268
2441
  };
@@ -2271,6 +2444,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2271
2444
  var ApplePayEntryPoint = /* @__PURE__ */ ((ApplePayEntryPoint2) => {
2272
2445
  ApplePayEntryPoint2["PAYWALL"] = "article_paywall";
2273
2446
  ApplePayEntryPoint2["REGWALL"] = "article_regwall";
2447
+ ApplePayEntryPoint2["DUAL_OFFER_BANNER"] = "dual_offer_banner";
2274
2448
  return ApplePayEntryPoint2;
2275
2449
  })(ApplePayEntryPoint || {});
2276
2450
 
@@ -951,7 +951,6 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
951
951
  cta.removeAttribute("aria-busy");
952
952
  }
953
953
  }).catch(() => {
954
- console.error("[web-apple-pay] apple-pay-modal: failed to pre-fetch reCAPTCHA tokens; CTA remains disabled");
955
954
  if (cta) {
956
955
  cta.removeAttribute("aria-busy");
957
956
  }
@@ -1137,15 +1136,11 @@ var isApplePayAvailable = async () => {
1137
1136
  }
1138
1137
  const merchantId = getApplePayConfig()?.merchantId;
1139
1138
  if (!merchantId) {
1140
- console.warn(
1141
- "[web-apple-pay] Missing merchantId. Call configureApplePay({ merchantId, ... }) before rendering Apple Pay components."
1142
- );
1143
1139
  return false;
1144
1140
  }
1145
1141
  const hasActiveCard = await applePaySession.canMakePaymentsWithActiveCard(merchantId);
1146
1142
  return hasActiveCard;
1147
- } catch (error) {
1148
- console.error("Error checking Apple Pay active card status:", error);
1143
+ } catch {
1149
1144
  return false;
1150
1145
  }
1151
1146
  };
@@ -1392,8 +1387,7 @@ async function handleMerchantValidation(event, session, config) {
1392
1387
  return;
1393
1388
  }
1394
1389
  session.completeMerchantValidation(response.merchantSession);
1395
- } catch (err) {
1396
- console.error("[web-apple-pay] onvalidatemerchant: error during validation", err);
1390
+ } catch {
1397
1391
  session.abort();
1398
1392
  redirectToFallbackCheckout(config);
1399
1393
  }
@@ -1426,8 +1420,7 @@ function startApplePaySession(config) {
1426
1420
  };
1427
1421
  trackWalletPaymentSheetOpen(config.skuId);
1428
1422
  session.begin();
1429
- } catch (err) {
1430
- console.error("[web-apple-pay] startApplePaySession: failed to create session", err);
1423
+ } catch {
1431
1424
  redirectToFallbackCheckout(config);
1432
1425
  }
1433
1426
  }
@@ -1642,7 +1635,6 @@ async function handlePaymentAuthorized(event, session, sessionData, config) {
1642
1635
  failApplePaySession(session, err.errors);
1643
1636
  return;
1644
1637
  }
1645
- console.error("[web-apple-pay] onpaymentauthorized error", { skuId, err });
1646
1638
  const walletError = parseWalletApiError(err);
1647
1639
  trackWalletPaymentFailure(skuId, walletError?.errorType ?? "UNKNOWN");
1648
1640
  failApplePaySession(session);
@@ -1920,7 +1912,6 @@ var FEATURE_APPLE_PAY_EXPRESS_CHECKOUT = "FEATURE_APPLE_PAY_EXPRESS_CHECKOUT";
1920
1912
  var TOTAL_LABEL = "The Economist";
1921
1913
  var DEFAULT_CURRENCY = "USD";
1922
1914
  var DEFAULT_TOTAL = "0.00";
1923
- var ERROR_INITIATE = "Failed to initiate Apple Pay session:";
1924
1915
  var SEL_CONTAINER = ".apple-pay-container";
1925
1916
  var SEL_BUTTON = ".apple-pay-btn";
1926
1917
  var APPLE_PAY_EXCLUDED_VARIANTS = [
@@ -2044,19 +2035,203 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2044
2035
  // ─── Render pipeline ────────────────────────────────────────────────────────
2045
2036
  async #run() {
2046
2037
  try {
2038
+ console.log(
2039
+ "[ApplePayButton] #run start",
2040
+ JSON.stringify(
2041
+ {
2042
+ country: this.#country,
2043
+ offer_sku: this.#offer?.sku_id,
2044
+ entry_point: this.#entryPoint
2045
+ },
2046
+ null,
2047
+ 2
2048
+ )
2049
+ );
2047
2050
  this.#renderTemplate();
2048
- if (await this.#checkAvailability()) return;
2049
- if (this.#checkOffer()) return;
2050
- if (await this.#checkSession()) return;
2051
+ console.log(
2052
+ "[ApplePayButton] #renderTemplate done",
2053
+ JSON.stringify(
2054
+ {
2055
+ country: this.#country,
2056
+ offer_sku: this.#offer?.sku_id
2057
+ },
2058
+ null,
2059
+ 2
2060
+ )
2061
+ );
2062
+ const availabilityBlocked = await this.#checkAvailability();
2063
+ console.log(
2064
+ "[ApplePayButton] #checkAvailability result",
2065
+ JSON.stringify(
2066
+ {
2067
+ blocked: availabilityBlocked,
2068
+ country: this.#country,
2069
+ offer_sku: this.#offer?.sku_id
2070
+ },
2071
+ null,
2072
+ 2
2073
+ )
2074
+ );
2075
+ if (availabilityBlocked) {
2076
+ console.log(
2077
+ "[ApplePayButton] #run early return after #checkAvailability",
2078
+ JSON.stringify(
2079
+ {
2080
+ country: this.#country,
2081
+ offer_sku: this.#offer?.sku_id
2082
+ },
2083
+ null,
2084
+ 2
2085
+ )
2086
+ );
2087
+ return;
2088
+ }
2089
+ const offerMissing = this.#checkOffer();
2090
+ console.log(
2091
+ "[ApplePayButton] #checkOffer result",
2092
+ JSON.stringify(
2093
+ {
2094
+ blocked: offerMissing,
2095
+ country: this.#country,
2096
+ offer_sku: this.#offer?.sku_id
2097
+ },
2098
+ null,
2099
+ 2
2100
+ )
2101
+ );
2102
+ if (offerMissing) {
2103
+ console.log(
2104
+ "[ApplePayButton] #run early return after #checkOffer",
2105
+ JSON.stringify(
2106
+ {
2107
+ country: this.#country,
2108
+ offer_sku: this.#offer?.sku_id
2109
+ },
2110
+ null,
2111
+ 2
2112
+ )
2113
+ );
2114
+ return;
2115
+ }
2116
+ const sessionBlocked = await this.#checkSession();
2117
+ console.log(
2118
+ "[ApplePayButton] #checkSession result",
2119
+ JSON.stringify(
2120
+ {
2121
+ blocked: sessionBlocked,
2122
+ country: this.#country,
2123
+ offer_sku: this.#offer?.sku_id,
2124
+ session_user_type: this.#sessionData?.userType,
2125
+ session_logged_in: this.#sessionData?.loggedIn
2126
+ },
2127
+ null,
2128
+ 2
2129
+ )
2130
+ );
2131
+ if (sessionBlocked) {
2132
+ console.log(
2133
+ "[ApplePayButton] #run early return after #checkSession",
2134
+ JSON.stringify(
2135
+ {
2136
+ country: this.#country,
2137
+ offer_sku: this.#offer?.sku_id
2138
+ },
2139
+ null,
2140
+ 2
2141
+ )
2142
+ );
2143
+ return;
2144
+ }
2051
2145
  this.#captureReturnUrl();
2146
+ console.log(
2147
+ "[ApplePayButton] #captureReturnUrl done",
2148
+ JSON.stringify(
2149
+ {
2150
+ return_url: this.#returnUrl
2151
+ },
2152
+ null,
2153
+ 2
2154
+ )
2155
+ );
2052
2156
  this.#computeBillingCountries();
2053
- if (await this.#fetchAndCacheOptions()) return;
2157
+ console.log(
2158
+ "[ApplePayButton] #computeBillingCountries done",
2159
+ JSON.stringify(
2160
+ {
2161
+ supported_billing_countries: this.#supportedBillingCountries
2162
+ },
2163
+ null,
2164
+ 2
2165
+ )
2166
+ );
2167
+ const optionsBlocked = await this.#fetchAndCacheOptions();
2168
+ console.log(
2169
+ "[ApplePayButton] #fetchAndCacheOptions result",
2170
+ JSON.stringify(
2171
+ {
2172
+ blocked: optionsBlocked,
2173
+ has_apple_pay_option: Boolean(this.#paymentOptions?.options?.apple_pay)
2174
+ },
2175
+ null,
2176
+ 2
2177
+ )
2178
+ );
2179
+ if (optionsBlocked) {
2180
+ console.log(
2181
+ "[ApplePayButton] #run early return after #fetchAndCacheOptions",
2182
+ JSON.stringify(
2183
+ {
2184
+ country: this.#country,
2185
+ offer_sku: this.#offer?.sku_id
2186
+ },
2187
+ null,
2188
+ 2
2189
+ )
2190
+ );
2191
+ return;
2192
+ }
2054
2193
  this.#finishLoading();
2055
- } catch (err) {
2056
- console.error("[web-apple-pay] #run: unexpected error, hiding button", err);
2194
+ console.log(
2195
+ "[ApplePayButton] #finishLoading done",
2196
+ JSON.stringify(
2197
+ {
2198
+ country: this.#country,
2199
+ offer_sku: this.#offer?.sku_id
2200
+ },
2201
+ null,
2202
+ 2
2203
+ )
2204
+ );
2205
+ } catch (error) {
2206
+ console.log(
2207
+ "[ApplePayButton] #run failed",
2208
+ JSON.stringify(
2209
+ {
2210
+ country: this.#country,
2211
+ offer_sku: this.#offer?.sku_id,
2212
+ error: error instanceof Error ? {
2213
+ name: error.name,
2214
+ message: error.message,
2215
+ stack: error.stack
2216
+ } : error
2217
+ },
2218
+ null,
2219
+ 2
2220
+ )
2221
+ );
2057
2222
  this.style.display = "none";
2058
2223
  this.querySelector(SEL_CONTAINER)?.remove();
2059
2224
  } finally {
2225
+ console.log(
2226
+ "[ApplePayButton] #run finally",
2227
+ JSON.stringify(
2228
+ {
2229
+ rendering: this.#rendering
2230
+ },
2231
+ null,
2232
+ 2
2233
+ )
2234
+ );
2060
2235
  this.#rendering = false;
2061
2236
  }
2062
2237
  }
@@ -2194,8 +2369,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2194
2369
  */
2195
2370
  #scheduleRecaptchaTokens() {
2196
2371
  const attempt = getPurchaseRecaptchaTokens();
2197
- attempt.catch((err) => {
2198
- console.error("[web-apple-pay] reCAPTCHA token pre-fetch failed; will retry on modal open", err);
2372
+ attempt.catch(() => {
2199
2373
  if (this.#recaptchaTokensPromise === attempt) {
2200
2374
  this.#recaptchaTokensPromise = null;
2201
2375
  }
@@ -2256,8 +2430,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2256
2430
  recaptchaTokens
2257
2431
  )
2258
2432
  );
2259
- } catch (error) {
2260
- console.error(ERROR_INITIATE, error);
2433
+ } catch {
2261
2434
  }
2262
2435
  }
2263
2436
  };