Browse Source
Bugfix/coupon validation in Stripe checkout session (#7877)
Fix coupon validation
pull/7878/head
Thomas Kaul
2 days ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with
9 additions and
3 deletions
-
apps/api/src/app/subscription/subscription.service.ts
|
|
@ -58,17 +58,23 @@ export class SubscriptionService { |
|
|
} = |
|
|
} = |
|
|
(await this.propertyService.getByKey<any>(PROPERTY_STRIPE_CONFIG)) ?? {}; |
|
|
(await this.propertyService.getByKey<any>(PROPERTY_STRIPE_CONFIG)) ?? {}; |
|
|
|
|
|
|
|
|
const subscriptionOffer = Object.values(subscriptionOffers).find( |
|
|
const subscriptionOffersForPrice = Object.values(subscriptionOffers).filter( |
|
|
(subscriptionOffer) => { |
|
|
(subscriptionOffer) => { |
|
|
return subscriptionOffer.priceId === priceId; |
|
|
return subscriptionOffer.priceId === priceId; |
|
|
} |
|
|
} |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
if (!subscriptionOffer) { |
|
|
if (subscriptionOffersForPrice.length === 0) { |
|
|
throw new BadRequestException('Invalid priceId'); |
|
|
throw new BadRequestException('Invalid priceId'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (couponId && couponId !== subscriptionOffer.couponId) { |
|
|
const subscriptionOffer = subscriptionOffersForPrice.find( |
|
|
|
|
|
(subscriptionOffer) => { |
|
|
|
|
|
return subscriptionOffer.couponId === couponId; |
|
|
|
|
|
} |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
if (!subscriptionOffer) { |
|
|
throw new BadRequestException('Invalid couponId'); |
|
|
throw new BadRequestException('Invalid couponId'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|