mirror of
https://github.com/MAGICGrants/campaign-site.git
synced 2026-01-09 12:27:59 -05:00
fix: correctly handle btcpay webhooks and fix donationList query
This commit is contained in:
@@ -66,13 +66,14 @@ export default async function handler(
|
||||
|
||||
await prisma.cryptoDonation.create({
|
||||
data: {
|
||||
userId: invoiceMetadata.userId,
|
||||
userId: invoiceMetadata.userId as string,
|
||||
invoiceId: body.invoiceId,
|
||||
crypto: 'XMR',
|
||||
projectName: invoiceMetadata.projectName,
|
||||
projectSlug: invoiceMetadata.projectSlug,
|
||||
fund: 'Monero Fund',
|
||||
fiatAmount: parseFloat(invoice.amount),
|
||||
status: 'Settled',
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -165,16 +165,18 @@ export const donationRouter = router({
|
||||
|
||||
const donations: Donation[] = []
|
||||
|
||||
if (!stripeCustomerId) {
|
||||
return { donations: [], billingPortalUrl: null }
|
||||
// TODO: Paginate?
|
||||
let stripePayments: Stripe.PaymentIntent[] = []
|
||||
|
||||
if (stripeCustomerId) {
|
||||
stripePayments = (
|
||||
await stripe.paymentIntents.list({
|
||||
customer: stripeCustomerId,
|
||||
})
|
||||
).data
|
||||
}
|
||||
|
||||
// TODO: Paginate?
|
||||
const stripePayments = await stripe.paymentIntents.list({
|
||||
customer: stripeCustomerId,
|
||||
})
|
||||
|
||||
stripePayments.data.forEach((payment) => {
|
||||
stripePayments.forEach((payment) => {
|
||||
// Filter out subscriptions as paymentIntents returns an empty metadata obj
|
||||
if (payment.invoice) return
|
||||
|
||||
@@ -266,14 +268,20 @@ export const donationRouter = router({
|
||||
new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()
|
||||
)
|
||||
|
||||
const billingPortalSession = await stripe.billingPortal.sessions.create({
|
||||
customer: stripeCustomerId,
|
||||
return_url: `${env.APP_URL}/account/my-donations`,
|
||||
})
|
||||
let billingPortalUrl: string | null = null
|
||||
|
||||
if (stripeCustomerId) {
|
||||
const billingPortalSession = await stripe.billingPortal.sessions.create({
|
||||
customer: stripeCustomerId,
|
||||
return_url: `${env.APP_URL}/account/my-donations`,
|
||||
})
|
||||
|
||||
billingPortalUrl = billingPortalSession.url
|
||||
}
|
||||
|
||||
return {
|
||||
donations: donationsSorted,
|
||||
billingPortalUrl: billingPortalSession.url,
|
||||
billingPortalUrl,
|
||||
}
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -8,12 +8,18 @@ import { env } from '../env.mjs'
|
||||
|
||||
sendgrid.setApiKey(env.SENDGRID_API_KEY)
|
||||
|
||||
const prisma = new PrismaClient({
|
||||
log:
|
||||
process.env.NODE_ENV === 'production'
|
||||
? ['error']
|
||||
: ['query', 'info', 'warn', 'error'],
|
||||
})
|
||||
const globalForPrisma = global as unknown as { prisma: PrismaClient }
|
||||
|
||||
const prisma =
|
||||
globalForPrisma.prisma ||
|
||||
new PrismaClient({
|
||||
log:
|
||||
process.env.NODE_ENV === 'production'
|
||||
? ['error']
|
||||
: ['query', 'info', 'warn', 'error'],
|
||||
})
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma
|
||||
|
||||
const keycloak = new KeycloakAdminClient({
|
||||
baseUrl: 'http://localhost:8080',
|
||||
|
||||
Reference in New Issue
Block a user