Loading...
Loading...
Toss Payments, Stripe 등 최신 결제 시스템을 Next.js에 통합하는 스킬. 정기결제, 보안 결제, 웹훅 처리를 전문적으로 다룹니다.
npx skill4agent add kyuhyi/bsd_claude_skills payment-integrationimport { NextResponse } from "next/server";
export async function POST(req: Request) {
const { paymentKey, orderId, amount } = await req.json();
// 1. 서버 사이드 금액 검증 로직 추가 필수
// const product = await db.product.findUnique({ where: { orderId } });
// if (product.price !== amount) throw new Error('Invalid amount');
const secretKey = process.env.TOSS_SECRET_KEY;
const basicToken = Buffer.from(`${secretKey}:`).toString("base64");
const response = await fetch(
"https://api.tosspayments.com/v1/payments/confirm",
{
method: "POST",
headers: {
Authorization: `Basic ${basicToken}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ paymentKey, orderId, amount }),
}
);
const result = await response.json();
if (response.ok) {
// DB 업데이트 등 후처리 수행
return NextResponse.json(result);
} else {
return NextResponse.json(result, { status: response.status });
}
}"use client";
import { loadTossPayments } from "@tosspayments/payment-sdk";
export default function Checkout() {
const handlePayment = async () => {
const tossPayments = await loadTossPayments(
process.env.NEXT_PUBLIC_TOSS_CLIENT_KEY!
);
await tossPayments.requestPayment("카드", {
amount: 50000,
orderId: "ORDER_123",
orderName: "Next.js 마스터클래스",
successUrl: `${window.location.origin}/success`,
failUrl: `${window.location.origin}/fail`,
});
};
return <button onClick={handlePayment}>50,000원 결제하기</button>;
}.envIdempotency-Key