diff --git a/src/components/pages/gallery/PlanSelector.tsx b/src/components/pages/gallery/PlanSelector.tsx index 15533acfb..a5ad2c342 100644 --- a/src/components/pages/gallery/PlanSelector.tsx +++ b/src/components/pages/gallery/PlanSelector.tsx @@ -16,6 +16,8 @@ import { hasPaidSubscription, isOnFreePlan, planForSubscription, + hasMobileSubscription, + hasPaypalSubscription, } from 'utils/billing'; import { reverseString } from 'utils/common'; import { SetDialogMessage } from 'components/MessageDialog'; @@ -143,8 +145,7 @@ function PlanSelector(props: Props) { async function onPlanSelect(plan: Plan) { if ( - hasPaidSubscription(subscription) && - !hasStripeSubscription(subscription) && + hasMobileSubscription(subscription) && !isSubscriptionCancelled(subscription) ) { props.setDialogMessage({ @@ -152,6 +153,15 @@ function PlanSelector(props: Props) { content: constants.CANCEL_SUBSCRIPTION_ON_MOBILE, close: { variant: 'danger' }, }); + } else if ( + hasPaypalSubscription(subscription) && + !isSubscriptionCancelled(subscription) + ) { + props.setDialogMessage({ + title: constants.MANAGE_PLAN, + content: constants.PAYPAL_MANAGE_NOT_SUPPORTED_MESSAGE(), + close: { variant: 'danger' }, + }); } else if (hasStripeSubscription(subscription)) { props.setDialogMessage({ title: `${constants.CONFIRM} ${reverseString( diff --git a/src/utils/billing/index.ts b/src/utils/billing/index.ts index e8043d61d..b696665b7 100644 --- a/src/utils/billing/index.ts +++ b/src/utils/billing/index.ts @@ -9,6 +9,9 @@ import { CustomError } from '../error'; import { logError } from '../sentry'; const PAYMENT_PROVIDER_STRIPE = 'stripe'; +const PAYMENT_PROVIDER_APPSTORE = 'appstore'; +const PAYMENT_PROVIDER_PLAYSTORE = 'playstore'; +const PAYMENT_PROVIDER_PAYPAL = 'paypal'; const FREE_PLAN = 'free'; enum FAILURE_REASON { @@ -96,6 +99,23 @@ export function hasStripeSubscription(subscription: Subscription) { ); } +export function hasMobileSubscription(subscription: Subscription) { + return ( + hasPaidSubscription(subscription) && + subscription.paymentProvider.length > 0 && + (subscription.paymentProvider === PAYMENT_PROVIDER_APPSTORE || + subscription.paymentProvider === PAYMENT_PROVIDER_PLAYSTORE) + ); +} + +export function hasPaypalSubscription(subscription: Subscription) { + return ( + hasPaidSubscription(subscription) && + subscription.paymentProvider.length > 0 && + subscription.paymentProvider === PAYMENT_PROVIDER_PAYPAL + ); +} + export async function updateSubscription( plan: Plan, setDialogMessage: SetDialogMessage, diff --git a/src/utils/strings/englishConstants.tsx b/src/utils/strings/englishConstants.tsx index 0a2e5fc9f..2d73d4b0a 100644 --- a/src/utils/strings/englishConstants.tsx +++ b/src/utils/strings/englishConstants.tsx @@ -332,6 +332,14 @@ const englishConstants = { SUBSCRIPTION_PURCHASE_SUCCESS_TITLE: 'thank you', CANCEL_SUBSCRIPTION_ON_MOBILE: 'please cancel your subscription from the mobile app to activate a subscription here', + PAYPAL_MANAGE_NOT_SUPPORTED_MESSAGE: () => ( + <> + please contact us at{' '} + paypal@ente.io to manage your + subscription + + ), + PAYPAL_MANAGE_NOT_SUPPORTED: 'manage paypal plan', RENAME: 'rename', RENAME_COLLECTION: 'rename album', CONFIRM_DELETE_COLLECTION: 'confirm album deletion',