| 1 |
<?php |
| 2 |
defined('ABSPATH') || exit(); |
| 3 |
|
| 4 |
class Better_Payment_Installer |
| 5 |
{ |
| 6 |
|
| 7 |
public static function install() { |
| 8 |
self::create_tables(); |
| 9 |
|
| 10 |
//check setup wizard condition |
| 11 |
self::enable_setup_wizard(); |
| 12 |
} |
| 13 |
|
| 14 |
private static function get_schema() { |
| 15 |
global $wpdb; |
| 16 |
return [ |
| 17 |
"CREATE TABLE IF NOT EXISTS {$wpdb->prefix}better_payment( |
| 18 |
id bigint(20) NOT NULL AUTO_INCREMENT, |
| 19 |
order_id varchar(50) NOT NULL, |
| 20 |
transaction_id varchar(50) DEFAULT '', |
| 21 |
amount decimal(10,2) NOT NULL, |
| 22 |
status varchar(50) DEFAULT NULL, |
| 23 |
source varchar(50) NOT NULL, |
| 24 |
payment_date datetime DEFAULT NULL, |
| 25 |
email varchar(50) NOT NULL DEFAULT '', |
| 26 |
customer_info longtext, |
| 27 |
form_fields_info longtext, |
| 28 |
currency varchar(11) NOT NULL DEFAULT '', |
| 29 |
referer varchar(64) DEFAULT NULL, |
| 30 |
obj_id text, |
| 31 |
PRIMARY KEY (id), |
| 32 |
KEY order_id (order_id), |
| 33 |
KEY status (status) |
| 34 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8 " |
| 35 |
]; |
| 36 |
} |
| 37 |
|
| 38 |
public static function create_tables() { |
| 39 |
global $wpdb; |
| 40 |
$wpdb->hide_errors(); |
| 41 |
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
| 42 |
$tables = self::get_schema(); |
| 43 |
foreach ( $tables as $table ) { |
| 44 |
dbDelta( $table ); |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Save setup wizard data |
| 50 |
* |
| 51 |
* @since 0.0.2 |
| 52 |
*/ |
| 53 |
public static function enable_setup_wizard() |
| 54 |
{ |
| 55 |
if ( !get_option( 'better_payment_setup_wizard' ) ) { |
| 56 |
update_option( 'better_payment_setup_wizard', 'redirect' ); |
| 57 |
} |
| 58 |
} |
| 59 |
} |
| 60 |
|