Initial commit

This commit is contained in:
2026-03-27 19:35:14 +01:00
commit 38581b88a4
68 changed files with 12137 additions and 0 deletions

47
lib/payment-uri.ts Normal file
View File

@@ -0,0 +1,47 @@
import { PaymentMethodType } from "@prisma/client";
function looksLikeUrl(value: string) {
try {
const url = new URL(value);
return ["http:", "https:"].includes(url.protocol);
} catch {
return false;
}
}
export function buildPaymentUri(type: PaymentMethodType, value: string, network?: string | null) {
const cleaned = value.trim();
switch (type) {
case "PAYPAL": {
if (looksLikeUrl(cleaned)) {
return cleaned;
}
return `https://paypal.me/${cleaned}`;
}
case "BITCOIN":
return `bitcoin:${cleaned}`;
case "ETHEREUM":
return `ethereum:${cleaned}`;
case "MONERO":
return `monero:${cleaned}`;
case "LITECOIN":
return `litecoin:${cleaned}`;
case "SOLANA":
return `solana:${cleaned}`;
case "USDT":
return network ? `usdt:${network}:${cleaned}` : `usdt:${cleaned}`;
case "REVOLUT": {
if (looksLikeUrl(cleaned)) {
return cleaned;
}
return `https://revolut.me/${cleaned}`;
}
case "BANK_TRANSFER":
return cleaned;
case "CUSTOM":
return cleaned;
default:
return cleaned;
}
}