@forgeroute/ui 0.5.0 → 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_METHOD_PLUGIN, PaymentMethodPlugin, SkeletonComponent, StackComponent, TextComponent, TextInputComponent, UiLabelsService, callHost, formatCurrency, safeLocale, uiLocale, uiText } 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";
@@ -120,6 +120,20 @@ function getStripeErrorMessage(error, options = {}) {
120
120
  if (technical) return technical;
121
121
  return message || fallback;
122
122
  }
123
+ function confirmationTokenEventOf(token) {
124
+ const preview = token.payment_method_preview;
125
+ const card = preview?.card ?? null;
126
+ const funding = card ? card.funding === "credit" || card.funding === "debit" || card.funding === "prepaid" ? card.funding : "unknown" : null;
127
+ return {
128
+ id: token.id,
129
+ paymentMethodType: preview?.type ?? null,
130
+ funding,
131
+ brand: card?.brand ?? null,
132
+ last4: card?.last4 ?? null,
133
+ country: card?.country ?? null,
134
+ wallet: card?.wallet?.type ?? null
135
+ };
136
+ }
123
137
  const MSG_NOT_INITIALIZED = "Payment system not initialized";
124
138
  const MSG_INTENT_FAILED = "Failed to create payment intent";
125
139
  const MSG_NOT_COMPLETED = "Payment was not completed";
@@ -129,6 +143,7 @@ const MSG_AUTH_FAILED = "Payment authentication failed";
129
143
  const MSG_AUTH_NOT_COMPLETED = "Payment authentication was not completed";
130
144
  const MSG_KEY_MISSING = "A Stripe publishable key is required";
131
145
  const MSG_LOAD_FAILED = "Failed to load Stripe";
146
+ const MSG_TOKEN_FAILED = "The card details could not be checked. Please try again.";
132
147
  function paymentMethodIdOf(intent) {
133
148
  const pm = intent?.payment_method;
134
149
  if (!pm) return null;
@@ -202,7 +217,8 @@ const KNOWN_MESSAGE_KEYS = {
202
217
  "Card payments are not available right now.": "stripePayment.msg.cardsUnavailable",
203
218
  "Failed to initialize payment. Please try again.": "stripePayment.msg.initFailed",
204
219
  "Could not calculate the fees. Please try again.": "stripePayment.msg.feesFailed",
205
- "Payment failed. Please try again.": "stripeErrors.defaultMessage"
220
+ "Payment failed. Please try again.": "stripeErrors.defaultMessage",
221
+ "The card details could not be checked. Please try again.": "stripePayment.msg.tokenFailed"
206
222
  };
207
223
  function localizeStripeMessage(message) {
208
224
  const key = KNOWN_MESSAGE_KEYS[message];
@@ -397,16 +413,6 @@ const TOKENS = [
397
413
  ["--ui-stripe-border-radius", "borderRadius"],
398
414
  ["--ui-stripe-font-size-base", "fontSizeBase"]
399
415
  ];
400
- function isDarkPage(doc) {
401
- const forced = doc.documentElement.getAttribute("data-theme");
402
- if (forced === "dark") return true;
403
- if (forced === "light") return false;
404
- try {
405
- return !!doc.defaultView?.matchMedia?.("(prefers-color-scheme: dark)").matches;
406
- } catch {
407
- return false;
408
- }
409
- }
410
416
  function readStripeAppearance(doc, element = doc.documentElement) {
411
417
  const view = doc.defaultView;
412
418
  const variables = {};
@@ -452,6 +458,18 @@ const STRIPE_A11Y_MESSAGES = {
452
458
  }
453
459
  };
454
460
  const STRIPE_ACH_NOTICE = "Signing in to your bank account lets you pay right away. Entering your routing and account numbers instead requires verification with two small deposits, which typically take a couple of days to arrive in your account.";
461
+ const AMBIGUOUS_STRIPE_TYPES = /* @__PURE__ */ new Set([
462
+ "api_connection_error",
463
+ "api_error",
464
+ "rate_limit_error",
465
+ "idempotency_error"
466
+ ]);
467
+ const AMBIGUOUS_STRIPE_CODES = /* @__PURE__ */ new Set([
468
+ "payment_intent_unexpected_state",
469
+ "idempotency_error",
470
+ "idempotency_key_in_use",
471
+ "lock_timeout"
472
+ ]);
455
473
  let nextId = 0;
456
474
  const jsonEqual = (a, b) => JSON.stringify(a) === JSON.stringify(b);
457
475
  var StripePaymentComponent = class StripePaymentComponent {
@@ -489,6 +507,26 @@ var StripePaymentComponent = class StripePaymentComponent {
489
507
  this.redirect = input("if_required", ...ngDevMode ? [{ debugName: "redirect" }] : /* istanbul ignore next */ []);
490
508
  this.submitBeforeConfirm = input(null, ...ngDevMode ? [{ debugName: "submitBeforeConfirm" }] : /* istanbul ignore next */ []);
491
509
  this.autoHandleCardAction = input(false, ...ngDevMode ? [{ debugName: "autoHandleCardAction" }] : /* istanbul ignore next */ []);
510
+ this.collectConfirmationToken = input(false, ...ngDevMode ? [{ debugName: "collectConfirmationToken" }] : /* istanbul ignore next */ []);
511
+ this.duplicateProtection = input(false, ...ngDevMode ? [{ debugName: "duplicateProtection" }] : /* istanbul ignore next */ []);
512
+ this.attemptAmount = input(null, ...ngDevMode ? [{ debugName: "attemptAmount" }] : /* istanbul ignore next */ []);
513
+ this.attemptMethod = input(null, ...ngDevMode ? [{ debugName: "attemptMethod" }] : /* istanbul ignore next */ []);
514
+ this.payableRef = input(null, ...ngDevMode ? [{ debugName: "payableRef" }] : /* istanbul ignore next */ []);
515
+ this.attemptKey = input(null, ...ngDevMode ? [{ debugName: "attemptKey" }] : /* istanbul ignore next */ []);
516
+ this.checkStatus = input(null, ...ngDevMode ? [{ debugName: "checkStatus" }] : /* istanbul ignore next */ []);
517
+ this.paid = input(false, ...ngDevMode ? [{ debugName: "paid" }] : /* istanbul ignore next */ []);
518
+ this.hostPending = input(false, ...ngDevMode ? [{ debugName: "hostPending" }] : /* istanbul ignore next */ []);
519
+ this.statusPollMs = input(PAYMENT_STATUS_POLL_MS, ...ngDevMode ? [{ debugName: "statusPollMs" }] : /* istanbul ignore next */ []);
520
+ this.statusPollMaxMs = input(PAYMENT_STATUS_POLL_MAX_MS, ...ngDevMode ? [{ debugName: "statusPollMaxMs" }] : /* istanbul ignore next */ []);
521
+ this.statusCheckTimeoutMs = input(PAYMENT_STATUS_CHECK_TIMEOUT_MS, ...ngDevMode ? [{ debugName: "statusCheckTimeoutMs" }] : /* istanbul ignore next */ []);
522
+ this.statusFailGraceMs = input(PAYMENT_STATUS_FAIL_GRACE_MS, ...ngDevMode ? [{ debugName: "statusFailGraceMs" }] : /* istanbul ignore next */ []);
523
+ this.allowStartOver = input(false, ...ngDevMode ? [{ debugName: "allowStartOver" }] : /* istanbul ignore next */ []);
524
+ this.offlineOverride = input(false, ...ngDevMode ? [{ debugName: "offlineOverride" }] : /* istanbul ignore next */ []);
525
+ this.authTimeoutMs = input(PAYMENT_AUTH_TIMEOUT_MS, ...ngDevMode ? [{ debugName: "authTimeoutMs" }] : /* istanbul ignore next */ []);
526
+ this.confirmTimeoutMs = input(PAYMENT_REQUEST_TIMEOUT_MS, ...ngDevMode ? [{ debugName: "confirmTimeoutMs" }] : /* istanbul ignore next */ []);
527
+ this.readinessCheck = input(null, ...ngDevMode ? [{ debugName: "readinessCheck" }] : /* istanbul ignore next */ []);
528
+ this.readinessTimeoutMs = input(PAYMENT_READINESS_TIMEOUT_MS, ...ngDevMode ? [{ debugName: "readinessTimeoutMs" }] : /* istanbul ignore next */ []);
529
+ this.readinessEveryMs = input(PAYMENT_READINESS_EVERY_MS, ...ngDevMode ? [{ debugName: "readinessEveryMs" }] : /* istanbul ignore next */ []);
492
530
  this.submitLabel = input("", ...ngDevMode ? [{ debugName: "submitLabel" }] : /* istanbul ignore next */ []);
493
531
  this.showSubmit = input(true, ...ngDevMode ? [{ debugName: "showSubmit" }] : /* istanbul ignore next */ []);
494
532
  this.disabled = input(false, ...ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []);
@@ -525,9 +563,14 @@ var StripePaymentComponent = class StripePaymentComponent {
525
563
  this.ready = output();
526
564
  this.paymentMethodTypeChange = output();
527
565
  this.elementChange = output();
566
+ this.confirmationToken = output();
528
567
  this.confirmed = output();
529
568
  this.failed = output();
530
569
  this.loadError = output();
570
+ this.inFlightChange = output();
571
+ this.outcome = output();
572
+ this.attemptKeyChange = output();
573
+ this.readinessChange = output();
531
574
  this.loading = signal(false, ...ngDevMode ? [{ debugName: "loading" }] : /* istanbul ignore next */ []);
532
575
  this.isReady = signal(false, ...ngDevMode ? [{ debugName: "isReady" }] : /* istanbul ignore next */ []);
533
576
  this.submitting = signal(false, ...ngDevMode ? [{ debugName: "submitting" }] : /* istanbul ignore next */ []);
@@ -541,7 +584,7 @@ var StripePaymentComponent = class StripePaymentComponent {
541
584
  this.mountHidden = computed(() => !this.mountOnly() && (this.loading() || this.pending() || !!this.loadErrorText()), ...ngDevMode ? [{ debugName: "mountHidden" }] : /* istanbul ignore next */ []);
542
585
  this.achNoticeVisible = computed(() => this.showAchNotice() && this.selectedType() === "us_bank_account", ...ngDevMode ? [{ debugName: "achNoticeVisible" }] : /* istanbul ignore next */ []);
543
586
  this.effectiveSubmitLabel = computed(() => this.submitLabel() || (this.mode() === "setup" ? this.labels.t("stripePayment.saveMethod") : this.labels.t("stripePayment.pay")), ...ngDevMode ? [{ debugName: "effectiveSubmitLabel" }] : /* istanbul ignore next */ []);
544
- this.submitDisabled = computed(() => this.disabled() || this.loading() || this.pending() || !this.isReady() || !!this.loadErrorText(), ...ngDevMode ? [{ debugName: "submitDisabled" }] : /* istanbul ignore next */ []);
587
+ this.submitDisabled = computed(() => this.disabled() || this.loading() || this.pending() || !this.isReady() || !!this.loadErrorText() || this.protectionOn() && (this.attempt.unknown() || this.attempt.paidLocked() || !this.readiness.ready()), ...ngDevMode ? [{ debugName: "submitDisabled" }] : /* istanbul ignore next */ []);
545
588
  this.messages = computed(() => {
546
589
  const given = Object.fromEntries(Object.entries(this.a11yMessages() ?? {}).filter(([, text]) => typeof text === "string"));
547
590
  return {
@@ -612,13 +655,38 @@ var StripePaymentComponent = class StripePaymentComponent {
612
655
  this.lastType = null;
613
656
  this.lastFailure = null;
614
657
  this.destroyed = false;
658
+ this.confirmSeq = 0;
615
659
  this.appliedDefaultValues = "";
616
660
  this.appliedDisabled = false;
661
+ this.protectionOn = computed(() => this.duplicateProtection() && this.mode() === "payment", ...ngDevMode ? [{ debugName: "protectionOn" }] : /* istanbul ignore next */ []);
662
+ this.retryTick = signal(0, ...ngDevMode ? [{ debugName: "retryTick" }] : /* istanbul ignore next */ []);
663
+ const protection = createPaymentProtection(this, {
664
+ amount: () => {
665
+ const own = this.attemptAmount();
666
+ if (own != null) return own;
667
+ const minor = this.deferred()?.amount;
668
+ return minor == null ? null : minor / 100;
669
+ },
670
+ method: () => this.attemptMethod() ?? this.selectedType() ?? "card",
671
+ sdk: () => this.loadErrorText() ? "blocked" : this.loading() ? "loading" : "ok",
672
+ enabled: () => this.protectionOn(),
673
+ onOutcome: (o) => this.outcome.emit(o),
674
+ onInFlightChange: (v) => this.inFlightChange.emit(v),
675
+ onKeyChange: (k) => {
676
+ if (this.protectionOn()) this.attemptKeyChange.emit(k);
677
+ },
678
+ onReadinessChange: (r) => {
679
+ if (this.protectionOn()) this.readinessChange.emit(r);
680
+ }
681
+ });
682
+ this.attempt = protection.attempt;
683
+ this.readiness = protection.readiness;
617
684
  effect(() => {
618
685
  const mount = this.mountRef();
619
686
  const connection = this.connection();
620
687
  const elements = this.elementsConfig();
621
688
  const element = this.elementConfig();
689
+ this.retryTick();
622
690
  if (!mount) return;
623
691
  untracked(() => {
624
692
  this.init(mount.nativeElement, connection, elements, element);
@@ -647,13 +715,138 @@ var StripePaymentComponent = class StripePaymentComponent {
647
715
  });
648
716
  }
649
717
  async confirm(options = {}) {
650
- if (this.submitting() || this.disabled()) return null;
718
+ if (this.disabled()) return null;
719
+ if (this.protectionOn()) return this.confirmProtected(options);
720
+ if (this.submitting()) return null;
721
+ return this.confirmCore(options, null);
722
+ }
723
+ async confirmProtected(options) {
724
+ if (!this.readiness.passSync()) {
725
+ const reason = this.readiness.reasons()[0] ?? "checking";
726
+ this.outcome.emit({
727
+ kind: "refused",
728
+ attemptKey: this.attempt.key(),
729
+ reason
730
+ });
731
+ this.fail(failure(reason, this.labels.t(refusalLabelKey(reason)), "submit"));
732
+ return null;
733
+ }
734
+ if (this.attempt.paidLocked() || this.attempt.unknown()) {
735
+ this.attempt.begin();
736
+ return null;
737
+ }
738
+ const run = await this.attempt.run(async (key) => {
739
+ const trace = {
740
+ held: true,
741
+ failure: null,
742
+ thrown: false,
743
+ outcome: null
744
+ };
745
+ try {
746
+ const event = await this.confirmCore(options, key, trace, this.attempt.pinnedRef());
747
+ trace.held = false;
748
+ return this.classifyConfirm(event, trace, this.attempt.isLive(key));
749
+ } finally {
750
+ trace.held = false;
751
+ }
752
+ }, { timeoutMs: this.confirmTimeoutMs() });
753
+ return "refused" in run && run.refused ? null : run.value ?? null;
754
+ }
755
+ classifyConfirm(event, trace, live) {
756
+ const show = (f) => {
757
+ if (live) this.publishFailure(f);
758
+ };
759
+ const say = (key) => {
760
+ if (live) this.announcement.set(this.labels.t(key));
761
+ };
762
+ if (event) {
763
+ if (event.outcome === "requires_action") {
764
+ say("paymentAttempt.authRequired");
765
+ return {
766
+ kind: "pending",
767
+ value: event,
768
+ reason: "auth_required"
769
+ };
770
+ }
771
+ return {
772
+ kind: "success",
773
+ value: event
774
+ };
775
+ }
776
+ const f = trace.failure;
777
+ if (!f) return {
778
+ kind: "unknown",
779
+ reason: "no_result"
780
+ };
781
+ if (f.code === "attempt_failed_use_new_key") {
782
+ show(f);
783
+ return {
784
+ kind: "failure",
785
+ reason: f.code
786
+ };
787
+ }
788
+ if (f.stage === "submit" || f.stage === "intent") {
789
+ show(f);
790
+ return {
791
+ kind: "released",
792
+ reason: f.code
793
+ };
794
+ }
795
+ if (f.stage === "action") {
796
+ const errorIntent = f.error?.payment_intent;
797
+ if ((f.code === "authentication_failed" || f.code === "payment_intent_authentication_failure" && errorIntent?.status === "requires_payment_method") && !trace.thrown) {
798
+ show(f);
799
+ return {
800
+ kind: "failure",
801
+ reason: f.code
802
+ };
803
+ }
804
+ say("paymentAttempt.authAbandoned");
805
+ return {
806
+ kind: "unknown",
807
+ reason: "auth_abandoned"
808
+ };
809
+ }
810
+ if (trace.thrown || f.type !== void 0 && AMBIGUOUS_STRIPE_TYPES.has(f.type) || AMBIGUOUS_STRIPE_CODES.has(f.code)) return {
811
+ kind: "unknown",
812
+ reason: "error"
813
+ };
814
+ if (f.stage === "result" && f.code !== "requires_payment_method" && f.code !== "no_payment_method" && trace.outcome !== "canceled") return {
815
+ kind: "unknown",
816
+ reason: "unexpected_status"
817
+ };
818
+ show(f);
819
+ return {
820
+ kind: "failure",
821
+ reason: f.code
822
+ };
823
+ }
824
+ reload() {
825
+ this.retryTick.update((n) => n + 1);
826
+ }
827
+ markUnknown() {
828
+ this.attempt.markUnknown("host");
829
+ }
830
+ markSucceeded() {
831
+ this.attempt.succeed("host");
832
+ }
833
+ markFailed() {
834
+ this.attempt.fail("host");
835
+ }
836
+ markNotCharged() {
837
+ this.attempt.markNotCharged();
838
+ }
839
+ resetPaid() {
840
+ this.attempt.resetPaid();
841
+ }
842
+ async confirmCore(options, attemptKey, trace, payableRef = null) {
651
843
  const stripe = this.stripe;
652
844
  const elements = this.elements;
653
845
  if (!stripe || !elements) {
654
- this.fail(failure("not_initialized", MSG_NOT_INITIALIZED, "submit"));
846
+ this.fail(failure("not_initialized", MSG_NOT_INITIALIZED, "submit"), trace);
655
847
  return null;
656
848
  }
849
+ const mine = ++this.confirmSeq;
657
850
  this.submitting.set(true);
658
851
  this.errorText.set("");
659
852
  this.announcement.set("");
@@ -662,30 +855,52 @@ var StripePaymentComponent = class StripePaymentComponent {
662
855
  const mode = this.mode();
663
856
  const existing = options.useExistingIntent === true;
664
857
  const deferred = !existing && !this.clientSecret() && !!this.deferred();
665
- if (!existing && (this.submitBeforeConfirm() ?? deferred)) {
858
+ const wantToken = deferred && this.collectConfirmationToken() && (this.selectedType() ?? "card") === "card";
859
+ if (!existing && ((this.submitBeforeConfirm() ?? deferred) || wantToken)) {
666
860
  const { error } = await elements.submit();
667
861
  if (error) {
668
- this.fail(failureFromError(error, "submit", this.errorOptions("submit")));
862
+ this.fail(failureFromError(error, "submit", this.errorOptions("submit")), trace);
669
863
  return null;
670
864
  }
671
865
  }
866
+ let token = null;
867
+ if (wantToken) {
868
+ const made = await this.makeConfirmationToken(stripe, elements);
869
+ if ("id" in made && made.paymentMethodType === "card") {
870
+ token = made;
871
+ this.confirmationToken.emit(made);
872
+ }
873
+ }
672
874
  let secret = existing ? options.clientSecret : void 0;
673
875
  if (deferred) {
674
876
  stage = "intent";
675
877
  const create = this.createIntent();
676
878
  if (!create) {
677
- this.fail(failure("no_intent_factory", MSG_INTENT_FAILED, "intent"));
879
+ this.fail(failure("no_intent_factory", MSG_INTENT_FAILED, "intent"), trace);
678
880
  return null;
679
881
  }
680
882
  try {
681
- const created = await create({ mode });
883
+ const context = token ? {
884
+ mode,
885
+ confirmationToken: token
886
+ } : { mode };
887
+ const created = await create(attemptKey ? {
888
+ ...context,
889
+ attemptKey,
890
+ payableRef
891
+ } : context);
892
+ if (wasQueuedOffline(created)) {
893
+ warnQueuedPayment();
894
+ this.fail(failure("not_sent", this.labels.t("paymentAttempt.queuedOffline"), "intent"), trace);
895
+ return null;
896
+ }
682
897
  secret = typeof created === "string" ? created : created?.clientSecret;
683
898
  } catch (err) {
684
- this.fail(failure("intent_creation_failed", messageOfThrown(err, STRIPE_DEFAULT_ERROR_MESSAGE), "intent", messageOfThrown(err, "")));
899
+ this.fail(failure(isAttemptFailedReplay(err) ? "attempt_failed_use_new_key" : "intent_creation_failed", messageOfThrown(err, STRIPE_DEFAULT_ERROR_MESSAGE), "intent", messageOfThrown(err, "")), trace);
685
900
  return null;
686
901
  }
687
902
  if (!secret) {
688
- this.fail(failure("intent_creation_failed", MSG_INTENT_FAILED, "intent"));
903
+ this.fail(failure("intent_creation_failed", MSG_INTENT_FAILED, "intent"), trace);
689
904
  return null;
690
905
  }
691
906
  }
@@ -699,31 +914,62 @@ var StripePaymentComponent = class StripePaymentComponent {
699
914
  };
700
915
  const result = mode === "setup" ? await stripe.confirmSetup(params) : await stripe.confirmPayment(params);
701
916
  if (result.error) {
702
- this.fail(failureFromError(result.error, "confirm", this.errorOptions("confirm")));
917
+ this.fail(failureFromError(result.error, "confirm", this.errorOptions("confirm")), trace);
703
918
  return null;
704
919
  }
705
920
  const intent = mode === "setup" ? result.setupIntent : result.paymentIntent;
706
921
  if (!intent) {
707
- this.fail(failure("not_completed", mode === "setup" ? "Payment method setup was incomplete. Please try again." : MSG_NOT_COMPLETED, "result"));
922
+ this.fail(failure("not_completed", mode === "setup" ? "Payment method setup was incomplete. Please try again." : MSG_NOT_COMPLETED, "result"), trace);
708
923
  return null;
709
924
  }
710
925
  let event = normalizeIntent(mode, intent);
711
926
  if (mode === "setup" && !event.paymentMethodId) {
712
- this.fail(failure("no_payment_method", MSG_NO_PAYMENT_METHOD, "result"));
927
+ this.fail(failure("no_payment_method", MSG_NO_PAYMENT_METHOD, "result"), trace);
713
928
  return null;
714
929
  }
715
930
  if (mode === "payment" && event.outcome === "requires_action" && this.autoHandleCardAction()) {
716
931
  stage = "action";
717
- const handled = await this.runCardAction(stripe, intent.client_secret);
932
+ if (trace) this.attempt.markPending("auth_required");
933
+ const handled = await this.runCardAction(stripe, intent.client_secret, trace);
718
934
  if (!handled) return null;
719
935
  event = handled;
720
936
  }
721
- return this.finish(event);
937
+ return this.finish(event, false, trace);
722
938
  } catch (err) {
723
- this.fail(this.thrownFailure(err, stage));
939
+ if (trace) trace.thrown = true;
940
+ this.fail(this.thrownFailure(err, stage), trace);
724
941
  return null;
725
942
  } finally {
726
- this.submitting.set(false);
943
+ if (mine === this.confirmSeq) this.submitting.set(false);
944
+ }
945
+ }
946
+ async createConfirmationToken() {
947
+ if (this.submitting() || this.disabled()) return null;
948
+ const stripe = this.stripe;
949
+ const elements = this.elements;
950
+ if (!stripe || !elements) return failure("not_initialized", MSG_NOT_INITIALIZED, "submit");
951
+ try {
952
+ const { error } = await elements.submit();
953
+ if (error) return failureFromError(error, "submit", this.errorOptions("submit"));
954
+ } catch (err) {
955
+ return this.thrownFailure(err, "submit");
956
+ }
957
+ const made = await this.makeConfirmationToken(stripe, elements);
958
+ if ("id" in made && made.paymentMethodType === "card") this.confirmationToken.emit(made);
959
+ return made;
960
+ }
961
+ async makeConfirmationToken(stripe, elements) {
962
+ if (!stripe.createConfirmationToken) return failure("confirmation_token_unavailable", MSG_TOKEN_FAILED, "confirm");
963
+ const billing = this.billingDetails();
964
+ try {
965
+ const { confirmationToken, error } = await stripe.createConfirmationToken({
966
+ elements,
967
+ ...billing ? { params: { payment_method_data: { billing_details: billing } } } : {}
968
+ });
969
+ if (error) return failureFromError(error, "confirm", this.errorOptions("confirm"));
970
+ return confirmationToken ? confirmationTokenEventOf(confirmationToken) : failure("confirmation_token_unavailable", MSG_TOKEN_FAILED, "confirm");
971
+ } catch (err) {
972
+ return this.thrownFailure(err, "confirm");
727
973
  }
728
974
  }
729
975
  async handleNextAction(clientSecret) {
@@ -733,16 +979,31 @@ var StripePaymentComponent = class StripePaymentComponent {
733
979
  this.fail(failure("not_initialized", MSG_NOT_INITIALIZED, "action"));
734
980
  return null;
735
981
  }
982
+ const guarded = this.protectionOn() && this.attempt.inFlight();
983
+ const trace = guarded ? {
984
+ held: true,
985
+ failure: null,
986
+ thrown: false,
987
+ outcome: null
988
+ } : void 0;
989
+ if (guarded) this.attempt.markPending("auth_required");
736
990
  this.submitting.set(true);
737
991
  this.errorText.set("");
992
+ let event = null;
738
993
  try {
739
- const handled = await this.runCardAction(stripe, clientSecret);
740
- return handled ? this.finish(handled) : null;
994
+ const handled = await this.runCardAction(stripe, clientSecret, trace);
995
+ event = handled ? this.finish(handled, false, trace) : null;
996
+ return event;
741
997
  } catch (err) {
742
- this.fail(this.thrownFailure(err, "action"));
998
+ if (trace) trace.thrown = true;
999
+ this.fail(this.thrownFailure(err, "action"), trace);
743
1000
  return null;
744
1001
  } finally {
745
1002
  this.submitting.set(false);
1003
+ if (trace) {
1004
+ trace.held = false;
1005
+ this.attempt.apply(this.classifyConfirm(event, trace, true));
1006
+ }
746
1007
  }
747
1008
  }
748
1009
  async fetchUpdates() {
@@ -833,19 +1094,27 @@ var StripePaymentComponent = class StripePaymentComponent {
833
1094
  Object.assign(params, this.confirmParams() ?? {});
834
1095
  return Object.keys(params).length ? params : null;
835
1096
  }
836
- fail(f) {
1097
+ fail(f, trace) {
837
1098
  const override = this.errorMessages()?.[f.code];
838
1099
  if (override) f = {
839
1100
  ...f,
840
1101
  message: override.split("{status}").join(f.status ?? "")
841
1102
  };
842
1103
  this.lastFailure = f;
1104
+ if (trace) {
1105
+ trace.failure = f;
1106
+ if (trace.held) return;
1107
+ }
1108
+ this.publishFailure(f);
1109
+ }
1110
+ publishFailure(f) {
843
1111
  if (this.destroyed) return;
844
1112
  if (this.showErrors()) this.errorText.set(f.message);
845
1113
  this.announcement.set("");
846
1114
  this.failed.emit(f);
847
1115
  }
848
- finish(event, fromReturn = false) {
1116
+ finish(event, fromReturn = false, trace) {
1117
+ if (trace) trace.outcome = event.outcome;
849
1118
  const acted = {
850
1119
  ...event.actionHandled ? { actionHandled: true } : {},
851
1120
  status: event.status
@@ -854,14 +1123,14 @@ var StripePaymentComponent = class StripePaymentComponent {
854
1123
  this.fail({
855
1124
  ...failure("requires_payment_method", MSG_REQUIRES_PAYMENT_METHOD, fromReturn ? "return" : "result"),
856
1125
  ...acted
857
- });
1126
+ }, trace);
858
1127
  return null;
859
1128
  }
860
1129
  if (event.outcome === "canceled" || event.outcome === "unknown") {
861
1130
  this.fail({
862
1131
  ...failure("not_completed", MSG_NOT_COMPLETED, fromReturn ? "return" : "result"),
863
1132
  ...acted
864
- });
1133
+ }, trace);
865
1134
  return null;
866
1135
  }
867
1136
  if (this.destroyed) return event;
@@ -879,13 +1148,13 @@ var StripePaymentComponent = class StripePaymentComponent {
879
1148
  default: return m.actionRequired;
880
1149
  }
881
1150
  }
882
- async runCardAction(stripe, clientSecret) {
1151
+ async runCardAction(stripe, clientSecret, trace) {
883
1152
  const acted = { actionHandled: true };
884
1153
  if (!stripe.handleCardAction || !clientSecret) {
885
1154
  this.fail({
886
1155
  ...failure("action_unavailable", MSG_AUTH_NOT_COMPLETED, "action"),
887
1156
  ...acted
888
- });
1157
+ }, trace);
889
1158
  return null;
890
1159
  }
891
1160
  const { error, paymentIntent } = await stripe.handleCardAction(clientSecret);
@@ -896,14 +1165,14 @@ var StripePaymentComponent = class StripePaymentComponent {
896
1165
  fallback: MSG_AUTH_FAILED
897
1166
  }),
898
1167
  ...acted
899
- });
1168
+ }, trace);
900
1169
  return null;
901
1170
  }
902
1171
  if (!paymentIntent) {
903
1172
  this.fail({
904
1173
  ...failure("action_incomplete", MSG_AUTH_NOT_COMPLETED, "action"),
905
1174
  ...acted
906
- });
1175
+ }, trace);
907
1176
  return null;
908
1177
  }
909
1178
  const event = {
@@ -915,7 +1184,7 @@ var StripePaymentComponent = class StripePaymentComponent {
915
1184
  ...failure("authentication_failed", "Payment authentication failed. Please try a different payment method.", "action"),
916
1185
  ...acted,
917
1186
  status: event.status
918
- });
1187
+ }, trace);
919
1188
  return null;
920
1189
  }
921
1190
  return event;
@@ -1267,6 +1536,146 @@ var StripePaymentComponent = class StripePaymentComponent {
1267
1536
  isRequired: false,
1268
1537
  transformFunction: null
1269
1538
  },
1539
+ collectConfirmationToken: {
1540
+ classPropertyName: "collectConfirmationToken",
1541
+ publicName: "collectConfirmationToken",
1542
+ isSignal: true,
1543
+ isRequired: false,
1544
+ transformFunction: null
1545
+ },
1546
+ duplicateProtection: {
1547
+ classPropertyName: "duplicateProtection",
1548
+ publicName: "duplicateProtection",
1549
+ isSignal: true,
1550
+ isRequired: false,
1551
+ transformFunction: null
1552
+ },
1553
+ attemptAmount: {
1554
+ classPropertyName: "attemptAmount",
1555
+ publicName: "attemptAmount",
1556
+ isSignal: true,
1557
+ isRequired: false,
1558
+ transformFunction: null
1559
+ },
1560
+ attemptMethod: {
1561
+ classPropertyName: "attemptMethod",
1562
+ publicName: "attemptMethod",
1563
+ isSignal: true,
1564
+ isRequired: false,
1565
+ transformFunction: null
1566
+ },
1567
+ payableRef: {
1568
+ classPropertyName: "payableRef",
1569
+ publicName: "payableRef",
1570
+ isSignal: true,
1571
+ isRequired: false,
1572
+ transformFunction: null
1573
+ },
1574
+ attemptKey: {
1575
+ classPropertyName: "attemptKey",
1576
+ publicName: "attemptKey",
1577
+ isSignal: true,
1578
+ isRequired: false,
1579
+ transformFunction: null
1580
+ },
1581
+ checkStatus: {
1582
+ classPropertyName: "checkStatus",
1583
+ publicName: "checkStatus",
1584
+ isSignal: true,
1585
+ isRequired: false,
1586
+ transformFunction: null
1587
+ },
1588
+ paid: {
1589
+ classPropertyName: "paid",
1590
+ publicName: "paid",
1591
+ isSignal: true,
1592
+ isRequired: false,
1593
+ transformFunction: null
1594
+ },
1595
+ hostPending: {
1596
+ classPropertyName: "hostPending",
1597
+ publicName: "hostPending",
1598
+ isSignal: true,
1599
+ isRequired: false,
1600
+ transformFunction: null
1601
+ },
1602
+ statusPollMs: {
1603
+ classPropertyName: "statusPollMs",
1604
+ publicName: "statusPollMs",
1605
+ isSignal: true,
1606
+ isRequired: false,
1607
+ transformFunction: null
1608
+ },
1609
+ statusPollMaxMs: {
1610
+ classPropertyName: "statusPollMaxMs",
1611
+ publicName: "statusPollMaxMs",
1612
+ isSignal: true,
1613
+ isRequired: false,
1614
+ transformFunction: null
1615
+ },
1616
+ statusCheckTimeoutMs: {
1617
+ classPropertyName: "statusCheckTimeoutMs",
1618
+ publicName: "statusCheckTimeoutMs",
1619
+ isSignal: true,
1620
+ isRequired: false,
1621
+ transformFunction: null
1622
+ },
1623
+ statusFailGraceMs: {
1624
+ classPropertyName: "statusFailGraceMs",
1625
+ publicName: "statusFailGraceMs",
1626
+ isSignal: true,
1627
+ isRequired: false,
1628
+ transformFunction: null
1629
+ },
1630
+ allowStartOver: {
1631
+ classPropertyName: "allowStartOver",
1632
+ publicName: "allowStartOver",
1633
+ isSignal: true,
1634
+ isRequired: false,
1635
+ transformFunction: null
1636
+ },
1637
+ offlineOverride: {
1638
+ classPropertyName: "offlineOverride",
1639
+ publicName: "offlineOverride",
1640
+ isSignal: true,
1641
+ isRequired: false,
1642
+ transformFunction: null
1643
+ },
1644
+ authTimeoutMs: {
1645
+ classPropertyName: "authTimeoutMs",
1646
+ publicName: "authTimeoutMs",
1647
+ isSignal: true,
1648
+ isRequired: false,
1649
+ transformFunction: null
1650
+ },
1651
+ confirmTimeoutMs: {
1652
+ classPropertyName: "confirmTimeoutMs",
1653
+ publicName: "confirmTimeoutMs",
1654
+ isSignal: true,
1655
+ isRequired: false,
1656
+ transformFunction: null
1657
+ },
1658
+ readinessCheck: {
1659
+ classPropertyName: "readinessCheck",
1660
+ publicName: "readinessCheck",
1661
+ isSignal: true,
1662
+ isRequired: false,
1663
+ transformFunction: null
1664
+ },
1665
+ readinessTimeoutMs: {
1666
+ classPropertyName: "readinessTimeoutMs",
1667
+ publicName: "readinessTimeoutMs",
1668
+ isSignal: true,
1669
+ isRequired: false,
1670
+ transformFunction: null
1671
+ },
1672
+ readinessEveryMs: {
1673
+ classPropertyName: "readinessEveryMs",
1674
+ publicName: "readinessEveryMs",
1675
+ isSignal: true,
1676
+ isRequired: false,
1677
+ transformFunction: null
1678
+ },
1270
1679
  submitLabel: {
1271
1680
  classPropertyName: "submitLabel",
1272
1681
  publicName: "submitLabel",
@@ -1413,9 +1822,14 @@ var StripePaymentComponent = class StripePaymentComponent {
1413
1822
  ready: "ready",
1414
1823
  paymentMethodTypeChange: "paymentMethodTypeChange",
1415
1824
  elementChange: "elementChange",
1825
+ confirmationToken: "confirmationToken",
1416
1826
  confirmed: "confirmed",
1417
1827
  failed: "failed",
1418
- loadError: "loadError"
1828
+ loadError: "loadError",
1829
+ inFlightChange: "inFlightChange",
1830
+ outcome: "outcome",
1831
+ attemptKeyChange: "attemptKeyChange",
1832
+ readinessChange: "readinessChange"
1419
1833
  },
1420
1834
  host: { properties: { "attr.aria-busy": "!mountOnly() && (loading() || submitting()) ? \"true\" : null" } },
1421
1835
  viewQueries: [{
@@ -1431,6 +1845,9 @@ var StripePaymentComponent = class StripePaymentComponent {
1431
1845
  @if (!mountOnly() || a11yMessages()) {
1432
1846
  <div class="sp-sr" role="status" aria-live="polite" data-testid="stripe-status">{{ statusText() }}</div>
1433
1847
  }
1848
+ @if (!mountOnly() && protectionOn()) {
1849
+ <ui-payment-attempt-status [attempt]="attempt" [readiness]="readiness" [allowStartOver]="allowStartOver()" (retryLoad)="reload()" />
1850
+ }
1434
1851
  @if (!mountOnly() && (loading() || pending())) {
1435
1852
  <div class="sp-skeleton" data-testid="stripe-skeleton" aria-hidden="true">
1436
1853
  <ui-skeleton [height]="44" [mb]="10" />
@@ -1509,6 +1926,18 @@ var StripePaymentComponent = class StripePaymentComponent {
1509
1926
  "modal-footer-right"
1510
1927
  ]
1511
1928
  },
1929
+ {
1930
+ kind: "component",
1931
+ type: PaymentAttemptStatusComponent,
1932
+ selector: "ui-payment-attempt-status",
1933
+ inputs: [
1934
+ "attempt",
1935
+ "showPaid",
1936
+ "allowStartOver",
1937
+ "readiness"
1938
+ ],
1939
+ outputs: ["retryLoad"]
1940
+ },
1512
1941
  {
1513
1942
  kind: "component",
1514
1943
  type: SkeletonComponent,
@@ -1542,6 +1971,7 @@ i0.ɵɵngDeclareClassMetadata({
1542
1971
  imports: [
1543
1972
  AlertComponent,
1544
1973
  ButtonComponent,
1974
+ PaymentAttemptStatusComponent,
1545
1975
  SkeletonComponent
1546
1976
  ],
1547
1977
  host: { "[attr.aria-busy]": "!mountOnly() && (loading() || submitting()) ? \"true\" : null" },
@@ -1550,6 +1980,9 @@ i0.ɵɵngDeclareClassMetadata({
1550
1980
  @if (!mountOnly() || a11yMessages()) {
1551
1981
  <div class="sp-sr" role="status" aria-live="polite" data-testid="stripe-status">{{ statusText() }}</div>
1552
1982
  }
1983
+ @if (!mountOnly() && protectionOn()) {
1984
+ <ui-payment-attempt-status [attempt]="attempt" [readiness]="readiness" [allowStartOver]="allowStartOver()" (retryLoad)="reload()" />
1985
+ }
1553
1986
  @if (!mountOnly() && (loading() || pending())) {
1554
1987
  <div class="sp-skeleton" data-testid="stripe-skeleton" aria-hidden="true">
1555
1988
  <ui-skeleton [height]="44" [mb]="10" />
@@ -1776,27 +2209,187 @@ i0.ɵɵngDeclareClassMetadata({
1776
2209
  required: false
1777
2210
  }]
1778
2211
  }],
1779
- redirect: [{
2212
+ redirect: [{
2213
+ type: i0.Input,
2214
+ args: [{
2215
+ isSignal: true,
2216
+ alias: "redirect",
2217
+ required: false
2218
+ }]
2219
+ }],
2220
+ submitBeforeConfirm: [{
2221
+ type: i0.Input,
2222
+ args: [{
2223
+ isSignal: true,
2224
+ alias: "submitBeforeConfirm",
2225
+ required: false
2226
+ }]
2227
+ }],
2228
+ autoHandleCardAction: [{
2229
+ type: i0.Input,
2230
+ args: [{
2231
+ isSignal: true,
2232
+ alias: "autoHandleCardAction",
2233
+ required: false
2234
+ }]
2235
+ }],
2236
+ collectConfirmationToken: [{
2237
+ type: i0.Input,
2238
+ args: [{
2239
+ isSignal: true,
2240
+ alias: "collectConfirmationToken",
2241
+ required: false
2242
+ }]
2243
+ }],
2244
+ duplicateProtection: [{
2245
+ type: i0.Input,
2246
+ args: [{
2247
+ isSignal: true,
2248
+ alias: "duplicateProtection",
2249
+ required: false
2250
+ }]
2251
+ }],
2252
+ attemptAmount: [{
2253
+ type: i0.Input,
2254
+ args: [{
2255
+ isSignal: true,
2256
+ alias: "attemptAmount",
2257
+ required: false
2258
+ }]
2259
+ }],
2260
+ attemptMethod: [{
2261
+ type: i0.Input,
2262
+ args: [{
2263
+ isSignal: true,
2264
+ alias: "attemptMethod",
2265
+ required: false
2266
+ }]
2267
+ }],
2268
+ payableRef: [{
2269
+ type: i0.Input,
2270
+ args: [{
2271
+ isSignal: true,
2272
+ alias: "payableRef",
2273
+ required: false
2274
+ }]
2275
+ }],
2276
+ attemptKey: [{
2277
+ type: i0.Input,
2278
+ args: [{
2279
+ isSignal: true,
2280
+ alias: "attemptKey",
2281
+ required: false
2282
+ }]
2283
+ }],
2284
+ checkStatus: [{
2285
+ type: i0.Input,
2286
+ args: [{
2287
+ isSignal: true,
2288
+ alias: "checkStatus",
2289
+ required: false
2290
+ }]
2291
+ }],
2292
+ paid: [{
2293
+ type: i0.Input,
2294
+ args: [{
2295
+ isSignal: true,
2296
+ alias: "paid",
2297
+ required: false
2298
+ }]
2299
+ }],
2300
+ hostPending: [{
2301
+ type: i0.Input,
2302
+ args: [{
2303
+ isSignal: true,
2304
+ alias: "hostPending",
2305
+ required: false
2306
+ }]
2307
+ }],
2308
+ statusPollMs: [{
2309
+ type: i0.Input,
2310
+ args: [{
2311
+ isSignal: true,
2312
+ alias: "statusPollMs",
2313
+ required: false
2314
+ }]
2315
+ }],
2316
+ statusPollMaxMs: [{
2317
+ type: i0.Input,
2318
+ args: [{
2319
+ isSignal: true,
2320
+ alias: "statusPollMaxMs",
2321
+ required: false
2322
+ }]
2323
+ }],
2324
+ statusCheckTimeoutMs: [{
2325
+ type: i0.Input,
2326
+ args: [{
2327
+ isSignal: true,
2328
+ alias: "statusCheckTimeoutMs",
2329
+ required: false
2330
+ }]
2331
+ }],
2332
+ statusFailGraceMs: [{
2333
+ type: i0.Input,
2334
+ args: [{
2335
+ isSignal: true,
2336
+ alias: "statusFailGraceMs",
2337
+ required: false
2338
+ }]
2339
+ }],
2340
+ allowStartOver: [{
2341
+ type: i0.Input,
2342
+ args: [{
2343
+ isSignal: true,
2344
+ alias: "allowStartOver",
2345
+ required: false
2346
+ }]
2347
+ }],
2348
+ offlineOverride: [{
2349
+ type: i0.Input,
2350
+ args: [{
2351
+ isSignal: true,
2352
+ alias: "offlineOverride",
2353
+ required: false
2354
+ }]
2355
+ }],
2356
+ authTimeoutMs: [{
2357
+ type: i0.Input,
2358
+ args: [{
2359
+ isSignal: true,
2360
+ alias: "authTimeoutMs",
2361
+ required: false
2362
+ }]
2363
+ }],
2364
+ confirmTimeoutMs: [{
2365
+ type: i0.Input,
2366
+ args: [{
2367
+ isSignal: true,
2368
+ alias: "confirmTimeoutMs",
2369
+ required: false
2370
+ }]
2371
+ }],
2372
+ readinessCheck: [{
1780
2373
  type: i0.Input,
1781
2374
  args: [{
1782
2375
  isSignal: true,
1783
- alias: "redirect",
2376
+ alias: "readinessCheck",
1784
2377
  required: false
1785
2378
  }]
1786
2379
  }],
1787
- submitBeforeConfirm: [{
2380
+ readinessTimeoutMs: [{
1788
2381
  type: i0.Input,
1789
2382
  args: [{
1790
2383
  isSignal: true,
1791
- alias: "submitBeforeConfirm",
2384
+ alias: "readinessTimeoutMs",
1792
2385
  required: false
1793
2386
  }]
1794
2387
  }],
1795
- autoHandleCardAction: [{
2388
+ readinessEveryMs: [{
1796
2389
  type: i0.Input,
1797
2390
  args: [{
1798
2391
  isSignal: true,
1799
- alias: "autoHandleCardAction",
2392
+ alias: "readinessEveryMs",
1800
2393
  required: false
1801
2394
  }]
1802
2395
  }],
@@ -1976,6 +2569,10 @@ i0.ɵɵngDeclareClassMetadata({
1976
2569
  type: i0.Output,
1977
2570
  args: ["elementChange"]
1978
2571
  }],
2572
+ confirmationToken: [{
2573
+ type: i0.Output,
2574
+ args: ["confirmationToken"]
2575
+ }],
1979
2576
  confirmed: [{
1980
2577
  type: i0.Output,
1981
2578
  args: ["confirmed"]
@@ -1988,6 +2585,22 @@ i0.ɵɵngDeclareClassMetadata({
1988
2585
  type: i0.Output,
1989
2586
  args: ["loadError"]
1990
2587
  }],
2588
+ inFlightChange: [{
2589
+ type: i0.Output,
2590
+ args: ["inFlightChange"]
2591
+ }],
2592
+ outcome: [{
2593
+ type: i0.Output,
2594
+ args: ["outcome"]
2595
+ }],
2596
+ attemptKeyChange: [{
2597
+ type: i0.Output,
2598
+ args: ["attemptKeyChange"]
2599
+ }],
2600
+ readinessChange: [{
2601
+ type: i0.Output,
2602
+ args: ["readinessChange"]
2603
+ }],
1991
2604
  mountRef: [{
1992
2605
  type: i0.ViewChild,
1993
2606
  args: ["mount", { isSignal: true }]
@@ -3822,8 +4435,15 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
3822
4435
  this.fields = FIELDS;
3823
4436
  this.complete = signal(false, ...ngDevMode ? [{ debugName: "complete" }] : /* istanbul ignore next */ []);
3824
4437
  this.processing = signal(false, ...ngDevMode ? [{ debugName: "processing" }] : /* istanbul ignore next */ []);
4438
+ this.payAmount = null;
4439
+ this.attemptUnknown = false;
4440
+ this.payMethod = null;
4441
+ this.doneAmount = null;
4442
+ this.attempts = /* @__PURE__ */ new Map();
4443
+ this.doneMethod = null;
3825
4444
  this.done = signal(false, ...ngDevMode ? [{ debugName: "done" }] : /* istanbul ignore next */ []);
3826
4445
  this.error = signal("", ...ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []);
4446
+ this.finalRefusal = signal(null, ...ngDevMode ? [{ debugName: "finalRefusal" }] : /* istanbul ignore next */ []);
3827
4447
  this.estimate = signal(null, ...ngDevMode ? [{ debugName: "estimate" }] : /* istanbul ignore next */ []);
3828
4448
  this.estimating = signal(false, ...ngDevMode ? [{ debugName: "estimating" }] : /* istanbul ignore next */ []);
3829
4449
  this.estimateError = signal("", ...ngDevMode ? [{ debugName: "estimateError" }] : /* istanbul ignore next */ []);
@@ -3833,6 +4453,11 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
3833
4453
  this.lastAmount = signal(null, ...ngDevMode ? [{ debugName: "lastAmount" }] : /* istanbul ignore next */ []);
3834
4454
  this.intent = null;
3835
4455
  this.estimateRun = 0;
4456
+ this.previewFunding = signal(null, ...ngDevMode ? [{ debugName: "previewFunding" }] : /* istanbul ignore next */ []);
4457
+ this.previewTokenId = null;
4458
+ this.previewRun = 0;
4459
+ this.previewPending = signal(false, ...ngDevMode ? [{ debugName: "previewPending" }] : /* istanbul ignore next */ []);
4460
+ this.previewTimer = null;
3836
4461
  this.estimateStale = false;
3837
4462
  this.amountValue = computed(() => this.ctx().amount, ...ngDevMode ? [{ debugName: "amountValue" }] : /* istanbul ignore next */ []);
3838
4463
  this.methodValue = computed(() => this.ctx().method, ...ngDevMode ? [{ debugName: "methodValue" }] : /* istanbul ignore next */ []);
@@ -3878,19 +4503,51 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
3878
4503
  subtitle: this.labels.t("stripePaymentMethod.amountPlusFees")
3879
4504
  };
3880
4505
  }, ...ngDevMode ? [{ debugName: "totalCard" }] : /* istanbul ignore next */ []);
3881
- this.createIntentFn = async () => {
4506
+ this.createIntentFn = async (context) => {
3882
4507
  const create = this.config().createIntent();
3883
4508
  const ctx = this.ctx();
3884
4509
  if (!create || ctx.amount == null) throw new Error(this.labels.t("stripePayment.msg.cardsUnavailable"));
3885
4510
  this.cancelIntent(true);
3886
- const info = await callHost(() => create({
3887
- amount: ctx.amount,
3888
- paymentMethod: ctx.method,
3889
- paymentMethodType: this.methodType(),
3890
- receivedDate: ctx.receivedDate,
3891
- notes: ctx.note || null,
3892
- ...ctx.allocation
3893
- }));
4511
+ const attempt = this.payment()?.attempt;
4512
+ const amount = attempt?.pinnedAmount() ?? ctx.amount;
4513
+ const method = attempt?.pinnedMethod() ?? ctx.method;
4514
+ if (context?.attemptKey) this.attempts.set(context.attemptKey, {
4515
+ amount,
4516
+ method
4517
+ });
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
+ }
4547
+ if (wasQueuedOffline(info)) {
4548
+ warnQueuedPayment();
4549
+ throw new Error(this.labels.t("paymentAttempt.queuedOffline"));
4550
+ }
3894
4551
  if (!info?.clientSecret) throw new Error(this.labels.t("stripePayment.msg.initFailed"));
3895
4552
  this.intent = info;
3896
4553
  this.intentFees.set({
@@ -3906,6 +4563,15 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
3906
4563
  const amount = this.amountValue();
3907
4564
  if (amount != null) untracked(() => this.lastAmount.set(amount));
3908
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
+ });
3909
4575
  effect(() => {
3910
4576
  const ctx = this.ctx();
3911
4577
  const processing = this.processing();
@@ -3914,11 +4580,14 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
3914
4580
  const estimating = this.estimating();
3915
4581
  const done = this.done();
3916
4582
  const estimateFailed = !!this.estimateError();
4583
+ const previewPending = this.previewPending();
4584
+ const finalRefusal = !!this.finalRefusal();
4585
+ const protectedOff = !!this.payment()?.duplicateProtection() && (this.payment().attempt.unknown() || this.payment().attempt.paidLocked() || !this.payment().readiness.ready());
3917
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");
3918
4587
  untracked(() => ctx.setPrimary({
3919
4588
  label,
3920
4589
  loading: processing && !notice,
3921
- disabled: notice ? done : !complete || processing || estimating || estimateFailed || ctx.amount == null || done,
4590
+ disabled: notice ? done : !complete || processing || estimating || previewPending || estimateFailed || ctx.amount == null || done || protectedOff || finalRefusal,
3922
4591
  onClick: () => notice ? this.finish() : void this.pay()
3923
4592
  }));
3924
4593
  });
@@ -3926,6 +4595,7 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
3926
4595
  const estimate = this.config().estimateFees();
3927
4596
  const amount = this.amountValue();
3928
4597
  const method = this.methodValue();
4598
+ const funding = this.previewFunding();
3929
4599
  this.estimateTick();
3930
4600
  const run = ++this.estimateRun;
3931
4601
  untracked(() => {
@@ -3951,7 +4621,11 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
3951
4621
  fees = await callHost(() => estimate({
3952
4622
  amount,
3953
4623
  paymentMethod: method,
3954
- paymentMethodType: stripeMethodType(method)
4624
+ paymentMethodType: stripeMethodType(method),
4625
+ ...this.config().fundingPreview() ? {
4626
+ funding,
4627
+ confirmationTokenId: funding === null ? null : this.previewTokenId
4628
+ } : {}
3955
4629
  })) ?? null;
3956
4630
  } catch {
3957
4631
  fees = null;
@@ -3992,6 +4666,7 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
3992
4666
  untracked(() => {
3993
4667
  this.complete.set(false);
3994
4668
  this.error.set("");
4669
+ this.cancelPreview();
3995
4670
  });
3996
4671
  });
3997
4672
  effect(() => {
@@ -4000,8 +4675,77 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
4000
4675
  });
4001
4676
  inject(DestroyRef).onDestroy(() => {
4002
4677
  this.estimateRun++;
4678
+ this.cancelPreview();
4003
4679
  this.cancelIntent();
4004
4680
  });
4681
+ const controls = {
4682
+ markUnknown: () => this.payment()?.markUnknown(),
4683
+ markSucceeded: () => this.payment()?.markSucceeded(),
4684
+ markFailed: () => this.payment()?.markFailed(),
4685
+ resetPaid: () => {
4686
+ this.payment()?.resetPaid();
4687
+ this.done.set(false);
4688
+ this.confirmation.set(null);
4689
+ this.error.set("");
4690
+ this.ctx().setExclusive(false);
4691
+ },
4692
+ markNotCharged: () => {
4693
+ this.payment()?.markNotCharged();
4694
+ this.processing.set(false);
4695
+ this.ctx().setBusy(false);
4696
+ }
4697
+ };
4698
+ effect(() => {
4699
+ const config = this.config();
4700
+ untracked(() => config.attachControls(controls));
4701
+ });
4702
+ inject(DestroyRef).onDestroy(() => this.config().detachControls(controls));
4703
+ }
4704
+ onElementChange(change) {
4705
+ this.complete.set(change.complete);
4706
+ if (!this.config().fundingPreview() || !this.config().estimateFees() || this.methodType() !== "card") return;
4707
+ this.stopPreviewTimer();
4708
+ const run = ++this.previewRun;
4709
+ if (!change.complete) {
4710
+ this.previewTokenId = null;
4711
+ this.previewFunding.set(null);
4712
+ this.previewPending.set(false);
4713
+ return;
4714
+ }
4715
+ this.previewPending.set(true);
4716
+ this.previewTimer = setTimeout(() => void this.runPreview(run), 400);
4717
+ }
4718
+ async runPreview(run) {
4719
+ this.previewTimer = null;
4720
+ const payment = this.payment();
4721
+ if (!payment || this.processing() || this.done() || run !== this.previewRun) {
4722
+ if (run === this.previewRun) this.previewPending.set(false);
4723
+ return;
4724
+ }
4725
+ const made = await payment.createConfirmationToken();
4726
+ if (run !== this.previewRun) return;
4727
+ if (!made || !("id" in made) || made.paymentMethodType !== "card") {
4728
+ this.previewTokenId = null;
4729
+ this.previewFunding.set(null);
4730
+ this.previewPending.set(false);
4731
+ return;
4732
+ }
4733
+ this.previewTokenId = made.id;
4734
+ this.previewFunding.set(made.funding);
4735
+ this.previewPending.set(false);
4736
+ }
4737
+ stopPreviewTimer() {
4738
+ if (this.previewTimer) {
4739
+ clearTimeout(this.previewTimer);
4740
+ this.previewTimer = null;
4741
+ }
4742
+ }
4743
+ cancelPreview() {
4744
+ this.stopPreviewTimer();
4745
+ this.previewRun++;
4746
+ this.previewTokenId = null;
4747
+ this.previewFunding.set(null);
4748
+ this.previewPending.set(false);
4005
4749
  }
4006
4750
  retryEstimate() {
4007
4751
  this.estimateTick.update((n) => n + 1);
@@ -4015,11 +4759,81 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
4015
4759
  this.processing.set(false);
4016
4760
  this.ctx().report("failed", { message: failure.message });
4017
4761
  }
4762
+ onAttemptOutcome(outcome) {
4763
+ const ctx = this.ctx();
4764
+ const duplicate = outcome.kind === "unknown" && outcome.reason === "duplicate_suspected";
4765
+ if (outcome.kind === "unknown" && !duplicate) this.attemptUnknown = true;
4766
+ else if (outcome.kind === "succeeded" || outcome.kind === "failed") this.attemptUnknown = false;
4767
+ if (duplicate) {
4768
+ const message = this.labels.t("paymentAttempt.duplicate");
4769
+ this.error.set(message);
4770
+ ctx.report("duplicate_suspected", {
4771
+ message,
4772
+ attemptKey: outcome.attemptKey
4773
+ });
4774
+ ctx.announce(message);
4775
+ } else if (outcome.kind === "unknown") {
4776
+ this.payAmount = this.payment()?.attempt.pinnedAmount() ?? this.payAmount;
4777
+ this.payMethod = this.payment()?.attempt.pinnedMethod() ?? this.payMethod;
4778
+ const message = this.labels.t(outcome.reason === "offline" ? "paymentAttempt.offlineInFlight" : outcome.reason === "auth_abandoned" ? "paymentAttempt.authAbandoned" : outcome.reason === "timeout" ? "paymentAttempt.timeout" : "paymentAttempt.checking");
4779
+ ctx.report("unknown", { message });
4780
+ ctx.announce(message);
4781
+ } else if (outcome.kind === "refused") ctx.report("refused", { message: this.labels.t(refusalLabelKey(outcome.reason ?? "")) });
4782
+ else if (outcome.kind === "succeeded" && outcome.reason === "other_tab") ctx.report("paid_elsewhere", {
4783
+ message: this.labels.t("paymentAttempt.paid"),
4784
+ attemptKey: outcome.attemptKey,
4785
+ ...outcome.method !== void 0 ? { paid: {
4786
+ amount: outcome.amount ?? null,
4787
+ method: outcome.method
4788
+ } } : {}
4789
+ });
4790
+ else if (outcome.kind === "succeeded" && !this.done() && (outcome.reason === "status_check" || outcome.reason === "host" || !this.processing() || this.isOlderAttempt(outcome.attemptKey))) this.completeAfterCheck(ctx, this.isOlderAttempt(outcome.attemptKey), outcome);
4791
+ else if (outcome.kind === "failed" && (outcome.reason === "status_check" || outcome.reason === "host")) {
4792
+ const message = this.labels.t("paymentAttempt.failedAfterCheck");
4793
+ this.error.set(message);
4794
+ ctx.report("failed", { message });
4795
+ this.cancelIntent(true);
4796
+ ctx.setBusy(false);
4797
+ }
4798
+ }
4799
+ isOlderAttempt(key) {
4800
+ const attempt = this.payment()?.attempt;
4801
+ return !!attempt && attempt.inFlight() && attempt.key() !== key;
4802
+ }
4803
+ async completeAfterCheck(ctx, older = false, outcome) {
4804
+ if (this.done()) return;
4805
+ this.done.set(true);
4806
+ const info = older ? null : this.intent;
4807
+ if (!older) this.intent = null;
4808
+ let finalizeFailed = false;
4809
+ const finalize = this.config().finalize();
4810
+ if (finalize && info) try {
4811
+ await callHost(() => finalize(info));
4812
+ } catch {
4813
+ finalizeFailed = true;
4814
+ }
4815
+ const known = outcome ? this.attempts.get(outcome.attemptKey) : void 0;
4816
+ const result = {
4817
+ type: "stripe",
4818
+ paymentMethod: known?.method ?? this.payMethod ?? ctx.method,
4819
+ amount: known?.amount ?? outcome?.amount ?? this.payAmount ?? ctx.amount ?? this.lastAmount() ?? 0
4820
+ };
4821
+ this.doneAmount = result.amount;
4822
+ this.doneMethod = result.paymentMethod;
4823
+ ctx.report(finalizeFailed ? "finalize-failed" : "paid", { result });
4824
+ ctx.announce(this.labels.t("paymentAttempt.succeededAfterCheck"));
4825
+ ctx.setBusy(false);
4826
+ ctx.complete(result);
4827
+ }
4018
4828
  async pay() {
4019
4829
  const ctx = this.ctx();
4020
4830
  const payment = this.payment();
4021
4831
  if (this.processing() || this.estimating() || this.done() || !payment) return;
4022
4832
  if (!ctx.validate() || ctx.amount == null) return;
4833
+ this.payAmount = ctx.amount;
4834
+ this.payMethod = ctx.method;
4835
+ const attemptAmount = ctx.amount;
4836
+ const attemptMethod = ctx.method;
4023
4837
  this.error.set("");
4024
4838
  this.processing.set(true);
4025
4839
  ctx.setBusy(true);
@@ -4027,14 +4841,14 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
4027
4841
  let finished = false;
4028
4842
  try {
4029
4843
  const event = await payment.confirm();
4030
- if (event) finished = await this.afterConfirm(event, ctx);
4844
+ if (event) finished = await this.afterConfirm(event, ctx, attemptAmount, attemptMethod);
4031
4845
  } finally {
4032
4846
  this.processing.set(false);
4033
- if (!finished) ctx.setBusy(false);
4847
+ if (!finished && !payment.attempt.unknown()) ctx.setBusy(false);
4034
4848
  }
4035
4849
  }
4036
- async afterConfirm(event, ctx) {
4037
- const amount = ctx.amount;
4850
+ async afterConfirm(event, ctx, amount, method) {
4851
+ if (this.done()) return true;
4038
4852
  const money = formatCurrency(amount, { currency: ctx.currency });
4039
4853
  if (event.outcome !== "succeeded" && event.outcome !== "processing" && event.outcome !== "requires_verification") {
4040
4854
  this.error.set(this.texts.notCompleted);
@@ -4051,9 +4865,11 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
4051
4865
  }
4052
4866
  const result = {
4053
4867
  type: "stripe",
4054
- paymentMethod: ctx.method,
4868
+ paymentMethod: method,
4055
4869
  amount
4056
4870
  };
4871
+ this.doneAmount = amount;
4872
+ this.doneMethod = method;
4057
4873
  if (event.outcome === "succeeded") {
4058
4874
  ctx.report(finalizeFailed ? "finalize-failed" : "paid", { result });
4059
4875
  this.done.set(true);
@@ -4080,13 +4896,14 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
4080
4896
  this.done.set(true);
4081
4897
  ctx.complete({
4082
4898
  type: "stripe",
4083
- paymentMethod: ctx.method,
4084
- amount: ctx.amount ?? this.lastAmount() ?? 0
4899
+ paymentMethod: this.doneMethod ?? ctx.method,
4900
+ amount: this.doneAmount ?? ctx.amount ?? this.lastAmount() ?? 0
4085
4901
  });
4086
4902
  }
4087
4903
  cancelIntent(force = false) {
4088
4904
  const info = this.intent;
4089
4905
  if (!info || this.processing() && !force) return;
4906
+ if (this.attemptUnknown) return;
4090
4907
  this.intent = null;
4091
4908
  const cancel = this.config().cancel();
4092
4909
  if (cancel) callHost(() => cancel(info)).catch(() => {});
@@ -4152,9 +4969,12 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
4152
4969
  }
4153
4970
  @if (lastAmount() != null) {
4154
4971
  <ui-stripe-payment #payment mode="payment" [publishableKey]="config().publishableKey()" [stripeAccount]="config().stripeAccount()" [deferred]="deferred()"
4155
- [createIntent]="createIntentFn" [paymentMethodTypes]="[methodType()]" [showSubmit]="false" [showErrors]="false" [autoHandleCardAction]="true"
4972
+ [createIntent]="createIntentFn" [paymentMethodTypes]="[methodType()]" [showSubmit]="false" [showErrors]="false" [autoHandleCardAction]="true" [collectConfirmationToken]="config().fundingPreview()"
4973
+ [duplicateProtection]="config().duplicateProtection()" [attemptAmount]="ctx().amount" [attemptMethod]="ctx().method" [payableRef]="config().payableRef()" [attemptKey]="config().attemptKey()" [checkStatus]="config().checkStatus()" [paid]="config().paid()" [hostPending]="config().hostPending()"
4974
+ [statusPollMs]="config().statusPollMs()" [statusPollMaxMs]="config().statusPollMaxMs()" [statusCheckTimeoutMs]="config().statusCheckTimeoutMs()" [statusFailGraceMs]="config().statusFailGraceMs()" [authTimeoutMs]="config().authTimeoutMs()" [allowStartOver]="config().allowStartOver()" [offlineOverride]="config().offlineOverride()" [confirmTimeoutMs]="config().confirmTimeoutMs()"
4975
+ [readinessCheck]="config().readinessCheck()" [readinessTimeoutMs]="config().readinessTimeoutMs()" [readinessEveryMs]="config().readinessEveryMs()" (outcome)="onAttemptOutcome($event)"
4156
4976
  [wallets]="wallets" [fields]="fields" [defaultValues]="defaultValues()" [appearance]="$any(config().appearance())" [appearanceFromTokens]="true" [label]="labels.t('stripePaymentStripeMethod.paymentDetails')"
4157
- (ready)="onReady()" (elementChange)="complete.set($event.complete)" (failed)="onFailed($event)" (loadError)="onFailed($event)" />
4977
+ (ready)="onReady()" (elementChange)="onElementChange($event)" (failed)="onFailed($event)" (loadError)="onFailed($event)" />
4158
4978
  @if (totalCard(); as card) {
4159
4979
  <ui-kpi-card class="psm-total" data-testid="stripe-method-total" [label]="labels.t('stripePaymentStripeMethod.totalCharged')" [value]="card.value" [subtitle]="card.subtitle" icon="dollar" color="blue" valueColor="blue" />
4160
4980
  }
@@ -4171,7 +4991,7 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
4171
4991
  </div>
4172
4992
  `,
4173
4993
  isInline: true,
4174
- styles: ["ui-payment-stripe-body{display:block;min-width:0}ui-payment-stripe-body .psm-error{margin-top:12px}ui-payment-stripe-body .psm-total{display:block;margin-top:16px}ui-payment-stripe-body .psm-fees{margin:16px 0 0;padding:14px 16px;border:1px solid var(--ui-psp-border, #e2e8f0);border-radius:10px;font-size:.8125rem}ui-payment-stripe-body .psm-fee{display:flex;justify-content:space-between;padding:4px 0;color:var(--ui-psp-muted, #475569)}ui-payment-stripe-body .psm-fee dt,ui-payment-stripe-body .psm-fee dd{margin:0}ui-payment-stripe-body .psm-notice:focus{outline:none}ui-payment-stripe-body .psm-notice p{margin:0 0 6px}\n"],
4994
+ styles: ["ui-payment-stripe-body{display:block;min-width:0}ui-payment-stripe-body .psm-error{margin-top:12px}ui-payment-stripe-body .psm-total{display:block;margin-top:16px}ui-payment-stripe-body .psm-fees{margin:16px 0 0;padding:14px 16px;border:1px solid var(--ui-psp-border, #e2e8f0);border-radius:10px;font-size:.8125rem}ui-payment-stripe-body .psm-fee{display:flex;justify-content:space-between;gap:12px;padding:4px 0;color:var(--ui-psp-muted, #475569)}ui-payment-stripe-body .psm-fee dt,ui-payment-stripe-body .psm-fee dd{margin:0}ui-payment-stripe-body .psm-notice:focus{outline:none}ui-payment-stripe-body .psm-notice p{margin:0 0 6px}\n"],
4175
4995
  dependencies: [
4176
4996
  {
4177
4997
  kind: "component",
@@ -4281,6 +5101,26 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
4281
5101
  "redirect",
4282
5102
  "submitBeforeConfirm",
4283
5103
  "autoHandleCardAction",
5104
+ "collectConfirmationToken",
5105
+ "duplicateProtection",
5106
+ "attemptAmount",
5107
+ "attemptMethod",
5108
+ "payableRef",
5109
+ "attemptKey",
5110
+ "checkStatus",
5111
+ "paid",
5112
+ "hostPending",
5113
+ "statusPollMs",
5114
+ "statusPollMaxMs",
5115
+ "statusCheckTimeoutMs",
5116
+ "statusFailGraceMs",
5117
+ "allowStartOver",
5118
+ "offlineOverride",
5119
+ "authTimeoutMs",
5120
+ "confirmTimeoutMs",
5121
+ "readinessCheck",
5122
+ "readinessTimeoutMs",
5123
+ "readinessEveryMs",
4284
5124
  "submitLabel",
4285
5125
  "showSubmit",
4286
5126
  "disabled",
@@ -4307,9 +5147,14 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
4307
5147
  "ready",
4308
5148
  "paymentMethodTypeChange",
4309
5149
  "elementChange",
5150
+ "confirmationToken",
4310
5151
  "confirmed",
4311
5152
  "failed",
4312
- "loadError"
5153
+ "loadError",
5154
+ "inFlightChange",
5155
+ "outcome",
5156
+ "attemptKeyChange",
5157
+ "readinessChange"
4313
5158
  ]
4314
5159
  }
4315
5160
  ],
@@ -4357,9 +5202,12 @@ i0.ɵɵngDeclareClassMetadata({
4357
5202
  }
4358
5203
  @if (lastAmount() != null) {
4359
5204
  <ui-stripe-payment #payment mode="payment" [publishableKey]="config().publishableKey()" [stripeAccount]="config().stripeAccount()" [deferred]="deferred()"
4360
- [createIntent]="createIntentFn" [paymentMethodTypes]="[methodType()]" [showSubmit]="false" [showErrors]="false" [autoHandleCardAction]="true"
5205
+ [createIntent]="createIntentFn" [paymentMethodTypes]="[methodType()]" [showSubmit]="false" [showErrors]="false" [autoHandleCardAction]="true" [collectConfirmationToken]="config().fundingPreview()"
5206
+ [duplicateProtection]="config().duplicateProtection()" [attemptAmount]="ctx().amount" [attemptMethod]="ctx().method" [payableRef]="config().payableRef()" [attemptKey]="config().attemptKey()" [checkStatus]="config().checkStatus()" [paid]="config().paid()" [hostPending]="config().hostPending()"
5207
+ [statusPollMs]="config().statusPollMs()" [statusPollMaxMs]="config().statusPollMaxMs()" [statusCheckTimeoutMs]="config().statusCheckTimeoutMs()" [statusFailGraceMs]="config().statusFailGraceMs()" [authTimeoutMs]="config().authTimeoutMs()" [allowStartOver]="config().allowStartOver()" [offlineOverride]="config().offlineOverride()" [confirmTimeoutMs]="config().confirmTimeoutMs()"
5208
+ [readinessCheck]="config().readinessCheck()" [readinessTimeoutMs]="config().readinessTimeoutMs()" [readinessEveryMs]="config().readinessEveryMs()" (outcome)="onAttemptOutcome($event)"
4361
5209
  [wallets]="wallets" [fields]="fields" [defaultValues]="defaultValues()" [appearance]="$any(config().appearance())" [appearanceFromTokens]="true" [label]="labels.t('stripePaymentStripeMethod.paymentDetails')"
4362
- (ready)="onReady()" (elementChange)="complete.set($event.complete)" (failed)="onFailed($event)" (loadError)="onFailed($event)" />
5210
+ (ready)="onReady()" (elementChange)="onElementChange($event)" (failed)="onFailed($event)" (loadError)="onFailed($event)" />
4363
5211
  @if (totalCard(); as card) {
4364
5212
  <ui-kpi-card class="psm-total" data-testid="stripe-method-total" [label]="labels.t('stripePaymentStripeMethod.totalCharged')" [value]="card.value" [subtitle]="card.subtitle" icon="dollar" color="blue" valueColor="blue" />
4365
5213
  }
@@ -4375,7 +5223,7 @@ i0.ɵɵngDeclareClassMetadata({
4375
5223
  }
4376
5224
  </div>
4377
5225
  `,
4378
- styles: ["ui-payment-stripe-body{display:block;min-width:0}ui-payment-stripe-body .psm-error{margin-top:12px}ui-payment-stripe-body .psm-total{display:block;margin-top:16px}ui-payment-stripe-body .psm-fees{margin:16px 0 0;padding:14px 16px;border:1px solid var(--ui-psp-border, #e2e8f0);border-radius:10px;font-size:.8125rem}ui-payment-stripe-body .psm-fee{display:flex;justify-content:space-between;padding:4px 0;color:var(--ui-psp-muted, #475569)}ui-payment-stripe-body .psm-fee dt,ui-payment-stripe-body .psm-fee dd{margin:0}ui-payment-stripe-body .psm-notice:focus{outline:none}ui-payment-stripe-body .psm-notice p{margin:0 0 6px}\n"]
5226
+ styles: ["ui-payment-stripe-body{display:block;min-width:0}ui-payment-stripe-body .psm-error{margin-top:12px}ui-payment-stripe-body .psm-total{display:block;margin-top:16px}ui-payment-stripe-body .psm-fees{margin:16px 0 0;padding:14px 16px;border:1px solid var(--ui-psp-border, #e2e8f0);border-radius:10px;font-size:.8125rem}ui-payment-stripe-body .psm-fee{display:flex;justify-content:space-between;gap:12px;padding:4px 0;color:var(--ui-psp-muted, #475569)}ui-payment-stripe-body .psm-fee dt,ui-payment-stripe-body .psm-fee dd{margin:0}ui-payment-stripe-body .psm-notice:focus{outline:none}ui-payment-stripe-body .psm-notice p{margin:0 0 6px}\n"]
4379
5227
  }]
4380
5228
  }],
4381
5229
  ctorParameters: () => [],
@@ -4424,15 +5272,55 @@ var StripePaymentMethodComponent = class StripePaymentMethodComponent extends Pa
4424
5272
  })), ...ngDevMode ? [{ debugName: "methodList" }] : /* istanbul ignore next */ []);
4425
5273
  this.estimateTimeoutMs = input(1e4, ...ngDevMode ? [{ debugName: "estimateTimeoutMs" }] : /* istanbul ignore next */ []);
4426
5274
  this.feesRequired = input(false, ...ngDevMode ? [{ debugName: "feesRequired" }] : /* istanbul ignore next */ []);
5275
+ this.fundingPreview = input(false, ...ngDevMode ? [{ debugName: "fundingPreview" }] : /* istanbul ignore next */ []);
5276
+ this.duplicateProtection = input(false, ...ngDevMode ? [{ debugName: "duplicateProtection" }] : /* istanbul ignore next */ []);
5277
+ this.payableRef = input(null, ...ngDevMode ? [{ debugName: "payableRef" }] : /* istanbul ignore next */ []);
5278
+ this.attemptKey = input(null, ...ngDevMode ? [{ debugName: "attemptKey" }] : /* istanbul ignore next */ []);
5279
+ this.checkStatus = input(null, ...ngDevMode ? [{ debugName: "checkStatus" }] : /* istanbul ignore next */ []);
5280
+ this.paid = input(false, ...ngDevMode ? [{ debugName: "paid" }] : /* istanbul ignore next */ []);
5281
+ this.hostPending = input(false, ...ngDevMode ? [{ debugName: "hostPending" }] : /* istanbul ignore next */ []);
5282
+ this.statusPollMs = input(PAYMENT_STATUS_POLL_MS, ...ngDevMode ? [{ debugName: "statusPollMs" }] : /* istanbul ignore next */ []);
5283
+ this.statusPollMaxMs = input(PAYMENT_STATUS_POLL_MAX_MS, ...ngDevMode ? [{ debugName: "statusPollMaxMs" }] : /* istanbul ignore next */ []);
5284
+ this.statusCheckTimeoutMs = input(PAYMENT_STATUS_CHECK_TIMEOUT_MS, ...ngDevMode ? [{ debugName: "statusCheckTimeoutMs" }] : /* istanbul ignore next */ []);
5285
+ this.statusFailGraceMs = input(PAYMENT_STATUS_FAIL_GRACE_MS, ...ngDevMode ? [{ debugName: "statusFailGraceMs" }] : /* istanbul ignore next */ []);
5286
+ this.allowStartOver = input(false, ...ngDevMode ? [{ debugName: "allowStartOver" }] : /* istanbul ignore next */ []);
5287
+ this.offlineOverride = input(false, ...ngDevMode ? [{ debugName: "offlineOverride" }] : /* istanbul ignore next */ []);
5288
+ this.authTimeoutMs = input(PAYMENT_AUTH_TIMEOUT_MS, ...ngDevMode ? [{ debugName: "authTimeoutMs" }] : /* istanbul ignore next */ []);
5289
+ this.confirmTimeoutMs = input(PAYMENT_REQUEST_TIMEOUT_MS, ...ngDevMode ? [{ debugName: "confirmTimeoutMs" }] : /* istanbul ignore next */ []);
5290
+ this.readinessCheck = input(null, ...ngDevMode ? [{ debugName: "readinessCheck" }] : /* istanbul ignore next */ []);
5291
+ this.readinessTimeoutMs = input(PAYMENT_READINESS_TIMEOUT_MS, ...ngDevMode ? [{ debugName: "readinessTimeoutMs" }] : /* istanbul ignore next */ []);
5292
+ this.readinessEveryMs = input(PAYMENT_READINESS_EVERY_MS, ...ngDevMode ? [{ debugName: "readinessEveryMs" }] : /* istanbul ignore next */ []);
4427
5293
  this.receiptNoteInput = input(null, {
4428
5294
  ...ngDevMode ? { debugName: "receiptNoteInput" } : /* istanbul ignore next */ {},
4429
5295
  alias: "receiptNote"
4430
5296
  });
4431
5297
  this.receiptNote = computed(() => this.receiptNoteInput() ?? STRIPE_METHOD_TEXTS.receiptNote, ...ngDevMode ? [{ debugName: "receiptNote" }] : /* istanbul ignore next */ []);
4432
5298
  this.body = viewChild("body", ...ngDevMode ? [{ debugName: "body" }] : /* istanbul ignore next */ []);
5299
+ this.controls = signal(null, ...ngDevMode ? [{ debugName: "controls" }] : /* istanbul ignore next */ []);
4433
5300
  this.methods = this.methodList;
4434
5301
  this.template = this.body;
4435
5302
  }
5303
+ attachControls(controls) {
5304
+ this.controls.set(controls);
5305
+ }
5306
+ detachControls(controls) {
5307
+ if (this.controls() === controls) this.controls.set(null);
5308
+ }
5309
+ markUnknown() {
5310
+ this.controls()?.markUnknown();
5311
+ }
5312
+ markSucceeded() {
5313
+ this.controls()?.markSucceeded();
5314
+ }
5315
+ markFailed() {
5316
+ this.controls()?.markFailed();
5317
+ }
5318
+ markNotCharged() {
5319
+ this.controls()?.markNotCharged();
5320
+ }
5321
+ resetPaid() {
5322
+ this.controls()?.resetPaid();
5323
+ }
4436
5324
  static {
4437
5325
  this.ɵfac = i0.ɵɵngDeclareFactory({
4438
5326
  minVersion: "12.0.0",
@@ -4528,6 +5416,132 @@ var StripePaymentMethodComponent = class StripePaymentMethodComponent extends Pa
4528
5416
  isRequired: false,
4529
5417
  transformFunction: null
4530
5418
  },
5419
+ fundingPreview: {
5420
+ classPropertyName: "fundingPreview",
5421
+ publicName: "fundingPreview",
5422
+ isSignal: true,
5423
+ isRequired: false,
5424
+ transformFunction: null
5425
+ },
5426
+ duplicateProtection: {
5427
+ classPropertyName: "duplicateProtection",
5428
+ publicName: "duplicateProtection",
5429
+ isSignal: true,
5430
+ isRequired: false,
5431
+ transformFunction: null
5432
+ },
5433
+ payableRef: {
5434
+ classPropertyName: "payableRef",
5435
+ publicName: "payableRef",
5436
+ isSignal: true,
5437
+ isRequired: false,
5438
+ transformFunction: null
5439
+ },
5440
+ attemptKey: {
5441
+ classPropertyName: "attemptKey",
5442
+ publicName: "attemptKey",
5443
+ isSignal: true,
5444
+ isRequired: false,
5445
+ transformFunction: null
5446
+ },
5447
+ checkStatus: {
5448
+ classPropertyName: "checkStatus",
5449
+ publicName: "checkStatus",
5450
+ isSignal: true,
5451
+ isRequired: false,
5452
+ transformFunction: null
5453
+ },
5454
+ paid: {
5455
+ classPropertyName: "paid",
5456
+ publicName: "paid",
5457
+ isSignal: true,
5458
+ isRequired: false,
5459
+ transformFunction: null
5460
+ },
5461
+ hostPending: {
5462
+ classPropertyName: "hostPending",
5463
+ publicName: "hostPending",
5464
+ isSignal: true,
5465
+ isRequired: false,
5466
+ transformFunction: null
5467
+ },
5468
+ statusPollMs: {
5469
+ classPropertyName: "statusPollMs",
5470
+ publicName: "statusPollMs",
5471
+ isSignal: true,
5472
+ isRequired: false,
5473
+ transformFunction: null
5474
+ },
5475
+ statusPollMaxMs: {
5476
+ classPropertyName: "statusPollMaxMs",
5477
+ publicName: "statusPollMaxMs",
5478
+ isSignal: true,
5479
+ isRequired: false,
5480
+ transformFunction: null
5481
+ },
5482
+ statusCheckTimeoutMs: {
5483
+ classPropertyName: "statusCheckTimeoutMs",
5484
+ publicName: "statusCheckTimeoutMs",
5485
+ isSignal: true,
5486
+ isRequired: false,
5487
+ transformFunction: null
5488
+ },
5489
+ statusFailGraceMs: {
5490
+ classPropertyName: "statusFailGraceMs",
5491
+ publicName: "statusFailGraceMs",
5492
+ isSignal: true,
5493
+ isRequired: false,
5494
+ transformFunction: null
5495
+ },
5496
+ allowStartOver: {
5497
+ classPropertyName: "allowStartOver",
5498
+ publicName: "allowStartOver",
5499
+ isSignal: true,
5500
+ isRequired: false,
5501
+ transformFunction: null
5502
+ },
5503
+ offlineOverride: {
5504
+ classPropertyName: "offlineOverride",
5505
+ publicName: "offlineOverride",
5506
+ isSignal: true,
5507
+ isRequired: false,
5508
+ transformFunction: null
5509
+ },
5510
+ authTimeoutMs: {
5511
+ classPropertyName: "authTimeoutMs",
5512
+ publicName: "authTimeoutMs",
5513
+ isSignal: true,
5514
+ isRequired: false,
5515
+ transformFunction: null
5516
+ },
5517
+ confirmTimeoutMs: {
5518
+ classPropertyName: "confirmTimeoutMs",
5519
+ publicName: "confirmTimeoutMs",
5520
+ isSignal: true,
5521
+ isRequired: false,
5522
+ transformFunction: null
5523
+ },
5524
+ readinessCheck: {
5525
+ classPropertyName: "readinessCheck",
5526
+ publicName: "readinessCheck",
5527
+ isSignal: true,
5528
+ isRequired: false,
5529
+ transformFunction: null
5530
+ },
5531
+ readinessTimeoutMs: {
5532
+ classPropertyName: "readinessTimeoutMs",
5533
+ publicName: "readinessTimeoutMs",
5534
+ isSignal: true,
5535
+ isRequired: false,
5536
+ transformFunction: null
5537
+ },
5538
+ readinessEveryMs: {
5539
+ classPropertyName: "readinessEveryMs",
5540
+ publicName: "readinessEveryMs",
5541
+ isSignal: true,
5542
+ isRequired: false,
5543
+ transformFunction: null
5544
+ },
4531
5545
  receiptNoteInput: {
4532
5546
  classPropertyName: "receiptNoteInput",
4533
5547
  publicName: "receiptNote",
@@ -4671,6 +5685,150 @@ i0.ɵɵngDeclareClassMetadata({
4671
5685
  required: false
4672
5686
  }]
4673
5687
  }],
5688
+ fundingPreview: [{
5689
+ type: i0.Input,
5690
+ args: [{
5691
+ isSignal: true,
5692
+ alias: "fundingPreview",
5693
+ required: false
5694
+ }]
5695
+ }],
5696
+ duplicateProtection: [{
5697
+ type: i0.Input,
5698
+ args: [{
5699
+ isSignal: true,
5700
+ alias: "duplicateProtection",
5701
+ required: false
5702
+ }]
5703
+ }],
5704
+ payableRef: [{
5705
+ type: i0.Input,
5706
+ args: [{
5707
+ isSignal: true,
5708
+ alias: "payableRef",
5709
+ required: false
5710
+ }]
5711
+ }],
5712
+ attemptKey: [{
5713
+ type: i0.Input,
5714
+ args: [{
5715
+ isSignal: true,
5716
+ alias: "attemptKey",
5717
+ required: false
5718
+ }]
5719
+ }],
5720
+ checkStatus: [{
5721
+ type: i0.Input,
5722
+ args: [{
5723
+ isSignal: true,
5724
+ alias: "checkStatus",
5725
+ required: false
5726
+ }]
5727
+ }],
5728
+ paid: [{
5729
+ type: i0.Input,
5730
+ args: [{
5731
+ isSignal: true,
5732
+ alias: "paid",
5733
+ required: false
5734
+ }]
5735
+ }],
5736
+ hostPending: [{
5737
+ type: i0.Input,
5738
+ args: [{
5739
+ isSignal: true,
5740
+ alias: "hostPending",
5741
+ required: false
5742
+ }]
5743
+ }],
5744
+ statusPollMs: [{
5745
+ type: i0.Input,
5746
+ args: [{
5747
+ isSignal: true,
5748
+ alias: "statusPollMs",
5749
+ required: false
5750
+ }]
5751
+ }],
5752
+ statusPollMaxMs: [{
5753
+ type: i0.Input,
5754
+ args: [{
5755
+ isSignal: true,
5756
+ alias: "statusPollMaxMs",
5757
+ required: false
5758
+ }]
5759
+ }],
5760
+ statusCheckTimeoutMs: [{
5761
+ type: i0.Input,
5762
+ args: [{
5763
+ isSignal: true,
5764
+ alias: "statusCheckTimeoutMs",
5765
+ required: false
5766
+ }]
5767
+ }],
5768
+ statusFailGraceMs: [{
5769
+ type: i0.Input,
5770
+ args: [{
5771
+ isSignal: true,
5772
+ alias: "statusFailGraceMs",
5773
+ required: false
5774
+ }]
5775
+ }],
5776
+ allowStartOver: [{
5777
+ type: i0.Input,
5778
+ args: [{
5779
+ isSignal: true,
5780
+ alias: "allowStartOver",
5781
+ required: false
5782
+ }]
5783
+ }],
5784
+ offlineOverride: [{
5785
+ type: i0.Input,
5786
+ args: [{
5787
+ isSignal: true,
5788
+ alias: "offlineOverride",
5789
+ required: false
5790
+ }]
5791
+ }],
5792
+ authTimeoutMs: [{
5793
+ type: i0.Input,
5794
+ args: [{
5795
+ isSignal: true,
5796
+ alias: "authTimeoutMs",
5797
+ required: false
5798
+ }]
5799
+ }],
5800
+ confirmTimeoutMs: [{
5801
+ type: i0.Input,
5802
+ args: [{
5803
+ isSignal: true,
5804
+ alias: "confirmTimeoutMs",
5805
+ required: false
5806
+ }]
5807
+ }],
5808
+ readinessCheck: [{
5809
+ type: i0.Input,
5810
+ args: [{
5811
+ isSignal: true,
5812
+ alias: "readinessCheck",
5813
+ required: false
5814
+ }]
5815
+ }],
5816
+ readinessTimeoutMs: [{
5817
+ type: i0.Input,
5818
+ args: [{
5819
+ isSignal: true,
5820
+ alias: "readinessTimeoutMs",
5821
+ required: false
5822
+ }]
5823
+ }],
5824
+ readinessEveryMs: [{
5825
+ type: i0.Input,
5826
+ args: [{
5827
+ isSignal: true,
5828
+ alias: "readinessEveryMs",
5829
+ required: false
5830
+ }]
5831
+ }],
4674
5832
  receiptNoteInput: [{
4675
5833
  type: i0.Input,
4676
5834
  args: [{