|
|
@ -53,32 +53,13 @@ export class SubscriptionService { |
|
|
priceId: string; |
|
|
priceId: string; |
|
|
user: UserWithSettings; |
|
|
user: UserWithSettings; |
|
|
}): Promise<CreateStripeCheckoutSessionResponse> { |
|
|
}): Promise<CreateStripeCheckoutSessionResponse> { |
|
|
if (!priceId) { |
|
|
const subscriptionOffer = user.subscription?.offer; |
|
|
throw new BadRequestException('Invalid priceId'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const subscriptionOffers: { |
|
|
|
|
|
[offer in SubscriptionOfferKey]: SubscriptionOffer; |
|
|
|
|
|
} = |
|
|
|
|
|
(await this.propertyService.getByKey<any>(PROPERTY_STRIPE_CONFIG)) ?? {}; |
|
|
|
|
|
|
|
|
|
|
|
const subscriptionOffersForPrice = Object.values(subscriptionOffers).filter( |
|
|
if (!priceId || subscriptionOffer?.priceId !== priceId) { |
|
|
(subscriptionOffer) => { |
|
|
|
|
|
return subscriptionOffer.priceId === priceId; |
|
|
|
|
|
} |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
if (subscriptionOffersForPrice.length === 0) { |
|
|
|
|
|
throw new BadRequestException('Invalid priceId'); |
|
|
throw new BadRequestException('Invalid priceId'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const subscriptionOffer = subscriptionOffersForPrice.find( |
|
|
if (subscriptionOffer.couponId !== couponId) { |
|
|
(subscriptionOffer) => { |
|
|
|
|
|
return subscriptionOffer.couponId === couponId; |
|
|
|
|
|
} |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
if (!subscriptionOffer) { |
|
|
|
|
|
throw new BadRequestException('Invalid couponId'); |
|
|
throw new BadRequestException('Invalid couponId'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|