import type { PaymentProvider, PaymentRequest, PaymentResult } from "./types.js"; /** * MockPaymentProvider — for local development WITHOUT real merchant accounts. * * - createPayment: returns a fake payment URL with the orderNo and amount embedded. * - verifyCallback: always returns success (any callback is treated as valid). * * The fake URL is designed so the frontend can simulate the full payment flow: * the user "visits" the URL, then the frontend calls the mock callback endpoint. */ export class MockPaymentProvider implements PaymentProvider { createPayment(request: PaymentRequest): PaymentResult { const { orderNo, amountCents, method } = request; // Build a realistic-looking mock payment URL const url = `https://pay.mock.local/pay?orderNo=${encodeURIComponent(orderNo)}&amount=${amountCents}&method=${method}`; const result: PaymentResult = { url }; // Include a fake QR code URL for WeChat to make the frontend flow more realistic if (method === "wechat") { result.qrCode = `https://pay.mock.local/qr?orderNo=${encodeURIComponent(orderNo)}`; } return result; } verifyCallback( params: Record, ): { orderNo: string; transactionId: string } | null { const orderNo = typeof params["orderNo"] === "string" ? params["orderNo"] : undefined; if (!orderNo) { return null; } // Always succeed in mock mode return { orderNo, transactionId: `MOCK${Date.now()}`, }; } }