Skip to content

Commit 0b94b05

Browse files
feat: Added the proper error messages as a toast notifications if error occurs with the checkout session (#1121)
2 parents 695130b + 46f7a1e commit 0b94b05

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

apps/web/components/UpgradePlan/Plans/PlanCard.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react';
22
import { plansApi, useSubscription } from 'subos-frontend';
33
import { Card, Text, Badge, Stack, Divider, LoadingOverlay } from '@mantine/core';
44
import { Button } from '@ui/button';
5-
import { colors, PLANCODEENUM, ROUTES } from '@config';
5+
import { colors, NOTIFICATION_KEYS, PLANCODEENUM, ROUTES } from '@config';
66
import { Plan } from './Plans';
77
import { PlanFeature } from './PlanFeature';
88
import useStyles from './Plans.styles';
@@ -28,8 +28,11 @@ export function PlanCard({ plan, isYearly }: PlanCardProps) {
2828
try {
2929
setIsLoading(true);
3030
await fetchSubscription(profileInfo.email);
31-
} catch (err) {
32-
notify('Failed to fetch subscription');
31+
} catch (err: any) {
32+
notify(NOTIFICATION_KEYS.ERROR_FETCHING_SUBSCRIPTION_DETAILS, {
33+
title: 'Failed to fetch subscription',
34+
message: err?.message,
35+
});
3336
} finally {
3437
setIsLoading(false);
3538
}
@@ -42,9 +45,9 @@ export function PlanCard({ plan, isYearly }: PlanCardProps) {
4245
setIsLoading(true);
4346
try {
4447
const response = await createPaymentSession(plan.code, {
45-
returnUrl: `${window.location.origin}/${ROUTES.SUBSCRIPTION_STATUS}`,
48+
returnUrl: `${window.location.origin}${ROUTES.SUBSCRIPTION_STATUS}`,
4649
externalId: profileInfo?.email,
47-
cancelUrl: `${window.location.origin}/${ROUTES.PAYMENT_CANCEL}`,
50+
cancelUrl: `${window.location.origin}${ROUTES.PAYMENT_CANCEL}`,
4851
});
4952
if (response?.success && response?.data?.checkoutUrl) {
5053
window.location.href = response?.data?.checkoutUrl;
@@ -54,7 +57,10 @@ export function PlanCard({ plan, isYearly }: PlanCardProps) {
5457

5558
return null;
5659
} catch (err: any) {
57-
notify('Failed to create payment session');
60+
notify(NOTIFICATION_KEYS.ERROR_CREATE_CHECKOUT_SESSION, {
61+
title: 'Failed to create the checkout session',
62+
message: err?.message,
63+
});
5864
} finally {
5965
setIsLoading(false);
6066
}

apps/web/config/constants.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ export const NOTIFICATION_KEYS = {
208208

209209
MEMBERSHIP_CANCELLED: 'MEMBERSHIP_CANCELLED',
210210
MEMBERSHIP_PURCHASED: 'MEMBERSHIP_PURCHASED',
211+
ERROR_CREATE_CHECKOUT_SESSION: 'ERROR_CREATE_PAYMENT_SESSION',
211212
ERROR_FETCHING_SUBSCRIPTION_DETAILS: 'ERROR_FETCHING_SUBSCRIPTION_DETAILS',
212213

213214
IMPORT_DUPLICATED: 'IMPORT_DUPLICATED',

0 commit comments

Comments
 (0)