/** * Types mapping to the wallet-payments-api BFF. * Aligned with UI-Integration-Mocks.md. */ export type PaymentOptionsRequest = { sku: string; countryCode: string; currencyCode: string; /** The current page URL, sent to Commerce Services for logging purposes. */ checkoutUrl: string; }; /** * Relevant subset of the wallet-payments-api BFF GET /v1/wallet/payment-options/sku/:sku/:countryCode/:currencyCode response. * Only the apple_pay field is consumed by this package. */ export type PaymentOptionsResponse = { options: { apple_pay?: { provider: string; settings: { supported_networks: string[]; }; }; }; }; /** * GET /v1/wallet/session — uses credentials: 'include' (cookie-based). * * BFF always returns userType, even for anonymous users. * Scenario C (active-subscription) → frontend MUST suppress Apple Pay button. */ export type SessionResponse = { loggedIn: false; userType: 'new-eligible-user'; } | { loggedIn: true; emailAddress: string; contactId: string; userType: 'active-subscription' | 'b2b-user' | 'new-eligible-user'; }; export type ValidateMerchantRequest = { validationURL: string; recaptchaToken: string; }; export type ValidateMerchantResponse = { merchantSession: Record; }; /** * Minimal shape of the Apple Pay token received from `onpaymentauthorized`. * Mirrors the relevant subset of `ApplePayJS.ApplePayPaymentToken` without * requiring the `@types/applepayjs` package as a dependency. */ export type ApplePayPaymentToken = { paymentData: unknown; paymentMethod: { displayName?: string; network?: string; type?: string; }; transactionIdentifier: string; }; /** * Subset of ApplePayJS.ApplePayPaymentContact used in purchase and shipping. */ export type ApplePayPaymentContact = { emailAddress?: string; givenName?: string; familyName?: string; phoneNumber?: string; addressLines?: string[]; locality?: string; administrativeArea?: string; postalCode?: string; countryCode?: string; }; /** * POST /v1/wallet/purchase * * The BFF orchestrates eligibility check, passwordless registration, * basket creation, and payment finalization in a single call. */ export type PurchaseRequest = { applePayToken: ApplePayPaymentToken; /** * @TODO [BFF Contract Misalignment] * BFF spec requests `offerData: { ratePlanId, offerId }` but Commerce Services * only provide a `skuId`. Frontend uses `skuId` directly — BFF must be aligned. */ skuId: string; currency: string; billingContact: ApplePayPaymentContact; /** Required if loggedIn: false — contains emailAddress from Apple Pay sheet. */ shippingContact?: ApplePayPaymentContact; recaptchaToken: string; }; export type PurchaseResponse = { basketId: string; }; /** * Structured error body returned by all /v1/wallet/* endpoints on 4xx/5xx. */ export type WalletApiError = { errorType: 'NOT_FOUND' | 'SERVICE_UNAVAILABLE' | 'INTERNAL_SERVER_ERROR' | 'NOT_IMPLEMENTED' | 'EMAIL_COLLISION' | 'ACCOUNT_CREATION_FAILED' | 'PAYMENT_DECLINED' | 'RECAPTCHA_FAILED' | 'ELIGIBILITY_REJECTED' | 'INVALID_REQUEST' | 'VALIDATION_ERROR' | 'UNAUTHORIZED' | 'BAD_REQUEST' | 'REGISTRATION_FAILED'; message: string; }; /** * Error thrown by apiFetch for non-2xx responses. * Carries the HTTP status and the parsed response body so callers can * branch on structured error types (e.g. WalletApiError). */ export declare class ApiError extends Error { readonly status: number; readonly body: unknown; constructor(status: number, body: unknown); }