fix: address code review comments (grace_days in Step B, simplified rate_map, spelling, comments)

Agent-Logs-Url: https://github.com/GameServerPanel/GSP/sessions/5dbd58e1-7aa0-41e2-8dd3-c56b69ede05e

Co-authored-by: iaretechnician <2749183+iaretechnician@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-05-01 22:19:17 +00:00 committed by GitHub
parent b03d9b2171
commit 79d78f074b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 10 additions and 9 deletions

View file

@ -210,7 +210,10 @@ if ($coupon_id > 0) {
}
}
// Mark all due invoices for this user as paid
// Mark all due invoices for this user as paid.
// Note: billing_invoices is the pre-purchase cart table and uses its own
// status vocabulary (due -> paid). This is separate from gsp_invoices
// (renewal invoices) and server_homes.billing_status (Active/Invoiced/Expired).
$updateInvoicesSql = "UPDATE {$table_prefix}billing_invoices
SET status='paid', paid_date='$now', payment_txid='$esc_txid', payment_method='paypal'
WHERE user_id=$user_id AND status='due'";

View file

@ -123,10 +123,8 @@ if (is_array($due_for_invoice)) {
// Normalise rate_type to the ENUM values used in {prefix}invoices
$raw_rate = strtolower($srv['invoice_duration'] ?? $default_rate_type);
$rate_map = ['day' => 'daily', 'daily' => 'daily',
'month' => 'monthly', 'monthly' => 'monthly',
'year' => 'yearly', 'yearly' => 'yearly'];
$rate_type = $rate_map[$raw_rate] ?? 'monthly';
$rate_map = ['day' => 'daily', 'month' => 'monthly', 'year' => 'yearly'];
$rate_type = $rate_map[$raw_rate] ?? $raw_rate;
// Pricing: billing_config > billing_orders flat price
$price_per_player = $default_price_player;
@ -206,7 +204,7 @@ if (is_array($due_for_invoice)) {
// Servers whose expiration date has passed and whose last invoice
// is still unpaid.
// ======================================================================
$db->logger("BILLING-CRON: --- Step B: Invoiced -> Expired ---");
$db->logger("BILLING-CRON: --- Step B: Invoiced -> Expired (grace_days={$grace_days}) ---");
$past_due = $db->resultQuery("
SELECT sh.home_id, sh.home_name, sh.user_id_main AS user_id,
@ -217,7 +215,7 @@ $past_due = $db->resultQuery("
WHERE sh.billing_enabled = 1
AND sh.billing_status = 'Invoiced'
AND sh.server_expiration_date IS NOT NULL
AND sh.server_expiration_date < NOW()
AND sh.server_expiration_date < DATE_SUB(NOW(), INTERVAL {$grace_days} DAY)
AND (
sh.last_invoice_id IS NULL
OR EXISTS (

View file

@ -194,7 +194,7 @@ WHERE sh.`server_expiration_date` IS NULL
AND bo.`end_date` IS NOT NULL;
-- ============================================================
-- SECTION 6: Normalise gsp_billing_orders.status to new values
-- SECTION 6: Normalize gsp_billing_orders.status to new values
-- ============================================================
-- Active (was: paid, installed, active, running, enabled, online)
@ -256,5 +256,5 @@ SELECT CONCAT(
'Migration complete. ',
'gsp_server_homes now has billing_status/next_invoice_date/last_invoice_id/billing_enabled. ',
'gsp_invoices and gsp_billing_config tables created. ',
'gsp_billing_orders.status normalised to Active/Invoiced/Expired.'
'gsp_billing_orders.status normalized to Active/Invoiced/Expired.'
) AS Migration_Result;