@economist/web-apple-pay 1.13.0 → 1.15.0

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/README.md CHANGED
@@ -78,9 +78,29 @@ If `merchantId` is not configured, Apple Pay availability checks return `false`
78
78
 
79
79
  - Requires `offer` and `country` before click flow is meaningful.
80
80
  - Checks Apple Pay availability on connect; if unavailable, it hides.
81
- - Skips rendering for excluded variants (`bundle`, `insider_print`).
81
+ - Skips rendering for excluded variants (`bundle`, `insider_print`). Every other `ProductVariant` (including `play`) is eligible; billing countries are restricted to the offer's price zone.
82
82
  - Forwards `data-logged-in` from button to modal (`modal.dataset.loggedIn`).
83
83
 
84
+ #### Native Apple Pay button
85
+
86
+ **Feature flag:** it is on for `localhost`, `dev.*` and `stage.*`, and **off in production** until
87
+ `NATIVE_BUTTON_ENABLED_IN_PRODUCTION` (`src/utils/nativeButtonFlag.ts`) is flipped to `true` in a release. It fails
88
+ closed: any other host (www.economist.com, previews, IPs) keeps the custom button. A host can force it either way
89
+ with `configureApplePay({ ..., nativeButton: true | false })`. The flag sets a `data-native-button` attribute on
90
+ `teg-apple-pay-button`, and the native CSS only applies when that attribute is present.
91
+
92
+ Once loading finishes, the button uses Apple's **native CSS button** (`-webkit-appearance: -apple-pay-button`)
93
+ wherever the browser supports it (Safari / iOS). Safari draws Apple's own artwork, so it follows Apple's design
94
+ guidelines, and because it is built into WebKit there is **no SDK script and no extra request** (safe for walls and
95
+ banners). Other browsers, and the loading spinner state, use the package's custom button as the fallback.
96
+
97
+ - Apple controls colour and wording: `--apple-pay-background-color`, `--apple-pay-foreground-color` and the
98
+ "Subscribe with" caption/logo do not apply to the native button.
99
+ - Optional overrides: `--apple-pay-button-type` (`plain`, `buy`, `subscribe`, `check-out`, ...; default `subscribe`)
100
+ and `--apple-pay-button-style` (`black`, `white`, `white-outline`; default `black`).
101
+ - Size and radius still follow `--apple-pay-height` and `--apple-pay-border-radius`.
102
+ - jsdom cannot render this, so tests assert the template contract. Verify visually in Safari.
103
+
84
104
  #### Awaiting render completion — `whenReady()`
85
105
 
86
106
  Use `whenReady()` to await the component's render lifecycle after appending it
@@ -128,6 +148,7 @@ Consumers should listen for this event and continue payment orchestration.
128
148
  - `DUAL_OFFER_BANNER` (or omitted): always-on after offer exclusions — no homepage/Safari gate at `createIfEnabled` (device gating via `isApplePayAvailable` on mount).
129
149
  - `FREE_TRIAL_BANNER`: same always-on-after-exclusions gate as Dual; wallet impression `entry_point` is `free_trial_banner`.
130
150
  - `FREE_TRIAL_POPUP`: same always-on-after-exclusions gate. Wallet impression `entry_point` is `free_trial_popup`.
151
+ - `SUBSCRIBE`: same always-on-after-exclusions gate for `/subscribe` (sma-checkout); no Amplitude. Wallet impression `entry_point` is `subscribe`.
131
152
  - `PAYWALL`: always-on after offer exclusions + Safari/Apple placement eligibility. No Amplitude experiment / `$exposure`.
132
153
  - `REGWALL`: inert — always returns `null`.
133
154
  - `ApplePayModal`: modal component class.
package/dist/index.js CHANGED
@@ -1111,6 +1111,41 @@ var apple_pay_button_template_default = `<style>
1111
1111
  transform: translate(-50%, -50%) rotate(360deg);
1112
1112
  }
1113
1113
  }
1114
+
1115
+ /*
1116
+ * Native Apple Pay button. Safari (and iOS) draw Apple's own artwork for this appearance, which keeps the
1117
+ * button compliant with Apple's design guidelines. It is built into WebKit: no SDK script and no network
1118
+ * request, so it costs nothing on latency-sensitive surfaces (walls, banners).
1119
+ *
1120
+ * Gated by the \`data-native-button\` attribute (feature flag, see utils/nativeButtonFlag.ts: on for
1121
+ * localhost/dev/stage, off for production until flipped). Applied only where the browser supports it and
1122
+ * only once loading has finished: the spinner
1123
+ * (.wap-loading) needs the custom button. Everywhere else (non-WebKit browsers, or the QA bypass on a
1124
+ * browser without support) the custom button above remains the fallback.
1125
+ *
1126
+ * Apple controls colour and wording, so --apple-pay-background-color / --apple-pay-foreground-color and
1127
+ * the caption/logo are ignored here. Override with:
1128
+ * --apple-pay-button-type (plain | buy | subscribe | check-out | ...) default: subscribe
1129
+ * --apple-pay-button-style (black | white | white-outline) default: black
1130
+ * Size and radius still follow --apple-pay-height and --apple-pay-border-radius.
1131
+ */
1132
+ @supports (-webkit-appearance: -apple-pay-button) {
1133
+ teg-apple-pay-button[data-native-button] .apple-pay-btn:not(.wap-loading) {
1134
+ -webkit-appearance: -apple-pay-button;
1135
+ appearance: -apple-pay-button;
1136
+ -apple-pay-button-type: var(--apple-pay-button-type, subscribe);
1137
+ -apple-pay-button-style: var(--apple-pay-button-style, black);
1138
+ min-height: var(--apple-pay-height, 2.5rem);
1139
+ border-radius: var(--apple-pay-border-radius, 0.25rem);
1140
+ font-size: 0;
1141
+ }
1142
+
1143
+ teg-apple-pay-button[data-native-button]
1144
+ .apple-pay-btn:not(.wap-loading)
1145
+ .apple-pay-btn__label {
1146
+ display: none;
1147
+ }
1148
+ }
1114
1149
  </style>
1115
1150
 
1116
1151
  <div class="apple-pay-container" aria-label="Subscribe with Apple Pay">
@@ -1942,6 +1977,21 @@ var getSupportedBillingCountries = (offerCountry, offerVariant) => {
1942
1977
  return [...zoneCountries];
1943
1978
  };
1944
1979
 
1980
+ // src/utils/nativeButtonFlag.ts
1981
+ var NATIVE_BUTTON_ENABLED_IN_PRODUCTION = false;
1982
+ var NON_PRODUCTION_FIRST_LABELS = ["localhost", "dev", "stage"];
1983
+ var isNativeButtonEnabled = (hostname = window.location.hostname, override, enabledInProduction = NATIVE_BUTTON_ENABLED_IN_PRODUCTION) => {
1984
+ if (override !== void 0) {
1985
+ return override;
1986
+ }
1987
+ if (enabledInProduction) {
1988
+ return true;
1989
+ }
1990
+ const isBareLocalhost = hostname === "localhost";
1991
+ const isEnvSubdomain = hostname.split(".").length > 1 && NON_PRODUCTION_FIRST_LABELS.includes(hostname.split(".")[0]);
1992
+ return isBareLocalhost || isEnvSubdomain;
1993
+ };
1994
+
1945
1995
  // src/utils/applePayExpressEligibility.ts
1946
1996
  var isEligibleForApplePayExpressPaywall = () => isAppleDeviceOrSafari();
1947
1997
 
@@ -1952,6 +2002,7 @@ var ApplePayEntryPoint = /* @__PURE__ */ ((ApplePayEntryPoint2) => {
1952
2002
  ApplePayEntryPoint2["DUAL_OFFER_BANNER"] = "dual_offer_banner";
1953
2003
  ApplePayEntryPoint2["FREE_TRIAL_BANNER"] = "free_trial_banner";
1954
2004
  ApplePayEntryPoint2["FREE_TRIAL_POPUP"] = "free_trial_popup";
2005
+ ApplePayEntryPoint2["SUBSCRIBE"] = "subscribe";
1955
2006
  return ApplePayEntryPoint2;
1956
2007
  })(ApplePayEntryPoint || {});
1957
2008
 
@@ -1972,6 +2023,10 @@ var ENTRY_POINT_CONFIG = {
1972
2023
  },
1973
2024
  ["free_trial_popup" /* FREE_TRIAL_POPUP */]: {
1974
2025
  isEligible: () => true
2026
+ },
2027
+ ["subscribe" /* SUBSCRIBE */]: {
2028
+ isEligible: () => true
2029
+ // Always-on after offer exclusions — host (sma-checkout) owns rollout toggle
1975
2030
  }
1976
2031
  };
1977
2032
  var TOTAL_LABEL = "The Economist";
@@ -2219,6 +2274,13 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2219
2274
  const template = document.createElement("template");
2220
2275
  template.innerHTML = apple_pay_button_template_default;
2221
2276
  this.appendChild(template.content.cloneNode(true));
2277
+ this.toggleAttribute(
2278
+ "data-native-button",
2279
+ isNativeButtonEnabled(
2280
+ window.location.hostname,
2281
+ getApplePayConfig()?.nativeButton
2282
+ )
2283
+ );
2222
2284
  const button = this.querySelector(SEL_BUTTON);
2223
2285
  button.classList.add("wap-loading");
2224
2286
  button.setAttribute("disabled", "");
@@ -1106,6 +1106,41 @@ var apple_pay_button_template_default = `<style>
1106
1106
  transform: translate(-50%, -50%) rotate(360deg);
1107
1107
  }
1108
1108
  }
1109
+
1110
+ /*
1111
+ * Native Apple Pay button. Safari (and iOS) draw Apple's own artwork for this appearance, which keeps the
1112
+ * button compliant with Apple's design guidelines. It is built into WebKit: no SDK script and no network
1113
+ * request, so it costs nothing on latency-sensitive surfaces (walls, banners).
1114
+ *
1115
+ * Gated by the \`data-native-button\` attribute (feature flag, see utils/nativeButtonFlag.ts: on for
1116
+ * localhost/dev/stage, off for production until flipped). Applied only where the browser supports it and
1117
+ * only once loading has finished: the spinner
1118
+ * (.wap-loading) needs the custom button. Everywhere else (non-WebKit browsers, or the QA bypass on a
1119
+ * browser without support) the custom button above remains the fallback.
1120
+ *
1121
+ * Apple controls colour and wording, so --apple-pay-background-color / --apple-pay-foreground-color and
1122
+ * the caption/logo are ignored here. Override with:
1123
+ * --apple-pay-button-type (plain | buy | subscribe | check-out | ...) default: subscribe
1124
+ * --apple-pay-button-style (black | white | white-outline) default: black
1125
+ * Size and radius still follow --apple-pay-height and --apple-pay-border-radius.
1126
+ */
1127
+ @supports (-webkit-appearance: -apple-pay-button) {
1128
+ teg-apple-pay-button[data-native-button] .apple-pay-btn:not(.wap-loading) {
1129
+ -webkit-appearance: -apple-pay-button;
1130
+ appearance: -apple-pay-button;
1131
+ -apple-pay-button-type: var(--apple-pay-button-type, subscribe);
1132
+ -apple-pay-button-style: var(--apple-pay-button-style, black);
1133
+ min-height: var(--apple-pay-height, 2.5rem);
1134
+ border-radius: var(--apple-pay-border-radius, 0.25rem);
1135
+ font-size: 0;
1136
+ }
1137
+
1138
+ teg-apple-pay-button[data-native-button]
1139
+ .apple-pay-btn:not(.wap-loading)
1140
+ .apple-pay-btn__label {
1141
+ display: none;
1142
+ }
1143
+ }
1109
1144
  </style>
1110
1145
 
1111
1146
  <div class="apple-pay-container" aria-label="Subscribe with Apple Pay">
@@ -1937,6 +1972,21 @@ var getSupportedBillingCountries = (offerCountry, offerVariant) => {
1937
1972
  return [...zoneCountries];
1938
1973
  };
1939
1974
 
1975
+ // src/utils/nativeButtonFlag.ts
1976
+ var NATIVE_BUTTON_ENABLED_IN_PRODUCTION = false;
1977
+ var NON_PRODUCTION_FIRST_LABELS = ["localhost", "dev", "stage"];
1978
+ var isNativeButtonEnabled = (hostname = window.location.hostname, override, enabledInProduction = NATIVE_BUTTON_ENABLED_IN_PRODUCTION) => {
1979
+ if (override !== void 0) {
1980
+ return override;
1981
+ }
1982
+ if (enabledInProduction) {
1983
+ return true;
1984
+ }
1985
+ const isBareLocalhost = hostname === "localhost";
1986
+ const isEnvSubdomain = hostname.split(".").length > 1 && NON_PRODUCTION_FIRST_LABELS.includes(hostname.split(".")[0]);
1987
+ return isBareLocalhost || isEnvSubdomain;
1988
+ };
1989
+
1940
1990
  // src/utils/applePayExpressEligibility.ts
1941
1991
  var isEligibleForApplePayExpressPaywall = () => isAppleDeviceOrSafari();
1942
1992
 
@@ -1957,6 +2007,10 @@ var ENTRY_POINT_CONFIG = {
1957
2007
  },
1958
2008
  ["free_trial_popup" /* FREE_TRIAL_POPUP */]: {
1959
2009
  isEligible: () => true
2010
+ },
2011
+ ["subscribe" /* SUBSCRIBE */]: {
2012
+ isEligible: () => true
2013
+ // Always-on after offer exclusions — host (sma-checkout) owns rollout toggle
1960
2014
  }
1961
2015
  };
1962
2016
  var TOTAL_LABEL = "The Economist";
@@ -2204,6 +2258,13 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2204
2258
  const template = document.createElement("template");
2205
2259
  template.innerHTML = apple_pay_button_template_default;
2206
2260
  this.appendChild(template.content.cloneNode(true));
2261
+ this.toggleAttribute(
2262
+ "data-native-button",
2263
+ isNativeButtonEnabled(
2264
+ window.location.hostname,
2265
+ getApplePayConfig()?.nativeButton
2266
+ )
2267
+ );
2207
2268
  const button = this.querySelector(SEL_BUTTON);
2208
2269
  button.classList.add("wap-loading");
2209
2270
  button.setAttribute("disabled", "");
@@ -1114,6 +1114,41 @@ var apple_pay_button_template_default = `<style>
1114
1114
  transform: translate(-50%, -50%) rotate(360deg);
1115
1115
  }
1116
1116
  }
1117
+
1118
+ /*
1119
+ * Native Apple Pay button. Safari (and iOS) draw Apple's own artwork for this appearance, which keeps the
1120
+ * button compliant with Apple's design guidelines. It is built into WebKit: no SDK script and no network
1121
+ * request, so it costs nothing on latency-sensitive surfaces (walls, banners).
1122
+ *
1123
+ * Gated by the \`data-native-button\` attribute (feature flag, see utils/nativeButtonFlag.ts: on for
1124
+ * localhost/dev/stage, off for production until flipped). Applied only where the browser supports it and
1125
+ * only once loading has finished: the spinner
1126
+ * (.wap-loading) needs the custom button. Everywhere else (non-WebKit browsers, or the QA bypass on a
1127
+ * browser without support) the custom button above remains the fallback.
1128
+ *
1129
+ * Apple controls colour and wording, so --apple-pay-background-color / --apple-pay-foreground-color and
1130
+ * the caption/logo are ignored here. Override with:
1131
+ * --apple-pay-button-type (plain | buy | subscribe | check-out | ...) default: subscribe
1132
+ * --apple-pay-button-style (black | white | white-outline) default: black
1133
+ * Size and radius still follow --apple-pay-height and --apple-pay-border-radius.
1134
+ */
1135
+ @supports (-webkit-appearance: -apple-pay-button) {
1136
+ teg-apple-pay-button[data-native-button] .apple-pay-btn:not(.wap-loading) {
1137
+ -webkit-appearance: -apple-pay-button;
1138
+ appearance: -apple-pay-button;
1139
+ -apple-pay-button-type: var(--apple-pay-button-type, subscribe);
1140
+ -apple-pay-button-style: var(--apple-pay-button-style, black);
1141
+ min-height: var(--apple-pay-height, 2.5rem);
1142
+ border-radius: var(--apple-pay-border-radius, 0.25rem);
1143
+ font-size: 0;
1144
+ }
1145
+
1146
+ teg-apple-pay-button[data-native-button]
1147
+ .apple-pay-btn:not(.wap-loading)
1148
+ .apple-pay-btn__label {
1149
+ display: none;
1150
+ }
1151
+ }
1117
1152
  </style>
1118
1153
 
1119
1154
  <div class="apple-pay-container" aria-label="Subscribe with Apple Pay">
@@ -1945,6 +1980,21 @@ var getSupportedBillingCountries = (offerCountry, offerVariant) => {
1945
1980
  return [...zoneCountries];
1946
1981
  };
1947
1982
 
1983
+ // src/utils/nativeButtonFlag.ts
1984
+ var NATIVE_BUTTON_ENABLED_IN_PRODUCTION = false;
1985
+ var NON_PRODUCTION_FIRST_LABELS = ["localhost", "dev", "stage"];
1986
+ var isNativeButtonEnabled = (hostname = window.location.hostname, override, enabledInProduction = NATIVE_BUTTON_ENABLED_IN_PRODUCTION) => {
1987
+ if (override !== void 0) {
1988
+ return override;
1989
+ }
1990
+ if (enabledInProduction) {
1991
+ return true;
1992
+ }
1993
+ const isBareLocalhost = hostname === "localhost";
1994
+ const isEnvSubdomain = hostname.split(".").length > 1 && NON_PRODUCTION_FIRST_LABELS.includes(hostname.split(".")[0]);
1995
+ return isBareLocalhost || isEnvSubdomain;
1996
+ };
1997
+
1948
1998
  // src/utils/applePayExpressEligibility.ts
1949
1999
  var isEligibleForApplePayExpressPaywall = () => isAppleDeviceOrSafari();
1950
2000
 
@@ -1965,6 +2015,10 @@ var ENTRY_POINT_CONFIG = {
1965
2015
  },
1966
2016
  ["free_trial_popup" /* FREE_TRIAL_POPUP */]: {
1967
2017
  isEligible: () => true
2018
+ },
2019
+ ["subscribe" /* SUBSCRIBE */]: {
2020
+ isEligible: () => true
2021
+ // Always-on after offer exclusions — host (sma-checkout) owns rollout toggle
1968
2022
  }
1969
2023
  };
1970
2024
  var TOTAL_LABEL = "The Economist";
@@ -2212,6 +2266,13 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2212
2266
  const template = document.createElement("template");
2213
2267
  template.innerHTML = apple_pay_button_template_default;
2214
2268
  this.appendChild(template.content.cloneNode(true));
2269
+ this.toggleAttribute(
2270
+ "data-native-button",
2271
+ isNativeButtonEnabled(
2272
+ window.location.hostname,
2273
+ getApplePayConfig()?.nativeButton
2274
+ )
2275
+ );
2215
2276
  const button = this.querySelector(SEL_BUTTON);
2216
2277
  button.classList.add("wap-loading");
2217
2278
  button.setAttribute("disabled", "");
@@ -1106,6 +1106,41 @@ var apple_pay_button_template_default = `<style>
1106
1106
  transform: translate(-50%, -50%) rotate(360deg);
1107
1107
  }
1108
1108
  }
1109
+
1110
+ /*
1111
+ * Native Apple Pay button. Safari (and iOS) draw Apple's own artwork for this appearance, which keeps the
1112
+ * button compliant with Apple's design guidelines. It is built into WebKit: no SDK script and no network
1113
+ * request, so it costs nothing on latency-sensitive surfaces (walls, banners).
1114
+ *
1115
+ * Gated by the \`data-native-button\` attribute (feature flag, see utils/nativeButtonFlag.ts: on for
1116
+ * localhost/dev/stage, off for production until flipped). Applied only where the browser supports it and
1117
+ * only once loading has finished: the spinner
1118
+ * (.wap-loading) needs the custom button. Everywhere else (non-WebKit browsers, or the QA bypass on a
1119
+ * browser without support) the custom button above remains the fallback.
1120
+ *
1121
+ * Apple controls colour and wording, so --apple-pay-background-color / --apple-pay-foreground-color and
1122
+ * the caption/logo are ignored here. Override with:
1123
+ * --apple-pay-button-type (plain | buy | subscribe | check-out | ...) default: subscribe
1124
+ * --apple-pay-button-style (black | white | white-outline) default: black
1125
+ * Size and radius still follow --apple-pay-height and --apple-pay-border-radius.
1126
+ */
1127
+ @supports (-webkit-appearance: -apple-pay-button) {
1128
+ teg-apple-pay-button[data-native-button] .apple-pay-btn:not(.wap-loading) {
1129
+ -webkit-appearance: -apple-pay-button;
1130
+ appearance: -apple-pay-button;
1131
+ -apple-pay-button-type: var(--apple-pay-button-type, subscribe);
1132
+ -apple-pay-button-style: var(--apple-pay-button-style, black);
1133
+ min-height: var(--apple-pay-height, 2.5rem);
1134
+ border-radius: var(--apple-pay-border-radius, 0.25rem);
1135
+ font-size: 0;
1136
+ }
1137
+
1138
+ teg-apple-pay-button[data-native-button]
1139
+ .apple-pay-btn:not(.wap-loading)
1140
+ .apple-pay-btn__label {
1141
+ display: none;
1142
+ }
1143
+ }
1109
1144
  </style>
1110
1145
 
1111
1146
  <div class="apple-pay-container" aria-label="Subscribe with Apple Pay">
@@ -1937,6 +1972,21 @@ var getSupportedBillingCountries = (offerCountry, offerVariant) => {
1937
1972
  return [...zoneCountries];
1938
1973
  };
1939
1974
 
1975
+ // src/utils/nativeButtonFlag.ts
1976
+ var NATIVE_BUTTON_ENABLED_IN_PRODUCTION = false;
1977
+ var NON_PRODUCTION_FIRST_LABELS = ["localhost", "dev", "stage"];
1978
+ var isNativeButtonEnabled = (hostname = window.location.hostname, override, enabledInProduction = NATIVE_BUTTON_ENABLED_IN_PRODUCTION) => {
1979
+ if (override !== void 0) {
1980
+ return override;
1981
+ }
1982
+ if (enabledInProduction) {
1983
+ return true;
1984
+ }
1985
+ const isBareLocalhost = hostname === "localhost";
1986
+ const isEnvSubdomain = hostname.split(".").length > 1 && NON_PRODUCTION_FIRST_LABELS.includes(hostname.split(".")[0]);
1987
+ return isBareLocalhost || isEnvSubdomain;
1988
+ };
1989
+
1940
1990
  // src/utils/applePayExpressEligibility.ts
1941
1991
  var isEligibleForApplePayExpressPaywall = () => isAppleDeviceOrSafari();
1942
1992
 
@@ -1957,6 +2007,10 @@ var ENTRY_POINT_CONFIG = {
1957
2007
  },
1958
2008
  ["free_trial_popup" /* FREE_TRIAL_POPUP */]: {
1959
2009
  isEligible: () => true
2010
+ },
2011
+ ["subscribe" /* SUBSCRIBE */]: {
2012
+ isEligible: () => true
2013
+ // Always-on after offer exclusions — host (sma-checkout) owns rollout toggle
1960
2014
  }
1961
2015
  };
1962
2016
  var TOTAL_LABEL = "The Economist";
@@ -2204,6 +2258,13 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2204
2258
  const template = document.createElement("template");
2205
2259
  template.innerHTML = apple_pay_button_template_default;
2206
2260
  this.appendChild(template.content.cloneNode(true));
2261
+ this.toggleAttribute(
2262
+ "data-native-button",
2263
+ isNativeButtonEnabled(
2264
+ window.location.hostname,
2265
+ getApplePayConfig()?.nativeButton
2266
+ )
2267
+ );
2207
2268
  const button = this.querySelector(SEL_BUTTON);
2208
2269
  button.classList.add("wap-loading");
2209
2270
  button.setAttribute("disabled", "");
@@ -3,6 +3,11 @@ export interface ApplePayRuntimeConfig {
3
3
  recaptchaSiteKey?: string;
4
4
  debugBypassEnabled?: boolean;
5
5
  walletApiBaseUrl: string;
6
+ /**
7
+ * Force Apple's native CSS button on/off, overriding the built-in flag
8
+ * (default: on for localhost/dev/stage, off for production).
9
+ */
10
+ nativeButton?: boolean;
6
11
  }
7
12
  export declare const configureApplePay: (config: ApplePayRuntimeConfig) => void;
8
13
  export declare const getApplePayConfig: () => ApplePayRuntimeConfig | null;
@@ -4,5 +4,7 @@ export declare enum ApplePayEntryPoint {
4
4
  DUAL_OFFER_BANNER = "dual_offer_banner",
5
5
  FREE_TRIAL_BANNER = "free_trial_banner",
6
6
  /** Post-registration free-trial popup. Not Amplitude-gated. */
7
- FREE_TRIAL_POPUP = "free_trial_popup"
7
+ FREE_TRIAL_POPUP = "free_trial_popup",
8
+ /** /subscribe offers page (sma-checkout). Not Amplitude-gated. */
9
+ SUBSCRIBE = "subscribe"
8
10
  }
@@ -5,6 +5,7 @@ var ApplePayEntryPoint = /* @__PURE__ */ ((ApplePayEntryPoint2) => {
5
5
  ApplePayEntryPoint2["DUAL_OFFER_BANNER"] = "dual_offer_banner";
6
6
  ApplePayEntryPoint2["FREE_TRIAL_BANNER"] = "free_trial_banner";
7
7
  ApplePayEntryPoint2["FREE_TRIAL_POPUP"] = "free_trial_popup";
8
+ ApplePayEntryPoint2["SUBSCRIBE"] = "subscribe";
8
9
  return ApplePayEntryPoint2;
9
10
  })(ApplePayEntryPoint || {});
10
11
  export {
package/dist/src/index.js CHANGED
@@ -1111,6 +1111,41 @@ var apple_pay_button_template_default = `<style>
1111
1111
  transform: translate(-50%, -50%) rotate(360deg);
1112
1112
  }
1113
1113
  }
1114
+
1115
+ /*
1116
+ * Native Apple Pay button. Safari (and iOS) draw Apple's own artwork for this appearance, which keeps the
1117
+ * button compliant with Apple's design guidelines. It is built into WebKit: no SDK script and no network
1118
+ * request, so it costs nothing on latency-sensitive surfaces (walls, banners).
1119
+ *
1120
+ * Gated by the \`data-native-button\` attribute (feature flag, see utils/nativeButtonFlag.ts: on for
1121
+ * localhost/dev/stage, off for production until flipped). Applied only where the browser supports it and
1122
+ * only once loading has finished: the spinner
1123
+ * (.wap-loading) needs the custom button. Everywhere else (non-WebKit browsers, or the QA bypass on a
1124
+ * browser without support) the custom button above remains the fallback.
1125
+ *
1126
+ * Apple controls colour and wording, so --apple-pay-background-color / --apple-pay-foreground-color and
1127
+ * the caption/logo are ignored here. Override with:
1128
+ * --apple-pay-button-type (plain | buy | subscribe | check-out | ...) default: subscribe
1129
+ * --apple-pay-button-style (black | white | white-outline) default: black
1130
+ * Size and radius still follow --apple-pay-height and --apple-pay-border-radius.
1131
+ */
1132
+ @supports (-webkit-appearance: -apple-pay-button) {
1133
+ teg-apple-pay-button[data-native-button] .apple-pay-btn:not(.wap-loading) {
1134
+ -webkit-appearance: -apple-pay-button;
1135
+ appearance: -apple-pay-button;
1136
+ -apple-pay-button-type: var(--apple-pay-button-type, subscribe);
1137
+ -apple-pay-button-style: var(--apple-pay-button-style, black);
1138
+ min-height: var(--apple-pay-height, 2.5rem);
1139
+ border-radius: var(--apple-pay-border-radius, 0.25rem);
1140
+ font-size: 0;
1141
+ }
1142
+
1143
+ teg-apple-pay-button[data-native-button]
1144
+ .apple-pay-btn:not(.wap-loading)
1145
+ .apple-pay-btn__label {
1146
+ display: none;
1147
+ }
1148
+ }
1114
1149
  </style>
1115
1150
 
1116
1151
  <div class="apple-pay-container" aria-label="Subscribe with Apple Pay">
@@ -1942,6 +1977,21 @@ var getSupportedBillingCountries = (offerCountry, offerVariant) => {
1942
1977
  return [...zoneCountries];
1943
1978
  };
1944
1979
 
1980
+ // src/utils/nativeButtonFlag.ts
1981
+ var NATIVE_BUTTON_ENABLED_IN_PRODUCTION = false;
1982
+ var NON_PRODUCTION_FIRST_LABELS = ["localhost", "dev", "stage"];
1983
+ var isNativeButtonEnabled = (hostname = window.location.hostname, override, enabledInProduction = NATIVE_BUTTON_ENABLED_IN_PRODUCTION) => {
1984
+ if (override !== void 0) {
1985
+ return override;
1986
+ }
1987
+ if (enabledInProduction) {
1988
+ return true;
1989
+ }
1990
+ const isBareLocalhost = hostname === "localhost";
1991
+ const isEnvSubdomain = hostname.split(".").length > 1 && NON_PRODUCTION_FIRST_LABELS.includes(hostname.split(".")[0]);
1992
+ return isBareLocalhost || isEnvSubdomain;
1993
+ };
1994
+
1945
1995
  // src/utils/applePayExpressEligibility.ts
1946
1996
  var isEligibleForApplePayExpressPaywall = () => isAppleDeviceOrSafari();
1947
1997
 
@@ -1952,6 +2002,7 @@ var ApplePayEntryPoint = /* @__PURE__ */ ((ApplePayEntryPoint2) => {
1952
2002
  ApplePayEntryPoint2["DUAL_OFFER_BANNER"] = "dual_offer_banner";
1953
2003
  ApplePayEntryPoint2["FREE_TRIAL_BANNER"] = "free_trial_banner";
1954
2004
  ApplePayEntryPoint2["FREE_TRIAL_POPUP"] = "free_trial_popup";
2005
+ ApplePayEntryPoint2["SUBSCRIBE"] = "subscribe";
1955
2006
  return ApplePayEntryPoint2;
1956
2007
  })(ApplePayEntryPoint || {});
1957
2008
 
@@ -1972,6 +2023,10 @@ var ENTRY_POINT_CONFIG = {
1972
2023
  },
1973
2024
  ["free_trial_popup" /* FREE_TRIAL_POPUP */]: {
1974
2025
  isEligible: () => true
2026
+ },
2027
+ ["subscribe" /* SUBSCRIBE */]: {
2028
+ isEligible: () => true
2029
+ // Always-on after offer exclusions — host (sma-checkout) owns rollout toggle
1975
2030
  }
1976
2031
  };
1977
2032
  var TOTAL_LABEL = "The Economist";
@@ -2219,6 +2274,13 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2219
2274
  const template = document.createElement("template");
2220
2275
  template.innerHTML = apple_pay_button_template_default;
2221
2276
  this.appendChild(template.content.cloneNode(true));
2277
+ this.toggleAttribute(
2278
+ "data-native-button",
2279
+ isNativeButtonEnabled(
2280
+ window.location.hostname,
2281
+ getApplePayConfig()?.nativeButton
2282
+ )
2283
+ );
2222
2284
  const button = this.querySelector(SEL_BUTTON);
2223
2285
  button.classList.add("wap-loading");
2224
2286
  button.setAttribute("disabled", "");
@@ -1,4 +1,4 @@
1
- export type ProductVariant = 'bundle' | 'digital' | 'espresso' | 'espressopod' | 'podcast' | 'insider_digital' | 'insider_print';
1
+ export type ProductVariant = 'bundle' | 'digital' | 'espresso' | 'espressopod' | 'podcast' | 'insider_digital' | 'play' | 'insider_print';
2
2
  export type PeriodUnit = 'week' | 'month' | 'year';
3
3
  export type Period = {
4
4
  duration: number;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Feature flag for Apple's native CSS button (see README "Native Apple Pay button").
3
+ *
4
+ * It is on for known non-production hosts (localhost, dev, stage) so it can be tested, and OFF for
5
+ * production until this constant is flipped to `true` in a release.
6
+ *
7
+ * Fails closed: only `localhost`, `dev.*` and `stage.*` count as non-production. Any other host
8
+ * (www.economist.com, previews, IPs, tunnels) keeps the custom button while the flag is off.
9
+ * A host can force either value with `configureApplePay({ nativeButton })`.
10
+ */
11
+ export declare const NATIVE_BUTTON_ENABLED_IN_PRODUCTION = false;
12
+ export declare const isNativeButtonEnabled: (hostname?: string, override?: boolean, enabledInProduction?: boolean) => boolean;
@@ -0,0 +1,18 @@
1
+ // src/utils/nativeButtonFlag.ts
2
+ var NATIVE_BUTTON_ENABLED_IN_PRODUCTION = false;
3
+ var NON_PRODUCTION_FIRST_LABELS = ["localhost", "dev", "stage"];
4
+ var isNativeButtonEnabled = (hostname = window.location.hostname, override, enabledInProduction = NATIVE_BUTTON_ENABLED_IN_PRODUCTION) => {
5
+ if (override !== void 0) {
6
+ return override;
7
+ }
8
+ if (enabledInProduction) {
9
+ return true;
10
+ }
11
+ const isBareLocalhost = hostname === "localhost";
12
+ const isEnvSubdomain = hostname.split(".").length > 1 && NON_PRODUCTION_FIRST_LABELS.includes(hostname.split(".")[0]);
13
+ return isBareLocalhost || isEnvSubdomain;
14
+ };
15
+ export {
16
+ NATIVE_BUTTON_ENABLED_IN_PRODUCTION,
17
+ isNativeButtonEnabled
18
+ };
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": "1.13.0",
4
+ "version": "1.15.0",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",