@economist/web-apple-pay 2.0.0-beta.1 → 2.0.0-beta.3
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 +34 -12
- package/dist/index.js +661 -351
- package/dist/src/apple-pay-button.d.ts +21 -14
- package/dist/src/apple-pay-button.js +650 -343
- package/dist/src/apple-pay-button.stories.js +647 -342
- package/dist/src/apple-pay-modal.js +44 -39
- package/dist/src/apple-pay-modal.stories.js +647 -342
- package/dist/src/clients/payment-checkout/apple-session.d.ts +14 -1
- package/dist/src/clients/payment-checkout/apple-session.js +46 -11
- package/dist/src/clients/payment-checkout/billing-contact-details.js +43 -0
- package/dist/src/clients/payment-checkout/delivery-contact-details.d.ts +16 -0
- package/dist/src/clients/payment-checkout/delivery-contact-details.js +395 -0
- package/dist/src/clients/payment-checkout/detects.d.ts +5 -0
- package/dist/src/clients/payment-checkout/detects.js +18 -14
- package/dist/src/clients/payment-checkout/messages.d.ts +6 -0
- package/dist/src/clients/payment-checkout/messages.js +7 -1
- package/dist/src/clients/payment-checkout/payment-handler.d.ts +10 -1
- package/dist/src/clients/payment-checkout/payment-handler.js +397 -30
- package/dist/src/clients/payment-checkout/session.js +13 -1
- package/dist/src/clients/payment-checkout/types.d.ts +7 -0
- package/dist/src/constants.d.ts +8 -28
- package/dist/src/constants.js +4 -7
- package/dist/src/index.d.ts +2 -4
- package/dist/src/index.js +661 -351
- package/dist/src/types/offer.types.d.ts +1 -1
- package/dist/src/utils/address-rules.d.ts +23 -0
- package/dist/src/utils/address-rules.js +258 -0
- package/dist/src/utils/addressParityFlag.d.ts +13 -0
- package/dist/src/utils/addressParityFlag.js +5 -0
- package/dist/src/utils/applePayExpressEligibility.d.ts +7 -9
- package/dist/src/utils/applePayExpressEligibility.js +2 -2
- package/dist/src/utils/buttonCopyFlag.d.ts +22 -0
- package/dist/src/utils/buttonCopyFlag.js +12 -0
- package/dist/src/utils/delivery-countries.d.ts +9 -0
- package/dist/src/utils/delivery-countries.js +255 -0
- package/dist/src/utils/expressCheckoutRedirect.d.ts +20 -2
- package/dist/src/utils/expressCheckoutRedirect.js +13 -1
- package/dist/src/utils/expressCheckoutTracking.d.ts +10 -16
- package/dist/src/utils/expressCheckoutTracking.js +5 -29
- package/dist/src/utils/latin-characters.d.ts +3 -0
- package/dist/src/utils/latin-characters.js +10 -0
- package/dist/src/utils/printOffersFlag.d.ts +11 -0
- package/dist/src/utils/printOffersFlag.js +5 -0
- package/dist/src/utils/recaptcha.d.ts +3 -2
- package/dist/src/utils/recaptcha.js +17 -8
- package/package.json +1 -1
- package/dist/src/apple-pay-logo.d.ts +0 -1
- package/dist/src/apple-pay-logo.js +0 -14
- package/dist/src/types/experiment-integration.d.js +0 -0
- package/dist/src/utils/getExperimentKeyFromNextData.d.ts +0 -8
- package/dist/src/utils/getExperimentKeyFromNextData.js +0 -9
package/README.md
CHANGED
|
@@ -27,7 +27,10 @@ npm install --save @economist/web-apple-pay
|
|
|
27
27
|
Call `configureApplePay(...)` once during app startup, before rendering Apple Pay UI:
|
|
28
28
|
|
|
29
29
|
```ts
|
|
30
|
-
import {
|
|
30
|
+
import {
|
|
31
|
+
configureApplePay,
|
|
32
|
+
defineApplePayElements,
|
|
33
|
+
} from '@economist/web-apple-pay';
|
|
31
34
|
|
|
32
35
|
configureApplePay({
|
|
33
36
|
merchantId: 'merchant.com.economist.your-app',
|
|
@@ -75,7 +78,7 @@ If `merchantId` is not configured, Apple Pay availability checks return `false`
|
|
|
75
78
|
|
|
76
79
|
- Requires `offer` and `country` before click flow is meaningful.
|
|
77
80
|
- Checks Apple Pay availability on connect; if unavailable, it hides.
|
|
78
|
-
- 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.
|
|
79
82
|
- Forwards `data-logged-in` from button to modal (`modal.dataset.loggedIn`).
|
|
80
83
|
|
|
81
84
|
#### Awaiting render completion — `whenReady()`
|
|
@@ -85,8 +88,8 @@ to the DOM. This is the supported, stable way to know whether Apple Pay is
|
|
|
85
88
|
available without touching lifecycle internals.
|
|
86
89
|
|
|
87
90
|
```ts
|
|
88
|
-
container.appendChild(btn);
|
|
89
|
-
await btn.whenReady();
|
|
91
|
+
container.appendChild(btn); // spec-compliant — browser fires connectedCallback naturally
|
|
92
|
+
await btn.whenReady(); // resolves when rendering is complete
|
|
90
93
|
if (btn.style.display !== 'none') {
|
|
91
94
|
// Apple Pay rendered successfully
|
|
92
95
|
} else {
|
|
@@ -122,17 +125,32 @@ Consumers should listen for this event and continue payment orchestration.
|
|
|
122
125
|
- `ApplePayButton`: button component class.
|
|
123
126
|
- `whenReady(): Promise<void>` — resolves when the current render lifecycle completes (available or hidden). Resolves immediately if called before the element is connected.
|
|
124
127
|
- `createIfEnabled(offer, country, entryPoint?)`: returns a configured button or `null`.
|
|
125
|
-
- `DUAL_OFFER_BANNER` (or omitted): always-on after
|
|
126
|
-
- `
|
|
128
|
+
- `DUAL_OFFER_BANNER` (or omitted): always-on after offer exclusions — no homepage/Safari gate at `createIfEnabled` (device gating via `isApplePayAvailable` on mount).
|
|
129
|
+
- `FREE_TRIAL_BANNER`: same always-on-after-exclusions gate as Dual; wallet impression `entry_point` is `free_trial_banner`.
|
|
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`.
|
|
127
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.
|
|
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):
|
|
144
|
+
- `CURRENT_PAGE`: the page the button is on (banners, popup, paywall, regwall), e.g. back to the article.
|
|
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).
|
|
146
|
+
- A new entry point must declare its policy, or it will not compile.
|
|
128
147
|
- `ApplePayModal`: modal component class.
|
|
129
|
-
- `ensureApplePayLogoSymbol()`: logo symbol injection helper.
|
|
130
|
-
- `APPLE_PAY_EXPRESS_PAYWALLS_EXPERIMENT_KEY`: Amplitude flag key for paywalls experiment gating / `$exposure`.
|
|
131
148
|
- `Offer`: offer contract type used by component props.
|
|
132
149
|
|
|
133
150
|
### Breaking changes
|
|
134
151
|
|
|
135
|
-
- `
|
|
152
|
+
- `APPLE_PAY_EXPRESS_PAYWALLS_EXPERIMENT_KEY`, `APPLE_PAY_EXPRESS_VARIANTS`, and `ApplePayExperimentFlagKey` are no longer exported. Paywalls are always-on after Safari/offer checks; drop those imports.
|
|
153
|
+
- `APPLE_PAY_EXPRESS_EXPERIMENT_KEY` (retired banners experiment flag) remains unpublished.
|
|
136
154
|
|
|
137
155
|
## Troubleshooting
|
|
138
156
|
|
|
@@ -141,9 +159,9 @@ Consumers should listen for this event and continue payment orchestration.
|
|
|
141
159
|
Check:
|
|
142
160
|
|
|
143
161
|
- `configureApplePay(...)` was called before rendering (with a valid `merchantId` and `walletApiBaseUrl`)
|
|
144
|
-
- device/browser supports Apple Pay (Safari on Apple device required)
|
|
145
|
-
- for paywalls:
|
|
146
|
-
- for banners
|
|
162
|
+
- device/browser supports Apple Pay (Safari on Apple device required — enforced by `isApplePayAvailable` on mount)
|
|
163
|
+
- for paywalls: Safari/Apple placement eligibility (or `?BYPASS_APPLE_PAY_CHECKS=1` for QA)
|
|
164
|
+
- for banners / `FREE_TRIAL_POPUP`: consumer kill switch off (no homepage/Safari gate at `createIfEnabled`)
|
|
147
165
|
- offer variant is not excluded (`bundle`, `insider_print`)
|
|
148
166
|
|
|
149
167
|
### Logged-in checkbox copy looks wrong
|
|
@@ -194,3 +212,7 @@ Story coverage matrix:
|
|
|
194
212
|
- `ApplePayButton` behavior and state variants are available as individual canvas stories in Storybook.
|
|
195
213
|
- `ApplePayModal` docs page shows the stable default example.
|
|
196
214
|
- `ApplePayModal` behavior and state variants are available as individual canvas stories in Storybook.
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|