From 986a4e53b4b6aebbd83f47d7f85df3f0c5bd5e1a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 2 May 2026 12:17:36 +0000 Subject: [PATCH] refactor(billing): clean architecture with payment gateway abstraction - Add PaymentGatewayInterface contract for all payment providers - Add PayPalGateway (reads credentials from config, not hardcoded) - Add ManualGateway for admin-triggered payments - Add StripeGateway stub for future implementation - Add GatewayFactory for gateway instantiation by name - Add BillingRepository: parameterized-SQL data layer - Add BillingService: pricing, invoice creation, payment processing - Add gsp_billing_transactions table (DB version 2) for audit trail - Add new columns to gsp_billing_invoices (home_id, rate_type, players, period_start/end, subtotal, total_due, payment_status) - Add gsp_billing_service_remote_servers mapping table - Move PayPal credentials from api files into config.inc.php - Fix double session_start() bug in capture_order.php - Replace raw SQL with prepared statements throughout - Refactor admin_invoices.php to use billing_invoices + BillingRepository - Refactor admin_payments.php to read from gsp_billing_transactions - Update admin.php with links to Transaction Log and Manage Invoices Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: iaretechnician <2749183+iaretechnician@users.noreply.github.com> --- modules/billing/admin.php | 7 +- modules/billing/admin_invoices.php | 269 ++++++----- modules/billing/admin_payments.php | 119 +++-- modules/billing/api/capture_order.php | 455 +++++------------- modules/billing/api/create_order.php | 284 ++--------- modules/billing/classes/BillingRepository.php | 279 +++++++++++ modules/billing/classes/BillingService.php | 188 ++++++++ modules/billing/classes/GatewayFactory.php | 30 ++ modules/billing/classes/ManualGateway.php | 36 ++ modules/billing/classes/PayPalGateway.php | 188 ++++++++ .../classes/PaymentGatewayInterface.php | 40 ++ modules/billing/classes/StripeGateway.php | 25 + modules/billing/includes/config.inc.php | 5 + modules/billing/module.php | 51 +- 14 files changed, 1227 insertions(+), 749 deletions(-) create mode 100644 modules/billing/classes/BillingRepository.php create mode 100644 modules/billing/classes/BillingService.php create mode 100644 modules/billing/classes/GatewayFactory.php create mode 100644 modules/billing/classes/ManualGateway.php create mode 100644 modules/billing/classes/PayPalGateway.php create mode 100644 modules/billing/classes/PaymentGatewayInterface.php create mode 100644 modules/billing/classes/StripeGateway.php diff --git a/modules/billing/admin.php b/modules/billing/admin.php index 95f77b76..e1022335 100644 --- a/modules/billing/admin.php +++ b/modules/billing/admin.php @@ -22,8 +22,9 @@ function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); }

Welcome to the admin area. From here you can manage servers, payments, and site settings.

- Manage Servers & Services - Invoice History + Manage Servers & Services + Manage Invoices + Transaction Log Manage Coupons Edit Site Config XML Config Editor @@ -39,7 +40,7 @@ function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); }

Sandbox account (testing)

-

Use PayPal sandbox credentials when testing payments. Set your sandbox client_id and client_secret in the runtime config that the payment handlers use (for this site those are in the respective files under _website/api/ or in a central config if you moved credentials).

+

Use PayPal sandbox credentials when testing payments. Set your sandbox client_id and client_secret in modules/billing/includes/config.inc.php (the $paypal_client_id and $paypal_client_secret variables). Set $paypal_sandbox = false for live payments.