upd(config): change the way stripeAgeCheck is handled in config file
This commit is contained in:
parent
dbded3b68d
commit
b3b5872e3e
6 changed files with 26 additions and 20 deletions
|
|
@ -112,7 +112,7 @@ export class ServerService implements OnApplicationShutdown {
|
|||
fastify.register(this.fileServerService.createServer);
|
||||
fastify.register(this.activityPubServerService.createServer);
|
||||
// only enable stripe webhook if verification is enabled
|
||||
if (this.config.stripeVerify) fastify.register(this.stripeHookServerService.createServer, { prefix: '/stripe' });
|
||||
if (this.config.stripeAgeCheck?.enabled) fastify.register(this.stripeHookServerService.createServer, { prefix: '/stripe' });
|
||||
fastify.register(this.nodeinfoServerService.createServer);
|
||||
fastify.register(this.wellKnownServerService.createServer);
|
||||
fastify.register(this.oauth2ProviderService.createServer, { prefix: '/oauth' });
|
||||
|
|
|
|||
|
|
@ -41,7 +41,9 @@ export class StripeHookServerService {
|
|||
request: FastifyRequest,
|
||||
reply: FastifyReply,
|
||||
) {
|
||||
const stripe = new Stripe(this.config.stripeKey);
|
||||
if (!this.config.stripeAgeCheck) return reply.code(400);
|
||||
|
||||
const stripe = new Stripe(this.config.stripeAgeCheck.key);
|
||||
|
||||
if (request.rawBody == null) {
|
||||
// Bad request
|
||||
|
|
@ -63,7 +65,7 @@ export class StripeHookServerService {
|
|||
// Verify the event came from Stripe
|
||||
try {
|
||||
const sig = headers['stripe-signature']!;
|
||||
event = stripe.webhooks.constructEvent(body, sig, this.config.stripeHookKey);
|
||||
event = stripe.webhooks.constructEvent(body, sig, this.config.stripeAgeCheck.hookKey);
|
||||
} catch (err: any) {
|
||||
// On error, log and return the error message
|
||||
console.log(`❌ Error message: ${err.message}`);
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
private config: Config,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
if (!this.config.stripeVerify) throw new ApiError(meta.errors.stripeIsDisabled);
|
||||
if (!this.config.stripeAgeCheck?.enabled) throw new ApiError(meta.errors.stripeIsDisabled);
|
||||
|
||||
const userProfile = await this.usersRepository.findOne({
|
||||
where: {
|
||||
|
|
@ -61,7 +61,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
}
|
||||
});
|
||||
|
||||
const stripe = new Stripe(this.config.stripeKey);
|
||||
const stripe = new Stripe(this.config.stripeAgeCheck.key);
|
||||
|
||||
if (userProfile == null) {
|
||||
throw new ApiError(meta.errors.userIsDeleted);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue