| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yatra\Database\Tables; |
| 4 |
|
| 5 |
/** |
| 6 |
* BookingPayments Table Class |
| 7 |
* |
| 8 |
* Represents the booking payments table (wp_yatra_booking_payments) containing |
| 9 |
* comprehensive payment history data including transaction details, gateway |
| 10 |
* information, payment status, and processing timestamps. |
| 11 |
* |
| 12 |
* This table follows the new simplified pattern with only two static methods: |
| 13 |
* - getTableName(): Returns the prefixed table name |
| 14 |
* - getSchema(): Returns the complete CREATE TABLE SQL statement |
| 15 |
* |
| 16 |
* Usage: |
| 17 |
* BookingPaymentsTable::getTableName() // Returns 'wp_yatra_booking_payments' |
| 18 |
* BookingPaymentsTable::getSchema() // Returns complete SQL schema |
| 19 |
* |
| 20 |
* @package Yatra\Database\Tables |
| 21 |
* @since 1.0.0 |
| 22 |
*/ |
| 23 |
class BookingPaymentsTable extends BaseTable |
| 24 |
{ |
| 25 |
/** |
| 26 |
* Table name without prefix |
| 27 |
* |
| 28 |
* @var string The base table name without WordPress prefix |
| 29 |
*/ |
| 30 |
protected static string $table = 'yatra_booking_payments'; |
| 31 |
|
| 32 |
/** |
| 33 |
* Get the complete table schema as raw SQL CREATE TABLE statement |
| 34 |
* |
| 35 |
* Returns the full SQL schema for the booking payments table using heredoc syntax |
| 36 |
* for proper IDE syntax highlighting. Includes all columns, indexes, |
| 37 |
* and constraints from the original Database.php schema. |
| 38 |
* |
| 39 |
* @return string Complete CREATE TABLE SQL statement |
| 40 |
*/ |
| 41 |
public static function getSchema(): string |
| 42 |
{ |
| 43 |
$tableName = static::getTableName(); |
| 44 |
$charsetCollate = static::getCharsetCollate(); |
| 45 |
|
| 46 |
return <<<SQL |
| 47 |
CREATE TABLE IF NOT EXISTS `{$tableName}` ( |
| 48 |
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, |
| 49 |
`booking_id` bigint(20) UNSIGNED NOT NULL, |
| 50 |
`customer_id` bigint(20) UNSIGNED DEFAULT NULL, |
| 51 |
`transaction_id` varchar(255) DEFAULT NULL, |
| 52 |
`gateway` varchar(80) NOT NULL, |
| 53 |
`amount` decimal(12,2) NOT NULL, |
| 54 |
`currency` char(3) DEFAULT 'USD', |
| 55 |
`status` enum('pending','completed','failed','refunded','cancelled') DEFAULT 'pending', |
| 56 |
`payment_type` enum('initial','partial','final','refund') DEFAULT 'initial', |
| 57 |
`gateway_response` longtext COMMENT 'JSON gateway response data', |
| 58 |
`meta` longtext DEFAULT NULL COMMENT 'JSON for future extensions', |
| 59 |
`notes` text, |
| 60 |
`processed_at` datetime DEFAULT NULL, |
| 61 |
`created_at` datetime DEFAULT CURRENT_TIMESTAMP, |
| 62 |
`updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| 63 |
|
| 64 |
PRIMARY KEY (`id`), |
| 65 |
KEY `idx_booking_id` (`booking_id`), |
| 66 |
KEY `idx_booking_created` (`booking_id`, `created_at`), |
| 67 |
KEY `idx_customer_id` (`customer_id`), |
| 68 |
KEY `idx_transaction_id` (`transaction_id`), |
| 69 |
KEY `idx_status` (`status`), |
| 70 |
KEY `idx_created` (`created_at`) |
| 71 |
) {$charsetCollate} COMMENT='Booking payment history'; |
| 72 |
SQL; |
| 73 |
} |
| 74 |
} |
| 75 |
|