@forgeroute/ui 0.5.1 → 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.
@@ -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";
@@ -4443,6 +4443,7 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
4443
4443
  this.doneMethod = null;
4444
4444
  this.done = signal(false, ...ngDevMode ? [{ debugName: "done" }] : /* istanbul ignore next */ []);
4445
4445
  this.error = signal("", ...ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []);
4446
+ this.finalRefusal = signal(null, ...ngDevMode ? [{ debugName: "finalRefusal" }] : /* istanbul ignore next */ []);
4446
4447
  this.estimate = signal(null, ...ngDevMode ? [{ debugName: "estimate" }] : /* istanbul ignore next */ []);
4447
4448
  this.estimating = signal(false, ...ngDevMode ? [{ debugName: "estimating" }] : /* istanbul ignore next */ []);
4448
4449
  this.estimateError = signal("", ...ngDevMode ? [{ debugName: "estimateError" }] : /* istanbul ignore next */ []);
@@ -4514,20 +4515,35 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
4514
4515
  amount,
4515
4516
  method
4516
4517
  });
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
- }));
4518
+ let info;
4519
+ try {
4520
+ info = await callHost(() => create({
4521
+ amount,
4522
+ paymentMethod: method,
4523
+ paymentMethodType: this.methodType(),
4524
+ receivedDate: ctx.receivedDate,
4525
+ notes: ctx.note || null,
4526
+ ...ctx.allocation,
4527
+ ...context?.confirmationToken ? {
4528
+ confirmationTokenId: context.confirmationToken.id,
4529
+ funding: context.confirmationToken.funding
4530
+ } : {},
4531
+ ...context?.attemptKey ? { attemptKey: context.attemptKey } : {},
4532
+ ...context?.attemptKey && context.payableRef !== void 0 ? { payableRef: context.payableRef } : {}
4533
+ }));
4534
+ } catch (err) {
4535
+ const labelKey = paymentErrorLabelKey(err);
4536
+ if (isFinalPaymentRefusal(err)) this.finalRefusal.set({
4537
+ method: ctx.method,
4538
+ ref: this.config().payableRef(),
4539
+ amount
4540
+ });
4541
+ if (labelKey) throw Object.assign(new Error(this.labels.t(labelKey)), {
4542
+ status: err.status,
4543
+ code: err.code ?? err.error?.code
4544
+ });
4545
+ throw err;
4546
+ }
4531
4547
  if (wasQueuedOffline(info)) {
4532
4548
  warnQueuedPayment();
4533
4549
  throw new Error(this.labels.t("paymentAttempt.queuedOffline"));
@@ -4547,6 +4563,15 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
4547
4563
  const amount = this.amountValue();
4548
4564
  if (amount != null) untracked(() => this.lastAmount.set(amount));
4549
4565
  });
4566
+ effect(() => {
4567
+ const scope = this.finalRefusal();
4568
+ if (!scope) return;
4569
+ const ctx = this.ctx();
4570
+ if (ctx.method !== scope.method || ctx.amount !== scope.amount || this.config().payableRef() !== scope.ref) untracked(() => {
4571
+ this.finalRefusal.set(null);
4572
+ this.error.set("");
4573
+ });
4574
+ });
4550
4575
  effect(() => {
4551
4576
  const ctx = this.ctx();
4552
4577
  const processing = this.processing();
@@ -4556,12 +4581,13 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
4556
4581
  const done = this.done();
4557
4582
  const estimateFailed = !!this.estimateError();
4558
4583
  const previewPending = this.previewPending();
4584
+ const finalRefusal = !!this.finalRefusal();
4559
4585
  const protectedOff = !!this.payment()?.duplicateProtection() && (this.payment().attempt.unknown() || this.payment().attempt.paidLocked() || !this.payment().readiness.ready());
4560
4586
  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
4587
  untracked(() => ctx.setPrimary({
4562
4588
  label,
4563
4589
  loading: processing && !notice,
4564
- disabled: notice ? done : !complete || processing || estimating || previewPending || estimateFailed || ctx.amount == null || done || protectedOff,
4590
+ disabled: notice ? done : !complete || processing || estimating || previewPending || estimateFailed || ctx.amount == null || done || protectedOff || finalRefusal,
4565
4591
  onClick: () => notice ? this.finish() : void this.pay()
4566
4592
  }));
4567
4593
  });