@economist/web-apple-pay 1.8.0 → 1.8.1

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
@@ -606,13 +606,8 @@ var getRecaptchaToken = async (action) => {
606
606
  });
607
607
  });
608
608
  };
609
- var getPurchaseRecaptchaTokens = async () => {
610
- const [checkEligibility, newBasket, registerUser] = await Promise.all([
611
- getRecaptchaToken("checkEligibility"),
612
- getRecaptchaToken("newBasket"),
613
- getRecaptchaToken("registerUser")
614
- ]);
615
- return { checkEligibility, newBasket, registerUser };
609
+ var getPurchaseRecaptchaToken = () => {
610
+ return getRecaptchaToken("walletPurchase");
616
611
  };
617
612
 
618
613
  // src/apple-pay-modal.ts
@@ -840,7 +835,7 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
840
835
  #isClosed = false;
841
836
  /**
842
837
  * Callback invoked synchronously from the CTA click handler.
843
- * Receives a Promise of reCAPTCHA tokens — the promise is already in-flight
838
+ * Receives a Promise of a reCAPTCHA token — the promise is already in-flight
844
839
  * by the time this is called. The caller (ApplePayButton) must call
845
840
  * new ApplePaySession() synchronously inside this callback to stay within
846
841
  * Safari's user-gesture window. The token promise resolves before
@@ -952,12 +947,12 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
952
947
  this.querySelector('[role="alert"]:not(#apple-pay-modal-error)')?.remove();
953
948
  cta.disabled = true;
954
949
  cta.setAttribute("aria-busy", "true");
955
- const recaptchaTokensPromise = getPurchaseRecaptchaTokens();
950
+ const recaptchaTokenPromise = getPurchaseRecaptchaToken();
956
951
  if (!this.#isClosed && this.onConfirm) {
957
- this.onConfirm(recaptchaTokensPromise);
952
+ this.onConfirm(recaptchaTokenPromise);
958
953
  this.close();
959
954
  }
960
- recaptchaTokensPromise.catch(() => {
955
+ recaptchaTokenPromise.catch(() => {
961
956
  if (this.#isClosed) return;
962
957
  cta.disabled = false;
963
958
  cta.removeAttribute("aria-busy");
@@ -1660,7 +1655,7 @@ async function handlePaymentAuthorized(event, session, sessionData, config) {
1660
1655
  ...event.payment.shippingContact && {
1661
1656
  shippingContact: event.payment.shippingContact
1662
1657
  },
1663
- recaptchaTokens: config.recaptchaTokens
1658
+ recaptchaToken: config.recaptchaToken
1664
1659
  });
1665
1660
  trackWalletPaymentSuccess(skuId, result.basketId);
1666
1661
  session.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
@@ -2210,8 +2205,8 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2210
2205
  }
2211
2206
  const skuId = this.#offer.sku_id;
2212
2207
  const country = this.#country;
2213
- modal.onConfirm = (recaptchaTokensPromise) => {
2214
- this.#initiateApplePay(skuId, country, recaptchaTokensPromise);
2208
+ modal.onConfirm = (recaptchaTokenPromise) => {
2209
+ this.#initiateApplePay(skuId, country, recaptchaTokenPromise);
2215
2210
  };
2216
2211
  modal.open();
2217
2212
  }
@@ -2234,7 +2229,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2234
2229
  return null;
2235
2230
  }
2236
2231
  }
2237
- #buildSessionParams(skuId, country, sessionData, paymentOptions, recaptchaTokensPromise) {
2232
+ #buildSessionParams(skuId, country, sessionData, paymentOptions, recaptchaTokenPromise) {
2238
2233
  const offer = this.#offer;
2239
2234
  const totalAmount = offer.price?.purchase ? `${offer.price.purchase}` : DEFAULT_TOTAL;
2240
2235
  return {
@@ -2247,19 +2242,19 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2247
2242
  returnUrl: this.#returnUrl,
2248
2243
  userLoggedIn: sessionData.loggedIn,
2249
2244
  onPaymentAuthorized: async (event, session) => {
2250
- const recaptchaTokens = await recaptchaTokensPromise;
2245
+ const recaptchaToken = await recaptchaTokenPromise;
2251
2246
  return handlePaymentAuthorized(event, session, sessionData, {
2252
2247
  skuId,
2253
2248
  country,
2254
2249
  currency: offer.price?.currency_code ?? DEFAULT_CURRENCY,
2255
2250
  returnUrl: this.#returnUrl,
2256
2251
  supportedBillingCountries: this.#supportedBillingCountries,
2257
- recaptchaTokens
2252
+ recaptchaToken
2258
2253
  });
2259
2254
  }
2260
2255
  };
2261
2256
  }
2262
- #initiateApplePay(skuId, country, recaptchaTokensPromise) {
2257
+ #initiateApplePay(skuId, country, recaptchaTokenPromise) {
2263
2258
  try {
2264
2259
  const sessionData = this.#sessionData ?? _ApplePayButton.#ANONYMOUS_SESSION;
2265
2260
  const paymentOptions = this.#paymentOptions;
@@ -2272,7 +2267,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2272
2267
  country,
2273
2268
  sessionData,
2274
2269
  paymentOptions,
2275
- recaptchaTokensPromise
2270
+ recaptchaTokenPromise
2276
2271
  )
2277
2272
  );
2278
2273
  } catch {
@@ -601,13 +601,8 @@ var getRecaptchaToken = async (action) => {
601
601
  });
602
602
  });
603
603
  };
604
- var getPurchaseRecaptchaTokens = async () => {
605
- const [checkEligibility, newBasket, registerUser] = await Promise.all([
606
- getRecaptchaToken("checkEligibility"),
607
- getRecaptchaToken("newBasket"),
608
- getRecaptchaToken("registerUser")
609
- ]);
610
- return { checkEligibility, newBasket, registerUser };
604
+ var getPurchaseRecaptchaToken = () => {
605
+ return getRecaptchaToken("walletPurchase");
611
606
  };
612
607
 
613
608
  // src/apple-pay-modal.ts
@@ -835,7 +830,7 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
835
830
  #isClosed = false;
836
831
  /**
837
832
  * Callback invoked synchronously from the CTA click handler.
838
- * Receives a Promise of reCAPTCHA tokens — the promise is already in-flight
833
+ * Receives a Promise of a reCAPTCHA token — the promise is already in-flight
839
834
  * by the time this is called. The caller (ApplePayButton) must call
840
835
  * new ApplePaySession() synchronously inside this callback to stay within
841
836
  * Safari's user-gesture window. The token promise resolves before
@@ -947,12 +942,12 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
947
942
  this.querySelector('[role="alert"]:not(#apple-pay-modal-error)')?.remove();
948
943
  cta.disabled = true;
949
944
  cta.setAttribute("aria-busy", "true");
950
- const recaptchaTokensPromise = getPurchaseRecaptchaTokens();
945
+ const recaptchaTokenPromise = getPurchaseRecaptchaToken();
951
946
  if (!this.#isClosed && this.onConfirm) {
952
- this.onConfirm(recaptchaTokensPromise);
947
+ this.onConfirm(recaptchaTokenPromise);
953
948
  this.close();
954
949
  }
955
- recaptchaTokensPromise.catch(() => {
950
+ recaptchaTokenPromise.catch(() => {
956
951
  if (this.#isClosed) return;
957
952
  cta.disabled = false;
958
953
  cta.removeAttribute("aria-busy");
@@ -1655,7 +1650,7 @@ async function handlePaymentAuthorized(event, session, sessionData, config) {
1655
1650
  ...event.payment.shippingContact && {
1656
1651
  shippingContact: event.payment.shippingContact
1657
1652
  },
1658
- recaptchaTokens: config.recaptchaTokens
1653
+ recaptchaToken: config.recaptchaToken
1659
1654
  });
1660
1655
  trackWalletPaymentSuccess(skuId, result.basketId);
1661
1656
  session.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
@@ -2205,8 +2200,8 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2205
2200
  }
2206
2201
  const skuId = this.#offer.sku_id;
2207
2202
  const country = this.#country;
2208
- modal.onConfirm = (recaptchaTokensPromise) => {
2209
- this.#initiateApplePay(skuId, country, recaptchaTokensPromise);
2203
+ modal.onConfirm = (recaptchaTokenPromise) => {
2204
+ this.#initiateApplePay(skuId, country, recaptchaTokenPromise);
2210
2205
  };
2211
2206
  modal.open();
2212
2207
  }
@@ -2229,7 +2224,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2229
2224
  return null;
2230
2225
  }
2231
2226
  }
2232
- #buildSessionParams(skuId, country, sessionData, paymentOptions, recaptchaTokensPromise) {
2227
+ #buildSessionParams(skuId, country, sessionData, paymentOptions, recaptchaTokenPromise) {
2233
2228
  const offer = this.#offer;
2234
2229
  const totalAmount = offer.price?.purchase ? `${offer.price.purchase}` : DEFAULT_TOTAL;
2235
2230
  return {
@@ -2242,19 +2237,19 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2242
2237
  returnUrl: this.#returnUrl,
2243
2238
  userLoggedIn: sessionData.loggedIn,
2244
2239
  onPaymentAuthorized: async (event, session) => {
2245
- const recaptchaTokens = await recaptchaTokensPromise;
2240
+ const recaptchaToken = await recaptchaTokenPromise;
2246
2241
  return handlePaymentAuthorized(event, session, sessionData, {
2247
2242
  skuId,
2248
2243
  country,
2249
2244
  currency: offer.price?.currency_code ?? DEFAULT_CURRENCY,
2250
2245
  returnUrl: this.#returnUrl,
2251
2246
  supportedBillingCountries: this.#supportedBillingCountries,
2252
- recaptchaTokens
2247
+ recaptchaToken
2253
2248
  });
2254
2249
  }
2255
2250
  };
2256
2251
  }
2257
- #initiateApplePay(skuId, country, recaptchaTokensPromise) {
2252
+ #initiateApplePay(skuId, country, recaptchaTokenPromise) {
2258
2253
  try {
2259
2254
  const sessionData = this.#sessionData ?? _ApplePayButton.#ANONYMOUS_SESSION;
2260
2255
  const paymentOptions = this.#paymentOptions;
@@ -2267,7 +2262,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2267
2262
  country,
2268
2263
  sessionData,
2269
2264
  paymentOptions,
2270
- recaptchaTokensPromise
2265
+ recaptchaTokenPromise
2271
2266
  )
2272
2267
  );
2273
2268
  } catch {
@@ -609,13 +609,8 @@ var getRecaptchaToken = async (action) => {
609
609
  });
610
610
  });
611
611
  };
612
- var getPurchaseRecaptchaTokens = async () => {
613
- const [checkEligibility, newBasket, registerUser] = await Promise.all([
614
- getRecaptchaToken("checkEligibility"),
615
- getRecaptchaToken("newBasket"),
616
- getRecaptchaToken("registerUser")
617
- ]);
618
- return { checkEligibility, newBasket, registerUser };
612
+ var getPurchaseRecaptchaToken = () => {
613
+ return getRecaptchaToken("walletPurchase");
619
614
  };
620
615
 
621
616
  // src/apple-pay-modal.ts
@@ -843,7 +838,7 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
843
838
  #isClosed = false;
844
839
  /**
845
840
  * Callback invoked synchronously from the CTA click handler.
846
- * Receives a Promise of reCAPTCHA tokens — the promise is already in-flight
841
+ * Receives a Promise of a reCAPTCHA token — the promise is already in-flight
847
842
  * by the time this is called. The caller (ApplePayButton) must call
848
843
  * new ApplePaySession() synchronously inside this callback to stay within
849
844
  * Safari's user-gesture window. The token promise resolves before
@@ -955,12 +950,12 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
955
950
  this.querySelector('[role="alert"]:not(#apple-pay-modal-error)')?.remove();
956
951
  cta.disabled = true;
957
952
  cta.setAttribute("aria-busy", "true");
958
- const recaptchaTokensPromise = getPurchaseRecaptchaTokens();
953
+ const recaptchaTokenPromise = getPurchaseRecaptchaToken();
959
954
  if (!this.#isClosed && this.onConfirm) {
960
- this.onConfirm(recaptchaTokensPromise);
955
+ this.onConfirm(recaptchaTokenPromise);
961
956
  this.close();
962
957
  }
963
- recaptchaTokensPromise.catch(() => {
958
+ recaptchaTokenPromise.catch(() => {
964
959
  if (this.#isClosed) return;
965
960
  cta.disabled = false;
966
961
  cta.removeAttribute("aria-busy");
@@ -1663,7 +1658,7 @@ async function handlePaymentAuthorized(event, session, sessionData, config) {
1663
1658
  ...event.payment.shippingContact && {
1664
1659
  shippingContact: event.payment.shippingContact
1665
1660
  },
1666
- recaptchaTokens: config.recaptchaTokens
1661
+ recaptchaToken: config.recaptchaToken
1667
1662
  });
1668
1663
  trackWalletPaymentSuccess(skuId, result.basketId);
1669
1664
  session.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
@@ -2213,8 +2208,8 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2213
2208
  }
2214
2209
  const skuId = this.#offer.sku_id;
2215
2210
  const country = this.#country;
2216
- modal.onConfirm = (recaptchaTokensPromise) => {
2217
- this.#initiateApplePay(skuId, country, recaptchaTokensPromise);
2211
+ modal.onConfirm = (recaptchaTokenPromise) => {
2212
+ this.#initiateApplePay(skuId, country, recaptchaTokenPromise);
2218
2213
  };
2219
2214
  modal.open();
2220
2215
  }
@@ -2237,7 +2232,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2237
2232
  return null;
2238
2233
  }
2239
2234
  }
2240
- #buildSessionParams(skuId, country, sessionData, paymentOptions, recaptchaTokensPromise) {
2235
+ #buildSessionParams(skuId, country, sessionData, paymentOptions, recaptchaTokenPromise) {
2241
2236
  const offer = this.#offer;
2242
2237
  const totalAmount = offer.price?.purchase ? `${offer.price.purchase}` : DEFAULT_TOTAL;
2243
2238
  return {
@@ -2250,19 +2245,19 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2250
2245
  returnUrl: this.#returnUrl,
2251
2246
  userLoggedIn: sessionData.loggedIn,
2252
2247
  onPaymentAuthorized: async (event, session) => {
2253
- const recaptchaTokens = await recaptchaTokensPromise;
2248
+ const recaptchaToken = await recaptchaTokenPromise;
2254
2249
  return handlePaymentAuthorized(event, session, sessionData, {
2255
2250
  skuId,
2256
2251
  country,
2257
2252
  currency: offer.price?.currency_code ?? DEFAULT_CURRENCY,
2258
2253
  returnUrl: this.#returnUrl,
2259
2254
  supportedBillingCountries: this.#supportedBillingCountries,
2260
- recaptchaTokens
2255
+ recaptchaToken
2261
2256
  });
2262
2257
  }
2263
2258
  };
2264
2259
  }
2265
- #initiateApplePay(skuId, country, recaptchaTokensPromise) {
2260
+ #initiateApplePay(skuId, country, recaptchaTokenPromise) {
2266
2261
  try {
2267
2262
  const sessionData = this.#sessionData ?? _ApplePayButton.#ANONYMOUS_SESSION;
2268
2263
  const paymentOptions = this.#paymentOptions;
@@ -2275,7 +2270,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2275
2270
  country,
2276
2271
  sessionData,
2277
2272
  paymentOptions,
2278
- recaptchaTokensPromise
2273
+ recaptchaTokenPromise
2279
2274
  )
2280
2275
  );
2281
2276
  } catch {
@@ -1,18 +1,17 @@
1
1
  import type { Offer } from './types/offer.types';
2
- import { type RecaptchaTokens } from './utils/recaptcha';
3
2
  export declare class ApplePayModal extends HTMLElement {
4
3
  #private;
5
4
  static readonly tag = "teg-apple-pay-modal";
6
5
  static define(): void;
7
6
  /**
8
7
  * Callback invoked synchronously from the CTA click handler.
9
- * Receives a Promise of reCAPTCHA tokens — the promise is already in-flight
8
+ * Receives a Promise of a reCAPTCHA token — the promise is already in-flight
10
9
  * by the time this is called. The caller (ApplePayButton) must call
11
10
  * new ApplePaySession() synchronously inside this callback to stay within
12
11
  * Safari's user-gesture window. The token promise resolves before
13
12
  * onPaymentAuthorized fires (user still needs to authenticate on the sheet).
14
13
  */
15
- onConfirm: ((recaptchaTokensPromise: Promise<RecaptchaTokens>) => void) | null;
14
+ onConfirm: ((recaptchaTokenPromise: Promise<string>) => void) | null;
16
15
  set offer(value: Offer | null);
17
16
  get country(): string;
18
17
  set country(value: string);
@@ -601,13 +601,8 @@ var getRecaptchaToken = async (action) => {
601
601
  });
602
602
  });
603
603
  };
604
- var getPurchaseRecaptchaTokens = async () => {
605
- const [checkEligibility, newBasket, registerUser] = await Promise.all([
606
- getRecaptchaToken("checkEligibility"),
607
- getRecaptchaToken("newBasket"),
608
- getRecaptchaToken("registerUser")
609
- ]);
610
- return { checkEligibility, newBasket, registerUser };
604
+ var getPurchaseRecaptchaToken = () => {
605
+ return getRecaptchaToken("walletPurchase");
611
606
  };
612
607
 
613
608
  // src/apple-pay-modal.ts
@@ -835,7 +830,7 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
835
830
  #isClosed = false;
836
831
  /**
837
832
  * Callback invoked synchronously from the CTA click handler.
838
- * Receives a Promise of reCAPTCHA tokens — the promise is already in-flight
833
+ * Receives a Promise of a reCAPTCHA token — the promise is already in-flight
839
834
  * by the time this is called. The caller (ApplePayButton) must call
840
835
  * new ApplePaySession() synchronously inside this callback to stay within
841
836
  * Safari's user-gesture window. The token promise resolves before
@@ -947,12 +942,12 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
947
942
  this.querySelector('[role="alert"]:not(#apple-pay-modal-error)')?.remove();
948
943
  cta.disabled = true;
949
944
  cta.setAttribute("aria-busy", "true");
950
- const recaptchaTokensPromise = getPurchaseRecaptchaTokens();
945
+ const recaptchaTokenPromise = getPurchaseRecaptchaToken();
951
946
  if (!this.#isClosed && this.onConfirm) {
952
- this.onConfirm(recaptchaTokensPromise);
947
+ this.onConfirm(recaptchaTokenPromise);
953
948
  this.close();
954
949
  }
955
- recaptchaTokensPromise.catch(() => {
950
+ recaptchaTokenPromise.catch(() => {
956
951
  if (this.#isClosed) return;
957
952
  cta.disabled = false;
958
953
  cta.removeAttribute("aria-busy");
@@ -601,13 +601,8 @@ var getRecaptchaToken = async (action) => {
601
601
  });
602
602
  });
603
603
  };
604
- var getPurchaseRecaptchaTokens = async () => {
605
- const [checkEligibility, newBasket, registerUser] = await Promise.all([
606
- getRecaptchaToken("checkEligibility"),
607
- getRecaptchaToken("newBasket"),
608
- getRecaptchaToken("registerUser")
609
- ]);
610
- return { checkEligibility, newBasket, registerUser };
604
+ var getPurchaseRecaptchaToken = () => {
605
+ return getRecaptchaToken("walletPurchase");
611
606
  };
612
607
 
613
608
  // src/apple-pay-modal.ts
@@ -835,7 +830,7 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
835
830
  #isClosed = false;
836
831
  /**
837
832
  * Callback invoked synchronously from the CTA click handler.
838
- * Receives a Promise of reCAPTCHA tokens — the promise is already in-flight
833
+ * Receives a Promise of a reCAPTCHA token — the promise is already in-flight
839
834
  * by the time this is called. The caller (ApplePayButton) must call
840
835
  * new ApplePaySession() synchronously inside this callback to stay within
841
836
  * Safari's user-gesture window. The token promise resolves before
@@ -947,12 +942,12 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
947
942
  this.querySelector('[role="alert"]:not(#apple-pay-modal-error)')?.remove();
948
943
  cta.disabled = true;
949
944
  cta.setAttribute("aria-busy", "true");
950
- const recaptchaTokensPromise = getPurchaseRecaptchaTokens();
945
+ const recaptchaTokenPromise = getPurchaseRecaptchaToken();
951
946
  if (!this.#isClosed && this.onConfirm) {
952
- this.onConfirm(recaptchaTokensPromise);
947
+ this.onConfirm(recaptchaTokenPromise);
953
948
  this.close();
954
949
  }
955
- recaptchaTokensPromise.catch(() => {
950
+ recaptchaTokenPromise.catch(() => {
956
951
  if (this.#isClosed) return;
957
952
  cta.disabled = false;
958
953
  cta.removeAttribute("aria-busy");
@@ -1655,7 +1650,7 @@ async function handlePaymentAuthorized(event, session, sessionData, config) {
1655
1650
  ...event.payment.shippingContact && {
1656
1651
  shippingContact: event.payment.shippingContact
1657
1652
  },
1658
- recaptchaTokens: config.recaptchaTokens
1653
+ recaptchaToken: config.recaptchaToken
1659
1654
  });
1660
1655
  trackWalletPaymentSuccess(skuId, result.basketId);
1661
1656
  session.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
@@ -2205,8 +2200,8 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2205
2200
  }
2206
2201
  const skuId = this.#offer.sku_id;
2207
2202
  const country = this.#country;
2208
- modal.onConfirm = (recaptchaTokensPromise) => {
2209
- this.#initiateApplePay(skuId, country, recaptchaTokensPromise);
2203
+ modal.onConfirm = (recaptchaTokenPromise) => {
2204
+ this.#initiateApplePay(skuId, country, recaptchaTokenPromise);
2210
2205
  };
2211
2206
  modal.open();
2212
2207
  }
@@ -2229,7 +2224,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2229
2224
  return null;
2230
2225
  }
2231
2226
  }
2232
- #buildSessionParams(skuId, country, sessionData, paymentOptions, recaptchaTokensPromise) {
2227
+ #buildSessionParams(skuId, country, sessionData, paymentOptions, recaptchaTokenPromise) {
2233
2228
  const offer = this.#offer;
2234
2229
  const totalAmount = offer.price?.purchase ? `${offer.price.purchase}` : DEFAULT_TOTAL;
2235
2230
  return {
@@ -2242,19 +2237,19 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2242
2237
  returnUrl: this.#returnUrl,
2243
2238
  userLoggedIn: sessionData.loggedIn,
2244
2239
  onPaymentAuthorized: async (event, session) => {
2245
- const recaptchaTokens = await recaptchaTokensPromise;
2240
+ const recaptchaToken = await recaptchaTokenPromise;
2246
2241
  return handlePaymentAuthorized(event, session, sessionData, {
2247
2242
  skuId,
2248
2243
  country,
2249
2244
  currency: offer.price?.currency_code ?? DEFAULT_CURRENCY,
2250
2245
  returnUrl: this.#returnUrl,
2251
2246
  supportedBillingCountries: this.#supportedBillingCountries,
2252
- recaptchaTokens
2247
+ recaptchaToken
2253
2248
  });
2254
2249
  }
2255
2250
  };
2256
2251
  }
2257
- #initiateApplePay(skuId, country, recaptchaTokensPromise) {
2252
+ #initiateApplePay(skuId, country, recaptchaTokenPromise) {
2258
2253
  try {
2259
2254
  const sessionData = this.#sessionData ?? _ApplePayButton.#ANONYMOUS_SESSION;
2260
2255
  const paymentOptions = this.#paymentOptions;
@@ -2267,7 +2262,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2267
2262
  country,
2268
2263
  sessionData,
2269
2264
  paymentOptions,
2270
- recaptchaTokensPromise
2265
+ recaptchaTokenPromise
2271
2266
  )
2272
2267
  );
2273
2268
  } catch {
@@ -20,10 +20,6 @@ export type PaymentHandlerConfig = {
20
20
  currency: string;
21
21
  returnUrl: string;
22
22
  supportedBillingCountries: string[];
23
- recaptchaTokens: {
24
- checkEligibility: string;
25
- newBasket: string;
26
- registerUser: string;
27
- };
23
+ recaptchaToken: string;
28
24
  };
29
25
  export declare function handlePaymentAuthorized(event: ApplePayJS.ApplePayPaymentAuthorizedEvent, session: ApplePaySession, sessionData: SessionResponse, config: PaymentHandlerConfig): Promise<void>;
@@ -359,7 +359,7 @@ async function handlePaymentAuthorized(event, session, sessionData, config) {
359
359
  ...event.payment.shippingContact && {
360
360
  shippingContact: event.payment.shippingContact
361
361
  },
362
- recaptchaTokens: config.recaptchaTokens
362
+ recaptchaToken: config.recaptchaToken
363
363
  });
364
364
  trackWalletPaymentSuccess(skuId, result.basketId);
365
365
  session.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
@@ -91,11 +91,7 @@ export type PurchaseRequest = {
91
91
  billingContact: ApplePayPaymentContact;
92
92
  /** Required if loggedIn: false — contains emailAddress from Apple Pay sheet. */
93
93
  shippingContact?: ApplePayPaymentContact;
94
- recaptchaTokens: {
95
- checkEligibility: string;
96
- newBasket: string;
97
- registerUser: string;
98
- };
94
+ recaptchaToken: string;
99
95
  };
100
96
  export type PurchaseResponse = {
101
97
  basketId: string;
package/dist/src/index.js CHANGED
@@ -606,13 +606,8 @@ var getRecaptchaToken = async (action) => {
606
606
  });
607
607
  });
608
608
  };
609
- var getPurchaseRecaptchaTokens = async () => {
610
- const [checkEligibility, newBasket, registerUser] = await Promise.all([
611
- getRecaptchaToken("checkEligibility"),
612
- getRecaptchaToken("newBasket"),
613
- getRecaptchaToken("registerUser")
614
- ]);
615
- return { checkEligibility, newBasket, registerUser };
609
+ var getPurchaseRecaptchaToken = () => {
610
+ return getRecaptchaToken("walletPurchase");
616
611
  };
617
612
 
618
613
  // src/apple-pay-modal.ts
@@ -840,7 +835,7 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
840
835
  #isClosed = false;
841
836
  /**
842
837
  * Callback invoked synchronously from the CTA click handler.
843
- * Receives a Promise of reCAPTCHA tokens — the promise is already in-flight
838
+ * Receives a Promise of a reCAPTCHA token — the promise is already in-flight
844
839
  * by the time this is called. The caller (ApplePayButton) must call
845
840
  * new ApplePaySession() synchronously inside this callback to stay within
846
841
  * Safari's user-gesture window. The token promise resolves before
@@ -952,12 +947,12 @@ var ApplePayModal = class _ApplePayModal extends HTMLElement {
952
947
  this.querySelector('[role="alert"]:not(#apple-pay-modal-error)')?.remove();
953
948
  cta.disabled = true;
954
949
  cta.setAttribute("aria-busy", "true");
955
- const recaptchaTokensPromise = getPurchaseRecaptchaTokens();
950
+ const recaptchaTokenPromise = getPurchaseRecaptchaToken();
956
951
  if (!this.#isClosed && this.onConfirm) {
957
- this.onConfirm(recaptchaTokensPromise);
952
+ this.onConfirm(recaptchaTokenPromise);
958
953
  this.close();
959
954
  }
960
- recaptchaTokensPromise.catch(() => {
955
+ recaptchaTokenPromise.catch(() => {
961
956
  if (this.#isClosed) return;
962
957
  cta.disabled = false;
963
958
  cta.removeAttribute("aria-busy");
@@ -1660,7 +1655,7 @@ async function handlePaymentAuthorized(event, session, sessionData, config) {
1660
1655
  ...event.payment.shippingContact && {
1661
1656
  shippingContact: event.payment.shippingContact
1662
1657
  },
1663
- recaptchaTokens: config.recaptchaTokens
1658
+ recaptchaToken: config.recaptchaToken
1664
1659
  });
1665
1660
  trackWalletPaymentSuccess(skuId, result.basketId);
1666
1661
  session.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
@@ -2210,8 +2205,8 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2210
2205
  }
2211
2206
  const skuId = this.#offer.sku_id;
2212
2207
  const country = this.#country;
2213
- modal.onConfirm = (recaptchaTokensPromise) => {
2214
- this.#initiateApplePay(skuId, country, recaptchaTokensPromise);
2208
+ modal.onConfirm = (recaptchaTokenPromise) => {
2209
+ this.#initiateApplePay(skuId, country, recaptchaTokenPromise);
2215
2210
  };
2216
2211
  modal.open();
2217
2212
  }
@@ -2234,7 +2229,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2234
2229
  return null;
2235
2230
  }
2236
2231
  }
2237
- #buildSessionParams(skuId, country, sessionData, paymentOptions, recaptchaTokensPromise) {
2232
+ #buildSessionParams(skuId, country, sessionData, paymentOptions, recaptchaTokenPromise) {
2238
2233
  const offer = this.#offer;
2239
2234
  const totalAmount = offer.price?.purchase ? `${offer.price.purchase}` : DEFAULT_TOTAL;
2240
2235
  return {
@@ -2247,19 +2242,19 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2247
2242
  returnUrl: this.#returnUrl,
2248
2243
  userLoggedIn: sessionData.loggedIn,
2249
2244
  onPaymentAuthorized: async (event, session) => {
2250
- const recaptchaTokens = await recaptchaTokensPromise;
2245
+ const recaptchaToken = await recaptchaTokenPromise;
2251
2246
  return handlePaymentAuthorized(event, session, sessionData, {
2252
2247
  skuId,
2253
2248
  country,
2254
2249
  currency: offer.price?.currency_code ?? DEFAULT_CURRENCY,
2255
2250
  returnUrl: this.#returnUrl,
2256
2251
  supportedBillingCountries: this.#supportedBillingCountries,
2257
- recaptchaTokens
2252
+ recaptchaToken
2258
2253
  });
2259
2254
  }
2260
2255
  };
2261
2256
  }
2262
- #initiateApplePay(skuId, country, recaptchaTokensPromise) {
2257
+ #initiateApplePay(skuId, country, recaptchaTokenPromise) {
2263
2258
  try {
2264
2259
  const sessionData = this.#sessionData ?? _ApplePayButton.#ANONYMOUS_SESSION;
2265
2260
  const paymentOptions = this.#paymentOptions;
@@ -2272,7 +2267,7 @@ var ApplePayButton = class _ApplePayButton extends HTMLElement {
2272
2267
  country,
2273
2268
  sessionData,
2274
2269
  paymentOptions,
2275
- recaptchaTokensPromise
2270
+ recaptchaTokenPromise
2276
2271
  )
2277
2272
  );
2278
2273
  } catch {
@@ -13,16 +13,10 @@
13
13
  */
14
14
  export declare const getRecaptchaToken: (action: string) => Promise<string>;
15
15
  /**
16
- * The set of reCAPTCHA tokens required by /v1/wallet/purchase.
17
- * Exported as a named type so both apple-pay-modal and apple-pay-button
18
- * share a single source of truth rather than deriving it independently.
16
+ * The reCAPTCHA token required by /v1/wallet/purchase.
19
17
  */
20
- export type RecaptchaTokens = {
21
- checkEligibility: string;
22
- newBasket: string;
23
- registerUser: string;
24
- };
18
+ export type RecaptchaToken = string;
25
19
  /**
26
- * Acquires all three reCAPTCHA tokens needed by /v1/wallet/purchase in parallel.
20
+ * Acquires the single reCAPTCHA token needed by /v1/wallet/purchase.
27
21
  */
28
- export declare const getPurchaseRecaptchaTokens: () => Promise<RecaptchaTokens>;
22
+ export declare const getPurchaseRecaptchaToken: () => Promise<RecaptchaToken>;
@@ -41,15 +41,10 @@ var getRecaptchaToken = async (action) => {
41
41
  });
42
42
  });
43
43
  };
44
- var getPurchaseRecaptchaTokens = async () => {
45
- const [checkEligibility, newBasket, registerUser] = await Promise.all([
46
- getRecaptchaToken("checkEligibility"),
47
- getRecaptchaToken("newBasket"),
48
- getRecaptchaToken("registerUser")
49
- ]);
50
- return { checkEligibility, newBasket, registerUser };
44
+ var getPurchaseRecaptchaToken = () => {
45
+ return getRecaptchaToken("walletPurchase");
51
46
  };
52
47
  export {
53
- getPurchaseRecaptchaTokens,
48
+ getPurchaseRecaptchaToken,
54
49
  getRecaptchaToken
55
50
  };
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.8.0",
4
+ "version": "1.8.1",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",