feat(core): add upgrade success page (#4738)

This commit is contained in:
JimmFly
2023-10-27 15:49:32 +08:00
committed by GitHub
parent 35dbbe561a
commit af24334264
6 changed files with 213 additions and 19 deletions

View File

@@ -194,8 +194,7 @@ export class SubscriptionResolver {
const session = await this.service.createCheckoutSession({
user,
recurring,
// TODO: replace with frontend url
redirectUrl: `${this.config.baseUrl}/api/stripe/success`,
redirectUrl: `${this.config.baseUrl}/upgrade-success`,
});
if (!session.url) {

View File

@@ -1,20 +1,16 @@
import type { RawBodyRequest } from '@nestjs/common';
import {
Controller,
Get,
Logger,
NotAcceptableException,
Post,
Req,
} from '@nestjs/common';
import { EventEmitter2 } from '@nestjs/event-emitter';
import type { User } from '@prisma/client';
import type { Request } from 'express';
import Stripe from 'stripe';
import { Config } from '../../config';
import { PrismaService } from '../../prisma';
import { Auth, CurrentUser } from '../auth';
@Controller('/api/stripe')
export class StripeWebhook {
@@ -24,23 +20,11 @@ export class StripeWebhook {
constructor(
config: Config,
private readonly stripe: Stripe,
private readonly event: EventEmitter2,
private readonly db: PrismaService
private readonly event: EventEmitter2
) {
this.config = config.payment;
}
// just for test
@Auth()
@Get('/success')
async handleSuccess(@CurrentUser() user: User) {
return this.db.userSubscription.findUnique({
where: {
userId: user.id,
},
});
}
@Post('/webhook')
async handleWebhook(@Req() req: RawBodyRequest<Request>) {
// Check if webhook signing is configured.