@frontegg/redux-store 5.28.1 → 5.30.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.
@@ -67,9 +67,6 @@ const initialBillingInformationState = {
67
67
  loading: false,
68
68
  error: null,
69
69
  fetching: true,
70
- externallyManaged: false,
71
- defaultPlanId: null,
72
- defaultPaymentId: null,
73
70
  cancellation: {
74
71
  loading: false,
75
72
  error: null,
@@ -79,10 +76,7 @@ const initialBillingInformationState = {
79
76
  error: null,
80
77
  },
81
78
  };
82
- const reducers$5 = Object.assign(Object.assign({}, createModuleCaseReducers()), { setBillingInformation: {
83
- prepare: (payload) => ({ payload }),
84
- reducer: (state, action) => (Object.assign(Object.assign({}, state), action.payload)),
85
- }, setCancellationLoading: createKeyCaseLoadingReducer('cancellation'), setCancellationError: createKeyCaseErrorReducer('cancellation'), setRenewalLoading: createKeyCaseLoadingReducer('renewal'), setRenewalError: createKeyCaseErrorReducer('renewal') });
79
+ const reducers$5 = Object.assign(Object.assign({}, createModuleCaseReducers()), { setCancellationLoading: createKeyCaseLoadingReducer('cancellation'), setCancellationError: createKeyCaseErrorReducer('cancellation'), setRenewalLoading: createKeyCaseLoadingReducer('renewal'), setRenewalError: createKeyCaseErrorReducer('renewal') });
86
80
  const { reducer: reducer$6, actions: overviewActions, name: name$5, } = toolkit.createSlice({
87
81
  name: `${constants.subscriptionsStoreName}/billing/information`,
88
82
  initialState: initialBillingInformationState,
@@ -245,15 +239,13 @@ exports.SubscriptionStatus = void 0;
245
239
  SubscriptionStatus["CANCELED"] = "CANCELED";
246
240
  SubscriptionStatus["INCOMPLETE"] = "INCOMPLETE";
247
241
  SubscriptionStatus["EXPIRED"] = "EXPIRED";
242
+ SubscriptionStatus["TRIALING"] = "TRIALING";
248
243
  })(exports.SubscriptionStatus || (exports.SubscriptionStatus = {}));
249
244
  exports.SubscriptionCancellationPolicy = void 0;
250
245
  (function (SubscriptionCancellationPolicy) {
251
246
  SubscriptionCancellationPolicy["AT_PERIOD_END"] = "atPeriodEnd";
252
247
  })(exports.SubscriptionCancellationPolicy || (exports.SubscriptionCancellationPolicy = {}));
253
248
 
254
- function toPrice(amount) {
255
- return +(amount / 100).toFixed(2);
256
- }
257
249
  function toSubscriptionCancellation({ policy }) {
258
250
  return {
259
251
  policy: toSubscriptionCancellationPolicy(),
@@ -272,6 +264,8 @@ function toSubscriptionStatus(status) {
272
264
  return exports.SubscriptionStatus.CANCELED;
273
265
  case restApi.ISubscriptionStatus.EXPIRED:
274
266
  return exports.SubscriptionStatus.EXPIRED;
267
+ case restApi.ISubscriptionStatus.TRIALING:
268
+ return exports.SubscriptionStatus.TRIALING;
275
269
  default:
276
270
  return exports.SubscriptionStatus.EXPIRED;
277
271
  }
@@ -390,12 +384,11 @@ function* loadSummaries(tenantId) {
390
384
  var _a, _b;
391
385
  yield effects.put(actions$6.setLoading(true));
392
386
  try {
393
- const { currentPlanId, subscriptionId, externallyManaged, defaultPlanId, paymentMethodId: defaultPaymentId, } = yield effects.call(restApi.api.subscriptions.getSubscriptionSummaries, tenantId);
387
+ const summary = yield effects.call(restApi.api.subscriptions.getSubscriptionSummaries, tenantId);
388
+ const { currentPlanId, subscriptionId, } = summary;
394
389
  const subscriptionResponse = yield effects.call(restApi.api.subscriptions.getManagedSubscription, subscriptionId);
395
390
  const planResponse = yield effects.call(restApi.api.subscriptions.getSubscriptionPlan, currentPlanId);
396
- yield effects.put(actions$6.setBillingInformation(Object.assign(Object.assign({ loading: false, fetching: false, externallyManaged,
397
- defaultPlanId,
398
- defaultPaymentId }, (subscriptionResponse
391
+ yield effects.put(actions$6.setState(Object.assign(Object.assign({ loading: false, fetching: false, summary }, (subscriptionResponse
399
392
  ? {
400
393
  subscription: {
401
394
  id: subscriptionResponse.id,
@@ -409,6 +402,7 @@ function* loadSummaries(tenantId) {
409
402
  id: subscriptionItem.id,
410
403
  planId: subscriptionItem.planId,
411
404
  })),
405
+ trialEnd: subscriptionResponse.trialEnd ? new Date(subscriptionResponse.trialEnd) : null,
412
406
  },
413
407
  }
414
408
  : {})), (planResponse
@@ -417,7 +411,7 @@ function* loadSummaries(tenantId) {
417
411
  id: planResponse.id,
418
412
  name: planResponse.name,
419
413
  description: planResponse.description,
420
- price: toPrice(((_a = planResponse.price) === null || _a === void 0 ? void 0 : _a.amount) || 0),
414
+ price: ((_a = planResponse.price) === null || _a === void 0 ? void 0 : _a.amount) || 0,
421
415
  currency: ((_b = planResponse.price) === null || _b === void 0 ? void 0 : _b.currency) || 'usd',
422
416
  recurringInterval: 'month',
423
417
  },
@@ -429,11 +423,12 @@ function* loadSummaries(tenantId) {
429
423
  }
430
424
  }
431
425
  function* cancelSubscription() {
426
+ var _a;
432
427
  const overview = yield effects.select((state) => state.subscriptions.billing.information);
433
428
  if (!overview.subscription) {
434
429
  return;
435
430
  }
436
- if (overview.externallyManaged) {
431
+ if ((_a = overview.summary) === null || _a === void 0 ? void 0 : _a.externallyManaged) {
437
432
  yield effects.put(actions$6.setCancellationError('Billing is externally managed'));
438
433
  return;
439
434
  }
@@ -443,7 +438,7 @@ function* cancelSubscription() {
443
438
  try {
444
439
  yield effects.put(actions$6.setCancellationLoading(true));
445
440
  yield effects.call(restApi.api.subscriptions.cancelManagedSubscription, subscriptionId);
446
- yield effects.put(actions$6.setBillingInformation({
441
+ yield effects.put(actions$6.setState({
447
442
  subscription: Object.assign(Object.assign({}, overview.subscription), { cancellation: {
448
443
  policy: exports.SubscriptionCancellationPolicy.AT_PERIOD_END,
449
444
  } }),
@@ -456,11 +451,12 @@ function* cancelSubscription() {
456
451
  }
457
452
  }
458
453
  function* renewSubscription() {
454
+ var _a;
459
455
  const overview = yield effects.select((state) => state.subscriptions.billing.information);
460
456
  if (!overview.subscription) {
461
457
  return;
462
458
  }
463
- if (overview.externallyManaged) {
459
+ if ((_a = overview.summary) === null || _a === void 0 ? void 0 : _a.externallyManaged) {
464
460
  yield effects.put(actions$6.setCancellationError('Billing is externally managed'));
465
461
  return;
466
462
  }
@@ -470,7 +466,7 @@ function* renewSubscription() {
470
466
  try {
471
467
  yield effects.put(actions$6.setRenewalLoading(true));
472
468
  yield effects.call(restApi.api.subscriptions.renewManagedSubscription, subscriptionId);
473
- yield effects.put(actions$6.setBillingInformation({
469
+ yield effects.put(actions$6.setState({
474
470
  subscription: Object.assign(Object.assign({}, overview.subscription), { cancellation: null }),
475
471
  }));
476
472
  yield effects.put(actions$6.setRenewalLoading(false));
@@ -496,12 +492,20 @@ function* loadSummariesMock() {
496
492
  var _a, _b;
497
493
  yield effects.put(actions$6.setLoading(true));
498
494
  yield effects.delay(500);
499
- yield effects.put(actions$6.setBillingInformation({
495
+ yield effects.put(actions$6.setState({
500
496
  loading: false,
501
497
  fetching: false,
502
- externallyManaged: false,
503
- subscription: Object.assign(Object.assign({}, subscriptionResponseMock), { startDate: new Date(subscriptionResponseMock.startDate), currentPeriodStart: new Date(subscriptionResponseMock.currentPeriodStart), currentPeriodEnd: new Date(subscriptionResponseMock.currentPeriodEnd), status: toSubscriptionStatus(subscriptionResponseMock.status), cancellation: subscriptionResponseMock.cancellation && toSubscriptionCancellation(subscriptionResponseMock.cancellation), items: subscriptionResponseMock.items }),
504
- plan: Object.assign(Object.assign({}, planResponseMock[0]), { price: toPrice((_a = planResponseMock[0].price) === null || _a === void 0 ? void 0 : _a.amount), currency: (_b = planResponseMock[0].price) === null || _b === void 0 ? void 0 : _b.currency, recurringInterval: 'month' }),
498
+ summary: {
499
+ subscriptionId: subscriptionResponseMock.id,
500
+ paymentMethodId: 'mockPaymentMethodId',
501
+ tenantConfigurationId: 'mockTenantConfigurationId',
502
+ providerType: restApi.ProviderType.Stripe,
503
+ externallyManaged: false,
504
+ currentPlanId: planResponseMock[0].id,
505
+ defaultPlanId: planResponseMock[0].id,
506
+ },
507
+ subscription: Object.assign(Object.assign({}, subscriptionResponseMock), { startDate: new Date(subscriptionResponseMock.startDate), currentPeriodStart: new Date(subscriptionResponseMock.currentPeriodStart), currentPeriodEnd: new Date(subscriptionResponseMock.currentPeriodEnd), status: toSubscriptionStatus(subscriptionResponseMock.status), cancellation: subscriptionResponseMock.cancellation && toSubscriptionCancellation(subscriptionResponseMock.cancellation), items: subscriptionResponseMock.items, trialEnd: null }),
508
+ plan: Object.assign(Object.assign({}, planResponseMock[0]), { price: (_a = planResponseMock[0].price) === null || _a === void 0 ? void 0 : _a.amount, currency: (_b = planResponseMock[0].price) === null || _b === void 0 ? void 0 : _b.currency, recurringInterval: 'month' }),
505
509
  }));
506
510
  }
507
511
  function* subscriptionBillingInformationSagasMock() {
@@ -677,18 +681,29 @@ function* resetCheckout() {
677
681
  }));
678
682
  }
679
683
  function* confirmPlan({ payload: paymentMethodId }) {
680
- const { subscription, status, planId } = yield effects.select(({ subscriptions: { billing: { information }, checkout, }, }) => ({
681
- subscription: information.subscription,
682
- status: checkout.status,
683
- planId: checkout.checkoutPlanId,
684
+ const { checkout: { status, checkoutPlanId, }, subscription, summary } = yield effects.select(({ subscriptions: { billing: { information: { summary, subscription } }, checkout, }, }) => ({
685
+ subscription,
686
+ summary,
687
+ checkout,
684
688
  }));
685
- if (!planId || !subscription) {
689
+ const isTrialing = (subscription === null || subscription === void 0 ? void 0 : subscription.trialEnd) || (subscription === null || subscription === void 0 ? void 0 : subscription.status) === exports.SubscriptionStatus.TRIALING;
690
+ const hasPaymentMethod = !!(summary === null || summary === void 0 ? void 0 : summary.paymentMethodId);
691
+ if (!checkoutPlanId || !subscription) {
686
692
  yield effects.put(actions$3.setState({
687
693
  loading: false,
688
694
  status: exports.CheckoutStatus.ERROR,
689
695
  }));
690
696
  return;
691
697
  }
698
+ if (isTrialing && hasPaymentMethod) {
699
+ yield effects.put(actions$3.setState({
700
+ checkoutPlanId: null,
701
+ loading: false,
702
+ status: exports.CheckoutStatus.CONFIRM,
703
+ }));
704
+ yield effects.put(actions$3.checkoutEvent(exports.CheckoutEvent.CONFIRMED));
705
+ return;
706
+ }
692
707
  if (status === exports.CheckoutStatus.CHECKOUT) {
693
708
  yield effects.put(actions$3.setState({
694
709
  loading: true,
@@ -697,7 +712,7 @@ function* confirmPlan({ payload: paymentMethodId }) {
697
712
  try {
698
713
  yield effects.call(restApi.api.subscriptions.updateManagedSubscription, subscription.id, {
699
714
  paymentMethodId,
700
- planId
715
+ planId: checkoutPlanId,
701
716
  });
702
717
  yield effects.put(actions$3.setState({
703
718
  checkoutPlanId: null,
@@ -771,7 +786,7 @@ function* loadPlans() {
771
786
  id: item.id,
772
787
  name: item.name,
773
788
  description: item.description,
774
- price: +((((_a = item.price) === null || _a === void 0 ? void 0 : _a.amount) || 0) / 100).toFixed(2),
789
+ price: ((_a = item.price) === null || _a === void 0 ? void 0 : _a.amount) || 0,
775
790
  currency: ((_b = item.price) === null || _b === void 0 ? void 0 : _b.currency) || 'usd',
776
791
  recurringInterval: 'month',
777
792
  });
@@ -797,7 +812,7 @@ function* loadPlansMock() {
797
812
  loading: false,
798
813
  plans: planResponseMock.map((item) => {
799
814
  var _a, _b;
800
- return (Object.assign(Object.assign({}, item), { price: +((((_a = item.price) === null || _a === void 0 ? void 0 : _a.amount) || 0) / 100).toFixed(2), currency: ((_b = item.price) === null || _b === void 0 ? void 0 : _b.currency) || 'usd', recurringInterval: 'month' }));
815
+ return (Object.assign(Object.assign({}, item), { price: ((_a = item.price) === null || _a === void 0 ? void 0 : _a.amount) || 0, currency: ((_b = item.price) === null || _b === void 0 ? void 0 : _b.currency) || 'usd', recurringInterval: 'month' }));
801
816
  }),
802
817
  }));
803
818
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@frontegg/redux-store",
3
3
  "libName": "FronteggReduxStore",
4
- "version": "5.28.1",
4
+ "version": "5.30.1",
5
5
  "author": "Frontegg LTD",
6
6
  "main": "./node/index.js",
7
7
  "module": "./index.js",
@@ -2,7 +2,6 @@ import { BillingInformationState } from './interfaces';
2
2
  export declare const initialBillingInformationState: BillingInformationState;
3
3
  declare const reducer: import("redux").Reducer<BillingInformationState, import("redux").AnyAction>;
4
4
  declare const actions: {
5
- setBillingInformation: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[Partial<BillingInformationState>], Partial<BillingInformationState>, string, never, never>;
6
5
  setCancellationLoading: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[boolean], boolean, string, never, never>;
7
6
  setCancellationError: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[string | null], string | null, string, never, never>;
8
7
  setRenewalLoading: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[boolean], boolean, string, never, never>;
@@ -1,11 +1,10 @@
1
1
  import { Plan, Subscription } from '../../general.interfaces';
2
+ import { ISubscriptionSummariesResponse } from '@frontegg/rest-api';
2
3
  export interface BillingInformationState {
3
4
  loading: boolean;
4
5
  error: string | null;
5
6
  fetching: boolean;
6
- externallyManaged: boolean;
7
- defaultPlanId: string | null;
8
- defaultPaymentId: string | null;
7
+ summary?: ISubscriptionSummariesResponse;
9
8
  subscription?: Subscription;
10
9
  plan?: Plan;
11
10
  cancellation: {
@@ -17,7 +17,6 @@ export declare const billingActions: {
17
17
  downloadInvoice: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[import("./interfaces").DownloadInvoiceActionPayload], import("./interfaces").DownloadInvoiceActionPayload, string, never, never>;
18
18
  };
19
19
  information: {
20
- setBillingInformation: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[Partial<import("./interfaces").BillingInformationState>], Partial<import("./interfaces").BillingInformationState>, string, never, never>;
21
20
  setCancellationLoading: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[boolean], boolean, string, never, never>;
22
21
  setCancellationError: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[string | null], string | null, string, never, never>;
23
22
  setRenewalLoading: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[boolean], boolean, string, never, never>;
@@ -13,7 +13,8 @@ export declare enum SubscriptionStatus {
13
13
  ACTIVE = "ACTIVE",
14
14
  CANCELED = "CANCELED",
15
15
  INCOMPLETE = "INCOMPLETE",
16
- EXPIRED = "EXPIRED"
16
+ EXPIRED = "EXPIRED",
17
+ TRIALING = "TRIALING"
17
18
  }
18
19
  export interface Subscription {
19
20
  id: string;
@@ -24,6 +25,7 @@ export interface Subscription {
24
25
  status: SubscriptionStatus;
25
26
  cancellation: SubscriptionCancellation | null;
26
27
  items: SubscriptionItem[];
28
+ trialEnd: Date | null;
27
29
  }
28
30
  export interface SubscriptionItem {
29
31
  id: string;
@@ -37,7 +37,6 @@ declare const _default: {
37
37
  downloadInvoice: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[import("./interfaces").DownloadInvoiceActionPayload], import("./interfaces").DownloadInvoiceActionPayload, string, never, never>;
38
38
  };
39
39
  information: {
40
- setBillingInformation: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[Partial<import("./interfaces").BillingInformationState>], Partial<import("./interfaces").BillingInformationState>, string, never, never>;
41
40
  setCancellationLoading: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[boolean], boolean, string, never, never>;
42
41
  setCancellationError: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[string | null], string | null, string, never, never>;
43
42
  setRenewalLoading: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[boolean], boolean, string, never, never>;
@@ -64,9 +64,6 @@ const initialBillingInformationState = {
64
64
  loading: false,
65
65
  error: null,
66
66
  fetching: true,
67
- externallyManaged: false,
68
- defaultPlanId: null,
69
- defaultPaymentId: null,
70
67
  cancellation: {
71
68
  loading: false,
72
69
  error: null,
@@ -76,10 +73,7 @@ const initialBillingInformationState = {
76
73
  error: null,
77
74
  },
78
75
  };
79
- const reducers$5 = Object.assign(Object.assign({}, createModuleCaseReducers()), { setBillingInformation: {
80
- prepare: (payload) => ({ payload }),
81
- reducer: (state, action) => (Object.assign(Object.assign({}, state), action.payload)),
82
- }, setCancellationLoading: createKeyCaseLoadingReducer('cancellation'), setCancellationError: createKeyCaseErrorReducer('cancellation'), setRenewalLoading: createKeyCaseLoadingReducer('renewal'), setRenewalError: createKeyCaseErrorReducer('renewal') });
76
+ const reducers$5 = Object.assign(Object.assign({}, createModuleCaseReducers()), { setCancellationLoading: createKeyCaseLoadingReducer('cancellation'), setCancellationError: createKeyCaseErrorReducer('cancellation'), setRenewalLoading: createKeyCaseLoadingReducer('renewal'), setRenewalError: createKeyCaseErrorReducer('renewal') });
83
77
  const { reducer: reducer$6, actions: overviewActions, name: name$5, } = createSlice({
84
78
  name: `${subscriptionsStoreName}/billing/information`,
85
79
  initialState: initialBillingInformationState,
@@ -242,15 +236,13 @@ var SubscriptionStatus;
242
236
  SubscriptionStatus["CANCELED"] = "CANCELED";
243
237
  SubscriptionStatus["INCOMPLETE"] = "INCOMPLETE";
244
238
  SubscriptionStatus["EXPIRED"] = "EXPIRED";
239
+ SubscriptionStatus["TRIALING"] = "TRIALING";
245
240
  })(SubscriptionStatus || (SubscriptionStatus = {}));
246
241
  var SubscriptionCancellationPolicy;
247
242
  (function (SubscriptionCancellationPolicy) {
248
243
  SubscriptionCancellationPolicy["AT_PERIOD_END"] = "atPeriodEnd";
249
244
  })(SubscriptionCancellationPolicy || (SubscriptionCancellationPolicy = {}));
250
245
 
251
- function toPrice(amount) {
252
- return +(amount / 100).toFixed(2);
253
- }
254
246
  function toSubscriptionCancellation({ policy }) {
255
247
  return {
256
248
  policy: toSubscriptionCancellationPolicy(),
@@ -269,6 +261,8 @@ function toSubscriptionStatus(status) {
269
261
  return SubscriptionStatus.CANCELED;
270
262
  case ISubscriptionStatus.EXPIRED:
271
263
  return SubscriptionStatus.EXPIRED;
264
+ case ISubscriptionStatus.TRIALING:
265
+ return SubscriptionStatus.TRIALING;
272
266
  default:
273
267
  return SubscriptionStatus.EXPIRED;
274
268
  }
@@ -387,12 +381,11 @@ function* loadSummaries(tenantId) {
387
381
  var _a, _b;
388
382
  yield put(actions$6.setLoading(true));
389
383
  try {
390
- const { currentPlanId, subscriptionId, externallyManaged, defaultPlanId, paymentMethodId: defaultPaymentId, } = yield call(api.subscriptions.getSubscriptionSummaries, tenantId);
384
+ const summary = yield call(api.subscriptions.getSubscriptionSummaries, tenantId);
385
+ const { currentPlanId, subscriptionId, } = summary;
391
386
  const subscriptionResponse = yield call(api.subscriptions.getManagedSubscription, subscriptionId);
392
387
  const planResponse = yield call(api.subscriptions.getSubscriptionPlan, currentPlanId);
393
- yield put(actions$6.setBillingInformation(Object.assign(Object.assign({ loading: false, fetching: false, externallyManaged,
394
- defaultPlanId,
395
- defaultPaymentId }, (subscriptionResponse
388
+ yield put(actions$6.setState(Object.assign(Object.assign({ loading: false, fetching: false, summary }, (subscriptionResponse
396
389
  ? {
397
390
  subscription: {
398
391
  id: subscriptionResponse.id,
@@ -406,6 +399,7 @@ function* loadSummaries(tenantId) {
406
399
  id: subscriptionItem.id,
407
400
  planId: subscriptionItem.planId,
408
401
  })),
402
+ trialEnd: subscriptionResponse.trialEnd ? new Date(subscriptionResponse.trialEnd) : null,
409
403
  },
410
404
  }
411
405
  : {})), (planResponse
@@ -414,7 +408,7 @@ function* loadSummaries(tenantId) {
414
408
  id: planResponse.id,
415
409
  name: planResponse.name,
416
410
  description: planResponse.description,
417
- price: toPrice(((_a = planResponse.price) === null || _a === void 0 ? void 0 : _a.amount) || 0),
411
+ price: ((_a = planResponse.price) === null || _a === void 0 ? void 0 : _a.amount) || 0,
418
412
  currency: ((_b = planResponse.price) === null || _b === void 0 ? void 0 : _b.currency) || 'usd',
419
413
  recurringInterval: 'month',
420
414
  },
@@ -426,11 +420,12 @@ function* loadSummaries(tenantId) {
426
420
  }
427
421
  }
428
422
  function* cancelSubscription() {
423
+ var _a;
429
424
  const overview = yield select((state) => state.subscriptions.billing.information);
430
425
  if (!overview.subscription) {
431
426
  return;
432
427
  }
433
- if (overview.externallyManaged) {
428
+ if ((_a = overview.summary) === null || _a === void 0 ? void 0 : _a.externallyManaged) {
434
429
  yield put(actions$6.setCancellationError('Billing is externally managed'));
435
430
  return;
436
431
  }
@@ -440,7 +435,7 @@ function* cancelSubscription() {
440
435
  try {
441
436
  yield put(actions$6.setCancellationLoading(true));
442
437
  yield call(api.subscriptions.cancelManagedSubscription, subscriptionId);
443
- yield put(actions$6.setBillingInformation({
438
+ yield put(actions$6.setState({
444
439
  subscription: Object.assign(Object.assign({}, overview.subscription), { cancellation: {
445
440
  policy: SubscriptionCancellationPolicy.AT_PERIOD_END,
446
441
  } }),
@@ -453,11 +448,12 @@ function* cancelSubscription() {
453
448
  }
454
449
  }
455
450
  function* renewSubscription() {
451
+ var _a;
456
452
  const overview = yield select((state) => state.subscriptions.billing.information);
457
453
  if (!overview.subscription) {
458
454
  return;
459
455
  }
460
- if (overview.externallyManaged) {
456
+ if ((_a = overview.summary) === null || _a === void 0 ? void 0 : _a.externallyManaged) {
461
457
  yield put(actions$6.setCancellationError('Billing is externally managed'));
462
458
  return;
463
459
  }
@@ -467,7 +463,7 @@ function* renewSubscription() {
467
463
  try {
468
464
  yield put(actions$6.setRenewalLoading(true));
469
465
  yield call(api.subscriptions.renewManagedSubscription, subscriptionId);
470
- yield put(actions$6.setBillingInformation({
466
+ yield put(actions$6.setState({
471
467
  subscription: Object.assign(Object.assign({}, overview.subscription), { cancellation: null }),
472
468
  }));
473
469
  yield put(actions$6.setRenewalLoading(false));
@@ -493,12 +489,20 @@ function* loadSummariesMock() {
493
489
  var _a, _b;
494
490
  yield put(actions$6.setLoading(true));
495
491
  yield delay(500);
496
- yield put(actions$6.setBillingInformation({
492
+ yield put(actions$6.setState({
497
493
  loading: false,
498
494
  fetching: false,
499
- externallyManaged: false,
500
- subscription: Object.assign(Object.assign({}, subscriptionResponseMock), { startDate: new Date(subscriptionResponseMock.startDate), currentPeriodStart: new Date(subscriptionResponseMock.currentPeriodStart), currentPeriodEnd: new Date(subscriptionResponseMock.currentPeriodEnd), status: toSubscriptionStatus(subscriptionResponseMock.status), cancellation: subscriptionResponseMock.cancellation && toSubscriptionCancellation(subscriptionResponseMock.cancellation), items: subscriptionResponseMock.items }),
501
- plan: Object.assign(Object.assign({}, planResponseMock[0]), { price: toPrice((_a = planResponseMock[0].price) === null || _a === void 0 ? void 0 : _a.amount), currency: (_b = planResponseMock[0].price) === null || _b === void 0 ? void 0 : _b.currency, recurringInterval: 'month' }),
495
+ summary: {
496
+ subscriptionId: subscriptionResponseMock.id,
497
+ paymentMethodId: 'mockPaymentMethodId',
498
+ tenantConfigurationId: 'mockTenantConfigurationId',
499
+ providerType: ProviderType.Stripe,
500
+ externallyManaged: false,
501
+ currentPlanId: planResponseMock[0].id,
502
+ defaultPlanId: planResponseMock[0].id,
503
+ },
504
+ subscription: Object.assign(Object.assign({}, subscriptionResponseMock), { startDate: new Date(subscriptionResponseMock.startDate), currentPeriodStart: new Date(subscriptionResponseMock.currentPeriodStart), currentPeriodEnd: new Date(subscriptionResponseMock.currentPeriodEnd), status: toSubscriptionStatus(subscriptionResponseMock.status), cancellation: subscriptionResponseMock.cancellation && toSubscriptionCancellation(subscriptionResponseMock.cancellation), items: subscriptionResponseMock.items, trialEnd: null }),
505
+ plan: Object.assign(Object.assign({}, planResponseMock[0]), { price: (_a = planResponseMock[0].price) === null || _a === void 0 ? void 0 : _a.amount, currency: (_b = planResponseMock[0].price) === null || _b === void 0 ? void 0 : _b.currency, recurringInterval: 'month' }),
502
506
  }));
503
507
  }
504
508
  function* subscriptionBillingInformationSagasMock() {
@@ -674,18 +678,29 @@ function* resetCheckout() {
674
678
  }));
675
679
  }
676
680
  function* confirmPlan({ payload: paymentMethodId }) {
677
- const { subscription, status, planId } = yield select(({ subscriptions: { billing: { information }, checkout, }, }) => ({
678
- subscription: information.subscription,
679
- status: checkout.status,
680
- planId: checkout.checkoutPlanId,
681
+ const { checkout: { status, checkoutPlanId, }, subscription, summary } = yield select(({ subscriptions: { billing: { information: { summary, subscription } }, checkout, }, }) => ({
682
+ subscription,
683
+ summary,
684
+ checkout,
681
685
  }));
682
- if (!planId || !subscription) {
686
+ const isTrialing = (subscription === null || subscription === void 0 ? void 0 : subscription.trialEnd) || (subscription === null || subscription === void 0 ? void 0 : subscription.status) === SubscriptionStatus.TRIALING;
687
+ const hasPaymentMethod = !!(summary === null || summary === void 0 ? void 0 : summary.paymentMethodId);
688
+ if (!checkoutPlanId || !subscription) {
683
689
  yield put(actions$3.setState({
684
690
  loading: false,
685
691
  status: CheckoutStatus.ERROR,
686
692
  }));
687
693
  return;
688
694
  }
695
+ if (isTrialing && hasPaymentMethod) {
696
+ yield put(actions$3.setState({
697
+ checkoutPlanId: null,
698
+ loading: false,
699
+ status: CheckoutStatus.CONFIRM,
700
+ }));
701
+ yield put(actions$3.checkoutEvent(CheckoutEvent.CONFIRMED));
702
+ return;
703
+ }
689
704
  if (status === CheckoutStatus.CHECKOUT) {
690
705
  yield put(actions$3.setState({
691
706
  loading: true,
@@ -694,7 +709,7 @@ function* confirmPlan({ payload: paymentMethodId }) {
694
709
  try {
695
710
  yield call(api.subscriptions.updateManagedSubscription, subscription.id, {
696
711
  paymentMethodId,
697
- planId
712
+ planId: checkoutPlanId,
698
713
  });
699
714
  yield put(actions$3.setState({
700
715
  checkoutPlanId: null,
@@ -768,7 +783,7 @@ function* loadPlans() {
768
783
  id: item.id,
769
784
  name: item.name,
770
785
  description: item.description,
771
- price: +((((_a = item.price) === null || _a === void 0 ? void 0 : _a.amount) || 0) / 100).toFixed(2),
786
+ price: ((_a = item.price) === null || _a === void 0 ? void 0 : _a.amount) || 0,
772
787
  currency: ((_b = item.price) === null || _b === void 0 ? void 0 : _b.currency) || 'usd',
773
788
  recurringInterval: 'month',
774
789
  });
@@ -794,7 +809,7 @@ function* loadPlansMock() {
794
809
  loading: false,
795
810
  plans: planResponseMock.map((item) => {
796
811
  var _a, _b;
797
- return (Object.assign(Object.assign({}, item), { price: +((((_a = item.price) === null || _a === void 0 ? void 0 : _a.amount) || 0) / 100).toFixed(2), currency: ((_b = item.price) === null || _b === void 0 ? void 0 : _b.currency) || 'usd', recurringInterval: 'month' }));
812
+ return (Object.assign(Object.assign({}, item), { price: ((_a = item.price) === null || _a === void 0 ? void 0 : _a.amount) || 0, currency: ((_b = item.price) === null || _b === void 0 ? void 0 : _b.currency) || 'usd', recurringInterval: 'month' }));
798
813
  }),
799
814
  }));
800
815
  }
@@ -1,7 +1,6 @@
1
1
  import { ISubscriptionCancellationPolicy, ISubscriptionCancellationResponse, ISubscriptionStatus, ProviderType } from '@frontegg/rest-api';
2
2
  import { PaymentProvider, SubscriptionCancellation, SubscriptionCancellationPolicy, SubscriptionStatus } from './general.interfaces';
3
3
  export declare function toApiPaymentProviderType(paymentProvider: PaymentProvider): ProviderType;
4
- export declare function toPrice(amount: number): number;
5
4
  export declare function toSubscriptionCancellation({ policy }: ISubscriptionCancellationResponse): SubscriptionCancellation;
6
5
  export declare function toSubscriptionCancellationPolicy(policy: ISubscriptionCancellationPolicy): SubscriptionCancellationPolicy;
7
6
  export declare function toSubscriptionStatus(status: ISubscriptionStatus): SubscriptionStatus;
@@ -24,7 +24,6 @@ declare const actions: {
24
24
  downloadInvoice: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[import("./interfaces").DownloadInvoiceActionPayload], import("./interfaces").DownloadInvoiceActionPayload, string, never, never>;
25
25
  };
26
26
  information: {
27
- setBillingInformation: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[Partial<import("./interfaces").BillingInformationState>], Partial<import("./interfaces").BillingInformationState>, string, never, never>;
28
27
  setCancellationLoading: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[boolean], boolean, string, never, never>;
29
28
  setCancellationError: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[string | null], string | null, string, never, never>;
30
29
  setRenewalLoading: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[boolean], boolean, string, never, never>;