Merge branch 'preprod'
This commit is contained in:
commit
b5f4e23826
@ -59,7 +59,7 @@
|
||||
"file-type-checker": "^1.0.8",
|
||||
"fp-ts": "^2.16.1",
|
||||
"jsonwebtoken": "^9.0.0",
|
||||
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.132",
|
||||
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.134",
|
||||
"module-alias": "^2.2.2",
|
||||
"monocle-ts": "^2.3.13",
|
||||
"multer": "^1.4.5-lts.1",
|
||||
|
@ -7,6 +7,7 @@ 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 { EPaymentFrequency } from "le-coffre-resources/dist/Admin/Subscription";
|
||||
import { Service } from "typedi";
|
||||
|
||||
@Controller()
|
||||
@ -27,12 +28,18 @@ export default class StripeController extends ApiController {
|
||||
//add office id to request body
|
||||
req.body.office = { uid: officeId };
|
||||
|
||||
const frequency : EPaymentFrequency = req.body.frequency;
|
||||
if(!frequency || !Object.values(EPaymentFrequency).includes(frequency)) {
|
||||
this.httpBadRequest(response, "Invalid frequency");
|
||||
return;
|
||||
}
|
||||
|
||||
//init Subscription resource with request body values
|
||||
const subscriptionEntity = Subscription.hydrate<Subscription>(req.body, { strategy: "excludeAll" });
|
||||
|
||||
await validateOrReject(subscriptionEntity, { groups: ["createSubscription"], forbidUnknownValues: false });
|
||||
|
||||
const stripeSession = await this.stripeService.createCheckoutSession(subscriptionEntity);
|
||||
const stripeSession = await this.stripeService.createCheckoutSession(subscriptionEntity, frequency);
|
||||
|
||||
this.httpCreated(response, stripeSession);
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { BackendVariables } from "@Common/config/variables/Variables";
|
||||
import { Subscription } from "le-coffre-resources/dist/Admin";
|
||||
import { EPaymentFrequency } from "le-coffre-resources/dist/Admin/Subscription";
|
||||
import Stripe from "stripe";
|
||||
import { Service } from "typedi";
|
||||
|
||||
@ -14,8 +15,25 @@ 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;
|
||||
public async createCheckoutSession(subscription: Subscription, frequency: EPaymentFrequency) {
|
||||
let priceId = this.variables.STRIPE_UNLIMITED_SUBSCRIPTION_PRICE_ID;
|
||||
if(subscription.type === "STANDARD") {
|
||||
if(frequency === EPaymentFrequency.Yearly) {
|
||||
priceId = this.variables.STRIPE_STANDARD_ANNUAL_SUBSCRIPTION_PRICE_ID;
|
||||
}
|
||||
else{
|
||||
priceId = this.variables.STRIPE_STANDARD_SUBSCRIPTION_PRICE_ID;
|
||||
}
|
||||
}
|
||||
else if(subscription.type === "UNLIMITED") {
|
||||
if(frequency === EPaymentFrequency.Yearly) {
|
||||
priceId = this.variables.STRIPE_UNLIMITED_ANNUAL_SUBSCRIPTION_PRICE_ID;
|
||||
}
|
||||
else{
|
||||
priceId = this.variables.STRIPE_UNLIMITED_SUBSCRIPTION_PRICE_ID;
|
||||
}
|
||||
}
|
||||
|
||||
return this.client.checkout.sessions.create({
|
||||
mode: "subscription",
|
||||
payment_method_types: ["card"],
|
||||
|
Loading…
x
Reference in New Issue
Block a user