Merge branch 'dev' into staging

This commit is contained in:
Maxime Lalo 2024-04-05 15:34:17 +02:00
commit 4eac51bf65
2 changed files with 32 additions and 10 deletions

View File

@ -19,12 +19,12 @@ export default class StripeController extends ApiController {
* @description Create a new checkout session
*/
@Post("/api/v1/admin/stripe", [authHandler])
protected async post(req: Request, response: Response) {
protected async createStripeSubscriptionCheckout(req: Request, response: Response) {
try {
const officeId: string = req.body.user.office_Id;
//add office id to request body
req.body.office = {uid: officeId};
req.body.office = { uid: officeId };
//init Subscription resource with request body values
const subscriptionEntity = Subscription.hydrate<Subscription>(req.body, { strategy: "excludeAll" });
@ -41,7 +41,7 @@ export default class StripeController extends ApiController {
}
@Get("/api/v1/admin/stripe/:uid", [authHandler])
protected async get(req: Request, response: Response) {
protected async getClientPortalSession(req: Request, response: Response) {
try {
const uid = req.params["uid"];
if (!uid) {
@ -57,4 +57,21 @@ export default class StripeController extends ApiController {
return;
}
}
@Get("/api/v1/admin/stripe/:uid/customer")
protected async getCustomerBySubscription(req: Request, response: Response) {
try {
const uid = req.params["uid"];
if (!uid) {
this.httpBadRequest(response, "No uid provided");
return;
}
const customer = await this.stripeService.getCustomerBySubscription(uid);
this.httpSuccess(response, customer);
} catch (error) {
this.httpInternalError(response, error);
return;
}
}
}

View File

@ -26,7 +26,7 @@ export default class StripeService {
line_items: [
{
price: priceId,
quantity: subscription.nb_seats,
quantity: subscription.type === "STANDARD" ? subscription.nb_seats : 1,
},
],
success_url: this.variables.APP_HOST + "/subscription/success",
@ -45,4 +45,9 @@ export default class StripeService {
return_url: this.variables.APP_HOST + "/subscription/manage",
});
}
public async getCustomerBySubscription(subscriptionId: string) {
const subscription = await this.client.subscriptions.retrieve(subscriptionId);
return this.client.customers.retrieve(subscription.customer as string);
}
}