manage facturation
This commit is contained in:
parent
948d661d30
commit
584f7bac57
@ -1,7 +1,7 @@
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
// import roleHandler from "@App/middlewares/RolesHandler";
|
||||
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 { validateOrReject } from "class-validator";
|
||||
import { Request, Response } from "express";
|
||||
@ -39,4 +39,22 @@ export default class StripeController extends ApiController {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -56,15 +56,6 @@ export default class SubscriptionsRepository extends BaseRepository {
|
||||
uid: subscription.office!.uid,
|
||||
},
|
||||
},
|
||||
seats: {
|
||||
create: subscription.seats!.map(seat => ({
|
||||
user: {
|
||||
connect: {
|
||||
uid: seat.user!.uid,
|
||||
},
|
||||
},
|
||||
})),
|
||||
},
|
||||
},
|
||||
};
|
||||
return this.model.create(createArgs);
|
||||
|
@ -14,23 +14,35 @@ export default class StripeService {
|
||||
return this.client;
|
||||
}
|
||||
|
||||
public async createCheckoutSession(subscription: Subscription) {
|
||||
const priceId = subscription.type === "STANDARD" ? this.variables.STRIPE_STANDARD_SUBSCRIPTION_PRICE_ID : this.variables.STRIPE_UNLIMITED_SUBSCRIPTION_PRICE_ID;
|
||||
return this.client.checkout.sessions.create({
|
||||
mode: "subscription",
|
||||
payment_method_types: ["card", "paypal"],
|
||||
billing_address_collection: "auto",
|
||||
line_items: [
|
||||
{
|
||||
price: priceId,
|
||||
quantity: subscription.nb_seats,
|
||||
},
|
||||
],
|
||||
success_url: this.variables.STRIPE_PAYMENT_SUCCESS_URL,
|
||||
cancel_url: this.variables.STRIPE_PAYMENT_CANCEL_URL,
|
||||
metadata: {
|
||||
subscription: JSON.stringify(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;
|
||||
return this.client.checkout.sessions.create({
|
||||
mode: "subscription",
|
||||
payment_method_types: ["card", "paypal"],
|
||||
billing_address_collection: "auto",
|
||||
line_items: [
|
||||
{
|
||||
price: priceId,
|
||||
quantity: subscription.nb_seats,
|
||||
},
|
||||
],
|
||||
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