Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/app/api/payments/danal/ready/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NextResponse } from "next/server";

import { requestDanalReady } from "@/lib/payments/danal/ready";
import { createServiceRoleClient } from "@/lib/supabase";
import type { MentoringPlanId } from "@/app/mentoring/apply/_config/mentoringPlans";

type ReadyPayload = {
Expand Down Expand Up @@ -64,6 +65,29 @@ export async function POST(request: Request) {
{ cancelUrl, returnUrl },
);

const supabase = createServiceRoleClient();
const { error } = await supabase.from("payments").insert({
order_id: body.orderId,
plan_id: planId,
amount: body.amount,
item_name: body.itemName,
user_id: body.userId,
user_name: body.userName,
user_phone: body.userPhone,
user_email: body.userEmail ?? null,
user_agent: body.userAgent,
bypass_value: body.bypassValue ?? null,
danal_start_url: readyResponse.startUrl,
danal_start_params: readyResponse.startParams,
});

if (error) {
return NextResponse.json(
{ error: "결제 정보를 저장하지 못했습니다." },
{ status: 500 },
);
}

return NextResponse.json(readyResponse);
} catch (error) {
const message =
Expand Down
26 changes: 26 additions & 0 deletions src/lib/supabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ type PartnershipInquiryRow = {
created_at: string;
};

type PaymentRow = {
id: string;
order_id: string;
plan_id: "standard" | "plus";
amount: number;
item_name: string;
user_id: string;
user_name: string;
user_phone: string;
user_email: string | null;
user_agent: "PC" | "MW" | "MA" | "MI";
bypass_value: string | null;
danal_start_url: string;
danal_start_params: string;
created_at: string;
};

type Database = {
public: {
Tables: {
Expand All @@ -52,6 +69,15 @@ type Database = {
Update: Partial<PartnershipInquiryRow>;
Relationships: [];
};
payments: {
Row: PaymentRow;
Insert: Omit<PaymentRow, "id" | "created_at"> & {
id?: string;
created_at?: string;
};
Update: Partial<PaymentRow>;
Relationships: [];
};
};
Views: Record<string, never>;
Functions: Record<string, never>;
Expand Down
20 changes: 20 additions & 0 deletions supabase/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,23 @@ create index if not exists partnership_inquiries_created_at_idx
on public.partnership_inquiries (created_at desc);
create index if not exists partnership_inquiries_contact_email_idx
on public.partnership_inquiries (lower(contact_email));

create table if not exists public.payments (
id uuid primary key default gen_random_uuid(),
order_id text not null unique check (char_length(btrim(order_id)) > 0),
plan_id text not null check (plan_id in ('standard', 'plus')),
amount integer not null check (amount > 0),
item_name text not null check (char_length(btrim(item_name)) > 0),
user_id text not null check (char_length(btrim(user_id)) > 0),
user_name text not null check (char_length(btrim(user_name)) > 0),
user_phone text not null check (char_length(btrim(user_phone)) > 0),
user_email text,
user_agent text not null check (user_agent in ('PC', 'MW', 'MA', 'MI')),
bypass_value text,
danal_start_url text not null check (char_length(btrim(danal_start_url)) > 0),
danal_start_params text not null check (char_length(btrim(danal_start_params)) > 0),
created_at timestamptz not null default timezone('utc', now())
);

create index if not exists payments_created_at_idx on public.payments (created_at desc);
create index if not exists payments_order_id_idx on public.payments (order_id);