@forgeroute/ui 0.5.1 → 0.5.3

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.
@@ -1,6 +1,6 @@
1
1
  import * as i0 from "@angular/core";
2
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, refusalLabelKey, uiText, warnQueuedPayment, wasQueuedOffline } from "@forgeroute/ui";
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, isAwaitingVerificationError, isDarkPage, isFinalPaymentRefusal, paymentErrorLabelKey, uiText, warnQueuedPayment, wasQueuedOffline } from "@forgeroute/ui";
4
4
  import { DOCUMENT, NgTemplateOutlet, isPlatformBrowser } from "@angular/common";
5
5
  import * as i1 from "@angular/forms";
6
6
  import { FormsModule } from "@angular/forms";
@@ -664,7 +664,7 @@ var SquarePaymentComponent = class SquarePaymentComponent {
664
664
  attemptKey: this.attempt.key(),
665
665
  reason
666
666
  });
667
- this.fail(squareFailure(reason, this.labels.t(refusalLabelKey(reason)), "validate"));
667
+ this.fail(squareFailure(reason, this.labels.t(this.readiness.labelKeyFor(reason)), "validate"));
668
668
  return true;
669
669
  }
670
670
  if (this.attempt.inFlight()) return true;
@@ -2946,6 +2946,7 @@ var PaymentSquareBodyComponent = class PaymentSquareBodyComponent {
2946
2946
  this.processing = signal(false, ...ngDevMode ? [{ debugName: "processing" }] : /* istanbul ignore next */ []);
2947
2947
  this.done = signal(false, ...ngDevMode ? [{ debugName: "done" }] : /* istanbul ignore next */ []);
2948
2948
  this.error = signal("", ...ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []);
2949
+ this.finalRefusal = signal(null, ...ngDevMode ? [{ debugName: "finalRefusal" }] : /* istanbul ignore next */ []);
2949
2950
  this.estimate = signal(null, ...ngDevMode ? [{ debugName: "estimate" }] : /* istanbul ignore next */ []);
2950
2951
  this.estimating = signal(false, ...ngDevMode ? [{ debugName: "estimating" }] : /* istanbul ignore next */ []);
2951
2952
  this.estimateError = signal("", ...ngDevMode ? [{ debugName: "estimateError" }] : /* istanbul ignore next */ []);
@@ -3050,6 +3051,15 @@ var PaymentSquareBodyComponent = class PaymentSquareBodyComponent {
3050
3051
  const amount = this.amountValue();
3051
3052
  if (amount != null) untracked(() => this.lastAmount.set(amount));
3052
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
+ });
3053
3063
  effect(() => {
3054
3064
  const ctx = this.ctx();
3055
3065
  const processing = this.processing();
@@ -3060,12 +3070,13 @@ var PaymentSquareBodyComponent = class PaymentSquareBodyComponent {
3060
3070
  const estimateFailed = !!this.estimateError();
3061
3071
  const unknown = this.attempt.unknown();
3062
3072
  const paidLocked = this.attempt.paidLocked();
3073
+ const finalRefusal = !!this.finalRefusal();
3063
3074
  const gateReady = this.readiness.ready();
3064
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");
3065
3076
  untracked(() => ctx.setPrimary({
3066
3077
  label,
3067
3078
  loading: processing && !notice,
3068
- disabled: notice ? done : !ready || processing || estimating || estimateFailed || ctx.amount == null || done || unknown || paidLocked || !gateReady,
3079
+ disabled: notice ? done : !ready || processing || estimating || estimateFailed || ctx.amount == null || done || unknown || paidLocked || finalRefusal || !gateReady,
3069
3080
  onClick: () => notice ? this.finish() : void this.pay()
3070
3081
  }));
3071
3082
  });
@@ -3221,9 +3232,15 @@ var PaymentSquareBodyComponent = class PaymentSquareBodyComponent {
3221
3232
  const kind = classifyHostError(err);
3222
3233
  if (kind === "unknown") return {
3223
3234
  kind: "unknown",
3224
- reason: "host_error"
3235
+ reason: isAwaitingVerificationError(err) ? "microdeposits" : "host_error"
3225
3236
  };
3226
- const message = hostErrorMessage(err, this.labels.t("squarePaymentMethod.paymentFailed"));
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
+ });
3227
3244
  if (kind === "not_sent") {
3228
3245
  if (live()) {
3229
3246
  this.error.set(message);
@@ -3281,7 +3298,7 @@ var PaymentSquareBodyComponent = class PaymentSquareBodyComponent {
3281
3298
  refused(ctx) {
3282
3299
  if (!this.readiness.passSync()) {
3283
3300
  const reason = this.readiness.reasons()[0] ?? "checking";
3284
- const message = this.labels.t(refusalLabelKey(reason));
3301
+ const message = this.labels.t(this.readiness.labelKeyFor(reason));
3285
3302
  this.error.set(message);
3286
3303
  ctx.report("refused", { message });
3287
3304
  ctx.announce(message);
@@ -3306,11 +3323,14 @@ var PaymentSquareBodyComponent = class PaymentSquareBodyComponent {
3306
3323
  } else if (outcome.kind === "unknown") {
3307
3324
  this.payAmount = this.attempt.pinnedAmount() ?? this.payAmount;
3308
3325
  this.payMethod = this.attempt.pinnedMethod() ?? this.payMethod;
3309
- const message = this.labels.t(outcome.reason === "offline" ? "paymentAttempt.offlineInFlight" : outcome.reason === "timeout" ? "paymentAttempt.timeout" : "paymentAttempt.checking");
3326
+ const message = this.labels.t(outcome.reason === "offline" ? "paymentAttempt.offlineInFlight" : outcome.reason === "timeout" ? "paymentAttempt.timeout" : outcome.reason === "microdeposits" || this.attempt.awaitingVerification() ? "paymentAttempt.awaitingVerification" : "paymentAttempt.checking");
3310
3327
  ctx.report("unknown", { message });
3311
3328
  ctx.announce(message);
3312
- } else if (outcome.kind === "refused") ctx.report("refused", { message: this.labels.t(refusalLabelKey(outcome.reason ?? "")) });
3313
- else if (outcome.kind === "succeeded" && outcome.reason === "other_tab") ctx.report("paid_elsewhere", {
3329
+ } else if (outcome.kind === "refused") {
3330
+ const refusedReason = outcome.reason ?? "";
3331
+ const refusedKey = refusedReason === "unknown" && this.attempt.awaitingVerification() ? "paymentAttempt.awaitingVerification" : this.readiness.labelKeyFor(refusedReason);
3332
+ ctx.report("refused", { message: this.labels.t(refusedKey) });
3333
+ } else if (outcome.kind === "succeeded" && outcome.reason === "other_tab") ctx.report("paid_elsewhere", {
3314
3334
  message: this.labels.t("paymentAttempt.paid"),
3315
3335
  attemptKey: outcome.attemptKey,
3316
3336
  ...outcome.method !== void 0 ? { paid: {