@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, Injectable, InjectionToken, Injector, PLATFORM_ID, ViewEncapsulation, afterNextRender, computed, effect, forwardRef, inject, input, model, output, signal, untracked, viewChild } from "@angular/core";
3
- import { AlertComponent, BadgeComponent, ButtonComponent, DetailCardComponent, FormRowComponent, FormSectionComponent, HintComponent, KpiCardComponent, ModalComponent, PAYMENT_AUTH_TIMEOUT_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, SkeletonComponent, StackComponent, TextComponent, TextInputComponent, UiLabelsService, callHost, createPaymentProtection, formatCurrency, isAttemptFailedReplay, isDarkPage, refusalLabelKey, safeLocale, uiLocale, uiText, warnQueuedPayment, wasQueuedOffline } from "@forgeroute/ui";
3
+ import { AlertComponent, BadgeComponent, ButtonComponent, DetailCardComponent, FormRowComponent, FormSectionComponent, HintComponent, KpiCardComponent, ModalComponent, PAYMENT_AUTH_TIMEOUT_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, SkeletonComponent, StackComponent, TextComponent, TextInputComponent, UiLabelsService, callHost, createPaymentProtection, formatCurrency, isAttemptFailedReplay, isDarkPage, isFinalPaymentRefusal, paymentErrorLabelKey, refusalLabelKey, safeLocale, uiLocale, 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";
@@ -453,6 +453,9 @@ const STRIPE_A11Y_MESSAGES = {
453
453
  get verificationNeeded() {
454
454
  return uiText("stripePayment.a11y.verificationNeeded");
455
455
  },
456
+ get verificationNeededSetup() {
457
+ return uiText("stripePayment.a11y.verificationNeededSetup");
458
+ },
456
459
  get actionRequired() {
457
460
  return uiText("stripePayment.a11y.actionRequired");
458
461
  }
@@ -728,7 +731,7 @@ var StripePaymentComponent = class StripePaymentComponent {
728
731
  attemptKey: this.attempt.key(),
729
732
  reason
730
733
  });
731
- this.fail(failure(reason, this.labels.t(refusalLabelKey(reason)), "submit"));
734
+ this.fail(failure(reason, this.labels.t(this.readiness.labelKeyFor(reason)), "submit"));
732
735
  return null;
733
736
  }
734
737
  if (this.attempt.paidLocked() || this.attempt.unknown()) {
@@ -768,6 +771,11 @@ var StripePaymentComponent = class StripePaymentComponent {
768
771
  reason: "auth_required"
769
772
  };
770
773
  }
774
+ if (event.outcome === "requires_verification") return {
775
+ kind: "unknown",
776
+ value: event,
777
+ reason: "microdeposits"
778
+ };
771
779
  return {
772
780
  kind: "success",
773
781
  value: event
@@ -1144,7 +1152,7 @@ var StripePaymentComponent = class StripePaymentComponent {
1144
1152
  case "succeeded": return event.kind === "setup" ? m.methodSaved : m.paymentReceived;
1145
1153
  case "processing": return m.paymentProcessing;
1146
1154
  case "requires_capture": return m.paymentAuthorized;
1147
- case "requires_verification": return m.verificationNeeded;
1155
+ case "requires_verification": return event.kind === "setup" ? m.verificationNeededSetup : m.verificationNeeded;
1148
1156
  default: return m.actionRequired;
1149
1157
  }
1150
1158
  }
@@ -2750,6 +2758,7 @@ var MicrodepositVerifyComponent = class MicrodepositVerifyComponent {
2750
2758
  this.stripeError = signal("", ...ngDevMode ? [{ debugName: "stripeError" }] : /* istanbul ignore next */ []);
2751
2759
  this.failedAttempts = 0;
2752
2760
  this.formHidden = computed(() => this.readOnly() || this.statusOnly(), ...ngDevMode ? [{ debugName: "formHidden" }] : /* istanbul ignore next */ []);
2761
+ this.paymentNotStarted = computed(() => !!this.clientSecret() && this.flow() === "payment" && !this.stepsText().trim(), ...ngDevMode ? [{ debugName: "paymentNotStarted" }] : /* istanbul ignore next */ []);
2753
2762
  this.heading = computed(() => this.title() || (this.isProcessing() ? this.copy.processingTitle : this.copy.title), ...ngDevMode ? [{ debugName: "heading" }] : /* istanbul ignore next */ []);
2754
2763
  this.bankLine = computed(() => {
2755
2764
  const bank = this.bankName().trim();
@@ -3029,6 +3038,9 @@ var MicrodepositVerifyComponent = class MicrodepositVerifyComponent {
3029
3038
  @if (bankLine(); as line) { <strong data-testid="bank-pending-bank">{{ line }}</strong> }
3030
3039
  <ui-badge [label]="labels.t('stripeMicrodepositVerify.pending')" variant="yellow" data-testid="bank-pending-badge" />
3031
3040
  </div>
3041
+ @if (paymentNotStarted()) {
3042
+ <ui-text size="sm" data-testid="bank-pending-not-started" [text]="labels.t('stripeMicrodepositVerify.paymentNotStarted')" />
3043
+ }
3032
3044
  @if (stepsText().trim()) {
3033
3045
  <ui-text size="sm" [text]="stepsText()" data-testid="bank-pending-steps" />
3034
3046
  } @else if (isProcessing()) {
@@ -3291,6 +3303,9 @@ i0.ɵɵngDeclareClassMetadata({
3291
3303
  @if (bankLine(); as line) { <strong data-testid="bank-pending-bank">{{ line }}</strong> }
3292
3304
  <ui-badge [label]="labels.t('stripeMicrodepositVerify.pending')" variant="yellow" data-testid="bank-pending-badge" />
3293
3305
  </div>
3306
+ @if (paymentNotStarted()) {
3307
+ <ui-text size="sm" data-testid="bank-pending-not-started" [text]="labels.t('stripeMicrodepositVerify.paymentNotStarted')" />
3308
+ }
3294
3309
  @if (stepsText().trim()) {
3295
3310
  <ui-text size="sm" [text]="stepsText()" data-testid="bank-pending-steps" />
3296
3311
  } @else if (isProcessing()) {
@@ -4406,9 +4421,6 @@ const STRIPE_METHOD_TEXTS = {
4406
4421
  return uiText("stripePaymentMethod.achTitle");
4407
4422
  },
4408
4423
  achMessage: (amount) => uiText("stripePaymentMethod.achMessage", { amount }),
4409
- get verificationTitle() {
4410
- return uiText("stripePaymentMethod.verificationTitle");
4411
- },
4412
4424
  verificationMessage: (amount) => uiText("stripePaymentMethod.verificationMessage", { amount }),
4413
4425
  get receiptNote() {
4414
4426
  return uiText("stripePaymentMethod.receiptNote");
@@ -4443,6 +4455,7 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
4443
4455
  this.doneMethod = null;
4444
4456
  this.done = signal(false, ...ngDevMode ? [{ debugName: "done" }] : /* istanbul ignore next */ []);
4445
4457
  this.error = signal("", ...ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []);
4458
+ this.finalRefusal = signal(null, ...ngDevMode ? [{ debugName: "finalRefusal" }] : /* istanbul ignore next */ []);
4446
4459
  this.estimate = signal(null, ...ngDevMode ? [{ debugName: "estimate" }] : /* istanbul ignore next */ []);
4447
4460
  this.estimating = signal(false, ...ngDevMode ? [{ debugName: "estimating" }] : /* istanbul ignore next */ []);
4448
4461
  this.estimateError = signal("", ...ngDevMode ? [{ debugName: "estimateError" }] : /* istanbul ignore next */ []);
@@ -4514,20 +4527,35 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
4514
4527
  amount,
4515
4528
  method
4516
4529
  });
4517
- const info = await callHost(() => create({
4518
- amount,
4519
- paymentMethod: method,
4520
- paymentMethodType: this.methodType(),
4521
- receivedDate: ctx.receivedDate,
4522
- notes: ctx.note || null,
4523
- ...ctx.allocation,
4524
- ...context?.confirmationToken ? {
4525
- confirmationTokenId: context.confirmationToken.id,
4526
- funding: context.confirmationToken.funding
4527
- } : {},
4528
- ...context?.attemptKey ? { attemptKey: context.attemptKey } : {},
4529
- ...context?.attemptKey && context.payableRef !== void 0 ? { payableRef: context.payableRef } : {}
4530
- }));
4530
+ let info;
4531
+ try {
4532
+ info = await callHost(() => create({
4533
+ amount,
4534
+ paymentMethod: method,
4535
+ paymentMethodType: this.methodType(),
4536
+ receivedDate: ctx.receivedDate,
4537
+ notes: ctx.note || null,
4538
+ ...ctx.allocation,
4539
+ ...context?.confirmationToken ? {
4540
+ confirmationTokenId: context.confirmationToken.id,
4541
+ funding: context.confirmationToken.funding
4542
+ } : {},
4543
+ ...context?.attemptKey ? { attemptKey: context.attemptKey } : {},
4544
+ ...context?.attemptKey && context.payableRef !== void 0 ? { payableRef: context.payableRef } : {}
4545
+ }));
4546
+ } catch (err) {
4547
+ const labelKey = paymentErrorLabelKey(err);
4548
+ if (isFinalPaymentRefusal(err) && (!context?.attemptKey || attempt?.isLive(context.attemptKey))) this.finalRefusal.set({
4549
+ method: ctx.method,
4550
+ ref: this.config().payableRef(),
4551
+ amount
4552
+ });
4553
+ if (labelKey) throw Object.assign(new Error(this.labels.t(labelKey)), {
4554
+ status: err.status,
4555
+ code: err.code ?? err.error?.code
4556
+ });
4557
+ throw err;
4558
+ }
4531
4559
  if (wasQueuedOffline(info)) {
4532
4560
  warnQueuedPayment();
4533
4561
  throw new Error(this.labels.t("paymentAttempt.queuedOffline"));
@@ -4547,6 +4575,15 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
4547
4575
  const amount = this.amountValue();
4548
4576
  if (amount != null) untracked(() => this.lastAmount.set(amount));
4549
4577
  });
4578
+ effect(() => {
4579
+ const scope = this.finalRefusal();
4580
+ if (!scope) return;
4581
+ const ctx = this.ctx();
4582
+ if (ctx.method !== scope.method || ctx.amount !== scope.amount || this.config().payableRef() !== scope.ref) untracked(() => {
4583
+ this.finalRefusal.set(null);
4584
+ this.error.set("");
4585
+ });
4586
+ });
4550
4587
  effect(() => {
4551
4588
  const ctx = this.ctx();
4552
4589
  const processing = this.processing();
@@ -4556,12 +4593,13 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
4556
4593
  const done = this.done();
4557
4594
  const estimateFailed = !!this.estimateError();
4558
4595
  const previewPending = this.previewPending();
4596
+ const finalRefusal = !!this.finalRefusal();
4559
4597
  const protectedOff = !!this.payment()?.duplicateProtection() && (this.payment().attempt.unknown() || this.payment().attempt.paidLocked() || !this.payment().readiness.ready());
4560
4598
  const label = notice ? this.labels.t("common.done") : ctx.amount != null ? `${this.labels.t("stripePayment.pay")} ${formatCurrency(this.total(), { currency: ctx.currency })}` : this.labels.t("stripePayment.pay");
4561
4599
  untracked(() => ctx.setPrimary({
4562
4600
  label,
4563
4601
  loading: processing && !notice,
4564
- disabled: notice ? done : !complete || processing || estimating || previewPending || estimateFailed || ctx.amount == null || done || protectedOff,
4602
+ disabled: notice ? done : !complete || processing || estimating || previewPending || estimateFailed || ctx.amount == null || done || protectedOff || finalRefusal,
4565
4603
  onClick: () => notice ? this.finish() : void this.pay()
4566
4604
  }));
4567
4605
  });
@@ -4749,11 +4787,15 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
4749
4787
  } else if (outcome.kind === "unknown") {
4750
4788
  this.payAmount = this.payment()?.attempt.pinnedAmount() ?? this.payAmount;
4751
4789
  this.payMethod = this.payment()?.attempt.pinnedMethod() ?? this.payMethod;
4752
- const message = this.labels.t(outcome.reason === "offline" ? "paymentAttempt.offlineInFlight" : outcome.reason === "auth_abandoned" ? "paymentAttempt.authAbandoned" : outcome.reason === "timeout" ? "paymentAttempt.timeout" : "paymentAttempt.checking");
4790
+ if (outcome.reason === "microdeposits") return;
4791
+ const message = this.labels.t(outcome.reason === "offline" ? "paymentAttempt.offlineInFlight" : outcome.reason === "auth_abandoned" ? "paymentAttempt.authAbandoned" : outcome.reason === "timeout" ? "paymentAttempt.timeout" : this.payment()?.attempt.awaitingVerification() ? "paymentAttempt.awaitingVerification" : "paymentAttempt.checking");
4753
4792
  ctx.report("unknown", { message });
4754
4793
  ctx.announce(message);
4755
- } else if (outcome.kind === "refused") ctx.report("refused", { message: this.labels.t(refusalLabelKey(outcome.reason ?? "")) });
4756
- else if (outcome.kind === "succeeded" && outcome.reason === "other_tab") ctx.report("paid_elsewhere", {
4794
+ } else if (outcome.kind === "refused") {
4795
+ const refusedReason = outcome.reason ?? "";
4796
+ const refusedKey = refusedReason === "unknown" && this.payment()?.attempt.awaitingVerification() ? "paymentAttempt.awaitingVerification" : this.payment()?.readiness.labelKeyFor(refusedReason) ?? refusalLabelKey(refusedReason);
4797
+ ctx.report("refused", { message: this.labels.t(refusedKey) });
4798
+ } else if (outcome.kind === "succeeded" && outcome.reason === "other_tab") ctx.report("paid_elsewhere", {
4757
4799
  message: this.labels.t("paymentAttempt.paid"),
4758
4800
  attemptKey: outcome.attemptKey,
4759
4801
  ...outcome.method !== void 0 ? { paid: {
@@ -4853,8 +4895,9 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
4853
4895
  const verification = event.outcome === "requires_verification";
4854
4896
  ctx.report(finalizeFailed ? "finalize-failed" : verification ? "verification" : "processing", { result });
4855
4897
  this.confirmation.set(verification ? {
4856
- title: this.texts.verificationTitle,
4857
- message: this.texts.verificationMessage(money)
4898
+ title: "",
4899
+ message: this.texts.verificationMessage(money),
4900
+ verification: true
4858
4901
  } : {
4859
4902
  title: this.texts.achTitle,
4860
4903
  message: this.texts.achMessage(money)
@@ -4926,9 +4969,11 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
4926
4969
  template: `
4927
4970
  <div class="psm">
4928
4971
  @if (confirmation(); as notice) {
4929
- <ui-alert variant="success" [title]="notice.title" tabindex="-1" class="psm-notice" data-testid="stripe-method-confirmation">
4972
+ <ui-alert [variant]="notice.verification ? 'warning' : 'success'" [title]="notice.title" tabindex="-1" class="psm-notice" data-testid="stripe-method-confirmation">
4930
4973
  <p>{{ notice.message }}</p>
4931
- <p>{{ receiptNote() }}</p>
4974
+ @if (!notice.verification) {
4975
+ <p>{{ receiptNote() }}</p>
4976
+ }
4932
4977
  </ui-alert>
4933
4978
  } @else {
4934
4979
  @if (ctx().amount == null) {
@@ -5159,9 +5204,11 @@ i0.ɵɵngDeclareClassMetadata({
5159
5204
  template: `
5160
5205
  <div class="psm">
5161
5206
  @if (confirmation(); as notice) {
5162
- <ui-alert variant="success" [title]="notice.title" tabindex="-1" class="psm-notice" data-testid="stripe-method-confirmation">
5207
+ <ui-alert [variant]="notice.verification ? 'warning' : 'success'" [title]="notice.title" tabindex="-1" class="psm-notice" data-testid="stripe-method-confirmation">
5163
5208
  <p>{{ notice.message }}</p>
5164
- <p>{{ receiptNote() }}</p>
5209
+ @if (!notice.verification) {
5210
+ <p>{{ receiptNote() }}</p>
5211
+ }
5165
5212
  </ui-alert>
5166
5213
  } @else {
5167
5214
  @if (ctx().amount == null) {