@economist/web-apple-pay 2.0.0-beta.2 → 2.0.0-beta.4

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.
Files changed (56) hide show
  1. package/README.md +20 -12
  2. package/dist/index.js +681 -361
  3. package/dist/src/apple-pay-button.d.ts +18 -16
  4. package/dist/src/apple-pay-button.js +670 -352
  5. package/dist/src/apple-pay-button.stories.js +667 -351
  6. package/dist/src/apple-pay-modal.js +44 -39
  7. package/dist/src/apple-pay-modal.stories.js +667 -351
  8. package/dist/src/clients/payment-checkout/apple-session.d.ts +14 -1
  9. package/dist/src/clients/payment-checkout/apple-session.js +66 -17
  10. package/dist/src/clients/payment-checkout/billing-contact-details.js +43 -0
  11. package/dist/src/clients/payment-checkout/delivery-contact-details.d.ts +16 -0
  12. package/dist/src/clients/payment-checkout/delivery-contact-details.js +397 -0
  13. package/dist/src/clients/payment-checkout/detects.d.ts +5 -0
  14. package/dist/src/clients/payment-checkout/detects.js +18 -14
  15. package/dist/src/clients/payment-checkout/messages.d.ts +6 -0
  16. package/dist/src/clients/payment-checkout/messages.js +7 -1
  17. package/dist/src/clients/payment-checkout/payment-handler.d.ts +10 -1
  18. package/dist/src/clients/payment-checkout/payment-handler.js +414 -36
  19. package/dist/src/clients/payment-checkout/session.js +13 -1
  20. package/dist/src/clients/payment-checkout/types.d.ts +11 -0
  21. package/dist/src/constants.d.ts +7 -28
  22. package/dist/src/constants.js +3 -7
  23. package/dist/src/index.d.ts +2 -4
  24. package/dist/src/index.js +681 -361
  25. package/dist/src/types/offer.types.d.ts +1 -1
  26. package/dist/src/utils/address-rules.d.ts +29 -0
  27. package/dist/src/utils/address-rules.js +260 -0
  28. package/dist/src/utils/addressParityFlag.d.ts +13 -0
  29. package/dist/src/utils/addressParityFlag.js +5 -0
  30. package/dist/src/utils/applePayExpressEligibility.d.ts +5 -6
  31. package/dist/src/utils/applePayExpressEligibility.js +2 -2
  32. package/dist/src/utils/billing-countries.js +46 -37
  33. package/dist/src/utils/buttonCopyFlag.d.ts +22 -0
  34. package/dist/src/utils/buttonCopyFlag.js +12 -0
  35. package/dist/src/utils/delivery-countries.d.ts +9 -0
  36. package/dist/src/utils/delivery-countries.js +255 -0
  37. package/dist/src/utils/expressCheckoutRedirect.d.ts +20 -2
  38. package/dist/src/utils/expressCheckoutRedirect.js +13 -1
  39. package/dist/src/utils/expressCheckoutTracking.d.ts +13 -20
  40. package/dist/src/utils/expressCheckoutTracking.js +22 -37
  41. package/dist/src/utils/latin-characters.d.ts +3 -0
  42. package/dist/src/utils/latin-characters.js +10 -0
  43. package/dist/src/utils/price-zones.d.ts +7 -0
  44. package/dist/src/utils/price-zones.js +212 -0
  45. package/dist/src/utils/print-variants.d.ts +5 -0
  46. package/dist/src/utils/print-variants.js +10 -0
  47. package/dist/src/utils/printOffersFlag.d.ts +11 -0
  48. package/dist/src/utils/printOffersFlag.js +5 -0
  49. package/dist/src/utils/recaptcha.d.ts +3 -2
  50. package/dist/src/utils/recaptcha.js +17 -8
  51. package/package.json +1 -1
  52. package/dist/src/apple-pay-logo.d.ts +0 -1
  53. package/dist/src/apple-pay-logo.js +0 -14
  54. package/dist/src/types/experiment-integration.d.js +0 -0
  55. package/dist/src/utils/getExperimentKeyFromNextData.d.ts +0 -8
  56. package/dist/src/utils/getExperimentKeyFromNextData.js +0 -9
package/README.md CHANGED
@@ -78,7 +78,7 @@ 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 variants excluded on its entry point (`getExcludedVariants(entryPoint)`: `bundle`, `insider_print` everywhere except `SUBSCRIBE` while `PRINT_OFFERS_ENABLED` is `true`). Every other `ProductVariant` (including `play`) is eligible; billing countries are restricted to the offer's price zone (unrestricted for print).
82
82
  - Forwards `data-logged-in` from button to modal (`modal.dataset.loggedIn`).
83
83
 
84
84
  #### Awaiting render completion — `whenReady()`
@@ -125,19 +125,24 @@ Consumers should listen for this event and continue payment orchestration.
125
125
  - `ApplePayButton`: button component class.
126
126
  - `whenReady(): Promise<void>` — resolves when the current render lifecycle completes (available or hidden). Resolves immediately if called before the element is connected.
127
127
  - `createIfEnabled(offer, country, entryPoint?)`: returns a configured button or `null`.
128
- - `DUAL_OFFER_BANNER` (or omitted): always-on after offer exclusions — no homepage/Safari gate at `createIfEnabled` (device gating via `isApplePayAvailable` on mount); no banners Amplitude experiment / `$exposure`.
128
+ - `DUAL_OFFER_BANNER` (or omitted): always-on after offer exclusions — no homepage/Safari gate at `createIfEnabled` (device gating via `isApplePayAvailable` on mount).
129
129
  - `FREE_TRIAL_BANNER`: same always-on-after-exclusions gate as Dual; wallet impression `entry_point` is `free_trial_banner`.
130
- - `PAYWALL`: experiment-gated via `apple-pay-express-checkout-on-paywalls` (`treatment` or QA URL).
130
+ - `FREE_TRIAL_POPUP`: same always-on-after-exclusions gate. Wallet impression `entry_point` is `free_trial_popup`. Payment success uses the same complete statuses as other entry points (`lex` logged-in, `nex` anonymous). The origin URL is still written to `checkout-redirect` for sma-checkout.
131
+ - `SUBSCRIBE`: same always-on-after-exclusions gate for `/subscribe` (sma-checkout); no Amplitude. Wallet impression `entry_point` is `subscribe`.
132
+ - `SALES_PAGE`: same always-on-after-exclusions gate for sma-checkout sales pages (Black Friday and other promotions); no Amplitude. Host-managed return URL like `SUBSCRIBE`; print offers excluded. Wallet impression `entry_point` is `sales_page`.
133
+ - `PAYWALL`: always-on after offer exclusions + Safari/Apple placement eligibility. No Amplitude experiment / `$exposure`.
131
134
  - `REGWALL`: inert — always returns `null`.
135
+ - **Analytics.** The entry point is sent as `entry_point` on every TEDL funnel event: `express_wallet_impression`, `express_wallet_click`, `wallet_payment_sheet_open`, `wallet_payment_authorised`, `wallet_payment_success`, `wallet_payment_failure` and `fallback_checkout`. It is left out when the host does not set one. The per-field `validation_*` events do not carry it.
136
+ - **Print offers (`bundle`, `insider_print`) — enabled.** `PRINT_OFFERS_ENABLED` is `true`. Entry points with `allowsPrintOffers: true` in `ENTRY_POINT_CONFIG` (`src/apple-pay-button.ts`) take print — currently only `SUBSCRIBE`; banners, popup, paywall, regwall and `SALES_PAGE` never do. Hosts that update `button.offer` in place should use `getExcludedVariants(entryPoint)` (it honours the flag) instead of the deprecated `APPLE_PAY_EXCLUDED_VARIANTS`. For an allowed print offer the sheet additionally collects the delivery address, name and phone and:
137
+ - limits delivery to the offer's price zone minus the countries print cannot be delivered to (`src/data/no-delivery-countries.json`, also set as Apple Pay `supportedCountries`); an offer with no deliverable country hides the button;
138
+ - validates the address with the sma-checkout delivery-form rules (required fields by zone, Commerce Services length limits, US zip / Canadian postcode formats, phone required for IN and CN) and keeps the sheet open with field-level errors (`delivery-contact-details.ts`, rules in `utils/address-rules.ts`);
139
+ - sends offer `countryCode`, `supportedBillingCountries`, `supportedDeliveryCountries` and the shipping contact to `/v1/wallet/purchase` (phone normalised by the validator, e.g. IN `098765 43210` → `+919876543210`), which re-validates and forwards the delivery address to Commerce Services. **Requires** wallet-payments-api with print delivery enabled;
140
+ - reports billing and delivery field errors together, so the sheet shows every bad field at once.
141
+ - Names and addresses must be Latin characters plus the approved diacritics for every purchase (SMA-3066), the same as sma-checkout; non-Latin input shows "Please use Latin characters only." in the sheet.
142
+ - **Return after purchase.** Banners, popup, paywall and regwall return the user to the page the button is on. `SUBSCRIBE` and `SALES_PAGE` leave the return target to the host (sma-checkout keeps the article the user arrived from).
132
143
  - `ApplePayModal`: modal component class.
133
- - `ensureApplePayLogoSymbol()`: logo symbol injection helper.
134
- - `APPLE_PAY_EXPRESS_PAYWALLS_EXPERIMENT_KEY`: Amplitude flag key for paywalls experiment gating / `$exposure`.
135
144
  - `Offer`: offer contract type used by component props.
136
145
 
137
- ### Breaking changes
138
-
139
- - `APPLE_PAY_EXPRESS_EXPERIMENT_KEY` (banners experiment flag) is no longer exported. Use `APPLE_PAY_EXPRESS_PAYWALLS_EXPERIMENT_KEY` for paywalls, or drop the import if you only needed the retired banners key.
140
-
141
146
  ## Troubleshooting
142
147
 
143
148
  ### Button does not appear
@@ -146,9 +151,9 @@ Check:
146
151
 
147
152
  - `configureApplePay(...)` was called before rendering (with a valid `merchantId` and `walletApiBaseUrl`)
148
153
  - device/browser supports Apple Pay (Safari on Apple device required — enforced by `isApplePayAvailable` on mount)
149
- - for paywalls: Amplitude treatment (or `?FEATURE_APPLE_PAY_EXPRESS_CHECKOUT`) is satisfied, plus Safari/Apple placement eligibility
150
- - for banners: consumer kill switch off (no homepage/Safari gate at `createIfEnabled`)
151
- - offer variant is not excluded (`bundle`, `insider_print`)
154
+ - for paywalls: Safari/Apple placement eligibility (or `?BYPASS_APPLE_PAY_CHECKS=1` for QA)
155
+ - for banners / `FREE_TRIAL_POPUP`: consumer kill switch off (no homepage/Safari gate at `createIfEnabled`)
156
+ - offer variant is not excluded (`bundle`, `insider_print` are only allowed on `SUBSCRIBE` while `PRINT_OFFERS_ENABLED` is `true`)
152
157
 
153
158
  ### Logged-in checkbox copy looks wrong
154
159
 
@@ -198,3 +203,6 @@ Story coverage matrix:
198
203
  - `ApplePayButton` behavior and state variants are available as individual canvas stories in Storybook.
199
204
  - `ApplePayModal` docs page shows the stable default example.
200
205
  - `ApplePayModal` behavior and state variants are available as individual canvas stories in Storybook.
206
+
207
+ Print offers are enabled (`PRINT_OFFERS_ENABLED` is `true`) on `SUBSCRIBE` only; see the Public API section above.
208
+