feat: extract shared payment utilities from rubgram

Move checkSlip into a shared lib/payment module so the donate page can reuse it without duplicating SlipOK API logic.
This commit is contained in:
2026-06-07 23:04:41 +00:00 Unverified
parent 75e711144f
commit e62202b2a8
2 changed files with 34 additions and 33 deletions
+3 -33
View File
@@ -3,7 +3,6 @@
import { and, desc, eq, gt, lt, not, sql } from "drizzle-orm";
import { revalidatePath } from "next/cache";
import { cookies } from "next/headers";
import image from "next/image";
import { redirect } from "next/navigation";
import { actionLog } from "@/lib/api";
import { adminCheck } from "@/lib/auth";
@@ -20,13 +19,9 @@ import {
} from "@/lib/db/schema";
import { sse } from "@/lib/db/sse-endpoints";
import { getPostHogClient } from "@/lib/posthog-server";
const {
SLIPOK_API_URL,
SLIPOK_API_KEY,
DISCORD_WEBHOOK_URL,
DISCORD_CLIENT_ID,
BASE_URL,
} = process.env as Record<string, string>;
import { checkSlip } from "@/lib/payment";
const { DISCORD_WEBHOOK_URL, DISCORD_CLIENT_ID, BASE_URL } =
process.env as Record<string, string>;
export async function archive({ onlyChecked = true, copy = true }) {
if (!(await adminCheck())) throw "Unauthorized";
@@ -333,31 +328,6 @@ export async function submitEndgamePayment(formData: FormData) {
return Array.isArray(queue) ? queue[0] : queue;
}
async function checkSlip(
buffer: Buffer<ArrayBuffer>,
type: string,
amount: number,
): Promise<SlipokResponse> {
const response = await fetch(SLIPOK_API_URL, {
method: "POST",
headers: {
"x-authorization": SLIPOK_API_KEY,
},
body: (() => {
const formData = new FormData();
formData.append("files", new Blob([buffer], { type }), image.name);
formData.append("amount", amount.toString());
// formData.append("log", "true"); // no log cause im logging myself
return formData;
})(),
});
const data = await response.json();
// if (!response.ok) throw data;
return data;
}
// discord auth
export async function getDiscordSession() {
const c = await cookies();
+31
View File
@@ -0,0 +1,31 @@
import { SlipokResponse } from "@/app/(ui)/rubgram/api";
const { SLIPOK_API_URL, SLIPOK_API_KEY } = process.env as Record<
string,
string
>;
export async function checkSlip(
buffer: Buffer<ArrayBuffer>,
type: string,
amount: number,
): Promise<SlipokResponse> {
const response = await fetch(SLIPOK_API_URL, {
method: "POST",
headers: {
"x-authorization": SLIPOK_API_KEY,
},
body: (() => {
const formData = new FormData();
formData.append("files", new Blob([buffer], { type }), "image");
formData.append("amount", amount.toString());
// formData.append("log", "true"); // no log cause im logging myself
return formData;
})(),
});
const data = await response.json();
// if (!response.ok) throw data;
return data;
}