Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage subscription on log in #1360

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -43,11 +43,27 @@ export class SubscriptionProvider extends Component {

componentDidUpdate = prevProps => {
if (isAndroid()) {
const { isLogged, isOnTrialPeriod, updateIsOnTrialPeriod } = this.props;
if (!prevProps.isLogged && isLogged)
const {
isLogged,
isOnTrialPeriod,
updateIsOnTrialPeriod,
subscriberId,
androidSubscriptionState,
comprobeSubscription
} = this.props;
if (!prevProps.isLogged && isLogged) {
if (!prevProps.subscriberId && subscriberId) {
const localTransaction = window.CdvPurchase.store.localTransactions;
if (
localTransaction.length ||
androidSubscriptionState !== NOT_SUBSCRIBED
)
comprobeSubscription();
}
if (isOnTrialPeriod === undefined || isOnTrialPeriod) {
updateIsOnTrialPeriod();
}
}
}
};

@@ -72,13 +88,12 @@ export class SubscriptionProvider extends Component {
code: e.data?.code, // **Validation error code
message: e.error.message
});
console.error(e);
return;
} else {
callback({
ok: false,
message: 'Impossible to proceed with validation, ' + e
});
}
callback({
ok: false,
message: 'Impossible to proceed with validation, ' + e
});
if (count < 3) {
setTimeout(() => {
window.CdvPurchase.store.verify(receipt);
@@ -97,7 +112,11 @@ export class SubscriptionProvider extends Component {
};

configInAppPurchasePlugin = () => {
const { updateSubscription, androidSubscriptionState } = this.props;
const {
updateSubscription,
androidSubscriptionState,
subscriberId
} = this.props;

this.configPurchaseValidator();

@@ -118,7 +137,7 @@ export class SubscriptionProvider extends Component {
})
.approved(receipt => {
console.log('Approved - receipt: ', receipt);
window.CdvPurchase.store.verify(receipt);
if (subscriberId) window.CdvPurchase.store.verify(receipt);
})
.verified(receipt => {
console.log('Verified - Receipt', receipt);
@@ -143,7 +162,8 @@ const mapStateToProps = state => ({
expiryDate: state.subscription.expiryDate,
androidSubscriptionState: state.subscription.androidSubscriptionState,
isOnTrialPeriod: state.subscription.isOnTrialPeriod,
isLogged: isLogged(state)
isLogged: isLogged(state),
subscriberId: state.subscription.subscriberId
});

const mapDispatchToProps = {
Original file line number Diff line number Diff line change
@@ -9,7 +9,10 @@ import {
HIDE_PREMIUM_REQUIRED,
NOT_SUBSCRIBED
} from './SubscriptionProvider.constants';
import { LOGOUT } from '../../components/Account/Login/Login.constants';
import {
LOGOUT,
LOGIN_SUCCESS
} from '../../components/Account/Login/Login.constants';

const initialState = {
subscriberId: '',
@@ -72,6 +75,20 @@ function subscriptionProviderReducer(state = initialState, action) {
message: message
}
};
case LOGIN_SUCCESS:
const subscriber = action.payload.subscriber || {};
const {
id = '',
status = NOT_SUBSCRIBED,
expiryDate: expiry = null
} = subscriber;

return {
...state,
subscriberId: id,
androidSubscriptionState: status,
expiryDate: expiry
};
case LOGOUT:
return initialState;
case SHOW_PREMIUM_REQUIRED: