@forgeroute/ui 0.5.6 → 0.5.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import * as i0 from "@angular/core";
2
2
  import { ChangeDetectionStrategy, Component, DestroyRef, ElementRef, Injectable, InjectionToken, Injector, PLATFORM_ID, ViewEncapsulation, afterNextRender, computed, effect, forwardRef, inject, input, model, output, signal, untracked, viewChild } from "@angular/core";
3
- import { AlertComponent, BadgeComponent, ButtonComponent, DetailCardComponent, FormRowComponent, FormSectionComponent, HintComponent, KpiCardComponent, ModalComponent, PAYMENT_AUTH_TIMEOUT_MS, PAYMENT_METHOD_PLUGIN, PAYMENT_READINESS_EVERY_MS, PAYMENT_READINESS_TIMEOUT_MS, PAYMENT_REQUEST_TIMEOUT_MS, PAYMENT_STATUS_CHECK_TIMEOUT_MS, PAYMENT_STATUS_FAIL_GRACE_MS, PAYMENT_STATUS_POLL_MAX_MS, PAYMENT_STATUS_POLL_MS, PaymentAttemptStatusComponent, PaymentMethodPlugin, SkeletonComponent, StackComponent, TextComponent, TextInputComponent, UiLabelsService, callHost, createPaymentProtection, formatCurrency, isAttemptFailedReplay, isDarkPage, isFinalPaymentRefusal, paymentErrorLabelKey, refusalLabelKey, safeLocale, uiLocale, uiText, warnQueuedPayment, wasQueuedOffline } from "@forgeroute/ui";
3
+ import { AlertComponent, BadgeComponent, ButtonComponent, DetailCardComponent, FormRowComponent, FormSectionComponent, HintComponent, KpiCardComponent, ModalComponent, PAYMENT_AUTH_TIMEOUT_MS, PAYMENT_METHOD_PLUGIN, PAYMENT_READINESS_EVERY_MS, PAYMENT_READINESS_TIMEOUT_MS, PAYMENT_REQUEST_TIMEOUT_MS, PAYMENT_STATUS_CHECK_TIMEOUT_MS, PAYMENT_STATUS_FAIL_GRACE_MS, PAYMENT_STATUS_HARD_MAX_MS, PAYMENT_STATUS_POLL_MAX_MS, PAYMENT_STATUS_POLL_MS, PaymentAttemptStatusComponent, PaymentMethodPlugin, SkeletonComponent, StackComponent, TextComponent, TextInputComponent, UiLabelsService, attemptLabelKey, 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";
@@ -469,10 +469,12 @@ const AMBIGUOUS_STRIPE_TYPES = /* @__PURE__ */ new Set([
469
469
  ]);
470
470
  const AMBIGUOUS_STRIPE_CODES = /* @__PURE__ */ new Set([
471
471
  "payment_intent_unexpected_state",
472
+ "setup_intent_unexpected_state",
472
473
  "idempotency_error",
473
474
  "idempotency_key_in_use",
474
475
  "lock_timeout"
475
476
  ]);
477
+ const MSG_SETUP_INCOMPLETE = "Payment method setup was incomplete. Please try again.";
476
478
  let nextId = 0;
477
479
  const jsonEqual = (a, b) => JSON.stringify(a) === JSON.stringify(b);
478
480
  var StripePaymentComponent = class StripePaymentComponent {
@@ -515,6 +517,8 @@ var StripePaymentComponent = class StripePaymentComponent {
515
517
  this.attemptAmount = input(null, ...ngDevMode ? [{ debugName: "attemptAmount" }] : /* istanbul ignore next */ []);
516
518
  this.attemptMethod = input(null, ...ngDevMode ? [{ debugName: "attemptMethod" }] : /* istanbul ignore next */ []);
517
519
  this.payableRef = input(null, ...ngDevMode ? [{ debugName: "payableRef" }] : /* istanbul ignore next */ []);
520
+ this.protectSetup = input(false, ...ngDevMode ? [{ debugName: "protectSetup" }] : /* istanbul ignore next */ []);
521
+ this.lockAfterSuccess = input(true, ...ngDevMode ? [{ debugName: "lockAfterSuccess" }] : /* istanbul ignore next */ []);
518
522
  this.attemptKey = input(null, ...ngDevMode ? [{ debugName: "attemptKey" }] : /* istanbul ignore next */ []);
519
523
  this.checkStatus = input(null, ...ngDevMode ? [{ debugName: "checkStatus" }] : /* istanbul ignore next */ []);
520
524
  this.paid = input(false, ...ngDevMode ? [{ debugName: "paid" }] : /* istanbul ignore next */ []);
@@ -523,6 +527,7 @@ var StripePaymentComponent = class StripePaymentComponent {
523
527
  this.statusPollMaxMs = input(PAYMENT_STATUS_POLL_MAX_MS, ...ngDevMode ? [{ debugName: "statusPollMaxMs" }] : /* istanbul ignore next */ []);
524
528
  this.statusCheckTimeoutMs = input(PAYMENT_STATUS_CHECK_TIMEOUT_MS, ...ngDevMode ? [{ debugName: "statusCheckTimeoutMs" }] : /* istanbul ignore next */ []);
525
529
  this.statusFailGraceMs = input(PAYMENT_STATUS_FAIL_GRACE_MS, ...ngDevMode ? [{ debugName: "statusFailGraceMs" }] : /* istanbul ignore next */ []);
530
+ this.statusHardMaxMs = input(PAYMENT_STATUS_HARD_MAX_MS, ...ngDevMode ? [{ debugName: "statusHardMaxMs" }] : /* istanbul ignore next */ []);
526
531
  this.allowStartOver = input(false, ...ngDevMode ? [{ debugName: "allowStartOver" }] : /* istanbul ignore next */ []);
527
532
  this.offlineOverride = input(false, ...ngDevMode ? [{ debugName: "offlineOverride" }] : /* istanbul ignore next */ []);
528
533
  this.authTimeoutMs = input(PAYMENT_AUTH_TIMEOUT_MS, ...ngDevMode ? [{ debugName: "authTimeoutMs" }] : /* istanbul ignore next */ []);
@@ -661,7 +666,7 @@ var StripePaymentComponent = class StripePaymentComponent {
661
666
  this.confirmSeq = 0;
662
667
  this.appliedDefaultValues = "";
663
668
  this.appliedDisabled = false;
664
- this.protectionOn = computed(() => this.duplicateProtection() && this.mode() === "payment", ...ngDevMode ? [{ debugName: "protectionOn" }] : /* istanbul ignore next */ []);
669
+ this.protectionOn = computed(() => this.duplicateProtection() && (this.mode() === "payment" || this.protectSetup()), ...ngDevMode ? [{ debugName: "protectionOn" }] : /* istanbul ignore next */ []);
665
670
  this.retryTick = signal(0, ...ngDevMode ? [{ debugName: "retryTick" }] : /* istanbul ignore next */ []);
666
671
  const protection = createPaymentProtection(this, {
667
672
  amount: () => {
@@ -673,7 +678,11 @@ var StripePaymentComponent = class StripePaymentComponent {
673
678
  method: () => this.attemptMethod() ?? this.selectedType() ?? "card",
674
679
  sdk: () => this.loadErrorText() ? "blocked" : this.loading() ? "loading" : "ok",
675
680
  enabled: () => this.protectionOn(),
676
- onOutcome: (o) => this.outcome.emit(o),
681
+ lockAfterSuccess: () => this.mode() === "payment" || this.lockAfterSuccess(),
682
+ onOutcome: (o) => {
683
+ if (this.mode() === "setup" && o.kind === "succeeded" && o.reason === "status_check") this.announcement.set("");
684
+ this.outcome.emit(o);
685
+ },
677
686
  onInFlightChange: (v) => this.inFlightChange.emit(v),
678
687
  onKeyChange: (k) => {
679
688
  if (this.protectionOn()) this.attemptKeyChange.emit(k);
@@ -731,7 +740,7 @@ var StripePaymentComponent = class StripePaymentComponent {
731
740
  attemptKey: this.attempt.key(),
732
741
  reason
733
742
  });
734
- this.fail(failure(reason, this.labels.t(this.readiness.labelKeyFor(reason)), "submit"));
743
+ this.fail(failure(reason, this.labels.t(attemptLabelKey(this.readiness.labelKeyFor(reason), this.mode())), "submit"));
735
744
  return null;
736
745
  }
737
746
  if (this.attempt.paidLocked() || this.attempt.unknown()) {
@@ -763,6 +772,11 @@ var StripePaymentComponent = class StripePaymentComponent {
763
772
  if (live) this.announcement.set(this.labels.t(key));
764
773
  };
765
774
  if (event) {
775
+ if (event.outcome === "requires_action" && event.kind === "setup") return {
776
+ kind: "unknown",
777
+ value: event,
778
+ reason: "setup_action"
779
+ };
766
780
  if (event.outcome === "requires_action") {
767
781
  say("paymentAttempt.authRequired");
768
782
  return {
@@ -776,6 +790,11 @@ var StripePaymentComponent = class StripePaymentComponent {
776
790
  value: event,
777
791
  reason: "microdeposits"
778
792
  };
793
+ if (event.outcome === "processing" && event.kind === "setup") return {
794
+ kind: "unknown",
795
+ value: event,
796
+ reason: "setup_processing"
797
+ };
779
798
  return {
780
799
  kind: "success",
781
800
  value: event
@@ -819,7 +838,7 @@ var StripePaymentComponent = class StripePaymentComponent {
819
838
  kind: "unknown",
820
839
  reason: "error"
821
840
  };
822
- if (f.stage === "result" && f.code !== "requires_payment_method" && f.code !== "no_payment_method" && trace.outcome !== "canceled") return {
841
+ if (f.stage === "result" && f.code !== "requires_payment_method" && trace.outcome !== "canceled") return {
823
842
  kind: "unknown",
824
843
  reason: "unexpected_status"
825
844
  };
@@ -899,7 +918,7 @@ var StripePaymentComponent = class StripePaymentComponent {
899
918
  } : context);
900
919
  if (wasQueuedOffline(created)) {
901
920
  warnQueuedPayment();
902
- this.fail(failure("not_sent", this.labels.t("paymentAttempt.queuedOffline"), "intent"), trace);
921
+ this.fail(failure("not_sent", this.labels.t(attemptLabelKey("paymentAttempt.queuedOffline", this.protectionOn() ? mode : "payment")), "intent"), trace);
903
922
  return null;
904
923
  }
905
924
  secret = typeof created === "string" ? created : created?.clientSecret;
@@ -927,11 +946,11 @@ var StripePaymentComponent = class StripePaymentComponent {
927
946
  }
928
947
  const intent = mode === "setup" ? result.setupIntent : result.paymentIntent;
929
948
  if (!intent) {
930
- this.fail(failure("not_completed", mode === "setup" ? "Payment method setup was incomplete. Please try again." : MSG_NOT_COMPLETED, "result"), trace);
949
+ this.fail(failure("not_completed", mode === "setup" ? MSG_SETUP_INCOMPLETE : MSG_NOT_COMPLETED, "result"), trace);
931
950
  return null;
932
951
  }
933
952
  let event = normalizeIntent(mode, intent);
934
- if (mode === "setup" && !event.paymentMethodId) {
953
+ if (mode === "setup" && !event.paymentMethodId && !(trace && (event.outcome === "requires_payment_method" || event.outcome === "canceled"))) {
935
954
  this.fail(failure("no_payment_method", MSG_NO_PAYMENT_METHOD, "result"), trace);
936
955
  return null;
937
956
  }
@@ -1054,6 +1073,7 @@ var StripePaymentComponent = class StripePaymentComponent {
1054
1073
  } catch (err) {
1055
1074
  const f = failure("load_error", messageOfThrown(err, MSG_LOAD_FAILED), "load", messageOfThrown(err, ""));
1056
1075
  this.fail(f);
1076
+ this.settleReturn(null);
1057
1077
  return {
1058
1078
  event: null,
1059
1079
  failure: f
@@ -1062,14 +1082,44 @@ var StripePaymentComponent = class StripePaymentComponent {
1062
1082
  const result = await retrieveIntent(stripe, kind, clientSecret);
1063
1083
  if (result.failure) {
1064
1084
  this.fail(result.failure);
1085
+ this.settleReturn(null);
1065
1086
  return result;
1066
1087
  }
1067
- if (result.event && !this.finish(result.event, true)) return {
1068
- event: null,
1069
- failure: this.lastFailure
1070
- };
1088
+ if (result.event && !this.finish(result.event, true)) {
1089
+ this.settleReturn(result.event);
1090
+ return {
1091
+ event: null,
1092
+ failure: this.lastFailure
1093
+ };
1094
+ }
1095
+ this.settleReturn(result.event);
1071
1096
  return result;
1072
1097
  }
1098
+ settleReturn(event) {
1099
+ if (!this.protectionOn()) return;
1100
+ if (!event) {
1101
+ this.attempt.markUnknown("error");
1102
+ return;
1103
+ }
1104
+ switch (event.outcome) {
1105
+ case "processing":
1106
+ if (event.kind === "setup") this.attempt.markUnknown("setup_processing");
1107
+ else this.attempt.succeed("return");
1108
+ break;
1109
+ case "succeeded":
1110
+ case "requires_capture":
1111
+ this.attempt.succeed("return");
1112
+ break;
1113
+ case "requires_payment_method":
1114
+ case "canceled":
1115
+ this.attempt.fail("return");
1116
+ break;
1117
+ case "requires_verification":
1118
+ this.attempt.markUnknown("microdeposits");
1119
+ break;
1120
+ default: this.attempt.markUnknown("return_action");
1121
+ }
1122
+ }
1073
1123
  errorOptions(stage) {
1074
1124
  return {
1075
1125
  display: this.errorDisplayByStage()?.[stage] ?? this.errorDisplay(),
@@ -1127,30 +1177,35 @@ var StripePaymentComponent = class StripePaymentComponent {
1127
1177
  ...event.actionHandled ? { actionHandled: true } : {},
1128
1178
  status: event.status
1129
1179
  };
1180
+ const setupProtected = event.kind === "setup" && this.protectionOn();
1130
1181
  if (event.outcome === "requires_payment_method") {
1131
1182
  this.fail({
1132
- ...failure("requires_payment_method", MSG_REQUIRES_PAYMENT_METHOD, fromReturn ? "return" : "result"),
1183
+ ...failure("requires_payment_method", setupProtected ? this.labels.t("paymentSetup.requiresPaymentMethod") : MSG_REQUIRES_PAYMENT_METHOD, fromReturn ? "return" : "result"),
1133
1184
  ...acted
1134
1185
  }, trace);
1135
1186
  return null;
1136
1187
  }
1188
+ if (event.outcome === "unknown" && fromReturn && this.protectionOn()) {
1189
+ this.lastFailure = failure("not_completed", setupProtected ? MSG_SETUP_INCOMPLETE : MSG_NOT_COMPLETED, "return");
1190
+ return null;
1191
+ }
1137
1192
  if (event.outcome === "canceled" || event.outcome === "unknown") {
1138
1193
  this.fail({
1139
- ...failure("not_completed", MSG_NOT_COMPLETED, fromReturn ? "return" : "result"),
1194
+ ...failure("not_completed", setupProtected ? MSG_SETUP_INCOMPLETE : MSG_NOT_COMPLETED, fromReturn ? "return" : "result"),
1140
1195
  ...acted
1141
1196
  }, trace);
1142
1197
  return null;
1143
1198
  }
1144
1199
  if (this.destroyed) return event;
1145
- this.announcement.set(this.announce(event));
1200
+ this.announcement.set(setupProtected && (event.outcome === "requires_action" || event.outcome === "requires_verification") ? "" : this.announce(event, setupProtected));
1146
1201
  this.confirmed.emit(event);
1147
1202
  return event;
1148
1203
  }
1149
- announce(event) {
1204
+ announce(event, setupProtected = false) {
1150
1205
  const m = this.messages();
1151
1206
  switch (event.outcome) {
1152
1207
  case "succeeded": return event.kind === "setup" ? m.methodSaved : m.paymentReceived;
1153
- case "processing": return m.paymentProcessing;
1208
+ case "processing": return setupProtected ? this.labels.t("paymentSetup.processing") : m.paymentProcessing;
1154
1209
  case "requires_capture": return m.paymentAuthorized;
1155
1210
  case "requires_verification": return event.kind === "setup" ? m.verificationNeededSetup : m.verificationNeeded;
1156
1211
  default: return m.actionRequired;
@@ -1579,6 +1634,20 @@ var StripePaymentComponent = class StripePaymentComponent {
1579
1634
  isRequired: false,
1580
1635
  transformFunction: null
1581
1636
  },
1637
+ protectSetup: {
1638
+ classPropertyName: "protectSetup",
1639
+ publicName: "protectSetup",
1640
+ isSignal: true,
1641
+ isRequired: false,
1642
+ transformFunction: null
1643
+ },
1644
+ lockAfterSuccess: {
1645
+ classPropertyName: "lockAfterSuccess",
1646
+ publicName: "lockAfterSuccess",
1647
+ isSignal: true,
1648
+ isRequired: false,
1649
+ transformFunction: null
1650
+ },
1582
1651
  attemptKey: {
1583
1652
  classPropertyName: "attemptKey",
1584
1653
  publicName: "attemptKey",
@@ -1635,6 +1704,13 @@ var StripePaymentComponent = class StripePaymentComponent {
1635
1704
  isRequired: false,
1636
1705
  transformFunction: null
1637
1706
  },
1707
+ statusHardMaxMs: {
1708
+ classPropertyName: "statusHardMaxMs",
1709
+ publicName: "statusHardMaxMs",
1710
+ isSignal: true,
1711
+ isRequired: false,
1712
+ transformFunction: null
1713
+ },
1638
1714
  allowStartOver: {
1639
1715
  classPropertyName: "allowStartOver",
1640
1716
  publicName: "allowStartOver",
@@ -1854,7 +1930,7 @@ var StripePaymentComponent = class StripePaymentComponent {
1854
1930
  <div class="sp-sr" role="status" aria-live="polite" data-testid="stripe-status">{{ statusText() }}</div>
1855
1931
  }
1856
1932
  @if (!mountOnly() && protectionOn()) {
1857
- <ui-payment-attempt-status [attempt]="attempt" [readiness]="readiness" [allowStartOver]="allowStartOver()" (retryLoad)="reload()" />
1933
+ <ui-payment-attempt-status [attempt]="attempt" [readiness]="readiness" [kind]="mode()" [allowStartOver]="allowStartOver()" (retryLoad)="reload()" />
1858
1934
  }
1859
1935
  @if (!mountOnly() && (loading() || pending())) {
1860
1936
  <div class="sp-skeleton" data-testid="stripe-skeleton" aria-hidden="true">
@@ -1942,7 +2018,8 @@ var StripePaymentComponent = class StripePaymentComponent {
1942
2018
  "attempt",
1943
2019
  "showPaid",
1944
2020
  "allowStartOver",
1945
- "readiness"
2021
+ "readiness",
2022
+ "kind"
1946
2023
  ],
1947
2024
  outputs: ["retryLoad"]
1948
2025
  },
@@ -1989,7 +2066,7 @@ i0.ɵɵngDeclareClassMetadata({
1989
2066
  <div class="sp-sr" role="status" aria-live="polite" data-testid="stripe-status">{{ statusText() }}</div>
1990
2067
  }
1991
2068
  @if (!mountOnly() && protectionOn()) {
1992
- <ui-payment-attempt-status [attempt]="attempt" [readiness]="readiness" [allowStartOver]="allowStartOver()" (retryLoad)="reload()" />
2069
+ <ui-payment-attempt-status [attempt]="attempt" [readiness]="readiness" [kind]="mode()" [allowStartOver]="allowStartOver()" (retryLoad)="reload()" />
1993
2070
  }
1994
2071
  @if (!mountOnly() && (loading() || pending())) {
1995
2072
  <div class="sp-skeleton" data-testid="stripe-skeleton" aria-hidden="true">
@@ -2281,6 +2358,22 @@ i0.ɵɵngDeclareClassMetadata({
2281
2358
  required: false
2282
2359
  }]
2283
2360
  }],
2361
+ protectSetup: [{
2362
+ type: i0.Input,
2363
+ args: [{
2364
+ isSignal: true,
2365
+ alias: "protectSetup",
2366
+ required: false
2367
+ }]
2368
+ }],
2369
+ lockAfterSuccess: [{
2370
+ type: i0.Input,
2371
+ args: [{
2372
+ isSignal: true,
2373
+ alias: "lockAfterSuccess",
2374
+ required: false
2375
+ }]
2376
+ }],
2284
2377
  attemptKey: [{
2285
2378
  type: i0.Input,
2286
2379
  args: [{
@@ -2345,6 +2438,14 @@ i0.ɵɵngDeclareClassMetadata({
2345
2438
  required: false
2346
2439
  }]
2347
2440
  }],
2441
+ statusHardMaxMs: [{
2442
+ type: i0.Input,
2443
+ args: [{
2444
+ isSignal: true,
2445
+ alias: "statusHardMaxMs",
2446
+ required: false
2447
+ }]
2448
+ }],
2348
2449
  allowStartOver: [{
2349
2450
  type: i0.Input,
2350
2451
  args: [{
@@ -5124,6 +5225,8 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
5124
5225
  "attemptAmount",
5125
5226
  "attemptMethod",
5126
5227
  "payableRef",
5228
+ "protectSetup",
5229
+ "lockAfterSuccess",
5127
5230
  "attemptKey",
5128
5231
  "checkStatus",
5129
5232
  "paid",
@@ -5132,6 +5235,7 @@ var PaymentStripeBodyComponent = class PaymentStripeBodyComponent {
5132
5235
  "statusPollMaxMs",
5133
5236
  "statusCheckTimeoutMs",
5134
5237
  "statusFailGraceMs",
5238
+ "statusHardMaxMs",
5135
5239
  "allowStartOver",
5136
5240
  "offlineOverride",
5137
5241
  "authTimeoutMs",