//#region src/core/commerce/square-web.d.ts declare global { interface Window { Square?: any; } } declare function loadSquare(environment: string): Promise; /** * The shared `Square.payments()` instance for an app + location, created on * first use. {@link mountCard} and {@link mountWallets} both go through here; * a caller only needs it directly to reach an SDK method this module does not * wrap (ACH, gift cards, `verifyBuyer`). */ declare function getPayments(appId: string, locationId: string, environment: string): Promise; interface SquareCardHandle { tokenize: () => Promise; destroy: () => void; } /** * Initialize a Square card input attached to `selector` and return a handle * that tokenizes on demand. Throws with the Square error detail on failure. */ declare function mountCard(appId: string, locationId: string, environment: string, selector: string): Promise; type SquareWallet = "applePay" | "googlePay"; interface SquareWalletsOptions { /** The amount the sheet shows, in minor units (cents). */ totalCents: number; /** ISO 3166-1 alpha-2 of the merchant, for example, "US". */ countryCode: string; /** ISO 4217, for example, "USD". */ currencyCode: string; /** Minor-unit digits of `currencyCode`—2 for USD, 0 for JPY. Default 2. */ fractionDigits?: number; /** The line the sheet shows next to the amount. Default "Total". */ label?: string; /** * Where Square renders its Google Pay button. Google Pay is skipped when * absent—unlike Apple Pay, whose button is the caller's own markup. */ googlePayEl?: HTMLElement | null; /** Passed to Square's `googlePay.attach`. Defaults to a black, fill-width "Pay" button. */ googlePayButton?: { buttonColor?: string; buttonSizeMode?: string; buttonType?: string; }; /** * Called for each wallet Square could not initialize, with the reason. * Wallets are optional so a refusal only hides a button—but without the * reason, "no Apple Pay button" is undiagnosable (browser without Apple Pay, * no card in Wallet, domain not verified in the Square Dashboard, …). */ onUnavailable?: (wallet: SquareWallet, reason: string) => void; } /** Apple Pay / Google Pay, whichever this browser + merchant support. */ interface SquareWalletsHandle { /** * Tokenizes via the Apple Pay sheet. Call it synchronously from the click * handler—Safari refuses to open the sheet after an `await`. Absent when * unavailable. */ applePay?: () => Promise; /** Tokenizes via Google Pay (its button is attached to `googlePayEl`). Absent when unavailable. */ googlePay?: () => Promise; /** Keep the sheet's total in step with the checkout's (a tip, a re-quote). */ setTotal: (cents: number) => void; /** Why each absent wallet is absent—the same text `onUnavailable` received. */ unavailable: Partial>; } /** * Set up Apple Pay and Google Pay for a charge of `totalCents`. Each is * optional: Apple Pay needs Safari on an Apple device AND the domain * registered with Square; Google Pay needs a supporting browser and an * element to draw its button into. Whatever Square can't initialize is left * out and reported through `unavailable`—the card form always remains. */ declare function mountWallets(appId: string, locationId: string, environment: string, options: SquareWalletsOptions): Promise; /** * Per-directive origin lists, keyed like a CSP builder's input: `script` → * `script-src`, and so on. Plain data—merge it into whatever assembles the * site's policy. */ interface SquareCspOrigins { script: string[]; style: string[]; frame: string[]; connect: string[]; font: string[]; } interface SquareCspOptions { /** * Which Square environments to allow. Both by default, so ONE build serves * either—the environment is a runtime secret, while a CSP is usually baked * at build time. Narrow it only when the policy is computed per request. */ environments?: ("sandbox" | "production")[]; /** * Add Google Pay's origins, for {@link mountWallets}. Apple Pay needs none: * its sheet is Safari's own UI, not a page resource. */ wallets?: boolean; } /** * The origins Square's Web Payments SDK needs, for {@link mountCard} and * optionally {@link mountWallets}. Every host is here because leaving it out * broke something observable; the comments say what, so none of them reads as * a mystery origin to be tidied away. */ declare function squareWebPaymentsCsp(options?: SquareCspOptions): SquareCspOrigins; //#endregion export { SquareCardHandle, SquareCspOptions, SquareCspOrigins, SquareWallet, SquareWalletsHandle, SquareWalletsOptions, getPayments, loadSquare, mountCard, mountWallets, squareWebPaymentsCsp };