Skip to content

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

feat: regional pricing

ammarahm-edf9f094ff4779
diff --git a/apps/mobile/src/components/premium/component.js b/apps/mobile/src/components/premium/component.js
index f6cf14cc7..4db72337a 100644
--- a/apps/mobile/src/components/premium/component.js
+++ b/apps/mobile/src/components/premium/component.js
@@ -1,5 +1,5 @@
import React, { useState } from 'react';
-import { ScrollView, View } from 'react-native';
+import { ActivityIndicator, ScrollView, View } from 'react-native';
import { LAUNCH_ROCKET } from '../../assets/images/assets';
import { useThemeStore } from '../../stores/theme';
import { useUserStore } from '../../stores/stores';
@@ -30,6 +30,7 @@ import { Walkthrough } from '../walkthroughs';
import { features } from './features';
import { Group } from './group';
import { PricingPlans } from './pricing-plans';
+import { usePricing } from '../../utils/hooks/use-pricing';
export const Component = ({ close, promo, getRef }) => {
const colors = useThemeStore(state => state.colors);
@@ -37,6 +38,7 @@ export const Component = ({ close, promo, getRef }) => {
const userCanRequestTrial =
user && (!user.subscription || !user.subscription.expiry) ? true : false;
const [floatingButton, setFloatingButton] = useState(false);
+ const pricing = usePricing('monthly');
const onPress = async () => {
if (user) {
@@ -58,7 +60,6 @@ export const Component = ({ close, promo, getRef }) => {
let contentSize = event.nativeEvent.contentSize.height;
contentSize = contentSize - event.nativeEvent.layoutMeasurement.height;
let yOffset = event.nativeEvent.contentOffset.y;
-
if (yOffset > 600 && yOffset < contentSize - 400) {
setFloatingButton(true);
} else {
@@ -97,6 +98,7 @@ export const Component = ({ close, promo, getRef }) => {
style={{
paddingHorizontal: DDS.isTab ? DDS.width / 5 : 0
}}
+ scrollEventThrottle={0}
keyboardDismissMode="none"
keyboardShouldPersistTaps="always"
onScroll={onScroll}
@@ -127,15 +129,26 @@ export const Component = ({ close, promo, getRef }) => {
</Heading>
</Heading>
- <Paragraph
- style={{
- alignSelf: 'center',
- marginBottom: 20
- }}
- size={SIZE.md}
- >
- ({PremiumService.getMontlySub().localizedPrice} / mo)
- </Paragraph>
+ {!pricing ? (
+ <ActivityIndicator
+ style={{
+ marginBottom: 20
+ }}
+ size={SIZE.md}
+ color={colors.accent}
+ />
+ ) : (
+ <Paragraph
+ style={{
+ alignSelf: 'center',
+ marginBottom: 20
+ }}
+ size={SIZE.md}
+ >
+ ({pricing?.product?.localizedPrice} / mo)
+ </Paragraph>
+ )}
+
<Paragraph
key="description"
size={SIZE.md}
diff --git a/apps/mobile/src/components/premium/pricingplans.js b/apps/mobile/src/components/premium/pricingplans.js
index fa3090220..ceb2f8e72 100644
--- a/apps/mobile/src/components/premium/pricingplans.js
+++ b/apps/mobile/src/components/premium/pricingplans.js
@@ -24,6 +24,7 @@ import Heading from '../ui/typography/heading';
import Paragraph from '../ui/typography/paragraph';
import { Walkthrough } from '../walkthroughs';
import { PricingItem } from './pricing-item';
+import { usePricing } from '../../utils/hooks/use-pricing';
const promoCyclesMonthly = {
1: 'first month',
@@ -37,39 +38,23 @@ const promoCyclesYearly = {
3: 'first 3 years'
};
-export const PricingPlans = ({
- promo,
- marginTop,
- heading = true,
- compact = false,
- trial = false,
- showTrialOption = true
-}) => {
+export const PricingPlans = ({ promo, marginTop, heading = true, compact = false }) => {
const colors = useThemeStore(state => state.colors);
const user = useUserStore(state => state.user);
const [product, setProduct] = useState(null);
- const [products, setProducts] = useState([]);
- const [offers, setOffers] = useState(null);
const [buying, setBuying] = useState(false);
const [loading, setLoading] = useState(false);
- const [upgrade, setUpgrade] = useState(!showTrialOption);
+ const userCanRequestTrial =
+ user && (!user.subscription || !user.subscription.expiry) ? true : false;
+ const [upgrade, setUpgrade] = useState(!userCanRequestTrial);
+ const yearlyPlan = usePricing('yearly');
+ const monthlyPlan = usePricing('monthly');
const getSkus = async () => {
try {
setLoading(true);
- let products = await PremiumService.getProducts();
- if (products.length > 0) {
- let offers = {
- monthly: products.find(p => p.productId === 'com.streetwriters.notesnook.sub.mo'),
- yearly: products.find(p => p.productId === 'com.streetwriters.notesnook.sub.yr')
- };
- setOffers(offers);
-
- if (promo?.promoCode) {
- getPromo(promo?.promoCode);
- }
-
- setProducts(products);
+ if (promo?.promoCode) {
+ getPromo(promo?.promoCode);
}
setLoading(false);
} catch (e) {
@@ -242,15 +227,31 @@ export const PricingPlans = ({
{user && !product ? (
<>
{heading ? (
- <Heading
- style={{
- alignSelf: 'center',
- marginTop: marginTop || 20,
- marginBottom: 20
- }}
- >
- Choose a plan
- </Heading>
+ <>
+ {monthlyPlan && monthlyPlan?.info?.discount > 0 ? (
+ <View
+ style={{
+ alignSelf: 'center',
+ marginTop: marginTop || 20,
+ marginBottom: 20
+ }}
+ >
+ <Heading color={colors.accent}>
+ Get {monthlyPlan?.info?.discount}% off in {monthlyPlan?.info?.country}
+ </Heading>
+ </View>
+ ) : (
+ <Heading
+ style={{
+ alignSelf: 'center',
+ marginTop: marginTop || 20,
+ marginBottom: 20
+ }}
+ >
+ Choose a plan
+ </Heading>
+ )}
+ </>
) : null}
<View
@@ -261,11 +262,11 @@ export const PricingPlans = ({
}}
>
<PricingItem
- onPress={() => buySubscription(offers?.monthly)}
+ onPress={() => buySubscription(monthlyPlan?.product)}
compact={compact}
product={{
type: 'monthly',
- data: offers?.monthly,
+ data: monthlyPlan?.product,
info: 'Pay monthly, cancel anytime.'
}}
/>
@@ -280,11 +281,11 @@ export const PricingPlans = ({
)}
<PricingItem
- onPress={() => buySubscription(offers?.yearly)}
+ onPress={() => buySubscription(yearlyPlan?.product)}
compact={compact}
product={{
type: 'yearly',
- data: offers?.yearly,
+ data: yearlyPlan?.product,
info: 'Pay yearly'
}}
/>
diff --git a/apps/mobile/src/screens/settings/usersection.js b/apps/mobile/src/screens/settings/usersection.js
index 3b6f9bd37..30184fa99 100644
--- a/apps/mobile/src/screens/settings/usersection.js
+++ b/apps/mobile/src/screens/settings/usersection.js
@@ -25,6 +25,7 @@ import {
eOpenPremiumDialog,
eOpenRecoveryKeyDialog
} from '../../utils/events';
+import { usePricing } from '../../utils/hooks/use-pricing';
import { SIZE } from '../../utils/size';
import { sleep } from '../../utils/time';
import TwoFactorAuth from './2fa';
@@ -47,6 +48,7 @@ const SettingsUserSection = () => {
const isExpired = user && subscriptionDaysLeft.time < 0;
const expiryDate = dayjs(user?.subscription?.expiry).format('MMMM D, YYYY');
const startDate = dayjs(user?.subscription?.start).format('MMMM D, YYYY');
+ const monthlyPlan = usePricing('monthly');
const manageSubscription = () => {
if (!user.isEmailConfirmed) {
@@ -214,12 +216,8 @@ const SettingsUserSection = () => {
Platform.OS === 'android'
? `Resubscribe from Google Playstore`
: user.subscription?.type === SUBSCRIPTION_STATUS.PREMIUM_EXPIRED
- ? `Resubscribe to Notesnook Pro (${
- PremiumService.getMontlySub().localizedPrice
- } / mo)`
- : `Subscribe to Notesnook Pro (${
- PremiumService.getMontlySub().localizedPrice
- } / mo)`
+ ? `Resubscribe to Notesnook Pro (${monthlyPlan?.product?.localizedPrice} / mo)`
+ : `Subscribe to Notesnook Pro (${monthlyPlan?.product?.localizedPrice} / mo)`
}
height={50}
type="accent"
diff --git a/apps/mobile/src/services/premium.js b/apps/mobile/src/services/premium.js
index 545eb81f9..8b75ede1e 100644
--- a/apps/mobile/src/services/premium.js
+++ b/apps/mobile/src/services/premium.js
@@ -68,7 +68,7 @@ async function getProducts() {
}
function get() {
- if (__DEV__) return true;
+ // if (__DEV__) return true;
return SUBSCRIPTION_STATUS.BASIC !== premiumStatus;
}
diff --git a/apps/mobile/src/utils/constants.js b/apps/mobile/src/utils/constants.js
index b56954d01..a0ff09606 100644
--- a/apps/mobile/src/utils/constants.js
+++ b/apps/mobile/src/utils/constants.js
@@ -30,7 +30,13 @@ export const itemSkus = [
'com.streetwriters.notesnook.sub.mo.15',
'com.streetwriters.notesnook.sub.mo.ofr',
'com.streetwriters.notesnook.sub.yr.trialoffer',
- 'com.streetwriters.notesnook.sub.mo.trialoffer'
+ 'com.streetwriters.notesnook.sub.mo.trialoffer',
+ 'com.streetwriters.notesnook.sub.mo.tier1',
+ 'com.streetwriters.notesnook.sub.yr.tier1',
+ 'com.streetwriters.notesnook.sub.mo.tier2',
+ 'com.streetwriters.notesnook.sub.yr.tier2',
+ 'com.streetwriters.notesnook.sub.mo.tier3',
+ 'com.streetwriters.notesnook.sub.yr.tier3'
];
export const SUBSCRIPTION_STATUS = {
diff --git a/apps/mobile/src/utils/hooks/usePricing.ts b/apps/mobile/src/utils/hooks/usePricing.ts
new file mode 100644
index 000000000..98816f896
--- /dev/null
+++ b/apps/mobile/src/utils/hooks/usePricing.ts
@@ -0,0 +1,45 @@
+import { useEffect, useState } from 'react';
+import { Platform } from 'react-native';
+import { Subscription } from 'react-native-iap';
+import PremiumService from '../../services/premium';
+import { db } from '../database';
+
+type PurchaseInfo = {
+ country: string;
+ countryCode: string;
+ sku: string;
+ discount: number;
+};
+
+const skuInfos: { [name: string]: PurchaseInfo | undefined } = {};
+
+export const usePricing = (period: 'monthly' | 'yearly') => {
+ const [current, setCurrent] =
+ useState<{ period: string; info?: PurchaseInfo; product?: Subscription }>();
+
+ const getDefaultSku = (period: 'monthly' | 'yearly') => {
+ return period === 'monthly'
+ ? 'com.streetwriters.notesnook.sub.mo'
+ : 'com.streetwriters.notesnook.sub.yr';
+ };
+
+ useEffect(() => {
+ (async () => {
+ let skuInfo =
+ skuInfos[period] ||
+ (await db.pricing?.sku(Platform.OS === 'android' ? 'android' : 'ios', period));
+ skuInfos[period] = skuInfo;
+ let products = (await PremiumService.getProducts()) as Subscription[];
+ let product = products.find(p => p.productId === skuInfo?.sku);
+ if (!product) product = products.find(p => p.productId === getDefaultSku(period));
+ console.log('skuInfos: ', skuInfos, product?.productId, product?.price, products.length);
+ setCurrent({
+ info: skuInfo,
+ period,
+ product
+ });
+ })();
+ }, [period]);
+
+ return current;
+};