@forgeroute/ui 0.5.2 → 0.5.4

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, isFinalPaymentRefusal, paymentErrorLabelKey, 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;
@@ -2977,7 +2977,7 @@ var PaymentQboBodyComponent = class PaymentQboBodyComponent {
2977
2977
  const kind = classifyHostError(err);
2978
2978
  if (kind === "unknown") return {
2979
2979
  kind: "unknown",
2980
- reason: "host_error"
2980
+ reason: isAwaitingVerificationError(err) ? "microdeposits" : "host_error"
2981
2981
  };
2982
2982
  const labelKey = paymentErrorLabelKey(err);
2983
2983
  const message = labelKey ? this.labels.t(labelKey) : hostErrorMessage(err, this.labels.t("qboPaymentMethod.paymentFailed"));
@@ -3043,7 +3043,7 @@ var PaymentQboBodyComponent = class PaymentQboBodyComponent {
3043
3043
  refused(ctx) {
3044
3044
  if (!this.readiness.passSync()) {
3045
3045
  const reason = this.readiness.reasons()[0] ?? "checking";
3046
- const message = this.labels.t(refusalLabelKey(reason));
3046
+ const message = this.labels.t(this.readiness.labelKeyFor(reason));
3047
3047
  this.error.set(message);
3048
3048
  ctx.report("refused", { message });
3049
3049
  ctx.announce(message);
@@ -3068,11 +3068,14 @@ var PaymentQboBodyComponent = class PaymentQboBodyComponent {
3068
3068
  } else if (outcome.kind === "unknown") {
3069
3069
  this.payAmount = this.attempt.pinnedAmount() ?? this.payAmount;
3070
3070
  this.payMethod = this.attempt.pinnedMethod() ?? this.payMethod;
3071
- 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");
3072
3072
  ctx.report("unknown", { message });
3073
3073
  ctx.announce(message);
3074
- } else if (outcome.kind === "refused") ctx.report("refused", { message: this.labels.t(refusalLabelKey(outcome.reason ?? "")) });
3075
- 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", {
3076
3079
  message: this.labels.t("paymentAttempt.paid"),
3077
3080
  attemptKey: outcome.attemptKey,
3078
3081
  ...outcome.method !== void 0 ? { paid: {
@@ -4026,6 +4029,7 @@ var QboHostedPayComponent = class QboHostedPayComponent {
4026
4029
  constructor() {
4027
4030
  this.labels = inject(UiLabelsService);
4028
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 */ []);
4029
4033
  this.companyName = input("", ...ngDevMode ? [{ debugName: "companyName" }] : /* istanbul ignore next */ []);
4030
4034
  this.amountLabel = input("", ...ngDevMode ? [{ debugName: "amountLabel" }] : /* istanbul ignore next */ []);
4031
4035
  this.description = input("", ...ngDevMode ? [{ debugName: "description" }] : /* istanbul ignore next */ []);
@@ -4423,28 +4427,10 @@ var QboHostedPayComponent = class QboHostedPayComponent {
4423
4427
  @if (companyName()) { <p class="qbh-company" data-testid="qbo-hosted-company">{{ companyName() }}</p> }
4424
4428
  @if (description()) { <p class="qbh-desc" data-testid="qbo-hosted-description">{{ description() }}</p> }
4425
4429
  </header>
4426
- @switch (state()) {
4427
- @case ('loading') {
4428
- <div class="qbh-body" data-testid="qbo-hosted-loading">
4429
- <ui-live-region data-testid="qbo-hosted-loading-status" [message]="labels.t('qboHostedPay.loading')" />
4430
- <div aria-hidden="true"><ui-skeleton [height]="44" [mb]="10" /><ui-skeleton [height]="44" [mb]="10" /><ui-skeleton [height]="44" width="60%" /></div>
4431
- </div>
4432
- }
4433
- @case ('expired') {
4434
- <ui-alert variant="warning" [title]="labels.t('qboHostedPay.expiredTitle')" data-testid="qbo-hosted-expired">{{ labels.t('qboHostedPay.expired') }}</ui-alert>
4435
- }
4436
- @case ('used') {
4437
- <ui-alert variant="success" [title]="labels.t('qboHostedPay.usedTitle')" data-testid="qbo-hosted-used">{{ labels.t('qboHostedPay.used') }}</ui-alert>
4438
- }
4439
- @case ('success') {
4440
- <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>
4441
- }
4442
- @case ('error') {
4443
- <ui-alert variant="danger" [title]="labels.t('qboHostedPay.errorTitle')" data-testid="qbo-hosted-error">{{ errorMessage() }}</ui-alert>
4444
- }
4445
- @default {
4446
- <div class="qbh-body">
4447
- @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> }
4448
4434
  <ui-qbo-payment [mode]="mode()" [environment]="environment()" [methods]="methods()" [method]="method()" [pending]="state() === 'processing'" [submitLabel]="submitText()" [showErrors]="false"
4449
4435
  [label]="formLabel()" [cardholderName]="cardholderName()" [requireName]="requireName()" [requirePostalCode]="requirePostalCode()" [postalCountry]="postalCountry()"
4450
4436
  [confirmAccountNumber]="confirmAccountNumber()" [requireAchConsent]="requireAchConsent()" [achConsentText]="achConsentText()" [errorDisplay]="errorDisplay()" [errorMessages]="errorMessages()"
@@ -4455,6 +4441,30 @@ var QboHostedPayComponent = class QboHostedPayComponent {
4455
4441
  (attemptKeyChange)="attemptKeyChange.emit($event)" (readinessChange)="readinessChange.emit($event)" />
4456
4442
  @if (localError()) { <ui-alert variant="danger" data-testid="qbo-hosted-field-error">{{ localError() }}</ui-alert> }
4457
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
+ }
4458
4468
  }
4459
4469
  }
4460
4470
  <footer class="qbh-footer" data-testid="qbo-hosted-footer">{{ labels.t('qboHostedPay.footer') }}</footer>
@@ -4589,28 +4599,10 @@ i0.ɵɵngDeclareClassMetadata({
4589
4599
  @if (companyName()) { <p class="qbh-company" data-testid="qbo-hosted-company">{{ companyName() }}</p> }
4590
4600
  @if (description()) { <p class="qbh-desc" data-testid="qbo-hosted-description">{{ description() }}</p> }
4591
4601
  </header>
4592
- @switch (state()) {
4593
- @case ('loading') {
4594
- <div class="qbh-body" data-testid="qbo-hosted-loading">
4595
- <ui-live-region data-testid="qbo-hosted-loading-status" [message]="labels.t('qboHostedPay.loading')" />
4596
- <div aria-hidden="true"><ui-skeleton [height]="44" [mb]="10" /><ui-skeleton [height]="44" [mb]="10" /><ui-skeleton [height]="44" width="60%" /></div>
4597
- </div>
4598
- }
4599
- @case ('expired') {
4600
- <ui-alert variant="warning" [title]="labels.t('qboHostedPay.expiredTitle')" data-testid="qbo-hosted-expired">{{ labels.t('qboHostedPay.expired') }}</ui-alert>
4601
- }
4602
- @case ('used') {
4603
- <ui-alert variant="success" [title]="labels.t('qboHostedPay.usedTitle')" data-testid="qbo-hosted-used">{{ labels.t('qboHostedPay.used') }}</ui-alert>
4604
- }
4605
- @case ('success') {
4606
- <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>
4607
- }
4608
- @case ('error') {
4609
- <ui-alert variant="danger" [title]="labels.t('qboHostedPay.errorTitle')" data-testid="qbo-hosted-error">{{ errorMessage() }}</ui-alert>
4610
- }
4611
- @default {
4612
- <div class="qbh-body">
4613
- @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> }
4614
4606
  <ui-qbo-payment [mode]="mode()" [environment]="environment()" [methods]="methods()" [method]="method()" [pending]="state() === 'processing'" [submitLabel]="submitText()" [showErrors]="false"
4615
4607
  [label]="formLabel()" [cardholderName]="cardholderName()" [requireName]="requireName()" [requirePostalCode]="requirePostalCode()" [postalCountry]="postalCountry()"
4616
4608
  [confirmAccountNumber]="confirmAccountNumber()" [requireAchConsent]="requireAchConsent()" [achConsentText]="achConsentText()" [errorDisplay]="errorDisplay()" [errorMessages]="errorMessages()"
@@ -4621,6 +4613,30 @@ i0.ɵɵngDeclareClassMetadata({
4621
4613
  (attemptKeyChange)="attemptKeyChange.emit($event)" (readinessChange)="readinessChange.emit($event)" />
4622
4614
  @if (localError()) { <ui-alert variant="danger" data-testid="qbo-hosted-field-error">{{ localError() }}</ui-alert> }
4623
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
+ }
4624
4640
  }
4625
4641
  }
4626
4642
  <footer class="qbh-footer" data-testid="qbo-hosted-footer">{{ labels.t('qboHostedPay.footer') }}</footer>