@economist/web-apple-pay 0.1.3-beta.35 → 0.1.3-beta.37

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
@@ -1122,27 +1122,50 @@ var isAppleDeviceOrSafari = () => {
1122
1122
  };
1123
1123
  var bypassApplePayChecks = () => new URLSearchParams(window.location.search).get("BYPASS_APPLE_PAY_CHECKS") !== null;
1124
1124
  var isApplePayAvailable = async () => {
1125
- if (!isAppleDeviceOrSafari() && !bypassApplePayChecks()) {
1126
- return false;
1125
+ if (bypassApplePayChecks()) {
1126
+ console.log("[ApplePay] bypass active \u2014 displaying button");
1127
+ return true;
1127
1128
  }
1128
1129
  const applePaySession = window.ApplePaySession;
1130
+ const isAppleDevice = isAppleDeviceOrSafari();
1131
+ console.log("[ApplePay] detection:", JSON.stringify({
1132
+ applePaySessionExists: !!applePaySession,
1133
+ isAppleDevice,
1134
+ userAgent: navigator.userAgent,
1135
+ maxTouchPoints: navigator.maxTouchPoints
1136
+ }, null, 2));
1137
+ if (!applePaySession && !isAppleDevice) {
1138
+ console.log("[ApplePay] not available \u2014 no ApplePaySession and not Apple device");
1139
+ return false;
1140
+ }
1129
1141
  if (!applePaySession) {
1142
+ console.log("[ApplePay] not available \u2014 Apple device but no ApplePaySession API");
1130
1143
  return false;
1131
1144
  }
1132
1145
  try {
1133
1146
  if (typeof applePaySession.canMakePayments !== "function") {
1147
+ console.log("[ApplePay] not available \u2014 canMakePayments is not a function");
1134
1148
  return false;
1135
1149
  }
1136
1150
  if (!applePaySession.canMakePayments()) {
1151
+ console.log("[ApplePay] not available \u2014 canMakePayments returned false");
1137
1152
  return false;
1138
1153
  }
1139
1154
  const merchantId = getApplePayConfig()?.merchantId;
1140
1155
  if (!merchantId) {
1156
+ console.log("[ApplePay] not available \u2014 no merchantId configured");
1141
1157
  return false;
1142
1158
  }
1143
1159
  const hasActiveCard = await applePaySession.canMakePaymentsWithActiveCard(merchantId);
1144
- return hasActiveCard;
1145
- } catch {
1160
+ console.log("[ApplePay] canMakePaymentsWithActiveCard:", JSON.stringify({ merchantId, hasActiveCard }, null, 2));
1161
+ if (!hasActiveCard) {
1162
+ console.log("[ApplePay] not available \u2014 no active card for merchant");
1163
+ return false;
1164
+ }
1165
+ console.log("[ApplePay] available \u2014 displaying button");
1166
+ return true;
1167
+ } catch (error) {
1168
+ console.log("[ApplePay] not available \u2014 error:", JSON.stringify({ error: String(error) }, null, 2));
1146
1169
  return false;
1147
1170
  }
1148
1171
  };
@@ -2037,203 +2060,18 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2037
2060
  // ─── Render pipeline ────────────────────────────────────────────────────────
2038
2061
  async #run() {
2039
2062
  try {
2040
- console.log(
2041
- "[ApplePayButton] #run start",
2042
- JSON.stringify(
2043
- {
2044
- country: this.#country,
2045
- offer_sku: this.#offer?.sku_id,
2046
- entry_point: this.#entryPoint
2047
- },
2048
- null,
2049
- 2
2050
- )
2051
- );
2052
2063
  this.#renderTemplate();
2053
- console.log(
2054
- "[ApplePayButton] #renderTemplate done",
2055
- JSON.stringify(
2056
- {
2057
- country: this.#country,
2058
- offer_sku: this.#offer?.sku_id
2059
- },
2060
- null,
2061
- 2
2062
- )
2063
- );
2064
- const availabilityBlocked = await this.#checkAvailability();
2065
- console.log(
2066
- "[ApplePayButton] #checkAvailability result",
2067
- JSON.stringify(
2068
- {
2069
- blocked: availabilityBlocked,
2070
- country: this.#country,
2071
- offer_sku: this.#offer?.sku_id
2072
- },
2073
- null,
2074
- 2
2075
- )
2076
- );
2077
- if (availabilityBlocked) {
2078
- console.log(
2079
- "[ApplePayButton] #run early return after #checkAvailability",
2080
- JSON.stringify(
2081
- {
2082
- country: this.#country,
2083
- offer_sku: this.#offer?.sku_id
2084
- },
2085
- null,
2086
- 2
2087
- )
2088
- );
2089
- return;
2090
- }
2091
- const offerMissing = this.#checkOffer();
2092
- console.log(
2093
- "[ApplePayButton] #checkOffer result",
2094
- JSON.stringify(
2095
- {
2096
- blocked: offerMissing,
2097
- country: this.#country,
2098
- offer_sku: this.#offer?.sku_id
2099
- },
2100
- null,
2101
- 2
2102
- )
2103
- );
2104
- if (offerMissing) {
2105
- console.log(
2106
- "[ApplePayButton] #run early return after #checkOffer",
2107
- JSON.stringify(
2108
- {
2109
- country: this.#country,
2110
- offer_sku: this.#offer?.sku_id
2111
- },
2112
- null,
2113
- 2
2114
- )
2115
- );
2116
- return;
2117
- }
2118
- const sessionBlocked = await this.#checkSession();
2119
- console.log(
2120
- "[ApplePayButton] #checkSession result",
2121
- JSON.stringify(
2122
- {
2123
- blocked: sessionBlocked,
2124
- country: this.#country,
2125
- offer_sku: this.#offer?.sku_id,
2126
- session_user_type: this.#sessionData?.userType,
2127
- session_logged_in: this.#sessionData?.loggedIn
2128
- },
2129
- null,
2130
- 2
2131
- )
2132
- );
2133
- if (sessionBlocked) {
2134
- console.log(
2135
- "[ApplePayButton] #run early return after #checkSession",
2136
- JSON.stringify(
2137
- {
2138
- country: this.#country,
2139
- offer_sku: this.#offer?.sku_id
2140
- },
2141
- null,
2142
- 2
2143
- )
2144
- );
2145
- return;
2146
- }
2064
+ if (await this.#checkAvailability()) return;
2065
+ if (this.#checkOffer()) return;
2066
+ if (await this.#checkSession()) return;
2147
2067
  this.#captureReturnUrl();
2148
- console.log(
2149
- "[ApplePayButton] #captureReturnUrl done",
2150
- JSON.stringify(
2151
- {
2152
- return_url: this.#returnUrl
2153
- },
2154
- null,
2155
- 2
2156
- )
2157
- );
2158
2068
  this.#computeBillingCountries();
2159
- console.log(
2160
- "[ApplePayButton] #computeBillingCountries done",
2161
- JSON.stringify(
2162
- {
2163
- supported_billing_countries: this.#supportedBillingCountries
2164
- },
2165
- null,
2166
- 2
2167
- )
2168
- );
2169
- const optionsBlocked = await this.#fetchAndCacheOptions();
2170
- console.log(
2171
- "[ApplePayButton] #fetchAndCacheOptions result",
2172
- JSON.stringify(
2173
- {
2174
- blocked: optionsBlocked,
2175
- has_apple_pay_option: Boolean(this.#paymentOptions?.options?.apple_pay)
2176
- },
2177
- null,
2178
- 2
2179
- )
2180
- );
2181
- if (optionsBlocked) {
2182
- console.log(
2183
- "[ApplePayButton] #run early return after #fetchAndCacheOptions",
2184
- JSON.stringify(
2185
- {
2186
- country: this.#country,
2187
- offer_sku: this.#offer?.sku_id
2188
- },
2189
- null,
2190
- 2
2191
- )
2192
- );
2193
- return;
2194
- }
2069
+ if (await this.#fetchAndCacheOptions()) return;
2195
2070
  this.#finishLoading();
2196
- console.log(
2197
- "[ApplePayButton] #finishLoading done",
2198
- JSON.stringify(
2199
- {
2200
- country: this.#country,
2201
- offer_sku: this.#offer?.sku_id
2202
- },
2203
- null,
2204
- 2
2205
- )
2206
- );
2207
- } catch (error) {
2208
- console.log(
2209
- "[ApplePayButton] #run failed",
2210
- JSON.stringify(
2211
- {
2212
- country: this.#country,
2213
- offer_sku: this.#offer?.sku_id,
2214
- error: error instanceof Error ? {
2215
- name: error.name,
2216
- message: error.message,
2217
- stack: error.stack
2218
- } : error
2219
- },
2220
- null,
2221
- 2
2222
- )
2223
- );
2071
+ } catch {
2224
2072
  this.style.display = "none";
2225
2073
  this.querySelector(SEL_CONTAINER)?.remove();
2226
2074
  } finally {
2227
- console.log(
2228
- "[ApplePayButton] #run finally",
2229
- JSON.stringify(
2230
- {
2231
- rendering: this.#rendering
2232
- },
2233
- null,
2234
- 2
2235
- )
2236
- );
2237
2075
  this.#rendering = false;
2238
2076
  }
2239
2077
  }
@@ -1117,27 +1117,50 @@ var isAppleDeviceOrSafari = () => {
1117
1117
  };
1118
1118
  var bypassApplePayChecks = () => new URLSearchParams(window.location.search).get("BYPASS_APPLE_PAY_CHECKS") !== null;
1119
1119
  var isApplePayAvailable = async () => {
1120
- if (!isAppleDeviceOrSafari() && !bypassApplePayChecks()) {
1121
- return false;
1120
+ if (bypassApplePayChecks()) {
1121
+ console.log("[ApplePay] bypass active \u2014 displaying button");
1122
+ return true;
1122
1123
  }
1123
1124
  const applePaySession = window.ApplePaySession;
1125
+ const isAppleDevice = isAppleDeviceOrSafari();
1126
+ console.log("[ApplePay] detection:", JSON.stringify({
1127
+ applePaySessionExists: !!applePaySession,
1128
+ isAppleDevice,
1129
+ userAgent: navigator.userAgent,
1130
+ maxTouchPoints: navigator.maxTouchPoints
1131
+ }, null, 2));
1132
+ if (!applePaySession && !isAppleDevice) {
1133
+ console.log("[ApplePay] not available \u2014 no ApplePaySession and not Apple device");
1134
+ return false;
1135
+ }
1124
1136
  if (!applePaySession) {
1137
+ console.log("[ApplePay] not available \u2014 Apple device but no ApplePaySession API");
1125
1138
  return false;
1126
1139
  }
1127
1140
  try {
1128
1141
  if (typeof applePaySession.canMakePayments !== "function") {
1142
+ console.log("[ApplePay] not available \u2014 canMakePayments is not a function");
1129
1143
  return false;
1130
1144
  }
1131
1145
  if (!applePaySession.canMakePayments()) {
1146
+ console.log("[ApplePay] not available \u2014 canMakePayments returned false");
1132
1147
  return false;
1133
1148
  }
1134
1149
  const merchantId = getApplePayConfig()?.merchantId;
1135
1150
  if (!merchantId) {
1151
+ console.log("[ApplePay] not available \u2014 no merchantId configured");
1136
1152
  return false;
1137
1153
  }
1138
1154
  const hasActiveCard = await applePaySession.canMakePaymentsWithActiveCard(merchantId);
1139
- return hasActiveCard;
1140
- } catch {
1155
+ console.log("[ApplePay] canMakePaymentsWithActiveCard:", JSON.stringify({ merchantId, hasActiveCard }, null, 2));
1156
+ if (!hasActiveCard) {
1157
+ console.log("[ApplePay] not available \u2014 no active card for merchant");
1158
+ return false;
1159
+ }
1160
+ console.log("[ApplePay] available \u2014 displaying button");
1161
+ return true;
1162
+ } catch (error) {
1163
+ console.log("[ApplePay] not available \u2014 error:", JSON.stringify({ error: String(error) }, null, 2));
1141
1164
  return false;
1142
1165
  }
1143
1166
  };
@@ -2032,203 +2055,18 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2032
2055
  // ─── Render pipeline ────────────────────────────────────────────────────────
2033
2056
  async #run() {
2034
2057
  try {
2035
- console.log(
2036
- "[ApplePayButton] #run start",
2037
- JSON.stringify(
2038
- {
2039
- country: this.#country,
2040
- offer_sku: this.#offer?.sku_id,
2041
- entry_point: this.#entryPoint
2042
- },
2043
- null,
2044
- 2
2045
- )
2046
- );
2047
2058
  this.#renderTemplate();
2048
- console.log(
2049
- "[ApplePayButton] #renderTemplate done",
2050
- JSON.stringify(
2051
- {
2052
- country: this.#country,
2053
- offer_sku: this.#offer?.sku_id
2054
- },
2055
- null,
2056
- 2
2057
- )
2058
- );
2059
- const availabilityBlocked = await this.#checkAvailability();
2060
- console.log(
2061
- "[ApplePayButton] #checkAvailability result",
2062
- JSON.stringify(
2063
- {
2064
- blocked: availabilityBlocked,
2065
- country: this.#country,
2066
- offer_sku: this.#offer?.sku_id
2067
- },
2068
- null,
2069
- 2
2070
- )
2071
- );
2072
- if (availabilityBlocked) {
2073
- console.log(
2074
- "[ApplePayButton] #run early return after #checkAvailability",
2075
- JSON.stringify(
2076
- {
2077
- country: this.#country,
2078
- offer_sku: this.#offer?.sku_id
2079
- },
2080
- null,
2081
- 2
2082
- )
2083
- );
2084
- return;
2085
- }
2086
- const offerMissing = this.#checkOffer();
2087
- console.log(
2088
- "[ApplePayButton] #checkOffer result",
2089
- JSON.stringify(
2090
- {
2091
- blocked: offerMissing,
2092
- country: this.#country,
2093
- offer_sku: this.#offer?.sku_id
2094
- },
2095
- null,
2096
- 2
2097
- )
2098
- );
2099
- if (offerMissing) {
2100
- console.log(
2101
- "[ApplePayButton] #run early return after #checkOffer",
2102
- JSON.stringify(
2103
- {
2104
- country: this.#country,
2105
- offer_sku: this.#offer?.sku_id
2106
- },
2107
- null,
2108
- 2
2109
- )
2110
- );
2111
- return;
2112
- }
2113
- const sessionBlocked = await this.#checkSession();
2114
- console.log(
2115
- "[ApplePayButton] #checkSession result",
2116
- JSON.stringify(
2117
- {
2118
- blocked: sessionBlocked,
2119
- country: this.#country,
2120
- offer_sku: this.#offer?.sku_id,
2121
- session_user_type: this.#sessionData?.userType,
2122
- session_logged_in: this.#sessionData?.loggedIn
2123
- },
2124
- null,
2125
- 2
2126
- )
2127
- );
2128
- if (sessionBlocked) {
2129
- console.log(
2130
- "[ApplePayButton] #run early return after #checkSession",
2131
- JSON.stringify(
2132
- {
2133
- country: this.#country,
2134
- offer_sku: this.#offer?.sku_id
2135
- },
2136
- null,
2137
- 2
2138
- )
2139
- );
2140
- return;
2141
- }
2059
+ if (await this.#checkAvailability()) return;
2060
+ if (this.#checkOffer()) return;
2061
+ if (await this.#checkSession()) return;
2142
2062
  this.#captureReturnUrl();
2143
- console.log(
2144
- "[ApplePayButton] #captureReturnUrl done",
2145
- JSON.stringify(
2146
- {
2147
- return_url: this.#returnUrl
2148
- },
2149
- null,
2150
- 2
2151
- )
2152
- );
2153
2063
  this.#computeBillingCountries();
2154
- console.log(
2155
- "[ApplePayButton] #computeBillingCountries done",
2156
- JSON.stringify(
2157
- {
2158
- supported_billing_countries: this.#supportedBillingCountries
2159
- },
2160
- null,
2161
- 2
2162
- )
2163
- );
2164
- const optionsBlocked = await this.#fetchAndCacheOptions();
2165
- console.log(
2166
- "[ApplePayButton] #fetchAndCacheOptions result",
2167
- JSON.stringify(
2168
- {
2169
- blocked: optionsBlocked,
2170
- has_apple_pay_option: Boolean(this.#paymentOptions?.options?.apple_pay)
2171
- },
2172
- null,
2173
- 2
2174
- )
2175
- );
2176
- if (optionsBlocked) {
2177
- console.log(
2178
- "[ApplePayButton] #run early return after #fetchAndCacheOptions",
2179
- JSON.stringify(
2180
- {
2181
- country: this.#country,
2182
- offer_sku: this.#offer?.sku_id
2183
- },
2184
- null,
2185
- 2
2186
- )
2187
- );
2188
- return;
2189
- }
2064
+ if (await this.#fetchAndCacheOptions()) return;
2190
2065
  this.#finishLoading();
2191
- console.log(
2192
- "[ApplePayButton] #finishLoading done",
2193
- JSON.stringify(
2194
- {
2195
- country: this.#country,
2196
- offer_sku: this.#offer?.sku_id
2197
- },
2198
- null,
2199
- 2
2200
- )
2201
- );
2202
- } catch (error) {
2203
- console.log(
2204
- "[ApplePayButton] #run failed",
2205
- JSON.stringify(
2206
- {
2207
- country: this.#country,
2208
- offer_sku: this.#offer?.sku_id,
2209
- error: error instanceof Error ? {
2210
- name: error.name,
2211
- message: error.message,
2212
- stack: error.stack
2213
- } : error
2214
- },
2215
- null,
2216
- 2
2217
- )
2218
- );
2066
+ } catch {
2219
2067
  this.style.display = "none";
2220
2068
  this.querySelector(SEL_CONTAINER)?.remove();
2221
2069
  } finally {
2222
- console.log(
2223
- "[ApplePayButton] #run finally",
2224
- JSON.stringify(
2225
- {
2226
- rendering: this.#rendering
2227
- },
2228
- null,
2229
- 2
2230
- )
2231
- );
2232
2070
  this.#rendering = false;
2233
2071
  }
2234
2072
  }
@@ -1125,27 +1125,50 @@ var isAppleDeviceOrSafari = () => {
1125
1125
  };
1126
1126
  var bypassApplePayChecks = () => new URLSearchParams(window.location.search).get("BYPASS_APPLE_PAY_CHECKS") !== null;
1127
1127
  var isApplePayAvailable = async () => {
1128
- if (!isAppleDeviceOrSafari() && !bypassApplePayChecks()) {
1129
- return false;
1128
+ if (bypassApplePayChecks()) {
1129
+ console.log("[ApplePay] bypass active \u2014 displaying button");
1130
+ return true;
1130
1131
  }
1131
1132
  const applePaySession = window.ApplePaySession;
1133
+ const isAppleDevice = isAppleDeviceOrSafari();
1134
+ console.log("[ApplePay] detection:", JSON.stringify({
1135
+ applePaySessionExists: !!applePaySession,
1136
+ isAppleDevice,
1137
+ userAgent: navigator.userAgent,
1138
+ maxTouchPoints: navigator.maxTouchPoints
1139
+ }, null, 2));
1140
+ if (!applePaySession && !isAppleDevice) {
1141
+ console.log("[ApplePay] not available \u2014 no ApplePaySession and not Apple device");
1142
+ return false;
1143
+ }
1132
1144
  if (!applePaySession) {
1145
+ console.log("[ApplePay] not available \u2014 Apple device but no ApplePaySession API");
1133
1146
  return false;
1134
1147
  }
1135
1148
  try {
1136
1149
  if (typeof applePaySession.canMakePayments !== "function") {
1150
+ console.log("[ApplePay] not available \u2014 canMakePayments is not a function");
1137
1151
  return false;
1138
1152
  }
1139
1153
  if (!applePaySession.canMakePayments()) {
1154
+ console.log("[ApplePay] not available \u2014 canMakePayments returned false");
1140
1155
  return false;
1141
1156
  }
1142
1157
  const merchantId = getApplePayConfig()?.merchantId;
1143
1158
  if (!merchantId) {
1159
+ console.log("[ApplePay] not available \u2014 no merchantId configured");
1144
1160
  return false;
1145
1161
  }
1146
1162
  const hasActiveCard = await applePaySession.canMakePaymentsWithActiveCard(merchantId);
1147
- return hasActiveCard;
1148
- } catch {
1163
+ console.log("[ApplePay] canMakePaymentsWithActiveCard:", JSON.stringify({ merchantId, hasActiveCard }, null, 2));
1164
+ if (!hasActiveCard) {
1165
+ console.log("[ApplePay] not available \u2014 no active card for merchant");
1166
+ return false;
1167
+ }
1168
+ console.log("[ApplePay] available \u2014 displaying button");
1169
+ return true;
1170
+ } catch (error) {
1171
+ console.log("[ApplePay] not available \u2014 error:", JSON.stringify({ error: String(error) }, null, 2));
1149
1172
  return false;
1150
1173
  }
1151
1174
  };
@@ -2040,203 +2063,18 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2040
2063
  // ─── Render pipeline ────────────────────────────────────────────────────────
2041
2064
  async #run() {
2042
2065
  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
- );
2055
2066
  this.#renderTemplate();
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
- }
2067
+ if (await this.#checkAvailability()) return;
2068
+ if (this.#checkOffer()) return;
2069
+ if (await this.#checkSession()) return;
2150
2070
  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
- );
2161
2071
  this.#computeBillingCountries();
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
- }
2072
+ if (await this.#fetchAndCacheOptions()) return;
2198
2073
  this.#finishLoading();
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
- );
2074
+ } catch {
2227
2075
  this.style.display = "none";
2228
2076
  this.querySelector(SEL_CONTAINER)?.remove();
2229
2077
  } finally {
2230
- console.log(
2231
- "[ApplePayButton] #run finally",
2232
- JSON.stringify(
2233
- {
2234
- rendering: this.#rendering
2235
- },
2236
- null,
2237
- 2
2238
- )
2239
- );
2240
2078
  this.#rendering = false;
2241
2079
  }
2242
2080
  }
@@ -1117,27 +1117,50 @@ var isAppleDeviceOrSafari = () => {
1117
1117
  };
1118
1118
  var bypassApplePayChecks = () => new URLSearchParams(window.location.search).get("BYPASS_APPLE_PAY_CHECKS") !== null;
1119
1119
  var isApplePayAvailable = async () => {
1120
- if (!isAppleDeviceOrSafari() && !bypassApplePayChecks()) {
1121
- return false;
1120
+ if (bypassApplePayChecks()) {
1121
+ console.log("[ApplePay] bypass active \u2014 displaying button");
1122
+ return true;
1122
1123
  }
1123
1124
  const applePaySession = window.ApplePaySession;
1125
+ const isAppleDevice = isAppleDeviceOrSafari();
1126
+ console.log("[ApplePay] detection:", JSON.stringify({
1127
+ applePaySessionExists: !!applePaySession,
1128
+ isAppleDevice,
1129
+ userAgent: navigator.userAgent,
1130
+ maxTouchPoints: navigator.maxTouchPoints
1131
+ }, null, 2));
1132
+ if (!applePaySession && !isAppleDevice) {
1133
+ console.log("[ApplePay] not available \u2014 no ApplePaySession and not Apple device");
1134
+ return false;
1135
+ }
1124
1136
  if (!applePaySession) {
1137
+ console.log("[ApplePay] not available \u2014 Apple device but no ApplePaySession API");
1125
1138
  return false;
1126
1139
  }
1127
1140
  try {
1128
1141
  if (typeof applePaySession.canMakePayments !== "function") {
1142
+ console.log("[ApplePay] not available \u2014 canMakePayments is not a function");
1129
1143
  return false;
1130
1144
  }
1131
1145
  if (!applePaySession.canMakePayments()) {
1146
+ console.log("[ApplePay] not available \u2014 canMakePayments returned false");
1132
1147
  return false;
1133
1148
  }
1134
1149
  const merchantId = getApplePayConfig()?.merchantId;
1135
1150
  if (!merchantId) {
1151
+ console.log("[ApplePay] not available \u2014 no merchantId configured");
1136
1152
  return false;
1137
1153
  }
1138
1154
  const hasActiveCard = await applePaySession.canMakePaymentsWithActiveCard(merchantId);
1139
- return hasActiveCard;
1140
- } catch {
1155
+ console.log("[ApplePay] canMakePaymentsWithActiveCard:", JSON.stringify({ merchantId, hasActiveCard }, null, 2));
1156
+ if (!hasActiveCard) {
1157
+ console.log("[ApplePay] not available \u2014 no active card for merchant");
1158
+ return false;
1159
+ }
1160
+ console.log("[ApplePay] available \u2014 displaying button");
1161
+ return true;
1162
+ } catch (error) {
1163
+ console.log("[ApplePay] not available \u2014 error:", JSON.stringify({ error: String(error) }, null, 2));
1141
1164
  return false;
1142
1165
  }
1143
1166
  };
@@ -2032,203 +2055,18 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2032
2055
  // ─── Render pipeline ────────────────────────────────────────────────────────
2033
2056
  async #run() {
2034
2057
  try {
2035
- console.log(
2036
- "[ApplePayButton] #run start",
2037
- JSON.stringify(
2038
- {
2039
- country: this.#country,
2040
- offer_sku: this.#offer?.sku_id,
2041
- entry_point: this.#entryPoint
2042
- },
2043
- null,
2044
- 2
2045
- )
2046
- );
2047
2058
  this.#renderTemplate();
2048
- console.log(
2049
- "[ApplePayButton] #renderTemplate done",
2050
- JSON.stringify(
2051
- {
2052
- country: this.#country,
2053
- offer_sku: this.#offer?.sku_id
2054
- },
2055
- null,
2056
- 2
2057
- )
2058
- );
2059
- const availabilityBlocked = await this.#checkAvailability();
2060
- console.log(
2061
- "[ApplePayButton] #checkAvailability result",
2062
- JSON.stringify(
2063
- {
2064
- blocked: availabilityBlocked,
2065
- country: this.#country,
2066
- offer_sku: this.#offer?.sku_id
2067
- },
2068
- null,
2069
- 2
2070
- )
2071
- );
2072
- if (availabilityBlocked) {
2073
- console.log(
2074
- "[ApplePayButton] #run early return after #checkAvailability",
2075
- JSON.stringify(
2076
- {
2077
- country: this.#country,
2078
- offer_sku: this.#offer?.sku_id
2079
- },
2080
- null,
2081
- 2
2082
- )
2083
- );
2084
- return;
2085
- }
2086
- const offerMissing = this.#checkOffer();
2087
- console.log(
2088
- "[ApplePayButton] #checkOffer result",
2089
- JSON.stringify(
2090
- {
2091
- blocked: offerMissing,
2092
- country: this.#country,
2093
- offer_sku: this.#offer?.sku_id
2094
- },
2095
- null,
2096
- 2
2097
- )
2098
- );
2099
- if (offerMissing) {
2100
- console.log(
2101
- "[ApplePayButton] #run early return after #checkOffer",
2102
- JSON.stringify(
2103
- {
2104
- country: this.#country,
2105
- offer_sku: this.#offer?.sku_id
2106
- },
2107
- null,
2108
- 2
2109
- )
2110
- );
2111
- return;
2112
- }
2113
- const sessionBlocked = await this.#checkSession();
2114
- console.log(
2115
- "[ApplePayButton] #checkSession result",
2116
- JSON.stringify(
2117
- {
2118
- blocked: sessionBlocked,
2119
- country: this.#country,
2120
- offer_sku: this.#offer?.sku_id,
2121
- session_user_type: this.#sessionData?.userType,
2122
- session_logged_in: this.#sessionData?.loggedIn
2123
- },
2124
- null,
2125
- 2
2126
- )
2127
- );
2128
- if (sessionBlocked) {
2129
- console.log(
2130
- "[ApplePayButton] #run early return after #checkSession",
2131
- JSON.stringify(
2132
- {
2133
- country: this.#country,
2134
- offer_sku: this.#offer?.sku_id
2135
- },
2136
- null,
2137
- 2
2138
- )
2139
- );
2140
- return;
2141
- }
2059
+ if (await this.#checkAvailability()) return;
2060
+ if (this.#checkOffer()) return;
2061
+ if (await this.#checkSession()) return;
2142
2062
  this.#captureReturnUrl();
2143
- console.log(
2144
- "[ApplePayButton] #captureReturnUrl done",
2145
- JSON.stringify(
2146
- {
2147
- return_url: this.#returnUrl
2148
- },
2149
- null,
2150
- 2
2151
- )
2152
- );
2153
2063
  this.#computeBillingCountries();
2154
- console.log(
2155
- "[ApplePayButton] #computeBillingCountries done",
2156
- JSON.stringify(
2157
- {
2158
- supported_billing_countries: this.#supportedBillingCountries
2159
- },
2160
- null,
2161
- 2
2162
- )
2163
- );
2164
- const optionsBlocked = await this.#fetchAndCacheOptions();
2165
- console.log(
2166
- "[ApplePayButton] #fetchAndCacheOptions result",
2167
- JSON.stringify(
2168
- {
2169
- blocked: optionsBlocked,
2170
- has_apple_pay_option: Boolean(this.#paymentOptions?.options?.apple_pay)
2171
- },
2172
- null,
2173
- 2
2174
- )
2175
- );
2176
- if (optionsBlocked) {
2177
- console.log(
2178
- "[ApplePayButton] #run early return after #fetchAndCacheOptions",
2179
- JSON.stringify(
2180
- {
2181
- country: this.#country,
2182
- offer_sku: this.#offer?.sku_id
2183
- },
2184
- null,
2185
- 2
2186
- )
2187
- );
2188
- return;
2189
- }
2064
+ if (await this.#fetchAndCacheOptions()) return;
2190
2065
  this.#finishLoading();
2191
- console.log(
2192
- "[ApplePayButton] #finishLoading done",
2193
- JSON.stringify(
2194
- {
2195
- country: this.#country,
2196
- offer_sku: this.#offer?.sku_id
2197
- },
2198
- null,
2199
- 2
2200
- )
2201
- );
2202
- } catch (error) {
2203
- console.log(
2204
- "[ApplePayButton] #run failed",
2205
- JSON.stringify(
2206
- {
2207
- country: this.#country,
2208
- offer_sku: this.#offer?.sku_id,
2209
- error: error instanceof Error ? {
2210
- name: error.name,
2211
- message: error.message,
2212
- stack: error.stack
2213
- } : error
2214
- },
2215
- null,
2216
- 2
2217
- )
2218
- );
2066
+ } catch {
2219
2067
  this.style.display = "none";
2220
2068
  this.querySelector(SEL_CONTAINER)?.remove();
2221
2069
  } finally {
2222
- console.log(
2223
- "[ApplePayButton] #run finally",
2224
- JSON.stringify(
2225
- {
2226
- rendering: this.#rendering
2227
- },
2228
- null,
2229
- 2
2230
- )
2231
- );
2232
2070
  this.#rendering = false;
2233
2071
  }
2234
2072
  }
@@ -10,27 +10,50 @@ var isAppleDeviceOrSafari = () => {
10
10
  };
11
11
  var bypassApplePayChecks = () => new URLSearchParams(window.location.search).get("BYPASS_APPLE_PAY_CHECKS") !== null;
12
12
  var isApplePayAvailable = async () => {
13
- if (!isAppleDeviceOrSafari() && !bypassApplePayChecks()) {
14
- return false;
13
+ if (bypassApplePayChecks()) {
14
+ console.log("[ApplePay] bypass active \u2014 displaying button");
15
+ return true;
15
16
  }
16
17
  const applePaySession = window.ApplePaySession;
18
+ const isAppleDevice = isAppleDeviceOrSafari();
19
+ console.log("[ApplePay] detection:", JSON.stringify({
20
+ applePaySessionExists: !!applePaySession,
21
+ isAppleDevice,
22
+ userAgent: navigator.userAgent,
23
+ maxTouchPoints: navigator.maxTouchPoints
24
+ }, null, 2));
25
+ if (!applePaySession && !isAppleDevice) {
26
+ console.log("[ApplePay] not available \u2014 no ApplePaySession and not Apple device");
27
+ return false;
28
+ }
17
29
  if (!applePaySession) {
30
+ console.log("[ApplePay] not available \u2014 Apple device but no ApplePaySession API");
18
31
  return false;
19
32
  }
20
33
  try {
21
34
  if (typeof applePaySession.canMakePayments !== "function") {
35
+ console.log("[ApplePay] not available \u2014 canMakePayments is not a function");
22
36
  return false;
23
37
  }
24
38
  if (!applePaySession.canMakePayments()) {
39
+ console.log("[ApplePay] not available \u2014 canMakePayments returned false");
25
40
  return false;
26
41
  }
27
42
  const merchantId = getApplePayConfig()?.merchantId;
28
43
  if (!merchantId) {
44
+ console.log("[ApplePay] not available \u2014 no merchantId configured");
29
45
  return false;
30
46
  }
31
47
  const hasActiveCard = await applePaySession.canMakePaymentsWithActiveCard(merchantId);
32
- return hasActiveCard;
33
- } catch {
48
+ console.log("[ApplePay] canMakePaymentsWithActiveCard:", JSON.stringify({ merchantId, hasActiveCard }, null, 2));
49
+ if (!hasActiveCard) {
50
+ console.log("[ApplePay] not available \u2014 no active card for merchant");
51
+ return false;
52
+ }
53
+ console.log("[ApplePay] available \u2014 displaying button");
54
+ return true;
55
+ } catch (error) {
56
+ console.log("[ApplePay] not available \u2014 error:", JSON.stringify({ error: String(error) }, null, 2));
34
57
  return false;
35
58
  }
36
59
  };
package/dist/src/index.js CHANGED
@@ -1122,27 +1122,50 @@ var isAppleDeviceOrSafari = () => {
1122
1122
  };
1123
1123
  var bypassApplePayChecks = () => new URLSearchParams(window.location.search).get("BYPASS_APPLE_PAY_CHECKS") !== null;
1124
1124
  var isApplePayAvailable = async () => {
1125
- if (!isAppleDeviceOrSafari() && !bypassApplePayChecks()) {
1126
- return false;
1125
+ if (bypassApplePayChecks()) {
1126
+ console.log("[ApplePay] bypass active \u2014 displaying button");
1127
+ return true;
1127
1128
  }
1128
1129
  const applePaySession = window.ApplePaySession;
1130
+ const isAppleDevice = isAppleDeviceOrSafari();
1131
+ console.log("[ApplePay] detection:", JSON.stringify({
1132
+ applePaySessionExists: !!applePaySession,
1133
+ isAppleDevice,
1134
+ userAgent: navigator.userAgent,
1135
+ maxTouchPoints: navigator.maxTouchPoints
1136
+ }, null, 2));
1137
+ if (!applePaySession && !isAppleDevice) {
1138
+ console.log("[ApplePay] not available \u2014 no ApplePaySession and not Apple device");
1139
+ return false;
1140
+ }
1129
1141
  if (!applePaySession) {
1142
+ console.log("[ApplePay] not available \u2014 Apple device but no ApplePaySession API");
1130
1143
  return false;
1131
1144
  }
1132
1145
  try {
1133
1146
  if (typeof applePaySession.canMakePayments !== "function") {
1147
+ console.log("[ApplePay] not available \u2014 canMakePayments is not a function");
1134
1148
  return false;
1135
1149
  }
1136
1150
  if (!applePaySession.canMakePayments()) {
1151
+ console.log("[ApplePay] not available \u2014 canMakePayments returned false");
1137
1152
  return false;
1138
1153
  }
1139
1154
  const merchantId = getApplePayConfig()?.merchantId;
1140
1155
  if (!merchantId) {
1156
+ console.log("[ApplePay] not available \u2014 no merchantId configured");
1141
1157
  return false;
1142
1158
  }
1143
1159
  const hasActiveCard = await applePaySession.canMakePaymentsWithActiveCard(merchantId);
1144
- return hasActiveCard;
1145
- } catch {
1160
+ console.log("[ApplePay] canMakePaymentsWithActiveCard:", JSON.stringify({ merchantId, hasActiveCard }, null, 2));
1161
+ if (!hasActiveCard) {
1162
+ console.log("[ApplePay] not available \u2014 no active card for merchant");
1163
+ return false;
1164
+ }
1165
+ console.log("[ApplePay] available \u2014 displaying button");
1166
+ return true;
1167
+ } catch (error) {
1168
+ console.log("[ApplePay] not available \u2014 error:", JSON.stringify({ error: String(error) }, null, 2));
1146
1169
  return false;
1147
1170
  }
1148
1171
  };
@@ -2037,203 +2060,18 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2037
2060
  // ─── Render pipeline ────────────────────────────────────────────────────────
2038
2061
  async #run() {
2039
2062
  try {
2040
- console.log(
2041
- "[ApplePayButton] #run start",
2042
- JSON.stringify(
2043
- {
2044
- country: this.#country,
2045
- offer_sku: this.#offer?.sku_id,
2046
- entry_point: this.#entryPoint
2047
- },
2048
- null,
2049
- 2
2050
- )
2051
- );
2052
2063
  this.#renderTemplate();
2053
- console.log(
2054
- "[ApplePayButton] #renderTemplate done",
2055
- JSON.stringify(
2056
- {
2057
- country: this.#country,
2058
- offer_sku: this.#offer?.sku_id
2059
- },
2060
- null,
2061
- 2
2062
- )
2063
- );
2064
- const availabilityBlocked = await this.#checkAvailability();
2065
- console.log(
2066
- "[ApplePayButton] #checkAvailability result",
2067
- JSON.stringify(
2068
- {
2069
- blocked: availabilityBlocked,
2070
- country: this.#country,
2071
- offer_sku: this.#offer?.sku_id
2072
- },
2073
- null,
2074
- 2
2075
- )
2076
- );
2077
- if (availabilityBlocked) {
2078
- console.log(
2079
- "[ApplePayButton] #run early return after #checkAvailability",
2080
- JSON.stringify(
2081
- {
2082
- country: this.#country,
2083
- offer_sku: this.#offer?.sku_id
2084
- },
2085
- null,
2086
- 2
2087
- )
2088
- );
2089
- return;
2090
- }
2091
- const offerMissing = this.#checkOffer();
2092
- console.log(
2093
- "[ApplePayButton] #checkOffer result",
2094
- JSON.stringify(
2095
- {
2096
- blocked: offerMissing,
2097
- country: this.#country,
2098
- offer_sku: this.#offer?.sku_id
2099
- },
2100
- null,
2101
- 2
2102
- )
2103
- );
2104
- if (offerMissing) {
2105
- console.log(
2106
- "[ApplePayButton] #run early return after #checkOffer",
2107
- JSON.stringify(
2108
- {
2109
- country: this.#country,
2110
- offer_sku: this.#offer?.sku_id
2111
- },
2112
- null,
2113
- 2
2114
- )
2115
- );
2116
- return;
2117
- }
2118
- const sessionBlocked = await this.#checkSession();
2119
- console.log(
2120
- "[ApplePayButton] #checkSession result",
2121
- JSON.stringify(
2122
- {
2123
- blocked: sessionBlocked,
2124
- country: this.#country,
2125
- offer_sku: this.#offer?.sku_id,
2126
- session_user_type: this.#sessionData?.userType,
2127
- session_logged_in: this.#sessionData?.loggedIn
2128
- },
2129
- null,
2130
- 2
2131
- )
2132
- );
2133
- if (sessionBlocked) {
2134
- console.log(
2135
- "[ApplePayButton] #run early return after #checkSession",
2136
- JSON.stringify(
2137
- {
2138
- country: this.#country,
2139
- offer_sku: this.#offer?.sku_id
2140
- },
2141
- null,
2142
- 2
2143
- )
2144
- );
2145
- return;
2146
- }
2064
+ if (await this.#checkAvailability()) return;
2065
+ if (this.#checkOffer()) return;
2066
+ if (await this.#checkSession()) return;
2147
2067
  this.#captureReturnUrl();
2148
- console.log(
2149
- "[ApplePayButton] #captureReturnUrl done",
2150
- JSON.stringify(
2151
- {
2152
- return_url: this.#returnUrl
2153
- },
2154
- null,
2155
- 2
2156
- )
2157
- );
2158
2068
  this.#computeBillingCountries();
2159
- console.log(
2160
- "[ApplePayButton] #computeBillingCountries done",
2161
- JSON.stringify(
2162
- {
2163
- supported_billing_countries: this.#supportedBillingCountries
2164
- },
2165
- null,
2166
- 2
2167
- )
2168
- );
2169
- const optionsBlocked = await this.#fetchAndCacheOptions();
2170
- console.log(
2171
- "[ApplePayButton] #fetchAndCacheOptions result",
2172
- JSON.stringify(
2173
- {
2174
- blocked: optionsBlocked,
2175
- has_apple_pay_option: Boolean(this.#paymentOptions?.options?.apple_pay)
2176
- },
2177
- null,
2178
- 2
2179
- )
2180
- );
2181
- if (optionsBlocked) {
2182
- console.log(
2183
- "[ApplePayButton] #run early return after #fetchAndCacheOptions",
2184
- JSON.stringify(
2185
- {
2186
- country: this.#country,
2187
- offer_sku: this.#offer?.sku_id
2188
- },
2189
- null,
2190
- 2
2191
- )
2192
- );
2193
- return;
2194
- }
2069
+ if (await this.#fetchAndCacheOptions()) return;
2195
2070
  this.#finishLoading();
2196
- console.log(
2197
- "[ApplePayButton] #finishLoading done",
2198
- JSON.stringify(
2199
- {
2200
- country: this.#country,
2201
- offer_sku: this.#offer?.sku_id
2202
- },
2203
- null,
2204
- 2
2205
- )
2206
- );
2207
- } catch (error) {
2208
- console.log(
2209
- "[ApplePayButton] #run failed",
2210
- JSON.stringify(
2211
- {
2212
- country: this.#country,
2213
- offer_sku: this.#offer?.sku_id,
2214
- error: error instanceof Error ? {
2215
- name: error.name,
2216
- message: error.message,
2217
- stack: error.stack
2218
- } : error
2219
- },
2220
- null,
2221
- 2
2222
- )
2223
- );
2071
+ } catch {
2224
2072
  this.style.display = "none";
2225
2073
  this.querySelector(SEL_CONTAINER)?.remove();
2226
2074
  } finally {
2227
- console.log(
2228
- "[ApplePayButton] #run finally",
2229
- JSON.stringify(
2230
- {
2231
- rendering: this.#rendering
2232
- },
2233
- null,
2234
- 2
2235
- )
2236
- );
2237
2075
  this.#rendering = false;
2238
2076
  }
2239
2077
  }
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.35",
4
+ "version": "0.1.3-beta.37",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",