File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { serve } from '@hono/node-server'
22import { Hono } from 'hono'
33import plansRouter from './routes/plans.js'
44import { showRoutes } from 'hono/dev'
5+ import transactionRouter from './routes/transaction.js'
56
67const app = new Hono ( )
78
@@ -10,6 +11,7 @@ app.get('/', (c) => {
1011} )
1112
1213app . route ( "/plan" , plansRouter )
14+ app . route ( "/transaction" , transactionRouter )
1315
1416// To list all routes
1517showRoutes ( app )
Original file line number Diff line number Diff line change 1+ import 'dotenv/config' ;
2+ import { Hono } from "hono" ;
3+ import { db } from '../db.js' ;
4+ import { zValidator } from '@hono/zod-validator' ;
5+ import { Transaction } from '../schema/index.js' ;
6+
7+ const transactionRouter = new Hono ( )
8+
9+ transactionRouter . post ( "/initialize" ,
10+ zValidator ( 'json' , Transaction ) ,
11+ async ( c ) => {
12+ const validateReq = c . req . valid ( 'json' )
13+ const api = await fetch ( `${ process . env . PAYSTACK_BASE_URL } /transaction/initialize` , {
14+ method : "POST" ,
15+ headers : {
16+ "Authorization" : `Bearer ${ process . env . PAYSTACK_SECRET_KEY } ` ,
17+ 'Content-Type' : "application/json"
18+ } ,
19+ body : JSON . stringify ( validateReq )
20+ } )
21+
22+ const response = await api . json ( )
23+
24+ if ( ! response [ "status" ] ) {
25+ return c . json ( {
26+ status : false ,
27+ data : { }
28+ } , 500 )
29+ }
30+
31+ return c . json ( {
32+ status : true ,
33+ data : response
34+ } , 200 )
35+ }
36+ )
37+
38+
39+ export default transactionRouter
Original file line number Diff line number Diff line change @@ -12,4 +12,10 @@ export const PlanUpdate = z.object({
1212 amount : z . number ( ) . optional ( ) ,
1313 interval : z . string ( ) . optional ( ) ,
1414 update_existing_subscriptions : z . boolean ( ) . optional ( )
15- } ) ;
15+ } ) ;
16+
17+ export const Transaction = z . object ( {
18+ email : z . email ( ) ,
19+ amount : z . number ( ) ,
20+ plan : z . string ( )
21+ } )
You can’t perform that action at this time.
0 commit comments