prefix.DB::$namespace.'_payments'; } public function __construct() { parent::__construct(); $this->table_name = $this->prefix.'_payments'; $this->primary_key = 'id'; $this->version = '1.0'; } public function sql_create() { return "CREATE TABLE {$this->table_name} ( id bigint(20) NOT NULL AUTO_INCREMENT, uuid varchar(36) NOT NULL, restaurant_id bigint(20) DEFAULT NULL, booking_id bigint(20) DEFAULT NULL, voucher_id bigint(20) DEFAULT NULL, order_hash varchar(256) DEFAULT NULL, amount int DEFAULT NULL, currency varchar(25) DEFAULT NULL, payment_type varchar(25) DEFAULT NULL, order_date timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), order_status varchar(25) DEFAULT NULL, notes text DEFAULT NULL, name varchar(25) DEFAULT NULL, email varchar(100) DEFAULT NULL, address varchar(255) DEFAULT NULL, country varchar(25) DEFAULT NULL, postal_code varchar(25) DEFAULT NULL, stripe_payment_intent_id varchar(255) DEFAULT NULL, status varchar(25) DEFAULT NULL, stripe_payment_status varchar(25) DEFAULT NULL, stripe_payment_method varchar(255) DEFAULT NULL, stripe_payment_response text DEFAULT NULL, date_created datetime NOT NULL, date_modified datetime NOT NULL, PRIMARY KEY (id), KEY payments_restaurant_id_foreign (restaurant_id), CONSTRAINT payments_restaurant_id_foreign FOREIGN KEY (restaurant_id) REFERENCES {$this->prefix}_restaurants (id) ON DELETE CASCADE, KEY payments_booking_id_foreign (booking_id), CONSTRAINT payments_booking_id_foreign FOREIGN KEY (booking_id) REFERENCES {$this->prefix}_bookings (id) ON DELETE CASCADE, KEY payments_voucher_id (voucher_id) )"; } public function sql_update_columns_releases() { $queries = []; // Release 56 $queries['56'][] = "ALTER TABLE {$this->table_name} ADD settings longtext DEFAULT NULL AFTER stripe_payment_response"; $queries['98'][] = "ALTER TABLE {$this->table_name} ADD is_sandbox tinyint DEFAULT 0 AFTER payment_type"; // Version 2.1.8 $queries['118'] = [ "ALTER TABLE {$this->table_name} ADD xendit_invoice_id varchar(255) DEFAULT NULL AFTER stripe_payment_response", "ALTER TABLE {$this->table_name} ADD xendit_external_id varchar(255) DEFAULT NULL AFTER xendit_invoice_id", "ALTER TABLE {$this->table_name} ADD xendit_invoice_status varchar(50) DEFAULT NULL AFTER xendit_external_id" ]; // Version 2.2.6 $queries['126'] = [ "ALTER TABLE {$this->table_name} ADD upayments_order_id varchar(255) DEFAULT NULL AFTER xendit_invoice_status", "ALTER TABLE {$this->table_name} ADD upayments_reference_id varchar(255) DEFAULT NULL AFTER upayments_order_id", "ALTER TABLE {$this->table_name} ADD upayments_payment_id varchar(255) DEFAULT NULL AFTER upayments_reference_id", "ALTER TABLE {$this->table_name} ADD upayments_status varchar(50) DEFAULT NULL AFTER upayments_payment_id" ]; // Gift Vouchers (addon_gift_cards) - release 143. Links a payment row to a // voucher purchase (booking_id stays NULL for voucher payments). No FK: the // vouchers table is created after payments in install order. $queries['143'][] = "ALTER TABLE {$this->table_name} ADD voucher_id bigint(20) DEFAULT NULL AFTER booking_id"; // Release 144: index on voucher_id for installs that got the column through // the ALTER above (fresh installs get it from sql_create). Guarded so a // "Duplicate key name" error can never be raised. global $wpdb; $has_index = $wpdb->get_var("SHOW INDEX FROM {$this->table_name} WHERE Key_name = 'payments_voucher_id'"); if (!$has_index) { $queries['144'][] = "ALTER TABLE {$this->table_name} ADD INDEX payments_voucher_id (voucher_id)"; } $this->run_queries_updates($queries); } } SRR_DB_Payments::init();