Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Stripe Handling New ULTRA Plan #300

Open
wants to merge 141 commits into
base: chat-everywhere
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
141 commits
Select commit Hold shift click to select a range
aa5399f
Fix File list query
1orZero May 27, 2024
4c04384
chore: Update subscription plan payment links and add new plans
1orZero May 27, 2024
6234389
chore: Enable chat with document feature
1orZero May 27, 2024
a2734e8
chore: Update SettingsModel dialog panel width for better responsiveness
1orZero May 27, 2024
9520363
chore: Add PlanComparison component to Settings_Account
1orZero May 27, 2024
717e7eb
chore: Move payment links to const file
1orZero May 27, 2024
b67415e
Update the style of the Tier badge
1orZero May 28, 2024
bc3cbf5
refactor: Update PlanComparison component to display current plan and…
1orZero May 28, 2024
0322488
chore: Update payment links and use CONST variable instead of env var…
1orZero May 28, 2024
be82c27
chore: Update const file
1orZero May 28, 2024
698896f
refactor: Update handleCheckoutSessionCompleted function to use UserP…
1orZero May 28, 2024
a1ac3a1
feat: Add enums for PaidPlan and TopUpRequest
1orZero May 28, 2024
9f95618
refactor: Move strip config to a new file from const file
1orZero May 28, 2024
a7b08e4
refactor: Update const variable name
1orZero May 28, 2024
92964e8
refactor: Refactor handleCheckoutSessionCompleted function
1orZero May 28, 2024
f8fd4a4
refactor: Add error logging to stripe webhook handler
1orZero May 28, 2024
5a72aa6
refactor: Add SubscriptionPlan type and update user.ts to use it
1orZero May 28, 2024
b62a782
refactor: Add getSubscriptionPlanByPaidPlan function to utils/app/pai…
1orZero May 28, 2024
f6f2383
refactor: Remove unused constant in stripe_config.ts
1orZero May 28, 2024
acb7446
refactor: Update updateUserAccount function to support extending pro/…
1orZero May 28, 2024
ac41bd6
refactor: Update handleCheckoutSessionCompleted function to use UserP…
1orZero May 28, 2024
805f2a8
refactor: Update import statement for getCustomerEmailByCustomerID in…
1orZero May 28, 2024
174a8e0
refactor: Update subscription event handling in stripe webhook handler
1orZero May 28, 2024
b4a75d3
refactor: rename file to paid_plan to paid_plan_helper
1orZero May 28, 2024
415bf96
refactor: Update import statement for getCustomerEmailByCustomerID in…
1orZero May 28, 2024
97f6072
refactor: Update localization for Chinese (Simplified) and Chinese (T…
1orZero May 29, 2024
a96b756
refactor: Add Tabs component for UI tab functionality
1orZero May 29, 2024
208657f
refactor: Add UltraYearly option to PaidPlan enum
1orZero May 29, 2024
ce36427
refactor: Update payment links for Pro and Ultra plans
1orZero May 29, 2024
5f25e16
refactor: Add support for yearly Ultra plan subscription
1orZero May 29, 2024
fd433e5
refactor: Update updateUserAccount function to extend membership
1orZero May 29, 2024
1a73f75
refactor: Update payment links for Pro and Ultra plans
1orZero May 29, 2024
3f1a88a
Refactor: Remove the updateUserAccount and make the function more atomic
1orZero May 29, 2024
5b77027
refactor: Update handleCheckoutSessionCompleted to use strip_helper f…
1orZero May 29, 2024
8e801fb
refactor: Update handleCustomerSubscriptionUpdated to use strip_helpe…
1orZero May 29, 2024
ea625c4
refactor: Update handleCustomerSubscriptionDeleted to use downgradeUs…
1orZero May 29, 2024
c87f6c4
refactor: Update handleCustomerSubscriptionDeleted to use downgradeUs…
1orZero May 29, 2024
ad40b13
refactor: Add support for monthly and yearly payment options in Chine…
1orZero May 29, 2024
246896b
feat: Add logic to handle one-time plan purchase for users already on…
1orZero May 29, 2024
27381da
refactor: Update payment links for staging
1orZero May 29, 2024
30be37f
fix: Calculate membership expiration date for Ultra Yearly plan
1orZero May 29, 2024
e4dc0c5
refactor: Update getSubscriptionPlanByPaidPlan to handle Ultra Yearly…
1orZero May 29, 2024
4d816e9
refactor: Remove console.log statements from handleCustomerSubscripti…
1orZero May 29, 2024
a586f02
refactor: Update PlanComparison component to improve UI and readability
1orZero May 29, 2024
d3ab5df
refactor: Improve UI and readability of PlanComparison component
1orZero May 29, 2024
10b18df
refactor: update the stripe product type format
1orZero May 29, 2024
fb28020
refactor: Add API endpoint for changing subscription plan
1orZero May 29, 2024
9d89727
refactor: Add API endpoint for changing subscription plan
1orZero May 29, 2024
97406b7
refactor: Update handleCustomerSubscriptionDeleted to use getCustomer…
1orZero May 29, 2024
4505d49
refactor: Update handleCustomerSubscriptionUpdated to use getCustomer…
1orZero May 29, 2024
e72ed64
refactor: Update getCustomerEmailByCustomerID function in strip_helper
1orZero May 29, 2024
5465e05
refactor: Improve PlanComparison component UI and readability
1orZero May 30, 2024
06dc18c
refactor: Update localization for Chinese (Simplified) and Chinese (T…
1orZero May 30, 2024
d2f6c34
refactor: Update stripe_config.ts to import StripeProduct type from '…
1orZero May 30, 2024
5b95c05
refactor: Update stripe product type format
1orZero May 30, 2024
80837ce
refactor: Update getPaidPlan function name to getDbSubscriptionPlanBy…
1orZero May 30, 2024
15db06c
refactor: Update getPaidPlan function name to getPaidPlanByPlanCode
1orZero May 30, 2024
3334507
refactor: Extract calculateMembershipExpirationDate function to strip…
1orZero May 30, 2024
1e525da
refactor: Extract getPriceIdByPaidPlan function to paid_plan_helper
1orZero May 30, 2024
fd8c788
refactor: Import dayjs plugin for UTC in handleCheckoutSessionCompleted
1orZero May 30, 2024
d65fd4c
refactor: Add newPaidPlan validation and update subscription plan in …
1orZero May 30, 2024
1c0fe25
refactor: Update stripe product type format
1orZero May 30, 2024
2c10c83
refactor: Update getPaidPlan function name to getDbSubscriptionPlanBy…
1orZero May 30, 2024
b24fa08
refactor: Update stripe helper functions and import StripeProduct type
1orZero May 30, 2024
315958d
refactor: Update BaseStripeProduct property name to productValue
1orZero May 30, 2024
f9f205b
refactor: Update handleCheckoutSessionCompleted to use productValue i…
1orZero May 30, 2024
6f4a5d3
refactor: Update stripe product list based on environment
1orZero May 30, 2024
5f90446
refactor: Update handleCheckoutSessionCompleted to include Top Up Req…
1orZero May 30, 2024
284120c
refactor: Update stripe helper functions and import StripeProduct type
1orZero May 30, 2024
1b2045a
refactor: Update handleCheckoutSessionCompleted to use getProductByCh…
1orZero May 30, 2024
d303329
refactor: Extend expiration date or change plan for Monthly Pro/Ultra…
1orZero May 30, 2024
0ba779e
refactor: Add second receiver email for resend functionality
1orZero May 31, 2024
3eed887
refactor: Update StripeProduct type and add mode property
1orZero May 31, 2024
ce7c568
refactor: Update sendReportForStripeWebhookError to include error cause
1orZero May 31, 2024
850f3dd
refactor: Update stripe product list based on environment
1orZero May 31, 2024
c833e77
refactor: Update getProductByCheckoutSessionId to include mode parameter
1orZero May 31, 2024
8217956
refactor: Update handleCustomerSubscriptionUpdated to include mode pa…
1orZero May 31, 2024
e8b53c1
refactor: Update handleCheckoutSessionCompleted to include session mo…
1orZero May 31, 2024
9ede547
refactor: Update error message in getProductByProductId to improve cl…
1orZero May 31, 2024
9c46dab
refactor: Update localization files for Chinese translations
1orZero May 31, 2024
0b93c06
refactor: Update change-subscription-plan API to use new price id for…
1orZero May 31, 2024
1200e39
refactor: Update useChangeSubscriptionPlan to include toast error mes…
1orZero May 31, 2024
abb1910
refactor: Update stripe_config imports to reflect new file structure
1orZero May 31, 2024
42f3318
refactor: Update stripe product list based on environment
1orZero May 31, 2024
249acf3
refactor: Update ULTRA monthly subscription payment links
1orZero May 31, 2024
cd7a2a0
refactor: Update STRIPE_PAID_PLAN_LINKS in const.ts
1orZero May 31, 2024
80a29ad
refactor: Update package.json with type-check script
1orZero May 31, 2024
f34f017
refactor: Update ULTRA yearly and monthly subscription payment links
1orZero May 31, 2024
cb07ff3
refactor: Update STRIPE_PAID_PLAN_LINKS in const.ts
1orZero May 31, 2024
9c9d534
refactor: Remove unused subscription JSON file
1orZero May 31, 2024
5230cfd
refactor: Update useChangeSubscriptionPlan to accept priceId parameter
1orZero May 31, 2024
a6047bd
refactor: Add useUserSubscriptionDetail hook for fetching user subscr…
1orZero Jun 3, 2024
81bdbdb
refactor: Remove useChangeSubscriptionPlan hook and related code
1orZero Jun 3, 2024
eb7f126
refactor: Add user subscription detail fetching and error handling
1orZero Jun 3, 2024
7ae32b2
refactor: Update PlanComparison component to include isPaidUser prop
1orZero Jun 3, 2024
e388ec6
refactor: Remove change subscription plan API endpoint
1orZero Jun 3, 2024
89c6c1e
refactor: Add user subscription detail API endpoint
1orZero Jun 3, 2024
39b1dcf
refactor: Update fetchSubscriptionIdByUserId to return null if no sub…
1orZero Jun 3, 2024
41cebf5
refactor: Add UserSubscriptionDetail interface for user subscription …
1orZero Jun 3, 2024
4dbcc47
refactor: Update PaidPlanLinks type to use AvailablePaidPlanType
1orZero Jun 3, 2024
7b0f604
refactor: Add ChangeSubscriptionButton component for managing user su…
1orZero Jun 3, 2024
531c224
refactor: Update localization for subscription change messages in Chi…
1orZero Jun 3, 2024
769842a
refactor: Remove unused import in stripe_config.ts
1orZero Jun 3, 2024
1026221
Merge branch 'chat-everywhere' into derek/20240527-stripe-ultra-subsc…
1orZero Jun 24, 2024
00b3318
Merge branch 'chat-everywhere' of https://github.com/exploratortech/c…
1orZero Jun 24, 2024
ebcf55f
Merge branch 'chat-everywhere' into derek/20240527-stripe-ultra-subsc…
1orZero Jun 24, 2024
f9e549b
chore: update package
1orZero Jun 24, 2024
65ddaf8
refactor: handle when no subscription data from stripe
1orZero Jun 24, 2024
4ce9d68
Merge branch 'chat-everywhere' into derek/20240527-stripe-ultra-subsc…
1orZero Jul 11, 2024
1562981
feat(tests): add account data and update pro user login
1orZero Jul 9, 2024
0a73f02
feat(api): add Chinese prompt for TW users
1orZero Jul 11, 2024
fbee487
feat(llm): add Chinese response for Taiwan users
1orZero Jul 11, 2024
8976179
feat(cypress): add TEST_PAYMENT_USER constant
1orZero Jul 12, 2024
74cf745
feat(cypress): add payment flow test skeleton
1orZero Jul 12, 2024
a699f30
feat(api): add test-payment-event endpoint
1orZero Jul 12, 2024
686fba7
feat(stripe): add test event handling for non-prod
1orZero Jul 12, 2024
d332b39
feat(api): add reset test payment user subscription
1orZero Jul 12, 2024
395ac13
feat(api): add test payment event for ultra plan
1orZero Jul 12, 2024
c96b326
feat(stripe): add fake event handling for testing
1orZero Jul 12, 2024
36f8482
feat(stripe): add isFakeEvent param to handleSubscription
1orZero Jul 12, 2024
5b75602
feat(api): add plan selection to test payment event
1orZero Jul 12, 2024
b83817d
feat(stripe): handle fake events in non-prod env
1orZero Jul 12, 2024
8bd04db
feat(test): add payment flow e2e tests
1orZero Jul 12, 2024
59a4336
Merge branch 'chat-everywhere' into derek/20240527-stripe-ultra-subsc…
1orZero Jul 12, 2024
b047c4e
Merge branch 'chat-everywhere' into derek/20240527-stripe-ultra-subsc…
1orZero Jul 14, 2024
a4982af
fix(UX): correct plan type in expiration date display condition
1orZero Jul 15, 2024
040ee13
fix(subscription): adjust fake event expiration period to one month
1orZero Jul 15, 2024
1749f51
test(e2e): add verification for plan expiration dates
1orZero Jul 15, 2024
72ae377
refactor(api): rename test-payment-event to test-subscription-plan-pa…
1orZero Jul 15, 2024
4c9a6d2
docs(api): clarify purpose of test subscription payment file
1orZero Jul 15, 2024
8ec4c2d
feat(stripe): add support for fake events in subscription deletion
1orZero Jul 15, 2024
208a7b6
feat(api): add test endpoint for subscription cancellation
1orZero Jul 15, 2024
a28cc97
test(e2e): implement downgrade flow verification
1orZero Jul 15, 2024
cc3fbeb
Merge branch 'chat-everywhere' into derek/20240527-stripe-ultra-subsc…
1orZero Jul 19, 2024
aa54ef4
fix(lint): expand firebase directory scope in .eslintignore
1orZero Jul 19, 2024
ac7fd20
fix(UserSettings): remove unused user prop from ChangeSubscriptionButton
1orZero Jul 19, 2024
63cb574
fix(config): correct environment variable reference in Settings_Accou…
1orZero Jul 19, 2024
96b3d19
refactor(subscriptions): adjust expiration date to include an extra d…
1orZero Jul 19, 2024
f10d86e
test(payment): extend expiration date by an extra day for Test Downgrade
1orZero Jul 19, 2024
a54e7ba
refactor(tests): rename test for subscription removal event accuracy
1orZero Jul 19, 2024
5cd9451
fix(payment): update description for subscription cancellation test
1orZero Jul 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: Move strip config to a new file from const file
  • Loading branch information
1orZero committed May 28, 2024
commit 9f95618981bd27d06821ecfb5f84f23a2fd09b66
51 changes: 14 additions & 37 deletions utils/app/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 4,20 @@ import { SubscriptionPlan } from '@/types/user';
import dayjs from 'dayjs';
import { v4 as uuidv4 } from 'uuid';

export {
STRIPE_PLAN_CODE_GPT4_CREDIT,
STRIPE_PLAN_CODE_IMAGE_CREDIT,
STRIPE_PLAN_CODE_MONTHLY_PRO_PLAN_SUBSCRIPTION,
STRIPE_PLAN_CODE_MONTHLY_ULTRA_PLAN_SUBSCRIPTION,
STRIPE_PLAN_CODE_ONE_TIME_PRO_PLAN_FOR_1_MONTH,
STRIPE_PLAN_CODE_ONE_TIME_ULTRA_PLAN_FOR_1_MONTH,
PRO_PLAN_PAYMENT_LINK,
ULTRA_PLAN_PAYMENT_LINK,
GPT4_CREDIT_PURCHASE_LINKS,
AI_IMAGE_CREDIT_PURCHASE_LINKS,
V2_CHAT_UPGRADE_LINK,
} from './stripe_config';

export const DEFAULT_SYSTEM_PROMPT =
"You are an AI language model named Chat Everywhere, designed to answer user questions as accurately and helpfully as possible. Always be aware of the current date and time, and make sure to generate responses in the exact same language as the user's query. Adapt your responses to match the user's input language and context, maintaining an informative and supportive communication style. Additionally, format all responses using Markdown syntax, regardless of the input format."
'If the input includes text such as [lang=xxx], the response should not include this text.'
Expand Down Expand Up @@ -108,40 122,3 @@ export const OrderedSubscriptionPlans: SubscriptionPlan[] = [
'ultra',
'edu',
];

export const ProPlanPaymentLink =
process.env.NEXT_PUBLIC_ENV === 'production'
? 'https://buy.stripe.com/8wM8Av2DM0u99fWfZ1'
: 'https://buy.stripe.com/test_4gw4hLcvq52Odt6fYY';

export const UltraPlanPaymentLink =
process.env.NEXT_PUBLIC_ENV === 'production'
? 'https://buy.stripe.com/8wM8Av2DM0u99fWfZ1' // TODO: Update the production link
: 'https://buy.stripe.com/test_00gcOhbrmgLwbkYdR0';

export const Gpt4CreditPurchaseLinks = {
'50': 'https://buy.stripe.com/28o03Z0vE3Glak09AJ',
'150': 'https://buy.stripe.com/cN2dUP6U2dgV0JqcMW',
'300': 'https://buy.stripe.com/dR6g2Xemu5Otcs83cn',
};
export const AiImageCreditPurchaseLinks = {
'100': 'https://buy.stripe.com/fZeg2Xdiq4Kp8bS9AT',
'500': 'https://buy.stripe.com/8wMg2XcemccR2Ry8wQ',
};

export const V2ChatUpgradeLink =
process.env.NEXT_PUBLIC_ENV === 'production'
? 'https://buy.stripe.com/4gw9Ez6U2gt71NudRd'
: 'https://buy.stripe.com/test_dR68y152Y7aWagUcMU';

// STRIPE CREDIT CODE
export const STRIPE_PLAN_CODE_GPT4_CREDIT = 'GPT4_CREDIT';
export const STRIPE_PLAN_CODE_IMAGE_CREDIT = 'IMAGE_CREDIT';

// STRIPE MONTHLY PLAN CODE
export const STRIPE_PLAN_CODE_MONTHLY_PRO_PLAN_SUBSCRIPTION =
'monthly_pro_plan_subscription';

// STRIPE ONE TIME PLAN CODE
export const STRIPE_PLAN_CODE_ONE_TIME_PRO_PLAN_FOR_1_MONTH =
'one_time_pro_plan_for_1_month';
31 changes: 31 additions & 0 deletions utils/app/paid_plan.ts
Original file line number Diff line number Diff line change
@@ -0,0 1,31 @@
import { PaidPlan, TopUpRequest } from '@/types/paid_plan';

import {
STRIPE_PLAN_CODE_GPT4_CREDIT,
STRIPE_PLAN_CODE_IMAGE_CREDIT,
STRIPE_PLAN_CODE_MONTHLY_PRO_PLAN_SUBSCRIPTION,
STRIPE_PLAN_CODE_MONTHLY_ULTRA_PLAN_SUBSCRIPTION,
STRIPE_PLAN_CODE_ONE_TIME_PRO_PLAN_FOR_1_MONTH,
STRIPE_PLAN_CODE_ONE_TIME_ULTRA_PLAN_FOR_1_MONTH,
} from './const';

export const getPaidPlan = (
planCode: string,
): PaidPlan | TopUpRequest | undefined => {
switch (planCode.toUpperCase()) {
case STRIPE_PLAN_CODE_MONTHLY_PRO_PLAN_SUBSCRIPTION.toUpperCase():
return PaidPlan.ProMonthly;
case STRIPE_PLAN_CODE_ONE_TIME_PRO_PLAN_FOR_1_MONTH.toUpperCase():
return PaidPlan.ProOneTime;
case STRIPE_PLAN_CODE_MONTHLY_ULTRA_PLAN_SUBSCRIPTION.toUpperCase():
return PaidPlan.UltraMonthly;
case STRIPE_PLAN_CODE_ONE_TIME_ULTRA_PLAN_FOR_1_MONTH.toUpperCase():
return PaidPlan.UltraOneTime;
case STRIPE_PLAN_CODE_IMAGE_CREDIT.toUpperCase():
return TopUpRequest.ImageCredit;
case STRIPE_PLAN_CODE_GPT4_CREDIT.toUpperCase():
return TopUpRequest.GPT4Credit;
default:
return undefined;
}
};
42 changes: 42 additions & 0 deletions utils/app/stripe_config.ts
Original file line number Diff line number Diff line change
@@ -0,0 1,42 @@
// P.S. All of the code below is used in the product payment link

// STRIPE CREDIT CODE
export const STRIPE_PLAN_CODE_GPT4_CREDIT = 'GPT4_CREDIT';
export const STRIPE_PLAN_CODE_IMAGE_CREDIT = 'IMAGE_CREDIT';

// STRIPE MONTHLY PLAN CODE
export const STRIPE_PLAN_CODE_MONTHLY_PRO_PLAN_SUBSCRIPTION =
'monthly_pro_plan_subscription';
export const STRIPE_PLAN_CODE_MONTHLY_ULTRA_PLAN_SUBSCRIPTION =
'monthly_ultra_plan_subscription';

// STRIPE ONE TIME PLAN CODE
export const STRIPE_PLAN_CODE_ONE_TIME_PRO_PLAN_FOR_1_MONTH =
'one_time_pro_plan_for_1_month';
export const STRIPE_PLAN_CODE_ONE_TIME_ULTRA_PLAN_FOR_1_MONTH =
'one_time_ultra_plan_for_1_month';

export const PRO_PLAN_PAYMENT_LINK =
process.env.NEXT_PUBLIC_ENV === 'production'
? 'https://buy.stripe.com/8wM8Av2DM0u99fWfZ1'
: 'https://buy.stripe.com/test_4gw4hLcvq52Odt6fYY';

export const ULTRA_PLAN_PAYMENT_LINK =
process.env.NEXT_PUBLIC_ENV === 'production'
? 'https://buy.stripe.com/8wM8Av2DM0u99fWfZ1' // TODO: Update the production link
: 'https://buy.stripe.com/test_00gcOhbrmgLwbkYdR0';

export const GPT4_CREDIT_PURCHASE_LINKS = {
'50': 'https://buy.stripe.com/28o03Z0vE3Glak09AJ',
'150': 'https://buy.stripe.com/cN2dUP6U2dgV0JqcMW',
'300': 'https://buy.stripe.com/dR6g2Xemu5Otcs83cn',
};
export const AI_IMAGE_CREDIT_PURCHASE_LINKS = {
'100': 'https://buy.stripe.com/fZeg2Xdiq4Kp8bS9AT',
'500': 'https://buy.stripe.com/8wMg2XcemccR2Ry8wQ',
};

export const V2_CHAT_UPGRADE_LINK =
process.env.NEXT_PUBLIC_ENV === 'production'
? 'https://buy.stripe.com/4gw9Ez6U2gt71NudRd'
: 'https://buy.stripe.com/test_dR68y152Y7aWagUcMU';