@forgeroute/ui 0.5.0 → 0.5.1

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, 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" />
@@ -1736,67 +2169,227 @@ i0.ɵɵngDeclareClassMetadata({
1736
2169
  required: false
1737
2170
  }]
1738
2171
  }],
1739
- appearance: [{
2172
+ appearance: [{
2173
+ type: i0.Input,
2174
+ args: [{
2175
+ isSignal: true,
2176
+ alias: "appearance",
2177
+ required: false
2178
+ }]
2179
+ }],
2180
+ appearanceFromTokens: [{
2181
+ type: i0.Input,
2182
+ args: [{
2183
+ isSignal: true,
2184
+ alias: "appearanceFromTokens",
2185
+ required: false
2186
+ }]
2187
+ }],
2188
+ returnUrl: [{
2189
+ type: i0.Input,
2190
+ args: [{
2191
+ isSignal: true,
2192
+ alias: "returnUrl",
2193
+ required: false
2194
+ }]
2195
+ }],
2196
+ billingDetails: [{
2197
+ type: i0.Input,
2198
+ args: [{
2199
+ isSignal: true,
2200
+ alias: "billingDetails",
2201
+ required: false
2202
+ }]
2203
+ }],
2204
+ confirmParams: [{
2205
+ type: i0.Input,
2206
+ args: [{
2207
+ isSignal: true,
2208
+ alias: "confirmParams",
2209
+ required: false
2210
+ }]
2211
+ }],
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: [{
1740
2333
  type: i0.Input,
1741
2334
  args: [{
1742
2335
  isSignal: true,
1743
- alias: "appearance",
2336
+ alias: "statusFailGraceMs",
1744
2337
  required: false
1745
2338
  }]
1746
2339
  }],
1747
- appearanceFromTokens: [{
2340
+ allowStartOver: [{
1748
2341
  type: i0.Input,
1749
2342
  args: [{
1750
2343
  isSignal: true,
1751
- alias: "appearanceFromTokens",
2344
+ alias: "allowStartOver",
1752
2345
  required: false
1753
2346
  }]
1754
2347
  }],
1755
- returnUrl: [{
2348
+ offlineOverride: [{
1756
2349
  type: i0.Input,
1757
2350
  args: [{
1758
2351
  isSignal: true,
1759
- alias: "returnUrl",
2352
+ alias: "offlineOverride",
1760
2353
  required: false
1761
2354
  }]
1762
2355
  }],
1763
- billingDetails: [{
2356
+ authTimeoutMs: [{
1764
2357
  type: i0.Input,
1765
2358
  args: [{
1766
2359
  isSignal: true,
1767
- alias: "billingDetails",
2360
+ alias: "authTimeoutMs",
1768
2361
  required: false
1769
2362
  }]
1770
2363
  }],
1771
- confirmParams: [{
2364
+ confirmTimeoutMs: [{
1772
2365
  type: i0.Input,
1773
2366
  args: [{
1774
2367
  isSignal: true,
1775
- alias: "confirmParams",
2368
+ alias: "confirmTimeoutMs",
1776
2369
  required: false
1777
2370
  }]
1778
2371
  }],
1779
- redirect: [{
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,6 +4435,12 @@ 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 */ []);
3827
4446
  this.estimate = signal(null, ...ngDevMode ? [{ debugName: "estimate" }] : /* istanbul ignore next */ []);
@@ -3833,6 +4452,11 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
3833
4452
  this.lastAmount = signal(null, ...ngDevMode ? [{ debugName: "lastAmount" }] : /* istanbul ignore next */ []);
3834
4453
  this.intent = null;
3835
4454
  this.estimateRun = 0;
4455
+ this.previewFunding = signal(null, ...ngDevMode ? [{ debugName: "previewFunding" }] : /* istanbul ignore next */ []);
4456
+ this.previewTokenId = null;
4457
+ this.previewRun = 0;
4458
+ this.previewPending = signal(false, ...ngDevMode ? [{ debugName: "previewPending" }] : /* istanbul ignore next */ []);
4459
+ this.previewTimer = null;
3836
4460
  this.estimateStale = false;
3837
4461
  this.amountValue = computed(() => this.ctx().amount, ...ngDevMode ? [{ debugName: "amountValue" }] : /* istanbul ignore next */ []);
3838
4462
  this.methodValue = computed(() => this.ctx().method, ...ngDevMode ? [{ debugName: "methodValue" }] : /* istanbul ignore next */ []);
@@ -3878,19 +4502,36 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
3878
4502
  subtitle: this.labels.t("stripePaymentMethod.amountPlusFees")
3879
4503
  };
3880
4504
  }, ...ngDevMode ? [{ debugName: "totalCard" }] : /* istanbul ignore next */ []);
3881
- this.createIntentFn = async () => {
4505
+ this.createIntentFn = async (context) => {
3882
4506
  const create = this.config().createIntent();
3883
4507
  const ctx = this.ctx();
3884
4508
  if (!create || ctx.amount == null) throw new Error(this.labels.t("stripePayment.msg.cardsUnavailable"));
3885
4509
  this.cancelIntent(true);
4510
+ const attempt = this.payment()?.attempt;
4511
+ const amount = attempt?.pinnedAmount() ?? ctx.amount;
4512
+ const method = attempt?.pinnedMethod() ?? ctx.method;
4513
+ if (context?.attemptKey) this.attempts.set(context.attemptKey, {
4514
+ amount,
4515
+ method
4516
+ });
3886
4517
  const info = await callHost(() => create({
3887
- amount: ctx.amount,
3888
- paymentMethod: ctx.method,
4518
+ amount,
4519
+ paymentMethod: method,
3889
4520
  paymentMethodType: this.methodType(),
3890
4521
  receivedDate: ctx.receivedDate,
3891
4522
  notes: ctx.note || null,
3892
- ...ctx.allocation
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 } : {}
3893
4530
  }));
4531
+ if (wasQueuedOffline(info)) {
4532
+ warnQueuedPayment();
4533
+ throw new Error(this.labels.t("paymentAttempt.queuedOffline"));
4534
+ }
3894
4535
  if (!info?.clientSecret) throw new Error(this.labels.t("stripePayment.msg.initFailed"));
3895
4536
  this.intent = info;
3896
4537
  this.intentFees.set({
@@ -3914,11 +4555,13 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
3914
4555
  const estimating = this.estimating();
3915
4556
  const done = this.done();
3916
4557
  const estimateFailed = !!this.estimateError();
4558
+ const previewPending = this.previewPending();
4559
+ const protectedOff = !!this.payment()?.duplicateProtection() && (this.payment().attempt.unknown() || this.payment().attempt.paidLocked() || !this.payment().readiness.ready());
3917
4560
  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
4561
  untracked(() => ctx.setPrimary({
3919
4562
  label,
3920
4563
  loading: processing && !notice,
3921
- disabled: notice ? done : !complete || processing || estimating || estimateFailed || ctx.amount == null || done,
4564
+ disabled: notice ? done : !complete || processing || estimating || previewPending || estimateFailed || ctx.amount == null || done || protectedOff,
3922
4565
  onClick: () => notice ? this.finish() : void this.pay()
3923
4566
  }));
3924
4567
  });
@@ -3926,6 +4569,7 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
3926
4569
  const estimate = this.config().estimateFees();
3927
4570
  const amount = this.amountValue();
3928
4571
  const method = this.methodValue();
4572
+ const funding = this.previewFunding();
3929
4573
  this.estimateTick();
3930
4574
  const run = ++this.estimateRun;
3931
4575
  untracked(() => {
@@ -3951,7 +4595,11 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
3951
4595
  fees = await callHost(() => estimate({
3952
4596
  amount,
3953
4597
  paymentMethod: method,
3954
- paymentMethodType: stripeMethodType(method)
4598
+ paymentMethodType: stripeMethodType(method),
4599
+ ...this.config().fundingPreview() ? {
4600
+ funding,
4601
+ confirmationTokenId: funding === null ? null : this.previewTokenId
4602
+ } : {}
3955
4603
  })) ?? null;
3956
4604
  } catch {
3957
4605
  fees = null;
@@ -3992,6 +4640,7 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
3992
4640
  untracked(() => {
3993
4641
  this.complete.set(false);
3994
4642
  this.error.set("");
4643
+ this.cancelPreview();
3995
4644
  });
3996
4645
  });
3997
4646
  effect(() => {
@@ -4000,8 +4649,77 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
4000
4649
  });
4001
4650
  inject(DestroyRef).onDestroy(() => {
4002
4651
  this.estimateRun++;
4652
+ this.cancelPreview();
4003
4653
  this.cancelIntent();
4004
4654
  });
4655
+ const controls = {
4656
+ markUnknown: () => this.payment()?.markUnknown(),
4657
+ markSucceeded: () => this.payment()?.markSucceeded(),
4658
+ markFailed: () => this.payment()?.markFailed(),
4659
+ resetPaid: () => {
4660
+ this.payment()?.resetPaid();
4661
+ this.done.set(false);
4662
+ this.confirmation.set(null);
4663
+ this.error.set("");
4664
+ this.ctx().setExclusive(false);
4665
+ },
4666
+ markNotCharged: () => {
4667
+ this.payment()?.markNotCharged();
4668
+ this.processing.set(false);
4669
+ this.ctx().setBusy(false);
4670
+ }
4671
+ };
4672
+ effect(() => {
4673
+ const config = this.config();
4674
+ untracked(() => config.attachControls(controls));
4675
+ });
4676
+ inject(DestroyRef).onDestroy(() => this.config().detachControls(controls));
4677
+ }
4678
+ onElementChange(change) {
4679
+ this.complete.set(change.complete);
4680
+ if (!this.config().fundingPreview() || !this.config().estimateFees() || this.methodType() !== "card") return;
4681
+ this.stopPreviewTimer();
4682
+ const run = ++this.previewRun;
4683
+ if (!change.complete) {
4684
+ this.previewTokenId = null;
4685
+ this.previewFunding.set(null);
4686
+ this.previewPending.set(false);
4687
+ return;
4688
+ }
4689
+ this.previewPending.set(true);
4690
+ this.previewTimer = setTimeout(() => void this.runPreview(run), 400);
4691
+ }
4692
+ async runPreview(run) {
4693
+ this.previewTimer = null;
4694
+ const payment = this.payment();
4695
+ if (!payment || this.processing() || this.done() || run !== this.previewRun) {
4696
+ if (run === this.previewRun) this.previewPending.set(false);
4697
+ return;
4698
+ }
4699
+ const made = await payment.createConfirmationToken();
4700
+ if (run !== this.previewRun) return;
4701
+ if (!made || !("id" in made) || made.paymentMethodType !== "card") {
4702
+ this.previewTokenId = null;
4703
+ this.previewFunding.set(null);
4704
+ this.previewPending.set(false);
4705
+ return;
4706
+ }
4707
+ this.previewTokenId = made.id;
4708
+ this.previewFunding.set(made.funding);
4709
+ this.previewPending.set(false);
4710
+ }
4711
+ stopPreviewTimer() {
4712
+ if (this.previewTimer) {
4713
+ clearTimeout(this.previewTimer);
4714
+ this.previewTimer = null;
4715
+ }
4716
+ }
4717
+ cancelPreview() {
4718
+ this.stopPreviewTimer();
4719
+ this.previewRun++;
4720
+ this.previewTokenId = null;
4721
+ this.previewFunding.set(null);
4722
+ this.previewPending.set(false);
4005
4723
  }
4006
4724
  retryEstimate() {
4007
4725
  this.estimateTick.update((n) => n + 1);
@@ -4015,11 +4733,81 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
4015
4733
  this.processing.set(false);
4016
4734
  this.ctx().report("failed", { message: failure.message });
4017
4735
  }
4736
+ onAttemptOutcome(outcome) {
4737
+ const ctx = this.ctx();
4738
+ const duplicate = outcome.kind === "unknown" && outcome.reason === "duplicate_suspected";
4739
+ if (outcome.kind === "unknown" && !duplicate) this.attemptUnknown = true;
4740
+ else if (outcome.kind === "succeeded" || outcome.kind === "failed") this.attemptUnknown = false;
4741
+ if (duplicate) {
4742
+ const message = this.labels.t("paymentAttempt.duplicate");
4743
+ this.error.set(message);
4744
+ ctx.report("duplicate_suspected", {
4745
+ message,
4746
+ attemptKey: outcome.attemptKey
4747
+ });
4748
+ ctx.announce(message);
4749
+ } else if (outcome.kind === "unknown") {
4750
+ this.payAmount = this.payment()?.attempt.pinnedAmount() ?? this.payAmount;
4751
+ 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");
4753
+ ctx.report("unknown", { message });
4754
+ 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", {
4757
+ message: this.labels.t("paymentAttempt.paid"),
4758
+ attemptKey: outcome.attemptKey,
4759
+ ...outcome.method !== void 0 ? { paid: {
4760
+ amount: outcome.amount ?? null,
4761
+ method: outcome.method
4762
+ } } : {}
4763
+ });
4764
+ 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);
4765
+ else if (outcome.kind === "failed" && (outcome.reason === "status_check" || outcome.reason === "host")) {
4766
+ const message = this.labels.t("paymentAttempt.failedAfterCheck");
4767
+ this.error.set(message);
4768
+ ctx.report("failed", { message });
4769
+ this.cancelIntent(true);
4770
+ ctx.setBusy(false);
4771
+ }
4772
+ }
4773
+ isOlderAttempt(key) {
4774
+ const attempt = this.payment()?.attempt;
4775
+ return !!attempt && attempt.inFlight() && attempt.key() !== key;
4776
+ }
4777
+ async completeAfterCheck(ctx, older = false, outcome) {
4778
+ if (this.done()) return;
4779
+ this.done.set(true);
4780
+ const info = older ? null : this.intent;
4781
+ if (!older) this.intent = null;
4782
+ let finalizeFailed = false;
4783
+ const finalize = this.config().finalize();
4784
+ if (finalize && info) try {
4785
+ await callHost(() => finalize(info));
4786
+ } catch {
4787
+ finalizeFailed = true;
4788
+ }
4789
+ const known = outcome ? this.attempts.get(outcome.attemptKey) : void 0;
4790
+ const result = {
4791
+ type: "stripe",
4792
+ paymentMethod: known?.method ?? this.payMethod ?? ctx.method,
4793
+ amount: known?.amount ?? outcome?.amount ?? this.payAmount ?? ctx.amount ?? this.lastAmount() ?? 0
4794
+ };
4795
+ this.doneAmount = result.amount;
4796
+ this.doneMethod = result.paymentMethod;
4797
+ ctx.report(finalizeFailed ? "finalize-failed" : "paid", { result });
4798
+ ctx.announce(this.labels.t("paymentAttempt.succeededAfterCheck"));
4799
+ ctx.setBusy(false);
4800
+ ctx.complete(result);
4801
+ }
4018
4802
  async pay() {
4019
4803
  const ctx = this.ctx();
4020
4804
  const payment = this.payment();
4021
4805
  if (this.processing() || this.estimating() || this.done() || !payment) return;
4022
4806
  if (!ctx.validate() || ctx.amount == null) return;
4807
+ this.payAmount = ctx.amount;
4808
+ this.payMethod = ctx.method;
4809
+ const attemptAmount = ctx.amount;
4810
+ const attemptMethod = ctx.method;
4023
4811
  this.error.set("");
4024
4812
  this.processing.set(true);
4025
4813
  ctx.setBusy(true);
@@ -4027,14 +4815,14 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
4027
4815
  let finished = false;
4028
4816
  try {
4029
4817
  const event = await payment.confirm();
4030
- if (event) finished = await this.afterConfirm(event, ctx);
4818
+ if (event) finished = await this.afterConfirm(event, ctx, attemptAmount, attemptMethod);
4031
4819
  } finally {
4032
4820
  this.processing.set(false);
4033
- if (!finished) ctx.setBusy(false);
4821
+ if (!finished && !payment.attempt.unknown()) ctx.setBusy(false);
4034
4822
  }
4035
4823
  }
4036
- async afterConfirm(event, ctx) {
4037
- const amount = ctx.amount;
4824
+ async afterConfirm(event, ctx, amount, method) {
4825
+ if (this.done()) return true;
4038
4826
  const money = formatCurrency(amount, { currency: ctx.currency });
4039
4827
  if (event.outcome !== "succeeded" && event.outcome !== "processing" && event.outcome !== "requires_verification") {
4040
4828
  this.error.set(this.texts.notCompleted);
@@ -4051,9 +4839,11 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
4051
4839
  }
4052
4840
  const result = {
4053
4841
  type: "stripe",
4054
- paymentMethod: ctx.method,
4842
+ paymentMethod: method,
4055
4843
  amount
4056
4844
  };
4845
+ this.doneAmount = amount;
4846
+ this.doneMethod = method;
4057
4847
  if (event.outcome === "succeeded") {
4058
4848
  ctx.report(finalizeFailed ? "finalize-failed" : "paid", { result });
4059
4849
  this.done.set(true);
@@ -4080,13 +4870,14 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
4080
4870
  this.done.set(true);
4081
4871
  ctx.complete({
4082
4872
  type: "stripe",
4083
- paymentMethod: ctx.method,
4084
- amount: ctx.amount ?? this.lastAmount() ?? 0
4873
+ paymentMethod: this.doneMethod ?? ctx.method,
4874
+ amount: this.doneAmount ?? ctx.amount ?? this.lastAmount() ?? 0
4085
4875
  });
4086
4876
  }
4087
4877
  cancelIntent(force = false) {
4088
4878
  const info = this.intent;
4089
4879
  if (!info || this.processing() && !force) return;
4880
+ if (this.attemptUnknown) return;
4090
4881
  this.intent = null;
4091
4882
  const cancel = this.config().cancel();
4092
4883
  if (cancel) callHost(() => cancel(info)).catch(() => {});
@@ -4152,9 +4943,12 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
4152
4943
  }
4153
4944
  @if (lastAmount() != null) {
4154
4945
  <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"
4946
+ [createIntent]="createIntentFn" [paymentMethodTypes]="[methodType()]" [showSubmit]="false" [showErrors]="false" [autoHandleCardAction]="true" [collectConfirmationToken]="config().fundingPreview()"
4947
+ [duplicateProtection]="config().duplicateProtection()" [attemptAmount]="ctx().amount" [attemptMethod]="ctx().method" [payableRef]="config().payableRef()" [attemptKey]="config().attemptKey()" [checkStatus]="config().checkStatus()" [paid]="config().paid()" [hostPending]="config().hostPending()"
4948
+ [statusPollMs]="config().statusPollMs()" [statusPollMaxMs]="config().statusPollMaxMs()" [statusCheckTimeoutMs]="config().statusCheckTimeoutMs()" [statusFailGraceMs]="config().statusFailGraceMs()" [authTimeoutMs]="config().authTimeoutMs()" [allowStartOver]="config().allowStartOver()" [offlineOverride]="config().offlineOverride()" [confirmTimeoutMs]="config().confirmTimeoutMs()"
4949
+ [readinessCheck]="config().readinessCheck()" [readinessTimeoutMs]="config().readinessTimeoutMs()" [readinessEveryMs]="config().readinessEveryMs()" (outcome)="onAttemptOutcome($event)"
4156
4950
  [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)" />
4951
+ (ready)="onReady()" (elementChange)="onElementChange($event)" (failed)="onFailed($event)" (loadError)="onFailed($event)" />
4158
4952
  @if (totalCard(); as card) {
4159
4953
  <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
4954
  }
@@ -4171,7 +4965,7 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
4171
4965
  </div>
4172
4966
  `,
4173
4967
  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"],
4968
+ 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
4969
  dependencies: [
4176
4970
  {
4177
4971
  kind: "component",
@@ -4281,6 +5075,26 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
4281
5075
  "redirect",
4282
5076
  "submitBeforeConfirm",
4283
5077
  "autoHandleCardAction",
5078
+ "collectConfirmationToken",
5079
+ "duplicateProtection",
5080
+ "attemptAmount",
5081
+ "attemptMethod",
5082
+ "payableRef",
5083
+ "attemptKey",
5084
+ "checkStatus",
5085
+ "paid",
5086
+ "hostPending",
5087
+ "statusPollMs",
5088
+ "statusPollMaxMs",
5089
+ "statusCheckTimeoutMs",
5090
+ "statusFailGraceMs",
5091
+ "allowStartOver",
5092
+ "offlineOverride",
5093
+ "authTimeoutMs",
5094
+ "confirmTimeoutMs",
5095
+ "readinessCheck",
5096
+ "readinessTimeoutMs",
5097
+ "readinessEveryMs",
4284
5098
  "submitLabel",
4285
5099
  "showSubmit",
4286
5100
  "disabled",
@@ -4307,9 +5121,14 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
4307
5121
  "ready",
4308
5122
  "paymentMethodTypeChange",
4309
5123
  "elementChange",
5124
+ "confirmationToken",
4310
5125
  "confirmed",
4311
5126
  "failed",
4312
- "loadError"
5127
+ "loadError",
5128
+ "inFlightChange",
5129
+ "outcome",
5130
+ "attemptKeyChange",
5131
+ "readinessChange"
4313
5132
  ]
4314
5133
  }
4315
5134
  ],
@@ -4357,9 +5176,12 @@ i0.ɵɵngDeclareClassMetadata({
4357
5176
  }
4358
5177
  @if (lastAmount() != null) {
4359
5178
  <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"
5179
+ [createIntent]="createIntentFn" [paymentMethodTypes]="[methodType()]" [showSubmit]="false" [showErrors]="false" [autoHandleCardAction]="true" [collectConfirmationToken]="config().fundingPreview()"
5180
+ [duplicateProtection]="config().duplicateProtection()" [attemptAmount]="ctx().amount" [attemptMethod]="ctx().method" [payableRef]="config().payableRef()" [attemptKey]="config().attemptKey()" [checkStatus]="config().checkStatus()" [paid]="config().paid()" [hostPending]="config().hostPending()"
5181
+ [statusPollMs]="config().statusPollMs()" [statusPollMaxMs]="config().statusPollMaxMs()" [statusCheckTimeoutMs]="config().statusCheckTimeoutMs()" [statusFailGraceMs]="config().statusFailGraceMs()" [authTimeoutMs]="config().authTimeoutMs()" [allowStartOver]="config().allowStartOver()" [offlineOverride]="config().offlineOverride()" [confirmTimeoutMs]="config().confirmTimeoutMs()"
5182
+ [readinessCheck]="config().readinessCheck()" [readinessTimeoutMs]="config().readinessTimeoutMs()" [readinessEveryMs]="config().readinessEveryMs()" (outcome)="onAttemptOutcome($event)"
4361
5183
  [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)" />
5184
+ (ready)="onReady()" (elementChange)="onElementChange($event)" (failed)="onFailed($event)" (loadError)="onFailed($event)" />
4363
5185
  @if (totalCard(); as card) {
4364
5186
  <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
5187
  }
@@ -4375,7 +5197,7 @@ i0.ɵɵngDeclareClassMetadata({
4375
5197
  }
4376
5198
  </div>
4377
5199
  `,
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"]
5200
+ 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
5201
  }]
4380
5202
  }],
4381
5203
  ctorParameters: () => [],
@@ -4424,15 +5246,55 @@ var StripePaymentMethodComponent = class StripePaymentMethodComponent extends Pa
4424
5246
  })), ...ngDevMode ? [{ debugName: "methodList" }] : /* istanbul ignore next */ []);
4425
5247
  this.estimateTimeoutMs = input(1e4, ...ngDevMode ? [{ debugName: "estimateTimeoutMs" }] : /* istanbul ignore next */ []);
4426
5248
  this.feesRequired = input(false, ...ngDevMode ? [{ debugName: "feesRequired" }] : /* istanbul ignore next */ []);
5249
+ this.fundingPreview = input(false, ...ngDevMode ? [{ debugName: "fundingPreview" }] : /* istanbul ignore next */ []);
5250
+ this.duplicateProtection = input(false, ...ngDevMode ? [{ debugName: "duplicateProtection" }] : /* istanbul ignore next */ []);
5251
+ this.payableRef = input(null, ...ngDevMode ? [{ debugName: "payableRef" }] : /* istanbul ignore next */ []);
5252
+ this.attemptKey = input(null, ...ngDevMode ? [{ debugName: "attemptKey" }] : /* istanbul ignore next */ []);
5253
+ this.checkStatus = input(null, ...ngDevMode ? [{ debugName: "checkStatus" }] : /* istanbul ignore next */ []);
5254
+ this.paid = input(false, ...ngDevMode ? [{ debugName: "paid" }] : /* istanbul ignore next */ []);
5255
+ this.hostPending = input(false, ...ngDevMode ? [{ debugName: "hostPending" }] : /* istanbul ignore next */ []);
5256
+ this.statusPollMs = input(PAYMENT_STATUS_POLL_MS, ...ngDevMode ? [{ debugName: "statusPollMs" }] : /* istanbul ignore next */ []);
5257
+ this.statusPollMaxMs = input(PAYMENT_STATUS_POLL_MAX_MS, ...ngDevMode ? [{ debugName: "statusPollMaxMs" }] : /* istanbul ignore next */ []);
5258
+ this.statusCheckTimeoutMs = input(PAYMENT_STATUS_CHECK_TIMEOUT_MS, ...ngDevMode ? [{ debugName: "statusCheckTimeoutMs" }] : /* istanbul ignore next */ []);
5259
+ this.statusFailGraceMs = input(PAYMENT_STATUS_FAIL_GRACE_MS, ...ngDevMode ? [{ debugName: "statusFailGraceMs" }] : /* istanbul ignore next */ []);
5260
+ this.allowStartOver = input(false, ...ngDevMode ? [{ debugName: "allowStartOver" }] : /* istanbul ignore next */ []);
5261
+ this.offlineOverride = input(false, ...ngDevMode ? [{ debugName: "offlineOverride" }] : /* istanbul ignore next */ []);
5262
+ this.authTimeoutMs = input(PAYMENT_AUTH_TIMEOUT_MS, ...ngDevMode ? [{ debugName: "authTimeoutMs" }] : /* istanbul ignore next */ []);
5263
+ this.confirmTimeoutMs = input(PAYMENT_REQUEST_TIMEOUT_MS, ...ngDevMode ? [{ debugName: "confirmTimeoutMs" }] : /* istanbul ignore next */ []);
5264
+ this.readinessCheck = input(null, ...ngDevMode ? [{ debugName: "readinessCheck" }] : /* istanbul ignore next */ []);
5265
+ this.readinessTimeoutMs = input(PAYMENT_READINESS_TIMEOUT_MS, ...ngDevMode ? [{ debugName: "readinessTimeoutMs" }] : /* istanbul ignore next */ []);
5266
+ this.readinessEveryMs = input(PAYMENT_READINESS_EVERY_MS, ...ngDevMode ? [{ debugName: "readinessEveryMs" }] : /* istanbul ignore next */ []);
4427
5267
  this.receiptNoteInput = input(null, {
4428
5268
  ...ngDevMode ? { debugName: "receiptNoteInput" } : /* istanbul ignore next */ {},
4429
5269
  alias: "receiptNote"
4430
5270
  });
4431
5271
  this.receiptNote = computed(() => this.receiptNoteInput() ?? STRIPE_METHOD_TEXTS.receiptNote, ...ngDevMode ? [{ debugName: "receiptNote" }] : /* istanbul ignore next */ []);
4432
5272
  this.body = viewChild("body", ...ngDevMode ? [{ debugName: "body" }] : /* istanbul ignore next */ []);
5273
+ this.controls = signal(null, ...ngDevMode ? [{ debugName: "controls" }] : /* istanbul ignore next */ []);
4433
5274
  this.methods = this.methodList;
4434
5275
  this.template = this.body;
4435
5276
  }
5277
+ attachControls(controls) {
5278
+ this.controls.set(controls);
5279
+ }
5280
+ detachControls(controls) {
5281
+ if (this.controls() === controls) this.controls.set(null);
5282
+ }
5283
+ markUnknown() {
5284
+ this.controls()?.markUnknown();
5285
+ }
5286
+ markSucceeded() {
5287
+ this.controls()?.markSucceeded();
5288
+ }
5289
+ markFailed() {
5290
+ this.controls()?.markFailed();
5291
+ }
5292
+ markNotCharged() {
5293
+ this.controls()?.markNotCharged();
5294
+ }
5295
+ resetPaid() {
5296
+ this.controls()?.resetPaid();
5297
+ }
4436
5298
  static {
4437
5299
  this.ɵfac = i0.ɵɵngDeclareFactory({
4438
5300
  minVersion: "12.0.0",
@@ -4528,6 +5390,132 @@ var StripePaymentMethodComponent = class StripePaymentMethodComponent extends Pa
4528
5390
  isRequired: false,
4529
5391
  transformFunction: null
4530
5392
  },
5393
+ fundingPreview: {
5394
+ classPropertyName: "fundingPreview",
5395
+ publicName: "fundingPreview",
5396
+ isSignal: true,
5397
+ isRequired: false,
5398
+ transformFunction: null
5399
+ },
5400
+ duplicateProtection: {
5401
+ classPropertyName: "duplicateProtection",
5402
+ publicName: "duplicateProtection",
5403
+ isSignal: true,
5404
+ isRequired: false,
5405
+ transformFunction: null
5406
+ },
5407
+ payableRef: {
5408
+ classPropertyName: "payableRef",
5409
+ publicName: "payableRef",
5410
+ isSignal: true,
5411
+ isRequired: false,
5412
+ transformFunction: null
5413
+ },
5414
+ attemptKey: {
5415
+ classPropertyName: "attemptKey",
5416
+ publicName: "attemptKey",
5417
+ isSignal: true,
5418
+ isRequired: false,
5419
+ transformFunction: null
5420
+ },
5421
+ checkStatus: {
5422
+ classPropertyName: "checkStatus",
5423
+ publicName: "checkStatus",
5424
+ isSignal: true,
5425
+ isRequired: false,
5426
+ transformFunction: null
5427
+ },
5428
+ paid: {
5429
+ classPropertyName: "paid",
5430
+ publicName: "paid",
5431
+ isSignal: true,
5432
+ isRequired: false,
5433
+ transformFunction: null
5434
+ },
5435
+ hostPending: {
5436
+ classPropertyName: "hostPending",
5437
+ publicName: "hostPending",
5438
+ isSignal: true,
5439
+ isRequired: false,
5440
+ transformFunction: null
5441
+ },
5442
+ statusPollMs: {
5443
+ classPropertyName: "statusPollMs",
5444
+ publicName: "statusPollMs",
5445
+ isSignal: true,
5446
+ isRequired: false,
5447
+ transformFunction: null
5448
+ },
5449
+ statusPollMaxMs: {
5450
+ classPropertyName: "statusPollMaxMs",
5451
+ publicName: "statusPollMaxMs",
5452
+ isSignal: true,
5453
+ isRequired: false,
5454
+ transformFunction: null
5455
+ },
5456
+ statusCheckTimeoutMs: {
5457
+ classPropertyName: "statusCheckTimeoutMs",
5458
+ publicName: "statusCheckTimeoutMs",
5459
+ isSignal: true,
5460
+ isRequired: false,
5461
+ transformFunction: null
5462
+ },
5463
+ statusFailGraceMs: {
5464
+ classPropertyName: "statusFailGraceMs",
5465
+ publicName: "statusFailGraceMs",
5466
+ isSignal: true,
5467
+ isRequired: false,
5468
+ transformFunction: null
5469
+ },
5470
+ allowStartOver: {
5471
+ classPropertyName: "allowStartOver",
5472
+ publicName: "allowStartOver",
5473
+ isSignal: true,
5474
+ isRequired: false,
5475
+ transformFunction: null
5476
+ },
5477
+ offlineOverride: {
5478
+ classPropertyName: "offlineOverride",
5479
+ publicName: "offlineOverride",
5480
+ isSignal: true,
5481
+ isRequired: false,
5482
+ transformFunction: null
5483
+ },
5484
+ authTimeoutMs: {
5485
+ classPropertyName: "authTimeoutMs",
5486
+ publicName: "authTimeoutMs",
5487
+ isSignal: true,
5488
+ isRequired: false,
5489
+ transformFunction: null
5490
+ },
5491
+ confirmTimeoutMs: {
5492
+ classPropertyName: "confirmTimeoutMs",
5493
+ publicName: "confirmTimeoutMs",
5494
+ isSignal: true,
5495
+ isRequired: false,
5496
+ transformFunction: null
5497
+ },
5498
+ readinessCheck: {
5499
+ classPropertyName: "readinessCheck",
5500
+ publicName: "readinessCheck",
5501
+ isSignal: true,
5502
+ isRequired: false,
5503
+ transformFunction: null
5504
+ },
5505
+ readinessTimeoutMs: {
5506
+ classPropertyName: "readinessTimeoutMs",
5507
+ publicName: "readinessTimeoutMs",
5508
+ isSignal: true,
5509
+ isRequired: false,
5510
+ transformFunction: null
5511
+ },
5512
+ readinessEveryMs: {
5513
+ classPropertyName: "readinessEveryMs",
5514
+ publicName: "readinessEveryMs",
5515
+ isSignal: true,
5516
+ isRequired: false,
5517
+ transformFunction: null
5518
+ },
4531
5519
  receiptNoteInput: {
4532
5520
  classPropertyName: "receiptNoteInput",
4533
5521
  publicName: "receiptNote",
@@ -4671,6 +5659,150 @@ i0.ɵɵngDeclareClassMetadata({
4671
5659
  required: false
4672
5660
  }]
4673
5661
  }],
5662
+ fundingPreview: [{
5663
+ type: i0.Input,
5664
+ args: [{
5665
+ isSignal: true,
5666
+ alias: "fundingPreview",
5667
+ required: false
5668
+ }]
5669
+ }],
5670
+ duplicateProtection: [{
5671
+ type: i0.Input,
5672
+ args: [{
5673
+ isSignal: true,
5674
+ alias: "duplicateProtection",
5675
+ required: false
5676
+ }]
5677
+ }],
5678
+ payableRef: [{
5679
+ type: i0.Input,
5680
+ args: [{
5681
+ isSignal: true,
5682
+ alias: "payableRef",
5683
+ required: false
5684
+ }]
5685
+ }],
5686
+ attemptKey: [{
5687
+ type: i0.Input,
5688
+ args: [{
5689
+ isSignal: true,
5690
+ alias: "attemptKey",
5691
+ required: false
5692
+ }]
5693
+ }],
5694
+ checkStatus: [{
5695
+ type: i0.Input,
5696
+ args: [{
5697
+ isSignal: true,
5698
+ alias: "checkStatus",
5699
+ required: false
5700
+ }]
5701
+ }],
5702
+ paid: [{
5703
+ type: i0.Input,
5704
+ args: [{
5705
+ isSignal: true,
5706
+ alias: "paid",
5707
+ required: false
5708
+ }]
5709
+ }],
5710
+ hostPending: [{
5711
+ type: i0.Input,
5712
+ args: [{
5713
+ isSignal: true,
5714
+ alias: "hostPending",
5715
+ required: false
5716
+ }]
5717
+ }],
5718
+ statusPollMs: [{
5719
+ type: i0.Input,
5720
+ args: [{
5721
+ isSignal: true,
5722
+ alias: "statusPollMs",
5723
+ required: false
5724
+ }]
5725
+ }],
5726
+ statusPollMaxMs: [{
5727
+ type: i0.Input,
5728
+ args: [{
5729
+ isSignal: true,
5730
+ alias: "statusPollMaxMs",
5731
+ required: false
5732
+ }]
5733
+ }],
5734
+ statusCheckTimeoutMs: [{
5735
+ type: i0.Input,
5736
+ args: [{
5737
+ isSignal: true,
5738
+ alias: "statusCheckTimeoutMs",
5739
+ required: false
5740
+ }]
5741
+ }],
5742
+ statusFailGraceMs: [{
5743
+ type: i0.Input,
5744
+ args: [{
5745
+ isSignal: true,
5746
+ alias: "statusFailGraceMs",
5747
+ required: false
5748
+ }]
5749
+ }],
5750
+ allowStartOver: [{
5751
+ type: i0.Input,
5752
+ args: [{
5753
+ isSignal: true,
5754
+ alias: "allowStartOver",
5755
+ required: false
5756
+ }]
5757
+ }],
5758
+ offlineOverride: [{
5759
+ type: i0.Input,
5760
+ args: [{
5761
+ isSignal: true,
5762
+ alias: "offlineOverride",
5763
+ required: false
5764
+ }]
5765
+ }],
5766
+ authTimeoutMs: [{
5767
+ type: i0.Input,
5768
+ args: [{
5769
+ isSignal: true,
5770
+ alias: "authTimeoutMs",
5771
+ required: false
5772
+ }]
5773
+ }],
5774
+ confirmTimeoutMs: [{
5775
+ type: i0.Input,
5776
+ args: [{
5777
+ isSignal: true,
5778
+ alias: "confirmTimeoutMs",
5779
+ required: false
5780
+ }]
5781
+ }],
5782
+ readinessCheck: [{
5783
+ type: i0.Input,
5784
+ args: [{
5785
+ isSignal: true,
5786
+ alias: "readinessCheck",
5787
+ required: false
5788
+ }]
5789
+ }],
5790
+ readinessTimeoutMs: [{
5791
+ type: i0.Input,
5792
+ args: [{
5793
+ isSignal: true,
5794
+ alias: "readinessTimeoutMs",
5795
+ required: false
5796
+ }]
5797
+ }],
5798
+ readinessEveryMs: [{
5799
+ type: i0.Input,
5800
+ args: [{
5801
+ isSignal: true,
5802
+ alias: "readinessEveryMs",
5803
+ required: false
5804
+ }]
5805
+ }],
4674
5806
  receiptNoteInput: [{
4675
5807
  type: i0.Input,
4676
5808
  args: [{