@forgeroute/ui 0.5.0 → 0.5.2

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.
@@ -0,0 +1,4332 @@
1
+ import * as i0 from "@angular/core";
2
+ import { ChangeDetectionStrategy, Component, DestroyRef, ElementRef, InjectionToken, Injector, PLATFORM_ID, ViewEncapsulation, afterNextRender, computed, effect, forwardRef, inject, input, model, output, signal, untracked, viewChild } from "@angular/core";
3
+ import { AlertComponent, BadgeComponent, ButtonComponent, CheckboxComponent, DetailCardComponent, HintComponent, KpiCardComponent, LiveRegionComponent, ModalComponent, PAYMENT_AUTH_TIMEOUT_MS, PAYMENT_HOST_SILENCE_MS, PAYMENT_METHOD_PLUGIN, PAYMENT_READINESS_EVERY_MS, PAYMENT_READINESS_TIMEOUT_MS, PAYMENT_REQUEST_TIMEOUT_MS, PAYMENT_STATUS_CHECK_TIMEOUT_MS, PAYMENT_STATUS_FAIL_GRACE_MS, PAYMENT_STATUS_POLL_MAX_MS, PAYMENT_STATUS_POLL_MS, PaymentAttemptStatusComponent, PaymentMethodPlugin, PillTabsComponent, SkeletonComponent, StackComponent, TextComponent, TextInputComponent, UiLabelsService, callHost, classifyHostError, createPaymentProtection, formatCurrency, hostErrorMessage, isDarkPage, isFinalPaymentRefusal, paymentErrorLabelKey, refusalLabelKey, uiText, warnQueuedPayment, wasQueuedOffline } from "@forgeroute/ui";
4
+ import { DOCUMENT, NgTemplateOutlet, isPlatformBrowser } from "@angular/common";
5
+ import * as i1 from "@angular/forms";
6
+ import { FormsModule } from "@angular/forms";
7
+ import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
8
+ const SQUARE_SDK_URL = "https://web.squarecdn.com/v1/square.js";
9
+ const SQUARE_SANDBOX_SDK_URL = "https://sandbox.web.squarecdn.com/v1/square.js";
10
+ const SQUARE_LOAD_TIMEOUT_MS = 2e4;
11
+ function withSquareTimeout(step, makeError) {
12
+ return new Promise((resolve, reject) => {
13
+ const timer = setTimeout(() => reject(makeError()), SQUARE_LOAD_TIMEOUT_MS);
14
+ Promise.resolve(step).then((value) => {
15
+ clearTimeout(timer);
16
+ resolve(value);
17
+ }, (error) => {
18
+ clearTimeout(timer);
19
+ reject(error);
20
+ });
21
+ });
22
+ }
23
+ const OWN_SCRIPT_MARK = "data-forgeroute-square";
24
+ var SquareLoadError = class extends Error {
25
+ constructor(code) {
26
+ super(code);
27
+ this.code = code;
28
+ this.name = "SquareLoadError";
29
+ }
30
+ };
31
+ const squareGlobal = () => window.Square;
32
+ const squareScript = {
33
+ pending: /* @__PURE__ */ new Map(),
34
+ active: null,
35
+ owners: /* @__PURE__ */ new Map(),
36
+ load(url) {
37
+ const switching = squareScript.active !== null && squareScript.active !== url;
38
+ if (squareGlobal() && !switching) return Promise.resolve();
39
+ for (const [other, inFlight] of squareScript.pending) if (other !== url) return inFlight.catch(() => void 0).then(() => squareScript.load(url));
40
+ const running = squareScript.pending.get(url);
41
+ if (running) return running;
42
+ const owner = {};
43
+ squareScript.owners.set(url, owner);
44
+ const promise = new Promise((resolve, reject) => {
45
+ const windowWithSquare = window;
46
+ const previous = switching ? windowWithSquare.Square : void 0;
47
+ const current = () => squareScript.owners.get(url) === owner;
48
+ let settled = false;
49
+ let loadTimer = null;
50
+ let script = null;
51
+ const finish = () => {
52
+ if (settled) return false;
53
+ settled = true;
54
+ if (loadTimer) {
55
+ clearTimeout(loadTimer);
56
+ loadTimer = null;
57
+ }
58
+ if (script) {
59
+ script.onload = null;
60
+ script.onerror = null;
61
+ }
62
+ return true;
63
+ };
64
+ const fail = () => {
65
+ if (!finish()) return;
66
+ if (current()) {
67
+ squareScript.pending.delete(url);
68
+ squareScript.owners.delete(url);
69
+ if (switching && previous && !windowWithSquare.Square) windowWithSquare.Square = previous;
70
+ }
71
+ reject(new SquareLoadError("script_failed"));
72
+ };
73
+ const done = () => {
74
+ if (!finish()) return;
75
+ if (current()) {
76
+ squareScript.active = url;
77
+ squareScript.pending.delete(url);
78
+ squareScript.owners.delete(url);
79
+ }
80
+ resolve();
81
+ };
82
+ const tags = Array.from(document.querySelectorAll("script")).filter((s) => s.getAttribute("src") === url);
83
+ let foreign = tags.filter((t) => !t.hasAttribute(OWN_SCRIPT_MARK));
84
+ if (switching) {
85
+ tags.forEach((t) => t.remove());
86
+ foreign = [];
87
+ delete windowWithSquare.Square;
88
+ } else tags.filter((t) => t.hasAttribute(OWN_SCRIPT_MARK)).forEach((t) => t.remove());
89
+ if (!switching && foreign.length) {
90
+ const started = Date.now();
91
+ const timer = setInterval(() => {
92
+ if (settled) {
93
+ clearInterval(timer);
94
+ return;
95
+ }
96
+ if (squareGlobal()) {
97
+ clearInterval(timer);
98
+ done();
99
+ } else if (Date.now() - started > 15e3) {
100
+ clearInterval(timer);
101
+ fail();
102
+ }
103
+ }, 50);
104
+ return;
105
+ }
106
+ const own = document.createElement("script");
107
+ script = own;
108
+ own.src = url;
109
+ own.async = true;
110
+ own.setAttribute(OWN_SCRIPT_MARK, "");
111
+ loadTimer = setTimeout(() => {
112
+ own.remove();
113
+ fail();
114
+ }, SQUARE_LOAD_TIMEOUT_MS);
115
+ own.onload = () => {
116
+ if (squareGlobal()) done();
117
+ else {
118
+ own.remove();
119
+ fail();
120
+ }
121
+ };
122
+ own.onerror = () => {
123
+ own.remove();
124
+ fail();
125
+ };
126
+ document.head.appendChild(own);
127
+ });
128
+ squareScript.pending.set(url, promise);
129
+ return promise;
130
+ }
131
+ };
132
+ const squareSdkUrl = (environment) => environment === "production" ? SQUARE_SDK_URL : SQUARE_SANDBOX_SDK_URL;
133
+ const defaultSquareLoader = async (config) => {
134
+ await squareScript.load(squareSdkUrl(config.environment));
135
+ const square = squareGlobal();
136
+ if (!square) throw new SquareLoadError("sdk_missing");
137
+ return square.payments(config.applicationId, config.locationId);
138
+ };
139
+ const SQUARE_LOADER = new InjectionToken("SQUARE_LOADER", {
140
+ providedIn: "root",
141
+ factory: () => defaultSquareLoader
142
+ });
143
+ const SQUARE_PAYMENT_DEFAULTS = new InjectionToken("SQUARE_PAYMENT_DEFAULTS", {
144
+ providedIn: "root",
145
+ factory: () => ({})
146
+ });
147
+ function provideSquarePayment(options = {}) {
148
+ const { loader, ...defaults } = options;
149
+ const providers = [{
150
+ provide: SQUARE_PAYMENT_DEFAULTS,
151
+ useValue: defaults
152
+ }];
153
+ if (loader) providers.push({
154
+ provide: SQUARE_LOADER,
155
+ useValue: loader
156
+ });
157
+ return providers;
158
+ }
159
+ const SQUARE_PAYMENT_ERROR_KEYS = {
160
+ GENERIC_DECLINE: "squareErrors.code.GENERIC_DECLINE",
161
+ CARD_DECLINED: "squareErrors.code.CARD_DECLINED",
162
+ CARD_DECLINED_CALL_ISSUER: "squareErrors.code.CARD_DECLINED_CALL_ISSUER",
163
+ CARD_DECLINED_VERIFICATION_REQUIRED: "squareErrors.code.CARD_DECLINED_VERIFICATION_REQUIRED",
164
+ INSUFFICIENT_FUNDS: "squareErrors.code.INSUFFICIENT_FUNDS",
165
+ CVV_FAILURE: "squareErrors.code.CVV_FAILURE",
166
+ VERIFY_CVV_FAILURE: "squareErrors.code.CVV_FAILURE",
167
+ ADDRESS_VERIFICATION_FAILURE: "squareErrors.code.ADDRESS_VERIFICATION_FAILURE",
168
+ VERIFY_AVS_FAILURE: "squareErrors.code.ADDRESS_VERIFICATION_FAILURE",
169
+ INVALID_EXPIRATION: "squareErrors.code.INVALID_EXPIRATION",
170
+ BAD_EXPIRATION: "squareErrors.code.INVALID_EXPIRATION",
171
+ CARD_EXPIRED: "squareErrors.code.CARD_EXPIRED",
172
+ INVALID_CARD: "squareErrors.code.INVALID_CARD",
173
+ PAN_FAILURE: "squareErrors.code.INVALID_CARD",
174
+ CARD_NOT_SUPPORTED: "squareErrors.code.CARD_NOT_SUPPORTED",
175
+ INVALID_ACCOUNT: "squareErrors.code.INVALID_ACCOUNT",
176
+ PAYMENT_LIMIT_EXCEEDED: "squareErrors.code.PAYMENT_LIMIT_EXCEEDED",
177
+ TRANSACTION_LIMIT: "squareErrors.code.PAYMENT_LIMIT_EXCEEDED",
178
+ BUYER_REFUSED_PAYMENT: "squareErrors.code.BUYER_REFUSED_PAYMENT",
179
+ CARDHOLDER_INSUFFICIENT_PERMISSIONS: "squareErrors.code.CARDHOLDER_INSUFFICIENT_PERMISSIONS",
180
+ IDEMPOTENCY_KEY_REUSED: "squareErrors.code.IDEMPOTENCY_KEY_REUSED",
181
+ RATE_LIMITED: "squareErrors.code.RATE_LIMITED",
182
+ UNAUTHORIZED: "squareErrors.code.UNAUTHORIZED",
183
+ ACCESS_TOKEN_EXPIRED: "squareErrors.code.UNAUTHORIZED",
184
+ ACCESS_TOKEN_REVOKED: "squareErrors.code.UNAUTHORIZED"
185
+ };
186
+ const SQUARE_FIELD_ERROR_KEYS = {
187
+ cardNumber: "squareErrors.field.cardNumber",
188
+ expirationDate: "squareErrors.field.expirationDate",
189
+ cvv: "squareErrors.field.cvv",
190
+ postalCode: "squareErrors.field.postalCode"
191
+ };
192
+ const SQUARE_TYPE_ERROR_KEYS = {
193
+ UNSUPPORTED_CARD_BRAND: "squareErrors.type.UNSUPPORTED_CARD_BRAND",
194
+ INVALID_APPLICATION_ID: "squareErrors.type.CONFIGURATION",
195
+ INVALID_LOCATION_ID: "squareErrors.type.CONFIGURATION",
196
+ PAYMENT_METHOD_NOT_SUPPORTED: "squareErrors.type.PAYMENT_METHOD_NOT_SUPPORTED"
197
+ };
198
+ function getSquarePaymentErrorMessage(code, options = {}) {
199
+ const fallback = options.fallback ?? uiText("squareErrors.defaultMessage");
200
+ const key = (code ?? "").toUpperCase();
201
+ const override = key ? options.overrides?.[code] ?? options.overrides?.[key] : void 0;
202
+ if (override) return override;
203
+ const table = SQUARE_PAYMENT_ERROR_KEYS[key];
204
+ return table ? uiText(table) : fallback;
205
+ }
206
+ function getSquareErrorMessage(error, options = {}) {
207
+ const fallback = options.fallback ?? uiText("squareErrors.defaultMessage");
208
+ if (!error) return fallback;
209
+ if (options.display === "square") return error.message || fallback;
210
+ const overrides = options.overrides ?? {};
211
+ for (const name of [
212
+ error.code,
213
+ error.type,
214
+ error.field
215
+ ]) if (name && overrides[name]) return overrides[name];
216
+ if (error.code && SQUARE_PAYMENT_ERROR_KEYS[error.code.toUpperCase()]) return uiText(SQUARE_PAYMENT_ERROR_KEYS[error.code.toUpperCase()]);
217
+ if (error.field && SQUARE_FIELD_ERROR_KEYS[error.field]) return uiText(SQUARE_FIELD_ERROR_KEYS[error.field]);
218
+ const type = (error.type ?? "").toUpperCase();
219
+ if (SQUARE_TYPE_ERROR_KEYS[type]) return uiText(SQUARE_TYPE_ERROR_KEYS[type]);
220
+ if (type === "VALIDATION_ERROR" && error.message) return error.message;
221
+ return fallback;
222
+ }
223
+ function squareFailure(code, message, stage, squareMessage = "") {
224
+ return {
225
+ code,
226
+ message,
227
+ squareMessage,
228
+ stage
229
+ };
230
+ }
231
+ function messageOfThrown(err, fallback) {
232
+ const e = err;
233
+ if (typeof e?.error?.message === "string" && e.error.message) return e.error.message;
234
+ if (typeof e?.message === "string" && e.message) return e.message;
235
+ return fallback;
236
+ }
237
+ const upper = (v) => typeof v === "string" ? v.toUpperCase() : "";
238
+ const text = (v) => typeof v === "string" && v.trim() ? v : null;
239
+ function normalizeSquareDetails(details) {
240
+ const card = details?.card;
241
+ const cardType = upper(card?.cardType);
242
+ const prepaid = upper(card?.prepaidType);
243
+ return {
244
+ brand: text(card?.brand),
245
+ last4: text(card?.last4) ?? text(details?.lastFour) ?? text(details?.ach?.lastFour),
246
+ expMonth: typeof card?.expMonth === "number" ? card.expMonth : null,
247
+ expYear: typeof card?.expYear === "number" ? card.expYear : null,
248
+ cardType: cardType === "CREDIT" || cardType === "DEBIT" || cardType === "UNKNOWN" ? cardType : null,
249
+ prepaidType: prepaid === "PREPAID" || prepaid === "NOT_PREPAID" || prepaid === "UNKNOWN" ? prepaid : null,
250
+ bankName: text(details?.bankName) ?? text(details?.ach?.bankName),
251
+ accountType: text(details?.accountType) ?? text(details?.ach?.accountType)
252
+ };
253
+ }
254
+ function failureFromTokenResult(result, method, options = {}) {
255
+ const errors = (result.errors ?? []).filter((e) => !!e);
256
+ const first = errors[0];
257
+ const base = {
258
+ status: result.status,
259
+ ...errors.length ? { errors } : {}
260
+ };
261
+ if (!first) {
262
+ const cancelled = result.status === "Cancel";
263
+ return {
264
+ ...squareFailure(cancelled ? "cancelled" : method === "ach" ? "ach_failed" : "tokenize_failed", uiText(cancelled ? "squarePayment.msg.cancelled" : method === "ach" ? "squarePayment.msg.achFailed" : "squarePayment.msg.tokenizeFailed"), "tokenize"),
265
+ ...base
266
+ };
267
+ }
268
+ const fallback = options.fallback ?? uiText(method === "ach" ? "squarePayment.msg.achFailed" : "squarePayment.msg.tokenizeFailed");
269
+ return {
270
+ ...squareFailure(first.code || first.type || "tokenize_failed", getSquareErrorMessage(first, {
271
+ ...options,
272
+ fallback
273
+ }), "tokenize", first.message ?? ""),
274
+ ...base,
275
+ ...first.field ? { field: first.field } : {}
276
+ };
277
+ }
278
+ function newIdempotencyKey() {
279
+ const c = typeof crypto !== "undefined" ? crypto : void 0;
280
+ return c && "randomUUID" in c ? c.randomUUID() : `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}-${Math.random().toString(36).slice(2)}`;
281
+ }
282
+ const DARK_TEXT = "#e2e8f0";
283
+ const DARK_BACKGROUND = "#0f172a";
284
+ const DARK_BORDER = "#64748b";
285
+ function readSquareCardStyle(doc, element = doc.documentElement) {
286
+ const view = doc.defaultView;
287
+ const token = (name) => view ? view.getComputedStyle(element).getPropertyValue(name).trim() : "";
288
+ const dark = isDarkPage(doc);
289
+ const primary = token("--ui-square-color-primary");
290
+ const text = token("--ui-square-color-text") || (dark ? DARK_TEXT : "");
291
+ const background = token("--ui-square-color-background") || (dark ? DARK_BACKGROUND : "");
292
+ const border = token("--ui-square-color-border") || (dark ? DARK_BORDER : "");
293
+ const danger = token("--ui-square-color-danger");
294
+ const font = token("--ui-square-font-family");
295
+ const radius = token("--ui-square-border-radius");
296
+ const size = token("--ui-square-font-size-base");
297
+ const style = {};
298
+ const put = (selector, props) => {
299
+ const filled = Object.fromEntries(Object.entries(props).filter(([, v]) => !!v));
300
+ if (Object.keys(filled).length) style[selector] = filled;
301
+ };
302
+ put(".input-container", {
303
+ borderColor: border,
304
+ borderRadius: radius
305
+ });
306
+ put(".input-container.is-focus", { borderColor: primary });
307
+ put(".input-container.is-error", { borderColor: danger });
308
+ put(".message-text", { color: text });
309
+ put(".message-icon", { color: text });
310
+ put(".message-text.is-error", { color: danger });
311
+ put("input", {
312
+ backgroundColor: background,
313
+ color: text,
314
+ fontFamily: font,
315
+ fontSize: size
316
+ });
317
+ put("input::placeholder", { color: dark ? "#94a3b8" : "" });
318
+ return style;
319
+ }
320
+ const SQUARE_A11Y_MESSAGES = {
321
+ get loading() {
322
+ return uiText("squarePayment.a11y.loading");
323
+ },
324
+ get processing() {
325
+ return uiText("squarePayment.a11y.processing");
326
+ },
327
+ get tokenized() {
328
+ return uiText("squarePayment.a11y.tokenized");
329
+ }
330
+ };
331
+ let nextId = 0;
332
+ const jsonEqual = (a, b) => JSON.stringify(a) === JSON.stringify(b);
333
+ function structuralEqual(a, b, inProgress = /* @__PURE__ */ new WeakMap()) {
334
+ if (Object.is(a, b)) return true;
335
+ if (typeof a !== "object" || typeof b !== "object" || !a || !b) return false;
336
+ if (inProgress.get(a)?.has(b)) return true;
337
+ if (Object.getPrototypeOf(a) !== Object.getPrototypeOf(b)) return false;
338
+ if (a instanceof Date) return b instanceof Date && a.getTime() === b.getTime();
339
+ if (a instanceof RegExp) return b instanceof RegExp && a.source === b.source && a.flags === b.flags;
340
+ const pairs = inProgress.get(a) ?? /* @__PURE__ */ new WeakSet();
341
+ pairs.add(b);
342
+ inProgress.set(a, pairs);
343
+ try {
344
+ if (a instanceof Map) {
345
+ const other = b;
346
+ return a.size === other.size && [...a].every(([k, v]) => other.has(k) && structuralEqual(v, other.get(k), inProgress));
347
+ }
348
+ if (a instanceof Set) {
349
+ const other = b;
350
+ if (a.size !== other.size) return false;
351
+ const rest = [...other];
352
+ for (const member of a) {
353
+ const at = rest.findIndex((candidate) => structuralEqual(member, candidate, inProgress));
354
+ if (at < 0) return false;
355
+ rest.splice(at, 1);
356
+ }
357
+ return true;
358
+ }
359
+ const keysA = Object.keys(a);
360
+ const keysB = Object.keys(b);
361
+ return keysA.length === keysB.length && keysA.every((k) => k in b && structuralEqual(a[k], b[k], inProgress));
362
+ } finally {
363
+ pairs.delete(b);
364
+ }
365
+ }
366
+ var SquarePaymentComponent = class SquarePaymentComponent {
367
+ constructor() {
368
+ this.labels = inject(UiLabelsService);
369
+ this.loader = inject(SQUARE_LOADER);
370
+ this.defaults = inject(SQUARE_PAYMENT_DEFAULTS);
371
+ this.doc = inject(DOCUMENT);
372
+ this.isBrowser = isPlatformBrowser(inject(PLATFORM_ID));
373
+ this.host = inject(ElementRef);
374
+ this.injector = inject(Injector);
375
+ this.mountOnly = input(false, ...ngDevMode ? [{ debugName: "mountOnly" }] : /* istanbul ignore next */ []);
376
+ this.mode = input("payment", ...ngDevMode ? [{ debugName: "mode" }] : /* istanbul ignore next */ []);
377
+ this.method = model("card", ...ngDevMode ? [{ debugName: "method" }] : /* istanbul ignore next */ []);
378
+ this.methods = input(null, ...ngDevMode ? [{ debugName: "methods" }] : /* istanbul ignore next */ []);
379
+ this.applicationId = input(null, ...ngDevMode ? [{ debugName: "applicationId" }] : /* istanbul ignore next */ []);
380
+ this.locationId = input(null, ...ngDevMode ? [{ debugName: "locationId" }] : /* istanbul ignore next */ []);
381
+ this.environment = input(null, ...ngDevMode ? [{ debugName: "environment" }] : /* istanbul ignore next */ []);
382
+ this.amount = input(null, ...ngDevMode ? [{ debugName: "amount" }] : /* istanbul ignore next */ []);
383
+ this.currency = input("USD", ...ngDevMode ? [{ debugName: "currency" }] : /* istanbul ignore next */ []);
384
+ this.billingContact = input(null, ...ngDevMode ? [{ debugName: "billingContact" }] : /* istanbul ignore next */ []);
385
+ this.verifyBuyer = input(null, ...ngDevMode ? [{ debugName: "verifyBuyer" }] : /* istanbul ignore next */ []);
386
+ this.accountHolderName = input("", ...ngDevMode ? [{ debugName: "accountHolderName" }] : /* istanbul ignore next */ []);
387
+ this.requireAchConsent = input(true, ...ngDevMode ? [{ debugName: "requireAchConsent" }] : /* istanbul ignore next */ []);
388
+ this.achConsentTextInput = input(null, {
389
+ ...ngDevMode ? { debugName: "achConsentTextInput" } : /* istanbul ignore next */ {},
390
+ alias: "achConsentText"
391
+ });
392
+ this.achConsent = computed(() => this.achConsentTextInput() ?? this.labels.t(this.mode() === "setup" ? "squarePayment.achConsentSetup" : "squarePayment.achConsent"), ...ngDevMode ? [{ debugName: "achConsent" }] : /* istanbul ignore next */ []);
393
+ this.achRedirectUri = input(null, ...ngDevMode ? [{ debugName: "achRedirectUri" }] : /* istanbul ignore next */ []);
394
+ this.achTransactionId = input(null, ...ngDevMode ? [{ debugName: "achTransactionId" }] : /* istanbul ignore next */ []);
395
+ this.cardOptions = input(null, ...ngDevMode ? [{ debugName: "cardOptions" }] : /* istanbul ignore next */ []);
396
+ this.cardStyle = input(null, ...ngDevMode ? [{ debugName: "cardStyle" }] : /* istanbul ignore next */ []);
397
+ this.styleFromTokens = input(false, ...ngDevMode ? [{ debugName: "styleFromTokens" }] : /* istanbul ignore next */ []);
398
+ this.showStatus = input(true, ...ngDevMode ? [{ debugName: "showStatus" }] : /* istanbul ignore next */ []);
399
+ this.payableRef = input(null, ...ngDevMode ? [{ debugName: "payableRef" }] : /* istanbul ignore next */ []);
400
+ this.attemptKey = input(null, ...ngDevMode ? [{ debugName: "attemptKey" }] : /* istanbul ignore next */ []);
401
+ this.checkStatus = input(null, ...ngDevMode ? [{ debugName: "checkStatus" }] : /* istanbul ignore next */ []);
402
+ this.paid = input(false, ...ngDevMode ? [{ debugName: "paid" }] : /* istanbul ignore next */ []);
403
+ this.hostPending = input(false, ...ngDevMode ? [{ debugName: "hostPending" }] : /* istanbul ignore next */ []);
404
+ this.statusPollMs = input(PAYMENT_STATUS_POLL_MS, ...ngDevMode ? [{ debugName: "statusPollMs" }] : /* istanbul ignore next */ []);
405
+ this.statusPollMaxMs = input(PAYMENT_STATUS_POLL_MAX_MS, ...ngDevMode ? [{ debugName: "statusPollMaxMs" }] : /* istanbul ignore next */ []);
406
+ this.statusCheckTimeoutMs = input(PAYMENT_STATUS_CHECK_TIMEOUT_MS, ...ngDevMode ? [{ debugName: "statusCheckTimeoutMs" }] : /* istanbul ignore next */ []);
407
+ this.statusFailGraceMs = input(PAYMENT_STATUS_FAIL_GRACE_MS, ...ngDevMode ? [{ debugName: "statusFailGraceMs" }] : /* istanbul ignore next */ []);
408
+ this.allowStartOver = input(false, ...ngDevMode ? [{ debugName: "allowStartOver" }] : /* istanbul ignore next */ []);
409
+ this.offlineOverride = input(false, ...ngDevMode ? [{ debugName: "offlineOverride" }] : /* istanbul ignore next */ []);
410
+ this.hostSilenceMs = input(PAYMENT_HOST_SILENCE_MS, ...ngDevMode ? [{ debugName: "hostSilenceMs" }] : /* istanbul ignore next */ []);
411
+ this.readinessCheck = input(null, ...ngDevMode ? [{ debugName: "readinessCheck" }] : /* istanbul ignore next */ []);
412
+ this.readinessTimeoutMs = input(PAYMENT_READINESS_TIMEOUT_MS, ...ngDevMode ? [{ debugName: "readinessTimeoutMs" }] : /* istanbul ignore next */ []);
413
+ this.readinessEveryMs = input(PAYMENT_READINESS_EVERY_MS, ...ngDevMode ? [{ debugName: "readinessEveryMs" }] : /* istanbul ignore next */ []);
414
+ this.submitLabel = input("", ...ngDevMode ? [{ debugName: "submitLabel" }] : /* istanbul ignore next */ []);
415
+ this.showSubmit = input(true, ...ngDevMode ? [{ debugName: "showSubmit" }] : /* istanbul ignore next */ []);
416
+ this.disabled = input(false, ...ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []);
417
+ this.pending = input(false, ...ngDevMode ? [{ debugName: "pending" }] : /* istanbul ignore next */ []);
418
+ this.labelInput = input(null, {
419
+ ...ngDevMode ? { debugName: "labelInput" } : /* istanbul ignore next */ {},
420
+ alias: "label"
421
+ });
422
+ this.label = computed(() => this.labelInput() ?? this.labels.t("squarePayment.label"), ...ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []);
423
+ this.required = input(false, ...ngDevMode ? [{ debugName: "required" }] : /* istanbul ignore next */ []);
424
+ this.mountId = input("", ...ngDevMode ? [{ debugName: "mountId" }] : /* istanbul ignore next */ []);
425
+ this.mountClass = input("", ...ngDevMode ? [{ debugName: "mountClass" }] : /* istanbul ignore next */ []);
426
+ this.mountTestId = input("square-card-form", ...ngDevMode ? [{ debugName: "mountTestId" }] : /* istanbul ignore next */ []);
427
+ this.errorTestId = input("square-error", ...ngDevMode ? [{ debugName: "errorTestId" }] : /* istanbul ignore next */ []);
428
+ this.holderTestId = input("square-holder", ...ngDevMode ? [{ debugName: "holderTestId" }] : /* istanbul ignore next */ []);
429
+ this.showErrors = input(true, ...ngDevMode ? [{ debugName: "showErrors" }] : /* istanbul ignore next */ []);
430
+ this.errorDisplay = input("friendly", ...ngDevMode ? [{ debugName: "errorDisplay" }] : /* istanbul ignore next */ []);
431
+ this.errorMessages = input(null, ...ngDevMode ? [{ debugName: "errorMessages" }] : /* istanbul ignore next */ []);
432
+ this.errorFallback = input("", ...ngDevMode ? [{ debugName: "errorFallback" }] : /* istanbul ignore next */ []);
433
+ this.loadErrorMessageInput = input(null, {
434
+ ...ngDevMode ? { debugName: "loadErrorMessageInput" } : /* istanbul ignore next */ {},
435
+ alias: "loadErrorMessage"
436
+ });
437
+ this.loadErrorMessage = computed(() => this.loadErrorMessageInput() ?? this.labels.t("squarePayment.loadErrorMessage"), ...ngDevMode ? [{ debugName: "loadErrorMessage" }] : /* istanbul ignore next */ []);
438
+ this.a11yMessages = input(null, ...ngDevMode ? [{ debugName: "a11yMessages" }] : /* istanbul ignore next */ []);
439
+ this.squareReady = output();
440
+ this.ready = output();
441
+ this.inFlightChange = output();
442
+ this.outcome = output();
443
+ this.attemptKeyChange = output();
444
+ this.readinessChange = output();
445
+ this.tokenized = output();
446
+ this.failed = output();
447
+ this.loadError = output();
448
+ this.loading = signal(false, ...ngDevMode ? [{ debugName: "loading" }] : /* istanbul ignore next */ []);
449
+ this.isReady = signal(false, ...ngDevMode ? [{ debugName: "isReady" }] : /* istanbul ignore next */ []);
450
+ this.submitting = signal(false, ...ngDevMode ? [{ debugName: "submitting" }] : /* istanbul ignore next */ []);
451
+ this.errorText = signal("", ...ngDevMode ? [{ debugName: "errorText" }] : /* istanbul ignore next */ []);
452
+ this.loadErrorText = signal("", ...ngDevMode ? [{ debugName: "loadErrorText" }] : /* istanbul ignore next */ []);
453
+ this.holder = signal("", ...ngDevMode ? [{ debugName: "holder" }] : /* istanbul ignore next */ []);
454
+ this.consent = signal(false, ...ngDevMode ? [{ debugName: "consent" }] : /* istanbul ignore next */ []);
455
+ this.attempted = signal(false, ...ngDevMode ? [{ debugName: "attempted" }] : /* istanbul ignore next */ []);
456
+ this.announcement = signal("", ...ngDevMode ? [{ debugName: "announcement" }] : /* istanbul ignore next */ []);
457
+ this.resetTick = signal(0, ...ngDevMode ? [{ debugName: "resetTick" }] : /* istanbul ignore next */ []);
458
+ this.errorId = `ui-square-error-${nextId++}`;
459
+ this.mountRef = viewChild("mount", ...ngDevMode ? [{ debugName: "mountRef" }] : /* istanbul ignore next */ []);
460
+ this.tabs = computed(() => {
461
+ const methods = this.methods();
462
+ if (!methods || methods.length < 2) return [];
463
+ return methods.map((m) => ({
464
+ key: m,
465
+ label: this.labels.t(m === "card" ? "squarePayment.method.card" : "squarePayment.method.ach")
466
+ }));
467
+ }, ...ngDevMode ? [{ debugName: "tabs" }] : /* istanbul ignore next */ []);
468
+ this.locked = computed(() => this.disabled() || this.submitting() || this.attempt.locked(), ...ngDevMode ? [{ debugName: "locked" }] : /* istanbul ignore next */ []);
469
+ this.mountHidden = computed(() => !this.mountOnly() && (this.loading() || this.pending() || !!this.loadErrorText()), ...ngDevMode ? [{ debugName: "mountHidden" }] : /* istanbul ignore next */ []);
470
+ this.mountLocked = computed(() => !this.mountOnly() && this.locked(), ...ngDevMode ? [{ debugName: "mountLocked" }] : /* istanbul ignore next */ []);
471
+ this.holderError = computed(() => this.attempted() && !this.holder().trim() ? this.labels.t("squarePayment.holderRequired") : "", ...ngDevMode ? [{ debugName: "holderError" }] : /* istanbul ignore next */ []);
472
+ this.effectiveSubmitLabel = computed(() => {
473
+ const given = this.submitLabel();
474
+ if (given) return given;
475
+ const setup = this.mode() === "setup";
476
+ return this.labels.t(this.method() === "ach" ? setup ? "squarePayment.submit.saveBank" : "squarePayment.submit.payBank" : setup ? "squarePayment.submit.saveCard" : "squarePayment.submit.pay");
477
+ }, ...ngDevMode ? [{ debugName: "effectiveSubmitLabel" }] : /* istanbul ignore next */ []);
478
+ this.submitDisabled = computed(() => this.disabled() || this.loading() || this.pending() || !this.isReady() || !!this.loadErrorText() || this.attempt.locked() || !this.readiness.ready(), ...ngDevMode ? [{ debugName: "submitDisabled" }] : /* istanbul ignore next */ []);
479
+ this.messages = computed(() => {
480
+ const given = Object.fromEntries(Object.entries(this.a11yMessages() ?? {}).filter(([, text]) => typeof text === "string"));
481
+ return {
482
+ ...SQUARE_A11Y_MESSAGES,
483
+ ...given
484
+ };
485
+ }, ...ngDevMode ? [{ debugName: "messages" }] : /* istanbul ignore next */ []);
486
+ this.statusText = computed(() => {
487
+ if (this.loading()) return this.messages().loading;
488
+ if (this.submitting()) return this.messages().processing;
489
+ return this.announcement();
490
+ }, ...ngDevMode ? [{ debugName: "statusText" }] : /* istanbul ignore next */ []);
491
+ this.connection = computed(() => ({
492
+ applicationId: this.applicationId() || this.defaults.applicationId || "",
493
+ locationId: this.locationId() || this.defaults.locationId || "",
494
+ environment: this.environment() ?? this.defaults.environment ?? "sandbox"
495
+ }), {
496
+ ...ngDevMode ? { debugName: "connection" } : /* istanbul ignore next */ {},
497
+ equal: jsonEqual
498
+ });
499
+ this.cardConfig = computed(() => {
500
+ const style = this.cardStyle();
501
+ const options = this.cardOptions();
502
+ if (!style && !options) return null;
503
+ return {
504
+ ...style ? { style } : {},
505
+ ...options ?? {}
506
+ };
507
+ }, {
508
+ ...ngDevMode ? { debugName: "cardConfig" } : /* istanbul ignore next */ {},
509
+ equal: structuralEqual
510
+ });
511
+ this.payments = null;
512
+ this.card = null;
513
+ this.ach = null;
514
+ this.generation = 0;
515
+ this.destroyed = false;
516
+ this.announced = false;
517
+ const protection = createPaymentProtection(this, {
518
+ amount: () => this.amount(),
519
+ method: () => this.method(),
520
+ sdk: () => this.loadErrorText() ? "blocked" : this.loading() ? "loading" : "ok",
521
+ offlineMidFlight: false,
522
+ onOutcome: (o) => this.outcome.emit(o),
523
+ onInFlightChange: (v) => this.inFlightChange.emit(v),
524
+ onKeyChange: (k) => this.attemptKeyChange.emit(k),
525
+ onReadinessChange: (r) => this.readinessChange.emit(r)
526
+ });
527
+ this.attempt = protection.attempt;
528
+ this.readiness = protection.readiness;
529
+ effect(() => {
530
+ const method = this.method();
531
+ const mount = method === "card" ? this.mountRef() : null;
532
+ const connection = this.connection();
533
+ const card = this.cardConfig();
534
+ const ach = {
535
+ redirectUri: this.achRedirectUri(),
536
+ transactionId: this.achTransactionId()
537
+ };
538
+ this.resetTick();
539
+ this.styleFromTokens();
540
+ if (method === "card" && !mount) return;
541
+ untracked(() => {
542
+ this.init(mount?.nativeElement ?? null, method, connection, card, ach);
543
+ });
544
+ });
545
+ effect(() => {
546
+ const name = this.accountHolderName();
547
+ untracked(() => this.holder.set(name));
548
+ });
549
+ inject(DestroyRef).onDestroy(() => {
550
+ this.destroyed = true;
551
+ this.generation++;
552
+ this.disposeInstances();
553
+ this.payments = null;
554
+ });
555
+ }
556
+ async tokenize() {
557
+ if (this.submitting() || this.disabled() || this.pending()) return null;
558
+ if (this.refusedByProtection()) return null;
559
+ const method = this.method();
560
+ const card = this.card;
561
+ const ach = this.ach;
562
+ if (!this.isReady() || (method === "card" ? !card : !ach)) {
563
+ this.fail(squareFailure("not_ready", this.labels.t("squarePayment.msg.notReady"), "tokenize"));
564
+ return null;
565
+ }
566
+ this.attempted.set(true);
567
+ const holder = this.holder().trim();
568
+ if (method === "ach") {
569
+ if (!holder) {
570
+ this.fail(squareFailure("holder_required", this.labels.t("squarePayment.holderRequired"), "validate"));
571
+ this.focusInput("holder");
572
+ return null;
573
+ }
574
+ if (this.requireAchConsent() && !this.mountOnly() && !this.consent()) {
575
+ this.fail(squareFailure("consent_required", this.labels.t("squarePayment.consentRequired"), "validate"));
576
+ this.focusInput("consent");
577
+ return null;
578
+ }
579
+ }
580
+ const generation = this.generation;
581
+ const kind = this.mode();
582
+ const begun = this.attempt.begin();
583
+ if (!begun.ok) return null;
584
+ const attemptKey = begun.key;
585
+ const payableRef = this.attempt.pinnedRef();
586
+ const amount = this.attempt.pinnedAmount();
587
+ let handedToHost = false;
588
+ this.submitting.set(true);
589
+ this.errorText.set("");
590
+ this.announcement.set("");
591
+ try {
592
+ const result = method === "card" ? await card.tokenize() : await ach.tokenize({ accountHolderName: holder });
593
+ if (this.destroyed || generation !== this.generation) return null;
594
+ if (result.status !== "OK" || !result.token) {
595
+ this.fail(failureFromTokenResult(result, method, this.errorOptions()));
596
+ return null;
597
+ }
598
+ let verificationToken = null;
599
+ if (method === "card" && this.shouldVerify(kind, amount)) {
600
+ const verified = await this.verify(result.token, kind, amount);
601
+ if (this.destroyed || generation !== this.generation) return null;
602
+ if ("code" in verified) {
603
+ this.fail(verified);
604
+ return null;
605
+ }
606
+ verificationToken = verified.token;
607
+ }
608
+ const event = {
609
+ token: result.token,
610
+ method,
611
+ kind,
612
+ details: normalizeSquareDetails(result.details),
613
+ verificationToken,
614
+ idempotencyKey: newIdempotencyKey(),
615
+ attemptKey,
616
+ amount,
617
+ payableRef
618
+ };
619
+ this.announcement.set(this.messages().tokenized);
620
+ if (kind === "payment") {
621
+ handedToHost = true;
622
+ this.attempt.markPending("token");
623
+ }
624
+ this.tokenized.emit(event);
625
+ return event;
626
+ } catch (err) {
627
+ if (this.destroyed || generation !== this.generation) return null;
628
+ this.fail({ ...squareFailure("tokenize_failed", this.errorFallback() || this.labels.t(method === "ach" ? "squarePayment.msg.achFailed" : "squarePayment.msg.tokenizeFailed"), "tokenize", messageOfThrown(err, "")) });
629
+ return null;
630
+ } finally {
631
+ this.submitting.set(false);
632
+ if (!handedToHost) this.attempt.release();
633
+ }
634
+ }
635
+ markUnknown() {
636
+ this.attempt.markUnknown("host");
637
+ }
638
+ markSucceeded() {
639
+ this.attempt.succeed("host");
640
+ }
641
+ markFailed() {
642
+ this.attempt.fail("host");
643
+ }
644
+ markNotCharged() {
645
+ this.attempt.markNotCharged();
646
+ }
647
+ resetPaid() {
648
+ this.attempt.resetPaid();
649
+ }
650
+ reset() {
651
+ this.resetTick.update((n) => n + 1);
652
+ }
653
+ destroyForm() {
654
+ this.generation++;
655
+ this.disposeInstances();
656
+ this.isReady.set(false);
657
+ this.loading.set(false);
658
+ }
659
+ refusedByProtection() {
660
+ if (!this.readiness.passSync()) {
661
+ const reason = this.readiness.reasons()[0] ?? "checking";
662
+ this.outcome.emit({
663
+ kind: "refused",
664
+ attemptKey: this.attempt.key(),
665
+ reason
666
+ });
667
+ this.fail(squareFailure(reason, this.labels.t(refusalLabelKey(reason)), "validate"));
668
+ return true;
669
+ }
670
+ if (this.attempt.inFlight()) return true;
671
+ if (this.attempt.paidLocked() || this.attempt.unknown()) {
672
+ this.attempt.begin();
673
+ return true;
674
+ }
675
+ return false;
676
+ }
677
+ retryLoad() {
678
+ this.reset();
679
+ }
680
+ focusInput(which) {
681
+ if (this.mountOnly()) return;
682
+ const id = which === "holder" ? this.holderTestId() : "square-consent";
683
+ afterNextRender(() => this.host.nativeElement.querySelector(`input[data-testid="${id}"]`)?.focus(), { injector: this.injector });
684
+ }
685
+ errorOptions() {
686
+ return {
687
+ display: this.errorDisplay(),
688
+ overrides: this.errorMessages(),
689
+ ...this.errorFallback() ? { fallback: this.errorFallback() } : {}
690
+ };
691
+ }
692
+ shouldVerify(kind, amount) {
693
+ const forced = this.verifyBuyer();
694
+ if (forced !== null) return forced;
695
+ return kind === "payment" ? amount !== null && !!this.billingContact() : !!this.billingContact();
696
+ }
697
+ async verify(token, kind, amount) {
698
+ const failure = (squareMessage = "") => squareFailure("verification_failed", this.labels.t("squarePayment.msg.verifyFailed"), "verify", squareMessage);
699
+ const verifyBuyer = this.payments?.verifyBuyer?.bind(this.payments);
700
+ if (!verifyBuyer || kind === "payment" && amount === null) return failure();
701
+ const billing = this.billingContact();
702
+ const details = {
703
+ intent: kind === "setup" ? "STORE" : "CHARGE",
704
+ ...kind === "payment" ? {
705
+ amount: (Math.round(amount * 100) / 100).toFixed(2),
706
+ currencyCode: this.currency().toUpperCase()
707
+ } : {},
708
+ ...billing ? { billingContact: billing } : {},
709
+ customerInitiated: true,
710
+ sellerKeyedIn: false
711
+ };
712
+ try {
713
+ const result = await verifyBuyer(token, details);
714
+ return result?.token ? { token: result.token } : failure();
715
+ } catch (err) {
716
+ return failure(messageOfThrown(err, ""));
717
+ }
718
+ }
719
+ fail(f) {
720
+ const override = this.errorMessages()?.[f.code];
721
+ if (override) f = {
722
+ ...f,
723
+ message: override
724
+ };
725
+ if (this.destroyed) return;
726
+ if (this.showErrors()) this.errorText.set(f.message);
727
+ this.announcement.set("");
728
+ this.failed.emit(f);
729
+ }
730
+ discardLate(pending) {
731
+ pending.then((late) => {
732
+ try {
733
+ Promise.resolve(late.destroy?.()).catch(() => void 0);
734
+ } catch {}
735
+ }, () => void 0);
736
+ }
737
+ disposeInstances() {
738
+ const card = this.card;
739
+ const ach = this.ach;
740
+ this.card = null;
741
+ this.ach = null;
742
+ if (this.announced) {
743
+ this.announced = false;
744
+ if (!this.destroyed) this.squareReady.emit(null);
745
+ }
746
+ for (const instance of [card, ach]) {
747
+ if (!instance?.destroy) continue;
748
+ try {
749
+ Promise.resolve(instance.destroy()).catch(() => void 0);
750
+ } catch {}
751
+ }
752
+ }
753
+ loadFailed(code, message, squareMessage) {
754
+ this.loading.set(false);
755
+ this.isReady.set(false);
756
+ this.loadErrorText.set(this.loadErrorMessage());
757
+ this.loadError.emit(squareFailure(code, message, "load", squareMessage));
758
+ }
759
+ async init(container, method, connection, cardConfig, ach) {
760
+ const generation = ++this.generation;
761
+ this.disposeInstances();
762
+ this.isReady.set(false);
763
+ this.errorText.set("");
764
+ this.loadErrorText.set("");
765
+ this.announcement.set("");
766
+ if (!this.isBrowser) {
767
+ this.loading.set(false);
768
+ return;
769
+ }
770
+ if (!connection.applicationId || !connection.locationId) {
771
+ this.loadFailed("config_missing", this.labels.t("squarePayment.msg.configMissing"), "");
772
+ return;
773
+ }
774
+ this.loading.set(true);
775
+ try {
776
+ this.payments = null;
777
+ const payments = await withSquareTimeout(this.loader(connection), () => new SquareLoadError("script_failed"));
778
+ if (generation !== this.generation) return;
779
+ this.payments = payments;
780
+ } catch (err) {
781
+ if (generation !== this.generation) return;
782
+ this.loadFailed(err instanceof SquareLoadError ? err.code : "load_error", this.labels.t("squarePayment.msg.loadFailed"), messageOfThrown(err, ""));
783
+ return;
784
+ }
785
+ try {
786
+ const payments = this.payments;
787
+ if (method === "card") {
788
+ const tokenStyle = this.styleFromTokens() && cardConfig?.["style"] === void 0 ? { style: readSquareCardStyle(this.doc, this.host.nativeElement) } : null;
789
+ const options = tokenStyle || cardConfig ? {
790
+ ...tokenStyle ?? {},
791
+ ...cardConfig ?? {}
792
+ } : null;
793
+ const pendingCard = options ? payments.card(options) : payments.card();
794
+ const card = await withSquareTimeout(pendingCard, () => /* @__PURE__ */ new Error("timeout")).catch((err) => {
795
+ this.discardLate(pendingCard);
796
+ throw err;
797
+ });
798
+ if (generation !== this.generation) {
799
+ try {
800
+ Promise.resolve(card.destroy()).catch(() => void 0);
801
+ } catch {}
802
+ return;
803
+ }
804
+ this.card = card;
805
+ try {
806
+ await withSquareTimeout(card.attach(container), () => /* @__PURE__ */ new Error("timeout"));
807
+ } catch (err) {
808
+ if (generation !== this.generation) return;
809
+ this.disposeInstances();
810
+ this.loadFailed("mount_failed", this.labels.t("squarePayment.msg.cardFormFailed"), messageOfThrown(err, ""));
811
+ return;
812
+ }
813
+ } else {
814
+ const options = {
815
+ ...ach.redirectUri ? { redirectURI: ach.redirectUri } : {},
816
+ ...ach.transactionId ? { transactionId: ach.transactionId } : {}
817
+ };
818
+ const pendingAch = Object.keys(options).length ? payments.ach(options) : payments.ach();
819
+ const instance = await withSquareTimeout(pendingAch, () => /* @__PURE__ */ new Error("timeout")).catch((err) => {
820
+ this.discardLate(pendingAch);
821
+ throw err;
822
+ });
823
+ if (generation !== this.generation) {
824
+ try {
825
+ Promise.resolve(instance.destroy?.()).catch(() => void 0);
826
+ } catch {}
827
+ return;
828
+ }
829
+ this.ach = instance;
830
+ }
831
+ if (generation !== this.generation) return;
832
+ this.loading.set(false);
833
+ this.isReady.set(true);
834
+ this.announced = true;
835
+ this.squareReady.emit({
836
+ payments,
837
+ card: this.card,
838
+ ach: this.ach
839
+ });
840
+ this.ready.emit();
841
+ } catch (err) {
842
+ if (generation !== this.generation) return;
843
+ this.disposeInstances();
844
+ this.loadFailed("init_failed", this.labels.t(method === "card" ? "squarePayment.msg.cardFormFailed" : "squarePayment.msg.achInitFailed"), messageOfThrown(err, ""));
845
+ }
846
+ }
847
+ onTab(key) {
848
+ if (this.submitting() || this.disabled() || this.attempt.locked() || key !== "card" && key !== "ach") return;
849
+ this.method.set(key);
850
+ this.errorText.set("");
851
+ }
852
+ static {
853
+ this.ɵfac = i0.ɵɵngDeclareFactory({
854
+ minVersion: "12.0.0",
855
+ version: "22.2.2",
856
+ ngImport: i0,
857
+ type: SquarePaymentComponent,
858
+ deps: [],
859
+ target: i0.ɵɵFactoryTarget.Component
860
+ });
861
+ }
862
+ static {
863
+ this.ɵcmp = i0.ɵɵngDeclareComponent({
864
+ minVersion: "17.0.0",
865
+ version: "22.2.2",
866
+ type: SquarePaymentComponent,
867
+ isStandalone: true,
868
+ selector: "ui-square-payment",
869
+ inputs: {
870
+ mountOnly: {
871
+ classPropertyName: "mountOnly",
872
+ publicName: "mountOnly",
873
+ isSignal: true,
874
+ isRequired: false,
875
+ transformFunction: null
876
+ },
877
+ mode: {
878
+ classPropertyName: "mode",
879
+ publicName: "mode",
880
+ isSignal: true,
881
+ isRequired: false,
882
+ transformFunction: null
883
+ },
884
+ method: {
885
+ classPropertyName: "method",
886
+ publicName: "method",
887
+ isSignal: true,
888
+ isRequired: false,
889
+ transformFunction: null
890
+ },
891
+ methods: {
892
+ classPropertyName: "methods",
893
+ publicName: "methods",
894
+ isSignal: true,
895
+ isRequired: false,
896
+ transformFunction: null
897
+ },
898
+ applicationId: {
899
+ classPropertyName: "applicationId",
900
+ publicName: "applicationId",
901
+ isSignal: true,
902
+ isRequired: false,
903
+ transformFunction: null
904
+ },
905
+ locationId: {
906
+ classPropertyName: "locationId",
907
+ publicName: "locationId",
908
+ isSignal: true,
909
+ isRequired: false,
910
+ transformFunction: null
911
+ },
912
+ environment: {
913
+ classPropertyName: "environment",
914
+ publicName: "environment",
915
+ isSignal: true,
916
+ isRequired: false,
917
+ transformFunction: null
918
+ },
919
+ amount: {
920
+ classPropertyName: "amount",
921
+ publicName: "amount",
922
+ isSignal: true,
923
+ isRequired: false,
924
+ transformFunction: null
925
+ },
926
+ currency: {
927
+ classPropertyName: "currency",
928
+ publicName: "currency",
929
+ isSignal: true,
930
+ isRequired: false,
931
+ transformFunction: null
932
+ },
933
+ billingContact: {
934
+ classPropertyName: "billingContact",
935
+ publicName: "billingContact",
936
+ isSignal: true,
937
+ isRequired: false,
938
+ transformFunction: null
939
+ },
940
+ verifyBuyer: {
941
+ classPropertyName: "verifyBuyer",
942
+ publicName: "verifyBuyer",
943
+ isSignal: true,
944
+ isRequired: false,
945
+ transformFunction: null
946
+ },
947
+ accountHolderName: {
948
+ classPropertyName: "accountHolderName",
949
+ publicName: "accountHolderName",
950
+ isSignal: true,
951
+ isRequired: false,
952
+ transformFunction: null
953
+ },
954
+ requireAchConsent: {
955
+ classPropertyName: "requireAchConsent",
956
+ publicName: "requireAchConsent",
957
+ isSignal: true,
958
+ isRequired: false,
959
+ transformFunction: null
960
+ },
961
+ achConsentTextInput: {
962
+ classPropertyName: "achConsentTextInput",
963
+ publicName: "achConsentText",
964
+ isSignal: true,
965
+ isRequired: false,
966
+ transformFunction: null
967
+ },
968
+ achRedirectUri: {
969
+ classPropertyName: "achRedirectUri",
970
+ publicName: "achRedirectUri",
971
+ isSignal: true,
972
+ isRequired: false,
973
+ transformFunction: null
974
+ },
975
+ achTransactionId: {
976
+ classPropertyName: "achTransactionId",
977
+ publicName: "achTransactionId",
978
+ isSignal: true,
979
+ isRequired: false,
980
+ transformFunction: null
981
+ },
982
+ cardOptions: {
983
+ classPropertyName: "cardOptions",
984
+ publicName: "cardOptions",
985
+ isSignal: true,
986
+ isRequired: false,
987
+ transformFunction: null
988
+ },
989
+ cardStyle: {
990
+ classPropertyName: "cardStyle",
991
+ publicName: "cardStyle",
992
+ isSignal: true,
993
+ isRequired: false,
994
+ transformFunction: null
995
+ },
996
+ styleFromTokens: {
997
+ classPropertyName: "styleFromTokens",
998
+ publicName: "styleFromTokens",
999
+ isSignal: true,
1000
+ isRequired: false,
1001
+ transformFunction: null
1002
+ },
1003
+ showStatus: {
1004
+ classPropertyName: "showStatus",
1005
+ publicName: "showStatus",
1006
+ isSignal: true,
1007
+ isRequired: false,
1008
+ transformFunction: null
1009
+ },
1010
+ payableRef: {
1011
+ classPropertyName: "payableRef",
1012
+ publicName: "payableRef",
1013
+ isSignal: true,
1014
+ isRequired: false,
1015
+ transformFunction: null
1016
+ },
1017
+ attemptKey: {
1018
+ classPropertyName: "attemptKey",
1019
+ publicName: "attemptKey",
1020
+ isSignal: true,
1021
+ isRequired: false,
1022
+ transformFunction: null
1023
+ },
1024
+ checkStatus: {
1025
+ classPropertyName: "checkStatus",
1026
+ publicName: "checkStatus",
1027
+ isSignal: true,
1028
+ isRequired: false,
1029
+ transformFunction: null
1030
+ },
1031
+ paid: {
1032
+ classPropertyName: "paid",
1033
+ publicName: "paid",
1034
+ isSignal: true,
1035
+ isRequired: false,
1036
+ transformFunction: null
1037
+ },
1038
+ hostPending: {
1039
+ classPropertyName: "hostPending",
1040
+ publicName: "hostPending",
1041
+ isSignal: true,
1042
+ isRequired: false,
1043
+ transformFunction: null
1044
+ },
1045
+ statusPollMs: {
1046
+ classPropertyName: "statusPollMs",
1047
+ publicName: "statusPollMs",
1048
+ isSignal: true,
1049
+ isRequired: false,
1050
+ transformFunction: null
1051
+ },
1052
+ statusPollMaxMs: {
1053
+ classPropertyName: "statusPollMaxMs",
1054
+ publicName: "statusPollMaxMs",
1055
+ isSignal: true,
1056
+ isRequired: false,
1057
+ transformFunction: null
1058
+ },
1059
+ statusCheckTimeoutMs: {
1060
+ classPropertyName: "statusCheckTimeoutMs",
1061
+ publicName: "statusCheckTimeoutMs",
1062
+ isSignal: true,
1063
+ isRequired: false,
1064
+ transformFunction: null
1065
+ },
1066
+ statusFailGraceMs: {
1067
+ classPropertyName: "statusFailGraceMs",
1068
+ publicName: "statusFailGraceMs",
1069
+ isSignal: true,
1070
+ isRequired: false,
1071
+ transformFunction: null
1072
+ },
1073
+ allowStartOver: {
1074
+ classPropertyName: "allowStartOver",
1075
+ publicName: "allowStartOver",
1076
+ isSignal: true,
1077
+ isRequired: false,
1078
+ transformFunction: null
1079
+ },
1080
+ offlineOverride: {
1081
+ classPropertyName: "offlineOverride",
1082
+ publicName: "offlineOverride",
1083
+ isSignal: true,
1084
+ isRequired: false,
1085
+ transformFunction: null
1086
+ },
1087
+ hostSilenceMs: {
1088
+ classPropertyName: "hostSilenceMs",
1089
+ publicName: "hostSilenceMs",
1090
+ isSignal: true,
1091
+ isRequired: false,
1092
+ transformFunction: null
1093
+ },
1094
+ readinessCheck: {
1095
+ classPropertyName: "readinessCheck",
1096
+ publicName: "readinessCheck",
1097
+ isSignal: true,
1098
+ isRequired: false,
1099
+ transformFunction: null
1100
+ },
1101
+ readinessTimeoutMs: {
1102
+ classPropertyName: "readinessTimeoutMs",
1103
+ publicName: "readinessTimeoutMs",
1104
+ isSignal: true,
1105
+ isRequired: false,
1106
+ transformFunction: null
1107
+ },
1108
+ readinessEveryMs: {
1109
+ classPropertyName: "readinessEveryMs",
1110
+ publicName: "readinessEveryMs",
1111
+ isSignal: true,
1112
+ isRequired: false,
1113
+ transformFunction: null
1114
+ },
1115
+ submitLabel: {
1116
+ classPropertyName: "submitLabel",
1117
+ publicName: "submitLabel",
1118
+ isSignal: true,
1119
+ isRequired: false,
1120
+ transformFunction: null
1121
+ },
1122
+ showSubmit: {
1123
+ classPropertyName: "showSubmit",
1124
+ publicName: "showSubmit",
1125
+ isSignal: true,
1126
+ isRequired: false,
1127
+ transformFunction: null
1128
+ },
1129
+ disabled: {
1130
+ classPropertyName: "disabled",
1131
+ publicName: "disabled",
1132
+ isSignal: true,
1133
+ isRequired: false,
1134
+ transformFunction: null
1135
+ },
1136
+ pending: {
1137
+ classPropertyName: "pending",
1138
+ publicName: "pending",
1139
+ isSignal: true,
1140
+ isRequired: false,
1141
+ transformFunction: null
1142
+ },
1143
+ labelInput: {
1144
+ classPropertyName: "labelInput",
1145
+ publicName: "label",
1146
+ isSignal: true,
1147
+ isRequired: false,
1148
+ transformFunction: null
1149
+ },
1150
+ required: {
1151
+ classPropertyName: "required",
1152
+ publicName: "required",
1153
+ isSignal: true,
1154
+ isRequired: false,
1155
+ transformFunction: null
1156
+ },
1157
+ mountId: {
1158
+ classPropertyName: "mountId",
1159
+ publicName: "mountId",
1160
+ isSignal: true,
1161
+ isRequired: false,
1162
+ transformFunction: null
1163
+ },
1164
+ mountClass: {
1165
+ classPropertyName: "mountClass",
1166
+ publicName: "mountClass",
1167
+ isSignal: true,
1168
+ isRequired: false,
1169
+ transformFunction: null
1170
+ },
1171
+ mountTestId: {
1172
+ classPropertyName: "mountTestId",
1173
+ publicName: "mountTestId",
1174
+ isSignal: true,
1175
+ isRequired: false,
1176
+ transformFunction: null
1177
+ },
1178
+ errorTestId: {
1179
+ classPropertyName: "errorTestId",
1180
+ publicName: "errorTestId",
1181
+ isSignal: true,
1182
+ isRequired: false,
1183
+ transformFunction: null
1184
+ },
1185
+ holderTestId: {
1186
+ classPropertyName: "holderTestId",
1187
+ publicName: "holderTestId",
1188
+ isSignal: true,
1189
+ isRequired: false,
1190
+ transformFunction: null
1191
+ },
1192
+ showErrors: {
1193
+ classPropertyName: "showErrors",
1194
+ publicName: "showErrors",
1195
+ isSignal: true,
1196
+ isRequired: false,
1197
+ transformFunction: null
1198
+ },
1199
+ errorDisplay: {
1200
+ classPropertyName: "errorDisplay",
1201
+ publicName: "errorDisplay",
1202
+ isSignal: true,
1203
+ isRequired: false,
1204
+ transformFunction: null
1205
+ },
1206
+ errorMessages: {
1207
+ classPropertyName: "errorMessages",
1208
+ publicName: "errorMessages",
1209
+ isSignal: true,
1210
+ isRequired: false,
1211
+ transformFunction: null
1212
+ },
1213
+ errorFallback: {
1214
+ classPropertyName: "errorFallback",
1215
+ publicName: "errorFallback",
1216
+ isSignal: true,
1217
+ isRequired: false,
1218
+ transformFunction: null
1219
+ },
1220
+ loadErrorMessageInput: {
1221
+ classPropertyName: "loadErrorMessageInput",
1222
+ publicName: "loadErrorMessage",
1223
+ isSignal: true,
1224
+ isRequired: false,
1225
+ transformFunction: null
1226
+ },
1227
+ a11yMessages: {
1228
+ classPropertyName: "a11yMessages",
1229
+ publicName: "a11yMessages",
1230
+ isSignal: true,
1231
+ isRequired: false,
1232
+ transformFunction: null
1233
+ }
1234
+ },
1235
+ outputs: {
1236
+ method: "methodChange",
1237
+ squareReady: "squareReady",
1238
+ ready: "ready",
1239
+ inFlightChange: "inFlightChange",
1240
+ outcome: "outcome",
1241
+ attemptKeyChange: "attemptKeyChange",
1242
+ readinessChange: "readinessChange",
1243
+ tokenized: "tokenized",
1244
+ failed: "failed",
1245
+ loadError: "loadError"
1246
+ },
1247
+ host: { properties: { "attr.aria-busy": "!mountOnly() && (loading() || submitting()) ? \"true\" : null" } },
1248
+ viewQueries: [{
1249
+ propertyName: "mountRef",
1250
+ first: true,
1251
+ predicate: ["mount"],
1252
+ descendants: true,
1253
+ isSignal: true
1254
+ }],
1255
+ ngImport: i0,
1256
+ template: `
1257
+ <div class="sqp">
1258
+ @if (!mountOnly() || a11yMessages()) {
1259
+ <ui-live-region data-testid="square-status" [message]="statusText()" />
1260
+ }
1261
+ @if (!mountOnly() && tabs().length > 1) {
1262
+ <div class="sqp-block"><ui-pill-tabs [ariaLabel]="labels.t('squarePayment.method.group')" [tabs]="tabs()" [activeKey]="method()" (tabChange)="onTab($event)" /></div>
1263
+ }
1264
+ @if (!mountOnly() && showStatus()) {
1265
+ <ui-payment-attempt-status [attempt]="attempt" [readiness]="readiness" [allowStartOver]="allowStartOver()" (retryLoad)="retryLoad()" />
1266
+ }
1267
+ @if (!mountOnly() && (loading() || pending())) {
1268
+ <div class="sqp-skeleton" data-testid="square-skeleton" aria-hidden="true">
1269
+ <ui-skeleton [height]="44" [mb]="10" />
1270
+ <ui-skeleton [height]="44" width="60%" />
1271
+ </div>
1272
+ }
1273
+ @if (!mountOnly() && loadErrorText(); as text) {
1274
+ <div class="sqp-block" data-testid="square-load-error"><ui-alert variant="danger">{{ text }}</ui-alert></div>
1275
+ }
1276
+ @if (!mountOnly() && required()) {
1277
+ <div class="sqp-label" data-testid="square-required-label">{{ label() }}<span class="sqp-required" aria-hidden="true">*</span></div>
1278
+ }
1279
+ @if (method() === 'card') {
1280
+ <div #mount class="sqp-mount" [attr.id]="mountId() || null" [class]="mountClass()" [class.sqp-mount--hidden]="mountHidden()" [class.sqp-mount--locked]="mountLocked()"
1281
+ [attr.aria-hidden]="mountHidden() ? 'true' : null" [attr.aria-disabled]="mountLocked() ? 'true' : null" [attr.inert]="mountHidden() || mountLocked() ? '' : null"
1282
+ [attr.role]="mountOnly() ? null : 'group'" [attr.aria-label]="mountOnly() ? null : label()" [attr.data-testid]="mountTestId()"></div>
1283
+ } @else if (!mountOnly()) {
1284
+ <div class="sqp-ach" data-testid="square-ach">
1285
+ <ui-text data-testid="square-ach-info" size="sm" tone="muted" [text]="labels.t('squarePayment.achInfo')" />
1286
+ <ui-text-input [label]="labels.t('squarePayment.holderLabel')" [placeholder]="labels.t('squarePayment.holderPlaceholder')" [inputTestId]="holderTestId()" autocomplete="name"
1287
+ [required]="true" [maxlength]="255" [error]="holderError()" [showErrors]="attempted()" [disabled]="locked()"
1288
+ [ngModel]="holder()" (ngModelChange)="holder.set($event ?? '')" />
1289
+ @if (requireAchConsent()) {
1290
+ <ui-checkbox testId="square-consent" [label]="achConsent()" [required]="true" [requiredMessage]="labels.t('squarePayment.consentRequired')" [showErrors]="attempted()"
1291
+ [disabled]="locked()" [ngModel]="consent()" (ngModelChange)="consent.set(!!$event)" />
1292
+ }
1293
+ </div>
1294
+ }
1295
+ @if (!mountOnly() && errorText(); as text) {
1296
+ <div class="sqp-block" [id]="errorId" [attr.data-testid]="errorTestId()"><ui-alert variant="danger">{{ text }}</ui-alert></div>
1297
+ }
1298
+ @if (!mountOnly() && showSubmit()) {
1299
+ <div class="sqp-actions">
1300
+ <ui-button variant="primary" type="button" [fullWidth]="true" [loading]="submitting()" [disabled]="submitDisabled()" [ariaDescribedBy]="errorText() ? errorId : undefined"
1301
+ data-testid="square-submit" (click)="tokenize()">{{ effectiveSubmitLabel() }}</ui-button>
1302
+ </div>
1303
+ }
1304
+ </div>
1305
+ `,
1306
+ isInline: true,
1307
+ styles: ["ui-square-payment{display:block;min-width:0}ui-square-payment .sqp{position:relative}ui-square-payment .sqp-block{margin-top:12px}ui-square-payment .sqp-label{font-size:.875rem;font-weight:500;color:var(--ui-text, #1e293b);margin-bottom:6px}ui-square-payment .sqp-required{color:var(--ui-danger, #dc2626);margin-left:2px}ui-square-payment .sqp-mount{min-height:44px;margin-top:12px}ui-square-payment .sqp-ach{display:flex;flex-direction:column;gap:14px;margin-top:12px}ui-square-payment .sqp-actions{margin-top:16px;display:flex;flex-direction:column;align-items:stretch}ui-square-payment .sqp-mount--hidden{position:absolute;top:0;left:0;right:0;opacity:0;pointer-events:none}ui-square-payment .sqp-mount--locked{pointer-events:none;opacity:.6}\n"],
1308
+ dependencies: [
1309
+ {
1310
+ kind: "component",
1311
+ type: AlertComponent,
1312
+ selector: "ui-alert",
1313
+ inputs: [
1314
+ "variant",
1315
+ "title",
1316
+ "dismissible",
1317
+ "dismissAriaLabel",
1318
+ "quiet",
1319
+ "compact",
1320
+ "inline",
1321
+ "fill"
1322
+ ],
1323
+ outputs: ["dismissed"]
1324
+ },
1325
+ {
1326
+ kind: "component",
1327
+ type: ButtonComponent,
1328
+ selector: "ui-button",
1329
+ inputs: [
1330
+ "variant",
1331
+ "routerLink",
1332
+ "queryParams",
1333
+ "fragment",
1334
+ "state",
1335
+ "href",
1336
+ "target",
1337
+ "rel",
1338
+ "shortLabel",
1339
+ "shortBelow",
1340
+ "color",
1341
+ "active",
1342
+ "size",
1343
+ "type",
1344
+ "disabled",
1345
+ "loading",
1346
+ "fullWidth",
1347
+ "ariaLabel",
1348
+ "ariaExpanded",
1349
+ "ariaPressed",
1350
+ "ariaDescribedBy",
1351
+ "modal-footer-left",
1352
+ "modal-footer-right"
1353
+ ]
1354
+ },
1355
+ {
1356
+ kind: "component",
1357
+ type: CheckboxComponent,
1358
+ selector: "ui-checkbox, ui-checkbox-group",
1359
+ inputs: [
1360
+ "label",
1361
+ "ariaLabel",
1362
+ "testId",
1363
+ "labelTestId",
1364
+ "headingLevel",
1365
+ "indeterminate",
1366
+ "checked",
1367
+ "options",
1368
+ "legend",
1369
+ "orientation",
1370
+ "values",
1371
+ "labelLinks",
1372
+ "description",
1373
+ "indent",
1374
+ "required",
1375
+ "requiredMessage",
1376
+ "hint",
1377
+ "error",
1378
+ "showErrors",
1379
+ "disabled"
1380
+ ],
1381
+ outputs: [
1382
+ "checkedChange",
1383
+ "valuesChange",
1384
+ "invalidChange"
1385
+ ]
1386
+ },
1387
+ {
1388
+ kind: "ngmodule",
1389
+ type: FormsModule
1390
+ },
1391
+ {
1392
+ kind: "directive",
1393
+ type: i1.NgControlStatus,
1394
+ selector: "[formControlName],[ngModel],[formControl]"
1395
+ },
1396
+ {
1397
+ kind: "directive",
1398
+ type: i1.RequiredValidator,
1399
+ selector: ":not([type=checkbox])[required][formControlName],:not([type=checkbox])[required][formControl],:not([type=checkbox])[required][ngModel]",
1400
+ inputs: ["required"]
1401
+ },
1402
+ {
1403
+ kind: "directive",
1404
+ type: i1.MaxLengthValidator,
1405
+ selector: "[maxlength][formControlName],[maxlength][formControl],[maxlength][ngModel]",
1406
+ inputs: ["maxlength"]
1407
+ },
1408
+ {
1409
+ kind: "directive",
1410
+ type: i1.NgModel,
1411
+ selector: "[ngModel]:not([formControlName]):not([formControl])",
1412
+ inputs: [
1413
+ "name",
1414
+ "disabled",
1415
+ "ngModel",
1416
+ "ngModelOptions"
1417
+ ],
1418
+ outputs: ["ngModelChange"],
1419
+ exportAs: ["ngModel"]
1420
+ },
1421
+ {
1422
+ kind: "component",
1423
+ type: LiveRegionComponent,
1424
+ selector: "ui-live-region",
1425
+ inputs: [
1426
+ "message",
1427
+ "politeness",
1428
+ "atomic",
1429
+ "visible"
1430
+ ]
1431
+ },
1432
+ {
1433
+ kind: "component",
1434
+ type: PaymentAttemptStatusComponent,
1435
+ selector: "ui-payment-attempt-status",
1436
+ inputs: [
1437
+ "attempt",
1438
+ "showPaid",
1439
+ "allowStartOver",
1440
+ "readiness"
1441
+ ],
1442
+ outputs: ["retryLoad"]
1443
+ },
1444
+ {
1445
+ kind: "component",
1446
+ type: PillTabsComponent,
1447
+ selector: "ui-pill-tabs",
1448
+ inputs: [
1449
+ "tabs",
1450
+ "activeKey",
1451
+ "ariaLabel",
1452
+ "name",
1453
+ "noWrap",
1454
+ "orientation",
1455
+ "controlsPanels",
1456
+ "showDescription",
1457
+ "headingLevel"
1458
+ ],
1459
+ outputs: ["tabChange"]
1460
+ },
1461
+ {
1462
+ kind: "component",
1463
+ type: SkeletonComponent,
1464
+ selector: "ui-skeleton",
1465
+ inputs: [
1466
+ "height",
1467
+ "width",
1468
+ "radius",
1469
+ "mb",
1470
+ "ariaLabel"
1471
+ ]
1472
+ },
1473
+ {
1474
+ kind: "component",
1475
+ type: TextComponent,
1476
+ selector: "ui-text",
1477
+ inputs: [
1478
+ "text",
1479
+ "size",
1480
+ "tone",
1481
+ "color",
1482
+ "strong",
1483
+ "weight"
1484
+ ]
1485
+ },
1486
+ {
1487
+ kind: "component",
1488
+ type: TextInputComponent,
1489
+ selector: "ui-text-input",
1490
+ inputs: [
1491
+ "label",
1492
+ "ariaLabel",
1493
+ "inputTestId",
1494
+ "inputName",
1495
+ "placeholder",
1496
+ "prefix",
1497
+ "leadingIcon",
1498
+ "revealable",
1499
+ "passwordRequirements",
1500
+ "passwordRules",
1501
+ "type",
1502
+ "maxlength",
1503
+ "required",
1504
+ "autocomplete",
1505
+ "inputmode",
1506
+ "readonly",
1507
+ "hint",
1508
+ "ariaDescribedBy",
1509
+ "error",
1510
+ "phoneFormat",
1511
+ "min",
1512
+ "max",
1513
+ "maxDecimals",
1514
+ "step",
1515
+ "valueType",
1516
+ "formatter",
1517
+ "integer",
1518
+ "showErrors",
1519
+ "disabled"
1520
+ ],
1521
+ outputs: [
1522
+ "valueChange",
1523
+ "focused",
1524
+ "blurred",
1525
+ "invalidChange"
1526
+ ]
1527
+ }
1528
+ ],
1529
+ changeDetection: i0.ChangeDetectionStrategy.OnPush,
1530
+ encapsulation: i0.ViewEncapsulation.None
1531
+ });
1532
+ }
1533
+ };
1534
+ i0.ɵɵngDeclareClassMetadata({
1535
+ minVersion: "12.0.0",
1536
+ version: "22.2.2",
1537
+ ngImport: i0,
1538
+ type: SquarePaymentComponent,
1539
+ decorators: [{
1540
+ type: Component,
1541
+ args: [{
1542
+ selector: "ui-square-payment",
1543
+ standalone: true,
1544
+ changeDetection: ChangeDetectionStrategy.OnPush,
1545
+ encapsulation: ViewEncapsulation.None,
1546
+ imports: [
1547
+ AlertComponent,
1548
+ ButtonComponent,
1549
+ CheckboxComponent,
1550
+ FormsModule,
1551
+ LiveRegionComponent,
1552
+ PaymentAttemptStatusComponent,
1553
+ PillTabsComponent,
1554
+ SkeletonComponent,
1555
+ TextComponent,
1556
+ TextInputComponent
1557
+ ],
1558
+ host: { "[attr.aria-busy]": "!mountOnly() && (loading() || submitting()) ? \"true\" : null" },
1559
+ template: `
1560
+ <div class="sqp">
1561
+ @if (!mountOnly() || a11yMessages()) {
1562
+ <ui-live-region data-testid="square-status" [message]="statusText()" />
1563
+ }
1564
+ @if (!mountOnly() && tabs().length > 1) {
1565
+ <div class="sqp-block"><ui-pill-tabs [ariaLabel]="labels.t('squarePayment.method.group')" [tabs]="tabs()" [activeKey]="method()" (tabChange)="onTab($event)" /></div>
1566
+ }
1567
+ @if (!mountOnly() && showStatus()) {
1568
+ <ui-payment-attempt-status [attempt]="attempt" [readiness]="readiness" [allowStartOver]="allowStartOver()" (retryLoad)="retryLoad()" />
1569
+ }
1570
+ @if (!mountOnly() && (loading() || pending())) {
1571
+ <div class="sqp-skeleton" data-testid="square-skeleton" aria-hidden="true">
1572
+ <ui-skeleton [height]="44" [mb]="10" />
1573
+ <ui-skeleton [height]="44" width="60%" />
1574
+ </div>
1575
+ }
1576
+ @if (!mountOnly() && loadErrorText(); as text) {
1577
+ <div class="sqp-block" data-testid="square-load-error"><ui-alert variant="danger">{{ text }}</ui-alert></div>
1578
+ }
1579
+ @if (!mountOnly() && required()) {
1580
+ <div class="sqp-label" data-testid="square-required-label">{{ label() }}<span class="sqp-required" aria-hidden="true">*</span></div>
1581
+ }
1582
+ @if (method() === 'card') {
1583
+ <div #mount class="sqp-mount" [attr.id]="mountId() || null" [class]="mountClass()" [class.sqp-mount--hidden]="mountHidden()" [class.sqp-mount--locked]="mountLocked()"
1584
+ [attr.aria-hidden]="mountHidden() ? 'true' : null" [attr.aria-disabled]="mountLocked() ? 'true' : null" [attr.inert]="mountHidden() || mountLocked() ? '' : null"
1585
+ [attr.role]="mountOnly() ? null : 'group'" [attr.aria-label]="mountOnly() ? null : label()" [attr.data-testid]="mountTestId()"></div>
1586
+ } @else if (!mountOnly()) {
1587
+ <div class="sqp-ach" data-testid="square-ach">
1588
+ <ui-text data-testid="square-ach-info" size="sm" tone="muted" [text]="labels.t('squarePayment.achInfo')" />
1589
+ <ui-text-input [label]="labels.t('squarePayment.holderLabel')" [placeholder]="labels.t('squarePayment.holderPlaceholder')" [inputTestId]="holderTestId()" autocomplete="name"
1590
+ [required]="true" [maxlength]="255" [error]="holderError()" [showErrors]="attempted()" [disabled]="locked()"
1591
+ [ngModel]="holder()" (ngModelChange)="holder.set($event ?? '')" />
1592
+ @if (requireAchConsent()) {
1593
+ <ui-checkbox testId="square-consent" [label]="achConsent()" [required]="true" [requiredMessage]="labels.t('squarePayment.consentRequired')" [showErrors]="attempted()"
1594
+ [disabled]="locked()" [ngModel]="consent()" (ngModelChange)="consent.set(!!$event)" />
1595
+ }
1596
+ </div>
1597
+ }
1598
+ @if (!mountOnly() && errorText(); as text) {
1599
+ <div class="sqp-block" [id]="errorId" [attr.data-testid]="errorTestId()"><ui-alert variant="danger">{{ text }}</ui-alert></div>
1600
+ }
1601
+ @if (!mountOnly() && showSubmit()) {
1602
+ <div class="sqp-actions">
1603
+ <ui-button variant="primary" type="button" [fullWidth]="true" [loading]="submitting()" [disabled]="submitDisabled()" [ariaDescribedBy]="errorText() ? errorId : undefined"
1604
+ data-testid="square-submit" (click)="tokenize()">{{ effectiveSubmitLabel() }}</ui-button>
1605
+ </div>
1606
+ }
1607
+ </div>
1608
+ `,
1609
+ styles: ["ui-square-payment{display:block;min-width:0}ui-square-payment .sqp{position:relative}ui-square-payment .sqp-block{margin-top:12px}ui-square-payment .sqp-label{font-size:.875rem;font-weight:500;color:var(--ui-text, #1e293b);margin-bottom:6px}ui-square-payment .sqp-required{color:var(--ui-danger, #dc2626);margin-left:2px}ui-square-payment .sqp-mount{min-height:44px;margin-top:12px}ui-square-payment .sqp-ach{display:flex;flex-direction:column;gap:14px;margin-top:12px}ui-square-payment .sqp-actions{margin-top:16px;display:flex;flex-direction:column;align-items:stretch}ui-square-payment .sqp-mount--hidden{position:absolute;top:0;left:0;right:0;opacity:0;pointer-events:none}ui-square-payment .sqp-mount--locked{pointer-events:none;opacity:.6}\n"]
1610
+ }]
1611
+ }],
1612
+ ctorParameters: () => [],
1613
+ propDecorators: {
1614
+ mountOnly: [{
1615
+ type: i0.Input,
1616
+ args: [{
1617
+ isSignal: true,
1618
+ alias: "mountOnly",
1619
+ required: false
1620
+ }]
1621
+ }],
1622
+ mode: [{
1623
+ type: i0.Input,
1624
+ args: [{
1625
+ isSignal: true,
1626
+ alias: "mode",
1627
+ required: false
1628
+ }]
1629
+ }],
1630
+ method: [{
1631
+ type: i0.Input,
1632
+ args: [{
1633
+ isSignal: true,
1634
+ alias: "method",
1635
+ required: false
1636
+ }]
1637
+ }, {
1638
+ type: i0.Output,
1639
+ args: ["methodChange"]
1640
+ }],
1641
+ methods: [{
1642
+ type: i0.Input,
1643
+ args: [{
1644
+ isSignal: true,
1645
+ alias: "methods",
1646
+ required: false
1647
+ }]
1648
+ }],
1649
+ applicationId: [{
1650
+ type: i0.Input,
1651
+ args: [{
1652
+ isSignal: true,
1653
+ alias: "applicationId",
1654
+ required: false
1655
+ }]
1656
+ }],
1657
+ locationId: [{
1658
+ type: i0.Input,
1659
+ args: [{
1660
+ isSignal: true,
1661
+ alias: "locationId",
1662
+ required: false
1663
+ }]
1664
+ }],
1665
+ environment: [{
1666
+ type: i0.Input,
1667
+ args: [{
1668
+ isSignal: true,
1669
+ alias: "environment",
1670
+ required: false
1671
+ }]
1672
+ }],
1673
+ amount: [{
1674
+ type: i0.Input,
1675
+ args: [{
1676
+ isSignal: true,
1677
+ alias: "amount",
1678
+ required: false
1679
+ }]
1680
+ }],
1681
+ currency: [{
1682
+ type: i0.Input,
1683
+ args: [{
1684
+ isSignal: true,
1685
+ alias: "currency",
1686
+ required: false
1687
+ }]
1688
+ }],
1689
+ billingContact: [{
1690
+ type: i0.Input,
1691
+ args: [{
1692
+ isSignal: true,
1693
+ alias: "billingContact",
1694
+ required: false
1695
+ }]
1696
+ }],
1697
+ verifyBuyer: [{
1698
+ type: i0.Input,
1699
+ args: [{
1700
+ isSignal: true,
1701
+ alias: "verifyBuyer",
1702
+ required: false
1703
+ }]
1704
+ }],
1705
+ accountHolderName: [{
1706
+ type: i0.Input,
1707
+ args: [{
1708
+ isSignal: true,
1709
+ alias: "accountHolderName",
1710
+ required: false
1711
+ }]
1712
+ }],
1713
+ requireAchConsent: [{
1714
+ type: i0.Input,
1715
+ args: [{
1716
+ isSignal: true,
1717
+ alias: "requireAchConsent",
1718
+ required: false
1719
+ }]
1720
+ }],
1721
+ achConsentTextInput: [{
1722
+ type: i0.Input,
1723
+ args: [{
1724
+ isSignal: true,
1725
+ alias: "achConsentText",
1726
+ required: false
1727
+ }]
1728
+ }],
1729
+ achRedirectUri: [{
1730
+ type: i0.Input,
1731
+ args: [{
1732
+ isSignal: true,
1733
+ alias: "achRedirectUri",
1734
+ required: false
1735
+ }]
1736
+ }],
1737
+ achTransactionId: [{
1738
+ type: i0.Input,
1739
+ args: [{
1740
+ isSignal: true,
1741
+ alias: "achTransactionId",
1742
+ required: false
1743
+ }]
1744
+ }],
1745
+ cardOptions: [{
1746
+ type: i0.Input,
1747
+ args: [{
1748
+ isSignal: true,
1749
+ alias: "cardOptions",
1750
+ required: false
1751
+ }]
1752
+ }],
1753
+ cardStyle: [{
1754
+ type: i0.Input,
1755
+ args: [{
1756
+ isSignal: true,
1757
+ alias: "cardStyle",
1758
+ required: false
1759
+ }]
1760
+ }],
1761
+ styleFromTokens: [{
1762
+ type: i0.Input,
1763
+ args: [{
1764
+ isSignal: true,
1765
+ alias: "styleFromTokens",
1766
+ required: false
1767
+ }]
1768
+ }],
1769
+ showStatus: [{
1770
+ type: i0.Input,
1771
+ args: [{
1772
+ isSignal: true,
1773
+ alias: "showStatus",
1774
+ required: false
1775
+ }]
1776
+ }],
1777
+ payableRef: [{
1778
+ type: i0.Input,
1779
+ args: [{
1780
+ isSignal: true,
1781
+ alias: "payableRef",
1782
+ required: false
1783
+ }]
1784
+ }],
1785
+ attemptKey: [{
1786
+ type: i0.Input,
1787
+ args: [{
1788
+ isSignal: true,
1789
+ alias: "attemptKey",
1790
+ required: false
1791
+ }]
1792
+ }],
1793
+ checkStatus: [{
1794
+ type: i0.Input,
1795
+ args: [{
1796
+ isSignal: true,
1797
+ alias: "checkStatus",
1798
+ required: false
1799
+ }]
1800
+ }],
1801
+ paid: [{
1802
+ type: i0.Input,
1803
+ args: [{
1804
+ isSignal: true,
1805
+ alias: "paid",
1806
+ required: false
1807
+ }]
1808
+ }],
1809
+ hostPending: [{
1810
+ type: i0.Input,
1811
+ args: [{
1812
+ isSignal: true,
1813
+ alias: "hostPending",
1814
+ required: false
1815
+ }]
1816
+ }],
1817
+ statusPollMs: [{
1818
+ type: i0.Input,
1819
+ args: [{
1820
+ isSignal: true,
1821
+ alias: "statusPollMs",
1822
+ required: false
1823
+ }]
1824
+ }],
1825
+ statusPollMaxMs: [{
1826
+ type: i0.Input,
1827
+ args: [{
1828
+ isSignal: true,
1829
+ alias: "statusPollMaxMs",
1830
+ required: false
1831
+ }]
1832
+ }],
1833
+ statusCheckTimeoutMs: [{
1834
+ type: i0.Input,
1835
+ args: [{
1836
+ isSignal: true,
1837
+ alias: "statusCheckTimeoutMs",
1838
+ required: false
1839
+ }]
1840
+ }],
1841
+ statusFailGraceMs: [{
1842
+ type: i0.Input,
1843
+ args: [{
1844
+ isSignal: true,
1845
+ alias: "statusFailGraceMs",
1846
+ required: false
1847
+ }]
1848
+ }],
1849
+ allowStartOver: [{
1850
+ type: i0.Input,
1851
+ args: [{
1852
+ isSignal: true,
1853
+ alias: "allowStartOver",
1854
+ required: false
1855
+ }]
1856
+ }],
1857
+ offlineOverride: [{
1858
+ type: i0.Input,
1859
+ args: [{
1860
+ isSignal: true,
1861
+ alias: "offlineOverride",
1862
+ required: false
1863
+ }]
1864
+ }],
1865
+ hostSilenceMs: [{
1866
+ type: i0.Input,
1867
+ args: [{
1868
+ isSignal: true,
1869
+ alias: "hostSilenceMs",
1870
+ required: false
1871
+ }]
1872
+ }],
1873
+ readinessCheck: [{
1874
+ type: i0.Input,
1875
+ args: [{
1876
+ isSignal: true,
1877
+ alias: "readinessCheck",
1878
+ required: false
1879
+ }]
1880
+ }],
1881
+ readinessTimeoutMs: [{
1882
+ type: i0.Input,
1883
+ args: [{
1884
+ isSignal: true,
1885
+ alias: "readinessTimeoutMs",
1886
+ required: false
1887
+ }]
1888
+ }],
1889
+ readinessEveryMs: [{
1890
+ type: i0.Input,
1891
+ args: [{
1892
+ isSignal: true,
1893
+ alias: "readinessEveryMs",
1894
+ required: false
1895
+ }]
1896
+ }],
1897
+ submitLabel: [{
1898
+ type: i0.Input,
1899
+ args: [{
1900
+ isSignal: true,
1901
+ alias: "submitLabel",
1902
+ required: false
1903
+ }]
1904
+ }],
1905
+ showSubmit: [{
1906
+ type: i0.Input,
1907
+ args: [{
1908
+ isSignal: true,
1909
+ alias: "showSubmit",
1910
+ required: false
1911
+ }]
1912
+ }],
1913
+ disabled: [{
1914
+ type: i0.Input,
1915
+ args: [{
1916
+ isSignal: true,
1917
+ alias: "disabled",
1918
+ required: false
1919
+ }]
1920
+ }],
1921
+ pending: [{
1922
+ type: i0.Input,
1923
+ args: [{
1924
+ isSignal: true,
1925
+ alias: "pending",
1926
+ required: false
1927
+ }]
1928
+ }],
1929
+ labelInput: [{
1930
+ type: i0.Input,
1931
+ args: [{
1932
+ isSignal: true,
1933
+ alias: "label",
1934
+ required: false
1935
+ }]
1936
+ }],
1937
+ required: [{
1938
+ type: i0.Input,
1939
+ args: [{
1940
+ isSignal: true,
1941
+ alias: "required",
1942
+ required: false
1943
+ }]
1944
+ }],
1945
+ mountId: [{
1946
+ type: i0.Input,
1947
+ args: [{
1948
+ isSignal: true,
1949
+ alias: "mountId",
1950
+ required: false
1951
+ }]
1952
+ }],
1953
+ mountClass: [{
1954
+ type: i0.Input,
1955
+ args: [{
1956
+ isSignal: true,
1957
+ alias: "mountClass",
1958
+ required: false
1959
+ }]
1960
+ }],
1961
+ mountTestId: [{
1962
+ type: i0.Input,
1963
+ args: [{
1964
+ isSignal: true,
1965
+ alias: "mountTestId",
1966
+ required: false
1967
+ }]
1968
+ }],
1969
+ errorTestId: [{
1970
+ type: i0.Input,
1971
+ args: [{
1972
+ isSignal: true,
1973
+ alias: "errorTestId",
1974
+ required: false
1975
+ }]
1976
+ }],
1977
+ holderTestId: [{
1978
+ type: i0.Input,
1979
+ args: [{
1980
+ isSignal: true,
1981
+ alias: "holderTestId",
1982
+ required: false
1983
+ }]
1984
+ }],
1985
+ showErrors: [{
1986
+ type: i0.Input,
1987
+ args: [{
1988
+ isSignal: true,
1989
+ alias: "showErrors",
1990
+ required: false
1991
+ }]
1992
+ }],
1993
+ errorDisplay: [{
1994
+ type: i0.Input,
1995
+ args: [{
1996
+ isSignal: true,
1997
+ alias: "errorDisplay",
1998
+ required: false
1999
+ }]
2000
+ }],
2001
+ errorMessages: [{
2002
+ type: i0.Input,
2003
+ args: [{
2004
+ isSignal: true,
2005
+ alias: "errorMessages",
2006
+ required: false
2007
+ }]
2008
+ }],
2009
+ errorFallback: [{
2010
+ type: i0.Input,
2011
+ args: [{
2012
+ isSignal: true,
2013
+ alias: "errorFallback",
2014
+ required: false
2015
+ }]
2016
+ }],
2017
+ loadErrorMessageInput: [{
2018
+ type: i0.Input,
2019
+ args: [{
2020
+ isSignal: true,
2021
+ alias: "loadErrorMessage",
2022
+ required: false
2023
+ }]
2024
+ }],
2025
+ a11yMessages: [{
2026
+ type: i0.Input,
2027
+ args: [{
2028
+ isSignal: true,
2029
+ alias: "a11yMessages",
2030
+ required: false
2031
+ }]
2032
+ }],
2033
+ squareReady: [{
2034
+ type: i0.Output,
2035
+ args: ["squareReady"]
2036
+ }],
2037
+ ready: [{
2038
+ type: i0.Output,
2039
+ args: ["ready"]
2040
+ }],
2041
+ inFlightChange: [{
2042
+ type: i0.Output,
2043
+ args: ["inFlightChange"]
2044
+ }],
2045
+ outcome: [{
2046
+ type: i0.Output,
2047
+ args: ["outcome"]
2048
+ }],
2049
+ attemptKeyChange: [{
2050
+ type: i0.Output,
2051
+ args: ["attemptKeyChange"]
2052
+ }],
2053
+ readinessChange: [{
2054
+ type: i0.Output,
2055
+ args: ["readinessChange"]
2056
+ }],
2057
+ tokenized: [{
2058
+ type: i0.Output,
2059
+ args: ["tokenized"]
2060
+ }],
2061
+ failed: [{
2062
+ type: i0.Output,
2063
+ args: ["failed"]
2064
+ }],
2065
+ loadError: [{
2066
+ type: i0.Output,
2067
+ args: ["loadError"]
2068
+ }],
2069
+ mountRef: [{
2070
+ type: i0.ViewChild,
2071
+ args: ["mount", { isSignal: true }]
2072
+ }]
2073
+ }
2074
+ });
2075
+ function isSquareUrl(url) {
2076
+ if (!url) return false;
2077
+ try {
2078
+ const u = new URL(url);
2079
+ return u.protocol === "https:" && [
2080
+ "squareup.com",
2081
+ "squareupsandbox.com",
2082
+ "square.com"
2083
+ ].some((d) => u.hostname === d || u.hostname.endsWith(`.${d}`));
2084
+ } catch {
2085
+ return false;
2086
+ }
2087
+ }
2088
+ var SquareConnectFlow = class {
2089
+ constructor(o) {
2090
+ this.o = o;
2091
+ this.tabOpened = false;
2092
+ }
2093
+ get blocked() {
2094
+ return this.o.state.loading() || !!this.o.disabled?.();
2095
+ }
2096
+ startConnect() {
2097
+ const start = this.o.start();
2098
+ if (!start || this.blocked) return;
2099
+ this.o.state.loading.set(true);
2100
+ const tab = this.openBlankTab();
2101
+ start().pipe(takeUntilDestroyed(this.o.destroyRef)).subscribe({
2102
+ next: (result) => {
2103
+ this.o.state.loading.set(false);
2104
+ this.openSquare(tab, result?.authUrl ?? result?.url);
2105
+ },
2106
+ error: (error) => {
2107
+ this.closeTab(tab);
2108
+ this.o.state.loading.set(false);
2109
+ this.o.emit({
2110
+ kind: "failed",
2111
+ action: "start",
2112
+ error
2113
+ });
2114
+ }
2115
+ });
2116
+ }
2117
+ check() {
2118
+ const status = this.o.getStatus();
2119
+ if (!status || this.blocked) return;
2120
+ this.o.state.loading.set(true);
2121
+ status().pipe(takeUntilDestroyed(this.o.destroyRef)).subscribe({
2122
+ next: (s) => {
2123
+ this.o.state.status.set(s);
2124
+ this.o.state.loading.set(false);
2125
+ if (s.connected && s.needsReconnect) this.o.emit({
2126
+ kind: "needs-reconnect",
2127
+ source: "check"
2128
+ });
2129
+ else if (s.connected) this.o.emit({
2130
+ kind: "connected",
2131
+ source: "check"
2132
+ });
2133
+ else this.o.emit({ kind: "not-connected" });
2134
+ },
2135
+ error: (error) => {
2136
+ this.o.state.loading.set(false);
2137
+ this.o.emit({
2138
+ kind: "failed",
2139
+ action: "check",
2140
+ error
2141
+ });
2142
+ }
2143
+ });
2144
+ }
2145
+ disconnect() {
2146
+ const disconnect = this.o.disconnect();
2147
+ if (!disconnect || this.blocked) return;
2148
+ this.o.state.loading.set(true);
2149
+ disconnect().pipe(takeUntilDestroyed(this.o.destroyRef)).subscribe({
2150
+ next: () => {
2151
+ this.o.state.status.set({ connected: false });
2152
+ this.o.state.loading.set(false);
2153
+ this.o.emit({ kind: "disconnected" });
2154
+ },
2155
+ error: (error) => {
2156
+ this.o.state.loading.set(false);
2157
+ this.o.emit({
2158
+ kind: "failed",
2159
+ action: "disconnect",
2160
+ error
2161
+ });
2162
+ }
2163
+ });
2164
+ }
2165
+ readStatusOnReturn() {
2166
+ const status = this.o.getStatus();
2167
+ if (!status) return;
2168
+ status().pipe(takeUntilDestroyed(this.o.destroyRef)).subscribe({
2169
+ next: (s) => {
2170
+ this.o.state.status.set(s);
2171
+ if (s.connected && s.needsReconnect) this.o.emit({
2172
+ kind: "needs-reconnect",
2173
+ source: "return"
2174
+ });
2175
+ else if (s.connected) this.o.emit({
2176
+ kind: "connected",
2177
+ source: "return"
2178
+ });
2179
+ },
2180
+ error: () => {}
2181
+ });
2182
+ }
2183
+ openSquare(tab, url) {
2184
+ if (isSquareUrl(url) && tab && !tab.closed) {
2185
+ tab.location.href = url;
2186
+ this.tabOpened = true;
2187
+ this.o.onOpened?.();
2188
+ } else if (isSquareUrl(url)) this.navigateCurrentTab(url);
2189
+ else {
2190
+ this.closeTab(tab);
2191
+ this.o.emit({ kind: "link-unavailable" });
2192
+ }
2193
+ }
2194
+ openBlankTab() {
2195
+ const tab = window.open("about:blank", "_blank");
2196
+ if (tab) try {
2197
+ tab.opener = null;
2198
+ } catch {}
2199
+ return tab;
2200
+ }
2201
+ navigateCurrentTab(url) {
2202
+ if (this.o.navigate) this.o.navigate(url);
2203
+ else window.location.href = url;
2204
+ }
2205
+ closeTab(tab) {
2206
+ try {
2207
+ tab?.close();
2208
+ } catch {}
2209
+ }
2210
+ };
2211
+ function squareConnectNotice(outcome) {
2212
+ switch (outcome.kind) {
2213
+ case "connected": return {
2214
+ variant: "success",
2215
+ message: uiText("squareConnect.noticeConnected")
2216
+ };
2217
+ case "needs-reconnect": return {
2218
+ variant: "error",
2219
+ message: uiText("squareConnect.noticeReconnect")
2220
+ };
2221
+ case "not-connected": return {
2222
+ variant: "info",
2223
+ message: uiText("squareConnect.noticeNotConnected")
2224
+ };
2225
+ case "disconnected": return {
2226
+ variant: "success",
2227
+ message: uiText("squareConnect.noticeDisconnected")
2228
+ };
2229
+ case "link-unavailable": return {
2230
+ variant: "error",
2231
+ message: uiText("squareConnect.noticeLinkUnavailable")
2232
+ };
2233
+ case "failed": return {
2234
+ variant: "error",
2235
+ message: uiText(outcome.action === "start" ? "squareConnect.failedStart" : outcome.action === "check" ? "squareConnect.failedCheck" : "squareConnect.failedDisconnect")
2236
+ };
2237
+ }
2238
+ }
2239
+ let nextConnectId = 0;
2240
+ var SquareConnectComponent = class SquareConnectComponent {
2241
+ constructor() {
2242
+ this.confirmMessageId = `sqc-disconnect-msg-${nextConnectId++}`;
2243
+ this.labels = inject(UiLabelsService);
2244
+ this.destroyRef = inject(DestroyRef);
2245
+ this.injector = inject(Injector);
2246
+ this.host = inject(ElementRef);
2247
+ this.startConnect = input(null, ...ngDevMode ? [{ debugName: "startConnect" }] : /* istanbul ignore next */ []);
2248
+ this.getStatus = input(null, ...ngDevMode ? [{ debugName: "getStatus" }] : /* istanbul ignore next */ []);
2249
+ this.disconnect = input(null, ...ngDevMode ? [{ debugName: "disconnect" }] : /* istanbul ignore next */ []);
2250
+ this.status = model(null, ...ngDevMode ? [{ debugName: "status" }] : /* istanbul ignore next */ []);
2251
+ this.titleInput = input(null, {
2252
+ ...ngDevMode ? { debugName: "titleInput" } : /* istanbul ignore next */ {},
2253
+ alias: "title"
2254
+ });
2255
+ this.title = computed(() => this.titleInput() ?? this.labels.t("squareConnect.title"), ...ngDevMode ? [{ debugName: "title" }] : /* istanbul ignore next */ []);
2256
+ this.bare = input(false, ...ngDevMode ? [{ debugName: "bare" }] : /* istanbul ignore next */ []);
2257
+ this.startTitleInput = input(null, {
2258
+ ...ngDevMode ? { debugName: "startTitleInput" } : /* istanbul ignore next */ {},
2259
+ alias: "startTitle"
2260
+ });
2261
+ this.startTitle = computed(() => this.startTitleInput() ?? this.labels.t("squareConnect.startTitle"), ...ngDevMode ? [{ debugName: "startTitle" }] : /* istanbul ignore next */ []);
2262
+ this.startTextInput = input(null, {
2263
+ ...ngDevMode ? { debugName: "startTextInput" } : /* istanbul ignore next */ {},
2264
+ alias: "startText"
2265
+ });
2266
+ this.startText = computed(() => this.startTextInput() ?? this.labels.t("squareConnect.startText"), ...ngDevMode ? [{ debugName: "startText" }] : /* istanbul ignore next */ []);
2267
+ this.startLabelInput = input(null, {
2268
+ ...ngDevMode ? { debugName: "startLabelInput" } : /* istanbul ignore next */ {},
2269
+ alias: "startLabel"
2270
+ });
2271
+ this.startLabel = computed(() => this.startLabelInput() ?? this.labels.t("squareConnect.startLabel"), ...ngDevMode ? [{ debugName: "startLabel" }] : /* istanbul ignore next */ []);
2272
+ this.disabled = input(false, ...ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []);
2273
+ this.confirmDisconnect = input(true, ...ngDevMode ? [{ debugName: "confirmDisconnect" }] : /* istanbul ignore next */ []);
2274
+ this.refreshOnReturn = input(false, ...ngDevMode ? [{ debugName: "refreshOnReturn" }] : /* istanbul ignore next */ []);
2275
+ this.navigateTab = input(null, ...ngDevMode ? [{ debugName: "navigateTab" }] : /* istanbul ignore next */ []);
2276
+ this.outcome = output();
2277
+ this.loading = model(false, ...ngDevMode ? [{ debugName: "loading" }] : /* istanbul ignore next */ []);
2278
+ this.awaiting = signal(false, ...ngDevMode ? [{ debugName: "awaiting" }] : /* istanbul ignore next */ []);
2279
+ this.confirming = signal(false, ...ngDevMode ? [{ debugName: "confirming" }] : /* istanbul ignore next */ []);
2280
+ this.state = computed(() => {
2281
+ const s = this.status();
2282
+ return !s?.connected ? "none" : s.needsReconnect ? "reconnect" : "connected";
2283
+ }, ...ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []);
2284
+ this.merchant = computed(() => this.status()?.merchantName || this.status()?.merchantId || "", ...ngDevMode ? [{ debugName: "merchant" }] : /* istanbul ignore next */ []);
2285
+ this.location = computed(() => this.status()?.locationName || this.status()?.locationId || "", ...ngDevMode ? [{ debugName: "location" }] : /* istanbul ignore next */ []);
2286
+ this.connectedOn = computed(() => this.labels.formatDate(this.status()?.connectedAt ?? null, "mediumDate"), ...ngDevMode ? [{ debugName: "connectedOn" }] : /* istanbul ignore next */ []);
2287
+ this.liveText = computed(() => {
2288
+ const text = this.labels.t({
2289
+ none: "squareConnect.live.none",
2290
+ connected: "squareConnect.live.connected",
2291
+ reconnect: "squareConnect.live.reconnect"
2292
+ }[this.state()]);
2293
+ return this.loading() ? this.labels.t("squareConnect.live.loading", { text }) : text;
2294
+ }, ...ngDevMode ? [{ debugName: "liveText" }] : /* istanbul ignore next */ []);
2295
+ this.acted = false;
2296
+ this.lastState = this.state();
2297
+ this.flow = new SquareConnectFlow({
2298
+ start: () => this.startConnect(),
2299
+ getStatus: () => this.getStatus(),
2300
+ disconnect: () => this.disconnect(),
2301
+ state: {
2302
+ status: this.status,
2303
+ loading: this.loading
2304
+ },
2305
+ emit: (outcome) => this.outcome.emit(outcome),
2306
+ disabled: () => this.disabled(),
2307
+ navigate: (url) => this.navigateCurrentTab(url),
2308
+ onOpened: () => this.awaiting.set(true),
2309
+ destroyRef: this.destroyRef
2310
+ });
2311
+ effect(() => {
2312
+ const state = this.state();
2313
+ if (this.loading()) return;
2314
+ const changed = state !== this.lastState;
2315
+ this.lastState = state;
2316
+ const focusIt = changed && this.acted;
2317
+ this.acted = false;
2318
+ if (state === "connected") this.awaiting.set(false);
2319
+ if (focusIt) afterNextRender(() => this.host.nativeElement.querySelector(".sqc-state")?.focus(), { injector: this.injector });
2320
+ });
2321
+ if (typeof document !== "undefined") {
2322
+ const onVisible = () => {
2323
+ if (document.visibilityState !== "visible" || !this.flow.tabOpened || !this.refreshOnReturn() || this.loading()) return;
2324
+ this.flow.tabOpened = false;
2325
+ this.flow.readStatusOnReturn();
2326
+ };
2327
+ document.addEventListener("visibilitychange", onVisible);
2328
+ this.destroyRef.onDestroy(() => document.removeEventListener("visibilitychange", onVisible));
2329
+ }
2330
+ }
2331
+ start() {
2332
+ const run = this.canRun(this.startConnect());
2333
+ this.flow.startConnect();
2334
+ this.acted ||= run;
2335
+ }
2336
+ check() {
2337
+ const run = this.canRun(this.getStatus());
2338
+ this.flow.check();
2339
+ this.acted ||= run;
2340
+ }
2341
+ askDisconnect() {
2342
+ if (this.disabled() || this.loading() || !this.disconnect()) return;
2343
+ if (this.confirmDisconnect()) this.confirming.set(true);
2344
+ else this.doDisconnect();
2345
+ }
2346
+ cancelDisconnect() {
2347
+ if (!this.loading()) this.confirming.set(false);
2348
+ }
2349
+ doDisconnect() {
2350
+ const run = this.canRun(this.disconnect());
2351
+ this.flow.disconnect();
2352
+ this.acted ||= run;
2353
+ this.confirming.set(false);
2354
+ }
2355
+ canRun(call) {
2356
+ return !!call && !this.loading() && !this.disabled();
2357
+ }
2358
+ navigateCurrentTab(url) {
2359
+ const navigate = this.navigateTab();
2360
+ if (navigate) navigate(url);
2361
+ else window.location.href = url;
2362
+ }
2363
+ static {
2364
+ this.ɵfac = i0.ɵɵngDeclareFactory({
2365
+ minVersion: "12.0.0",
2366
+ version: "22.2.2",
2367
+ ngImport: i0,
2368
+ type: SquareConnectComponent,
2369
+ deps: [],
2370
+ target: i0.ɵɵFactoryTarget.Component
2371
+ });
2372
+ }
2373
+ static {
2374
+ this.ɵcmp = i0.ɵɵngDeclareComponent({
2375
+ minVersion: "17.0.0",
2376
+ version: "22.2.2",
2377
+ type: SquareConnectComponent,
2378
+ isStandalone: true,
2379
+ selector: "ui-square-connect",
2380
+ inputs: {
2381
+ startConnect: {
2382
+ classPropertyName: "startConnect",
2383
+ publicName: "startConnect",
2384
+ isSignal: true,
2385
+ isRequired: false,
2386
+ transformFunction: null
2387
+ },
2388
+ getStatus: {
2389
+ classPropertyName: "getStatus",
2390
+ publicName: "getStatus",
2391
+ isSignal: true,
2392
+ isRequired: false,
2393
+ transformFunction: null
2394
+ },
2395
+ disconnect: {
2396
+ classPropertyName: "disconnect",
2397
+ publicName: "disconnect",
2398
+ isSignal: true,
2399
+ isRequired: false,
2400
+ transformFunction: null
2401
+ },
2402
+ status: {
2403
+ classPropertyName: "status",
2404
+ publicName: "status",
2405
+ isSignal: true,
2406
+ isRequired: false,
2407
+ transformFunction: null
2408
+ },
2409
+ titleInput: {
2410
+ classPropertyName: "titleInput",
2411
+ publicName: "title",
2412
+ isSignal: true,
2413
+ isRequired: false,
2414
+ transformFunction: null
2415
+ },
2416
+ bare: {
2417
+ classPropertyName: "bare",
2418
+ publicName: "bare",
2419
+ isSignal: true,
2420
+ isRequired: false,
2421
+ transformFunction: null
2422
+ },
2423
+ startTitleInput: {
2424
+ classPropertyName: "startTitleInput",
2425
+ publicName: "startTitle",
2426
+ isSignal: true,
2427
+ isRequired: false,
2428
+ transformFunction: null
2429
+ },
2430
+ startTextInput: {
2431
+ classPropertyName: "startTextInput",
2432
+ publicName: "startText",
2433
+ isSignal: true,
2434
+ isRequired: false,
2435
+ transformFunction: null
2436
+ },
2437
+ startLabelInput: {
2438
+ classPropertyName: "startLabelInput",
2439
+ publicName: "startLabel",
2440
+ isSignal: true,
2441
+ isRequired: false,
2442
+ transformFunction: null
2443
+ },
2444
+ disabled: {
2445
+ classPropertyName: "disabled",
2446
+ publicName: "disabled",
2447
+ isSignal: true,
2448
+ isRequired: false,
2449
+ transformFunction: null
2450
+ },
2451
+ confirmDisconnect: {
2452
+ classPropertyName: "confirmDisconnect",
2453
+ publicName: "confirmDisconnect",
2454
+ isSignal: true,
2455
+ isRequired: false,
2456
+ transformFunction: null
2457
+ },
2458
+ refreshOnReturn: {
2459
+ classPropertyName: "refreshOnReturn",
2460
+ publicName: "refreshOnReturn",
2461
+ isSignal: true,
2462
+ isRequired: false,
2463
+ transformFunction: null
2464
+ },
2465
+ navigateTab: {
2466
+ classPropertyName: "navigateTab",
2467
+ publicName: "navigateTab",
2468
+ isSignal: true,
2469
+ isRequired: false,
2470
+ transformFunction: null
2471
+ },
2472
+ loading: {
2473
+ classPropertyName: "loading",
2474
+ publicName: "loading",
2475
+ isSignal: true,
2476
+ isRequired: false,
2477
+ transformFunction: null
2478
+ }
2479
+ },
2480
+ outputs: {
2481
+ status: "statusChange",
2482
+ outcome: "outcome",
2483
+ loading: "loadingChange"
2484
+ },
2485
+ ngImport: i0,
2486
+ template: `
2487
+ <!-- Persistent live region: present before the state changes, so every new state is announced (and "Loading" while a request runs). -->
2488
+ <ui-live-region data-testid="square-connect-live" [message]="liveText()" />
2489
+ @if (bare()) {
2490
+ <ng-container *ngTemplateOutlet="body" />
2491
+ } @else {
2492
+ <ui-detail-card [collapsible]="false" [title]="title()" [headingLevel]="3" data-testid="square-connect-card">
2493
+ <ng-container *ngTemplateOutlet="body" />
2494
+ </ui-detail-card>
2495
+ }
2496
+
2497
+ <ng-template #body>
2498
+ @if (state() === 'none') {
2499
+ <ui-stack gap="sm" class="sqc-state" tabindex="-1" data-testid="square-connect-status-none" [attr.aria-busy]="loading() ? 'true' : null">
2500
+ <ui-text size="lg" weight="semibold" [text]="startTitle()" />
2501
+ <ui-text size="sm" [text]="startText()" />
2502
+ <ui-stack direction="horizontal">
2503
+ <ui-button variant="primary" size="sm" data-testid="square-connect-start-button" [disabled]="disabled()" (click)="start()">@if (loading()) {<span aria-hidden="true">{{ labels.t('common.loadingellipsis') }}</span><span class="sqc-sr">{{ labels.t('squareConnect.opensInNewTabBusy', { label: startLabel() }) }}</span>} @else { {{ startLabel() }}<span class="sqc-sr">{{ labels.t('squareConnect.opensInNewTabSr') }}</span>}</ui-button>
2504
+ @if (awaiting()) {
2505
+ <ui-button variant="secondary" size="sm" data-testid="square-connect-check-status-button" [disabled]="disabled() || loading()" (click)="check()">{{ labels.t(loading() ? 'squareConnect.checking' : 'squareConnect.checkStatus') }}</ui-button>
2506
+ }
2507
+ </ui-stack>
2508
+ </ui-stack>
2509
+ } @else if (state() === 'reconnect') {
2510
+ <ui-stack gap="sm" class="sqc-state" tabindex="-1" data-testid="square-connect-status-reconnect" [attr.aria-busy]="loading() ? 'true' : null">
2511
+ <span class="sqc-badge"><ui-badge [label]="labels.t('squareConnect.needsReconnect')" variant="red" data-testid="square-connect-reconnect-badge" /></span>
2512
+ <ui-text size="sm" [text]="labels.t('squareConnect.reconnectText')" />
2513
+ <ui-stack direction="horizontal">
2514
+ <ui-button variant="primary" size="sm" data-testid="square-connect-reconnect-button" [disabled]="disabled()" (click)="start()">@if (loading()) {<span aria-hidden="true">{{ labels.t('common.loadingellipsis') }}</span><span class="sqc-sr">{{ labels.t('squareConnect.opensInNewTabBusy', { label: labels.t('squareConnect.reconnect') }) }}</span>} @else { {{ labels.t('squareConnect.reconnect') }}<span class="sqc-sr">{{ labels.t('squareConnect.opensInNewTabSr') }}</span>}</ui-button>
2515
+ <ui-button variant="secondary" size="sm" data-testid="square-connect-disconnect-button" [disabled]="disabled() || loading()" (click)="askDisconnect()">{{ labels.t('squareConnect.disconnect') }}</ui-button>
2516
+ </ui-stack>
2517
+ </ui-stack>
2518
+ } @else {
2519
+ <ui-stack gap="sm" class="sqc-state" tabindex="-1" data-testid="square-connect-status-connected" [attr.aria-busy]="loading() ? 'true' : null">
2520
+ <ui-text size="lg" weight="semibold" [text]="labels.t('squareConnect.connected')" />
2521
+ @if (merchant(); as merchant) { <ui-text size="sm" tone="muted" data-testid="square-connect-merchant" [text]="labels.t('squareConnect.merchantLine', { merchant })" /> }
2522
+ @if (location(); as location) { <ui-text size="sm" tone="muted" data-testid="square-connect-location" [text]="labels.t('squareConnect.locationLine', { location })" /> }
2523
+ @if (connectedOn(); as date) { <ui-text size="sm" tone="muted" data-testid="square-connect-date" [text]="labels.t('squareConnect.connectedOn', { date })" /> }
2524
+ <ui-stack direction="horizontal">
2525
+ <ui-button variant="secondary" size="sm" data-testid="square-connect-check-status-button" [disabled]="disabled() || loading()" (click)="check()">{{ labels.t(loading() ? 'squareConnect.checking' : 'squareConnect.checkStatus') }}</ui-button>
2526
+ <ui-button variant="secondary" size="sm" data-testid="square-connect-disconnect-button" [disabled]="disabled() || loading()" (click)="askDisconnect()">{{ labels.t('squareConnect.disconnect') }}</ui-button>
2527
+ </ui-stack>
2528
+ </ui-stack>
2529
+ }
2530
+ </ng-template>
2531
+
2532
+ <ui-modal [open]="confirming()" [title]="labels.t('squareConnect.disconnectTitle')" maxWidth="440px" [describedBy]="confirmMessageId" [busy]="loading()" dialogTestId="square-connect-confirm" (close)="cancelDisconnect()">
2533
+ <p [id]="confirmMessageId" class="sqc-confirm" data-testid="square-connect-confirm-message">{{ labels.t('squareConnect.disconnectMessage') }}</p>
2534
+ <ui-button modal-footer-left variant="secondary" size="sm" data-testid="square-connect-confirm-cancel" [disabled]="loading()" (click)="cancelDisconnect()">{{ labels.t('common.cancel') }}</ui-button>
2535
+ <ui-button modal-footer-right variant="danger" size="sm" data-testid="square-connect-confirm-accept" [loading]="loading()" (click)="doDisconnect()">{{ labels.t('squareConnect.disconnect') }}</ui-button>
2536
+ </ui-modal>
2537
+ `,
2538
+ isInline: true,
2539
+ styles: ["ui-square-connect{display:block;min-width:0}ui-square-connect .sqc-badge{display:flex}ui-square-connect .sqc-confirm{margin:0;font-size:.9375rem;line-height:1.5}ui-square-connect .sqc-sr{position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap}\n"],
2540
+ dependencies: [
2541
+ {
2542
+ kind: "directive",
2543
+ type: NgTemplateOutlet,
2544
+ selector: "[ngTemplateOutlet]",
2545
+ inputs: [
2546
+ "ngTemplateOutletContext",
2547
+ "ngTemplateOutlet",
2548
+ "ngTemplateOutletInjector"
2549
+ ]
2550
+ },
2551
+ {
2552
+ kind: "component",
2553
+ type: BadgeComponent,
2554
+ selector: "ui-badge",
2555
+ inputs: [
2556
+ "label",
2557
+ "variant",
2558
+ "color"
2559
+ ]
2560
+ },
2561
+ {
2562
+ kind: "component",
2563
+ type: ButtonComponent,
2564
+ selector: "ui-button",
2565
+ inputs: [
2566
+ "variant",
2567
+ "routerLink",
2568
+ "queryParams",
2569
+ "fragment",
2570
+ "state",
2571
+ "href",
2572
+ "target",
2573
+ "rel",
2574
+ "shortLabel",
2575
+ "shortBelow",
2576
+ "color",
2577
+ "active",
2578
+ "size",
2579
+ "type",
2580
+ "disabled",
2581
+ "loading",
2582
+ "fullWidth",
2583
+ "ariaLabel",
2584
+ "ariaExpanded",
2585
+ "ariaPressed",
2586
+ "ariaDescribedBy",
2587
+ "modal-footer-left",
2588
+ "modal-footer-right"
2589
+ ]
2590
+ },
2591
+ {
2592
+ kind: "component",
2593
+ type: DetailCardComponent,
2594
+ selector: "ui-detail-card",
2595
+ inputs: [
2596
+ "title",
2597
+ "uppercaseTitle",
2598
+ "headingLevel",
2599
+ "titleId",
2600
+ "ariaLabel",
2601
+ "subtitle",
2602
+ "background",
2603
+ "headerBackground",
2604
+ "footerBackground",
2605
+ "footerAlign",
2606
+ "textColor",
2607
+ "showHeader",
2608
+ "collapsible",
2609
+ "expanded",
2610
+ "showEdit",
2611
+ "editLabel",
2612
+ "editTestId",
2613
+ "editIcon",
2614
+ "editAriaLabel",
2615
+ "fill",
2616
+ "noPadding",
2617
+ "maxBodyHeight",
2618
+ "selectable",
2619
+ "selected",
2620
+ "selectedColor",
2621
+ "selectedBackground"
2622
+ ],
2623
+ outputs: [
2624
+ "expandedChange",
2625
+ "editClick",
2626
+ "selectedChange"
2627
+ ]
2628
+ },
2629
+ {
2630
+ kind: "component",
2631
+ type: ModalComponent,
2632
+ selector: "ui-modal",
2633
+ inputs: [
2634
+ "open",
2635
+ "title",
2636
+ "description",
2637
+ "describedBy",
2638
+ "maxWidth",
2639
+ "bodyOverflow",
2640
+ "dialogTestId",
2641
+ "hideClose",
2642
+ "closable",
2643
+ "layout",
2644
+ "closeOnBackdrop",
2645
+ "closeOnEscape",
2646
+ "busy",
2647
+ "returnFocusTo"
2648
+ ],
2649
+ outputs: ["close"]
2650
+ },
2651
+ {
2652
+ kind: "component",
2653
+ type: LiveRegionComponent,
2654
+ selector: "ui-live-region",
2655
+ inputs: [
2656
+ "message",
2657
+ "politeness",
2658
+ "atomic",
2659
+ "visible"
2660
+ ]
2661
+ },
2662
+ {
2663
+ kind: "component",
2664
+ type: StackComponent,
2665
+ selector: "ui-stack",
2666
+ inputs: [
2667
+ "gap",
2668
+ "direction",
2669
+ "align",
2670
+ "justify",
2671
+ "wrap",
2672
+ "minHeight",
2673
+ "width",
2674
+ "maxWidth",
2675
+ "padding",
2676
+ "centered"
2677
+ ]
2678
+ },
2679
+ {
2680
+ kind: "component",
2681
+ type: TextComponent,
2682
+ selector: "ui-text",
2683
+ inputs: [
2684
+ "text",
2685
+ "size",
2686
+ "tone",
2687
+ "color",
2688
+ "strong",
2689
+ "weight"
2690
+ ]
2691
+ }
2692
+ ],
2693
+ changeDetection: i0.ChangeDetectionStrategy.OnPush,
2694
+ encapsulation: i0.ViewEncapsulation.None
2695
+ });
2696
+ }
2697
+ };
2698
+ i0.ɵɵngDeclareClassMetadata({
2699
+ minVersion: "12.0.0",
2700
+ version: "22.2.2",
2701
+ ngImport: i0,
2702
+ type: SquareConnectComponent,
2703
+ decorators: [{
2704
+ type: Component,
2705
+ args: [{
2706
+ selector: "ui-square-connect",
2707
+ standalone: true,
2708
+ changeDetection: ChangeDetectionStrategy.OnPush,
2709
+ imports: [
2710
+ NgTemplateOutlet,
2711
+ BadgeComponent,
2712
+ ButtonComponent,
2713
+ DetailCardComponent,
2714
+ ModalComponent,
2715
+ LiveRegionComponent,
2716
+ StackComponent,
2717
+ TextComponent
2718
+ ],
2719
+ template: `
2720
+ <!-- Persistent live region: present before the state changes, so every new state is announced (and "Loading" while a request runs). -->
2721
+ <ui-live-region data-testid="square-connect-live" [message]="liveText()" />
2722
+ @if (bare()) {
2723
+ <ng-container *ngTemplateOutlet="body" />
2724
+ } @else {
2725
+ <ui-detail-card [collapsible]="false" [title]="title()" [headingLevel]="3" data-testid="square-connect-card">
2726
+ <ng-container *ngTemplateOutlet="body" />
2727
+ </ui-detail-card>
2728
+ }
2729
+
2730
+ <ng-template #body>
2731
+ @if (state() === 'none') {
2732
+ <ui-stack gap="sm" class="sqc-state" tabindex="-1" data-testid="square-connect-status-none" [attr.aria-busy]="loading() ? 'true' : null">
2733
+ <ui-text size="lg" weight="semibold" [text]="startTitle()" />
2734
+ <ui-text size="sm" [text]="startText()" />
2735
+ <ui-stack direction="horizontal">
2736
+ <ui-button variant="primary" size="sm" data-testid="square-connect-start-button" [disabled]="disabled()" (click)="start()">@if (loading()) {<span aria-hidden="true">{{ labels.t('common.loadingellipsis') }}</span><span class="sqc-sr">{{ labels.t('squareConnect.opensInNewTabBusy', { label: startLabel() }) }}</span>} @else { {{ startLabel() }}<span class="sqc-sr">{{ labels.t('squareConnect.opensInNewTabSr') }}</span>}</ui-button>
2737
+ @if (awaiting()) {
2738
+ <ui-button variant="secondary" size="sm" data-testid="square-connect-check-status-button" [disabled]="disabled() || loading()" (click)="check()">{{ labels.t(loading() ? 'squareConnect.checking' : 'squareConnect.checkStatus') }}</ui-button>
2739
+ }
2740
+ </ui-stack>
2741
+ </ui-stack>
2742
+ } @else if (state() === 'reconnect') {
2743
+ <ui-stack gap="sm" class="sqc-state" tabindex="-1" data-testid="square-connect-status-reconnect" [attr.aria-busy]="loading() ? 'true' : null">
2744
+ <span class="sqc-badge"><ui-badge [label]="labels.t('squareConnect.needsReconnect')" variant="red" data-testid="square-connect-reconnect-badge" /></span>
2745
+ <ui-text size="sm" [text]="labels.t('squareConnect.reconnectText')" />
2746
+ <ui-stack direction="horizontal">
2747
+ <ui-button variant="primary" size="sm" data-testid="square-connect-reconnect-button" [disabled]="disabled()" (click)="start()">@if (loading()) {<span aria-hidden="true">{{ labels.t('common.loadingellipsis') }}</span><span class="sqc-sr">{{ labels.t('squareConnect.opensInNewTabBusy', { label: labels.t('squareConnect.reconnect') }) }}</span>} @else { {{ labels.t('squareConnect.reconnect') }}<span class="sqc-sr">{{ labels.t('squareConnect.opensInNewTabSr') }}</span>}</ui-button>
2748
+ <ui-button variant="secondary" size="sm" data-testid="square-connect-disconnect-button" [disabled]="disabled() || loading()" (click)="askDisconnect()">{{ labels.t('squareConnect.disconnect') }}</ui-button>
2749
+ </ui-stack>
2750
+ </ui-stack>
2751
+ } @else {
2752
+ <ui-stack gap="sm" class="sqc-state" tabindex="-1" data-testid="square-connect-status-connected" [attr.aria-busy]="loading() ? 'true' : null">
2753
+ <ui-text size="lg" weight="semibold" [text]="labels.t('squareConnect.connected')" />
2754
+ @if (merchant(); as merchant) { <ui-text size="sm" tone="muted" data-testid="square-connect-merchant" [text]="labels.t('squareConnect.merchantLine', { merchant })" /> }
2755
+ @if (location(); as location) { <ui-text size="sm" tone="muted" data-testid="square-connect-location" [text]="labels.t('squareConnect.locationLine', { location })" /> }
2756
+ @if (connectedOn(); as date) { <ui-text size="sm" tone="muted" data-testid="square-connect-date" [text]="labels.t('squareConnect.connectedOn', { date })" /> }
2757
+ <ui-stack direction="horizontal">
2758
+ <ui-button variant="secondary" size="sm" data-testid="square-connect-check-status-button" [disabled]="disabled() || loading()" (click)="check()">{{ labels.t(loading() ? 'squareConnect.checking' : 'squareConnect.checkStatus') }}</ui-button>
2759
+ <ui-button variant="secondary" size="sm" data-testid="square-connect-disconnect-button" [disabled]="disabled() || loading()" (click)="askDisconnect()">{{ labels.t('squareConnect.disconnect') }}</ui-button>
2760
+ </ui-stack>
2761
+ </ui-stack>
2762
+ }
2763
+ </ng-template>
2764
+
2765
+ <ui-modal [open]="confirming()" [title]="labels.t('squareConnect.disconnectTitle')" maxWidth="440px" [describedBy]="confirmMessageId" [busy]="loading()" dialogTestId="square-connect-confirm" (close)="cancelDisconnect()">
2766
+ <p [id]="confirmMessageId" class="sqc-confirm" data-testid="square-connect-confirm-message">{{ labels.t('squareConnect.disconnectMessage') }}</p>
2767
+ <ui-button modal-footer-left variant="secondary" size="sm" data-testid="square-connect-confirm-cancel" [disabled]="loading()" (click)="cancelDisconnect()">{{ labels.t('common.cancel') }}</ui-button>
2768
+ <ui-button modal-footer-right variant="danger" size="sm" data-testid="square-connect-confirm-accept" [loading]="loading()" (click)="doDisconnect()">{{ labels.t('squareConnect.disconnect') }}</ui-button>
2769
+ </ui-modal>
2770
+ `,
2771
+ encapsulation: ViewEncapsulation.None,
2772
+ styles: ["ui-square-connect{display:block;min-width:0}ui-square-connect .sqc-badge{display:flex}ui-square-connect .sqc-confirm{margin:0;font-size:.9375rem;line-height:1.5}ui-square-connect .sqc-sr{position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap}\n"]
2773
+ }]
2774
+ }],
2775
+ ctorParameters: () => [],
2776
+ propDecorators: {
2777
+ startConnect: [{
2778
+ type: i0.Input,
2779
+ args: [{
2780
+ isSignal: true,
2781
+ alias: "startConnect",
2782
+ required: false
2783
+ }]
2784
+ }],
2785
+ getStatus: [{
2786
+ type: i0.Input,
2787
+ args: [{
2788
+ isSignal: true,
2789
+ alias: "getStatus",
2790
+ required: false
2791
+ }]
2792
+ }],
2793
+ disconnect: [{
2794
+ type: i0.Input,
2795
+ args: [{
2796
+ isSignal: true,
2797
+ alias: "disconnect",
2798
+ required: false
2799
+ }]
2800
+ }],
2801
+ status: [{
2802
+ type: i0.Input,
2803
+ args: [{
2804
+ isSignal: true,
2805
+ alias: "status",
2806
+ required: false
2807
+ }]
2808
+ }, {
2809
+ type: i0.Output,
2810
+ args: ["statusChange"]
2811
+ }],
2812
+ titleInput: [{
2813
+ type: i0.Input,
2814
+ args: [{
2815
+ isSignal: true,
2816
+ alias: "title",
2817
+ required: false
2818
+ }]
2819
+ }],
2820
+ bare: [{
2821
+ type: i0.Input,
2822
+ args: [{
2823
+ isSignal: true,
2824
+ alias: "bare",
2825
+ required: false
2826
+ }]
2827
+ }],
2828
+ startTitleInput: [{
2829
+ type: i0.Input,
2830
+ args: [{
2831
+ isSignal: true,
2832
+ alias: "startTitle",
2833
+ required: false
2834
+ }]
2835
+ }],
2836
+ startTextInput: [{
2837
+ type: i0.Input,
2838
+ args: [{
2839
+ isSignal: true,
2840
+ alias: "startText",
2841
+ required: false
2842
+ }]
2843
+ }],
2844
+ startLabelInput: [{
2845
+ type: i0.Input,
2846
+ args: [{
2847
+ isSignal: true,
2848
+ alias: "startLabel",
2849
+ required: false
2850
+ }]
2851
+ }],
2852
+ disabled: [{
2853
+ type: i0.Input,
2854
+ args: [{
2855
+ isSignal: true,
2856
+ alias: "disabled",
2857
+ required: false
2858
+ }]
2859
+ }],
2860
+ confirmDisconnect: [{
2861
+ type: i0.Input,
2862
+ args: [{
2863
+ isSignal: true,
2864
+ alias: "confirmDisconnect",
2865
+ required: false
2866
+ }]
2867
+ }],
2868
+ refreshOnReturn: [{
2869
+ type: i0.Input,
2870
+ args: [{
2871
+ isSignal: true,
2872
+ alias: "refreshOnReturn",
2873
+ required: false
2874
+ }]
2875
+ }],
2876
+ navigateTab: [{
2877
+ type: i0.Input,
2878
+ args: [{
2879
+ isSignal: true,
2880
+ alias: "navigateTab",
2881
+ required: false
2882
+ }]
2883
+ }],
2884
+ outcome: [{
2885
+ type: i0.Output,
2886
+ args: ["outcome"]
2887
+ }],
2888
+ loading: [{
2889
+ type: i0.Input,
2890
+ args: [{
2891
+ isSignal: true,
2892
+ alias: "loading",
2893
+ required: false
2894
+ }]
2895
+ }, {
2896
+ type: i0.Output,
2897
+ args: ["loadingChange"]
2898
+ }]
2899
+ }
2900
+ });
2901
+ const PAID = /* @__PURE__ */ new Set(["COMPLETED", "PAID"]);
2902
+ const FAILED = /* @__PURE__ */ new Set([
2903
+ "FAILED",
2904
+ "CANCELED",
2905
+ "CANCELLED"
2906
+ ]);
2907
+ function squareOutcomeOf(status, method = "card") {
2908
+ const value = (status ?? "").trim().toUpperCase();
2909
+ if (!value) return method === "ach" ? "processing" : "paid";
2910
+ if (PAID.has(value)) return "paid";
2911
+ if (FAILED.has(value)) return "failed";
2912
+ return "processing";
2913
+ }
2914
+ const SQUARE_PAYMENT_METHOD_VALUES = ["CARD", "ACH"];
2915
+ const squareMethodLabel = (value) => value === "CARD" ? uiText("squarePaymentMethod.methodCard") : value === "ACH" ? uiText("squarePaymentMethod.methodAch") : value;
2916
+ const squareMethodOf = (method) => method === "ACH" ? "ach" : "card";
2917
+ const SQUARE_METHOD_TEXTS = {
2918
+ get amountNeeded() {
2919
+ return uiText("squarePaymentMethod.amountNeeded");
2920
+ },
2921
+ get notCompleted() {
2922
+ return uiText("squarePaymentMethod.notCompleted");
2923
+ },
2924
+ get achTitle() {
2925
+ return uiText("squarePaymentMethod.achTitle");
2926
+ },
2927
+ achMessage: (amount) => uiText("squarePaymentMethod.achMessage", { amount }),
2928
+ get pendingTitle() {
2929
+ return uiText("squarePaymentMethod.pendingTitle");
2930
+ },
2931
+ pendingMessage: (amount) => uiText("squarePaymentMethod.pendingMessage", { amount }),
2932
+ get receiptNote() {
2933
+ return uiText("squarePaymentMethod.receiptNote");
2934
+ }
2935
+ };
2936
+ var PaymentSquareBodyComponent = class PaymentSquareBodyComponent {
2937
+ constructor() {
2938
+ this.labels = inject(UiLabelsService);
2939
+ this.injector = inject(Injector);
2940
+ this.host = inject(ElementRef);
2941
+ this.ctx = input.required(...ngDevMode ? [{ debugName: "ctx" }] : /* istanbul ignore next */ []);
2942
+ this.config = input.required(...ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []);
2943
+ this.payment = viewChild(SquarePaymentComponent, ...ngDevMode ? [{ debugName: "payment" }] : /* istanbul ignore next */ []);
2944
+ this.texts = SQUARE_METHOD_TEXTS;
2945
+ this.ready = signal(false, ...ngDevMode ? [{ debugName: "ready" }] : /* istanbul ignore next */ []);
2946
+ this.processing = signal(false, ...ngDevMode ? [{ debugName: "processing" }] : /* istanbul ignore next */ []);
2947
+ this.done = signal(false, ...ngDevMode ? [{ debugName: "done" }] : /* istanbul ignore next */ []);
2948
+ this.error = signal("", ...ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []);
2949
+ this.finalRefusal = signal(null, ...ngDevMode ? [{ debugName: "finalRefusal" }] : /* istanbul ignore next */ []);
2950
+ this.estimate = signal(null, ...ngDevMode ? [{ debugName: "estimate" }] : /* istanbul ignore next */ []);
2951
+ this.estimating = signal(false, ...ngDevMode ? [{ debugName: "estimating" }] : /* istanbul ignore next */ []);
2952
+ this.estimateError = signal("", ...ngDevMode ? [{ debugName: "estimateError" }] : /* istanbul ignore next */ []);
2953
+ this.estimateTick = signal(0, ...ngDevMode ? [{ debugName: "estimateTick" }] : /* istanbul ignore next */ []);
2954
+ this.resultFees = signal(null, ...ngDevMode ? [{ debugName: "resultFees" }] : /* istanbul ignore next */ []);
2955
+ this.confirmation = signal(null, ...ngDevMode ? [{ debugName: "confirmation" }] : /* istanbul ignore next */ []);
2956
+ this.lastAmount = signal(null, ...ngDevMode ? [{ debugName: "lastAmount" }] : /* istanbul ignore next */ []);
2957
+ this.payAmount = null;
2958
+ this.payMethod = null;
2959
+ this.doneAmount = null;
2960
+ this.doneMethod = null;
2961
+ this.estimateRun = 0;
2962
+ this.amountValue = computed(() => this.ctx().amount, ...ngDevMode ? [{ debugName: "amountValue" }] : /* istanbul ignore next */ []);
2963
+ this.methodValue = computed(() => this.ctx().method, ...ngDevMode ? [{ debugName: "methodValue" }] : /* istanbul ignore next */ []);
2964
+ this.squareMethod = computed(() => squareMethodOf(this.ctx().method), ...ngDevMode ? [{ debugName: "squareMethod" }] : /* istanbul ignore next */ []);
2965
+ this.total = computed(() => this.resultFees()?.totalAmount ?? this.estimate()?.totalAmount ?? this.lastAmount() ?? 0, ...ngDevMode ? [{ debugName: "total" }] : /* istanbul ignore next */ []);
2966
+ this.chargedAmount = computed(() => this.estimate()?.totalAmount ?? this.resultFees()?.totalAmount ?? this.lastAmount(), ...ngDevMode ? [{ debugName: "chargedAmount" }] : /* istanbul ignore next */ []);
2967
+ this.receiptNote = computed(() => this.config().receiptNote(), ...ngDevMode ? [{ debugName: "receiptNote" }] : /* istanbul ignore next */ []);
2968
+ this.feeRows = computed(() => {
2969
+ const fees = this.resultFees() ?? this.estimate();
2970
+ const amount = this.lastAmount();
2971
+ if (!fees || amount == null || fees.processingFee === void 0 && fees.platformFee === void 0) return [];
2972
+ const money = (n) => formatCurrency(n, { currency: this.ctx().currency });
2973
+ const rows = [{
2974
+ key: "amount",
2975
+ label: this.labels.t("squarePaymentMethod.paymentAmount"),
2976
+ value: money(amount)
2977
+ }];
2978
+ if (fees.processingFee !== void 0) rows.push({
2979
+ key: "processing",
2980
+ label: `${this.labels.t("squarePaymentMethod.processingFee")}${fees.processingFeeLabel ? ` (${fees.processingFeeLabel})` : ""}`,
2981
+ value: money(fees.processingFee)
2982
+ });
2983
+ if (fees.platformFee !== void 0) rows.push({
2984
+ key: "platform",
2985
+ label: `${this.labels.t("squarePaymentMethod.platformFee")}${fees.platformFeeLabel ? ` (${fees.platformFeeLabel})` : ""}`,
2986
+ value: money(fees.platformFee)
2987
+ });
2988
+ return rows;
2989
+ }, ...ngDevMode ? [{ debugName: "feeRows" }] : /* istanbul ignore next */ []);
2990
+ this.totalCard = computed(() => {
2991
+ const fees = this.resultFees() ?? this.estimate();
2992
+ if (!fees || this.lastAmount() == null || fees.totalAmount === void 0) return null;
2993
+ return {
2994
+ value: formatCurrency(fees.totalAmount, { currency: this.ctx().currency }),
2995
+ subtitle: this.labels.t("squarePaymentMethod.amountPlusFees")
2996
+ };
2997
+ }, ...ngDevMode ? [{ debugName: "totalCard" }] : /* istanbul ignore next */ []);
2998
+ this.gone = false;
2999
+ const configured = (read) => computed(() => read(this.config()));
3000
+ const inputs = {
3001
+ payableRef: configured((c) => c.payableRef()),
3002
+ attemptKey: configured((c) => c.attemptKey()),
3003
+ checkStatus: configured((c) => c.checkStatus()),
3004
+ paid: configured((c) => c.paid()),
3005
+ hostPending: configured((c) => c.hostPending()),
3006
+ statusPollMs: configured((c) => c.statusPollMs()),
3007
+ statusPollMaxMs: configured((c) => c.statusPollMaxMs()),
3008
+ statusCheckTimeoutMs: configured((c) => c.statusCheckTimeoutMs()),
3009
+ statusFailGraceMs: configured((c) => c.statusFailGraceMs()),
3010
+ authTimeoutMs: configured((c) => c.authTimeoutMs()),
3011
+ readinessCheck: configured((c) => c.readinessCheck()),
3012
+ readinessTimeoutMs: configured((c) => c.readinessTimeoutMs()),
3013
+ readinessEveryMs: configured((c) => c.readinessEveryMs()),
3014
+ offlineOverride: configured((c) => c.offlineOverride())
3015
+ };
3016
+ const protection = createPaymentProtection(inputs, {
3017
+ amount: () => this.ctx().amount,
3018
+ method: () => this.ctx().method,
3019
+ sdk: () => this.payment()?.loadErrorText() ? "blocked" : "ok",
3020
+ onOutcome: (o) => this.onAttemptOutcome(o)
3021
+ });
3022
+ this.attempt = protection.attempt;
3023
+ this.readiness = protection.readiness;
3024
+ inject(DestroyRef).onDestroy(() => {
3025
+ this.gone = true;
3026
+ });
3027
+ const controls = {
3028
+ markUnknown: () => this.attempt.markUnknown("host"),
3029
+ markSucceeded: () => this.attempt.succeed("host"),
3030
+ markFailed: () => this.attempt.fail("host"),
3031
+ resetPaid: () => {
3032
+ this.attempt.resetPaid();
3033
+ this.done.set(false);
3034
+ this.confirmation.set(null);
3035
+ this.error.set("");
3036
+ this.ctx().setExclusive(false);
3037
+ },
3038
+ markNotCharged: () => {
3039
+ this.attempt.markNotCharged();
3040
+ this.payment()?.markNotCharged();
3041
+ this.processing.set(false);
3042
+ this.ctx().setBusy(false);
3043
+ }
3044
+ };
3045
+ effect(() => {
3046
+ const config = this.config();
3047
+ untracked(() => config.attachControls(controls));
3048
+ });
3049
+ inject(DestroyRef).onDestroy(() => this.config().detachControls(controls));
3050
+ effect(() => {
3051
+ const amount = this.amountValue();
3052
+ if (amount != null) untracked(() => this.lastAmount.set(amount));
3053
+ });
3054
+ effect(() => {
3055
+ const scope = this.finalRefusal();
3056
+ if (!scope) return;
3057
+ const ctx = this.ctx();
3058
+ if (ctx.method !== scope.method || ctx.amount !== scope.amount || this.config().payableRef() !== scope.ref) untracked(() => {
3059
+ this.finalRefusal.set(null);
3060
+ this.error.set("");
3061
+ });
3062
+ });
3063
+ effect(() => {
3064
+ const ctx = this.ctx();
3065
+ const processing = this.processing();
3066
+ const notice = this.confirmation();
3067
+ const ready = this.ready();
3068
+ const estimating = this.estimating();
3069
+ const done = this.done();
3070
+ const estimateFailed = !!this.estimateError();
3071
+ const unknown = this.attempt.unknown();
3072
+ const paidLocked = this.attempt.paidLocked();
3073
+ const finalRefusal = !!this.finalRefusal();
3074
+ const gateReady = this.readiness.ready();
3075
+ const label = notice ? this.labels.t("common.done") : ctx.amount != null ? `${this.labels.t("squarePaymentMethod.pay")} ${formatCurrency(this.total(), { currency: ctx.currency })}` : this.labels.t("squarePaymentMethod.pay");
3076
+ untracked(() => ctx.setPrimary({
3077
+ label,
3078
+ loading: processing && !notice,
3079
+ disabled: notice ? done : !ready || processing || estimating || estimateFailed || ctx.amount == null || done || unknown || paidLocked || finalRefusal || !gateReady,
3080
+ onClick: () => notice ? this.finish() : void this.pay()
3081
+ }));
3082
+ });
3083
+ effect((onCleanup) => {
3084
+ const estimate = this.config().estimateFees();
3085
+ const amount = this.amountValue();
3086
+ const method = this.methodValue();
3087
+ this.estimateTick();
3088
+ const run = ++this.estimateRun;
3089
+ untracked(() => {
3090
+ this.estimate.set(null);
3091
+ this.resultFees.set(null);
3092
+ this.estimateError.set("");
3093
+ });
3094
+ if (!estimate || amount == null) {
3095
+ untracked(() => this.estimating.set(false));
3096
+ return;
3097
+ }
3098
+ untracked(() => this.estimating.set(true));
3099
+ let hung = null;
3100
+ const failure = this.labels.t("squarePaymentMethod.feesFailed");
3101
+ const timer = setTimeout(async () => {
3102
+ hung = setTimeout(() => {
3103
+ if (run !== this.estimateRun) return;
3104
+ this.estimating.set(false);
3105
+ if (this.feesMustBeKnown()) this.estimateError.set(failure);
3106
+ }, Math.max(1, this.config().estimateTimeoutMs()));
3107
+ let fees = null;
3108
+ try {
3109
+ fees = await callHost(() => estimate({
3110
+ amount,
3111
+ paymentMethod: method,
3112
+ method: squareMethodOf(method),
3113
+ funding: null
3114
+ })) ?? null;
3115
+ } catch {
3116
+ fees = null;
3117
+ }
3118
+ if (hung) {
3119
+ clearTimeout(hung);
3120
+ hung = null;
3121
+ }
3122
+ if (run !== this.estimateRun) return;
3123
+ this.estimating.set(false);
3124
+ if (fees) {
3125
+ this.estimate.set(fees);
3126
+ this.estimateError.set("");
3127
+ } else {
3128
+ this.estimate.set(null);
3129
+ this.estimateError.set(this.feesMustBeKnown() ? failure : "");
3130
+ }
3131
+ }, 300);
3132
+ onCleanup(() => {
3133
+ clearTimeout(timer);
3134
+ if (hung) clearTimeout(hung);
3135
+ });
3136
+ });
3137
+ effect(() => {
3138
+ this.methodValue();
3139
+ const config = this.config();
3140
+ config.applicationId();
3141
+ config.locationId();
3142
+ config.environment();
3143
+ untracked(() => {
3144
+ this.ready.set(false);
3145
+ this.error.set("");
3146
+ });
3147
+ });
3148
+ effect(() => {
3149
+ const ctx = this.ctx();
3150
+ untracked(() => ctx.onCancel(() => {
3151
+ if (this.confirmation()) this.finish();
3152
+ }));
3153
+ });
3154
+ inject(DestroyRef).onDestroy(() => {
3155
+ this.estimateRun++;
3156
+ });
3157
+ }
3158
+ feesMustBeKnown() {
3159
+ return this.config().feesRequired() || !!this.config().billingContact();
3160
+ }
3161
+ retryEstimate() {
3162
+ this.estimateTick.update((n) => n + 1);
3163
+ }
3164
+ onReady() {
3165
+ this.ready.set(true);
3166
+ this.ctx().announce(this.labels.t("squarePaymentMethod.announceReady"));
3167
+ }
3168
+ onFailed(failure) {
3169
+ const message = failure.stage === "verify" ? `${failure.message} ${this.labels.t("paymentAttempt.verifyRetry", { amount: formatCurrency(this.total(), { currency: this.ctx().currency }) })}` : failure.message;
3170
+ failure = {
3171
+ ...failure,
3172
+ message
3173
+ };
3174
+ this.error.set(failure.message);
3175
+ this.processing.set(false);
3176
+ this.ctx().report("failed", { message: failure.message });
3177
+ }
3178
+ async pay() {
3179
+ const ctx = this.ctx();
3180
+ const payment = this.payment();
3181
+ if (this.processing() || this.estimating() || this.done() || !payment) return;
3182
+ if (this.refused(ctx)) return;
3183
+ if (!ctx.validate() || ctx.amount == null) return;
3184
+ this.payAmount = ctx.amount;
3185
+ this.payMethod = ctx.method;
3186
+ const attemptAmount = ctx.amount;
3187
+ const attemptMethod = ctx.method;
3188
+ const create = this.config().createPayment();
3189
+ if (!create) {
3190
+ this.onFailed({
3191
+ code: "not_configured",
3192
+ message: this.labels.t("squarePaymentMethod.unavailable"),
3193
+ squareMessage: "",
3194
+ stage: "tokenize"
3195
+ });
3196
+ return;
3197
+ }
3198
+ this.error.set("");
3199
+ this.processing.set(true);
3200
+ ctx.setBusy(true);
3201
+ ctx.announce(this.labels.t("squarePaymentMethod.announceProcessing"));
3202
+ let finished = false;
3203
+ const run = await this.attempt.run(async (key) => {
3204
+ const live = () => this.attempt.isLive(key);
3205
+ try {
3206
+ if (squareMethodOf(attemptMethod) === "ach") this.attempt.markPending("bank_window");
3207
+ const event = await payment.tokenize();
3208
+ if (!event) return { kind: "released" };
3209
+ if (this.gone) return {
3210
+ kind: "released",
3211
+ reason: "destroyed"
3212
+ };
3213
+ const request = {
3214
+ amount: attemptAmount,
3215
+ paymentMethod: attemptMethod,
3216
+ method: event.method,
3217
+ receivedDate: ctx.receivedDate,
3218
+ notes: ctx.note || null,
3219
+ ...ctx.allocation,
3220
+ token: event.token,
3221
+ details: event.details,
3222
+ funding: event.details.cardType,
3223
+ verificationToken: event.verificationToken,
3224
+ idempotencyKey: event.idempotencyKey,
3225
+ attemptKey: key,
3226
+ payableRef: this.attempt.pinnedRef()
3227
+ };
3228
+ let result;
3229
+ try {
3230
+ result = await callHost(() => create(request));
3231
+ } catch (err) {
3232
+ const kind = classifyHostError(err);
3233
+ if (kind === "unknown") return {
3234
+ kind: "unknown",
3235
+ reason: "host_error"
3236
+ };
3237
+ const labelKey = paymentErrorLabelKey(err);
3238
+ const message = labelKey ? this.labels.t(labelKey) : hostErrorMessage(err, this.labels.t("squarePaymentMethod.paymentFailed"));
3239
+ if (live() && isFinalPaymentRefusal(err)) this.finalRefusal.set({
3240
+ method: attemptMethod,
3241
+ ref: this.config().payableRef(),
3242
+ amount: attemptAmount
3243
+ });
3244
+ if (kind === "not_sent") {
3245
+ if (live()) {
3246
+ this.error.set(message);
3247
+ ctx.report("refused", { message });
3248
+ }
3249
+ return {
3250
+ kind: "released",
3251
+ reason: "not_sent"
3252
+ };
3253
+ }
3254
+ if (live()) {
3255
+ this.error.set(message);
3256
+ ctx.report("failed", { message });
3257
+ }
3258
+ return {
3259
+ kind: "failure",
3260
+ reason: "host_refused"
3261
+ };
3262
+ }
3263
+ if (wasQueuedOffline(result)) {
3264
+ warnQueuedPayment();
3265
+ const message = this.labels.t("paymentAttempt.queuedOffline");
3266
+ if (live()) {
3267
+ this.error.set(message);
3268
+ ctx.report("refused", { message });
3269
+ }
3270
+ return {
3271
+ kind: "released",
3272
+ reason: "not_sent"
3273
+ };
3274
+ }
3275
+ if (this.gone) return {
3276
+ kind: squareOutcomeOf(result?.status, squareMethodOf(attemptMethod)) === "failed" ? "failure" : "success",
3277
+ value: result ?? null,
3278
+ reason: "created"
3279
+ };
3280
+ finished = this.afterCreate(result ?? null, ctx, live(), attemptAmount, attemptMethod);
3281
+ return {
3282
+ kind: squareOutcomeOf(result?.status, squareMethodOf(attemptMethod)) === "failed" ? "failure" : "success",
3283
+ value: result ?? null,
3284
+ reason: "created"
3285
+ };
3286
+ } finally {
3287
+ if (live()) payment.markNotCharged();
3288
+ }
3289
+ }, { timeoutMs: this.config().paymentTimeoutMs() });
3290
+ this.processing.set(false);
3291
+ if ("refused" in run && run.refused) {
3292
+ ctx.setBusy(false);
3293
+ return;
3294
+ }
3295
+ if (run.kind === "unknown") return;
3296
+ if (!finished) ctx.setBusy(false);
3297
+ }
3298
+ refused(ctx) {
3299
+ if (!this.readiness.passSync()) {
3300
+ const reason = this.readiness.reasons()[0] ?? "checking";
3301
+ const message = this.labels.t(refusalLabelKey(reason));
3302
+ this.error.set(message);
3303
+ ctx.report("refused", { message });
3304
+ ctx.announce(message);
3305
+ return true;
3306
+ }
3307
+ if (this.attempt.paidLocked() || this.attempt.unknown()) {
3308
+ this.attempt.begin();
3309
+ return true;
3310
+ }
3311
+ return false;
3312
+ }
3313
+ onAttemptOutcome(outcome) {
3314
+ const ctx = this.ctx();
3315
+ if (outcome.kind === "unknown" && outcome.reason === "duplicate_suspected") {
3316
+ const message = this.labels.t("paymentAttempt.duplicate");
3317
+ this.error.set(message);
3318
+ ctx.report("duplicate_suspected", {
3319
+ message,
3320
+ attemptKey: outcome.attemptKey
3321
+ });
3322
+ ctx.announce(message);
3323
+ } else if (outcome.kind === "unknown") {
3324
+ this.payAmount = this.attempt.pinnedAmount() ?? this.payAmount;
3325
+ this.payMethod = this.attempt.pinnedMethod() ?? this.payMethod;
3326
+ const message = this.labels.t(outcome.reason === "offline" ? "paymentAttempt.offlineInFlight" : outcome.reason === "timeout" ? "paymentAttempt.timeout" : "paymentAttempt.checking");
3327
+ ctx.report("unknown", { message });
3328
+ ctx.announce(message);
3329
+ } else if (outcome.kind === "refused") ctx.report("refused", { message: this.labels.t(refusalLabelKey(outcome.reason ?? "")) });
3330
+ else if (outcome.kind === "succeeded" && outcome.reason === "other_tab") ctx.report("paid_elsewhere", {
3331
+ message: this.labels.t("paymentAttempt.paid"),
3332
+ attemptKey: outcome.attemptKey,
3333
+ ...outcome.method !== void 0 ? { paid: {
3334
+ amount: outcome.amount ?? null,
3335
+ method: outcome.method
3336
+ } } : {}
3337
+ });
3338
+ else if (outcome.kind === "succeeded" && (outcome.reason === "status_check" || outcome.reason === "host") && !this.done()) {
3339
+ const paid = {
3340
+ type: "stripe",
3341
+ paymentMethod: outcome.method ?? this.payMethod ?? ctx.method,
3342
+ amount: outcome.amount ?? this.payAmount ?? ctx.amount ?? this.lastAmount() ?? 0,
3343
+ processor: "square"
3344
+ };
3345
+ this.doneAmount = paid.amount;
3346
+ this.doneMethod = paid.paymentMethod;
3347
+ ctx.report("paid", { result: paid });
3348
+ ctx.announce(this.labels.t("paymentAttempt.succeededAfterCheck"));
3349
+ this.done.set(true);
3350
+ ctx.setBusy(false);
3351
+ ctx.complete(paid);
3352
+ } else if (outcome.kind === "failed") {
3353
+ if (outcome.reason === "status_check" || outcome.reason === "host") {
3354
+ const message = this.labels.t("paymentAttempt.failedAfterCheck");
3355
+ this.error.set(message);
3356
+ ctx.report("failed", { message });
3357
+ }
3358
+ this.payment()?.markNotCharged();
3359
+ ctx.setBusy(false);
3360
+ }
3361
+ }
3362
+ afterCreate(result, ctx, live, amount, method) {
3363
+ if (this.done() || this.confirmation()) return true;
3364
+ const money = formatCurrency(amount, { currency: ctx.currency });
3365
+ const outcome = squareOutcomeOf(result?.status, squareMethodOf(method));
3366
+ if (outcome === "failed") {
3367
+ if (live) {
3368
+ const message = result?.failureMessage || this.texts.notCompleted;
3369
+ this.error.set(message);
3370
+ ctx.report("failed", { message });
3371
+ }
3372
+ return false;
3373
+ }
3374
+ if (live && result && (result.processingFee !== void 0 || result.platformFee !== void 0 || result.totalAmount !== void 0)) this.resultFees.set({
3375
+ processingFee: result.processingFee,
3376
+ platformFee: result.platformFee,
3377
+ totalAmount: result.totalAmount,
3378
+ processingFeeLabel: result.processingFeeLabel,
3379
+ platformFeeLabel: result.platformFeeLabel
3380
+ });
3381
+ const paid = {
3382
+ type: "stripe",
3383
+ paymentMethod: method,
3384
+ amount,
3385
+ processor: "square"
3386
+ };
3387
+ this.doneAmount = amount;
3388
+ this.doneMethod = method;
3389
+ if (outcome === "paid") {
3390
+ ctx.report("paid", { result: paid });
3391
+ this.done.set(true);
3392
+ ctx.complete(paid);
3393
+ return true;
3394
+ }
3395
+ ctx.report("processing", { result: paid });
3396
+ this.confirmation.set(squareMethodOf(method) === "ach" ? {
3397
+ title: this.texts.achTitle,
3398
+ message: this.texts.achMessage(money)
3399
+ } : {
3400
+ title: this.texts.pendingTitle,
3401
+ message: this.texts.pendingMessage(money)
3402
+ });
3403
+ ctx.setExclusive(true);
3404
+ ctx.setBusy(false);
3405
+ afterNextRender(() => this.host.nativeElement.querySelector(".psq-notice")?.focus(), { injector: this.injector });
3406
+ return true;
3407
+ }
3408
+ finish() {
3409
+ const ctx = this.ctx();
3410
+ if (this.done()) return;
3411
+ this.done.set(true);
3412
+ ctx.complete({
3413
+ type: "stripe",
3414
+ paymentMethod: this.doneMethod ?? this.payMethod ?? ctx.method,
3415
+ amount: this.doneAmount ?? this.payAmount ?? ctx.amount ?? this.lastAmount() ?? 0,
3416
+ processor: "square"
3417
+ });
3418
+ }
3419
+ static {
3420
+ this.ɵfac = i0.ɵɵngDeclareFactory({
3421
+ minVersion: "12.0.0",
3422
+ version: "22.2.2",
3423
+ ngImport: i0,
3424
+ type: PaymentSquareBodyComponent,
3425
+ deps: [],
3426
+ target: i0.ɵɵFactoryTarget.Component
3427
+ });
3428
+ }
3429
+ static {
3430
+ this.ɵcmp = i0.ɵɵngDeclareComponent({
3431
+ minVersion: "17.0.0",
3432
+ version: "22.2.2",
3433
+ type: PaymentSquareBodyComponent,
3434
+ isStandalone: true,
3435
+ selector: "ui-payment-square-body",
3436
+ inputs: {
3437
+ ctx: {
3438
+ classPropertyName: "ctx",
3439
+ publicName: "ctx",
3440
+ isSignal: true,
3441
+ isRequired: true,
3442
+ transformFunction: null
3443
+ },
3444
+ config: {
3445
+ classPropertyName: "config",
3446
+ publicName: "config",
3447
+ isSignal: true,
3448
+ isRequired: true,
3449
+ transformFunction: null
3450
+ }
3451
+ },
3452
+ viewQueries: [{
3453
+ propertyName: "payment",
3454
+ first: true,
3455
+ predicate: SquarePaymentComponent,
3456
+ descendants: true,
3457
+ isSignal: true
3458
+ }],
3459
+ ngImport: i0,
3460
+ template: `
3461
+ <div class="psq">
3462
+ @if (confirmation(); as notice) {
3463
+ <ui-alert variant="success" [title]="notice.title" tabindex="-1" class="psq-notice" data-testid="square-method-confirmation">
3464
+ <p>{{ notice.message }}</p>
3465
+ <p>{{ receiptNote() }}</p>
3466
+ </ui-alert>
3467
+ } @else {
3468
+ <ui-payment-attempt-status [attempt]="attempt" [readiness]="readiness" [allowStartOver]="config().allowStartOver()" [showPaid]="!confirmation() && !done()" (retryLoad)="payment()?.reset()" />
3469
+ @if (ctx().amount == null) {
3470
+ <ui-hint data-testid="square-method-amount-needed">{{ texts.amountNeeded }}</ui-hint>
3471
+ }
3472
+ @if (estimateError()) {
3473
+ <div class="psq-error">
3474
+ <ui-alert variant="warning" data-testid="square-method-estimate-error">{{ estimateError() }}
3475
+ <ui-button variant="secondary" size="sm" data-testid="square-method-estimate-retry" (click)="retryEstimate()">{{ labels.t('common.tryAgain') }}</ui-button>
3476
+ </ui-alert>
3477
+ </div>
3478
+ }
3479
+ @if (lastAmount() != null) {
3480
+ <ui-square-payment #payment mode="payment" [method]="squareMethod()" [applicationId]="config().applicationId()" [locationId]="config().locationId()" [environment]="config().environment()"
3481
+ [amount]="chargedAmount()" [currency]="ctx().currency" [billingContact]="config().billingContact()" [accountHolderName]="config().accountHolderName()"
3482
+ [requireAchConsent]="config().requireAchConsent()" [cardStyle]="config().cardStyle()" [styleFromTokens]="true" [showSubmit]="false" [showErrors]="false"
3483
+ [showStatus]="false" [offlineOverride]="config().offlineOverride()" [disabled]="processing() || done() || attempt.unknown() || attempt.paidLocked()" [label]="labels.t('squarePaymentMethod.paymentDetails')" (ready)="onReady()" (failed)="onFailed($event)" (loadError)="onFailed($event)" />
3484
+ @if (totalCard(); as card) {
3485
+ <ui-kpi-card class="psq-total" data-testid="square-method-total" [label]="labels.t('squarePaymentMethod.totalCharged')" [value]="card.value" [subtitle]="card.subtitle" icon="dollar" color="blue" valueColor="blue" />
3486
+ }
3487
+ @if (feeRows().length) {
3488
+ <dl class="psq-fees" data-testid="square-method-fees" [attr.aria-label]="labels.t('squarePaymentMethod.paymentTotal')">
3489
+ @for (row of feeRows(); track row.key) {
3490
+ <div class="psq-fee" [attr.data-testid]="'square-fee-' + row.key"><dt>{{ row.label }}</dt><dd>{{ row.value }}</dd></div>
3491
+ }
3492
+ </dl>
3493
+ }
3494
+ @if (error()) { <div class="psq-error"><ui-alert variant="danger" data-testid="square-method-error">{{ error() }}</ui-alert></div> }
3495
+ }
3496
+ }
3497
+ </div>
3498
+ `,
3499
+ isInline: true,
3500
+ styles: ["ui-payment-square-body{display:block;min-width:0}ui-payment-square-body .psq-error{margin-top:12px}ui-payment-square-body .psq-total{display:block;margin-top:16px}ui-payment-square-body .psq-fees{margin:16px 0 0;padding:14px 16px;border:1px solid var(--ui-psp-border, #e2e8f0);border-radius:10px;font-size:.8125rem}ui-payment-square-body .psq-fee{display:flex;justify-content:space-between;gap:12px;padding:4px 0;color:var(--ui-psp-muted, #475569)}ui-payment-square-body .psq-fee dt,ui-payment-square-body .psq-fee dd{margin:0}ui-payment-square-body .psq-notice:focus{outline:none}ui-payment-square-body .psq-notice p{margin:0 0 6px}\n"],
3501
+ dependencies: [
3502
+ {
3503
+ kind: "component",
3504
+ type: AlertComponent,
3505
+ selector: "ui-alert",
3506
+ inputs: [
3507
+ "variant",
3508
+ "title",
3509
+ "dismissible",
3510
+ "dismissAriaLabel",
3511
+ "quiet",
3512
+ "compact",
3513
+ "inline",
3514
+ "fill"
3515
+ ],
3516
+ outputs: ["dismissed"]
3517
+ },
3518
+ {
3519
+ kind: "component",
3520
+ type: ButtonComponent,
3521
+ selector: "ui-button",
3522
+ inputs: [
3523
+ "variant",
3524
+ "routerLink",
3525
+ "queryParams",
3526
+ "fragment",
3527
+ "state",
3528
+ "href",
3529
+ "target",
3530
+ "rel",
3531
+ "shortLabel",
3532
+ "shortBelow",
3533
+ "color",
3534
+ "active",
3535
+ "size",
3536
+ "type",
3537
+ "disabled",
3538
+ "loading",
3539
+ "fullWidth",
3540
+ "ariaLabel",
3541
+ "ariaExpanded",
3542
+ "ariaPressed",
3543
+ "ariaDescribedBy",
3544
+ "modal-footer-left",
3545
+ "modal-footer-right"
3546
+ ]
3547
+ },
3548
+ {
3549
+ kind: "component",
3550
+ type: HintComponent,
3551
+ selector: "ui-hint"
3552
+ },
3553
+ {
3554
+ kind: "component",
3555
+ type: KpiCardComponent,
3556
+ selector: "ui-kpi-card",
3557
+ inputs: [
3558
+ "label",
3559
+ "value",
3560
+ "subtitle",
3561
+ "icon",
3562
+ "color",
3563
+ "highlight",
3564
+ "clickable",
3565
+ "valueColor",
3566
+ "loading",
3567
+ "loadingLabel",
3568
+ "background",
3569
+ "progress",
3570
+ "progressMax",
3571
+ "progressSize",
3572
+ "progressStrokeWidth",
3573
+ "progressVariant",
3574
+ "progressAriaLabel",
3575
+ "progressValueText"
3576
+ ]
3577
+ },
3578
+ {
3579
+ kind: "component",
3580
+ type: PaymentAttemptStatusComponent,
3581
+ selector: "ui-payment-attempt-status",
3582
+ inputs: [
3583
+ "attempt",
3584
+ "showPaid",
3585
+ "allowStartOver",
3586
+ "readiness"
3587
+ ],
3588
+ outputs: ["retryLoad"]
3589
+ },
3590
+ {
3591
+ kind: "component",
3592
+ type: SquarePaymentComponent,
3593
+ selector: "ui-square-payment",
3594
+ inputs: [
3595
+ "mountOnly",
3596
+ "mode",
3597
+ "method",
3598
+ "methods",
3599
+ "applicationId",
3600
+ "locationId",
3601
+ "environment",
3602
+ "amount",
3603
+ "currency",
3604
+ "billingContact",
3605
+ "verifyBuyer",
3606
+ "accountHolderName",
3607
+ "requireAchConsent",
3608
+ "achConsentText",
3609
+ "achRedirectUri",
3610
+ "achTransactionId",
3611
+ "cardOptions",
3612
+ "cardStyle",
3613
+ "styleFromTokens",
3614
+ "showStatus",
3615
+ "payableRef",
3616
+ "attemptKey",
3617
+ "checkStatus",
3618
+ "paid",
3619
+ "hostPending",
3620
+ "statusPollMs",
3621
+ "statusPollMaxMs",
3622
+ "statusCheckTimeoutMs",
3623
+ "statusFailGraceMs",
3624
+ "allowStartOver",
3625
+ "offlineOverride",
3626
+ "hostSilenceMs",
3627
+ "readinessCheck",
3628
+ "readinessTimeoutMs",
3629
+ "readinessEveryMs",
3630
+ "submitLabel",
3631
+ "showSubmit",
3632
+ "disabled",
3633
+ "pending",
3634
+ "label",
3635
+ "required",
3636
+ "mountId",
3637
+ "mountClass",
3638
+ "mountTestId",
3639
+ "errorTestId",
3640
+ "holderTestId",
3641
+ "showErrors",
3642
+ "errorDisplay",
3643
+ "errorMessages",
3644
+ "errorFallback",
3645
+ "loadErrorMessage",
3646
+ "a11yMessages"
3647
+ ],
3648
+ outputs: [
3649
+ "methodChange",
3650
+ "squareReady",
3651
+ "ready",
3652
+ "inFlightChange",
3653
+ "outcome",
3654
+ "attemptKeyChange",
3655
+ "readinessChange",
3656
+ "tokenized",
3657
+ "failed",
3658
+ "loadError"
3659
+ ]
3660
+ }
3661
+ ],
3662
+ changeDetection: i0.ChangeDetectionStrategy.OnPush,
3663
+ encapsulation: i0.ViewEncapsulation.None
3664
+ });
3665
+ }
3666
+ };
3667
+ i0.ɵɵngDeclareClassMetadata({
3668
+ minVersion: "12.0.0",
3669
+ version: "22.2.2",
3670
+ ngImport: i0,
3671
+ type: PaymentSquareBodyComponent,
3672
+ decorators: [{
3673
+ type: Component,
3674
+ args: [{
3675
+ selector: "ui-payment-square-body",
3676
+ standalone: true,
3677
+ changeDetection: ChangeDetectionStrategy.OnPush,
3678
+ encapsulation: ViewEncapsulation.None,
3679
+ imports: [
3680
+ AlertComponent,
3681
+ ButtonComponent,
3682
+ HintComponent,
3683
+ KpiCardComponent,
3684
+ PaymentAttemptStatusComponent,
3685
+ SquarePaymentComponent
3686
+ ],
3687
+ template: `
3688
+ <div class="psq">
3689
+ @if (confirmation(); as notice) {
3690
+ <ui-alert variant="success" [title]="notice.title" tabindex="-1" class="psq-notice" data-testid="square-method-confirmation">
3691
+ <p>{{ notice.message }}</p>
3692
+ <p>{{ receiptNote() }}</p>
3693
+ </ui-alert>
3694
+ } @else {
3695
+ <ui-payment-attempt-status [attempt]="attempt" [readiness]="readiness" [allowStartOver]="config().allowStartOver()" [showPaid]="!confirmation() && !done()" (retryLoad)="payment()?.reset()" />
3696
+ @if (ctx().amount == null) {
3697
+ <ui-hint data-testid="square-method-amount-needed">{{ texts.amountNeeded }}</ui-hint>
3698
+ }
3699
+ @if (estimateError()) {
3700
+ <div class="psq-error">
3701
+ <ui-alert variant="warning" data-testid="square-method-estimate-error">{{ estimateError() }}
3702
+ <ui-button variant="secondary" size="sm" data-testid="square-method-estimate-retry" (click)="retryEstimate()">{{ labels.t('common.tryAgain') }}</ui-button>
3703
+ </ui-alert>
3704
+ </div>
3705
+ }
3706
+ @if (lastAmount() != null) {
3707
+ <ui-square-payment #payment mode="payment" [method]="squareMethod()" [applicationId]="config().applicationId()" [locationId]="config().locationId()" [environment]="config().environment()"
3708
+ [amount]="chargedAmount()" [currency]="ctx().currency" [billingContact]="config().billingContact()" [accountHolderName]="config().accountHolderName()"
3709
+ [requireAchConsent]="config().requireAchConsent()" [cardStyle]="config().cardStyle()" [styleFromTokens]="true" [showSubmit]="false" [showErrors]="false"
3710
+ [showStatus]="false" [offlineOverride]="config().offlineOverride()" [disabled]="processing() || done() || attempt.unknown() || attempt.paidLocked()" [label]="labels.t('squarePaymentMethod.paymentDetails')" (ready)="onReady()" (failed)="onFailed($event)" (loadError)="onFailed($event)" />
3711
+ @if (totalCard(); as card) {
3712
+ <ui-kpi-card class="psq-total" data-testid="square-method-total" [label]="labels.t('squarePaymentMethod.totalCharged')" [value]="card.value" [subtitle]="card.subtitle" icon="dollar" color="blue" valueColor="blue" />
3713
+ }
3714
+ @if (feeRows().length) {
3715
+ <dl class="psq-fees" data-testid="square-method-fees" [attr.aria-label]="labels.t('squarePaymentMethod.paymentTotal')">
3716
+ @for (row of feeRows(); track row.key) {
3717
+ <div class="psq-fee" [attr.data-testid]="'square-fee-' + row.key"><dt>{{ row.label }}</dt><dd>{{ row.value }}</dd></div>
3718
+ }
3719
+ </dl>
3720
+ }
3721
+ @if (error()) { <div class="psq-error"><ui-alert variant="danger" data-testid="square-method-error">{{ error() }}</ui-alert></div> }
3722
+ }
3723
+ }
3724
+ </div>
3725
+ `,
3726
+ styles: ["ui-payment-square-body{display:block;min-width:0}ui-payment-square-body .psq-error{margin-top:12px}ui-payment-square-body .psq-total{display:block;margin-top:16px}ui-payment-square-body .psq-fees{margin:16px 0 0;padding:14px 16px;border:1px solid var(--ui-psp-border, #e2e8f0);border-radius:10px;font-size:.8125rem}ui-payment-square-body .psq-fee{display:flex;justify-content:space-between;gap:12px;padding:4px 0;color:var(--ui-psp-muted, #475569)}ui-payment-square-body .psq-fee dt,ui-payment-square-body .psq-fee dd{margin:0}ui-payment-square-body .psq-notice:focus{outline:none}ui-payment-square-body .psq-notice p{margin:0 0 6px}\n"]
3727
+ }]
3728
+ }],
3729
+ ctorParameters: () => [],
3730
+ propDecorators: {
3731
+ ctx: [{
3732
+ type: i0.Input,
3733
+ args: [{
3734
+ isSignal: true,
3735
+ alias: "ctx",
3736
+ required: true
3737
+ }]
3738
+ }],
3739
+ config: [{
3740
+ type: i0.Input,
3741
+ args: [{
3742
+ isSignal: true,
3743
+ alias: "config",
3744
+ required: true
3745
+ }]
3746
+ }],
3747
+ payment: [{
3748
+ type: i0.ViewChild,
3749
+ args: [i0.forwardRef(() => SquarePaymentComponent), { isSignal: true }]
3750
+ }]
3751
+ }
3752
+ });
3753
+ var SquarePaymentMethodComponent = class SquarePaymentMethodComponent extends PaymentMethodPlugin {
3754
+ constructor() {
3755
+ super(...arguments);
3756
+ this.self = this;
3757
+ this.createPayment = input(null, ...ngDevMode ? [{ debugName: "createPayment" }] : /* istanbul ignore next */ []);
3758
+ this.estimateFees = input(null, ...ngDevMode ? [{ debugName: "estimateFees" }] : /* istanbul ignore next */ []);
3759
+ this.applicationId = input(null, ...ngDevMode ? [{ debugName: "applicationId" }] : /* istanbul ignore next */ []);
3760
+ this.locationId = input(null, ...ngDevMode ? [{ debugName: "locationId" }] : /* istanbul ignore next */ []);
3761
+ this.environment = input(null, ...ngDevMode ? [{ debugName: "environment" }] : /* istanbul ignore next */ []);
3762
+ this.billingContact = input(null, ...ngDevMode ? [{ debugName: "billingContact" }] : /* istanbul ignore next */ []);
3763
+ this.accountHolderName = input("", ...ngDevMode ? [{ debugName: "accountHolderName" }] : /* istanbul ignore next */ []);
3764
+ this.requireAchConsent = input(true, ...ngDevMode ? [{ debugName: "requireAchConsent" }] : /* istanbul ignore next */ []);
3765
+ this.cardStyle = input(null, ...ngDevMode ? [{ debugName: "cardStyle" }] : /* istanbul ignore next */ []);
3766
+ this.methodListInput = input(null, {
3767
+ ...ngDevMode ? { debugName: "methodListInput" } : /* istanbul ignore next */ {},
3768
+ alias: "methodList"
3769
+ });
3770
+ this.methodList = computed(() => this.methodListInput() ?? SQUARE_PAYMENT_METHOD_VALUES.map((value) => ({
3771
+ value,
3772
+ label: squareMethodLabel(value)
3773
+ })), ...ngDevMode ? [{ debugName: "methodList" }] : /* istanbul ignore next */ []);
3774
+ this.estimateTimeoutMs = input(1e4, ...ngDevMode ? [{ debugName: "estimateTimeoutMs" }] : /* istanbul ignore next */ []);
3775
+ this.payableRef = input(null, ...ngDevMode ? [{ debugName: "payableRef" }] : /* istanbul ignore next */ []);
3776
+ this.attemptKey = input(null, ...ngDevMode ? [{ debugName: "attemptKey" }] : /* istanbul ignore next */ []);
3777
+ this.checkStatus = input(null, ...ngDevMode ? [{ debugName: "checkStatus" }] : /* istanbul ignore next */ []);
3778
+ this.paid = input(false, ...ngDevMode ? [{ debugName: "paid" }] : /* istanbul ignore next */ []);
3779
+ this.hostPending = input(false, ...ngDevMode ? [{ debugName: "hostPending" }] : /* istanbul ignore next */ []);
3780
+ this.statusPollMs = input(PAYMENT_STATUS_POLL_MS, ...ngDevMode ? [{ debugName: "statusPollMs" }] : /* istanbul ignore next */ []);
3781
+ this.statusPollMaxMs = input(PAYMENT_STATUS_POLL_MAX_MS, ...ngDevMode ? [{ debugName: "statusPollMaxMs" }] : /* istanbul ignore next */ []);
3782
+ this.statusCheckTimeoutMs = input(PAYMENT_STATUS_CHECK_TIMEOUT_MS, ...ngDevMode ? [{ debugName: "statusCheckTimeoutMs" }] : /* istanbul ignore next */ []);
3783
+ this.statusFailGraceMs = input(PAYMENT_STATUS_FAIL_GRACE_MS, ...ngDevMode ? [{ debugName: "statusFailGraceMs" }] : /* istanbul ignore next */ []);
3784
+ this.allowStartOver = input(false, ...ngDevMode ? [{ debugName: "allowStartOver" }] : /* istanbul ignore next */ []);
3785
+ this.offlineOverride = input(false, ...ngDevMode ? [{ debugName: "offlineOverride" }] : /* istanbul ignore next */ []);
3786
+ this.authTimeoutMs = input(PAYMENT_AUTH_TIMEOUT_MS, ...ngDevMode ? [{ debugName: "authTimeoutMs" }] : /* istanbul ignore next */ []);
3787
+ this.paymentTimeoutMs = input(PAYMENT_REQUEST_TIMEOUT_MS, ...ngDevMode ? [{ debugName: "paymentTimeoutMs" }] : /* istanbul ignore next */ []);
3788
+ this.readinessCheck = input(null, ...ngDevMode ? [{ debugName: "readinessCheck" }] : /* istanbul ignore next */ []);
3789
+ this.readinessTimeoutMs = input(PAYMENT_READINESS_TIMEOUT_MS, ...ngDevMode ? [{ debugName: "readinessTimeoutMs" }] : /* istanbul ignore next */ []);
3790
+ this.readinessEveryMs = input(PAYMENT_READINESS_EVERY_MS, ...ngDevMode ? [{ debugName: "readinessEveryMs" }] : /* istanbul ignore next */ []);
3791
+ this.feesRequired = input(false, ...ngDevMode ? [{ debugName: "feesRequired" }] : /* istanbul ignore next */ []);
3792
+ this.receiptNoteInput = input(null, {
3793
+ ...ngDevMode ? { debugName: "receiptNoteInput" } : /* istanbul ignore next */ {},
3794
+ alias: "receiptNote"
3795
+ });
3796
+ this.receiptNote = computed(() => this.receiptNoteInput() ?? SQUARE_METHOD_TEXTS.receiptNote, ...ngDevMode ? [{ debugName: "receiptNote" }] : /* istanbul ignore next */ []);
3797
+ this.body = viewChild("body", ...ngDevMode ? [{ debugName: "body" }] : /* istanbul ignore next */ []);
3798
+ this.controls = signal(null, ...ngDevMode ? [{ debugName: "controls" }] : /* istanbul ignore next */ []);
3799
+ this.methods = this.methodList;
3800
+ this.template = this.body;
3801
+ }
3802
+ attachControls(controls) {
3803
+ this.controls.set(controls);
3804
+ }
3805
+ detachControls(controls) {
3806
+ if (this.controls() === controls) this.controls.set(null);
3807
+ }
3808
+ markUnknown() {
3809
+ this.controls()?.markUnknown();
3810
+ }
3811
+ markSucceeded() {
3812
+ this.controls()?.markSucceeded();
3813
+ }
3814
+ markFailed() {
3815
+ this.controls()?.markFailed();
3816
+ }
3817
+ markNotCharged() {
3818
+ this.controls()?.markNotCharged();
3819
+ }
3820
+ resetPaid() {
3821
+ this.controls()?.resetPaid();
3822
+ }
3823
+ static {
3824
+ this.ɵfac = i0.ɵɵngDeclareFactory({
3825
+ minVersion: "12.0.0",
3826
+ version: "22.2.2",
3827
+ ngImport: i0,
3828
+ type: SquarePaymentMethodComponent,
3829
+ deps: null,
3830
+ target: i0.ɵɵFactoryTarget.Component
3831
+ });
3832
+ }
3833
+ static {
3834
+ this.ɵcmp = i0.ɵɵngDeclareComponent({
3835
+ minVersion: "17.2.0",
3836
+ version: "22.2.2",
3837
+ type: SquarePaymentMethodComponent,
3838
+ isStandalone: true,
3839
+ selector: "ui-square-payment-method",
3840
+ inputs: {
3841
+ createPayment: {
3842
+ classPropertyName: "createPayment",
3843
+ publicName: "createPayment",
3844
+ isSignal: true,
3845
+ isRequired: false,
3846
+ transformFunction: null
3847
+ },
3848
+ estimateFees: {
3849
+ classPropertyName: "estimateFees",
3850
+ publicName: "estimateFees",
3851
+ isSignal: true,
3852
+ isRequired: false,
3853
+ transformFunction: null
3854
+ },
3855
+ applicationId: {
3856
+ classPropertyName: "applicationId",
3857
+ publicName: "applicationId",
3858
+ isSignal: true,
3859
+ isRequired: false,
3860
+ transformFunction: null
3861
+ },
3862
+ locationId: {
3863
+ classPropertyName: "locationId",
3864
+ publicName: "locationId",
3865
+ isSignal: true,
3866
+ isRequired: false,
3867
+ transformFunction: null
3868
+ },
3869
+ environment: {
3870
+ classPropertyName: "environment",
3871
+ publicName: "environment",
3872
+ isSignal: true,
3873
+ isRequired: false,
3874
+ transformFunction: null
3875
+ },
3876
+ billingContact: {
3877
+ classPropertyName: "billingContact",
3878
+ publicName: "billingContact",
3879
+ isSignal: true,
3880
+ isRequired: false,
3881
+ transformFunction: null
3882
+ },
3883
+ accountHolderName: {
3884
+ classPropertyName: "accountHolderName",
3885
+ publicName: "accountHolderName",
3886
+ isSignal: true,
3887
+ isRequired: false,
3888
+ transformFunction: null
3889
+ },
3890
+ requireAchConsent: {
3891
+ classPropertyName: "requireAchConsent",
3892
+ publicName: "requireAchConsent",
3893
+ isSignal: true,
3894
+ isRequired: false,
3895
+ transformFunction: null
3896
+ },
3897
+ cardStyle: {
3898
+ classPropertyName: "cardStyle",
3899
+ publicName: "cardStyle",
3900
+ isSignal: true,
3901
+ isRequired: false,
3902
+ transformFunction: null
3903
+ },
3904
+ methodListInput: {
3905
+ classPropertyName: "methodListInput",
3906
+ publicName: "methodList",
3907
+ isSignal: true,
3908
+ isRequired: false,
3909
+ transformFunction: null
3910
+ },
3911
+ estimateTimeoutMs: {
3912
+ classPropertyName: "estimateTimeoutMs",
3913
+ publicName: "estimateTimeoutMs",
3914
+ isSignal: true,
3915
+ isRequired: false,
3916
+ transformFunction: null
3917
+ },
3918
+ payableRef: {
3919
+ classPropertyName: "payableRef",
3920
+ publicName: "payableRef",
3921
+ isSignal: true,
3922
+ isRequired: false,
3923
+ transformFunction: null
3924
+ },
3925
+ attemptKey: {
3926
+ classPropertyName: "attemptKey",
3927
+ publicName: "attemptKey",
3928
+ isSignal: true,
3929
+ isRequired: false,
3930
+ transformFunction: null
3931
+ },
3932
+ checkStatus: {
3933
+ classPropertyName: "checkStatus",
3934
+ publicName: "checkStatus",
3935
+ isSignal: true,
3936
+ isRequired: false,
3937
+ transformFunction: null
3938
+ },
3939
+ paid: {
3940
+ classPropertyName: "paid",
3941
+ publicName: "paid",
3942
+ isSignal: true,
3943
+ isRequired: false,
3944
+ transformFunction: null
3945
+ },
3946
+ hostPending: {
3947
+ classPropertyName: "hostPending",
3948
+ publicName: "hostPending",
3949
+ isSignal: true,
3950
+ isRequired: false,
3951
+ transformFunction: null
3952
+ },
3953
+ statusPollMs: {
3954
+ classPropertyName: "statusPollMs",
3955
+ publicName: "statusPollMs",
3956
+ isSignal: true,
3957
+ isRequired: false,
3958
+ transformFunction: null
3959
+ },
3960
+ statusPollMaxMs: {
3961
+ classPropertyName: "statusPollMaxMs",
3962
+ publicName: "statusPollMaxMs",
3963
+ isSignal: true,
3964
+ isRequired: false,
3965
+ transformFunction: null
3966
+ },
3967
+ statusCheckTimeoutMs: {
3968
+ classPropertyName: "statusCheckTimeoutMs",
3969
+ publicName: "statusCheckTimeoutMs",
3970
+ isSignal: true,
3971
+ isRequired: false,
3972
+ transformFunction: null
3973
+ },
3974
+ statusFailGraceMs: {
3975
+ classPropertyName: "statusFailGraceMs",
3976
+ publicName: "statusFailGraceMs",
3977
+ isSignal: true,
3978
+ isRequired: false,
3979
+ transformFunction: null
3980
+ },
3981
+ allowStartOver: {
3982
+ classPropertyName: "allowStartOver",
3983
+ publicName: "allowStartOver",
3984
+ isSignal: true,
3985
+ isRequired: false,
3986
+ transformFunction: null
3987
+ },
3988
+ offlineOverride: {
3989
+ classPropertyName: "offlineOverride",
3990
+ publicName: "offlineOverride",
3991
+ isSignal: true,
3992
+ isRequired: false,
3993
+ transformFunction: null
3994
+ },
3995
+ authTimeoutMs: {
3996
+ classPropertyName: "authTimeoutMs",
3997
+ publicName: "authTimeoutMs",
3998
+ isSignal: true,
3999
+ isRequired: false,
4000
+ transformFunction: null
4001
+ },
4002
+ paymentTimeoutMs: {
4003
+ classPropertyName: "paymentTimeoutMs",
4004
+ publicName: "paymentTimeoutMs",
4005
+ isSignal: true,
4006
+ isRequired: false,
4007
+ transformFunction: null
4008
+ },
4009
+ readinessCheck: {
4010
+ classPropertyName: "readinessCheck",
4011
+ publicName: "readinessCheck",
4012
+ isSignal: true,
4013
+ isRequired: false,
4014
+ transformFunction: null
4015
+ },
4016
+ readinessTimeoutMs: {
4017
+ classPropertyName: "readinessTimeoutMs",
4018
+ publicName: "readinessTimeoutMs",
4019
+ isSignal: true,
4020
+ isRequired: false,
4021
+ transformFunction: null
4022
+ },
4023
+ readinessEveryMs: {
4024
+ classPropertyName: "readinessEveryMs",
4025
+ publicName: "readinessEveryMs",
4026
+ isSignal: true,
4027
+ isRequired: false,
4028
+ transformFunction: null
4029
+ },
4030
+ feesRequired: {
4031
+ classPropertyName: "feesRequired",
4032
+ publicName: "feesRequired",
4033
+ isSignal: true,
4034
+ isRequired: false,
4035
+ transformFunction: null
4036
+ },
4037
+ receiptNoteInput: {
4038
+ classPropertyName: "receiptNoteInput",
4039
+ publicName: "receiptNote",
4040
+ isSignal: true,
4041
+ isRequired: false,
4042
+ transformFunction: null
4043
+ }
4044
+ },
4045
+ host: { styleAttribute: "display: none" },
4046
+ providers: [{
4047
+ provide: PAYMENT_METHOD_PLUGIN,
4048
+ useExisting: forwardRef(() => SquarePaymentMethodComponent)
4049
+ }],
4050
+ viewQueries: [{
4051
+ propertyName: "body",
4052
+ first: true,
4053
+ predicate: ["body"],
4054
+ descendants: true,
4055
+ isSignal: true
4056
+ }],
4057
+ usesInheritance: true,
4058
+ ngImport: i0,
4059
+ template: `<ng-template #body let-ctx><ui-payment-square-body [ctx]="ctx" [config]="self" /></ng-template>`,
4060
+ isInline: true,
4061
+ dependencies: [{
4062
+ kind: "component",
4063
+ type: PaymentSquareBodyComponent,
4064
+ selector: "ui-payment-square-body",
4065
+ inputs: ["ctx", "config"]
4066
+ }],
4067
+ changeDetection: i0.ChangeDetectionStrategy.OnPush
4068
+ });
4069
+ }
4070
+ };
4071
+ i0.ɵɵngDeclareClassMetadata({
4072
+ minVersion: "12.0.0",
4073
+ version: "22.2.2",
4074
+ ngImport: i0,
4075
+ type: SquarePaymentMethodComponent,
4076
+ decorators: [{
4077
+ type: Component,
4078
+ args: [{
4079
+ selector: "ui-square-payment-method",
4080
+ standalone: true,
4081
+ changeDetection: ChangeDetectionStrategy.OnPush,
4082
+ imports: [PaymentSquareBodyComponent],
4083
+ providers: [{
4084
+ provide: PAYMENT_METHOD_PLUGIN,
4085
+ useExisting: forwardRef(() => SquarePaymentMethodComponent)
4086
+ }],
4087
+ host: { style: "display: none" },
4088
+ template: `<ng-template #body let-ctx><ui-payment-square-body [ctx]="ctx" [config]="self" /></ng-template>`
4089
+ }]
4090
+ }],
4091
+ propDecorators: {
4092
+ createPayment: [{
4093
+ type: i0.Input,
4094
+ args: [{
4095
+ isSignal: true,
4096
+ alias: "createPayment",
4097
+ required: false
4098
+ }]
4099
+ }],
4100
+ estimateFees: [{
4101
+ type: i0.Input,
4102
+ args: [{
4103
+ isSignal: true,
4104
+ alias: "estimateFees",
4105
+ required: false
4106
+ }]
4107
+ }],
4108
+ applicationId: [{
4109
+ type: i0.Input,
4110
+ args: [{
4111
+ isSignal: true,
4112
+ alias: "applicationId",
4113
+ required: false
4114
+ }]
4115
+ }],
4116
+ locationId: [{
4117
+ type: i0.Input,
4118
+ args: [{
4119
+ isSignal: true,
4120
+ alias: "locationId",
4121
+ required: false
4122
+ }]
4123
+ }],
4124
+ environment: [{
4125
+ type: i0.Input,
4126
+ args: [{
4127
+ isSignal: true,
4128
+ alias: "environment",
4129
+ required: false
4130
+ }]
4131
+ }],
4132
+ billingContact: [{
4133
+ type: i0.Input,
4134
+ args: [{
4135
+ isSignal: true,
4136
+ alias: "billingContact",
4137
+ required: false
4138
+ }]
4139
+ }],
4140
+ accountHolderName: [{
4141
+ type: i0.Input,
4142
+ args: [{
4143
+ isSignal: true,
4144
+ alias: "accountHolderName",
4145
+ required: false
4146
+ }]
4147
+ }],
4148
+ requireAchConsent: [{
4149
+ type: i0.Input,
4150
+ args: [{
4151
+ isSignal: true,
4152
+ alias: "requireAchConsent",
4153
+ required: false
4154
+ }]
4155
+ }],
4156
+ cardStyle: [{
4157
+ type: i0.Input,
4158
+ args: [{
4159
+ isSignal: true,
4160
+ alias: "cardStyle",
4161
+ required: false
4162
+ }]
4163
+ }],
4164
+ methodListInput: [{
4165
+ type: i0.Input,
4166
+ args: [{
4167
+ isSignal: true,
4168
+ alias: "methodList",
4169
+ required: false
4170
+ }]
4171
+ }],
4172
+ estimateTimeoutMs: [{
4173
+ type: i0.Input,
4174
+ args: [{
4175
+ isSignal: true,
4176
+ alias: "estimateTimeoutMs",
4177
+ required: false
4178
+ }]
4179
+ }],
4180
+ payableRef: [{
4181
+ type: i0.Input,
4182
+ args: [{
4183
+ isSignal: true,
4184
+ alias: "payableRef",
4185
+ required: false
4186
+ }]
4187
+ }],
4188
+ attemptKey: [{
4189
+ type: i0.Input,
4190
+ args: [{
4191
+ isSignal: true,
4192
+ alias: "attemptKey",
4193
+ required: false
4194
+ }]
4195
+ }],
4196
+ checkStatus: [{
4197
+ type: i0.Input,
4198
+ args: [{
4199
+ isSignal: true,
4200
+ alias: "checkStatus",
4201
+ required: false
4202
+ }]
4203
+ }],
4204
+ paid: [{
4205
+ type: i0.Input,
4206
+ args: [{
4207
+ isSignal: true,
4208
+ alias: "paid",
4209
+ required: false
4210
+ }]
4211
+ }],
4212
+ hostPending: [{
4213
+ type: i0.Input,
4214
+ args: [{
4215
+ isSignal: true,
4216
+ alias: "hostPending",
4217
+ required: false
4218
+ }]
4219
+ }],
4220
+ statusPollMs: [{
4221
+ type: i0.Input,
4222
+ args: [{
4223
+ isSignal: true,
4224
+ alias: "statusPollMs",
4225
+ required: false
4226
+ }]
4227
+ }],
4228
+ statusPollMaxMs: [{
4229
+ type: i0.Input,
4230
+ args: [{
4231
+ isSignal: true,
4232
+ alias: "statusPollMaxMs",
4233
+ required: false
4234
+ }]
4235
+ }],
4236
+ statusCheckTimeoutMs: [{
4237
+ type: i0.Input,
4238
+ args: [{
4239
+ isSignal: true,
4240
+ alias: "statusCheckTimeoutMs",
4241
+ required: false
4242
+ }]
4243
+ }],
4244
+ statusFailGraceMs: [{
4245
+ type: i0.Input,
4246
+ args: [{
4247
+ isSignal: true,
4248
+ alias: "statusFailGraceMs",
4249
+ required: false
4250
+ }]
4251
+ }],
4252
+ allowStartOver: [{
4253
+ type: i0.Input,
4254
+ args: [{
4255
+ isSignal: true,
4256
+ alias: "allowStartOver",
4257
+ required: false
4258
+ }]
4259
+ }],
4260
+ offlineOverride: [{
4261
+ type: i0.Input,
4262
+ args: [{
4263
+ isSignal: true,
4264
+ alias: "offlineOverride",
4265
+ required: false
4266
+ }]
4267
+ }],
4268
+ authTimeoutMs: [{
4269
+ type: i0.Input,
4270
+ args: [{
4271
+ isSignal: true,
4272
+ alias: "authTimeoutMs",
4273
+ required: false
4274
+ }]
4275
+ }],
4276
+ paymentTimeoutMs: [{
4277
+ type: i0.Input,
4278
+ args: [{
4279
+ isSignal: true,
4280
+ alias: "paymentTimeoutMs",
4281
+ required: false
4282
+ }]
4283
+ }],
4284
+ readinessCheck: [{
4285
+ type: i0.Input,
4286
+ args: [{
4287
+ isSignal: true,
4288
+ alias: "readinessCheck",
4289
+ required: false
4290
+ }]
4291
+ }],
4292
+ readinessTimeoutMs: [{
4293
+ type: i0.Input,
4294
+ args: [{
4295
+ isSignal: true,
4296
+ alias: "readinessTimeoutMs",
4297
+ required: false
4298
+ }]
4299
+ }],
4300
+ readinessEveryMs: [{
4301
+ type: i0.Input,
4302
+ args: [{
4303
+ isSignal: true,
4304
+ alias: "readinessEveryMs",
4305
+ required: false
4306
+ }]
4307
+ }],
4308
+ feesRequired: [{
4309
+ type: i0.Input,
4310
+ args: [{
4311
+ isSignal: true,
4312
+ alias: "feesRequired",
4313
+ required: false
4314
+ }]
4315
+ }],
4316
+ receiptNoteInput: [{
4317
+ type: i0.Input,
4318
+ args: [{
4319
+ isSignal: true,
4320
+ alias: "receiptNote",
4321
+ required: false
4322
+ }]
4323
+ }],
4324
+ body: [{
4325
+ type: i0.ViewChild,
4326
+ args: ["body", { isSignal: true }]
4327
+ }]
4328
+ }
4329
+ });
4330
+ export { SQUARE_A11Y_MESSAGES, SQUARE_FIELD_ERROR_KEYS, SQUARE_LOADER, SQUARE_METHOD_TEXTS, SQUARE_PAYMENT_DEFAULTS, SQUARE_PAYMENT_ERROR_KEYS, SQUARE_PAYMENT_METHOD_VALUES, SQUARE_SANDBOX_SDK_URL, SQUARE_SDK_URL, SQUARE_TYPE_ERROR_KEYS, SquareConnectComponent, SquareConnectFlow, SquareLoadError, SquarePaymentComponent, SquarePaymentMethodComponent, defaultSquareLoader, failureFromTokenResult, getSquareErrorMessage, getSquarePaymentErrorMessage, isSquareUrl, newIdempotencyKey, normalizeSquareDetails, provideSquarePayment, readSquareCardStyle, squareConnectNotice, squareMethodLabel, squareOutcomeOf, squareSdkUrl };
4331
+
4332
+ //# sourceMappingURL=forgeroute-ui-square.mjs.map