@economist/web-apple-pay 0.1.3-beta.2 → 0.1.3-beta.21
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 +633 -191
- package/dist/src/apple-pay-button.js +628 -180
- package/dist/src/apple-pay-button.stories.js +654 -195
- package/dist/src/apple-pay-modal.d.ts +16 -1
- package/dist/src/apple-pay-modal.js +556 -10
- package/dist/src/apple-pay-modal.stories.js +628 -180
- package/dist/src/clients/payment-checkout/apple-session.js +34 -59
- package/dist/src/clients/payment-checkout/config.js +0 -7
- package/dist/src/clients/payment-checkout/detects.js +2 -10
- package/dist/src/clients/payment-checkout/index.js +7 -0
- package/dist/src/clients/payment-checkout/payment-handler.d.ts +1 -0
- package/dist/src/clients/payment-checkout/payment-handler.js +36 -39
- package/dist/src/clients/payment-checkout/session.js +7 -0
- package/dist/src/clients/payment-checkout/shipping-contact-details.js +0 -21
- package/dist/src/clients/payment-checkout/types.d.ts +1 -0
- package/dist/src/index.js +633 -191
- package/dist/src/stories/utils/story-env.js +18 -7
- package/dist/src/utils/expressCheckoutRedirect.d.ts +27 -6
- package/dist/src/utils/expressCheckoutRedirect.js +19 -4
- package/package.json +1 -1
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
// src/clients/payment-checkout/config.ts
|
|
2
2
|
var runtimeConfig = null;
|
|
3
3
|
var configureApplePay = (config) => {
|
|
4
|
-
console.log("[web-apple-pay] configureApplePay called", {
|
|
5
|
-
merchantId: config.merchantId,
|
|
6
|
-
walletApiBaseUrl: config.walletApiBaseUrl,
|
|
7
|
-
debugBypassEnabled: config.debugBypassEnabled,
|
|
8
|
-
recaptchaSiteKey: config.recaptchaSiteKey ? "***" : void 0
|
|
9
|
-
});
|
|
10
4
|
runtimeConfig = {
|
|
11
5
|
...config
|
|
12
6
|
};
|
|
13
7
|
};
|
|
14
8
|
var resetApplePayConfig = () => {
|
|
15
|
-
console.log("[web-apple-pay] resetApplePayConfig called");
|
|
16
9
|
runtimeConfig = null;
|
|
17
10
|
};
|
|
18
11
|
|
|
@@ -39,6 +32,24 @@ var createFetchMock = (sessionResponse, sessionStatus = 200) => {
|
|
|
39
32
|
headers: { "content-type": "application/json" }
|
|
40
33
|
});
|
|
41
34
|
}
|
|
35
|
+
if (requestUrl.includes("/v1/wallet/payment-options/sku/")) {
|
|
36
|
+
return new Response(
|
|
37
|
+
JSON.stringify({
|
|
38
|
+
options: {
|
|
39
|
+
apple_pay: {
|
|
40
|
+
provider: "apple-pay",
|
|
41
|
+
settings: {
|
|
42
|
+
supported_networks: ["visa", "masterCard", "amex"]
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}),
|
|
47
|
+
{
|
|
48
|
+
status: 200,
|
|
49
|
+
headers: { "content-type": "application/json" }
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
}
|
|
42
53
|
return new Response("Not Found", {
|
|
43
54
|
status: 404,
|
|
44
55
|
statusText: "Not Found"
|
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Centralized redirect URL builders for the Express Checkout payment handler.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Before redirecting, the origin article URL is persisted to localStorage under
|
|
5
|
+
* the `checkout-redirect` key so that sma-checkout / the onboarding app can
|
|
6
|
+
* return the user to the article after checkout and onboarding complete.
|
|
6
7
|
*
|
|
7
8
|
* Matches sma-checkout: src/lib/navigate-to-checkout/index.tsx
|
|
8
9
|
*/
|
|
10
|
+
/**
|
|
11
|
+
* Validates that a URL is safe to use as a post-checkout redirect destination,
|
|
12
|
+
* then writes it to localStorage under `checkout-redirect`.
|
|
13
|
+
*
|
|
14
|
+
* Allowed values:
|
|
15
|
+
* - Relative paths (start with `/`)
|
|
16
|
+
* - Absolute URLs on `economist.com` or any subdomain of it
|
|
17
|
+
*
|
|
18
|
+
* Any other value (e.g. an external domain) is silently rejected to prevent
|
|
19
|
+
* open-redirect vulnerabilities.
|
|
20
|
+
*/
|
|
21
|
+
export declare const writeCheckoutRedirect: (originUrl: string) => void;
|
|
9
22
|
/**
|
|
10
23
|
* Captures the current page URL (the article the user is reading).
|
|
11
24
|
* Must be called before any redirect occurs.
|
|
@@ -29,26 +42,34 @@ export declare const buildQueryString: () => string;
|
|
|
29
42
|
export declare const decodeSku: (sku: string) => string;
|
|
30
43
|
/**
|
|
31
44
|
* Builds the success redirect URL.
|
|
32
|
-
* /checkout/complete?basketId={id}&lmo_offer={sku}&status={userStatus}&redirectToCheckout=true
|
|
45
|
+
* /checkout/complete?basketId={id}&lmo_offer={sku}&status={userStatus}&redirectToCheckout=true
|
|
46
|
+
*
|
|
47
|
+
* The origin article URL is written to localStorage by the caller via
|
|
48
|
+
* writeCheckoutRedirect() before this redirect fires.
|
|
33
49
|
*/
|
|
34
50
|
export declare const redirectToCheckoutComplete: (params: {
|
|
35
51
|
basketId: string;
|
|
36
52
|
status: "nex" | "lex";
|
|
37
53
|
skuId: string;
|
|
38
|
-
returnUrl: string;
|
|
39
54
|
queryString?: string;
|
|
40
55
|
}) => string;
|
|
41
56
|
/**
|
|
42
57
|
* Builds the fallback redirect URL for error scenarios.
|
|
43
|
-
* /checkout?lmo_offer={
|
|
58
|
+
* /checkout?lmo_offer={offerPath}&inlineError=...
|
|
59
|
+
*
|
|
60
|
+
* The skuId is decoded via decodeSku() before being set as lmo_offer, producing
|
|
61
|
+
* a Limio offer path (e.g. /offers2/UK-UK.DIGITAL.1YAR.X.DISC.30.NYT) as
|
|
62
|
+
* checkout expects. If decoding fails (malformed SKU), the raw skuId is used.
|
|
44
63
|
*
|
|
45
64
|
* Builds on top of the current page URL (window.location.href) so that any
|
|
46
65
|
* existing query params (UTM tags, campaign flags) are preserved — matching
|
|
47
66
|
* sma-checkout: src/lib/navigate-to-checkout/index.tsx
|
|
67
|
+
*
|
|
68
|
+
* The origin article URL is written to localStorage by the caller via
|
|
69
|
+
* writeCheckoutRedirect() before this redirect fires.
|
|
48
70
|
*/
|
|
49
71
|
export declare const redirectToCheckoutFallback: (params: {
|
|
50
72
|
skuId: string;
|
|
51
|
-
returnUrl: string;
|
|
52
73
|
inlineError?: string;
|
|
53
74
|
emailError?: string;
|
|
54
75
|
email?: string;
|
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
// src/utils/expressCheckoutRedirect.ts
|
|
2
|
+
var CHECKOUT_REDIRECT_KEY = "checkout-redirect";
|
|
3
|
+
var ALLOWED_REDIRECT_HOSTNAME = "economist.com";
|
|
4
|
+
var writeCheckoutRedirect = (originUrl) => {
|
|
5
|
+
if (originUrl.startsWith("/")) {
|
|
6
|
+
localStorage.setItem(CHECKOUT_REDIRECT_KEY, originUrl);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
try {
|
|
10
|
+
const { hostname } = new URL(originUrl);
|
|
11
|
+
const isAllowed = hostname === ALLOWED_REDIRECT_HOSTNAME || hostname.endsWith(`.${ALLOWED_REDIRECT_HOSTNAME}`);
|
|
12
|
+
if (isAllowed) {
|
|
13
|
+
localStorage.setItem(CHECKOUT_REDIRECT_KEY, originUrl);
|
|
14
|
+
}
|
|
15
|
+
} catch {
|
|
16
|
+
}
|
|
17
|
+
};
|
|
2
18
|
var captureOriginUrl = () => window.location.href;
|
|
3
19
|
var buildQueryString = () => {
|
|
4
20
|
const countryCode = new URLSearchParams(window.location.search).get(
|
|
@@ -23,18 +39,16 @@ var redirectToCheckoutComplete = (params) => {
|
|
|
23
39
|
url.searchParams.set("lmo_offer", params.skuId);
|
|
24
40
|
url.searchParams.set("status", params.status);
|
|
25
41
|
url.searchParams.set("redirectToCheckout", "true");
|
|
26
|
-
url.searchParams.set("returnUrl", params.returnUrl);
|
|
27
42
|
return url.pathname + url.search;
|
|
28
43
|
};
|
|
29
44
|
var redirectToCheckoutFallback = (params) => {
|
|
30
45
|
const url = new URL(window.location.href);
|
|
31
46
|
url.pathname = "/checkout";
|
|
32
|
-
url.searchParams.set("lmo_offer", params.skuId);
|
|
47
|
+
url.searchParams.set("lmo_offer", decodeSku(params.skuId));
|
|
33
48
|
if (params.inlineError)
|
|
34
49
|
url.searchParams.set("inlineError", params.inlineError);
|
|
35
50
|
if (params.email) url.searchParams.set("email", params.email);
|
|
36
51
|
if (params.emailError) url.searchParams.set("emailError", params.emailError);
|
|
37
|
-
url.searchParams.set("returnUrl", params.returnUrl);
|
|
38
52
|
return url.pathname + url.search;
|
|
39
53
|
};
|
|
40
54
|
export {
|
|
@@ -42,5 +56,6 @@ export {
|
|
|
42
56
|
captureOriginUrl,
|
|
43
57
|
decodeSku,
|
|
44
58
|
redirectToCheckoutComplete,
|
|
45
|
-
redirectToCheckoutFallback
|
|
59
|
+
redirectToCheckoutFallback,
|
|
60
|
+
writeCheckoutRedirect
|
|
46
61
|
};
|
package/package.json
CHANGED