@economist/web-apple-pay 1.15.2 → 1.16.0-beta.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.
Files changed (42) hide show
  1. package/README.md +9 -21
  2. package/dist/index.js +563 -281
  3. package/dist/src/apple-pay-button.d.ts +10 -0
  4. package/dist/src/apple-pay-button.js +552 -270
  5. package/dist/src/apple-pay-button.stories.js +549 -269
  6. package/dist/src/apple-pay-modal.js +24 -30
  7. package/dist/src/apple-pay-modal.stories.js +549 -269
  8. package/dist/src/clients/payment-checkout/apple-session.d.ts +12 -0
  9. package/dist/src/clients/payment-checkout/apple-session.js +28 -2
  10. package/dist/src/clients/payment-checkout/billing-contact-details.js +43 -0
  11. package/dist/src/clients/payment-checkout/config.d.ts +0 -5
  12. package/dist/src/clients/payment-checkout/delivery-contact-details.d.ts +16 -0
  13. package/dist/src/clients/payment-checkout/delivery-contact-details.js +395 -0
  14. package/dist/src/clients/payment-checkout/detects.d.ts +5 -0
  15. package/dist/src/clients/payment-checkout/detects.js +18 -14
  16. package/dist/src/clients/payment-checkout/messages.d.ts +6 -0
  17. package/dist/src/clients/payment-checkout/messages.js +7 -1
  18. package/dist/src/clients/payment-checkout/payment-handler.d.ts +8 -0
  19. package/dist/src/clients/payment-checkout/payment-handler.js +395 -2
  20. package/dist/src/clients/payment-checkout/session.js +13 -1
  21. package/dist/src/clients/payment-checkout/types.d.ts +7 -0
  22. package/dist/src/constants.d.ts +3 -1
  23. package/dist/src/constants.js +1 -0
  24. package/dist/src/index.d.ts +1 -2
  25. package/dist/src/index.js +563 -281
  26. package/dist/src/utils/address-rules.d.ts +23 -0
  27. package/dist/src/utils/address-rules.js +258 -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/buttonCopyFlag.d.ts +22 -0
  31. package/dist/src/utils/buttonCopyFlag.js +12 -0
  32. package/dist/src/utils/delivery-countries.d.ts +9 -0
  33. package/dist/src/utils/delivery-countries.js +255 -0
  34. package/dist/src/utils/latin-characters.d.ts +3 -0
  35. package/dist/src/utils/latin-characters.js +10 -0
  36. package/dist/src/utils/printOffersFlag.d.ts +11 -0
  37. package/dist/src/utils/printOffersFlag.js +5 -0
  38. package/package.json +1 -1
  39. package/dist/src/apple-pay-logo.d.ts +0 -1
  40. package/dist/src/apple-pay-logo.js +0 -14
  41. package/dist/src/utils/nativeButtonFlag.d.ts +0 -12
  42. package/dist/src/utils/nativeButtonFlag.js +0 -18
package/README.md CHANGED
@@ -81,26 +81,6 @@ If `merchantId` is not configured, Apple Pay availability checks return `false`
81
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
-
104
84
  #### Awaiting render completion — `whenReady()`
105
85
 
106
86
  Use `whenReady()` to await the component's render lifecycle after appending it
@@ -149,14 +129,22 @@ Consumers should listen for this event and continue payment orchestration.
149
129
  - `FREE_TRIAL_BANNER`: same always-on-after-exclusions gate as Dual; wallet impression `entry_point` is `free_trial_banner`.
150
130
  - `FREE_TRIAL_POPUP`: same always-on-after-exclusions gate. Wallet impression `entry_point` is `free_trial_popup`. On payment success for a logged-in reader, `/checkout/complete` is opened with `status=nspc`. An anonymous popup stays `nex`. Other entry points stay `lex` or `nex`. The origin URL is still written to `checkout-redirect` for sma-checkout.
151
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`.
152
133
  - `PAYWALL`: always-on after offer exclusions + Safari/Apple placement eligibility. No Amplitude experiment / `$exposure`.
153
134
  - `REGWALL`: inert — always returns `null`.
135
+ - **Address parity — behind a flag.** `ADDRESS_PARITY_ENABLED` (`src/utils/addressParityFlag.ts`) ships `false`. When `true`, billing names/addresses must be Latin characters plus the approved diacritics (SMA-3066; the sheet shows "Please use Latin characters only.") and the purchase carries `strictAddressRules`, so the wallet-payments-api also truncates billing lines to the Commerce limits and maps Puerto Rico to US. Print delivery details are always held to these rules. Deploy the wallet-payments-api change first.
136
+ - **Button wording — behind a flag.** `CONTINUE_WITH_COPY_ENABLED` (`src/utils/buttonCopyFlag.ts`) ships `false`: the button reads "Subscribe with Apple Pay" on every surface, as before. Flip it to `true` in a release for "Continue with Apple Pay" (caption and accessible name).
137
+ - **Print offers (`bundle`, `insider_print`) — behind a flag.** `PRINT_OFFERS_ENABLED` (`src/utils/printOffersFlag.ts`) ships `false`: every entry point excludes print exactly as before, so releasing and bumping the package changes nothing. Flip it to `true` in a release to enable the feature. Even then, only entry points with `allowsPrintOffers: true` in `ENTRY_POINT_CONFIG` (`src/apple-pay-button.ts`) take print — currently only `SUBSCRIBE`; banners, popup, paywall and regwall 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:
138
+ - limits delivery to the offer's price zone minus the countries print cannot be delivered to (`src/data/no-delivery-countries.json`); an offer with no deliverable country hides the button;
139
+ - 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`);
140
+ - sends `supportedDeliveryCountries` and the shipping contact to `/v1/wallet/purchase`, which re-validates and forwards the delivery address to Commerce Services. **Release order:** deploy the wallet-payments-api change before flipping the flag.
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
+ The address rules, zones and no-delivery list are copies of sma-checkout's; keep them in sync.
154
143
  - **Where the user returns after purchase.** Each entry point sets a `ReturnUrlPolicy` in `ENTRY_POINT_CONFIG` (`src/apple-pay-button.ts`), which decides what is written to `localStorage['checkout-redirect']` (read by the onboarding app):
155
144
  - `CURRENT_PAGE`: the page the button is on (banners, popup, paywall, regwall), e.g. back to the article.
156
145
  - `HOST_MANAGED`: nothing is written, so the host's own value is kept (`SUBSCRIBE`: sma-checkout stores the article the user arrived from; with none stored, onboarding returns them to the home page).
157
146
  - A new entry point must declare its policy, or it will not compile.
158
147
  - `ApplePayModal`: modal component class.
159
- - `ensureApplePayLogoSymbol()`: logo symbol injection helper.
160
148
  - `Offer`: offer contract type used by component props.
161
149
 
162
150
  ### Breaking changes