@frontegg/redux-store 5.27.0 → 5.29.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.
@@ -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
  }
@@ -442,8 +437,8 @@ function* cancelSubscription() {
442
437
  if (isCancellable) {
443
438
  try {
444
439
  yield effects.put(actions$6.setCancellationLoading(true));
445
- yield effects.call(restApi.api.subscriptions.cancelSubscription, subscriptionId);
446
- yield effects.put(actions$6.setBillingInformation({
440
+ yield effects.call(restApi.api.subscriptions.cancelManagedSubscription, subscriptionId);
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
  }
@@ -469,8 +465,8 @@ function* renewSubscription() {
469
465
  if (renewable) {
470
466
  try {
471
467
  yield effects.put(actions$6.setRenewalLoading(true));
472
- yield effects.call(restApi.api.subscriptions.renewSubscription, subscriptionId);
473
- yield effects.put(actions$6.setBillingInformation({
468
+ yield effects.call(restApi.api.subscriptions.renewManagedSubscription, subscriptionId);
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() {
@@ -662,6 +666,18 @@ function* checkoutSagas() {
662
666
  yield effects.takeEvery(actions$3.errorCheckout, errorCheckout);
663
667
  }
664
668
  function* checkoutPlan({ payload: planId }) {
669
+ const { subscription, summary } = yield effects.select((state) => state.subscriptions.billing.information);
670
+ const isTrialing = (subscription === null || subscription === void 0 ? void 0 : subscription.trialEnd) || (subscription === null || subscription === void 0 ? void 0 : subscription.status) === exports.SubscriptionStatus.TRIALING;
671
+ const hasPaymentMethod = !!(summary === null || summary === void 0 ? void 0 : summary.paymentMethodId);
672
+ if (isTrialing && hasPaymentMethod) {
673
+ yield effects.put(actions$3.setState({
674
+ checkoutPlanId: null,
675
+ loading: false,
676
+ status: exports.CheckoutStatus.CONFIRM,
677
+ }));
678
+ yield effects.put(actions$3.checkoutEvent(exports.CheckoutEvent.CONFIRMED));
679
+ return;
680
+ }
665
681
  yield effects.put(actions$3.setState({
666
682
  checkoutPlanId: planId,
667
683
  loading: false,
@@ -698,7 +714,6 @@ function* confirmPlan({ payload: paymentMethodId }) {
698
714
  yield effects.call(restApi.api.subscriptions.updateManagedSubscription, subscription.id, {
699
715
  paymentMethodId,
700
716
  planId,
701
- items: []
702
717
  });
703
718
  yield effects.put(actions$3.setState({
704
719
  checkoutPlanId: null,
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@frontegg/redux-store",
3
3
  "libName": "FronteggReduxStore",
4
- "version": "5.27.0",
4
+ "version": "5.29.0",
5
5
  "author": "Frontegg LTD",
6
6
  "main": "./node/index.js",
7
7
  "module": "./index.js",
8
8
  "types": "./index.d.ts",
9
9
  "dependencies": {
10
- "@frontegg/rest-api": "2.10.60",
10
+ "@frontegg/rest-api": "2.10.61",
11
11
  "@reduxjs/toolkit": "^1.5.0",
12
12
  "redux-saga": "^1.1.0",
13
13
  "tslib": "^2.3.1",
@@ -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
  }
@@ -439,8 +434,8 @@ function* cancelSubscription() {
439
434
  if (isCancellable) {
440
435
  try {
441
436
  yield put(actions$6.setCancellationLoading(true));
442
- yield call(api.subscriptions.cancelSubscription, subscriptionId);
443
- yield put(actions$6.setBillingInformation({
437
+ yield call(api.subscriptions.cancelManagedSubscription, subscriptionId);
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
  }
@@ -466,8 +462,8 @@ function* renewSubscription() {
466
462
  if (renewable) {
467
463
  try {
468
464
  yield put(actions$6.setRenewalLoading(true));
469
- yield call(api.subscriptions.renewSubscription, subscriptionId);
470
- yield put(actions$6.setBillingInformation({
465
+ yield call(api.subscriptions.renewManagedSubscription, subscriptionId);
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() {
@@ -659,6 +663,18 @@ function* checkoutSagas() {
659
663
  yield takeEvery(actions$3.errorCheckout, errorCheckout);
660
664
  }
661
665
  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
+ }
662
678
  yield put(actions$3.setState({
663
679
  checkoutPlanId: planId,
664
680
  loading: false,
@@ -695,7 +711,6 @@ function* confirmPlan({ payload: paymentMethodId }) {
695
711
  yield call(api.subscriptions.updateManagedSubscription, subscription.id, {
696
712
  paymentMethodId,
697
713
  planId,
698
- items: []
699
714
  });
700
715
  yield put(actions$3.setState({
701
716
  checkoutPlanId: null,
@@ -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>;