From bba73644f1476bb850d37ef2e7b3ce6d40e9b3bf Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Fri, 26 Apr 2024 11:42:58 +0200 Subject: [PATCH] :sparkles: add taxes automatic --- .../common/StripeService/StripeService.ts | 67 +++++++++---------- 1 file changed, 31 insertions(+), 36 deletions(-) diff --git a/src/services/common/StripeService/StripeService.ts b/src/services/common/StripeService/StripeService.ts index eabfe670..72774210 100644 --- a/src/services/common/StripeService/StripeService.ts +++ b/src/services/common/StripeService/StripeService.ts @@ -16,45 +16,40 @@ export default class StripeService { } 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; - } + 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; - } + } 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"], - billing_address_collection: "auto", - line_items: [ - { - price: priceId, - quantity: subscription.type === "STANDARD" ? subscription.nb_seats : 1, - }, - ], - success_url: this.variables.APP_HOST + "/subscription/success", - cancel_url: this.variables.APP_HOST + "/subscription/error", - metadata: { - subscription: JSON.stringify(subscription), - env: this.variables.ENV, - }, - allow_promotion_codes: true, - }); - + } - + return this.client.checkout.sessions.create({ + mode: "subscription", + payment_method_types: ["card"], + billing_address_collection: "auto", + line_items: [ + { + price: priceId, + quantity: subscription.type === "STANDARD" ? subscription.nb_seats : 1, + }, + ], + success_url: this.variables.APP_HOST + "/subscription/success", + cancel_url: this.variables.APP_HOST + "/subscription/error", + metadata: { + subscription: JSON.stringify(subscription), + env: this.variables.ENV, + }, + allow_promotion_codes: true, + automatic_tax: { enabled: true }, + }); } public async getStripeSubscriptionByUid(subscriptionId: string) {