Skip to content

Commit 1cee52d

Browse files
feat: implement transaction
1 parent 16332f0 commit 1cee52d

3 files changed

Lines changed: 48 additions & 1 deletion

File tree

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { serve } from '@hono/node-server'
22
import { Hono } from 'hono'
33
import plansRouter from './routes/plans.js'
44
import { showRoutes } from 'hono/dev'
5+
import transactionRouter from './routes/transaction.js'
56

67
const app = new Hono()
78

@@ -10,6 +11,7 @@ app.get('/', (c) => {
1011
})
1112

1213
app.route("/plan", plansRouter)
14+
app.route("/transaction", transactionRouter)
1315

1416
// To list all routes
1517
showRoutes(app)

src/routes/transaction.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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

src/schema/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff 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+
})

0 commit comments

Comments
 (0)