mirror of
https://github.com/MAGICGrants/campaign-site.git
synced 2026-01-09 12:27:59 -05:00
fix: use correct stripe client for each fund on webhooks
This commit is contained in:
@@ -7,4 +7,4 @@ export const config = {
|
||||
},
|
||||
}
|
||||
|
||||
export default getStripeWebhookHandler(env.STRIPE_FIRO_WEBHOOK_SECRET)
|
||||
export default getStripeWebhookHandler('firo', env.STRIPE_FIRO_WEBHOOK_SECRET)
|
||||
|
||||
@@ -7,4 +7,4 @@ export const config = {
|
||||
},
|
||||
}
|
||||
|
||||
export default getStripeWebhookHandler(env.STRIPE_GENERAL_WEBHOOK_SECRET)
|
||||
export default getStripeWebhookHandler('general', env.STRIPE_GENERAL_WEBHOOK_SECRET)
|
||||
|
||||
@@ -7,4 +7,4 @@ export const config = {
|
||||
},
|
||||
}
|
||||
|
||||
export default getStripeWebhookHandler(env.STRIPE_MONERO_WEBHOOK_SECRET)
|
||||
export default getStripeWebhookHandler('monero', env.STRIPE_MONERO_WEBHOOK_SECRET)
|
||||
|
||||
@@ -7,4 +7,4 @@ export const config = {
|
||||
},
|
||||
}
|
||||
|
||||
export default getStripeWebhookHandler(env.STRIPE_PRIVACY_GUIDES_WEBHOOK_SECRET)
|
||||
export default getStripeWebhookHandler('privacyguides', env.STRIPE_PRIVACY_GUIDES_WEBHOOK_SECRET)
|
||||
|
||||
@@ -37,9 +37,9 @@ const btcpayApi = axios.create({
|
||||
|
||||
const stripe: Record<FundSlug, Stripe> = {
|
||||
monero: new Stripe(env.STRIPE_MONERO_SECRET_KEY, { apiVersion: '2024-04-10' }),
|
||||
firo: new Stripe(env.STRIPE_MONERO_SECRET_KEY, { apiVersion: '2024-04-10' }),
|
||||
privacyguides: new Stripe(env.STRIPE_MONERO_SECRET_KEY, { apiVersion: '2024-04-10' }),
|
||||
general: new Stripe(env.STRIPE_MONERO_SECRET_KEY, { apiVersion: '2024-04-10' }),
|
||||
firo: new Stripe(env.STRIPE_FIRO_SECRET_KEY, { apiVersion: '2024-04-10' }),
|
||||
privacyguides: new Stripe(env.STRIPE_PRIVACY_GUIDES_SECRET_KEY, { apiVersion: '2024-04-10' }),
|
||||
general: new Stripe(env.STRIPE_GENERAL_SECRET_KEY, { apiVersion: '2024-04-10' }),
|
||||
}
|
||||
|
||||
export { prisma, keycloak, transporter, btcpayApi, stripe }
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
import { FundSlug } from '@prisma/client'
|
||||
import Stripe from 'stripe'
|
||||
import getRawBody from 'raw-body'
|
||||
import dayjs from 'dayjs'
|
||||
|
||||
import { btcpayApi as _btcpayApi, prisma, stripe } from '../../server/services'
|
||||
import { btcpayApi as _btcpayApi, prisma, stripe as _stripe } from '../../server/services'
|
||||
import { DonationMetadata } from '../../server/types'
|
||||
import { sendDonationConfirmationEmail } from './mailing'
|
||||
|
||||
export function getStripeWebhookHandler(secret: string) {
|
||||
export function getStripeWebhookHandler(fundSlug: FundSlug, secret: string) {
|
||||
return async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
let event: Stripe.Event
|
||||
|
||||
@@ -15,7 +16,8 @@ export function getStripeWebhookHandler(secret: string) {
|
||||
const signature = req.headers['stripe-signature']
|
||||
|
||||
try {
|
||||
event = stripe.monero.webhooks.constructEvent(await getRawBody(req), signature!, secret)
|
||||
const stripe = _stripe[fundSlug]
|
||||
event = stripe.webhooks.constructEvent(await getRawBody(req), signature!, secret)
|
||||
} catch (err) {
|
||||
console.log(`⚠️ Webhook signature verification failed.`, (err as any).message)
|
||||
res.status(400).end()
|
||||
|
||||
Reference in New Issue
Block a user