fix billing+migration: correct migration indexes, table name, column names, webhook URL

Agent-Logs-Url: https://github.com/GameServerPanel/GSP/sessions/862c51a7-d835-4eb2-bd0e-2e2a5459036b

Co-authored-by: iaretechnician <2749183+iaretechnician@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-05-05 20:13:08 +00:00 committed by GitHub
parent 9dc051d090
commit e010085347
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 289 additions and 51 deletions

View file

@ -3,18 +3,18 @@
-- Idempotent migration: adds columns required by the billing checkout fixes.
-- Safe to run multiple times (uses IF-based prepared statements).
-- Run against the panel database after deploying the updated PHP files.
-- Table prefix is hardcoded to gsp_.
-- IMPORTANT: Replace <PREFIX> with your actual table prefix (e.g. gsp_ or ogp_).
-- =============================================================================
SET @db = DATABASE();
SET @tbl = 'gsp_billing_invoices';
SET @tbl = '<PREFIX>billing_invoices';
-- 1) coupon_id — tracks which coupon was applied to an invoice
SET @cnt = 0;
SELECT COUNT(*) INTO @cnt FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = @tbl AND COLUMN_NAME = 'coupon_id';
SET @sql = IF(@cnt = 0,
'ALTER TABLE `gsp_billing_invoices` ADD COLUMN `coupon_id` INT(11) NOT NULL DEFAULT 0 AFTER `qty`',
'ALTER TABLE `<PREFIX>billing_invoices` ADD COLUMN `coupon_id` INT(11) NOT NULL DEFAULT 0 AFTER `qty`',
'SELECT 1');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
@ -23,7 +23,7 @@ SET @cnt = 0;
SELECT COUNT(*) INTO @cnt FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = @tbl AND COLUMN_NAME = 'discount_amount';
SET @sql = IF(@cnt = 0,
'ALTER TABLE `gsp_billing_invoices` ADD COLUMN `discount_amount` DECIMAL(10,2) NOT NULL DEFAULT 0.00 AFTER `amount`',
'ALTER TABLE `<PREFIX>billing_invoices` ADD COLUMN `discount_amount` DECIMAL(10,2) NOT NULL DEFAULT 0.00 AFTER `amount`',
'SELECT 1');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
@ -33,14 +33,14 @@ SET @cnt = 0;
SELECT COUNT(*) INTO @cnt FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = @tbl AND COLUMN_NAME = 'payment_status';
SET @sql = IF(@cnt = 0,
"ALTER TABLE `gsp_billing_invoices` ADD COLUMN `payment_status` ENUM('unpaid','paid','cancelled','refunded') NOT NULL DEFAULT 'unpaid' AFTER `currency`",
"ALTER TABLE `<PREFIX>billing_invoices` ADD COLUMN `payment_status` ENUM('unpaid','paid','cancelled','refunded') NOT NULL DEFAULT 'unpaid' AFTER `currency`",
'SELECT 1');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
-- Backfill payment_status for existing rows:
-- 'paid' → payment_status = 'paid'
-- anything else → payment_status = 'unpaid'
UPDATE `gsp_billing_invoices`
UPDATE `<PREFIX>billing_invoices`
SET `payment_status` = 'paid'
WHERE `status` = 'paid' AND `payment_status` <> 'paid';
@ -49,7 +49,7 @@ SET @cnt = 0;
SELECT COUNT(*) INTO @cnt FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = @tbl AND COLUMN_NAME = 'subtotal';
SET @sql = IF(@cnt = 0,
'ALTER TABLE `gsp_billing_invoices` ADD COLUMN `subtotal` DECIMAL(15,2) NOT NULL DEFAULT 0 AFTER `discount_amount`',
'ALTER TABLE `<PREFIX>billing_invoices` ADD COLUMN `subtotal` DECIMAL(15,2) NOT NULL DEFAULT 0 AFTER `discount_amount`',
'SELECT 1');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
@ -58,7 +58,7 @@ SET @cnt = 0;
SELECT COUNT(*) INTO @cnt FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = @tbl AND COLUMN_NAME = 'total_due';
SET @sql = IF(@cnt = 0,
'ALTER TABLE `gsp_billing_invoices` ADD COLUMN `total_due` DECIMAL(15,2) NOT NULL DEFAULT 0 AFTER `subtotal`',
'ALTER TABLE `<PREFIX>billing_invoices` ADD COLUMN `total_due` DECIMAL(15,2) NOT NULL DEFAULT 0 AFTER `subtotal`',
'SELECT 1');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
@ -67,21 +67,21 @@ SET @cnt = 0;
SELECT COUNT(*) INTO @cnt FROM information_schema.STATISTICS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = @tbl AND INDEX_NAME = 'coupon_id';
SET @sql = IF(@cnt = 0,
'ALTER TABLE `gsp_billing_invoices` ADD KEY `coupon_id` (`coupon_id`)',
'ALTER TABLE `<PREFIX>billing_invoices` ADD KEY `coupon_id` (`coupon_id`)',
'SELECT 1');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
-- -------------------------
-- billing_orders additions
-- -------------------------
SET @tbl = 'gsp_billing_orders';
SET @tbl = '<PREFIX>billing_orders';
-- 7) coupon_id on billing_orders (already in baseline schema but guard for older installs)
SET @cnt = 0;
SELECT COUNT(*) INTO @cnt FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = @tbl AND COLUMN_NAME = 'coupon_id';
SET @sql = IF(@cnt = 0,
'ALTER TABLE `gsp_billing_orders` ADD COLUMN `coupon_id` INT(11) NOT NULL DEFAULT 0 AFTER `paid_ts`',
'ALTER TABLE `<PREFIX>billing_orders` ADD COLUMN `coupon_id` INT(11) NOT NULL DEFAULT 0 AFTER `paid_ts`',
'SELECT 1');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
@ -90,7 +90,7 @@ SET @cnt = 0;
SELECT COUNT(*) INTO @cnt FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = @tbl AND COLUMN_NAME = 'discount_amount';
SET @sql = IF(@cnt = 0,
'ALTER TABLE `gsp_billing_orders` ADD COLUMN `discount_amount` DECIMAL(10,2) NOT NULL DEFAULT 0.00 AFTER `price`',
'ALTER TABLE `<PREFIX>billing_orders` ADD COLUMN `discount_amount` DECIMAL(10,2) NOT NULL DEFAULT 0.00 AFTER `price`',
'SELECT 1');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;

View file

@ -17,19 +17,19 @@
-- ============================================================
-- Map old 'installed' to 'Active'
UPDATE `gsp_billing_orders`
UPDATE `<PREFIX>billing_orders`
SET `status` = 'Active'
WHERE `status` = 'installed';
-- Map old 'paid' to 'Active'
-- (Orders that were paid but not yet provisioned should be provisioned
-- via the admin orders panel after this migration.)
UPDATE `gsp_billing_orders`
UPDATE `<PREFIX>billing_orders`
SET `status` = 'Active'
WHERE `status` = 'paid';
-- Map old 'suspended' to 'Expired'
UPDATE `gsp_billing_orders`
UPDATE `<PREFIX>billing_orders`
SET `status` = 'Expired'
WHERE `status` = 'suspended';