| 1 |
<?php |
| 2 |
/** |
| 3 |
* Transactions: BerlinDB database table |
| 4 |
* |
| 5 |
* @package SimplePay |
| 6 |
* @subpackage Core |
| 7 |
* @copyright Copyright (c) 2022, Sandhills Development, LLC |
| 8 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 |
* @since 4.4.6 |
| 10 |
*/ |
| 11 |
|
| 12 |
// phpcs:disable WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid |
| 13 |
// phpcs:disable PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.MethodDoubleUnderscore |
| 14 |
|
| 15 |
namespace SimplePay\Core\Transaction\Database; |
| 16 |
|
| 17 |
use SimplePay\Vendor\BerlinDB\Database\Table as BerlinDBTable; |
| 18 |
|
| 19 |
/** |
| 20 |
* Table class. |
| 21 |
* |
| 22 |
* @since 4.4.6 |
| 23 |
*/ |
| 24 |
class Table extends BerlinDBTable { |
| 25 |
|
| 26 |
/** |
| 27 |
* {@inheritdoc} |
| 28 |
* |
| 29 |
* @var string |
| 30 |
*/ |
| 31 |
protected $prefix = 'wpsp'; |
| 32 |
|
| 33 |
/** |
| 34 |
* {@inheritdoc} |
| 35 |
* |
| 36 |
* @var string |
| 37 |
*/ |
| 38 |
protected $name = 'transactions'; |
| 39 |
|
| 40 |
/** |
| 41 |
* {@inheritdoc} |
| 42 |
* |
| 43 |
* @var int |
| 44 |
*/ |
| 45 |
protected $version = 202404230001; |
| 46 |
|
| 47 |
/** |
| 48 |
* {@inheritdoc} |
| 49 |
* |
| 50 |
* @var string |
| 51 |
*/ |
| 52 |
protected $schema = __NAMESPACE__ . '\\Schema'; |
| 53 |
|
| 54 |
/** |
| 55 |
* {@inheritdoc} |
| 56 |
* |
| 57 |
* @var array<string, int> |
| 58 |
*/ |
| 59 |
protected $upgrades = array( // @phpstan-ignore-line |
| 60 |
'202206170001' => 202206170001, |
| 61 |
'202301090001' => 202301090001, |
| 62 |
'202404230001' => 202404230001, |
| 63 |
); |
| 64 |
|
| 65 |
/** |
| 66 |
* {@inheritdoc} |
| 67 |
* |
| 68 |
* @return void |
| 69 |
*/ |
| 70 |
protected function set_schema() { |
| 71 |
$this->schema = ' |
| 72 |
id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, |
| 73 |
form_id bigint(20) UNSIGNED NOT NULL DEFAULT 0, |
| 74 |
object varchar(100) NOT NULL, |
| 75 |
_object_id varchar(255) DEFAULT NULL, |
| 76 |
livemode tinyint(1) NOT NULL DEFAULT 0, |
| 77 |
amount_total bigint(20) NOT NULL, |
| 78 |
amount_subtotal bigint(20) NOT NULL, |
| 79 |
amount_shipping bigint(20) NOT NULL, |
| 80 |
amount_discount bigint(20) NOT NULL, |
| 81 |
amount_refunded bigint(20) NOT NULL DEFAULT 0, |
| 82 |
amount_tax bigint(20) NOT NULL, |
| 83 |
currency varchar(3) NOT NULL, |
| 84 |
payment_method_type varchar(50) DEFAULT NULL, |
| 85 |
email varchar(255) DEFAULT NULL, |
| 86 |
customer_id varchar(255) DEFAULT NULL, |
| 87 |
subscription_id varchar(255) DEFAULT NULL, |
| 88 |
status varchar(50) NOT NULL, |
| 89 |
application_fee tinyint(1) NOT NULL DEFAULT false, |
| 90 |
ip_address varchar(128) NOT NULL, |
| 91 |
date_created datetime NOT NULL DEFAULT CURRENT_TIMESTAMP(), |
| 92 |
date_modified datetime NOT NULL DEFAULT CURRENT_TIMESTAMP(), |
| 93 |
uuid varchar(100) NOT NULL, |
| 94 |
|
| 95 |
PRIMARY KEY (id), |
| 96 |
KEY form_id (form_id), |
| 97 |
KEY object_id (_object_id), |
| 98 |
KEY date_created (date_created), |
| 99 |
KEY customer_id (customer_id), |
| 100 |
KEY email (email), |
| 101 |
KEY subscription_id (subscription_id), |
| 102 |
KEY object_status (object(100),status(50)) |
| 103 |
'; |
| 104 |
} |
| 105 |
|
| 106 |
/** |
| 107 |
* Upgrade to version 202206170001. |
| 108 |
* - Change the length of column `object` to `varchar(100)`. |
| 109 |
* - Change the length of column `status` to `varchar(50)`. |
| 110 |
* - Update the `object_status` index to reflect the new length of `object` and `status`. |
| 111 |
* |
| 112 |
* @since 4.4.7 |
| 113 |
* |
| 114 |
* @return bool |
| 115 |
*/ |
| 116 |
protected function __202206170001() { |
| 117 |
// Set column `object` length. |
| 118 |
$this->get_db()->query( |
| 119 |
"ALTER TABLE {$this->table_name} MODIFY COLUMN `object` varchar(100) NOT NULL" |
| 120 |
); |
| 121 |
|
| 122 |
// Set column `status` length. |
| 123 |
$this->get_db()->query( |
| 124 |
"ALTER TABLE {$this->table_name} MODIFY COLUMN `status` varchar(50) NOT NULL" |
| 125 |
); |
| 126 |
|
| 127 |
// Update the `object_status` index. |
| 128 |
$this->get_db()->query( |
| 129 |
"DROP INDEX object_status ON {$this->table_name}" |
| 130 |
); |
| 131 |
|
| 132 |
$this->get_db()->query( |
| 133 |
"ALTER TABLE {$this->table_name} ADD INDEX object_status (`object`(100), `status`(50))" |
| 134 |
); |
| 135 |
|
| 136 |
return $this->is_success( true ); |
| 137 |
} |
| 138 |
|
| 139 |
/** |
| 140 |
* Upgrade to version 202206170001. |
| 141 |
* - Add a new `payment_method_type` column. |
| 142 |
* |
| 143 |
* @since 4.6.7 |
| 144 |
* |
| 145 |
* @return bool |
| 146 |
*/ |
| 147 |
protected function __202301090001() { |
| 148 |
// Add the `payment_method_type` column after `currency`. |
| 149 |
$this->get_db()->query( |
| 150 |
"ALTER TABLE {$this->table_name} ADD COLUMN `payment_method_type` varchar(50) DEFAULT NULL AFTER `currency`" |
| 151 |
); |
| 152 |
|
| 153 |
return $this->is_success( true ); |
| 154 |
} |
| 155 |
|
| 156 |
/** |
| 157 |
* Upgrade to version 202404230001. |
| 158 |
* - Add a new `amount_refunded` column. |
| 159 |
* |
| 160 |
* @since 4.10.0 |
| 161 |
* |
| 162 |
* @return bool |
| 163 |
*/ |
| 164 |
protected function __202404230001() { |
| 165 |
// Add the `amount_refunded` column after `amount_discount`. |
| 166 |
$this->get_db()->query( |
| 167 |
"ALTER TABLE {$this->table_name} ADD COLUMN `amount_refunded` bigint(20) NOT NULL DEFAULT 0 AFTER `amount_discount`" |
| 168 |
); |
| 169 |
|
| 170 |
return $this->is_success( true ); |
| 171 |
} |
| 172 |
} |
| 173 |
|