-- Stripe Checkout integration for the PHP panel. -- Set STRIPE_CREDENTIAL_KEY before saving credentials in the admin panel. -- Import after cloud.sql so the invoice payment status contract can be widened. CREATE TABLE `stripe_orders` ( `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, `order_no` varchar(32) NOT NULL, `checkout_session_id` varchar(255) DEFAULT NULL, `payment_intent_id` varchar(255) DEFAULT NULL, `paylist_id` bigint(20) UNSIGNED NOT NULL, `user_id` bigint(20) UNSIGNED NOT NULL, `payment_method` varchar(16) NOT NULL, `amount` decimal(12,2) NOT NULL, `currency` char(3) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'usd', `livemode` tinyint(1) UNSIGNED NOT NULL DEFAULT 0, `checkout_url` text DEFAULT NULL, `status` varchar(24) NOT NULL DEFAULT 'creating', `error_message` varchar(500) NOT NULL DEFAULT '', `paid_at` int(10) UNSIGNED NOT NULL DEFAULT 0, `created_at` int(10) UNSIGNED NOT NULL DEFAULT 0, `updated_at` int(10) UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (`id`), UNIQUE KEY `uniq_stripe_order_no` (`order_no`), UNIQUE KEY `uniq_stripe_checkout_session` (`checkout_session_id`), UNIQUE KEY `uniq_stripe_payment_intent` (`payment_intent_id`), UNIQUE KEY `uniq_stripe_paylist_id` (`paylist_id`), KEY `idx_stripe_user_created` (`user_id`,`created_at`), KEY `idx_stripe_status_created` (`status`,`created_at`), KEY `idx_stripe_method_created` (`payment_method`,`created_at`), CONSTRAINT `chk_stripe_order_method` CHECK (`payment_method` IN ('card','alipay')), CONSTRAINT `chk_stripe_order_currency` CHECK (`currency` = 'usd'), CONSTRAINT `chk_stripe_order_livemode` CHECK (`livemode` IN (0,1)), CONSTRAINT `chk_stripe_order_status` CHECK (`status` IN ( 'creating','pending','paid','failed','expired','not_created','creation_unknown' )) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; CREATE TABLE `stripe_webhook_events` ( `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, `event_id` varchar(255) NOT NULL, `event_type` varchar(80) NOT NULL, `object_id` varchar(255) NOT NULL, `order_no` varchar(32) NOT NULL, `livemode` tinyint(1) UNSIGNED NOT NULL DEFAULT 0, `payload` mediumtext NOT NULL, `received_at` int(10) UNSIGNED NOT NULL DEFAULT 0, `processed_at` int(10) UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (`id`), UNIQUE KEY `uniq_stripe_event_id` (`event_id`), KEY `idx_stripe_event_order` (`order_no`,`received_at`), KEY `idx_stripe_event_type` (`event_type`,`received_at`), CONSTRAINT `chk_stripe_event_livemode` CHECK (`livemode` IN (0,1)) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; ALTER TABLE `cloud_invoice_payments` DROP CHECK `chk_cloud_invoice_payment_status`, ADD CONSTRAINT `chk_cloud_invoice_payment_status` CHECK (`status` IN ( 'creating','pending','paid_invoice','credited_balance', 'failed','expired','not_created','creation_unknown' ));