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>
This commit is contained in:
parent
b0e00c9370
commit
986a4e53b4
14 changed files with 1227 additions and 749 deletions
|
|
@ -25,7 +25,7 @@
|
|||
// Module general information
|
||||
$module_title = "billing";
|
||||
$module_version = "3.0";
|
||||
$db_version = 1;
|
||||
$db_version = 2;
|
||||
$module_required = FALSE;
|
||||
// Module description
|
||||
$module_description = "Billing storefront / provisioning integration. Public ordering runs as a standalone site; panel pages provide provisioning and admin order management.";
|
||||
|
|
@ -124,4 +124,53 @@ $install_queries[0] = array(
|
|||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;"
|
||||
);
|
||||
|
||||
// Version 2: New columns on billing_invoices, transaction log table, service-to-node mapping
|
||||
$install_queries[1] = array(
|
||||
// Add new columns to billing_invoices (IF NOT EXISTS for idempotence)
|
||||
"ALTER TABLE `".OGP_DB_PREFIX."billing_invoices`
|
||||
ADD COLUMN IF NOT EXISTS `home_id` INT(11) NOT NULL DEFAULT 0 AFTER `service_id`,
|
||||
ADD COLUMN IF NOT EXISTS `rate_type` ENUM('daily','monthly','yearly') NOT NULL DEFAULT 'monthly' AFTER `invoice_duration`,
|
||||
ADD COLUMN IF NOT EXISTS `rate_per_player` FLOAT(15,4) NOT NULL DEFAULT 0 AFTER `rate_type`,
|
||||
ADD COLUMN IF NOT EXISTS `players` INT(11) NOT NULL DEFAULT 0 AFTER `rate_per_player`,
|
||||
ADD COLUMN IF NOT EXISTS `period_start` DATETIME NULL AFTER `players`,
|
||||
ADD COLUMN IF NOT EXISTS `period_end` DATETIME NULL AFTER `period_start`,
|
||||
ADD COLUMN IF NOT EXISTS `subtotal` FLOAT(15,2) NOT NULL DEFAULT 0 AFTER `period_end`,
|
||||
ADD COLUMN IF NOT EXISTS `total_due` FLOAT(15,2) NOT NULL DEFAULT 0 AFTER `subtotal`,
|
||||
ADD COLUMN IF NOT EXISTS `payment_status` ENUM('unpaid','paid','cancelled','refunded') NOT NULL DEFAULT 'unpaid' AFTER `total_due`",
|
||||
|
||||
// Payment transaction log — immutable audit trail
|
||||
"CREATE TABLE IF NOT EXISTS `".OGP_DB_PREFIX."billing_transactions` (
|
||||
`transaction_id` INT(11) NOT NULL AUTO_INCREMENT,
|
||||
`invoice_id` INT(11) NOT NULL DEFAULT 0,
|
||||
`user_id` INT(11) NOT NULL DEFAULT 0,
|
||||
`home_id` INT(11) NOT NULL DEFAULT 0,
|
||||
`payment_method` VARCHAR(50) NOT NULL DEFAULT 'paypal',
|
||||
`transaction_external_id` VARCHAR(255) NOT NULL DEFAULT '',
|
||||
`amount` DECIMAL(15,2) NOT NULL DEFAULT 0.00,
|
||||
`currency` VARCHAR(3) NOT NULL DEFAULT 'USD',
|
||||
`status` ENUM('pending','completed','failed','refunded') NOT NULL DEFAULT 'pending',
|
||||
`raw_response` MEDIUMTEXT NULL,
|
||||
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`transaction_id`),
|
||||
KEY `invoice_id` (`invoice_id`),
|
||||
KEY `user_id` (`user_id`),
|
||||
KEY `home_id` (`home_id`),
|
||||
KEY `status` (`status`),
|
||||
KEY `payment_method` (`payment_method`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;",
|
||||
|
||||
// Service-to-remote-server mapping (admin can enable/disable per service)
|
||||
"CREATE TABLE IF NOT EXISTS `".OGP_DB_PREFIX."billing_service_remote_servers` (
|
||||
`id` INT(11) NOT NULL AUTO_INCREMENT,
|
||||
`service_id` INT(11) NOT NULL,
|
||||
`remote_server_id` INT(11) NOT NULL,
|
||||
`enabled` TINYINT(1) NOT NULL DEFAULT 1,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `svc_rs` (`service_id`, `remote_server_id`),
|
||||
KEY `service_id` (`service_id`),
|
||||
KEY `remote_server_id` (`remote_server_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"
|
||||
);
|
||||
|
||||
?>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue