37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
// 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 StripeService from "@Services/common/StripeService/StripeService";
|
|
import { validateOrReject } from "class-validator";
|
|
import { Request, Response } from "express";
|
|
import { Subscription } from "le-coffre-resources/dist/Admin";
|
|
import { Service } from "typedi";
|
|
|
|
@Controller()
|
|
@Service()
|
|
export default class StripeController extends ApiController {
|
|
constructor(private stripeService: StripeService) {
|
|
super();
|
|
}
|
|
|
|
/**
|
|
* @description Create a new checkout session
|
|
*/
|
|
@Post("/api/v1/admin/stripe")
|
|
protected async post(req: Request, response: Response) {
|
|
try {
|
|
//init Subscription resource with request body values
|
|
const subscriptionEntity = Subscription.hydrate<Subscription>(req.body);
|
|
|
|
await validateOrReject(subscriptionEntity, { groups: ["createSubscription"], forbidUnknownValues: false });
|
|
|
|
const stripeSession = await this.stripeService.createCheckoutSession(subscriptionEntity);
|
|
|
|
this.httpCreated(response, stripeSession);
|
|
} catch (error) {
|
|
this.httpInternalError(response, error);
|
|
return;
|
|
}
|
|
}
|
|
} |