Thomas Kaul
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
8 additions and
4 deletions
-
apps/api/src/app/subscription/subscription.controller.ts
-
apps/api/src/app/subscription/subscription.service.ts
|
|
@ -70,7 +70,9 @@ export class SubscriptionController { |
|
|
|
value: JSON.stringify(coupons) |
|
|
|
}); |
|
|
|
|
|
|
|
Logger.log(`Coupon with code '${couponCode}' has been redeemed`); |
|
|
|
Logger.log( |
|
|
|
`Subscription for user '${this.request.user.id}' has been created with coupon` |
|
|
|
); |
|
|
|
|
|
|
|
res.status(StatusCodes.OK); |
|
|
|
|
|
|
@ -82,10 +84,12 @@ export class SubscriptionController { |
|
|
|
|
|
|
|
@Get('stripe/callback') |
|
|
|
public async stripeCallback(@Req() req, @Res() res) { |
|
|
|
await this.subscriptionService.createSubscriptionViaStripe( |
|
|
|
const userId = await this.subscriptionService.createSubscriptionViaStripe( |
|
|
|
req.query.checkoutSessionId |
|
|
|
); |
|
|
|
|
|
|
|
Logger.log(`Subscription for user '${userId}' has been created via Stripe`); |
|
|
|
|
|
|
|
res.redirect(`${this.configurationService.get('ROOT_URL')}/account`); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -75,8 +75,6 @@ export class SubscriptionService { |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
Logger.log(`Subscription for user '${aUserId}' has been created`); |
|
|
|
} |
|
|
|
|
|
|
|
public async createSubscriptionViaStripe(aCheckoutSessionId: string) { |
|
|
@ -90,6 +88,8 @@ export class SubscriptionService { |
|
|
|
await this.stripe.customers.update(session.customer as string, { |
|
|
|
description: session.client_reference_id |
|
|
|
}); |
|
|
|
|
|
|
|
return session.client_reference_id; |
|
|
|
} catch (error) { |
|
|
|
Logger.error(error); |
|
|
|
} |
|
|
|