Skip to content

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

feat: add subscription yearly plan

thecodrr63af279d017f
diff --git a/apps/web/src/common/checkout.js b/apps/web/src/common/checkout.js
index 14f1ee50a..1555c7763 100644
--- a/apps/web/src/common/checkout.js
+++ b/apps/web/src/common/checkout.js
@@ -1,9 +1,12 @@
import { trackEvent } from "../utils/analytics";
-const isDev = process.env.NODE_ENV === "development";
+const isDev = false; // process.env.NODE_ENV === "development";
const VENDOR_ID = isDev ? 1506 : 128190;
-const PRODUCT_ID = isDev ? 9822 : 648884;
+const PRODUCT_ID = (plan) => {
+ if (isDev) return plan === "monthly" ? 9822 : 0;
+ else return plan === "monthly" ? 648884 : 658759;
+};
function loadPaddle(eventCallback) {
return new Promise((resolve) => {
@@ -23,7 +26,7 @@ function loadPaddle(eventCallback) {
});
}
-async function upgrade(user, coupon) {
+async function upgrade(user, coupon, plan) {
if (!window.Paddle) {
await loadPaddle();
}
@@ -38,7 +41,7 @@ async function upgrade(user, coupon) {
}
Paddle.Checkout.open({
- product: PRODUCT_ID,
+ product: PRODUCT_ID(plan),
email: user.email,
coupon,
passthrough: JSON.stringify({
@@ -61,10 +64,12 @@ async function openPaddleDialog(overrideUrl) {
});
}
-async function getCouponData(coupon) {
- console.log(coupon);
+async function getCouponData(coupon, plan) {
let url =
- "https://checkout-service.paddle.com/checkout/97379638-chre9f4b00ed6b3-732b0e853d/coupon";
+ plan === "monthly"
+ ? "https://checkout-service.paddle.com/checkout/97379638-chre9f4b00ed6b3-732b0e853d/coupon"
+ : "https://checkout-service.paddle.com/checkout/98675996-chre252e5763eaf-15b142d0e3/coupon";
+
const response = await fetch(url, {
headers: {
accept: "application/json, text/plain, */*",
diff --git a/apps/web/src/components/dialogs/buydialog.js b/apps/web/src/components/dialogs/buydialog.js
index 2e71090d6..741ec041c 100644
--- a/apps/web/src/components/dialogs/buydialog.js
+++ b/apps/web/src/components/dialogs/buydialog.js
@@ -116,6 +116,7 @@ function BuyDialog(props) {
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState();
const [prices, setPrices] = useState();
+ const [plan, setPlan] = useState("monthly");
const isLoggedIn = useUserStore((store) => store.isLoggedIn);
const user = useUserStore((store) => store.user);
const accent = useThemeStore((store) => store.accent);
@@ -125,7 +126,8 @@ function BuyDialog(props) {
try {
setIsLoading(true);
setError();
- const data = await getCouponData(coupon);
+ const data = await getCouponData(coupon, plan);
+ console.log(data);
setPrices({
...data.paddlejs.vendor,
withoutDiscount: data.total[0],
@@ -137,7 +139,7 @@ function BuyDialog(props) {
setIsLoading(false);
}
})();
- }, [coupon]);
+ }, [coupon, plan]);
useEffect(() => {
trackEvent("Buy dialog opened.", "buy");
@@ -219,6 +221,27 @@ function BuyDialog(props) {
</>
) : (
<>
+ <Button
+ variant="anchor"
+ display="flex"
+ justifyContent="center"
+ alignItems="center"
+ onClick={() => {
+ setPlan((s) => (s === "monthly" ? "yearly" : "monthly"));
+ }}
+ >
+ <Text variant="body" mr={1}>
+ Monthly
+ </Text>
+ {plan === "monthly" ? (
+ <Icon.ToggleUnchecked color="primary" />
+ ) : (
+ <Icon.ToggleChecked color="primary" />
+ )}
+ <Text variant="body" ml={1}>
+ Yearly
+ </Text>
+ </Button>
{coupon ? (
<Flex mb={1} alignItems="center" justifyContent="space-between">
<Flex alignItems="center" justifyContent="center">
@@ -284,9 +307,9 @@ function BuyDialog(props) {
</Text>
)}
<Text variant="heading" fontSize={24} color="primary">
- Only <MainPricing prices={prices} />
+ Only <MainPricing prices={prices} plan={plan} />
</Text>
- <RecurringPricing prices={prices} />
+ <RecurringPricing prices={prices} plan={plan} />
<Text display="flex" variant="subBody" color="text" mt={1} mb={2}>
Cancel anytime. No questions asked.
</Text>
@@ -296,7 +319,7 @@ function BuyDialog(props) {
onClick={async () => {
trackEvent("Subscribe button clicked.", "buy");
if (isLoggedIn) {
- await upgrade(user, coupon);
+ await upgrade(user, coupon, plan);
} else {
await showLogInDialog();
await upgrade(user, coupon);
@@ -316,7 +339,7 @@ function BuyDialog(props) {
export default BuyDialog;
function MainPricing(props) {
- const { prices } = props;
+ const { prices, plan } = props;
if (prices.withoutDiscount.net !== prices.prices.total)
return (
@@ -329,21 +352,21 @@ function MainPricing(props) {
</del>{" "}
<Price currency={prices.currency} price={prices.prices.total} />
{prices.recurring_prices.total === prices.prices.total
- ? " per month"
- : " your first month"}
+ ? ` per ${planToPeriod(plan)}`
+ : ` your first ${planToPeriod(plan)}`}
</>
);
else
return (
<>
<Price currency={prices.currency} price={prices.prices.total} />
- {" per month"}
+ {` per ${planToPeriod(plan)}`}
</>
);
}
function RecurringPricing(props) {
- const { prices } = props;
+ const { prices, plan } = props;
if (prices.prices.total === prices.recurring_prices.total) return null;
return (
@@ -356,7 +379,7 @@ function RecurringPricing(props) {
>
And then{" "}
<Price currency={prices.currency} price={prices.recurring_prices.total} />{" "}
- every month afterwards.
+ every {planToPeriod(plan)} afterwards.
</Text>
);
}
@@ -370,3 +393,7 @@ function Price(props) {
</>
);
}
+
+function planToPeriod(plan) {
+ return plan === "monthly" ? "month" : "year";
+}