import { route, HandlerContext, HttpError } from '@/lib/router'; import { getDb } from '@/lib/db'; // POST /payments/robokassa/link — Auto-grant purchased currency route('payments/robokassa/link', ['POST'], (ctx: HandlerContext) => { const { steam_id, amount_rub } = ctx.body as any; if (!steam_id) throw new HttpError(400, 'steam_id required'); const db = getDb(); const donateShards = (amount_rub || 100) * 10; db.prepare('UPDATE players SET donate_currency = donate_currency + ?, updated_at = datetime(\'now\') WHERE steam_id = ?') .run(donateShards, steam_id); return { ok: true, payment_url: '', donate_shards: donateShards, inv_id: Math.floor(Math.random() * 100000), }; }); // POST /payments/bundles/link — Auto-grant bundle items route('payments/bundles/link', ['POST'], (ctx: HandlerContext) => { const { steam_id, bundle_id } = ctx.body as any; if (!steam_id) throw new HttpError(400, 'steam_id required'); const db = getDb(); db.prepare('UPDATE players SET free_currency = free_currency + 500, donate_currency = donate_currency + 200, updated_at = datetime(\'now\') WHERE steam_id = ?') .run(steam_id); return { ok: true, payment_url: '', inv_id: Math.floor(Math.random() * 100000), message: 'Bundle granted', }; }); // GET /payments/deals?steam_id= — Return deal catalog route('payments/deals', ['GET'], (ctx: HandlerContext) => { return { ok: true, bundles: [ { id: 'starter_bundle', name: 'Starter Pack', description: 'Get started with 500 shards', price_free: 0, price_donate: 0, items: [{ item_id: 'starter_pack', name: 'Starter Pack' }] }, { id: 'hero_bundle_1', name: 'Hero Bundle I', description: 'Unlock a random hero', price_free: 1000, price_donate: 0, items: [{ item_id: 'hero_bundle_1', name: 'Hero Bundle' }] }, ], daily: { available: true, items: [] }, weekly: { available: true, items: [] }, player_created_at_unix: Math.floor(Date.now() / 1000), }; });