CREATE TABLE `fiat_orders` (
	`id` int AUTO_INCREMENT NOT NULL,
	`orderId` varchar(64) NOT NULL,
	`gatewayOrderId` varchar(128),
	`channel` enum('alipay','wechat','paypal') NOT NULL,
	`userId` varchar(64),
	`payerEmail` varchar(128),
	`payerOpenId` varchar(128),
	`xicReceiveAddress` varchar(64),
	`usdtEquivalent` decimal(20,6) NOT NULL,
	`currency` varchar(8) NOT NULL DEFAULT 'USD',
	`originalAmount` decimal(20,4) NOT NULL,
	`xicAmount` decimal(30,6) NOT NULL,
	`status` enum('pending','paid','distributed','refunded','failed','expired') NOT NULL DEFAULT 'pending',
	`qrCodeUrl` text,
	`paymentUrl` text,
	`callbackPayload` text,
	`distributedAt` timestamp,
	`expiredAt` timestamp,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `fiat_orders_id` PRIMARY KEY(`id`),
	CONSTRAINT `fiat_orders_orderId_unique` UNIQUE(`orderId`)
);
