manage facturation
This commit is contained in:
parent
948d661d30
commit
584f7bac57
@ -1,7 +1,7 @@
|
|||||||
import authHandler from "@App/middlewares/AuthHandler";
|
import authHandler from "@App/middlewares/AuthHandler";
|
||||||
// import roleHandler from "@App/middlewares/RolesHandler";
|
// import roleHandler from "@App/middlewares/RolesHandler";
|
||||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||||
import { Controller, Post } from "@ControllerPattern/index";
|
import { Controller, Get, Post } from "@ControllerPattern/index";
|
||||||
import StripeService from "@Services/common/StripeService/StripeService";
|
import StripeService from "@Services/common/StripeService/StripeService";
|
||||||
import { validateOrReject } from "class-validator";
|
import { validateOrReject } from "class-validator";
|
||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
@ -39,4 +39,22 @@ export default class StripeController extends ApiController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get("/api/v1/admin/stripe/:uid", [authHandler])
|
||||||
|
protected async get(req: Request, response: Response) {
|
||||||
|
try {
|
||||||
|
const uid = req.params["uid"];
|
||||||
|
if (!uid) {
|
||||||
|
this.httpBadRequest(response, "No uid provided");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const client_portal = await this.stripeService.createClientPortalSession(uid);
|
||||||
|
|
||||||
|
this.httpSuccess(response, client_portal);
|
||||||
|
} catch (error) {
|
||||||
|
this.httpInternalError(response, error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -40,7 +40,7 @@ export default class SubscriptionsRepository extends BaseRepository {
|
|||||||
/**
|
/**
|
||||||
* @description : Create a subscription
|
* @description : Create a subscription
|
||||||
*/
|
*/
|
||||||
public async create(subscription: Subscription): Promise<Subscriptions> {
|
public async create(subscription: Subscription): Promise<Subscriptions> {
|
||||||
if(subscription.type === "STANDARD")
|
if(subscription.type === "STANDARD")
|
||||||
{
|
{
|
||||||
const createArgs: Prisma.SubscriptionsCreateArgs = {
|
const createArgs: Prisma.SubscriptionsCreateArgs = {
|
||||||
@ -56,15 +56,6 @@ export default class SubscriptionsRepository extends BaseRepository {
|
|||||||
uid: subscription.office!.uid,
|
uid: subscription.office!.uid,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
seats: {
|
|
||||||
create: subscription.seats!.map(seat => ({
|
|
||||||
user: {
|
|
||||||
connect: {
|
|
||||||
uid: seat.user!.uid,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
return this.model.create(createArgs);
|
return this.model.create(createArgs);
|
||||||
|
@ -14,23 +14,35 @@ export default class StripeService {
|
|||||||
return this.client;
|
return this.client;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async createCheckoutSession(subscription: Subscription) {
|
public async createCheckoutSession(subscription: Subscription) {
|
||||||
const priceId = subscription.type === "STANDARD" ? this.variables.STRIPE_STANDARD_SUBSCRIPTION_PRICE_ID : this.variables.STRIPE_UNLIMITED_SUBSCRIPTION_PRICE_ID;
|
const priceId =
|
||||||
return this.client.checkout.sessions.create({
|
subscription.type === "STANDARD"
|
||||||
mode: "subscription",
|
? this.variables.STRIPE_STANDARD_SUBSCRIPTION_PRICE_ID
|
||||||
payment_method_types: ["card", "paypal"],
|
: this.variables.STRIPE_UNLIMITED_SUBSCRIPTION_PRICE_ID;
|
||||||
billing_address_collection: "auto",
|
return this.client.checkout.sessions.create({
|
||||||
line_items: [
|
mode: "subscription",
|
||||||
{
|
payment_method_types: ["card", "paypal"],
|
||||||
price: priceId,
|
billing_address_collection: "auto",
|
||||||
quantity: subscription.nb_seats,
|
line_items: [
|
||||||
},
|
{
|
||||||
],
|
price: priceId,
|
||||||
success_url: this.variables.STRIPE_PAYMENT_SUCCESS_URL,
|
quantity: subscription.nb_seats,
|
||||||
cancel_url: this.variables.STRIPE_PAYMENT_CANCEL_URL,
|
},
|
||||||
metadata: {
|
],
|
||||||
subscription: JSON.stringify(subscription),
|
success_url: this.variables.STRIPE_PAYMENT_SUCCESS_URL,
|
||||||
},
|
cancel_url: this.variables.STRIPE_PAYMENT_CANCEL_URL,
|
||||||
});
|
metadata: {
|
||||||
}
|
subscription: JSON.stringify(subscription),
|
||||||
}
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public async createClientPortalSession(subscriptionId: string) {
|
||||||
|
const subscription = await this.client.subscriptions.retrieve(subscriptionId);
|
||||||
|
|
||||||
|
return this.client.billingPortal.sessions.create({
|
||||||
|
customer: subscription.customer as string,
|
||||||
|
return_url: this.variables.STRIPE_PAYMENT_SUCCESS_URL,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user