Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

fix subscription flow on iOS

ammarahm-edc495a15f81eb
diff --git a/apps/mobile/AppRootEvents.js b/apps/mobile/AppRootEvents.js
index 6b677812b..0153b72e7 100644
--- a/apps/mobile/AppRootEvents.js
+++ b/apps/mobile/AppRootEvents.js
@@ -289,10 +289,7 @@ export const AppRootEvents = React.memo(
};
const onAccountStatusChange = async (userStatus) => {
- console.log('STATUS CODE', userStatus);
-
if (!PremiumService.get() && userStatus.type === 5) {
- console.log('STATUS CODE IN', userStatus.type);
eSendEvent(eOpenProgressDialog, {
title: 'Notesnook Pro',
paragraph: `Your Notesnook Pro subscription has been successfully activated.`,
@@ -354,7 +351,6 @@ export const AppRootEvents = React.memo(
const setCurrentUser = async () => {
try {
let user = await db.user.fetchUser(true);
-
if (user) {
attachIAPListeners();
clearMessage(dispatch);
@@ -364,7 +360,6 @@ export const AppRootEvents = React.memo(
setEmailVerifyMessage(dispatch);
return;
}
- console.log('RUNNING SYNC');
await Sync.run();
} else {
await PremiumService.setPremiumStatus();
@@ -384,9 +379,8 @@ export const AppRootEvents = React.memo(
const onSuccessfulSubscription = async (subscription) => {
const receipt = subscription.transactionReceipt;
-
+ console.log(receipt);
if (prevTransactionId === subscription.transactionId) {
- console.log('returning same ID');
return;
}
await processReceipt(receipt);
@@ -407,6 +401,7 @@ export const AppRootEvents = React.memo(
};
const processReceipt = async (receipt) => {
+ console.log(receipt);
if (receipt) {
if (Platform.OS === 'ios') {
let user = await db.user.getUser();
@@ -422,6 +417,7 @@ export const AppRootEvents = React.memo(
},
})
.then(async (r) => {
+ if (!r.ok) return;
let text = await r.text();
if (text === 'Receipt already expired.') {
await RNIap.clearTransactionIOS();
diff --git a/apps/mobile/src/components/Premium/PremiumComponent.js b/apps/mobile/src/components/Premium/PremiumComponent.js
index 7f0dc804d..dffd18144 100644
--- a/apps/mobile/src/components/Premium/PremiumComponent.js
+++ b/apps/mobile/src/components/Premium/PremiumComponent.js
@@ -20,9 +20,14 @@ import {eSendEvent} from '../../services/EventManager';
import PremiumService from '../../services/PremiumService';
import {dWidth, itemSkus} from '../../utils';
import {db} from '../../utils/DB';
-import {eOpenLoginDialog} from '../../utils/Events';
+import {
+ eCloseProgressDialog,
+ eOpenLoginDialog,
+ eOpenProgressDialog,
+} from '../../utils/Events';
import {openLinkInBrowser} from '../../utils/functions';
import {SIZE} from '../../utils/SizeUtils';
+import {sleep} from '../../utils/TimeUtils';
import {Button} from '../Button';
import {PressableButton} from '../PressableButton';
import {Toast} from '../Toast';
@@ -86,6 +91,7 @@ export const PremiumComponent = React.memo(
const [user, setUser] = useState(null);
const [product, setProduct] = useState(null);
const [products, setProducts] = useState([]);
+ const [buying, setBuying] = useState(false);
const scrollViewRef = useRef();
const getSkus = async () => {
@@ -111,12 +117,14 @@ export const PremiumComponent = React.memo(
}, []);
const buySubscription = async () => {
+ if (buying) return;
if (!user) {
close();
setTimeout(() => {
eSendEvent(eOpenLoginDialog);
}, 400);
} else {
+ setBuying(true);
RNIap.requestSubscription(
product?.productId,
false,
@@ -125,10 +133,23 @@ export const PremiumComponent = React.memo(
null,
user.id,
)
- .then((r) => {
+ .then(async (r) => {
+ setBuying(false);
close();
+ await sleep(1000);
+ eSendEvent(eOpenProgressDialog, {
+ title: 'Thank you for subscribing!',
+ paragraph: `Your Notesnook Pro subscription will be activated within a few hours. If your account is not upgraded to Notesnook Pro, your money will be refunded to you. In case of any issues, please reach out to us at [email protected]`,
+ action: async () => {
+ eSendEvent(eCloseProgressDialog);
+ },
+ icon: 'check',
+ actionText: 'Continue',
+ noProgress: true,
+ });
})
.catch((e) => {
+ setBuying(false);
console.log(e);
});
}
@@ -180,6 +201,7 @@ export const PremiumComponent = React.memo(
<Button
onPress={buySubscription}
fontSize={SIZE.lg}
+ loading={buying}
title={
user
? `Subscribe for ${product?.localizedPrice || '$4.49'} / Month`
diff --git a/apps/mobile/src/utils/index.js b/apps/mobile/src/utils/index.js
index 302681599..17d4c9b43 100755
--- a/apps/mobile/src/utils/index.js
+++ b/apps/mobile/src/utils/index.js
@@ -172,7 +172,7 @@ export const SUBSCRIPTION_PROVIDER = {
1: {
type: 'iOS',
title: 'Subscribed on iOS',
- desc: 'You subscribed to Notesnook Pro on iOS using Apple In App Purchase.',
+ desc: 'You subscribed to Notesnook Pro on iOS using Apple In App Purchase. You can cancel anytime with your iTunes Account settings.',
icon: 'ios',
},
2: {
diff --git a/apps/mobile/src/views/Settings/index.js b/apps/mobile/src/views/Settings/index.js
index a6b9806e1..63fe49abf 100644
--- a/apps/mobile/src/views/Settings/index.js
+++ b/apps/mobile/src/views/Settings/index.js
@@ -697,7 +697,7 @@ const SettingsUserSection = () => {
</View>
) : null}
- {!user.isEmailConfirmed &&
+ {user.isEmailConfirmed &&
user.subscription.type !== 5 &&
user.subscription.type !== 2 && (
<>
@@ -710,13 +710,18 @@ const SettingsUserSection = () => {
fontSize={SIZE.md}
title={
user.subscription.type === 6
- ? 'Resubscribe to Notesnook Pro'
+ ? `Resubscribe to Notesnook Pro (${
+ PremiumService.getProducts().length > 0
+ ? PremiumService.getProducts()[0]
+ .localizedPrice
+ : '$4.49'
+ } / mo)`
: `Subscribe to Notesnook Pro (${
PremiumService.getProducts().length > 0
? PremiumService.getProducts()[0]
.localizedPrice
: '$4.49'
- } / Month)`
+ } / mo)`
}
height={50}
type="transparent"
@@ -732,6 +737,7 @@ const SettingsUserSection = () => {
SUBSCRIPTION_PROVIDER[user?.subscription?.provider]?.title
}
onPress={() => {
+ console.log('opening');
eSendEvent(eOpenProgressDialog, {
title:
SUBSCRIPTION_PROVIDER[user?.subscription?.provider]
@@ -740,15 +746,13 @@ const SettingsUserSection = () => {
SUBSCRIPTION_PROVIDER[user?.subscription?.provider]
.desc,
noProgress: true,
- icon:
- SUBSCRIPTION_PROVIDER[user?.subscription?.provider]
- .icon,
});
}}
style={{
alignSelf: 'flex-end',
marginTop: 10,
borderRadius: 3,
+ zIndex: 10,
}}
fontSize={11}
textStyle={{
@@ -1100,7 +1104,7 @@ const SettingsPrivacyAndSecurity = () => {
settings.appLockMode === item.value ? 'accent' : 'transparent'
}
onPress={() => {
- SettingsService.set('appLockMode',item.value)
+ SettingsService.set('appLockMode', item.value);
}}
customStyle={{
justifyContent: 'flex-start',