1. Updated packages
2. Added comments to schema 3. Minor API updates
This commit is contained in:
@@ -4,11 +4,11 @@ import {
|
||||
CancelSubscriptionParamsSchema,
|
||||
CreateBillingCheckoutSchema,
|
||||
CreateBillingPortalSessionSchema,
|
||||
QueryBillingUsageSchema,
|
||||
ReportBillingUsageSchema,
|
||||
RetrieveCheckoutSessionSchema,
|
||||
UpdateSubscriptionParamsSchema,
|
||||
} from '../schema';
|
||||
import { QueryBillingUsageSchema } from '../schema/query-billing-usage.schema';
|
||||
|
||||
export abstract class BillingStrategyProviderService {
|
||||
abstract createBillingPortalSession(
|
||||
@@ -53,7 +53,7 @@ export abstract class BillingStrategyProviderService {
|
||||
value: number;
|
||||
}>;
|
||||
|
||||
abstract updateSubscription(
|
||||
abstract updateSubscriptionItem(
|
||||
params: z.infer<typeof UpdateSubscriptionParamsSchema>,
|
||||
): Promise<{
|
||||
success: boolean;
|
||||
|
||||
@@ -27,12 +27,12 @@
|
||||
"@kit/tailwind-config": "workspace:*",
|
||||
"@kit/tsconfig": "workspace:*",
|
||||
"@kit/ui": "workspace:^",
|
||||
"@supabase/supabase-js": "^2.42.6",
|
||||
"@types/react": "^18.2.79",
|
||||
"@supabase/supabase-js": "^2.42.7",
|
||||
"@types/react": "^18.3.1",
|
||||
"date-fns": "^3.6.0",
|
||||
"lucide-react": "^0.373.0",
|
||||
"lucide-react": "^0.376.0",
|
||||
"next": "14.2.3",
|
||||
"react": "18.2.0",
|
||||
"react": "18.3.1",
|
||||
"react-hook-form": "^7.51.3",
|
||||
"react-i18next": "^14.1.1",
|
||||
"zod": "^3.23.4"
|
||||
|
||||
@@ -44,10 +44,7 @@ class BillingGatewayService {
|
||||
async createCheckoutSession(
|
||||
params: z.infer<typeof CreateBillingCheckoutSchema>,
|
||||
) {
|
||||
const strategy = await BillingGatewayFactoryService.GetProviderStrategy(
|
||||
this.provider,
|
||||
);
|
||||
|
||||
const strategy = await this.getStrategy();
|
||||
const payload = CreateBillingCheckoutSchema.parse(params);
|
||||
|
||||
return strategy.createCheckoutSession(payload);
|
||||
@@ -61,10 +58,7 @@ class BillingGatewayService {
|
||||
async retrieveCheckoutSession(
|
||||
params: z.infer<typeof RetrieveCheckoutSessionSchema>,
|
||||
) {
|
||||
const strategy = await BillingGatewayFactoryService.GetProviderStrategy(
|
||||
this.provider,
|
||||
);
|
||||
|
||||
const strategy = await this.getStrategy();
|
||||
const payload = RetrieveCheckoutSessionSchema.parse(params);
|
||||
|
||||
return strategy.retrieveCheckoutSession(payload);
|
||||
@@ -78,10 +72,7 @@ class BillingGatewayService {
|
||||
async createBillingPortalSession(
|
||||
params: z.infer<typeof CreateBillingPortalSessionSchema>,
|
||||
) {
|
||||
const strategy = await BillingGatewayFactoryService.GetProviderStrategy(
|
||||
this.provider,
|
||||
);
|
||||
|
||||
const strategy = await this.getStrategy();
|
||||
const payload = CreateBillingPortalSessionSchema.parse(params);
|
||||
|
||||
return strategy.createBillingPortalSession(payload);
|
||||
@@ -95,10 +86,7 @@ class BillingGatewayService {
|
||||
async cancelSubscription(
|
||||
params: z.infer<typeof CancelSubscriptionParamsSchema>,
|
||||
) {
|
||||
const strategy = await BillingGatewayFactoryService.GetProviderStrategy(
|
||||
this.provider,
|
||||
);
|
||||
|
||||
const strategy = await this.getStrategy();
|
||||
const payload = CancelSubscriptionParamsSchema.parse(params);
|
||||
|
||||
return strategy.cancelSubscription(payload);
|
||||
@@ -110,10 +98,7 @@ class BillingGatewayService {
|
||||
* @param params
|
||||
*/
|
||||
async reportUsage(params: z.infer<typeof ReportBillingUsageSchema>) {
|
||||
const strategy = await BillingGatewayFactoryService.GetProviderStrategy(
|
||||
this.provider,
|
||||
);
|
||||
|
||||
const strategy = await this.getStrategy();
|
||||
const payload = ReportBillingUsageSchema.parse(params);
|
||||
|
||||
return strategy.reportUsage(payload);
|
||||
@@ -125,10 +110,7 @@ class BillingGatewayService {
|
||||
* @param params
|
||||
*/
|
||||
async queryUsage(params: z.infer<typeof QueryBillingUsageSchema>) {
|
||||
const strategy = await BillingGatewayFactoryService.GetProviderStrategy(
|
||||
this.provider,
|
||||
);
|
||||
|
||||
const strategy = await this.getStrategy();
|
||||
const payload = QueryBillingUsageSchema.parse(params);
|
||||
|
||||
return strategy.queryUsage(payload);
|
||||
@@ -141,12 +123,13 @@ class BillingGatewayService {
|
||||
async updateSubscriptionItem(
|
||||
params: z.infer<typeof UpdateSubscriptionParamsSchema>,
|
||||
) {
|
||||
const strategy = await BillingGatewayFactoryService.GetProviderStrategy(
|
||||
this.provider,
|
||||
);
|
||||
|
||||
const strategy = await this.getStrategy();
|
||||
const payload = UpdateSubscriptionParamsSchema.parse(params);
|
||||
|
||||
return strategy.updateSubscription(payload);
|
||||
return strategy.updateSubscriptionItem(payload);
|
||||
}
|
||||
|
||||
getStrategy() {
|
||||
return BillingGatewayFactoryService.GetProviderStrategy(this.provider);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,9 +25,9 @@
|
||||
"@kit/tailwind-config": "workspace:*",
|
||||
"@kit/tsconfig": "workspace:*",
|
||||
"@kit/ui": "workspace:^",
|
||||
"@types/react": "^18.2.79",
|
||||
"@types/react": "^18.3.1",
|
||||
"next": "14.2.3",
|
||||
"react": "18.2.0",
|
||||
"react": "18.3.1",
|
||||
"zod": "^3.23.4"
|
||||
},
|
||||
"eslintConfig": {
|
||||
|
||||
@@ -307,7 +307,7 @@ export class LemonSqueezyBillingStrategyService
|
||||
* @description Queries the usage of the metered billing
|
||||
* @param params
|
||||
*/
|
||||
async updateSubscription(
|
||||
async updateSubscriptionItem(
|
||||
params: z.infer<typeof UpdateSubscriptionParamsSchema>,
|
||||
) {
|
||||
const logger = await getLogger();
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
"dependencies": {
|
||||
"@stripe/react-stripe-js": "^2.7.0",
|
||||
"@stripe/stripe-js": "^3.3.0",
|
||||
"stripe": "^15.3.0"
|
||||
"stripe": "^15.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@kit/billing": "workspace:^",
|
||||
@@ -28,10 +28,10 @@
|
||||
"@kit/tailwind-config": "workspace:*",
|
||||
"@kit/tsconfig": "workspace:*",
|
||||
"@kit/ui": "workspace:^",
|
||||
"@types/react": "^18.2.79",
|
||||
"@types/react": "^18.3.1",
|
||||
"date-fns": "^3.6.0",
|
||||
"next": "14.2.3",
|
||||
"react": "18.2.0",
|
||||
"react": "18.3.1",
|
||||
"zod": "^3.23.4"
|
||||
},
|
||||
"eslintConfig": {
|
||||
|
||||
@@ -273,11 +273,11 @@ export class StripeBillingStrategyService
|
||||
}
|
||||
|
||||
/**
|
||||
* @name updateSubscription
|
||||
* @name updateSubscriptionItem
|
||||
* @description Updates a subscription
|
||||
* @param params
|
||||
*/
|
||||
async updateSubscription(
|
||||
async updateSubscriptionItem(
|
||||
params: z.infer<typeof UpdateSubscriptionParamsSchema>,
|
||||
) {
|
||||
const stripe = await this.stripeProvider();
|
||||
|
||||
Reference in New Issue
Block a user