@economist/web-apple-pay 0.1.1-beta.0
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 +186 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1642 -0
- package/dist/src/apple-pay-button.d.ts +45 -0
- package/dist/src/apple-pay-button.js +1621 -0
- package/dist/src/apple-pay-button.stories.js +1934 -0
- package/dist/src/apple-pay-logo.d.ts +1 -0
- package/dist/src/apple-pay-logo.js +14 -0
- package/dist/src/apple-pay-modal.d.ts +12 -0
- package/dist/src/apple-pay-modal.js +442 -0
- package/dist/src/apple-pay-modal.stories.js +1778 -0
- package/dist/src/clients/payment-checkout/apple-session.d.ts +18 -0
- package/dist/src/clients/payment-checkout/apple-session.js +243 -0
- package/dist/src/clients/payment-checkout/billing-contact-details.d.ts +21 -0
- package/dist/src/clients/payment-checkout/billing-contact-details.js +109 -0
- package/dist/src/clients/payment-checkout/config.d.ts +9 -0
- package/dist/src/clients/payment-checkout/config.js +23 -0
- package/dist/src/clients/payment-checkout/contact-validation.d.ts +21 -0
- package/dist/src/clients/payment-checkout/contact-validation.js +50 -0
- package/dist/src/clients/payment-checkout/detects.d.ts +3 -0
- package/dist/src/clients/payment-checkout/detects.js +56 -0
- package/dist/src/clients/payment-checkout/index.d.ts +5 -0
- package/dist/src/clients/payment-checkout/index.js +83 -0
- package/dist/src/clients/payment-checkout/messages.d.ts +33 -0
- package/dist/src/clients/payment-checkout/messages.js +19 -0
- package/dist/src/clients/payment-checkout/payment-handler.d.ts +36 -0
- package/dist/src/clients/payment-checkout/payment-handler.js +389 -0
- package/dist/src/clients/payment-checkout/session.d.ts +2 -0
- package/dist/src/clients/payment-checkout/session.js +67 -0
- package/dist/src/clients/payment-checkout/shipping-contact-details.d.ts +10 -0
- package/dist/src/clients/payment-checkout/shipping-contact-details.js +83 -0
- package/dist/src/clients/payment-checkout/types.d.ts +118 -0
- package/dist/src/clients/payment-checkout/types.js +14 -0
- package/dist/src/index.d.ts +7 -0
- package/dist/src/index.js +1642 -0
- package/dist/src/stories/fixtures/offer.d.ts +2 -0
- package/dist/src/stories/fixtures/offer.js +28 -0
- package/dist/src/stories/utils/story-env.d.ts +11 -0
- package/dist/src/stories/utils/story-env.js +148 -0
- package/dist/src/types/html-template.d.js +0 -0
- package/dist/src/types/offer.types.d.ts +73 -0
- package/dist/src/types/offer.types.js +0 -0
- package/dist/src/utils/billing-countries.d.ts +19 -0
- package/dist/src/utils/billing-countries.js +263 -0
- package/dist/src/utils/define.d.ts +1 -0
- package/dist/src/utils/define.js +9 -0
- package/dist/src/utils/expressCheckoutRedirect.d.ts +55 -0
- package/dist/src/utils/expressCheckoutRedirect.js +46 -0
- package/dist/src/utils/expressCheckoutTracking.d.ts +64 -0
- package/dist/src/utils/expressCheckoutTracking.js +84 -0
- package/dist/src/utils/pricing.d.ts +1 -0
- package/dist/src/utils/pricing.js +60 -0
- package/dist/src/utils/recaptcha.d.ts +22 -0
- package/dist/src/utils/recaptcha.js +54 -0
- package/package.json +64 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types mapping to the wallet-payments-api BFF.
|
|
3
|
+
* Aligned with UI-Integration-Mocks.md.
|
|
4
|
+
*/
|
|
5
|
+
export type PaymentOptionsRequest = {
|
|
6
|
+
sku: string;
|
|
7
|
+
countryCode: string;
|
|
8
|
+
currencyCode: string;
|
|
9
|
+
/** The current page URL, sent to Commerce Services for logging purposes. */
|
|
10
|
+
checkoutUrl: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Relevant subset of the wallet-payments-api BFF GET /v1/wallet/payment-options/sku/:sku/:countryCode/:currencyCode response.
|
|
14
|
+
* Only the apple_pay field is consumed by this package.
|
|
15
|
+
*/
|
|
16
|
+
export type PaymentOptionsResponse = {
|
|
17
|
+
options: {
|
|
18
|
+
apple_pay?: {
|
|
19
|
+
provider: string;
|
|
20
|
+
settings: {
|
|
21
|
+
supported_networks: string[];
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* GET /v1/wallet/session — uses credentials: 'include' (cookie-based).
|
|
28
|
+
*
|
|
29
|
+
* BFF always returns userType, even for anonymous users.
|
|
30
|
+
* Scenario C (active-subscription) → frontend MUST suppress Apple Pay button.
|
|
31
|
+
*/
|
|
32
|
+
export type SessionResponse = {
|
|
33
|
+
loggedIn: false;
|
|
34
|
+
userType: 'new-eligible-user';
|
|
35
|
+
} | {
|
|
36
|
+
loggedIn: true;
|
|
37
|
+
emailAddress: string;
|
|
38
|
+
contactId: string;
|
|
39
|
+
userType: 'active-subscription' | 'b2b-user' | 'new-eligible-user';
|
|
40
|
+
};
|
|
41
|
+
export type ValidateMerchantRequest = {
|
|
42
|
+
validationURL: string;
|
|
43
|
+
recaptchaToken: string;
|
|
44
|
+
};
|
|
45
|
+
export type ValidateMerchantResponse = {
|
|
46
|
+
merchantSession: Record<string, unknown>;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Minimal shape of the Apple Pay token received from `onpaymentauthorized`.
|
|
50
|
+
* Mirrors the relevant subset of `ApplePayJS.ApplePayPaymentToken` without
|
|
51
|
+
* requiring the `@types/applepayjs` package as a dependency.
|
|
52
|
+
*/
|
|
53
|
+
export type ApplePayPaymentToken = {
|
|
54
|
+
paymentData: unknown;
|
|
55
|
+
paymentMethod: {
|
|
56
|
+
displayName?: string;
|
|
57
|
+
network?: string;
|
|
58
|
+
type?: string;
|
|
59
|
+
};
|
|
60
|
+
transactionIdentifier: string;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Subset of ApplePayJS.ApplePayPaymentContact used in purchase and shipping.
|
|
64
|
+
*/
|
|
65
|
+
export type ApplePayPaymentContact = {
|
|
66
|
+
emailAddress?: string;
|
|
67
|
+
givenName?: string;
|
|
68
|
+
familyName?: string;
|
|
69
|
+
phoneNumber?: string;
|
|
70
|
+
addressLines?: string[];
|
|
71
|
+
locality?: string;
|
|
72
|
+
administrativeArea?: string;
|
|
73
|
+
postalCode?: string;
|
|
74
|
+
countryCode?: string;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* POST /v1/wallet/purchase
|
|
78
|
+
*
|
|
79
|
+
* The BFF orchestrates eligibility check, passwordless registration,
|
|
80
|
+
* basket creation, and payment finalization in a single call.
|
|
81
|
+
*/
|
|
82
|
+
export type PurchaseRequest = {
|
|
83
|
+
applePayToken: ApplePayPaymentToken;
|
|
84
|
+
/**
|
|
85
|
+
* @TODO [BFF Contract Misalignment]
|
|
86
|
+
* BFF spec requests `offerData: { ratePlanId, offerId }` but Commerce Services
|
|
87
|
+
* only provide a `skuId`. Frontend uses `skuId` directly — BFF must be aligned.
|
|
88
|
+
*/
|
|
89
|
+
skuId: string;
|
|
90
|
+
billingContact: ApplePayPaymentContact;
|
|
91
|
+
/** Required if loggedIn: false — contains emailAddress from Apple Pay sheet. */
|
|
92
|
+
shippingContact?: ApplePayPaymentContact;
|
|
93
|
+
recaptchaTokens: {
|
|
94
|
+
checkEligibility: string;
|
|
95
|
+
newBasket: string;
|
|
96
|
+
registerUser: string;
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
export type PurchaseResponse = {
|
|
100
|
+
basketId: string;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Structured error body returned by all /v1/wallet/* endpoints on 4xx/5xx.
|
|
104
|
+
*/
|
|
105
|
+
export type WalletApiError = {
|
|
106
|
+
errorType: 'SERVICE_UNAVAILABLE' | 'PAYMENT_DECLINED' | 'VALIDATION_ERROR' | 'BAD_REQUEST' | 'EMAIL_COLLISION' | 'ELIGIBILITY_REJECTED' | 'REGISTRATION_FAILED';
|
|
107
|
+
message: string;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Error thrown by apiFetch for non-2xx responses.
|
|
111
|
+
* Carries the HTTP status and the parsed response body so callers can
|
|
112
|
+
* branch on structured error types (e.g. WalletApiError).
|
|
113
|
+
*/
|
|
114
|
+
export declare class ApiError extends Error {
|
|
115
|
+
readonly status: number;
|
|
116
|
+
readonly body: unknown;
|
|
117
|
+
constructor(status: number, body: unknown);
|
|
118
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/clients/payment-checkout/types.ts
|
|
2
|
+
var ApiError = class extends Error {
|
|
3
|
+
status;
|
|
4
|
+
body;
|
|
5
|
+
constructor(status, body) {
|
|
6
|
+
super(`API request failed with status ${status}`);
|
|
7
|
+
this.name = "ApiError";
|
|
8
|
+
this.status = status;
|
|
9
|
+
this.body = body;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
export {
|
|
13
|
+
ApiError
|
|
14
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { ApplePayButton, APPLE_PAY_EXCLUDED_VARIANTS, } from './apple-pay-button';
|
|
2
|
+
export { ApplePayModal } from './apple-pay-modal';
|
|
3
|
+
export { ensureApplePayLogoSymbol } from './apple-pay-logo';
|
|
4
|
+
export { configureApplePay } from './clients/payment-checkout/config';
|
|
5
|
+
export type { ApplePayRuntimeConfig } from './clients/payment-checkout/config';
|
|
6
|
+
export type { Offer } from './types/offer.types';
|
|
7
|
+
export declare function defineApplePayElements(): void;
|