Refactor: Fully migrated to direct PostgreSQL, implemented Public API v1, fixed Vercel deployment conflicts, and updated documentation
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { stripe } from '@/lib/stripe';
|
||||
import { supabaseAdmin } from '@/lib/supabase-admin';
|
||||
import { db } from '@/lib/db';
|
||||
|
||||
const webhookSecret = process.env.STRIPE_WEBHOOK_SECRET!;
|
||||
|
||||
@@ -36,15 +36,14 @@ export async function POST(req: NextRequest) {
|
||||
|
||||
async function handlePaymentSucceeded(paymentIntent: any) {
|
||||
// 1. Update status in our DB
|
||||
const { data: transaction, error: updateError } = await supabaseAdmin
|
||||
.from('transactions')
|
||||
.update({ status: 'succeeded' })
|
||||
.eq('stripe_pi_id', paymentIntent.id)
|
||||
.select('*')
|
||||
.single();
|
||||
const result = await db.query(
|
||||
'UPDATE transactions SET status = $1 WHERE stripe_pi_id = $2 RETURNING *',
|
||||
['succeeded', paymentIntent.id]
|
||||
);
|
||||
const transaction = result.rows[0];
|
||||
|
||||
if (updateError) {
|
||||
console.error('Error updating transaction success:', updateError);
|
||||
if (!transaction) {
|
||||
console.error('Transaction not found for success webhook:', paymentIntent.id);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -78,12 +77,8 @@ async function handlePaymentSucceeded(paymentIntent: any) {
|
||||
}
|
||||
|
||||
async function handlePaymentFailed(paymentIntent: any) {
|
||||
const { error } = await supabaseAdmin
|
||||
.from('transactions')
|
||||
.update({ status: 'failed' })
|
||||
.eq('stripe_pi_id', paymentIntent.id);
|
||||
|
||||
if (error) {
|
||||
console.error('Error updating transaction failure:', error);
|
||||
}
|
||||
await db.query(
|
||||
'UPDATE transactions SET status = $1 WHERE stripe_pi_id = $2',
|
||||
['failed', paymentIntent.id]
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user