Browse Source
			
			
			Feature/Improve subscription service (#3989)
			
				* Various improvements
			
			
				pull/3990/head
			
			
		 
		
			
				
					
						
						Thomas Kaul
					
					1 year ago
					
						
							committed by
							
								
								GitHub
							
						 
					
				 
				
			 
		 
		
			
				
					
					No known key found for this signature in database
					
						
							GPG Key ID: B5690EEEBB952194
						
					
				
			
		
		
		
	
		
			
				 6 changed files with 
15 additions and 
6 deletions
			 
			
		 
		
			
				- 
					
					
					 
					apps/api/src/app/subscription/subscription.controller.ts
				
 
			
				- 
					
					
					 
					apps/api/src/app/subscription/subscription.service.ts
				
 
			
				- 
					
					
					 
					apps/client/src/app/components/header/header.component.html
				
 
			
				- 
					
					
					 
					apps/client/src/app/components/user-account-membership/user-account-membership.html
				
 
			
				- 
					
					
					 
					apps/client/src/app/pages/pricing/pricing-page.html
				
 
			
				- 
					
					
					 
					libs/common/src/lib/types/subscription-offer.type.ts
				
 
			
		
		
			
			
			
			
			
			
				
				
					
						
							
								
									
	
		
			
				
					| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -113,7 +113,7 @@ export class SubscriptionController { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  @Post('stripe/checkout-session') | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  @UseGuards(AuthGuard('jwt'), HasPermissionGuard) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  public async createCheckoutSession( | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    @Body() { couponId, priceId }: { couponId: string; priceId: string } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    @Body() { couponId, priceId }: { couponId?: string; priceId: string } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  ) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    try { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      return this.subscriptionService.createCheckoutSession({ | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
				 | 
				
					
  | 
				
			
			
		
	
								
							
						
					 
					
				 
			 
		
			
			
			
			
			
			
				
				
					
						
							
								
									
	
		
			
				
					| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -124,7 +124,9 @@ export class SubscriptionService { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      let offer: SubscriptionOffer = price ? 'renewal' : 'default'; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      if (isBefore(createdAt, parseDate('2023-01-01'))) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        offer = 'renewal-early-bird'; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        offer = 'renewal-early-bird-2023'; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      } else if (isBefore(createdAt, parseDate('2024-01-01'))) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        offer = 'renewal-early-bird-2024'; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      return { | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
				 | 
				
					
  | 
				
			
			
		
	
								
							
						
					 
					
				 
			 
		
			
			
			
			
			
			
				
				
					
						
							
								
									
	
		
			
				
					| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -180,7 +180,8 @@ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    <ng-container i18n>Upgrade Plan</ng-container> | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                  } @else if ( | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    user.subscription.offer === 'renewal' || | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    user.subscription.offer === 'renewal-early-bird' | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    user.subscription.offer === 'renewal-early-bird-2023' || | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    user.subscription.offer === 'renewal-early-bird-2024' | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                  ) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    <ng-container i18n>Renew Plan</ng-container> | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                  } | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
				 | 
				
					
  | 
				
			
			
		
	
								
							
						
					 
					
				 
			 
		
			
			
			
			
			
			
				
				
					
						
							
								
									
	
		
			
				
					| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -16,7 +16,8 @@ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                  <ng-container i18n>Upgrade Plan</ng-container> | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                } @else if ( | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                  user.subscription.offer === 'renewal' || | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                  user.subscription.offer === 'renewal-early-bird' | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                  user.subscription.offer === 'renewal-early-bird-2023' || | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                  user.subscription.offer === 'renewal-early-bird-2024' | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                ) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                  <ng-container i18n>Renew Plan</ng-container> | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                } | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
				 | 
				
					
  | 
				
			
			
		
	
								
							
						
					 
					
				 
			 
		
			
			
			
			
			
			
				
				
					
						
							
								
									
	
		
			
				
					| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -278,7 +278,8 @@ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                      <ng-container i18n>Upgrade Plan</ng-container> | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    } @else if ( | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                      user.subscription.offer === 'renewal' || | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                      user.subscription.offer === 'renewal-early-bird' | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                      user.subscription.offer === 'renewal-early-bird-2023' || | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                      user.subscription.offer === 'renewal-early-bird-2024' | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    ) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                      <ng-container i18n>Renew Plan</ng-container> | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    } | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
				 | 
				
					
  | 
				
			
			
		
	
								
							
						
					 
					
				 
			 
		
			
			
			
			
			
			
				
				
					
						
							
								
									
	
		
			
				
					| 
						
						
						
					 | 
				
				 | 
				
					@ -1 +1,5 @@ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					export type SubscriptionOffer = 'default' | 'renewal' | 'renewal-early-bird'; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					export type SubscriptionOffer = | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  | 'default' | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  | 'renewal' | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  | 'renewal-early-bird-2023' | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  | 'renewal-early-bird-2024'; | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
					 | 
				
				 | 
				
					
  |