@@ -2,7 +2,7 @@ import Razorpay from 'razorpay';
22import cuid from 'cuid' ;
33import { NextApiRequest , NextApiResponse } from 'next' ;
44
5- import { donationsBase , PaymentStatus , fundingsBase } from '../../services/airtable' ;
5+ import { donationsBase , PaymentStatus , fundingsBase , paymentsBase } from '../../services/airtable' ;
66import { getFinalAmount } from '../../utils' ;
77
88const RZP_KEY = process . env . NODE_ENV === 'development' ? process . env . RZP_TEST_KEY : process . env . RZP_LIVE_KEY ;
@@ -18,7 +18,7 @@ const razorpay = new Razorpay(rzpCredentials);
1818
1919export default async function handler ( req : NextApiRequest , res : NextApiResponse ) {
2020 try {
21- const { email, name, amount, phone, paymentMethod = 'Razorpay' , campaign } = req . body ;
21+ const { email, name, amount, phone, paymentMethod = 'Razorpay' , campaign, isPayment } = req . body ;
2222 const id = cuid ( ) ;
2323 const data : { id : string ; status : PaymentStatus } = await razorpay . orders . create ( {
2424 amount : getFinalAmount ( Number ( amount ) ) * 100 , // in paise
@@ -30,6 +30,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
3030 phone,
3131 name,
3232 campaign,
33+ isPayment
3334 } ,
3435 } ) ;
3536 if ( campaign ) {
@@ -48,6 +49,21 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
4849 } ,
4950 { typecast : true }
5051 ) ;
52+ } else if ( isPayment ) {
53+ await paymentsBase . create (
54+ {
55+ id,
56+ name,
57+ email,
58+ phone,
59+ paid_amount : Number ( amount ) ,
60+ payment_method : paymentMethod ,
61+ status : PaymentStatus . created ,
62+ order_id : data . id ,
63+ created_at : new Date ( ) . toISOString ( ) ,
64+ } ,
65+ { typecast : true }
66+ ) ;
5167 } else {
5268 await donationsBase . create (
5369 {
0 commit comments