diff --git a/.config/docker_example.yml b/.config/docker_example.yml index 03bfa1b7de..99b0bb528c 100644 --- a/.config/docker_example.yml +++ b/.config/docker_example.yml @@ -298,9 +298,10 @@ checkActivityPubGetSignature: false # maxFileSize: 262144000 # enable stripe identity for ID verification -# stripeVerify: true -# stripeKey: sk_ -# stripeHookKey: whsec_ +#stripeAgeCheck: +# enabled: true +# key: sk_ +# hookKey: whsec_ # Upload or download file size limits (bytes) #maxFileSize: 262144000 diff --git a/.config/example.yml b/.config/example.yml index c92191e4e2..81b72938c0 100644 --- a/.config/example.yml +++ b/.config/example.yml @@ -313,9 +313,10 @@ checkActivityPubGetSignature: false # maxFileSize: 262144000 # enable stripe identity for ID verification -# stripeVerify: true -# stripeKey: sk_ -# stripeHookKey: whsec_ +#stripeAgeCheck: +# enabled: true +# key: sk_ +# hookKey: whsec_ # PID File of master process #pidFile: /tmp/misskey.pid diff --git a/packages/backend/src/config.ts b/packages/backend/src/config.ts index cebd46ea85..8af2410314 100644 --- a/packages/backend/src/config.ts +++ b/packages/backend/src/config.ts @@ -108,9 +108,11 @@ type Source = { maxFileSize: number; }; - stripeVerify?: boolean; - stripeKey?: string; - stripeHookKey?: string; + stripeAgeCheck?: { + enabled: boolean; + key: string; + hookKey: string; + }; pidFile: string; }; @@ -201,9 +203,11 @@ export type Config = { maxFileSize: number; } | undefined; - stripeVerify: boolean | undefined; - stripeKey: string; - stripeHookKey: string; + stripeAgeCheck: { + enabled: boolean | undefined; + key: string; + hookKey: string; + } | undefined; pidFile: string; }; @@ -327,9 +331,7 @@ export function loadConfig(): Config { perUserNotificationsMaxCount: config.perUserNotificationsMaxCount ?? 500, deactivateAntennaThreshold: config.deactivateAntennaThreshold ?? (1000 * 60 * 60 * 24 * 7), import: config.import, - stripeVerify: config.stripeVerify ?? false, - stripeKey: config.stripeKey ?? '', - stripeHookKey: config.stripeHookKey ?? '', + stripeAgeCheck: config.stripeAgeCheck, pidFile: config.pidFile, }; } diff --git a/packages/backend/src/server/ServerService.ts b/packages/backend/src/server/ServerService.ts index 2ab2e7152e..ef60283f08 100644 --- a/packages/backend/src/server/ServerService.ts +++ b/packages/backend/src/server/ServerService.ts @@ -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' }); diff --git a/packages/backend/src/server/StripeHookServerService.ts b/packages/backend/src/server/StripeHookServerService.ts index ebb1c53db7..9f3afc29dc 100644 --- a/packages/backend/src/server/StripeHookServerService.ts +++ b/packages/backend/src/server/StripeHookServerService.ts @@ -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}`); diff --git a/packages/backend/src/server/api/endpoints/stripe/create-verify-session.ts b/packages/backend/src/server/api/endpoints/stripe/create-verify-session.ts index 1978167c2c..de42a3cda5 100644 --- a/packages/backend/src/server/api/endpoints/stripe/create-verify-session.ts +++ b/packages/backend/src/server/api/endpoints/stripe/create-verify-session.ts @@ -53,7 +53,7 @@ export default class extends Endpoint { // 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 { // 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);