-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroute.ts
More file actions
35 lines (31 loc) · 1001 Bytes
/
route.ts
File metadata and controls
35 lines (31 loc) · 1001 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import stripe from "@/utils/stripe";
import { NextRequest, NextResponse } from "next/server";
export async function POST(request: NextRequest) {
try {
const { customerId, amount, itemId } = await request.json();
if (!customerId || !amount || !itemId) {
return NextResponse.json(
{ error: "Missing information" },
{ status: 400 },
);
}
const setupIntent = await stripe.setupIntents.create({
customer: customerId,
payment_method_types: ["card"],
usage: "on_session",
metadata: {
item_id: itemId,
bid_amount_gbp: (amount / 100).toFixed(2),
reason: `Bid authorization for item ${itemId}`,
},
description: `Authorize card for bid on item ${itemId}`,
});
return NextResponse.json({
success: true,
clientSecret: setupIntent.client_secret,
});
} catch (error) {
console.error(error);
return NextResponse.json({ error: "An error occurred" }, { status: 500 });
}
}