@frontegg/redux-store 5.29.0 → 5.31.0

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,7 +1,7 @@
1
1
  import { s as subscriptionsStoreName } from '../constants-4d9682b2.js';
2
2
  export { s as subscriptionsStoreName } from '../constants-4d9682b2.js';
3
3
  import { createSlice, createAction, combineReducers } from '@reduxjs/toolkit';
4
- import { takeEvery, select, put, call, delay, all } from 'redux-saga/effects';
4
+ import { takeEvery, select, put, call, all, delay } from 'redux-saga/effects';
5
5
  import { ISubscriptionStatus, PaymentMethodType as PaymentMethodType$1, api, ProviderType } from '@frontegg/rest-api';
6
6
 
7
7
  function createModuleCaseReducers() {
@@ -44,7 +44,7 @@ const { actions: sliceActions$2, reducer: reducer$8, name: name$7 } = createSlic
44
44
  initialState: plansInitialState,
45
45
  reducers: Object.assign({}, createModuleCaseReducers()),
46
46
  });
47
- const actions$8 = Object.assign({ loadPlans: createAction(`${name$7}/loadPlans`) }, sliceActions$2);
47
+ const actions$9 = Object.assign({ loadPlans: createAction(`${name$7}/loadPlans`) }, sliceActions$2);
48
48
 
49
49
  const configInitialState = {
50
50
  loading: false,
@@ -58,7 +58,7 @@ const { actions: configActions, reducer: reducer$7, name: name$6, } = createSlic
58
58
  initialState: configInitialState,
59
59
  reducers: reducers$6,
60
60
  });
61
- const actions$7 = Object.assign({ loadPaymentConfiguration: createAction(`${name$6}/loadPaymentConfiguration`) }, configActions);
61
+ const actions$8 = Object.assign({ loadPaymentConfiguration: createAction(`${name$6}/loadPaymentConfiguration`) }, configActions);
62
62
 
63
63
  const initialBillingInformationState = {
64
64
  loading: false,
@@ -79,7 +79,7 @@ const { reducer: reducer$6, actions: overviewActions, name: name$5, } = createSl
79
79
  initialState: initialBillingInformationState,
80
80
  reducers: reducers$5,
81
81
  });
82
- const actions$6 = Object.assign({ loadBillingInformation: createAction(`${name$5}/loadBillingInformation`), cancelSubscription: createAction(`${name$5}/cancelSubscription`), renewSubscription: createAction(`${name$5}/renewSubscription`) }, overviewActions);
82
+ const actions$7 = Object.assign({ loadBillingInformation: createAction(`${name$5}/loadBillingInformation`), cancelSubscription: createAction(`${name$5}/cancelSubscription`), renewSubscription: createAction(`${name$5}/renewSubscription`) }, overviewActions);
83
83
 
84
84
  const initialPaymentMethodState = {
85
85
  loading: false,
@@ -95,7 +95,7 @@ const { reducer: reducer$5, actions: paymentActions, name: name$4, } = createSli
95
95
  initialState: initialPaymentMethodState,
96
96
  reducers: reducers$4,
97
97
  });
98
- const actions$5 = Object.assign({ loadPaymentMethod: createAction(`${name$4}/loadPaymentMethod`), submitPaymentMethod: createAction(`${name$4}/submitPaymentMethod`), submitPaymentMethodError: createAction(`${name$4}/submitPaymentMethodError`), submitPaymentMethodSuccess: createAction(`${name$4}/submitPaymentMethodSuccess`), updatePaymentMethodBillingDetails: createAction(`${name$4}/updateBillingDetails`, (payload) => ({ payload })) }, paymentActions);
98
+ const actions$6 = Object.assign({ loadPaymentMethod: createAction(`${name$4}/loadPaymentMethod`), submitPaymentMethod: createAction(`${name$4}/submitPaymentMethod`), submitPaymentMethodError: createAction(`${name$4}/submitPaymentMethodError`), submitPaymentMethodSuccess: createAction(`${name$4}/submitPaymentMethodSuccess`), updatePaymentMethodBillingDetails: createAction(`${name$4}/updateBillingDetails`, (payload) => ({ payload })) }, paymentActions);
99
99
 
100
100
  const initialInvoicesState = {
101
101
  loading: false,
@@ -116,7 +116,11 @@ const { reducer: reducer$4, actions: sliceActions$1, name: name$3, } = createSli
116
116
  initialState: initialInvoicesState,
117
117
  reducers: reducers$3,
118
118
  });
119
- const actions$4 = Object.assign({ loadInvoices: createAction(`${name$3}/loadInvoices`), downloadInvoice: createAction(`${name$3}/downloadInvoice`, (payload) => ({ payload })) }, sliceActions$1);
119
+ const actions$5 = Object.assign({ loadInvoices: createAction(`${name$3}/loadInvoices`), downloadInvoice: createAction(`${name$3}/downloadInvoice`, (payload) => ({ payload })) }, sliceActions$1);
120
+
121
+ const actions$4 = {
122
+ load: createAction(`${subscriptionsStoreName}/subscription/load`),
123
+ };
120
124
 
121
125
  const billingInitialState = {
122
126
  information: initialBillingInformationState,
@@ -124,9 +128,10 @@ const billingInitialState = {
124
128
  paymentMethod: initialPaymentMethodState,
125
129
  };
126
130
  const billingActions = {
127
- invoices: actions$4,
128
- information: actions$6,
129
- paymentMethod: actions$5,
131
+ invoices: actions$5,
132
+ information: actions$7,
133
+ paymentMethod: actions$6,
134
+ subscription: actions$4,
130
135
  };
131
136
  const billingReducer = combineReducers({
132
137
  invoices: reducer$4,
@@ -176,10 +181,7 @@ const initialSubscriptionStripeState = {
176
181
  error: null,
177
182
  cardSetupIntentSecret: null,
178
183
  };
179
- const reducers$1 = Object.assign(Object.assign({}, createModuleCaseReducers()), { setStripeState: {
180
- prepare: (payload) => ({ payload }),
181
- reducer: (state, action) => (Object.assign(Object.assign({}, state), action.payload)),
182
- } });
184
+ const reducers$1 = Object.assign({}, createModuleCaseReducers());
183
185
  const { reducer: reducer$2, actions: reducerActions, name: name$1, } = createSlice({
184
186
  name: `${subscriptionsStoreName}/stripe`,
185
187
  initialState: initialSubscriptionStripeState,
@@ -210,9 +212,9 @@ const initialState = {
210
212
  managedSubscriptions: managedSubscriptionsInitialState,
211
213
  };
212
214
  const actions = {
213
- config: actions$7,
215
+ config: actions$8,
214
216
  billing: billingActions,
215
- plans: actions$8,
217
+ plans: actions$9,
216
218
  checkout: actions$3,
217
219
  stripe: actions$2,
218
220
  managedSubscriptions: actions$1,
@@ -357,49 +359,48 @@ const paymentMethodsMock = [
357
359
  ];
358
360
 
359
361
  function* subscriptionBillingInformationSagas() {
360
- yield takeEvery(actions$6.loadBillingInformation, loadBillingInformation);
361
- yield takeEvery(actions$6.cancelSubscription, cancelSubscription);
362
- yield takeEvery(actions$6.renewSubscription, renewSubscription);
362
+ yield takeEvery(actions$7.loadBillingInformation, loadBillingInformation);
363
+ yield takeEvery(actions$7.cancelSubscription, cancelSubscription);
364
+ yield takeEvery(actions$7.renewSubscription, renewSubscription);
363
365
  yield takeEvery(actions$3.checkoutEvent, checkoutEvent$2);
364
366
  }
365
367
  function* loadBillingInformation() {
366
368
  const paymentProvider = yield select((state) => { var _a; return (_a = state.subscriptions.config.config) === null || _a === void 0 ? void 0 : _a.paymentProvider; });
367
369
  const tenantId = yield select((state) => { var _a, _b, _c; return (_c = (_b = (_a = state.auth) === null || _a === void 0 ? void 0 : _a.profileState) === null || _b === void 0 ? void 0 : _b.profile) === null || _c === void 0 ? void 0 : _c.tenantId; });
368
- yield put(actions$6.setLoading(true));
369
370
  if (!paymentProvider || !tenantId) {
370
- yield put(actions$6.setError(!paymentProvider ? 'Internal feature failure' : 'Not authorized'));
371
+ yield put(actions$7.setError(!paymentProvider ? 'Internal feature failure' : 'Not authorized'));
371
372
  return;
372
373
  }
373
- try {
374
- yield loadSummaries(tenantId);
375
- }
376
- catch (e) {
377
- yield put(actions$6.setError(e.message));
378
- }
374
+ yield loadSummaries(tenantId);
379
375
  }
380
376
  function* loadSummaries(tenantId) {
381
377
  var _a, _b;
382
- yield put(actions$6.setLoading(true));
378
+ yield put(actions$7.setLoading(true));
383
379
  try {
384
380
  const summary = yield call(api.subscriptions.getSubscriptionSummaries, tenantId);
385
- const { currentPlanId, subscriptionId, } = summary;
386
- const subscriptionResponse = yield call(api.subscriptions.getManagedSubscription, subscriptionId);
387
- const planResponse = yield call(api.subscriptions.getSubscriptionPlan, currentPlanId);
388
- yield put(actions$6.setState(Object.assign(Object.assign({ loading: false, fetching: false, summary }, (subscriptionResponse
381
+ const { currentPlanId, externallyManaged, subscriptionId } = summary;
382
+ let subscriptionResponse = null;
383
+ let planResponse;
384
+ if (!externallyManaged) {
385
+ [subscriptionResponse, planResponse] = yield all([
386
+ call(api.subscriptions.getManagedSubscription, subscriptionId),
387
+ call(api.subscriptions.getSubscriptionPlan, currentPlanId),
388
+ ]);
389
+ }
390
+ else {
391
+ planResponse = yield call(api.subscriptions.getSubscriptionPlan, currentPlanId);
392
+ }
393
+ yield put(actions$7.setState(Object.assign(Object.assign({ loading: false, fetching: false, summary }, (subscriptionResponse
389
394
  ? {
390
395
  subscription: {
391
396
  id: subscriptionResponse.id,
392
397
  externalId: subscriptionResponse.externalId,
393
- startDate: new Date(subscriptionResponse.startDate),
394
- currentPeriodStart: new Date(subscriptionResponse.currentPeriodStart),
395
- currentPeriodEnd: new Date(subscriptionResponse.currentPeriodEnd),
398
+ startDate: subscriptionResponse.startDate,
399
+ currentPeriodStart: subscriptionResponse.currentPeriodStart,
400
+ currentPeriodEnd: subscriptionResponse.currentPeriodEnd,
396
401
  status: toSubscriptionStatus(subscriptionResponse.status),
397
402
  cancellation: subscriptionResponse.cancellation && toSubscriptionCancellation(subscriptionResponse.cancellation),
398
- items: subscriptionResponse.items.map((subscriptionItem) => ({
399
- id: subscriptionItem.id,
400
- planId: subscriptionItem.planId,
401
- })),
402
- trialEnd: subscriptionResponse.trialEnd ? new Date(subscriptionResponse.trialEnd) : null,
403
+ trialEnd: subscriptionResponse.trialEnd ? subscriptionResponse.trialEnd : null,
403
404
  },
404
405
  }
405
406
  : {})), (planResponse
@@ -416,34 +417,33 @@ function* loadSummaries(tenantId) {
416
417
  : {}))));
417
418
  }
418
419
  catch (e) {
419
- yield put(actions$6.setError(e.message));
420
+ yield put(actions$7.setError(e.message));
420
421
  }
421
422
  }
422
423
  function* cancelSubscription() {
423
- var _a;
424
- const overview = yield select((state) => state.subscriptions.billing.information);
425
- if (!overview.subscription) {
424
+ const { summary, subscription } = yield select((state) => state.subscriptions.billing.information);
425
+ if (!subscription) {
426
426
  return;
427
427
  }
428
- if ((_a = overview.summary) === null || _a === void 0 ? void 0 : _a.externallyManaged) {
429
- yield put(actions$6.setCancellationError('Billing is externally managed'));
428
+ if (summary === null || summary === void 0 ? void 0 : summary.externallyManaged) {
429
+ yield put(actions$7.setCancellationError('Billing is externally managed'));
430
430
  return;
431
431
  }
432
- const { id: subscriptionId, cancellation, status } = overview.subscription || {};
432
+ const { id: subscriptionId, cancellation, status } = subscription || {};
433
433
  const isCancellable = !cancellation && status === SubscriptionStatus.ACTIVE;
434
434
  if (isCancellable) {
435
435
  try {
436
- yield put(actions$6.setCancellationLoading(true));
436
+ yield put(actions$7.setCancellationLoading(true));
437
437
  yield call(api.subscriptions.cancelManagedSubscription, subscriptionId);
438
- yield put(actions$6.setState({
439
- subscription: Object.assign(Object.assign({}, overview.subscription), { cancellation: {
438
+ yield put(actions$7.setState({
439
+ subscription: Object.assign(Object.assign({}, subscription), { cancellation: {
440
440
  policy: SubscriptionCancellationPolicy.AT_PERIOD_END,
441
441
  } }),
442
442
  }));
443
- yield put(actions$6.setCancellationLoading(false));
443
+ yield put(actions$7.setCancellationLoading(false));
444
444
  }
445
445
  catch (e) {
446
- yield put(actions$6.setCancellationError(e.message));
446
+ yield put(actions$7.setCancellationError(e.message));
447
447
  }
448
448
  }
449
449
  }
@@ -454,22 +454,22 @@ function* renewSubscription() {
454
454
  return;
455
455
  }
456
456
  if ((_a = overview.summary) === null || _a === void 0 ? void 0 : _a.externallyManaged) {
457
- yield put(actions$6.setCancellationError('Billing is externally managed'));
457
+ yield put(actions$7.setCancellationError('Billing is externally managed'));
458
458
  return;
459
459
  }
460
460
  const { id: subscriptionId, cancellation } = overview.subscription || {};
461
461
  const renewable = (cancellation === null || cancellation === void 0 ? void 0 : cancellation.policy) === SubscriptionCancellationPolicy.AT_PERIOD_END;
462
462
  if (renewable) {
463
463
  try {
464
- yield put(actions$6.setRenewalLoading(true));
464
+ yield put(actions$7.setRenewalLoading(true));
465
465
  yield call(api.subscriptions.renewManagedSubscription, subscriptionId);
466
- yield put(actions$6.setState({
466
+ yield put(actions$7.setState({
467
467
  subscription: Object.assign(Object.assign({}, overview.subscription), { cancellation: null }),
468
468
  }));
469
- yield put(actions$6.setRenewalLoading(false));
469
+ yield put(actions$7.setRenewalLoading(false));
470
470
  }
471
471
  catch (e) {
472
- yield put(actions$6.setCancellationError(e.message));
472
+ yield put(actions$7.setCancellationError(e.message));
473
473
  }
474
474
  }
475
475
  }
@@ -482,14 +482,13 @@ function* checkoutEvent$2({ payload }) {
482
482
  * Preview Sagas
483
483
  *********************************/
484
484
  function* loadBillingInformationMock() {
485
- yield put(actions$6.setLoading(true));
486
485
  yield loadSummariesMock();
487
486
  }
488
487
  function* loadSummariesMock() {
489
488
  var _a, _b;
490
- yield put(actions$6.setLoading(true));
489
+ yield put(actions$7.setLoading(true));
491
490
  yield delay(500);
492
- yield put(actions$6.setState({
491
+ yield put(actions$7.setState({
493
492
  loading: false,
494
493
  fetching: false,
495
494
  summary: {
@@ -501,35 +500,35 @@ function* loadSummariesMock() {
501
500
  currentPlanId: planResponseMock[0].id,
502
501
  defaultPlanId: planResponseMock[0].id,
503
502
  },
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 }),
503
+ subscription: Object.assign(Object.assign({}, subscriptionResponseMock), { startDate: subscriptionResponseMock.startDate, currentPeriodStart: subscriptionResponseMock.currentPeriodStart, currentPeriodEnd: subscriptionResponseMock.currentPeriodEnd, status: toSubscriptionStatus(subscriptionResponseMock.status), cancellation: subscriptionResponseMock.cancellation && toSubscriptionCancellation(subscriptionResponseMock.cancellation), trialEnd: null }),
505
504
  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' }),
506
505
  }));
507
506
  }
508
507
  function* subscriptionBillingInformationSagasMock() {
509
- yield takeEvery(actions$6.loadBillingInformation, loadBillingInformationMock);
508
+ yield takeEvery(actions$7.loadBillingInformation, loadBillingInformationMock);
510
509
  }
511
510
 
512
511
  function* subscriptionsPaymentMethodSagas() {
513
- yield takeEvery(actions$5.loadPaymentMethod, loadPaymentMethod);
514
- yield takeEvery(actions$5.submitPaymentMethod, submitPaymentMethod);
515
- yield takeEvery(actions$5.submitPaymentMethodError, submitPaymentMethodError);
516
- yield takeEvery(actions$5.submitPaymentMethodSuccess, submitPaymentMethodSuccess);
517
- yield takeEvery(actions$5.updatePaymentMethodBillingDetails, updateBillingDetails);
512
+ yield takeEvery(actions$6.loadPaymentMethod, loadPaymentMethod);
513
+ yield takeEvery(actions$6.submitPaymentMethod, submitPaymentMethod);
514
+ yield takeEvery(actions$6.submitPaymentMethodError, submitPaymentMethodError);
515
+ yield takeEvery(actions$6.submitPaymentMethodSuccess, submitPaymentMethodSuccess);
516
+ yield takeEvery(actions$6.updatePaymentMethodBillingDetails, updateBillingDetails);
518
517
  yield takeEvery(actions$3.checkoutEvent, checkoutEvent$1);
519
518
  }
520
519
  function* loadPaymentMethod() {
521
- yield put(actions$5.setLoading(true));
520
+ yield put(actions$6.setLoading(true));
522
521
  try {
523
522
  const paymentMethods = yield call(api.subscriptions.getPaymentMethods);
524
523
  const paymentMethod = paymentMethods[0];
525
- yield put(actions$5.setState({
524
+ yield put(actions$6.setState({
526
525
  paymentMethod,
527
526
  loading: false,
528
527
  fetching: false,
529
528
  }));
530
529
  }
531
530
  catch (e) {
532
- yield put(actions$5.setError(e.message));
531
+ yield put(actions$6.setError(e.message));
533
532
  }
534
533
  }
535
534
  function* checkoutEvent$1({ payload }) {
@@ -538,7 +537,7 @@ function* checkoutEvent$1({ payload }) {
538
537
  }
539
538
  }
540
539
  function* updateBillingDetails({ payload, }) {
541
- yield put(actions$5.setLoading(true));
540
+ yield put(actions$6.setLoading(true));
542
541
  const { id, email, address, callback } = payload;
543
542
  try {
544
543
  yield call(api.subscriptions.updatePaymentMethodBillingDetails, id, Object.assign({ email }, address));
@@ -546,44 +545,44 @@ function* updateBillingDetails({ payload, }) {
546
545
  callback === null || callback === void 0 ? void 0 : callback(true);
547
546
  }
548
547
  catch (e) {
549
- yield put(actions$5.setError(e.message));
548
+ yield put(actions$6.setError(e.message));
550
549
  callback === null || callback === void 0 ? void 0 : callback(false);
551
550
  }
552
- yield put(actions$5.setLoading(false));
551
+ yield put(actions$6.setLoading(false));
553
552
  }
554
553
  function* submitPaymentMethod() {
555
- yield put(actions$5.setLoading(true));
554
+ yield put(actions$6.setLoading(true));
556
555
  }
557
556
  function* submitPaymentMethodError({ payload: error }) {
558
- yield put(actions$5.setError(error));
557
+ yield put(actions$6.setError(error));
559
558
  }
560
559
  function* submitPaymentMethodSuccess() {
561
- yield put(actions$5.loadPaymentMethod());
560
+ yield put(actions$6.loadPaymentMethod());
562
561
  }
563
562
  /*********************************
564
563
  * Preview Sagas
565
564
  *********************************/
566
565
  function* loadPaymentMethodMock() {
567
- yield put(actions$5.setLoading(true));
566
+ yield put(actions$6.setLoading(true));
568
567
  yield delay(500);
569
568
  const paymentMethod = paymentMethodsMock[0];
570
- yield put(actions$5.setState({
569
+ yield put(actions$6.setState({
571
570
  paymentMethod,
572
571
  loading: false,
573
572
  fetching: false,
574
573
  }));
575
574
  }
576
575
  function* subscriptionsPaymentMethodSagasMock() {
577
- yield takeEvery(actions$5.loadPaymentMethod, loadPaymentMethodMock);
576
+ yield takeEvery(actions$6.loadPaymentMethod, loadPaymentMethodMock);
578
577
  }
579
578
 
580
579
  function* subscriptionInvoicesSagas() {
581
- yield takeEvery(actions$4.loadInvoices, loadInvoices);
582
- yield takeEvery(actions$4.downloadInvoice, downloadInvoice);
580
+ yield takeEvery(actions$5.loadInvoices, loadInvoices);
581
+ yield takeEvery(actions$5.downloadInvoice, downloadInvoice);
583
582
  yield takeEvery(actions$3.checkoutEvent, checkoutEvent);
584
583
  }
585
584
  function* loadInvoices() {
586
- yield put(actions$4.setLoading(true));
585
+ yield put(actions$5.setLoading(true));
587
586
  try {
588
587
  const responseInvoices = yield call(api.subscriptions.getSubscriptionInvoices);
589
588
  const invoices = responseInvoices.map((invoice) => ({
@@ -596,24 +595,24 @@ function* loadInvoices() {
596
595
  paid: invoice.paid || false,
597
596
  receiptNumber: invoice.receiptNumber,
598
597
  }));
599
- yield put(actions$4.setState({
598
+ yield put(actions$5.setState({
600
599
  loading: false,
601
600
  fetching: false,
602
601
  invoices,
603
602
  }));
604
603
  }
605
604
  catch (e) {
606
- yield put(actions$4.setError(e.message));
605
+ yield put(actions$5.setError(e.message));
607
606
  }
608
607
  }
609
608
  function* downloadInvoice({ payload }) {
610
- yield put(actions$4.setInvoiceDownloadState({ loading: true, error: null }));
609
+ yield put(actions$5.setInvoiceDownloadState({ loading: true, error: null }));
611
610
  try {
612
611
  yield call(api.subscriptions.getSubscriptionInvoicePdf, payload.invoiceId, payload.filename);
613
- yield put(actions$4.setInvoiceDownloadState({ loading: false, error: null }));
612
+ yield put(actions$5.setInvoiceDownloadState({ loading: false, error: null }));
614
613
  }
615
614
  catch (e) {
616
- yield put(actions$4.setInvoiceDownloadState({ loading: false, error: e.message || null }));
615
+ yield put(actions$5.setInvoiceDownloadState({ loading: false, error: e.message || null }));
617
616
  }
618
617
  }
619
618
  function* checkoutEvent({ payload }) {
@@ -625,18 +624,35 @@ function* checkoutEvent({ payload }) {
625
624
  * Preview Sagas
626
625
  *********************************/
627
626
  function* loadInvoicesMock() {
628
- yield put(actions$4.setLoading(true));
627
+ yield put(actions$5.setLoading(true));
629
628
  yield delay(500);
630
629
  const selectPlanTitle = 'Premium';
631
- yield put(actions$4.setState({
630
+ yield put(actions$5.setState({
632
631
  loading: false,
633
632
  fetching: false,
634
633
  invoices: invoicesMock.map((invoice) => (Object.assign(Object.assign({}, invoice), { selectedPlan: selectPlanTitle, paymentDate: new Date(Date.parse(invoice.paymentDate)), totalAmount: +((invoice.totalAmount || 0) / 100).toFixed(2) }))),
635
634
  }));
636
- yield put(actions$4.setLoading(false));
635
+ yield put(actions$5.setLoading(false));
637
636
  }
638
637
  function* subscriptionInvoicesSagasMock() {
639
- yield takeEvery(actions$4.loadInvoices, loadInvoicesMock);
638
+ yield takeEvery(actions$5.loadInvoices, loadInvoicesMock);
639
+ }
640
+
641
+ function* subscriptionSagas() {
642
+ yield takeEvery(actions$4.load, loadSubscription);
643
+ }
644
+ function* loadSubscription() {
645
+ const profile = yield select((state) => { var _a, _b; return (_b = (_a = state.auth) === null || _a === void 0 ? void 0 : _a.profileState) === null || _b === void 0 ? void 0 : _b.profile; });
646
+ yield loadSummaries(profile.tenantId);
647
+ }
648
+ /*********************************
649
+ * Preview Sagas
650
+ *********************************/
651
+ function* loadMock() {
652
+ yield loadSummariesMock();
653
+ }
654
+ function* subscriptionSagasMock() {
655
+ yield takeEvery(actions$4.load, loadMock);
640
656
  }
641
657
 
642
658
  function* billingSagas() {
@@ -644,6 +660,7 @@ function* billingSagas() {
644
660
  call(subscriptionBillingInformationSagas),
645
661
  call(subscriptionsPaymentMethodSagas),
646
662
  call(subscriptionInvoicesSagas),
663
+ call(subscriptionSagas),
647
664
  ]);
648
665
  }
649
666
  function* billingSagasMock() {
@@ -651,6 +668,7 @@ function* billingSagasMock() {
651
668
  call(subscriptionBillingInformationSagasMock),
652
669
  call(subscriptionsPaymentMethodSagasMock),
653
670
  call(subscriptionInvoicesSagasMock),
671
+ call(subscriptionSagasMock),
654
672
  ]);
655
673
  }
656
674
 
@@ -663,18 +681,6 @@ function* checkoutSagas() {
663
681
  yield takeEvery(actions$3.errorCheckout, errorCheckout);
664
682
  }
665
683
  function* checkoutPlan({ payload: planId }) {
666
- const { subscription, summary } = yield select((state) => state.subscriptions.billing.information);
667
- const isTrialing = (subscription === null || subscription === void 0 ? void 0 : subscription.trialEnd) || (subscription === null || subscription === void 0 ? void 0 : subscription.status) === SubscriptionStatus.TRIALING;
668
- const hasPaymentMethod = !!(summary === null || summary === void 0 ? void 0 : summary.paymentMethodId);
669
- if (isTrialing && hasPaymentMethod) {
670
- yield put(actions$3.setState({
671
- checkoutPlanId: null,
672
- loading: false,
673
- status: CheckoutStatus.CONFIRM,
674
- }));
675
- yield put(actions$3.checkoutEvent(CheckoutEvent.CONFIRMED));
676
- return;
677
- }
678
684
  yield put(actions$3.setState({
679
685
  checkoutPlanId: planId,
680
686
  loading: false,
@@ -690,18 +696,29 @@ function* resetCheckout() {
690
696
  }));
691
697
  }
692
698
  function* confirmPlan({ payload: paymentMethodId }) {
693
- const { subscription, status, planId } = yield select(({ subscriptions: { billing: { information }, checkout, }, }) => ({
694
- subscription: information.subscription,
695
- status: checkout.status,
696
- planId: checkout.checkoutPlanId,
699
+ const { checkout: { status, checkoutPlanId, }, subscription, summary } = yield select(({ subscriptions: { billing: { information: { summary, subscription } }, checkout, }, }) => ({
700
+ subscription,
701
+ summary,
702
+ checkout,
697
703
  }));
698
- if (!planId || !subscription) {
704
+ const isTrialing = (subscription === null || subscription === void 0 ? void 0 : subscription.trialEnd) || (subscription === null || subscription === void 0 ? void 0 : subscription.status) === SubscriptionStatus.TRIALING;
705
+ const hasPaymentMethod = !!(summary === null || summary === void 0 ? void 0 : summary.paymentMethodId);
706
+ if (!checkoutPlanId || !subscription) {
699
707
  yield put(actions$3.setState({
700
708
  loading: false,
701
709
  status: CheckoutStatus.ERROR,
702
710
  }));
703
711
  return;
704
712
  }
713
+ if (isTrialing && hasPaymentMethod) {
714
+ yield put(actions$3.setState({
715
+ checkoutPlanId: null,
716
+ loading: false,
717
+ status: CheckoutStatus.CONFIRM,
718
+ }));
719
+ yield put(actions$3.checkoutEvent(CheckoutEvent.CONFIRMED));
720
+ return;
721
+ }
705
722
  if (status === CheckoutStatus.CHECKOUT) {
706
723
  yield put(actions$3.setState({
707
724
  loading: true,
@@ -710,7 +727,7 @@ function* confirmPlan({ payload: paymentMethodId }) {
710
727
  try {
711
728
  yield call(api.subscriptions.updateManagedSubscription, subscription.id, {
712
729
  paymentMethodId,
713
- planId,
730
+ planId: checkoutPlanId,
714
731
  });
715
732
  yield put(actions$3.setState({
716
733
  checkoutPlanId: null,
@@ -772,10 +789,10 @@ function* checkoutSagasMock() {
772
789
  }
773
790
 
774
791
  function* plansSagas() {
775
- yield takeEvery(actions$8.loadPlans, loadPlans);
792
+ yield takeEvery(actions$9.loadPlans, loadPlans);
776
793
  }
777
794
  function* loadPlans() {
778
- yield put(actions$8.setLoading(true));
795
+ yield put(actions$9.setLoading(true));
779
796
  try {
780
797
  const products = yield call(api.subscriptions.getSubscriptionPlans);
781
798
  const plans = products.map((item) => {
@@ -784,38 +801,38 @@ function* loadPlans() {
784
801
  id: item.id,
785
802
  name: item.name,
786
803
  description: item.description,
787
- price: +((((_a = item.price) === null || _a === void 0 ? void 0 : _a.amount) || 0) / 100).toFixed(2),
804
+ price: ((_a = item.price) === null || _a === void 0 ? void 0 : _a.amount) || 0,
788
805
  currency: ((_b = item.price) === null || _b === void 0 ? void 0 : _b.currency) || 'usd',
789
806
  recurringInterval: 'month',
790
807
  });
791
808
  });
792
- yield put(actions$8.setState({
809
+ yield put(actions$9.setState({
793
810
  fetching: false,
794
811
  loading: false,
795
812
  plans,
796
813
  }));
797
814
  }
798
815
  catch (e) {
799
- yield put(actions$8.setError(e.message));
816
+ yield put(actions$9.setError(e.message));
800
817
  }
801
818
  }
802
819
  /*********************************
803
820
  * Preview Sagas
804
821
  *********************************/
805
822
  function* loadPlansMock() {
806
- yield put(actions$8.setLoading(true));
823
+ yield put(actions$9.setLoading(true));
807
824
  yield delay(500);
808
- yield put(actions$8.setState({
825
+ yield put(actions$9.setState({
809
826
  fetching: false,
810
827
  loading: false,
811
828
  plans: planResponseMock.map((item) => {
812
829
  var _a, _b;
813
- 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' }));
830
+ 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' }));
814
831
  }),
815
832
  }));
816
833
  }
817
834
  function* plansSagasMock() {
818
- yield takeEvery(actions$8.loadPlans, loadPlansMock);
835
+ yield takeEvery(actions$9.loadPlans, loadPlansMock);
819
836
  }
820
837
 
821
838
  var PaymentMethodType;
@@ -825,10 +842,10 @@ var PaymentMethodType;
825
842
  })(PaymentMethodType || (PaymentMethodType = {}));
826
843
 
827
844
  function* configSagas() {
828
- yield takeEvery(actions$7.loadPaymentConfiguration, loadPaymentConfiguration);
845
+ yield takeEvery(actions$8.loadPaymentConfiguration, loadPaymentConfiguration);
829
846
  }
830
847
  function* loadPaymentConfiguration() {
831
- yield put(actions$7.setLoading(true));
848
+ yield put(actions$8.setLoading(true));
832
849
  try {
833
850
  const response = yield call(api.subscriptions.getPaymentProviders) || [];
834
851
  const stripePaymentProvider = response.find((paymentProvider) => paymentProvider.status === '1' && paymentProvider.providerType === ProviderType.Stripe);
@@ -836,18 +853,18 @@ function* loadPaymentConfiguration() {
836
853
  yield loadStripePaymentConfiguration();
837
854
  }
838
855
  else {
839
- yield put(actions$7.setError('Payment provider not configured'));
856
+ yield put(actions$8.setError('Payment provider not configured'));
840
857
  }
841
858
  }
842
859
  catch (e) {
843
- yield put(actions$7.setError(e.message));
860
+ yield put(actions$8.setError(e.message));
844
861
  }
845
862
  }
846
863
  function* loadStripePaymentConfiguration() {
847
- yield put(actions$7.setLoading(true));
864
+ yield put(actions$8.setLoading(true));
848
865
  try {
849
866
  const response = yield call(api.subscriptions.getStripePaymentProviderConfiguration);
850
- yield put(actions$7.setState({
867
+ yield put(actions$8.setState({
851
868
  loading: false,
852
869
  fetching: false,
853
870
  config: {
@@ -857,16 +874,16 @@ function* loadStripePaymentConfiguration() {
857
874
  }));
858
875
  }
859
876
  catch (e) {
860
- yield put(actions$7.setError(e.message));
877
+ yield put(actions$8.setError(e.message));
861
878
  }
862
879
  }
863
880
  /*********************************
864
881
  * Preview Sagas
865
882
  *********************************/
866
883
  function* loadPaymentConfigurationMock() {
867
- yield put(actions$7.setLoading(true));
884
+ yield put(actions$8.setLoading(true));
868
885
  yield delay(500);
869
- yield put(actions$7.setState({
886
+ yield put(actions$8.setState({
870
887
  loading: false,
871
888
  fetching: false,
872
889
  config: {
@@ -876,25 +893,27 @@ function* loadPaymentConfigurationMock() {
876
893
  }));
877
894
  }
878
895
  function* configSagasMock() {
879
- yield takeEvery(actions$7.loadPaymentConfiguration, loadPaymentConfigurationMock);
896
+ yield takeEvery(actions$8.loadPaymentConfiguration, loadPaymentConfigurationMock);
880
897
  }
881
898
 
882
899
  function* subscriptionStripeSagas() {
883
900
  yield takeEvery(actions$2.createCardSetupIntentSecret, createCardSetupIntentSecret);
884
901
  }
885
902
  function* createCardSetupIntentSecret({ payload }) {
886
- yield put(actions$2.setStripeState({
903
+ yield put(actions$2.setState({
887
904
  loading: true,
888
905
  error: null,
889
- cardSetupIntentSecret: null
906
+ cardSetupIntentSecret: null,
890
907
  }));
891
908
  try {
892
- const { setupIntentSecret } = yield call(api.subscriptions.createStripePaymentMethodSetupIntentSecret, {
893
- paymentMethodId: payload || undefined
894
- });
895
- yield put(actions$2.setStripeState({
909
+ const request = {};
910
+ if (payload) {
911
+ request.paymentMethodId = payload;
912
+ }
913
+ const { setupIntentSecret } = yield call(api.subscriptions.createStripePaymentMethodSetupIntentSecret, request);
914
+ yield put(actions$2.setState({
896
915
  cardSetupIntentSecret: setupIntentSecret,
897
- loading: false
916
+ loading: false,
898
917
  }));
899
918
  }
900
919
  catch (e) {