Initial Commit
This commit is contained in:
113
inc/database/payments/class-payment-query.php
Normal file
113
inc/database/payments/class-payment-query.php
Normal file
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying payments.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Payments
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Payments;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Query;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Class used for querying payments.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Payment_Query extends Query {
|
||||
|
||||
/** Table Properties ******************************************************/
|
||||
|
||||
/**
|
||||
* Name of the database table to query.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_name = 'payments';
|
||||
|
||||
/**
|
||||
* String used to alias the database table in MySQL statement.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_alias = 'pay';
|
||||
|
||||
/**
|
||||
* Name of class used to setup the database schema
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_schema = '\\WP_Ultimo\\Database\\Payments\\Payments_Schema';
|
||||
|
||||
/** Item ******************************************************************/
|
||||
|
||||
/**
|
||||
* Name for a single item
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $item_name = 'payment';
|
||||
|
||||
/**
|
||||
* Plural version for a group of items.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $item_name_plural = 'payments';
|
||||
|
||||
/**
|
||||
* Callback function for turning IDs into objects
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var mixed
|
||||
*/
|
||||
protected $item_shape = '\\WP_Ultimo\\Models\\Payment';
|
||||
|
||||
/**
|
||||
* Group to cache queries and queried items in.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $cache_group = 'payments';
|
||||
|
||||
/**
|
||||
* If we should use a global cache group.
|
||||
*
|
||||
* @since 2.1.2
|
||||
* @var bool
|
||||
*/
|
||||
protected $global_cache = true;
|
||||
|
||||
/**
|
||||
* Sets up the customer query, based on the query vars passed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
*
|
||||
* @param string|array $query Array of query arguments.
|
||||
*/
|
||||
public function __construct($query = array()) {
|
||||
|
||||
parent::__construct($query);
|
||||
|
||||
} // end __construct;
|
||||
|
||||
} // end class Payment_Query;
|
97
inc/database/payments/class-payment-status.php
Normal file
97
inc/database/payments/class-payment-status.php
Normal file
@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/**
|
||||
* Payment Status enum.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage WP_Ultimo\Database\Payments
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Payments;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
use \WP_Ultimo\Database\Engine\Enum;
|
||||
|
||||
/**
|
||||
* Payment Status.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Payment_Status extends Enum {
|
||||
|
||||
/**
|
||||
* Default product type.
|
||||
*/
|
||||
const __default = 'pending'; // phpcs:ignore
|
||||
|
||||
const PENDING = 'pending';
|
||||
const COMPLETED = 'completed';
|
||||
const REFUND = 'refunded';
|
||||
const PARTIAL_REFUND = 'partially-refunded';
|
||||
const PARTIAL = 'partially-paid';
|
||||
const FAILED = 'failed';
|
||||
const CANCELLED = 'cancelled';
|
||||
|
||||
/**
|
||||
* Returns an array with values => CSS Classes.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
protected function classes() {
|
||||
|
||||
return array(
|
||||
static::PENDING => 'wu-bg-gray-200 wu-text-gray-700',
|
||||
static::COMPLETED => 'wu-bg-green-200 wu-text-green-700',
|
||||
static::REFUND => 'wu-bg-blue-200 wu-text-gray-700',
|
||||
static::PARTIAL_REFUND => 'wu-bg-blue-200 wu-text-gray-700',
|
||||
static::PARTIAL => 'wu-bg-yellow-200 wu-text-yellow-700',
|
||||
static::FAILED => 'wu-bg-red-200 wu-text-red-700',
|
||||
static::CANCELLED => 'wu-bg-orange-200 wu-text-orange-700',
|
||||
);
|
||||
|
||||
} // end classes;
|
||||
|
||||
/**
|
||||
* Returns an array with values => CSS Classes.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
protected function icon_classes() {
|
||||
|
||||
return array(
|
||||
static::PENDING => 'wu-align-middle dashicons-wu-clock wu-text-gray-700',
|
||||
static::COMPLETED => 'wu-align-middle dashicons-wu-check wu-text-green-700',
|
||||
static::REFUND => 'wu-align-middle dashicons-wu-cw wu-text-gray-700',
|
||||
static::PARTIAL_REFUND => 'wu-align-middle dashicons-wu-cw wu-text-gray-700',
|
||||
static::PARTIAL => 'wu-align-middle dashicons-wu-cw wu-text-yellow-700',
|
||||
static::FAILED => 'wu-align-middle dashicons-wu-circle-with-cross wu-text-red-700',
|
||||
static::CANCELLED => 'wu-align-middle dashicons-wu-circle-with-cross wu-text-orange-700',
|
||||
);
|
||||
|
||||
} // end icon_classes;
|
||||
|
||||
/**
|
||||
* Returns an array with values => labels.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
protected function labels() {
|
||||
|
||||
return array(
|
||||
static::PENDING => __('Pending', 'wp-ultimo'),
|
||||
static::COMPLETED => __('Completed', 'wp-ultimo'),
|
||||
static::REFUND => __('Refunded', 'wp-ultimo'),
|
||||
static::PARTIAL_REFUND => __('Partially Refunded', 'wp-ultimo'),
|
||||
static::PARTIAL => __('Partially Paid', 'wp-ultimo'),
|
||||
static::FAILED => __('Failed', 'wp-ultimo'),
|
||||
static::CANCELLED => __('Cancelled', 'wp-ultimo'),
|
||||
);
|
||||
|
||||
} // end labels;
|
||||
|
||||
} // end class Payment_Status;
|
82
inc/database/payments/class-payments-meta-table.php
Normal file
82
inc/database/payments/class-payments-meta-table.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying payments' meta data.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Payments
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Payments;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Table;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Setup the "wu_paymentmeta" database table
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
final class Payments_Meta_Table extends Table {
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'paymentmeta';
|
||||
|
||||
/**
|
||||
* Is this table global?
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var boolean
|
||||
*/
|
||||
protected $global = true;
|
||||
|
||||
/**
|
||||
* Table current version
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $version = '2.0.0';
|
||||
|
||||
/**
|
||||
* Payments constructor.
|
||||
*
|
||||
* @access public
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Setup the database schema
|
||||
*
|
||||
* @access protected
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
protected function set_schema() {
|
||||
|
||||
$max_index_length = 191;
|
||||
|
||||
$this->schema = "meta_id bigint(20) unsigned NOT NULL auto_increment,
|
||||
wu_payment_id bigint(20) unsigned NOT NULL default '0',
|
||||
meta_key varchar(255) DEFAULT NULL,
|
||||
meta_value longtext DEFAULT NULL,
|
||||
PRIMARY KEY (meta_id),
|
||||
KEY wu_payment_id (wu_payment_id),
|
||||
KEY meta_key (meta_key({$max_index_length}))";
|
||||
|
||||
} // end set_schema;
|
||||
|
||||
} // end class Payments_Meta_Table;
|
192
inc/database/payments/class-payments-schema.php
Normal file
192
inc/database/payments/class-payments-schema.php
Normal file
@ -0,0 +1,192 @@
|
||||
<?php
|
||||
/**
|
||||
* Payment schema class
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Payments
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Payments;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Schema;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Payments Schema Class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Payments_Schema extends Schema {
|
||||
|
||||
/**
|
||||
* Array of database column objects
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var array
|
||||
*/
|
||||
public $columns = array(
|
||||
|
||||
// id
|
||||
array(
|
||||
'name' => 'id',
|
||||
'type' => 'bigint',
|
||||
'length' => '20',
|
||||
'unsigned' => true,
|
||||
'extra' => 'auto_increment',
|
||||
'primary' => true,
|
||||
'sortable' => true,
|
||||
'searchable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'status',
|
||||
'type' => 'varchar',
|
||||
'length' => '12',
|
||||
'default' => 'pending',
|
||||
'sortable' => true,
|
||||
'transition' => true,
|
||||
),
|
||||
|
||||
// customer_id
|
||||
array(
|
||||
'name' => 'customer_id',
|
||||
'type' => 'bigint',
|
||||
'length' => '20',
|
||||
'unsigned' => true,
|
||||
'transition' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'membership_id',
|
||||
'type' => 'bigint',
|
||||
'length' => '20',
|
||||
'unsigned' => true,
|
||||
'transition' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'parent_id',
|
||||
'type' => 'bigint',
|
||||
'length' => '20',
|
||||
'unsigned' => true,
|
||||
'transition' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'product_id',
|
||||
'type' => 'bigint',
|
||||
'length' => '20',
|
||||
'unsigned' => true,
|
||||
'sortable' => true,
|
||||
'transition' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'migrated_from_id',
|
||||
'type' => 'bigint',
|
||||
'length' => '20',
|
||||
'unsigned' => true,
|
||||
'sortable' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
// currency
|
||||
array(
|
||||
'name' => 'currency',
|
||||
'type' => 'varchar',
|
||||
'length' => '20',
|
||||
'default' => 'USD',
|
||||
'sortable' => true
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'discount_code',
|
||||
'type' => 'tinytext',
|
||||
'default' => '',
|
||||
'searchable' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'discount_total',
|
||||
'type' => 'decimal(13,4)',
|
||||
'default' => '',
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'subtotal',
|
||||
'type' => 'decimal(13,4)',
|
||||
'default' => '',
|
||||
'sortable' => true,
|
||||
'transition' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'refund_total',
|
||||
'type' => 'decimal(13,4)',
|
||||
'default' => '',
|
||||
'sortable' => true,
|
||||
'transition' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'tax_total',
|
||||
'type' => 'decimal(13,4)',
|
||||
'default' => '',
|
||||
'sortable' => true,
|
||||
'transition' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'total',
|
||||
'type' => 'decimal(13,4)',
|
||||
'default' => '',
|
||||
'sortable' => true,
|
||||
'transition' => true,
|
||||
),
|
||||
|
||||
// gateway
|
||||
array(
|
||||
'name' => 'gateway',
|
||||
'type' => 'tinytext',
|
||||
'default' => '',
|
||||
'searchable' => true,
|
||||
),
|
||||
|
||||
// gateway
|
||||
array(
|
||||
'name' => 'gateway_payment_id',
|
||||
'type' => 'tinytext',
|
||||
'default' => '',
|
||||
'searchable' => true,
|
||||
),
|
||||
|
||||
// date_created
|
||||
array(
|
||||
'name' => 'date_created',
|
||||
'type' => 'datetime',
|
||||
'created' => true,
|
||||
'date_query' => true,
|
||||
'sortable' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
// date_modified
|
||||
array(
|
||||
'name' => 'date_modified',
|
||||
'type' => 'datetime',
|
||||
'modified' => true,
|
||||
'date_query' => true,
|
||||
'sortable' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
);
|
||||
|
||||
} // end class Payments_Schema;
|
198
inc/database/payments/class-payments-table.php
Normal file
198
inc/database/payments/class-payments-table.php
Normal file
@ -0,0 +1,198 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying payment.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Payments
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Payments;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Table;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Setup the "wu_payments" database table
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
final class Payments_Table extends Table {
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'payments';
|
||||
|
||||
/**
|
||||
* Is this table global?
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var boolean
|
||||
*/
|
||||
protected $global = true;
|
||||
|
||||
/**
|
||||
* Table current version
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $version = '2.0.1-revision.20230601';
|
||||
|
||||
/**
|
||||
* List of table upgrades.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $upgrades = array(
|
||||
'2.0.1-revision.20210417' => 20_210_417,
|
||||
'2.0.1-revision.20210607' => 20_210_607,
|
||||
'2.0.1-revision.20230601' => 20_230_601,
|
||||
);
|
||||
|
||||
/**
|
||||
* Payments constructor.
|
||||
*
|
||||
* @access public
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Setup the database schema.
|
||||
*
|
||||
* @access protected
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
protected function set_schema() {
|
||||
|
||||
$this->schema = "id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
|
||||
status varchar(20) NOT NULL DEFAULT 'pending',
|
||||
customer_id bigint(20) unsigned NOT NULL default '0',
|
||||
membership_id bigint(20) unsigned NOT NULL default '0',
|
||||
parent_id bigint(20) unsigned NOT NULL default '0',
|
||||
product_id bigint(9) NOT NULL default '0',
|
||||
migrated_from_id bigint(20) DEFAULT NULL,
|
||||
discount_code tinytext NOT NULL default '',
|
||||
currency varchar(10) NOT NULL DEFAULT 'USD',
|
||||
subtotal decimal(13,4) default 0,
|
||||
refund_total decimal(13,4) default 0,
|
||||
tax_total decimal(13,4) default 0,
|
||||
discount_total decimal(13,4) default 0,
|
||||
total decimal(13,4) default 0,
|
||||
gateway tinytext NOT NULL default '',
|
||||
gateway_payment_id tinytext DEFAULT NULL,
|
||||
date_created datetime NULL,
|
||||
date_modified datetime NULL,
|
||||
PRIMARY KEY (id),
|
||||
KEY customer_id (customer_id),
|
||||
KEY membership_id (membership_id),
|
||||
KEY parent_id (parent_id),
|
||||
KEY product_id (product_id),
|
||||
KEY status (status)";
|
||||
|
||||
} // end set_schema;
|
||||
|
||||
/**
|
||||
* Adds the refund_total column.
|
||||
*
|
||||
* This does not work on older versions of MySQL, so we needed
|
||||
* the other migration below.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return bool
|
||||
*/
|
||||
protected function __20210417() { // phpcs:ignore
|
||||
|
||||
$result = $this->column_exists('refund_total');
|
||||
|
||||
// Maybe add column
|
||||
if (empty($result)) {
|
||||
|
||||
$query = "ALTER TABLE {$this->table_name} ADD COLUMN `refund_total` decimal(13,4) default 0 AFTER `subtotal`;";
|
||||
|
||||
$result = $this->get_db()->query($query);
|
||||
|
||||
} // end if;
|
||||
|
||||
// Return success/fail
|
||||
return $this->is_success($result);
|
||||
|
||||
} // end __20210417;
|
||||
|
||||
/**
|
||||
* Adds the refund_total column.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return bool
|
||||
*/
|
||||
protected function __20210607() { // phpcs:ignore
|
||||
|
||||
$result = $this->column_exists('refund_total');
|
||||
|
||||
// Maybe add column
|
||||
if (empty($result)) {
|
||||
|
||||
$query_set = "SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';";
|
||||
|
||||
$result_set = $this->get_db()->query($query_set);
|
||||
|
||||
if ($this->is_success($result_set) === false) {
|
||||
|
||||
return false;
|
||||
|
||||
} // end if;
|
||||
|
||||
$query = "ALTER TABLE {$this->table_name} ADD COLUMN `refund_total` decimal(13,4) default 0 AFTER `subtotal`;";
|
||||
|
||||
$result = $this->get_db()->query($query);
|
||||
|
||||
} // end if;
|
||||
|
||||
// Return success/fail
|
||||
return $this->is_success($result);
|
||||
|
||||
} // end __20210607;
|
||||
/**
|
||||
* Fixes the datetime columns to accept null.
|
||||
*
|
||||
* @since 2.1.2
|
||||
*/
|
||||
protected function __20230601(): bool {
|
||||
|
||||
$null_columns = array(
|
||||
'date_created',
|
||||
'date_modified',
|
||||
);
|
||||
|
||||
foreach ($null_columns as $column) {
|
||||
|
||||
$query = "ALTER TABLE {$this->table_name} MODIFY COLUMN `{$column}` datetime DEFAULT NULL;";
|
||||
|
||||
$result = $this->get_db()->query($query);
|
||||
|
||||
if (!$this->is_success($result)) {
|
||||
|
||||
return false;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end foreach;
|
||||
|
||||
return true;
|
||||
|
||||
} // end __20230601;
|
||||
|
||||
} // end class Payments_Table;
|
Reference in New Issue
Block a user