feat: add Solana USDT/USDC support and refine admin payouts UI
This commit is contained in:
@@ -59,7 +59,7 @@ export async function POST(request: Request) {
|
||||
const map: Record<string, string> = {};
|
||||
result.rows.forEach(r => map[r.key] = r.value);
|
||||
return {
|
||||
sol: map.sol_platform_address || process.env.SOL_PLATFORM_ADDRESS || "5pLH1tqZhx8p8WpZ18yr28N42KXB3FXVPzZ9ceCtpBVe",
|
||||
sol: map.sol_platform_address || process.env.SOL_PLATFORM_ADDRESS || "Ajr4nKieZJVu9q2d1eVF9pQPRCLoZ6v4tapB3iQn2SyQ",
|
||||
evm: map.evm_platform_address || process.env.EVM_PLATFORM_ADDRESS || "0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
|
||||
tron: map.tron_platform_address || process.env.TRON_PLATFORM_ADDRESS || "TLYpfG6rre8Gv9m8pYjR7yvX7S9rK6G1P",
|
||||
btc: map.btc_platform_address || process.env.BTC_PLATFORM_ADDRESS || "bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfJH",
|
||||
@@ -139,12 +139,35 @@ export async function POST(request: Request) {
|
||||
const feeAmount = (grossAmount * feePercent) / 100;
|
||||
const merchantNetCredit = grossAmount - feeAmount;
|
||||
|
||||
// 6.2 Update Merchant's virtual balance
|
||||
// 6.2 Calculate crypto credit after fee
|
||||
const cryptoAmount = parseFloat(expectedCryptoAmount);
|
||||
const cryptoFee = (cryptoAmount * feePercent) / 100;
|
||||
const cryptoNetCredit = cryptoAmount - cryptoFee;
|
||||
|
||||
// 6.3 Update Merchant's TRY balance (legacy)
|
||||
await db.query(`UPDATE merchants SET available_balance = available_balance + $1 WHERE id = $2`,
|
||||
[merchantNetCredit, transaction.merchant_id]);
|
||||
|
||||
// 6.3 Update transaction status
|
||||
await db.query(`UPDATE transactions SET status = 'succeeded' WHERE id = $1`, [transaction.id]);
|
||||
// 6.4 Update Merchant's per-network crypto balance
|
||||
await db.query(`
|
||||
INSERT INTO merchant_balances (merchant_id, network, token, balance, total_gross)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
ON CONFLICT (merchant_id, network, token)
|
||||
DO UPDATE SET
|
||||
balance = merchant_balances.balance + $4,
|
||||
total_gross = merchant_balances.total_gross + $5
|
||||
`, [transaction.merchant_id, selectedNetwork, selectedToken, cryptoNetCredit, cryptoAmount]);
|
||||
|
||||
// 6.5 Update transaction status and recorded blockchain info
|
||||
await db.query(`
|
||||
UPDATE transactions
|
||||
SET status = 'succeeded',
|
||||
paid_network = $2,
|
||||
paid_token = $3,
|
||||
paid_amount_crypto = $4
|
||||
WHERE id = $1`,
|
||||
[transaction.id, selectedNetwork, selectedToken, expectedCryptoAmount]
|
||||
);
|
||||
|
||||
// 7. Automated Webhook Notification
|
||||
if (transaction.callback_url) {
|
||||
|
||||
Reference in New Issue
Block a user