You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
3.4 KiB
SQL
65 lines
3.4 KiB
SQL
-- Apply once to the existing panel database before enabling the FX checkout.
|
|
-- Legacy provider orders and balances keep their original values.
|
|
CREATE TABLE `payment_checkout_quotes` (
|
|
`order_no` varchar(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
`provider` varchar(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
`user_id` bigint unsigned NOT NULL,
|
|
`quote_version` tinyint unsigned NOT NULL,
|
|
`usd_cents` bigint unsigned NOT NULL,
|
|
`asset` varchar(4) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
`expected_units` bigint unsigned NOT NULL,
|
|
`rate` decimal(16,12) DEFAULT NULL,
|
|
`source` varchar(16) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
`source_at` bigint unsigned DEFAULT NULL,
|
|
`fetched_at` bigint unsigned DEFAULT NULL,
|
|
`rate_actor_id` bigint unsigned DEFAULT NULL,
|
|
`rate_reason` varchar(240) DEFAULT NULL,
|
|
`quoted_at` bigint unsigned DEFAULT NULL,
|
|
`provider_expires_at` bigint unsigned DEFAULT NULL,
|
|
`accept_until` bigint unsigned DEFAULT NULL,
|
|
`status` varchar(12) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'quoted',
|
|
`review_reason` varchar(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
`receipt_ref` varchar(100) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
`received_at` bigint unsigned DEFAULT NULL,
|
|
`paid_at` bigint unsigned DEFAULT NULL,
|
|
`received_units` bigint unsigned DEFAULT NULL,
|
|
`credit_cents` bigint unsigned DEFAULT NULL,
|
|
`referral_id` bigint unsigned DEFAULT NULL,
|
|
PRIMARY KEY (`order_no`),
|
|
KEY `payment_quote_user` (`user_id`,`status`),
|
|
KEY `payment_quote_review` (`provider`,`status`,`received_at`),
|
|
CONSTRAINT `chk_payment_quote_asset` CHECK (
|
|
(`provider` = 'usdt' AND `asset` = 'USDT') OR
|
|
(`provider` IN ('paytaro','yipay_alipay','yipay_wxpay') AND `asset` = 'CNY')
|
|
),
|
|
CONSTRAINT `chk_payment_quote_version` CHECK (
|
|
(`quote_version` = 0 AND `status` = 'review' AND `rate` IS NULL) OR
|
|
(`quote_version` = 1 AND `rate` IS NOT NULL AND `rate` > 0 AND `source` IS NOT NULL
|
|
AND `quoted_at` IS NOT NULL
|
|
AND (
|
|
(`provider` = 'usdt' AND `provider_expires_at` IS NOT NULL
|
|
AND `accept_until` IS NOT NULL AND `provider_expires_at` > `quoted_at`
|
|
AND `accept_until` >= `provider_expires_at`)
|
|
OR
|
|
(`provider` IN ('paytaro','yipay_alipay','yipay_wxpay')
|
|
AND (`provider_expires_at` IS NULL OR `provider_expires_at` > `quoted_at`)
|
|
AND (`accept_until` IS NULL OR (`provider_expires_at` IS NOT NULL
|
|
AND `accept_until` >= `provider_expires_at`)))
|
|
))
|
|
),
|
|
CONSTRAINT `chk_payment_quote_receipt` CHECK (
|
|
(`status` = 'quoted' AND `receipt_ref` IS NULL AND `credit_cents` IS NULL AND `review_reason` IS NULL) OR
|
|
(`status` = 'review' AND `receipt_ref` IS NOT NULL AND `credit_cents` IS NULL AND `review_reason` IS NOT NULL) OR
|
|
(`status` = 'accepted' AND `receipt_ref` IS NOT NULL AND `credit_cents` IS NOT NULL
|
|
AND `credit_cents` >= `usd_cents` AND `review_reason` IS NULL)
|
|
)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
ALTER TABLE `usdt_payment_orders`
|
|
MODIFY COLUMN `exchange_rate` decimal(12,4) DEFAULT NULL,
|
|
ALTER COLUMN `currency` SET DEFAULT 'USD';
|
|
|
|
ALTER TABLE `yipay_refunds`
|
|
ADD COLUMN `gateway_amount` decimal(12,2) DEFAULT NULL AFTER `amount`,
|
|
ADD COLUMN `gateway_currency` char(3) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL AFTER `gateway_amount`;
|