From 2bc263fcfba29b4530eea28694be4751508072de Mon Sep 17 00:00:00 2001 From: tomivm Date: Wed, 8 Feb 2023 18:42:42 -0300 Subject: [PATCH 1/5] Create redux stuff's to update is on trial period state --- .../SubscriptionProvider.actions.js | 29 +++++++++++++++++++ .../SubscriptionProvider.constants.js | 1 + .../SubscriptionProvider.reducer.js | 6 ++++ 3 files changed, 36 insertions(+) diff --git a/src/providers/SubscriptionProvider/SubscriptionProvider.actions.js b/src/providers/SubscriptionProvider/SubscriptionProvider.actions.js index 41fc4723f..c78269efc 100644 --- a/src/providers/SubscriptionProvider/SubscriptionProvider.actions.js +++ b/src/providers/SubscriptionProvider/SubscriptionProvider.actions.js @@ -1,4 +1,6 @@ +import { isAndroid } from '../../cordova-util'; import { + UPDATE_IS_ON_TRIAL_PERIOD, UPDATE_ANDROID_SUBSCRIPTION_STATE, UPDATE_SUBSCRIBER_ID, UPDATE_IS_SUBSCRIBED, @@ -12,6 +14,33 @@ import { ACTIVE } from './SubscriptionProvider.constants'; +export function updateIsOnTrialPeriod() { + return (dispatch, getState) => { + const userCreatedAt = getState().app.userData.createdAt; + const { isSubscribed } = getState().subscription; + const isOnTrialPeriod = isUserOnTrialPeriod(userCreatedAt); + dispatch({ + type: UPDATE_IS_ON_TRIAL_PERIOD, + isOnTrialPeriod + }); + + if (!isOnTrialPeriod && !isSubscribed) + dispatch(showPremiumRequired({ showTryPeriodFinishedMessages: true })); + + function isUserOnTrialPeriod(createdAt) { + const createdAtDate = new Date(createdAt); + const actualDate = new Date(); + const DAYS_TO_TRY = 30; + const tryLimitDate = createdAtDate.setDate( + createdAtDate.getDate() + DAYS_TO_TRY + ); + if (!createdAt) return false; //this case are already created users + if (actualDate >= tryLimitDate) return false; + return true; + } + }; +} + export function updateAndroidSubscriptionState(payload = {}) { return { type: UPDATE_ANDROID_SUBSCRIPTION_STATE, diff --git a/src/providers/SubscriptionProvider/SubscriptionProvider.constants.js b/src/providers/SubscriptionProvider/SubscriptionProvider.constants.js index d089c04bf..07852a1f2 100644 --- a/src/providers/SubscriptionProvider/SubscriptionProvider.constants.js +++ b/src/providers/SubscriptionProvider/SubscriptionProvider.constants.js @@ -1,3 +1,4 @@ +export const UPDATE_IS_ON_TRIAL_PERIOD = 'UPDATE_IS_ON_TRIAL_PERIOD'; export const UPDATE_ANDROID_SUBSCRIPTION_STATE = 'cboard/subscription/UPDATE_ANDROID_SUBSCRIPTION_STATE'; export const UPDATE_SUBSCRIBER_ID = 'cboard/subscription/UPDATE_SUBSCRIBER_ID'; diff --git a/src/providers/SubscriptionProvider/SubscriptionProvider.reducer.js b/src/providers/SubscriptionProvider/SubscriptionProvider.reducer.js index 2724bfdfd..e6a7d25c1 100644 --- a/src/providers/SubscriptionProvider/SubscriptionProvider.reducer.js +++ b/src/providers/SubscriptionProvider/SubscriptionProvider.reducer.js @@ -1,4 +1,5 @@ import { + UPDATE_IS_ON_TRIAL_PERIOD, UPDATE_ANDROID_SUBSCRIPTION_STATE, UPDATE_SUBSCRIBER_ID, UPDATE_IS_SUBSCRIBED, @@ -28,6 +29,11 @@ const initialState = { function subscriptionProviderReducer(state = initialState, action) { switch (action.type) { + case UPDATE_IS_ON_TRIAL_PERIOD: + return { + ...state, + isOnTrialPeriod: action.isOnTrialPeriod + }; case UPDATE_ANDROID_SUBSCRIPTION_STATE: return { ...state, From b8bc9600e31b98ee3f0aef33760ee2d202f798c9 Mon Sep 17 00:00:00 2001 From: tomivm Date: Wed, 8 Feb 2023 18:48:06 -0300 Subject: [PATCH 2/5] Update is on trial period from subscription provider --- .../SubscriptionProvider.container.js | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/providers/SubscriptionProvider/SubscriptionProvider.container.js b/src/providers/SubscriptionProvider/SubscriptionProvider.container.js index 10ff2ee78..ab84a0f51 100644 --- a/src/providers/SubscriptionProvider/SubscriptionProvider.container.js +++ b/src/providers/SubscriptionProvider/SubscriptionProvider.container.js @@ -9,10 +9,12 @@ import { updateAndroidSubscriptionState, updateIsSubscribed, updateSubscription, - comprobeSubscription + comprobeSubscription, + updateIsOnTrialPeriod } from './SubscriptionProvider.actions'; import { onAndroidResume } from '../../cordova-util'; import { NOT_SUBSCRIBED, PROCCESING } from './SubscriptionProvider.constants'; +import { isLogged } from '../../components/App/App.selectors'; export class SubscriptionProvider extends Component { static propTypes = { @@ -21,15 +23,34 @@ export class SubscriptionProvider extends Component { componentDidMount() { const { isSubscribed, comprobeSubscription } = this.props; + + const manageTrialPeriod = () => { + const { isLogged, updateIsOnTrialPeriod } = this.props; + if (isLogged) { + updateIsOnTrialPeriod(); + } + }; + if (isAndroid()) { this.configInAppPurchasePlugin(); if (isSubscribed) { comprobeSubscription(); } onAndroidResume(() => comprobeSubscription()); + manageTrialPeriod(); } } + componentDidUpdate = prevProps => { + if (isAndroid()) { + const { isLogged, isOnTrialPeriod, updateIsOnTrialPeriod } = this.props; + if (!prevProps.isLogged && isLogged) + if (isOnTrialPeriod === undefined || isOnTrialPeriod) { + updateIsOnTrialPeriod(); + } + } + }; + configPurchaseValidator = () => { let count = 1; window.CdvPurchase.store.validator = async function(receipt, callback) { @@ -120,14 +141,17 @@ export class SubscriptionProvider extends Component { const mapStateToProps = state => ({ isSubscribed: state.subscription.isSubscribed, expiryDate: state.subscription.expiryDate, - androidSubscriptionState: state.subscription.androidSubscriptionState + androidSubscriptionState: state.subscription.androidSubscriptionState, + isOnTrialPeriod: state.subscription.isOnTrialPeriod, + isLogged: isLogged(state) }); const mapDispatchToProps = { updateAndroidSubscriptionState, updateIsSubscribed, updateSubscription, - comprobeSubscription + comprobeSubscription, + updateIsOnTrialPeriod }; export default connect( From 32fc75049d688a2c832c61569db03ff15131486b Mon Sep 17 00:00:00 2001 From: tomivm Date: Wed, 8 Feb 2023 19:56:23 -0300 Subject: [PATCH 3/5] Prevent show a wrong message during close PremiumRequiredModal --- .../SubscriptionProvider/SubscriptionProvider.reducer.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/providers/SubscriptionProvider/SubscriptionProvider.reducer.js b/src/providers/SubscriptionProvider/SubscriptionProvider.reducer.js index e6a7d25c1..d0cdb0f34 100644 --- a/src/providers/SubscriptionProvider/SubscriptionProvider.reducer.js +++ b/src/providers/SubscriptionProvider/SubscriptionProvider.reducer.js @@ -86,7 +86,8 @@ function subscriptionProviderReducer(state = initialState, action) { ...state, premiumRequiredModalState: { open: false, - showTryPeriodFinishedMessages: false + showTryPeriodFinishedMessages: + state.premiumRequiredModalState.showTryPeriodFinishedMessages } }; default: From 4d0cfdf720074ee4723cfe67305cf044f90c08f5 Mon Sep 17 00:00:00 2001 From: tomivm Date: Thu, 9 Feb 2023 10:16:24 -0300 Subject: [PATCH 4/5] remove unnecessary import of isAndroid --- .../SubscriptionProvider/SubscriptionProvider.actions.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/providers/SubscriptionProvider/SubscriptionProvider.actions.js b/src/providers/SubscriptionProvider/SubscriptionProvider.actions.js index c78269efc..a976fba35 100644 --- a/src/providers/SubscriptionProvider/SubscriptionProvider.actions.js +++ b/src/providers/SubscriptionProvider/SubscriptionProvider.actions.js @@ -1,4 +1,3 @@ -import { isAndroid } from '../../cordova-util'; import { UPDATE_IS_ON_TRIAL_PERIOD, UPDATE_ANDROID_SUBSCRIPTION_STATE, From c54091d47906f00a575eb7eedaf46bc2829d2d16 Mon Sep 17 00:00:00 2001 From: tomivm Date: Thu, 9 Feb 2023 18:08:07 -0300 Subject: [PATCH 5/5] Return false on first line of isUserOnTrialPeriod if is an old user --- .../SubscriptionProvider/SubscriptionProvider.actions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/providers/SubscriptionProvider/SubscriptionProvider.actions.js b/src/providers/SubscriptionProvider/SubscriptionProvider.actions.js index a976fba35..f88b57566 100644 --- a/src/providers/SubscriptionProvider/SubscriptionProvider.actions.js +++ b/src/providers/SubscriptionProvider/SubscriptionProvider.actions.js @@ -27,13 +27,13 @@ export function updateIsOnTrialPeriod() { dispatch(showPremiumRequired({ showTryPeriodFinishedMessages: true })); function isUserOnTrialPeriod(createdAt) { + if (!createdAt) return false; //this case are already created users const createdAtDate = new Date(createdAt); const actualDate = new Date(); const DAYS_TO_TRY = 30; const tryLimitDate = createdAtDate.setDate( createdAtDate.getDate() + DAYS_TO_TRY ); - if (!createdAt) return false; //this case are already created users if (actualDate >= tryLimitDate) return false; return true; }