@economist/web-apple-pay 0.1.3-beta.24 → 0.1.3-beta.27

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
@@ -320,28 +320,41 @@ var apple_pay_modal_template_default = `<style>
320
320
  cursor: not-allowed;
321
321
  }
322
322
 
323
- .apm__cta[aria-busy="true"] > * {
324
- visibility: hidden;
323
+ .apm__cta-content {
324
+ display: flex;
325
+ align-items: center;
326
+ gap: 0.375rem;
327
+ }
328
+
329
+ .apm__cta-label {
330
+ display: inline-flex;
331
+ align-items: center;
332
+ gap: 0.375rem;
325
333
  }
326
334
 
327
- .apm__cta[aria-busy="true"]::after {
335
+ .apm__cta-loading {
336
+ display: none;
337
+ }
338
+
339
+ .apm__cta[aria-busy="true"]::before {
328
340
  content: '';
329
341
  position: absolute;
330
- left: 50%;
331
342
  top: 50%;
332
- margin-left: -0.625rem;
333
- margin-top: -0.625rem;
343
+ left: 50%;
334
344
  width: 1.25rem;
335
345
  height: 1.25rem;
336
- border: 2px solid rgba(255, 255, 255, 0.2);
346
+ border: 2px solid rgba(255, 255, 255, 0.25);
337
347
  border-top-color: #fff;
338
348
  border-radius: 50%;
339
349
  animation: apm-cta-spinner 0.8s linear infinite;
340
350
  }
341
351
 
342
352
  @keyframes apm-cta-spinner {
353
+ from {
354
+ transform: translate(-50%, -50%) rotate(0deg);
355
+ }
343
356
  to {
344
- transform: rotate(360deg);
357
+ transform: translate(-50%, -50%) rotate(360deg);
345
358
  }
346
359
  }
347
360
 
@@ -518,11 +531,14 @@ var apple_pay_modal_template_default = `<style>
518
531
  </div>
519
532
  <button class="apm__cta" id="apple-pay-modal-cta" aria-label="Continue with Apple Pay">
520
533
  <span class="apm__cta-content">
521
- Continue with
522
- <svg width="51" height="22" aria-hidden="true" role="img">
523
- <use href="#apple-pay-logo" />
524
- </svg>
534
+ <span class="apm__cta-label">
535
+ Continue with
536
+ <svg width="51" height="22" aria-hidden="true" role="img">
537
+ <use href="#apple-pay-logo" />
538
+ </svg>
539
+ </span>
525
540
  </span>
541
+ <span class="apm__cta-loading" aria-hidden="true">Loading...</span>
526
542
  </button>
527
543
  </div>
528
544
  </div>
@@ -1035,28 +1051,34 @@ var apple_pay_button_template_default = `<style>
1035
1051
  cursor: default;
1036
1052
  }
1037
1053
 
1038
- teg-apple-pay-button .apple-pay-btn.wap-loading svg {
1039
- visibility: hidden;
1040
- }
1041
-
1042
- teg-apple-pay-button .apple-pay-btn.wap-loading::after {
1054
+ teg-apple-pay-button .apple-pay-btn.wap-loading::before {
1043
1055
  content: '';
1044
1056
  position: absolute;
1045
- left: 50%;
1046
1057
  top: 50%;
1047
- margin-left: -0.625rem;
1048
- margin-top: -0.625rem;
1058
+ left: 50%;
1049
1059
  width: 1.25rem;
1050
1060
  height: 1.25rem;
1051
- border: 2px solid rgba(255, 255, 255, 0.2);
1061
+ border: 2px solid rgba(255, 255, 255, 0.25);
1052
1062
  border-top-color: #fff;
1053
1063
  border-radius: 50%;
1054
1064
  animation: wap-button-spinner 0.8s linear infinite;
1055
1065
  }
1056
1066
 
1067
+ teg-apple-pay-button .apple-pay-btn__logo {
1068
+ display: inline-flex;
1069
+ align-items: center;
1070
+ }
1071
+
1072
+ teg-apple-pay-button .apple-pay-btn__loading {
1073
+ display: none;
1074
+ }
1075
+
1057
1076
  @keyframes wap-button-spinner {
1077
+ from {
1078
+ transform: translate(-50%, -50%) rotate(0deg);
1079
+ }
1058
1080
  to {
1059
- transform: rotate(360deg);
1081
+ transform: translate(-50%, -50%) rotate(360deg);
1060
1082
  }
1061
1083
  }
1062
1084
  </style>
@@ -1068,9 +1090,12 @@ var apple_pay_button_template_default = `<style>
1068
1090
  aria-label="Pay with Apple Pay"
1069
1091
  data-analytics="paywall:apple-pay-checkout"
1070
1092
  >
1071
- <svg width="51" height="22" aria-label="Apple Pay" role="img">
1072
- <use href="#apple-pay-logo" />
1073
- </svg>
1093
+ <span class="apple-pay-btn__logo">
1094
+ <svg width="51" height="22" aria-label="Apple Pay" role="img">
1095
+ <use href="#apple-pay-logo" />
1096
+ </svg>
1097
+ </span>
1098
+ <span class="apple-pay-btn__loading" aria-hidden="true">Loading...</span>
1074
1099
  </button>
1075
1100
  </div>
1076
1101
  `;
@@ -1182,6 +1207,7 @@ var validateAppleMerchant = (data) => {
1182
1207
  });
1183
1208
  };
1184
1209
  var performPurchase = (data) => {
1210
+ console.log("[web-apple-pay] /v1/wallet/purchase payload", JSON.stringify(data, null, 2));
1185
1211
  return apiFetch("/v1/wallet/purchase", {
1186
1212
  method: "POST",
1187
1213
  body: JSON.stringify(data),
@@ -1594,13 +1620,17 @@ async function handlePaymentAuthorized(event, session, sessionData, config) {
1594
1620
  sessionData,
1595
1621
  config.supportedBillingCountries
1596
1622
  );
1623
+ const resolvedShippingContact = sessionData.loggedIn ? event.payment.shippingContact?.emailAddress ? event.payment.shippingContact : {
1624
+ ...event.payment.shippingContact ?? {},
1625
+ emailAddress: sessionData.emailAddress
1626
+ } : event.payment.shippingContact;
1597
1627
  const result = await performPurchase({
1598
1628
  applePayToken: event.payment.token,
1599
1629
  skuId: config.skuId,
1600
1630
  currency: config.currency,
1601
1631
  billingContact: event.payment.billingContact,
1602
- ...event.payment.shippingContact && {
1603
- shippingContact: event.payment.shippingContact
1632
+ ...resolvedShippingContact && {
1633
+ shippingContact: resolvedShippingContact
1604
1634
  },
1605
1635
  recaptchaTokens: config.recaptchaTokens
1606
1636
  });
@@ -1929,7 +1959,9 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
1929
1959
  const button = document.createElement(_ApplePayButton.tag);
1930
1960
  button.offer = offer;
1931
1961
  button.country = country;
1932
- button.entryPoint = entryPoint;
1962
+ if (entryPoint) {
1963
+ button.entryPoint = entryPoint;
1964
+ }
1933
1965
  return button;
1934
1966
  }
1935
1967
  /**
@@ -2239,6 +2271,13 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2239
2271
  }
2240
2272
  };
2241
2273
 
2274
+ // src/constants.ts
2275
+ var ApplePayEntryPoint = /* @__PURE__ */ ((ApplePayEntryPoint2) => {
2276
+ ApplePayEntryPoint2["PAYWALL"] = "article_paywall";
2277
+ ApplePayEntryPoint2["REGWALL"] = "article_regwall";
2278
+ return ApplePayEntryPoint2;
2279
+ })(ApplePayEntryPoint || {});
2280
+
2242
2281
  // src/index.ts
2243
2282
  function defineApplePayElements() {
2244
2283
  ApplePayButton.define();
@@ -2247,6 +2286,7 @@ function defineApplePayElements() {
2247
2286
  export {
2248
2287
  APPLE_PAY_EXCLUDED_VARIANTS,
2249
2288
  ApplePayButton,
2289
+ ApplePayEntryPoint,
2250
2290
  ApplePayModal,
2251
2291
  configureApplePay,
2252
2292
  defineApplePayElements,
@@ -1,4 +1,5 @@
1
1
  import type { Offer, ProductVariant } from './types/offer.types';
2
+ import { ApplePayEntryPoint } from './constants';
2
3
  export declare const APPLE_PAY_EXCLUDED_VARIANTS: readonly ProductVariant[];
3
4
  export declare class ApplePayButton extends HTMLElement {
4
5
  #private;
@@ -7,13 +8,13 @@ export declare class ApplePayButton extends HTMLElement {
7
8
  /**
8
9
  * Creates and configures an ApplePayButton if the feature flag is present.
9
10
  */
10
- static createIfEnabled(offer: Offer | undefined, country: string, entryPoint: string): ApplePayButton | null;
11
+ static createIfEnabled(offer: Offer | undefined, country: string, entryPoint?: ApplePayEntryPoint): ApplePayButton | null;
11
12
  get offer(): Offer | null;
12
13
  set offer(value: Offer | null);
13
14
  get country(): string;
14
15
  set country(value: string);
15
- get entryPoint(): string;
16
- set entryPoint(value: string);
16
+ get entryPoint(): ApplePayEntryPoint | '';
17
+ set entryPoint(value: ApplePayEntryPoint);
17
18
  /**
18
19
  * Awaitable contract for the component's current render lifecycle.
19
20
  *
@@ -320,28 +320,41 @@ var apple_pay_modal_template_default = `<style>
320
320
  cursor: not-allowed;
321
321
  }
322
322
 
323
- .apm__cta[aria-busy="true"] > * {
324
- visibility: hidden;
323
+ .apm__cta-content {
324
+ display: flex;
325
+ align-items: center;
326
+ gap: 0.375rem;
327
+ }
328
+
329
+ .apm__cta-label {
330
+ display: inline-flex;
331
+ align-items: center;
332
+ gap: 0.375rem;
325
333
  }
326
334
 
327
- .apm__cta[aria-busy="true"]::after {
335
+ .apm__cta-loading {
336
+ display: none;
337
+ }
338
+
339
+ .apm__cta[aria-busy="true"]::before {
328
340
  content: '';
329
341
  position: absolute;
330
- left: 50%;
331
342
  top: 50%;
332
- margin-left: -0.625rem;
333
- margin-top: -0.625rem;
343
+ left: 50%;
334
344
  width: 1.25rem;
335
345
  height: 1.25rem;
336
- border: 2px solid rgba(255, 255, 255, 0.2);
346
+ border: 2px solid rgba(255, 255, 255, 0.25);
337
347
  border-top-color: #fff;
338
348
  border-radius: 50%;
339
349
  animation: apm-cta-spinner 0.8s linear infinite;
340
350
  }
341
351
 
342
352
  @keyframes apm-cta-spinner {
353
+ from {
354
+ transform: translate(-50%, -50%) rotate(0deg);
355
+ }
343
356
  to {
344
- transform: rotate(360deg);
357
+ transform: translate(-50%, -50%) rotate(360deg);
345
358
  }
346
359
  }
347
360
 
@@ -518,11 +531,14 @@ var apple_pay_modal_template_default = `<style>
518
531
  </div>
519
532
  <button class="apm__cta" id="apple-pay-modal-cta" aria-label="Continue with Apple Pay">
520
533
  <span class="apm__cta-content">
521
- Continue with
522
- <svg width="51" height="22" aria-hidden="true" role="img">
523
- <use href="#apple-pay-logo" />
524
- </svg>
534
+ <span class="apm__cta-label">
535
+ Continue with
536
+ <svg width="51" height="22" aria-hidden="true" role="img">
537
+ <use href="#apple-pay-logo" />
538
+ </svg>
539
+ </span>
525
540
  </span>
541
+ <span class="apm__cta-loading" aria-hidden="true">Loading...</span>
526
542
  </button>
527
543
  </div>
528
544
  </div>
@@ -1030,28 +1046,34 @@ var apple_pay_button_template_default = `<style>
1030
1046
  cursor: default;
1031
1047
  }
1032
1048
 
1033
- teg-apple-pay-button .apple-pay-btn.wap-loading svg {
1034
- visibility: hidden;
1035
- }
1036
-
1037
- teg-apple-pay-button .apple-pay-btn.wap-loading::after {
1049
+ teg-apple-pay-button .apple-pay-btn.wap-loading::before {
1038
1050
  content: '';
1039
1051
  position: absolute;
1040
- left: 50%;
1041
1052
  top: 50%;
1042
- margin-left: -0.625rem;
1043
- margin-top: -0.625rem;
1053
+ left: 50%;
1044
1054
  width: 1.25rem;
1045
1055
  height: 1.25rem;
1046
- border: 2px solid rgba(255, 255, 255, 0.2);
1056
+ border: 2px solid rgba(255, 255, 255, 0.25);
1047
1057
  border-top-color: #fff;
1048
1058
  border-radius: 50%;
1049
1059
  animation: wap-button-spinner 0.8s linear infinite;
1050
1060
  }
1051
1061
 
1062
+ teg-apple-pay-button .apple-pay-btn__logo {
1063
+ display: inline-flex;
1064
+ align-items: center;
1065
+ }
1066
+
1067
+ teg-apple-pay-button .apple-pay-btn__loading {
1068
+ display: none;
1069
+ }
1070
+
1052
1071
  @keyframes wap-button-spinner {
1072
+ from {
1073
+ transform: translate(-50%, -50%) rotate(0deg);
1074
+ }
1053
1075
  to {
1054
- transform: rotate(360deg);
1076
+ transform: translate(-50%, -50%) rotate(360deg);
1055
1077
  }
1056
1078
  }
1057
1079
  </style>
@@ -1063,9 +1085,12 @@ var apple_pay_button_template_default = `<style>
1063
1085
  aria-label="Pay with Apple Pay"
1064
1086
  data-analytics="paywall:apple-pay-checkout"
1065
1087
  >
1066
- <svg width="51" height="22" aria-label="Apple Pay" role="img">
1067
- <use href="#apple-pay-logo" />
1068
- </svg>
1088
+ <span class="apple-pay-btn__logo">
1089
+ <svg width="51" height="22" aria-label="Apple Pay" role="img">
1090
+ <use href="#apple-pay-logo" />
1091
+ </svg>
1092
+ </span>
1093
+ <span class="apple-pay-btn__loading" aria-hidden="true">Loading...</span>
1069
1094
  </button>
1070
1095
  </div>
1071
1096
  `;
@@ -1177,6 +1202,7 @@ var validateAppleMerchant = (data) => {
1177
1202
  });
1178
1203
  };
1179
1204
  var performPurchase = (data) => {
1205
+ console.log("[web-apple-pay] /v1/wallet/purchase payload", JSON.stringify(data, null, 2));
1180
1206
  return apiFetch("/v1/wallet/purchase", {
1181
1207
  method: "POST",
1182
1208
  body: JSON.stringify(data),
@@ -1589,13 +1615,17 @@ async function handlePaymentAuthorized(event, session, sessionData, config) {
1589
1615
  sessionData,
1590
1616
  config.supportedBillingCountries
1591
1617
  );
1618
+ const resolvedShippingContact = sessionData.loggedIn ? event.payment.shippingContact?.emailAddress ? event.payment.shippingContact : {
1619
+ ...event.payment.shippingContact ?? {},
1620
+ emailAddress: sessionData.emailAddress
1621
+ } : event.payment.shippingContact;
1592
1622
  const result = await performPurchase({
1593
1623
  applePayToken: event.payment.token,
1594
1624
  skuId: config.skuId,
1595
1625
  currency: config.currency,
1596
1626
  billingContact: event.payment.billingContact,
1597
- ...event.payment.shippingContact && {
1598
- shippingContact: event.payment.shippingContact
1627
+ ...resolvedShippingContact && {
1628
+ shippingContact: resolvedShippingContact
1599
1629
  },
1600
1630
  recaptchaTokens: config.recaptchaTokens
1601
1631
  });
@@ -1924,7 +1954,9 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
1924
1954
  const button = document.createElement(_ApplePayButton.tag);
1925
1955
  button.offer = offer;
1926
1956
  button.country = country;
1927
- button.entryPoint = entryPoint;
1957
+ if (entryPoint) {
1958
+ button.entryPoint = entryPoint;
1959
+ }
1928
1960
  return button;
1929
1961
  }
1930
1962
  /**
@@ -320,28 +320,41 @@ var apple_pay_modal_template_default = `<style>
320
320
  cursor: not-allowed;
321
321
  }
322
322
 
323
- .apm__cta[aria-busy="true"] > * {
324
- visibility: hidden;
323
+ .apm__cta-content {
324
+ display: flex;
325
+ align-items: center;
326
+ gap: 0.375rem;
327
+ }
328
+
329
+ .apm__cta-label {
330
+ display: inline-flex;
331
+ align-items: center;
332
+ gap: 0.375rem;
325
333
  }
326
334
 
327
- .apm__cta[aria-busy="true"]::after {
335
+ .apm__cta-loading {
336
+ display: none;
337
+ }
338
+
339
+ .apm__cta[aria-busy="true"]::before {
328
340
  content: '';
329
341
  position: absolute;
330
- left: 50%;
331
342
  top: 50%;
332
- margin-left: -0.625rem;
333
- margin-top: -0.625rem;
343
+ left: 50%;
334
344
  width: 1.25rem;
335
345
  height: 1.25rem;
336
- border: 2px solid rgba(255, 255, 255, 0.2);
346
+ border: 2px solid rgba(255, 255, 255, 0.25);
337
347
  border-top-color: #fff;
338
348
  border-radius: 50%;
339
349
  animation: apm-cta-spinner 0.8s linear infinite;
340
350
  }
341
351
 
342
352
  @keyframes apm-cta-spinner {
353
+ from {
354
+ transform: translate(-50%, -50%) rotate(0deg);
355
+ }
343
356
  to {
344
- transform: rotate(360deg);
357
+ transform: translate(-50%, -50%) rotate(360deg);
345
358
  }
346
359
  }
347
360
 
@@ -518,11 +531,14 @@ var apple_pay_modal_template_default = `<style>
518
531
  </div>
519
532
  <button class="apm__cta" id="apple-pay-modal-cta" aria-label="Continue with Apple Pay">
520
533
  <span class="apm__cta-content">
521
- Continue with
522
- <svg width="51" height="22" aria-hidden="true" role="img">
523
- <use href="#apple-pay-logo" />
524
- </svg>
534
+ <span class="apm__cta-label">
535
+ Continue with
536
+ <svg width="51" height="22" aria-hidden="true" role="img">
537
+ <use href="#apple-pay-logo" />
538
+ </svg>
539
+ </span>
525
540
  </span>
541
+ <span class="apm__cta-loading" aria-hidden="true">Loading...</span>
526
542
  </button>
527
543
  </div>
528
544
  </div>
@@ -1038,28 +1054,34 @@ var apple_pay_button_template_default = `<style>
1038
1054
  cursor: default;
1039
1055
  }
1040
1056
 
1041
- teg-apple-pay-button .apple-pay-btn.wap-loading svg {
1042
- visibility: hidden;
1043
- }
1044
-
1045
- teg-apple-pay-button .apple-pay-btn.wap-loading::after {
1057
+ teg-apple-pay-button .apple-pay-btn.wap-loading::before {
1046
1058
  content: '';
1047
1059
  position: absolute;
1048
- left: 50%;
1049
1060
  top: 50%;
1050
- margin-left: -0.625rem;
1051
- margin-top: -0.625rem;
1061
+ left: 50%;
1052
1062
  width: 1.25rem;
1053
1063
  height: 1.25rem;
1054
- border: 2px solid rgba(255, 255, 255, 0.2);
1064
+ border: 2px solid rgba(255, 255, 255, 0.25);
1055
1065
  border-top-color: #fff;
1056
1066
  border-radius: 50%;
1057
1067
  animation: wap-button-spinner 0.8s linear infinite;
1058
1068
  }
1059
1069
 
1070
+ teg-apple-pay-button .apple-pay-btn__logo {
1071
+ display: inline-flex;
1072
+ align-items: center;
1073
+ }
1074
+
1075
+ teg-apple-pay-button .apple-pay-btn__loading {
1076
+ display: none;
1077
+ }
1078
+
1060
1079
  @keyframes wap-button-spinner {
1080
+ from {
1081
+ transform: translate(-50%, -50%) rotate(0deg);
1082
+ }
1061
1083
  to {
1062
- transform: rotate(360deg);
1084
+ transform: translate(-50%, -50%) rotate(360deg);
1063
1085
  }
1064
1086
  }
1065
1087
  </style>
@@ -1071,9 +1093,12 @@ var apple_pay_button_template_default = `<style>
1071
1093
  aria-label="Pay with Apple Pay"
1072
1094
  data-analytics="paywall:apple-pay-checkout"
1073
1095
  >
1074
- <svg width="51" height="22" aria-label="Apple Pay" role="img">
1075
- <use href="#apple-pay-logo" />
1076
- </svg>
1096
+ <span class="apple-pay-btn__logo">
1097
+ <svg width="51" height="22" aria-label="Apple Pay" role="img">
1098
+ <use href="#apple-pay-logo" />
1099
+ </svg>
1100
+ </span>
1101
+ <span class="apple-pay-btn__loading" aria-hidden="true">Loading...</span>
1077
1102
  </button>
1078
1103
  </div>
1079
1104
  `;
@@ -1185,6 +1210,7 @@ var validateAppleMerchant = (data) => {
1185
1210
  });
1186
1211
  };
1187
1212
  var performPurchase = (data) => {
1213
+ console.log("[web-apple-pay] /v1/wallet/purchase payload", JSON.stringify(data, null, 2));
1188
1214
  return apiFetch("/v1/wallet/purchase", {
1189
1215
  method: "POST",
1190
1216
  body: JSON.stringify(data),
@@ -1597,13 +1623,17 @@ async function handlePaymentAuthorized(event, session, sessionData, config) {
1597
1623
  sessionData,
1598
1624
  config.supportedBillingCountries
1599
1625
  );
1626
+ const resolvedShippingContact = sessionData.loggedIn ? event.payment.shippingContact?.emailAddress ? event.payment.shippingContact : {
1627
+ ...event.payment.shippingContact ?? {},
1628
+ emailAddress: sessionData.emailAddress
1629
+ } : event.payment.shippingContact;
1600
1630
  const result = await performPurchase({
1601
1631
  applePayToken: event.payment.token,
1602
1632
  skuId: config.skuId,
1603
1633
  currency: config.currency,
1604
1634
  billingContact: event.payment.billingContact,
1605
- ...event.payment.shippingContact && {
1606
- shippingContact: event.payment.shippingContact
1635
+ ...resolvedShippingContact && {
1636
+ shippingContact: resolvedShippingContact
1607
1637
  },
1608
1638
  recaptchaTokens: config.recaptchaTokens
1609
1639
  });
@@ -1932,7 +1962,9 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
1932
1962
  const button = document.createElement(_ApplePayButton.tag);
1933
1963
  button.offer = offer;
1934
1964
  button.country = country;
1935
- button.entryPoint = entryPoint;
1965
+ if (entryPoint) {
1966
+ button.entryPoint = entryPoint;
1967
+ }
1936
1968
  return button;
1937
1969
  }
1938
1970
  /**
@@ -320,28 +320,41 @@ var apple_pay_modal_template_default = `<style>
320
320
  cursor: not-allowed;
321
321
  }
322
322
 
323
- .apm__cta[aria-busy="true"] > * {
324
- visibility: hidden;
323
+ .apm__cta-content {
324
+ display: flex;
325
+ align-items: center;
326
+ gap: 0.375rem;
327
+ }
328
+
329
+ .apm__cta-label {
330
+ display: inline-flex;
331
+ align-items: center;
332
+ gap: 0.375rem;
325
333
  }
326
334
 
327
- .apm__cta[aria-busy="true"]::after {
335
+ .apm__cta-loading {
336
+ display: none;
337
+ }
338
+
339
+ .apm__cta[aria-busy="true"]::before {
328
340
  content: '';
329
341
  position: absolute;
330
- left: 50%;
331
342
  top: 50%;
332
- margin-left: -0.625rem;
333
- margin-top: -0.625rem;
343
+ left: 50%;
334
344
  width: 1.25rem;
335
345
  height: 1.25rem;
336
- border: 2px solid rgba(255, 255, 255, 0.2);
346
+ border: 2px solid rgba(255, 255, 255, 0.25);
337
347
  border-top-color: #fff;
338
348
  border-radius: 50%;
339
349
  animation: apm-cta-spinner 0.8s linear infinite;
340
350
  }
341
351
 
342
352
  @keyframes apm-cta-spinner {
353
+ from {
354
+ transform: translate(-50%, -50%) rotate(0deg);
355
+ }
343
356
  to {
344
- transform: rotate(360deg);
357
+ transform: translate(-50%, -50%) rotate(360deg);
345
358
  }
346
359
  }
347
360
 
@@ -518,11 +531,14 @@ var apple_pay_modal_template_default = `<style>
518
531
  </div>
519
532
  <button class="apm__cta" id="apple-pay-modal-cta" aria-label="Continue with Apple Pay">
520
533
  <span class="apm__cta-content">
521
- Continue with
522
- <svg width="51" height="22" aria-hidden="true" role="img">
523
- <use href="#apple-pay-logo" />
524
- </svg>
534
+ <span class="apm__cta-label">
535
+ Continue with
536
+ <svg width="51" height="22" aria-hidden="true" role="img">
537
+ <use href="#apple-pay-logo" />
538
+ </svg>
539
+ </span>
525
540
  </span>
541
+ <span class="apm__cta-loading" aria-hidden="true">Loading...</span>
526
542
  </button>
527
543
  </div>
528
544
  </div>
@@ -320,28 +320,41 @@ var apple_pay_modal_template_default = `<style>
320
320
  cursor: not-allowed;
321
321
  }
322
322
 
323
- .apm__cta[aria-busy="true"] > * {
324
- visibility: hidden;
323
+ .apm__cta-content {
324
+ display: flex;
325
+ align-items: center;
326
+ gap: 0.375rem;
327
+ }
328
+
329
+ .apm__cta-label {
330
+ display: inline-flex;
331
+ align-items: center;
332
+ gap: 0.375rem;
325
333
  }
326
334
 
327
- .apm__cta[aria-busy="true"]::after {
335
+ .apm__cta-loading {
336
+ display: none;
337
+ }
338
+
339
+ .apm__cta[aria-busy="true"]::before {
328
340
  content: '';
329
341
  position: absolute;
330
- left: 50%;
331
342
  top: 50%;
332
- margin-left: -0.625rem;
333
- margin-top: -0.625rem;
343
+ left: 50%;
334
344
  width: 1.25rem;
335
345
  height: 1.25rem;
336
- border: 2px solid rgba(255, 255, 255, 0.2);
346
+ border: 2px solid rgba(255, 255, 255, 0.25);
337
347
  border-top-color: #fff;
338
348
  border-radius: 50%;
339
349
  animation: apm-cta-spinner 0.8s linear infinite;
340
350
  }
341
351
 
342
352
  @keyframes apm-cta-spinner {
353
+ from {
354
+ transform: translate(-50%, -50%) rotate(0deg);
355
+ }
343
356
  to {
344
- transform: rotate(360deg);
357
+ transform: translate(-50%, -50%) rotate(360deg);
345
358
  }
346
359
  }
347
360
 
@@ -518,11 +531,14 @@ var apple_pay_modal_template_default = `<style>
518
531
  </div>
519
532
  <button class="apm__cta" id="apple-pay-modal-cta" aria-label="Continue with Apple Pay">
520
533
  <span class="apm__cta-content">
521
- Continue with
522
- <svg width="51" height="22" aria-hidden="true" role="img">
523
- <use href="#apple-pay-logo" />
524
- </svg>
534
+ <span class="apm__cta-label">
535
+ Continue with
536
+ <svg width="51" height="22" aria-hidden="true" role="img">
537
+ <use href="#apple-pay-logo" />
538
+ </svg>
539
+ </span>
525
540
  </span>
541
+ <span class="apm__cta-loading" aria-hidden="true">Loading...</span>
526
542
  </button>
527
543
  </div>
528
544
  </div>
@@ -1030,28 +1046,34 @@ var apple_pay_button_template_default = `<style>
1030
1046
  cursor: default;
1031
1047
  }
1032
1048
 
1033
- teg-apple-pay-button .apple-pay-btn.wap-loading svg {
1034
- visibility: hidden;
1035
- }
1036
-
1037
- teg-apple-pay-button .apple-pay-btn.wap-loading::after {
1049
+ teg-apple-pay-button .apple-pay-btn.wap-loading::before {
1038
1050
  content: '';
1039
1051
  position: absolute;
1040
- left: 50%;
1041
1052
  top: 50%;
1042
- margin-left: -0.625rem;
1043
- margin-top: -0.625rem;
1053
+ left: 50%;
1044
1054
  width: 1.25rem;
1045
1055
  height: 1.25rem;
1046
- border: 2px solid rgba(255, 255, 255, 0.2);
1056
+ border: 2px solid rgba(255, 255, 255, 0.25);
1047
1057
  border-top-color: #fff;
1048
1058
  border-radius: 50%;
1049
1059
  animation: wap-button-spinner 0.8s linear infinite;
1050
1060
  }
1051
1061
 
1062
+ teg-apple-pay-button .apple-pay-btn__logo {
1063
+ display: inline-flex;
1064
+ align-items: center;
1065
+ }
1066
+
1067
+ teg-apple-pay-button .apple-pay-btn__loading {
1068
+ display: none;
1069
+ }
1070
+
1052
1071
  @keyframes wap-button-spinner {
1072
+ from {
1073
+ transform: translate(-50%, -50%) rotate(0deg);
1074
+ }
1053
1075
  to {
1054
- transform: rotate(360deg);
1076
+ transform: translate(-50%, -50%) rotate(360deg);
1055
1077
  }
1056
1078
  }
1057
1079
  </style>
@@ -1063,9 +1085,12 @@ var apple_pay_button_template_default = `<style>
1063
1085
  aria-label="Pay with Apple Pay"
1064
1086
  data-analytics="paywall:apple-pay-checkout"
1065
1087
  >
1066
- <svg width="51" height="22" aria-label="Apple Pay" role="img">
1067
- <use href="#apple-pay-logo" />
1068
- </svg>
1088
+ <span class="apple-pay-btn__logo">
1089
+ <svg width="51" height="22" aria-label="Apple Pay" role="img">
1090
+ <use href="#apple-pay-logo" />
1091
+ </svg>
1092
+ </span>
1093
+ <span class="apple-pay-btn__loading" aria-hidden="true">Loading...</span>
1069
1094
  </button>
1070
1095
  </div>
1071
1096
  `;
@@ -1177,6 +1202,7 @@ var validateAppleMerchant = (data) => {
1177
1202
  });
1178
1203
  };
1179
1204
  var performPurchase = (data) => {
1205
+ console.log("[web-apple-pay] /v1/wallet/purchase payload", JSON.stringify(data, null, 2));
1180
1206
  return apiFetch("/v1/wallet/purchase", {
1181
1207
  method: "POST",
1182
1208
  body: JSON.stringify(data),
@@ -1589,13 +1615,17 @@ async function handlePaymentAuthorized(event, session, sessionData, config) {
1589
1615
  sessionData,
1590
1616
  config.supportedBillingCountries
1591
1617
  );
1618
+ const resolvedShippingContact = sessionData.loggedIn ? event.payment.shippingContact?.emailAddress ? event.payment.shippingContact : {
1619
+ ...event.payment.shippingContact ?? {},
1620
+ emailAddress: sessionData.emailAddress
1621
+ } : event.payment.shippingContact;
1592
1622
  const result = await performPurchase({
1593
1623
  applePayToken: event.payment.token,
1594
1624
  skuId: config.skuId,
1595
1625
  currency: config.currency,
1596
1626
  billingContact: event.payment.billingContact,
1597
- ...event.payment.shippingContact && {
1598
- shippingContact: event.payment.shippingContact
1627
+ ...resolvedShippingContact && {
1628
+ shippingContact: resolvedShippingContact
1599
1629
  },
1600
1630
  recaptchaTokens: config.recaptchaTokens
1601
1631
  });
@@ -1924,7 +1954,9 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
1924
1954
  const button = document.createElement(_ApplePayButton.tag);
1925
1955
  button.offer = offer;
1926
1956
  button.country = country;
1927
- button.entryPoint = entryPoint;
1957
+ if (entryPoint) {
1958
+ button.entryPoint = entryPoint;
1959
+ }
1928
1960
  return button;
1929
1961
  }
1930
1962
  /**
@@ -69,6 +69,7 @@ var validateAppleMerchant = (data) => {
69
69
  });
70
70
  };
71
71
  var performPurchase = (data) => {
72
+ console.log("[web-apple-pay] /v1/wallet/purchase payload", JSON.stringify(data, null, 2));
72
73
  return apiFetch("/v1/wallet/purchase", {
73
74
  method: "POST",
74
75
  body: JSON.stringify(data),
@@ -55,6 +55,7 @@ var apiFetch = async (path, options = {}) => {
55
55
  return response.json();
56
56
  };
57
57
  var performPurchase = (data) => {
58
+ console.log("[web-apple-pay] /v1/wallet/purchase payload", JSON.stringify(data, null, 2));
58
59
  return apiFetch("/v1/wallet/purchase", {
59
60
  method: "POST",
60
61
  body: JSON.stringify(data),
@@ -359,13 +360,17 @@ async function handlePaymentAuthorized(event, session, sessionData, config) {
359
360
  sessionData,
360
361
  config.supportedBillingCountries
361
362
  );
363
+ const resolvedShippingContact = sessionData.loggedIn ? event.payment.shippingContact?.emailAddress ? event.payment.shippingContact : {
364
+ ...event.payment.shippingContact ?? {},
365
+ emailAddress: sessionData.emailAddress
366
+ } : event.payment.shippingContact;
362
367
  const result = await performPurchase({
363
368
  applePayToken: event.payment.token,
364
369
  skuId: config.skuId,
365
370
  currency: config.currency,
366
371
  billingContact: event.payment.billingContact,
367
- ...event.payment.shippingContact && {
368
- shippingContact: event.payment.shippingContact
372
+ ...resolvedShippingContact && {
373
+ shippingContact: resolvedShippingContact
369
374
  },
370
375
  recaptchaTokens: config.recaptchaTokens
371
376
  });
@@ -89,7 +89,11 @@ export type PurchaseRequest = {
89
89
  skuId: string;
90
90
  currency: string;
91
91
  billingContact: ApplePayPaymentContact;
92
- /** Required if loggedIn: false — contains emailAddress from Apple Pay sheet. */
92
+ /**
93
+ * Contains an emailAddress for /purchase. For anonymous users this is sourced
94
+ * from Apple Pay shipping contact; for logged-in users it may be filled from
95
+ * authenticated session data when Apple Pay does not return shipping fields.
96
+ */
93
97
  shippingContact?: ApplePayPaymentContact;
94
98
  recaptchaTokens: {
95
99
  checkEligibility: string;
@@ -0,0 +1,4 @@
1
+ export declare enum ApplePayEntryPoint {
2
+ PAYWALL = "article_paywall",
3
+ REGWALL = "article_regwall"
4
+ }
@@ -0,0 +1,9 @@
1
+ // src/constants.ts
2
+ var ApplePayEntryPoint = /* @__PURE__ */ ((ApplePayEntryPoint2) => {
3
+ ApplePayEntryPoint2["PAYWALL"] = "article_paywall";
4
+ ApplePayEntryPoint2["REGWALL"] = "article_regwall";
5
+ return ApplePayEntryPoint2;
6
+ })(ApplePayEntryPoint || {});
7
+ export {
8
+ ApplePayEntryPoint
9
+ };
@@ -2,6 +2,7 @@ export { ApplePayButton, APPLE_PAY_EXCLUDED_VARIANTS, } from './apple-pay-button
2
2
  export { ApplePayModal } from './apple-pay-modal';
3
3
  export { ensureApplePayLogoSymbol } from './apple-pay-logo';
4
4
  export { configureApplePay } from './clients/payment-checkout/config';
5
+ export { ApplePayEntryPoint } from './constants';
5
6
  export type { ApplePayRuntimeConfig } from './clients/payment-checkout/config';
6
7
  export type { Offer } from './types/offer.types';
7
8
  export declare function defineApplePayElements(): void;
package/dist/src/index.js CHANGED
@@ -320,28 +320,41 @@ var apple_pay_modal_template_default = `<style>
320
320
  cursor: not-allowed;
321
321
  }
322
322
 
323
- .apm__cta[aria-busy="true"] > * {
324
- visibility: hidden;
323
+ .apm__cta-content {
324
+ display: flex;
325
+ align-items: center;
326
+ gap: 0.375rem;
327
+ }
328
+
329
+ .apm__cta-label {
330
+ display: inline-flex;
331
+ align-items: center;
332
+ gap: 0.375rem;
325
333
  }
326
334
 
327
- .apm__cta[aria-busy="true"]::after {
335
+ .apm__cta-loading {
336
+ display: none;
337
+ }
338
+
339
+ .apm__cta[aria-busy="true"]::before {
328
340
  content: '';
329
341
  position: absolute;
330
- left: 50%;
331
342
  top: 50%;
332
- margin-left: -0.625rem;
333
- margin-top: -0.625rem;
343
+ left: 50%;
334
344
  width: 1.25rem;
335
345
  height: 1.25rem;
336
- border: 2px solid rgba(255, 255, 255, 0.2);
346
+ border: 2px solid rgba(255, 255, 255, 0.25);
337
347
  border-top-color: #fff;
338
348
  border-radius: 50%;
339
349
  animation: apm-cta-spinner 0.8s linear infinite;
340
350
  }
341
351
 
342
352
  @keyframes apm-cta-spinner {
353
+ from {
354
+ transform: translate(-50%, -50%) rotate(0deg);
355
+ }
343
356
  to {
344
- transform: rotate(360deg);
357
+ transform: translate(-50%, -50%) rotate(360deg);
345
358
  }
346
359
  }
347
360
 
@@ -518,11 +531,14 @@ var apple_pay_modal_template_default = `<style>
518
531
  </div>
519
532
  <button class="apm__cta" id="apple-pay-modal-cta" aria-label="Continue with Apple Pay">
520
533
  <span class="apm__cta-content">
521
- Continue with
522
- <svg width="51" height="22" aria-hidden="true" role="img">
523
- <use href="#apple-pay-logo" />
524
- </svg>
534
+ <span class="apm__cta-label">
535
+ Continue with
536
+ <svg width="51" height="22" aria-hidden="true" role="img">
537
+ <use href="#apple-pay-logo" />
538
+ </svg>
539
+ </span>
525
540
  </span>
541
+ <span class="apm__cta-loading" aria-hidden="true">Loading...</span>
526
542
  </button>
527
543
  </div>
528
544
  </div>
@@ -1035,28 +1051,34 @@ var apple_pay_button_template_default = `<style>
1035
1051
  cursor: default;
1036
1052
  }
1037
1053
 
1038
- teg-apple-pay-button .apple-pay-btn.wap-loading svg {
1039
- visibility: hidden;
1040
- }
1041
-
1042
- teg-apple-pay-button .apple-pay-btn.wap-loading::after {
1054
+ teg-apple-pay-button .apple-pay-btn.wap-loading::before {
1043
1055
  content: '';
1044
1056
  position: absolute;
1045
- left: 50%;
1046
1057
  top: 50%;
1047
- margin-left: -0.625rem;
1048
- margin-top: -0.625rem;
1058
+ left: 50%;
1049
1059
  width: 1.25rem;
1050
1060
  height: 1.25rem;
1051
- border: 2px solid rgba(255, 255, 255, 0.2);
1061
+ border: 2px solid rgba(255, 255, 255, 0.25);
1052
1062
  border-top-color: #fff;
1053
1063
  border-radius: 50%;
1054
1064
  animation: wap-button-spinner 0.8s linear infinite;
1055
1065
  }
1056
1066
 
1067
+ teg-apple-pay-button .apple-pay-btn__logo {
1068
+ display: inline-flex;
1069
+ align-items: center;
1070
+ }
1071
+
1072
+ teg-apple-pay-button .apple-pay-btn__loading {
1073
+ display: none;
1074
+ }
1075
+
1057
1076
  @keyframes wap-button-spinner {
1077
+ from {
1078
+ transform: translate(-50%, -50%) rotate(0deg);
1079
+ }
1058
1080
  to {
1059
- transform: rotate(360deg);
1081
+ transform: translate(-50%, -50%) rotate(360deg);
1060
1082
  }
1061
1083
  }
1062
1084
  </style>
@@ -1068,9 +1090,12 @@ var apple_pay_button_template_default = `<style>
1068
1090
  aria-label="Pay with Apple Pay"
1069
1091
  data-analytics="paywall:apple-pay-checkout"
1070
1092
  >
1071
- <svg width="51" height="22" aria-label="Apple Pay" role="img">
1072
- <use href="#apple-pay-logo" />
1073
- </svg>
1093
+ <span class="apple-pay-btn__logo">
1094
+ <svg width="51" height="22" aria-label="Apple Pay" role="img">
1095
+ <use href="#apple-pay-logo" />
1096
+ </svg>
1097
+ </span>
1098
+ <span class="apple-pay-btn__loading" aria-hidden="true">Loading...</span>
1074
1099
  </button>
1075
1100
  </div>
1076
1101
  `;
@@ -1182,6 +1207,7 @@ var validateAppleMerchant = (data) => {
1182
1207
  });
1183
1208
  };
1184
1209
  var performPurchase = (data) => {
1210
+ console.log("[web-apple-pay] /v1/wallet/purchase payload", JSON.stringify(data, null, 2));
1185
1211
  return apiFetch("/v1/wallet/purchase", {
1186
1212
  method: "POST",
1187
1213
  body: JSON.stringify(data),
@@ -1594,13 +1620,17 @@ async function handlePaymentAuthorized(event, session, sessionData, config) {
1594
1620
  sessionData,
1595
1621
  config.supportedBillingCountries
1596
1622
  );
1623
+ const resolvedShippingContact = sessionData.loggedIn ? event.payment.shippingContact?.emailAddress ? event.payment.shippingContact : {
1624
+ ...event.payment.shippingContact ?? {},
1625
+ emailAddress: sessionData.emailAddress
1626
+ } : event.payment.shippingContact;
1597
1627
  const result = await performPurchase({
1598
1628
  applePayToken: event.payment.token,
1599
1629
  skuId: config.skuId,
1600
1630
  currency: config.currency,
1601
1631
  billingContact: event.payment.billingContact,
1602
- ...event.payment.shippingContact && {
1603
- shippingContact: event.payment.shippingContact
1632
+ ...resolvedShippingContact && {
1633
+ shippingContact: resolvedShippingContact
1604
1634
  },
1605
1635
  recaptchaTokens: config.recaptchaTokens
1606
1636
  });
@@ -1929,7 +1959,9 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
1929
1959
  const button = document.createElement(_ApplePayButton.tag);
1930
1960
  button.offer = offer;
1931
1961
  button.country = country;
1932
- button.entryPoint = entryPoint;
1962
+ if (entryPoint) {
1963
+ button.entryPoint = entryPoint;
1964
+ }
1933
1965
  return button;
1934
1966
  }
1935
1967
  /**
@@ -2239,6 +2271,13 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2239
2271
  }
2240
2272
  };
2241
2273
 
2274
+ // src/constants.ts
2275
+ var ApplePayEntryPoint = /* @__PURE__ */ ((ApplePayEntryPoint2) => {
2276
+ ApplePayEntryPoint2["PAYWALL"] = "article_paywall";
2277
+ ApplePayEntryPoint2["REGWALL"] = "article_regwall";
2278
+ return ApplePayEntryPoint2;
2279
+ })(ApplePayEntryPoint || {});
2280
+
2242
2281
  // src/index.ts
2243
2282
  function defineApplePayElements() {
2244
2283
  ApplePayButton.define();
@@ -2247,6 +2286,7 @@ function defineApplePayElements() {
2247
2286
  export {
2248
2287
  APPLE_PAY_EXCLUDED_VARIANTS,
2249
2288
  ApplePayButton,
2289
+ ApplePayEntryPoint,
2250
2290
  ApplePayModal,
2251
2291
  configureApplePay,
2252
2292
  defineApplePayElements,
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.24",
4
+ "version": "0.1.3-beta.27",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",