@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, ViewEncapsulation, afterNextRender, computed, effect, forwardRef, inject, input, isDevMode, model, output, signal, untracked, viewChild } from "@angular/core";
3
- import { AlertComponent, BadgeComponent, ButtonComponent, CheckboxComponent, DetailCardComponent, FormRowComponent, FormSectionComponent, HintComponent, KpiCardComponent, LiveRegionComponent, ModalComponent, 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, SelectComponent, SkeletonComponent, StackComponent, TextComponent, TextInputComponent, UiLabelsService, callHost, classifyHostError, createPaymentProtection, formatCurrency, hostErrorMessage, refusalLabelKey, uiText, warnQueuedPayment, wasQueuedOffline } from "@forgeroute/ui";
3
+ import { AlertComponent, BadgeComponent, ButtonComponent, CheckboxComponent, DetailCardComponent, FormRowComponent, FormSectionComponent, HintComponent, KpiCardComponent, LiveRegionComponent, ModalComponent, 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, SelectComponent, SkeletonComponent, StackComponent, TextComponent, TextInputComponent, UiLabelsService, callHost, classifyHostError, createPaymentProtection, formatCurrency, hostErrorMessage, isAwaitingVerificationError, isFinalPaymentRefusal, paymentErrorLabelKey, uiText, warnQueuedPayment, wasQueuedOffline } from "@forgeroute/ui";
4
4
  import * as i1 from "@angular/forms";
5
5
  import { FormsModule } from "@angular/forms";
6
6
  import { NgTemplateOutlet } from "@angular/common";
@@ -562,7 +562,7 @@ var QboPaymentComponent = class QboPaymentComponent {
562
562
  });
563
563
  this.fail({
564
564
  code: reason,
565
- message: this.labels.t(refusalLabelKey(reason)),
565
+ message: this.labels.t(this.readiness.labelKeyFor(reason)),
566
566
  stage: "validate"
567
567
  });
568
568
  return true;
@@ -2719,6 +2719,7 @@ var PaymentQboBodyComponent = class PaymentQboBodyComponent {
2719
2719
  this.processing = signal(false, ...ngDevMode ? [{ debugName: "processing" }] : /* istanbul ignore next */ []);
2720
2720
  this.done = signal(false, ...ngDevMode ? [{ debugName: "done" }] : /* istanbul ignore next */ []);
2721
2721
  this.error = signal("", ...ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []);
2722
+ this.finalRefusal = signal(null, ...ngDevMode ? [{ debugName: "finalRefusal" }] : /* istanbul ignore next */ []);
2722
2723
  this.estimate = signal(null, ...ngDevMode ? [{ debugName: "estimate" }] : /* istanbul ignore next */ []);
2723
2724
  this.estimating = signal(false, ...ngDevMode ? [{ debugName: "estimating" }] : /* istanbul ignore next */ []);
2724
2725
  this.estimateError = signal("", ...ngDevMode ? [{ debugName: "estimateError" }] : /* istanbul ignore next */ []);
@@ -2820,6 +2821,15 @@ var PaymentQboBodyComponent = class PaymentQboBodyComponent {
2820
2821
  const amount = this.amountValue();
2821
2822
  if (amount != null) untracked(() => this.lastAmount.set(amount));
2822
2823
  });
2824
+ effect(() => {
2825
+ const scope = this.finalRefusal();
2826
+ if (!scope) return;
2827
+ const ctx = this.ctx();
2828
+ if (ctx.method !== scope.method || ctx.amount !== scope.amount || this.config().payableRef() !== scope.ref) untracked(() => {
2829
+ this.finalRefusal.set(null);
2830
+ this.error.set("");
2831
+ });
2832
+ });
2823
2833
  effect(() => {
2824
2834
  const ctx = this.ctx();
2825
2835
  const processing = this.processing();
@@ -2829,12 +2839,13 @@ var PaymentQboBodyComponent = class PaymentQboBodyComponent {
2829
2839
  const estimateFailed = !!this.estimateError();
2830
2840
  const unknown = this.attempt.unknown();
2831
2841
  const paidLocked = this.attempt.paidLocked();
2842
+ const finalRefusal = !!this.finalRefusal();
2832
2843
  const gateReady = this.readiness.ready();
2833
2844
  const label = notice ? this.labels.t("common.done") : ctx.amount != null ? `${this.labels.t("qboPaymentMethod.pay")} ${formatCurrency(this.total(), { currency: ctx.currency })}` : this.labels.t("qboPaymentMethod.pay");
2834
2845
  untracked(() => ctx.setPrimary({
2835
2846
  label,
2836
2847
  loading: processing && !notice,
2837
- disabled: notice ? done : processing || estimating || estimateFailed || ctx.amount == null || done || unknown || paidLocked || !gateReady,
2848
+ disabled: notice ? done : processing || estimating || estimateFailed || ctx.amount == null || done || unknown || paidLocked || finalRefusal || !gateReady,
2838
2849
  onClick: () => notice ? this.finish() : void this.pay()
2839
2850
  }));
2840
2851
  });
@@ -2966,9 +2977,15 @@ var PaymentQboBodyComponent = class PaymentQboBodyComponent {
2966
2977
  const kind = classifyHostError(err);
2967
2978
  if (kind === "unknown") return {
2968
2979
  kind: "unknown",
2969
- reason: "host_error"
2980
+ reason: isAwaitingVerificationError(err) ? "microdeposits" : "host_error"
2970
2981
  };
2971
- const message = hostErrorMessage(err, this.labels.t("qboPaymentMethod.paymentFailed"));
2982
+ const labelKey = paymentErrorLabelKey(err);
2983
+ const message = labelKey ? this.labels.t(labelKey) : hostErrorMessage(err, this.labels.t("qboPaymentMethod.paymentFailed"));
2984
+ if (live() && isFinalPaymentRefusal(err)) this.finalRefusal.set({
2985
+ method: attemptMethod,
2986
+ ref: this.config().payableRef(),
2987
+ amount: attemptAmount
2988
+ });
2972
2989
  if (kind === "not_sent") {
2973
2990
  if (live()) {
2974
2991
  this.error.set(message);
@@ -3026,7 +3043,7 @@ var PaymentQboBodyComponent = class PaymentQboBodyComponent {
3026
3043
  refused(ctx) {
3027
3044
  if (!this.readiness.passSync()) {
3028
3045
  const reason = this.readiness.reasons()[0] ?? "checking";
3029
- const message = this.labels.t(refusalLabelKey(reason));
3046
+ const message = this.labels.t(this.readiness.labelKeyFor(reason));
3030
3047
  this.error.set(message);
3031
3048
  ctx.report("refused", { message });
3032
3049
  ctx.announce(message);
@@ -3051,11 +3068,14 @@ var PaymentQboBodyComponent = class PaymentQboBodyComponent {
3051
3068
  } else if (outcome.kind === "unknown") {
3052
3069
  this.payAmount = this.attempt.pinnedAmount() ?? this.payAmount;
3053
3070
  this.payMethod = this.attempt.pinnedMethod() ?? this.payMethod;
3054
- const message = this.labels.t(outcome.reason === "offline" ? "paymentAttempt.offlineInFlight" : outcome.reason === "timeout" ? "paymentAttempt.timeout" : "paymentAttempt.checking");
3071
+ 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");
3055
3072
  ctx.report("unknown", { message });
3056
3073
  ctx.announce(message);
3057
- } else if (outcome.kind === "refused") ctx.report("refused", { message: this.labels.t(refusalLabelKey(outcome.reason ?? "")) });
3058
- else if (outcome.kind === "succeeded" && outcome.reason === "other_tab") ctx.report("paid_elsewhere", {
3074
+ } else if (outcome.kind === "refused") {
3075
+ const refusedReason = outcome.reason ?? "";
3076
+ const refusedKey = refusedReason === "unknown" && this.attempt.awaitingVerification() ? "paymentAttempt.awaitingVerification" : this.readiness.labelKeyFor(refusedReason);
3077
+ ctx.report("refused", { message: this.labels.t(refusedKey) });
3078
+ } else if (outcome.kind === "succeeded" && outcome.reason === "other_tab") ctx.report("paid_elsewhere", {
3059
3079
  message: this.labels.t("paymentAttempt.paid"),
3060
3080
  attemptKey: outcome.attemptKey,
3061
3081
  ...outcome.method !== void 0 ? { paid: {
@@ -4009,6 +4029,7 @@ var QboHostedPayComponent = class QboHostedPayComponent {
4009
4029
  constructor() {
4010
4030
  this.labels = inject(UiLabelsService);
4011
4031
  this.state = input("loading", ...ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []);
4032
+ this.showForm = computed(() => this.state() === "form" || this.state() === "processing", ...ngDevMode ? [{ debugName: "showForm" }] : /* istanbul ignore next */ []);
4012
4033
  this.companyName = input("", ...ngDevMode ? [{ debugName: "companyName" }] : /* istanbul ignore next */ []);
4013
4034
  this.amountLabel = input("", ...ngDevMode ? [{ debugName: "amountLabel" }] : /* istanbul ignore next */ []);
4014
4035
  this.description = input("", ...ngDevMode ? [{ debugName: "description" }] : /* istanbul ignore next */ []);
@@ -4406,28 +4427,10 @@ var QboHostedPayComponent = class QboHostedPayComponent {
4406
4427
  @if (companyName()) { <p class="qbh-company" data-testid="qbo-hosted-company">{{ companyName() }}</p> }
4407
4428
  @if (description()) { <p class="qbh-desc" data-testid="qbo-hosted-description">{{ description() }}</p> }
4408
4429
  </header>
4409
- @switch (state()) {
4410
- @case ('loading') {
4411
- <div class="qbh-body" data-testid="qbo-hosted-loading">
4412
- <ui-live-region data-testid="qbo-hosted-loading-status" [message]="labels.t('qboHostedPay.loading')" />
4413
- <div aria-hidden="true"><ui-skeleton [height]="44" [mb]="10" /><ui-skeleton [height]="44" [mb]="10" /><ui-skeleton [height]="44" width="60%" /></div>
4414
- </div>
4415
- }
4416
- @case ('expired') {
4417
- <ui-alert variant="warning" [title]="labels.t('qboHostedPay.expiredTitle')" data-testid="qbo-hosted-expired">{{ labels.t('qboHostedPay.expired') }}</ui-alert>
4418
- }
4419
- @case ('used') {
4420
- <ui-alert variant="success" [title]="labels.t('qboHostedPay.usedTitle')" data-testid="qbo-hosted-used">{{ labels.t('qboHostedPay.used') }}</ui-alert>
4421
- }
4422
- @case ('success') {
4423
- <ui-alert variant="success" [title]="labels.t(effectiveSuccessKind() === 'submitted' ? 'qboHostedPay.submittedTitle' : 'qboHostedPay.successTitle')" data-testid="qbo-hosted-success">{{ labels.t(effectiveSuccessKind() === 'submitted' ? 'qboHostedPay.submitted' : 'qboHostedPay.success', { amount: amountLabel() }) }}</ui-alert>
4424
- }
4425
- @case ('error') {
4426
- <ui-alert variant="danger" [title]="labels.t('qboHostedPay.errorTitle')" data-testid="qbo-hosted-error">{{ errorMessage() }}</ui-alert>
4427
- }
4428
- @default {
4429
- <div class="qbh-body">
4430
- @if (errorMessage() && !localError()) { <ui-alert variant="danger" data-testid="qbo-hosted-form-error">{{ errorMessage() }}</ui-alert> }
4430
+ @if (showForm()) {
4431
+ <!-- 'form' and 'processing' are ONE view (the form keeps the typed data and its lock while the host charges the token) -->
4432
+ <div class="qbh-body">
4433
+ @if (errorMessage() && !localError()) { <ui-alert variant="danger" data-testid="qbo-hosted-form-error">{{ errorMessage() }}</ui-alert> }
4431
4434
  <ui-qbo-payment [mode]="mode()" [environment]="environment()" [methods]="methods()" [method]="method()" [pending]="state() === 'processing'" [submitLabel]="submitText()" [showErrors]="false"
4432
4435
  [label]="formLabel()" [cardholderName]="cardholderName()" [requireName]="requireName()" [requirePostalCode]="requirePostalCode()" [postalCountry]="postalCountry()"
4433
4436
  [confirmAccountNumber]="confirmAccountNumber()" [requireAchConsent]="requireAchConsent()" [achConsentText]="achConsentText()" [errorDisplay]="errorDisplay()" [errorMessages]="errorMessages()"
@@ -4438,6 +4441,30 @@ var QboHostedPayComponent = class QboHostedPayComponent {
4438
4441
  (attemptKeyChange)="attemptKeyChange.emit($event)" (readinessChange)="readinessChange.emit($event)" />
4439
4442
  @if (localError()) { <ui-alert variant="danger" data-testid="qbo-hosted-field-error">{{ localError() }}</ui-alert> }
4440
4443
  </div>
4444
+ } @else {
4445
+ @switch (state()) {
4446
+ @case ('loading') {
4447
+ <div class="qbh-body" data-testid="qbo-hosted-loading">
4448
+ <ui-live-region data-testid="qbo-hosted-loading-status" [message]="labels.t('qboHostedPay.loading')" />
4449
+ <div aria-hidden="true"><ui-skeleton [height]="44" [mb]="10" /><ui-skeleton [height]="44" [mb]="10" /><ui-skeleton [height]="44" width="60%" /></div>
4450
+ </div>
4451
+ }
4452
+ @case ('expired') {
4453
+ <ui-alert variant="warning" [title]="labels.t('qboHostedPay.expiredTitle')" data-testid="qbo-hosted-expired">{{ labels.t('qboHostedPay.expired') }}</ui-alert>
4454
+ }
4455
+ @case ('used') {
4456
+ <ui-alert variant="success" [title]="labels.t('qboHostedPay.usedTitle')" data-testid="qbo-hosted-used">{{ labels.t('qboHostedPay.used') }}</ui-alert>
4457
+ }
4458
+ @case ('success') {
4459
+ <ui-alert variant="success" [title]="labels.t(effectiveSuccessKind() === 'submitted' ? 'qboHostedPay.submittedTitle' : 'qboHostedPay.successTitle')" data-testid="qbo-hosted-success">{{ labels.t(effectiveSuccessKind() === 'submitted' ? 'qboHostedPay.submitted' : 'qboHostedPay.success', { amount: amountLabel() }) }}</ui-alert>
4460
+ }
4461
+ @case ('error') {
4462
+ <ui-alert variant="danger" [title]="labels.t('qboHostedPay.errorTitle')" data-testid="qbo-hosted-error">{{ errorMessage() }}</ui-alert>
4463
+ }
4464
+ @default {
4465
+ <!-- a state this screen does not know (cancelled, claimed, an empty string...): never the payment form -->
4466
+ <ui-alert variant="danger" [title]="labels.t('qboHostedPay.errorTitle')" data-testid="qbo-hosted-error">{{ errorMessage() || labels.t('qboHostedPay.unavailable') }}</ui-alert>
4467
+ }
4441
4468
  }
4442
4469
  }
4443
4470
  <footer class="qbh-footer" data-testid="qbo-hosted-footer">{{ labels.t('qboHostedPay.footer') }}</footer>
@@ -4572,28 +4599,10 @@ i0.ɵɵngDeclareClassMetadata({
4572
4599
  @if (companyName()) { <p class="qbh-company" data-testid="qbo-hosted-company">{{ companyName() }}</p> }
4573
4600
  @if (description()) { <p class="qbh-desc" data-testid="qbo-hosted-description">{{ description() }}</p> }
4574
4601
  </header>
4575
- @switch (state()) {
4576
- @case ('loading') {
4577
- <div class="qbh-body" data-testid="qbo-hosted-loading">
4578
- <ui-live-region data-testid="qbo-hosted-loading-status" [message]="labels.t('qboHostedPay.loading')" />
4579
- <div aria-hidden="true"><ui-skeleton [height]="44" [mb]="10" /><ui-skeleton [height]="44" [mb]="10" /><ui-skeleton [height]="44" width="60%" /></div>
4580
- </div>
4581
- }
4582
- @case ('expired') {
4583
- <ui-alert variant="warning" [title]="labels.t('qboHostedPay.expiredTitle')" data-testid="qbo-hosted-expired">{{ labels.t('qboHostedPay.expired') }}</ui-alert>
4584
- }
4585
- @case ('used') {
4586
- <ui-alert variant="success" [title]="labels.t('qboHostedPay.usedTitle')" data-testid="qbo-hosted-used">{{ labels.t('qboHostedPay.used') }}</ui-alert>
4587
- }
4588
- @case ('success') {
4589
- <ui-alert variant="success" [title]="labels.t(effectiveSuccessKind() === 'submitted' ? 'qboHostedPay.submittedTitle' : 'qboHostedPay.successTitle')" data-testid="qbo-hosted-success">{{ labels.t(effectiveSuccessKind() === 'submitted' ? 'qboHostedPay.submitted' : 'qboHostedPay.success', { amount: amountLabel() }) }}</ui-alert>
4590
- }
4591
- @case ('error') {
4592
- <ui-alert variant="danger" [title]="labels.t('qboHostedPay.errorTitle')" data-testid="qbo-hosted-error">{{ errorMessage() }}</ui-alert>
4593
- }
4594
- @default {
4595
- <div class="qbh-body">
4596
- @if (errorMessage() && !localError()) { <ui-alert variant="danger" data-testid="qbo-hosted-form-error">{{ errorMessage() }}</ui-alert> }
4602
+ @if (showForm()) {
4603
+ <!-- 'form' and 'processing' are ONE view (the form keeps the typed data and its lock while the host charges the token) -->
4604
+ <div class="qbh-body">
4605
+ @if (errorMessage() && !localError()) { <ui-alert variant="danger" data-testid="qbo-hosted-form-error">{{ errorMessage() }}</ui-alert> }
4597
4606
  <ui-qbo-payment [mode]="mode()" [environment]="environment()" [methods]="methods()" [method]="method()" [pending]="state() === 'processing'" [submitLabel]="submitText()" [showErrors]="false"
4598
4607
  [label]="formLabel()" [cardholderName]="cardholderName()" [requireName]="requireName()" [requirePostalCode]="requirePostalCode()" [postalCountry]="postalCountry()"
4599
4608
  [confirmAccountNumber]="confirmAccountNumber()" [requireAchConsent]="requireAchConsent()" [achConsentText]="achConsentText()" [errorDisplay]="errorDisplay()" [errorMessages]="errorMessages()"
@@ -4604,6 +4613,30 @@ i0.ɵɵngDeclareClassMetadata({
4604
4613
  (attemptKeyChange)="attemptKeyChange.emit($event)" (readinessChange)="readinessChange.emit($event)" />
4605
4614
  @if (localError()) { <ui-alert variant="danger" data-testid="qbo-hosted-field-error">{{ localError() }}</ui-alert> }
4606
4615
  </div>
4616
+ } @else {
4617
+ @switch (state()) {
4618
+ @case ('loading') {
4619
+ <div class="qbh-body" data-testid="qbo-hosted-loading">
4620
+ <ui-live-region data-testid="qbo-hosted-loading-status" [message]="labels.t('qboHostedPay.loading')" />
4621
+ <div aria-hidden="true"><ui-skeleton [height]="44" [mb]="10" /><ui-skeleton [height]="44" [mb]="10" /><ui-skeleton [height]="44" width="60%" /></div>
4622
+ </div>
4623
+ }
4624
+ @case ('expired') {
4625
+ <ui-alert variant="warning" [title]="labels.t('qboHostedPay.expiredTitle')" data-testid="qbo-hosted-expired">{{ labels.t('qboHostedPay.expired') }}</ui-alert>
4626
+ }
4627
+ @case ('used') {
4628
+ <ui-alert variant="success" [title]="labels.t('qboHostedPay.usedTitle')" data-testid="qbo-hosted-used">{{ labels.t('qboHostedPay.used') }}</ui-alert>
4629
+ }
4630
+ @case ('success') {
4631
+ <ui-alert variant="success" [title]="labels.t(effectiveSuccessKind() === 'submitted' ? 'qboHostedPay.submittedTitle' : 'qboHostedPay.successTitle')" data-testid="qbo-hosted-success">{{ labels.t(effectiveSuccessKind() === 'submitted' ? 'qboHostedPay.submitted' : 'qboHostedPay.success', { amount: amountLabel() }) }}</ui-alert>
4632
+ }
4633
+ @case ('error') {
4634
+ <ui-alert variant="danger" [title]="labels.t('qboHostedPay.errorTitle')" data-testid="qbo-hosted-error">{{ errorMessage() }}</ui-alert>
4635
+ }
4636
+ @default {
4637
+ <!-- a state this screen does not know (cancelled, claimed, an empty string...): never the payment form -->
4638
+ <ui-alert variant="danger" [title]="labels.t('qboHostedPay.errorTitle')" data-testid="qbo-hosted-error">{{ errorMessage() || labels.t('qboHostedPay.unavailable') }}</ui-alert>
4639
+ }
4607
4640
  }
4608
4641
  }
4609
4642
  <footer class="qbh-footer" data-testid="qbo-hosted-footer">{{ labels.t('qboHostedPay.footer') }}</footer>