diff --git a/src/App.tsx b/src/App.tsx index d37e5659f..d6a693f6b 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -188,7 +188,7 @@ const App = (props: AppProps): JSX.Element => { to={`/?preferences=open§ion=account&subsection=${params.get('tab') ?? 'account'}`} /> - {pathName !== 'checkout-plan' && pathName !== 'checkout' && isMobile && isAuthenticated ? ( + {pathName !== 'checkout' && isMobile && isAuthenticated ? ( diff --git a/src/app/auth/views/Auth/signup.ts b/src/app/auth/views/Auth/signup.ts index fa1c25283..7c6894d6f 100644 --- a/src/app/auth/views/Auth/signup.ts +++ b/src/app/auth/views/Auth/signup.ts @@ -39,13 +39,7 @@ const signup = async (data, dispatch, doRegister, setLoading, appRedirect?, setE localStorage.removeItem('email'); localStorage.removeItem('password'); setLoading(false); - appRedirect - ? window.open(`${process.env.REACT_APP_HOSTNAME}`, '_parent', 'noopener') - : window.open( - `${process.env.REACT_APP_HOSTNAME}/checkout-plan?planId=plan_F7ptyrVRmyL8Gn&couponCode=g3S2TZFZ&freeTrials=30&mode=subscription`, - '_parent', - 'noopener', - ); + window.open(`${process.env.REACT_APP_HOSTNAME}`, '_parent', 'noopener'); } catch (err: unknown) { setError(errorService.castError(err).message); setLoading(false); diff --git a/src/app/core/config/views.ts b/src/app/core/config/views.ts index c91cb9010..e35e5e4f5 100644 --- a/src/app/core/config/views.ts +++ b/src/app/core/config/views.ts @@ -31,7 +31,6 @@ import ChangeEmailView from '../views/ChangeEmailView'; import NotFoundView from '../views/NotFoundView/NotFoundView'; import VerifyEmailView from '../views/VerifyEmailView'; import CheckoutViewWrapper from '../../payment/views/IntegratedCheckoutView/CheckoutViewWrapper'; -import CheckoutPlanView from '../../payment/views/RedirectToCheckoutView/CheckoutPlanView'; const views: Array<{ id: string; @@ -59,7 +58,6 @@ const views: Array<{ { id: AppView.CheckoutSuccess, component: CheckoutSuccessView }, { id: AppView.CheckoutCancel, component: CheckoutCancelView }, { id: AppView.Checkout, component: CheckoutViewWrapper }, - { id: AppView.CheckoutPlan, component: CheckoutPlanView }, { id: AppView.RecoveryLink, component: RecoveryLinkView }, { id: AppView.ShareFileToken, component: ShareFileView }, { id: AppView.ShareFileToken2, component: ShareFileView }, diff --git a/src/app/core/types.ts b/src/app/core/types.ts index c4a852979..0b282a942 100644 --- a/src/app/core/types.ts +++ b/src/app/core/types.ts @@ -126,7 +126,6 @@ export enum AppView { Deactivation = 'deactivation', CheckoutSuccess = 'checkout-success', CheckoutCancel = 'checkout-cancel', - CheckoutPlan = 'checkout-plan', Checkout = 'checkout', RecoveryLink = 'recovery-link', ShareFileToken = 'share-token', diff --git a/src/app/newSettings/Sections/Account/Plans/PlansSection.tsx b/src/app/newSettings/Sections/Account/Plans/PlansSection.tsx index df07b4b59..8cb81da43 100644 --- a/src/app/newSettings/Sections/Account/Plans/PlansSection.tsx +++ b/src/app/newSettings/Sections/Account/Plans/PlansSection.tsx @@ -17,7 +17,7 @@ import { RootState } from '../../../../store'; import { useAppDispatch } from '../../../../store/hooks'; import { PlanState, planThunks } from '../../../../store/slices/plan'; import CancelSubscriptionModal from '../../Workspace/Billing/CancelSubscriptionModal'; -import { createCheckoutSession, fetchPlanPrices, getStripe } from './api/plansApi'; +import { fetchPlanPrices, getStripe } from './api/plansApi'; import ChangePlanDialog from './components/ChangePlanDialog'; import PlanCard from './components/PlanCard'; import PlanSelectionCard from './components/PlanSelectionCard'; @@ -200,28 +200,6 @@ const PlansSection = ({ changeSection, onClosePreferences }: PlansSectionProps) } }; - const handleCheckoutSession = async ({ - priceId, - currency, - userEmail, - mode, - }: { - userEmail: string; - priceId: string; - mode: string; - currency: string; - }) => { - try { - const response = await createCheckoutSession({ userEmail, priceId, currency, mode }); - localStorage.setItem('sessionId', response.sessionId); - await paymentService.redirectToCheckout(response); - } catch (err) { - const error = errorService.castError(err); - errorService.reportError(error); - showCancelSubscriptionErrorNotification(); - } - }; - const onChangePlanClicked = async (priceId: string, currency: string) => { setIsLoadingCheckout(true); setIsUpdatingSubscription(true); diff --git a/src/app/newSettings/Sections/Account/Plans/api/plansApi.ts b/src/app/newSettings/Sections/Account/Plans/api/plansApi.ts index d9084d4c7..990049a25 100644 --- a/src/app/newSettings/Sections/Account/Plans/api/plansApi.ts +++ b/src/app/newSettings/Sections/Account/Plans/api/plansApi.ts @@ -38,27 +38,6 @@ const fetchPlanPrices = async (userType: UserType) => { } }; -const createCheckoutSession = async ({ - userEmail, - priceId, - mode, - currency, -}: { - userEmail: string; - priceId: string; - mode: string; - currency: string; -}) => { - return paymentService.createCheckoutSession({ - price_id: priceId, - success_url: `${window.location.origin}/checkout/success`, - cancel_url: `${window.location.origin}/checkout/cancel?price_id=${priceId}`, - customer_email: userEmail, - mode: mode, - currency: currency, - }); -}; - const getStripe = async (stripe): Promise => { if (!stripe) { stripe = (await loadStripe( @@ -69,4 +48,4 @@ const getStripe = async (stripe): Promise => { return stripe; }; -export { createCheckoutSession, fetchPlanPrices, getStripe }; +export { fetchPlanPrices, getStripe }; diff --git a/src/app/payment/services/payment.service.ts b/src/app/payment/services/payment.service.ts index 31d480f3b..a71cf0d6e 100644 --- a/src/app/payment/services/payment.service.ts +++ b/src/app/payment/services/payment.service.ts @@ -1,5 +1,4 @@ import { - CreateCheckoutSessionPayload, CreatedSubscriptionData, CustomerBillingInfo, DisplayPrice, @@ -167,14 +166,6 @@ const paymentService = { return paymentsClient.cancelSubscription(userType); }, - async createCheckoutSession( - payload: CreateCheckoutSessionPayload & { mode?: string }, - ): Promise<{ sessionId: string }> { - const paymentsClient = await SdkFactory.getInstance().createPaymentsClient(); - - return paymentsClient.createCheckoutSession(payload); - }, - async updateCustomerBillingInfo(payload: CustomerBillingInfo): Promise { const paymentsClient = await SdkFactory.getInstance().createPaymentsClient(); return paymentsClient.updateCustomerBillingInfo(payload); diff --git a/src/app/payment/views/RedirectToCheckoutView/CheckoutPlanView.tsx b/src/app/payment/views/RedirectToCheckoutView/CheckoutPlanView.tsx deleted file mode 100644 index d1faefb0c..000000000 --- a/src/app/payment/views/RedirectToCheckoutView/CheckoutPlanView.tsx +++ /dev/null @@ -1,163 +0,0 @@ -import { UserType } from '@internxt/sdk/dist/drive/payments/types'; -import { UserSettings } from '@internxt/sdk/dist/shared/types/userSettings'; -import navigationService from 'app/core/services/navigation.service'; -import { AppView } from 'app/core/types'; -import { useTranslationContext } from 'app/i18n/provider/TranslationProvider'; -import notificationsService, { ToastType } from 'app/notifications/services/notifications.service'; -import paymentService from 'app/payment/services/payment.service'; -import { RootState } from 'app/store'; -import { useAppDispatch, useAppSelector } from 'app/store/hooks'; -import { planActions, PlanState } from 'app/store/slices/plan'; -import { useEffect } from 'react'; -import { useSelector } from 'react-redux'; -import errorService from '../../../core/services/error.service'; -import { uiActions } from '../../../store/slices/ui'; -import workspacesSelectors from '../../../store/slices/workspaces/workspaces.selectors'; - -interface CheckoutOptions { - price_id: string; - coupon_code?: string; - trial_days?: number; - success_url: string; - cancel_url: string; - customer_email: string; - mode: string | undefined; - currency: string; -} - -// THIS ONLY APPLY TO B2B PLANS, BECAUSE B2C USES THE INTEGRATED CHECKOUT -export default function CheckoutPlanView(): JSX.Element { - const dispatch = useAppDispatch(); - const { translate } = useTranslationContext(); - const params = new URLSearchParams(window.location.search); - const planType = String(params.get('planType')); - - const selectedWorkspace = useAppSelector(workspacesSelectors.getSelectedWorkspace); - - const plan = useSelector((state: RootState) => state.plan) as PlanState; - const user = useSelector((state: RootState) => state.user.user) as UserSettings; - if (user === undefined) { - navigationService.push(AppView.Login); - } - const { individualSubscription, businessSubscription } = plan; - - const subscription = planType === 'business' ? businessSubscription : individualSubscription; - - useEffect(() => { - if (subscription) { - const params = new URLSearchParams(window.location.search); - const planId = String(params.get('planId')); - const coupon = String(params.get('couponCode')); - const mode = String(params.get('mode') as string | undefined); - const freeTrials = Number(params.get('freeTrials')); - const currency = String(params.get('currency')); - const planType = String(params.get('planType')); - - checkout(planId, currency, coupon, mode, freeTrials, planType); - } - }, [subscription]); - - async function checkout( - planId: string, - currency: string, - coupon?: string, - mode?: string, - freeTrials?: number, - planType?: string, - ) { - let response; - - const checkoutOptions: CheckoutOptions = { - price_id: planId, - success_url: `${window.location.origin}/checkout/success`, - cancel_url: `${window.location.origin}/checkout/cancel`, - customer_email: user.email, - mode: mode, - currency, - }; - - if (subscription?.type !== 'subscription') { - try { - if (coupon && freeTrials) { - checkoutOptions.coupon_code = coupon; - checkoutOptions.trial_days = freeTrials; - } else if (coupon !== 'null') { - checkoutOptions.coupon_code = coupon; - } - - response = await paymentService.createCheckoutSession(checkoutOptions); - localStorage.setItem('sessionId', response.sessionId); - - await paymentService.redirectToCheckout(response); - } catch (err) { - errorService.reportError(err); - notificationsService.show({ - text: translate('notificationMessages.errorCancelSubscription'), - type: ToastType.Error, - }); - } - } else { - if (mode === 'payment') { - try { - if (coupon && coupon !== 'null') { - checkoutOptions.coupon_code = coupon; - } - response = await paymentService.createCheckoutSession(checkoutOptions); - localStorage.setItem('sessionId', response.sessionId); - await paymentService.redirectToCheckout(response).then(async (result) => { - await paymentService.cancelSubscription(); - if (result.error) { - notificationsService.show({ - type: ToastType.Error, - text: result.error.message as string, - }); - } else { - notificationsService.show({ - type: ToastType.Success, - text: 'Payment successful', - }); - } - }); - } catch (error) { - notificationsService.show({ - text: translate('notificationMessages.errorCancelSubscription'), - type: ToastType.Error, - }); - } - } else { - try { - if (planType === 'business') { - notificationsService.show({ - text: translate('notificationMessages.errorPurchaseBusinessPlan'), - type: ToastType.Info, - }); - navigationService.push(AppView.Login); - } - const couponCode = coupon === 'null' ? undefined : coupon; - const { userSubscription } = await paymentService.updateSubscriptionPrice({ - priceId: planId, - coupon: couponCode, - userType: UserType.Business, - }); - if (userSubscription && userSubscription.type === 'subscription') { - if (userSubscription.userType == UserType.Business) - dispatch(planActions.setSubscriptionBusiness(userSubscription)); - } - navigationService.openPreferencesDialog({ - section: 'account', - subsection: 'account', - workspaceUuid: selectedWorkspace?.workspaceUser.workspaceId, - }); - dispatch(uiActions.setIsPreferencesDialogOpen(true)); - } catch (err) { - notificationsService.show({ - text: translate('notificationMessages.errorCancelSubscription'), - type: ToastType.Error, - }); - } - } - } - } - - return <>; -} diff --git a/src/app/routes/paths.json b/src/app/routes/paths.json index ef744aa3a..0458116a0 100644 --- a/src/app/routes/paths.json +++ b/src/app/routes/paths.json @@ -143,13 +143,6 @@ "exact": true, "auth": false }, - { - "id": "checkout-plan", - "layout": "empty", - "path": "/checkout-plan/", - "exact": true, - "auth": true - }, { "id": "recovery-link", "layout": "empty",