From 89d4f1bdcae8790ec555ceadeec981c5edd15f9a Mon Sep 17 00:00:00 2001 From: Rene Vergara A Date: Fri, 30 Dec 2022 15:54:06 -0500 Subject: [PATCH] First version of unified payment component --- assets/php/class-submenu-page.php | 586 ++++++++++++++++++++++++++++++ assets/php/class-submenu.php | 44 +++ zgopmtgwy.php | 14 +- 3 files changed, 643 insertions(+), 1 deletion(-) create mode 100644 assets/php/class-submenu-page.php create mode 100644 assets/php/class-submenu.php diff --git a/assets/php/class-submenu-page.php b/assets/php/class-submenu-page.php new file mode 100644 index 0000000..5660907 --- /dev/null +++ b/assets/php/class-submenu-page.php @@ -0,0 +1,586 @@ +_path = $path; + $this->console_log('$_path -> '. $this->_path); + + $this->_nrows = $this->getPmtsCount(); + // + // Create zgo_pmtlst if does not exist + // + $sql = 'create table if not exists zgo_pmtlst (' . + 'pg_ix integer ,' . + 'pg_page integer not null default 0,' . + 'pg_npages integer not null default 0,' . + 'pg_offset integer not null default 0,' . + 'pg_limit integer not null default 0,' . + 'pg_dt datetime default current_timestamp, '. + 'unique lstix (pg_ix) );'; + $wpdb->query($sql); + + if ( ! $this->pmtLstRdy() ) { + // + // Calculate first time pagination paramters + // + $this->_limit = 10; + $this->_page = 1; + $this->_offset = 0; + $this->_npages = intdiv($this->_nrows,$this->_limit); + if ( $this->_nrows > ($this->_npages*$this->_limit) ) { + $this->_npages++; + } + + $sql = 'insert into zgo_pmtlst (pg_ix,pg_page,pg_npages,pg_offset,pg_limit) values (1,' . + $this->_page . ',' . + $this->_npages . ',' . + $this->_offset . ',' . + $this->_limit .')'; + $wpdb->query($sql); + } else { + // Load last state + $params = $this->pmtLstParams(); + $this->_page = $params->pg_page; + $this->_offset = $params->pg_offset; + $this->_limit = $params->pg_limit; + $this->_npages = $params->pg_npages; + if ( $this->_nrows > ($this->_npages*$this->_limit) ) { + // + // Calc new number of pages + // + $this->_npages = intdiv($this->_nrows,$this->_limit); + if ( $this->_nrows > ($this->_npages*$this->_limit) ) { + $this->_npages++; + } + $sql = 'update zgo_pmtlst set pg_npages=' . $this->_npages . ' where pg_ix=1'; + $wpdb->query($sql); + } + } + } + + public function getPmtsCount() { + global $wpdb; + + $sql = "select count(*) as npmts from zgo_payments"; + $result = $wpdb->get_var($sql); + $this->console_log('getPmtsCount() -> ' . $result); + return $result; + } + + public function pmtLstRdy() { + global $wpdb; + $sql = 'select count(*) as nrecs from zgo_pmtlst;'; + $result = $wpdb->get_var($sql); + $this->console_log("pmtLstRdy() -> " . $result); + return $result; + } + + public function pmtLstParams() { + global $wpdb; + $sql = 'select * from zgo_pmtlst where pg_ix=1;'; + $result = $wpdb->get_row($sql,OBJECT); + $this->console_log('Params -> ' . json_encode($result) ); + $this->console_log('pg_ix -> ' . $result->pg_ix ); + $this->console_log('pg_page -> ' . $result->pg_page ); + $this->console_log('pg_offset -> ' . $result->pg_offset ); + return $result; + } + + public function console_log($data) { + + $file = $this->_path . 'zgopmtgwy/assets/console.log'; + file_put_contents($file, 'LST::' . $data . chr(0x0D) . chr(0x0A), FILE_TEXT | FILE_APPEND | LOCK_EX ); + + } + + public function render() { + global $wpdb; + + $currentDate = date('Y-m-d H:i:s'); + + if ($_SERVER['REQUEST_METHOD'] === 'POST') { + // + // Navigation button pressed + // + $sql = 'select * from zgo_pmtlst where pg_ix=1;'; + $result = $wpdb->get_row($sql,OBJECT); + $this->_page = $result->pg_page; + $this->console_log("_page -> " . $this->_page); + $this->_limit = $result->pg_limit; + $this->console_log("_limit -> " . $this->_limit); + $this->_npages = $result->pg_npages; + $this->console_log("_npages -> " . $this->_npages); + $this->_nrows = $this->getPmtsCount(); + $this->console_log("_nrows -> " . $this->_nrows); + if ( $this->_nrows > ($this->_npages*$this->_limit) ) { + $this->console_log('_nrows > ' . ($this->_npages*$this->_limit)); + $this->_npages = intdiv($this->_nrows,$this->_limit); + $this->console_log('_npages > ' . $this->_npages ); + if ( $this->_nrows > ($this->_npages*$this->_limit) ) { + $this->_npages++; + $this->console_log('Page number increased to ' . $this->_npages); + } + } + + if ( isset($_POST['First'])) { + $this->_page = 1; + $this->_offset = 0; + } + + if ( isset($_POST['Previous'])) { + if ($this->_page > 1) { + $this->_page--; + } + $this->_offset = $this->_limit*($this->_page-1); + } + + if ( isset($_POST['Next'])) { + if ($this->_page < $this->_npages ) { + $this->_page++; + } + $this->_offset = $this->_limit*($this->_page-1); + } + + if ( isset($_POST['Last'])) { + $this->_page = $this->_npages; + $this->_offset = $this->_limit*($this->_page-1); + } + // + // Save new list state + // + $sql = 'update zgo_pmtlst set pg_page=' . $this->_page . + ', pg_npages=' . $this->_npages . + ', pg_offset=' . $this->_offset . ' where pg_ix=1;'; + $this->console_log( $sql ); + $wpdb->query($sql); + } + + ?> +
+ ZGo Payment Gateway - Received Payments +
+ +
+ + + + + +
+ _page . '/' . $this->_npages; + ?> + + +
+ + + + + + + + + + + + + + _offset . "," . $this->_limit; + $result = $wpdb->get_results($sql,OBJECT); + $npmts = count($result); + if ( $npmts > 0 ) { + $line = 0; + while ( $line < $npmts ) { + $row = $result[$line]; + if ( fmod($line,2) ) { + print ''; + } else { + print ''; + } + $line++; + print '"; + print ""; + print ""; + print '"; + print '"; + print '"; + print '"; + print '"; + print '"; + } + ?> +
ZGo Order IdShop Order IdCustomerAcceptedConfirmedOrder TotalRateTotal ZECPaid?
' . $row->pmt_orderid . "" . $row->pmt_wc_order . "" . $row->pmt_wc_custname . "'. $row->pmt_accepted . "'.$row->pmt_confirmed ."'. number_format($row->pmt_amount,2) . "'. number_format($row->pmt_rate,2) . "'. number_format($row->pmt_zec,8) . "'.$row->pmt_wc_paid ."
+
+
+
+ + + + + + + + + +
+ + + + + + + +
+
+ + render_stats(); + $this->render_totals(); + } + } + + public function render_stats() { + + global $wpdb; + + $sql = "select ifnull(a.dTotalAmount,0) as dTotalAmount, ifnull(a.dTotalZec,0) as dTotalZec, ifnull(a.dTotalPmts,0) as dTotalPmts, ifnull(b.wTotalAmount,0) as wTotalAmount, ifnull(b.wTotalZec,0) as wTotalZec, ifnull(b.wTotalPmts,0) as wTotalPmts, ifnull(c.mTotalAmount,0) as mTotalAmount, ifnull(c.mTotalZec,0) as mTotalZec, ifnull(c.mTotalPmts,0) as mTotalPmts from (select sum(a0.pmt_amount) as dTotalAmount, sum(a0.pmt_zec) as dTotalZec, count(*) as dTotalPmts from zgo_payments a0 where STR_TO_DATE(left(a0.pmt_confirmed,10), '%Y-%m-%d') = CURRENT_DATE ) a join (select sum(aa.pmt_amount) as wTotalAmount, sum(aa.pmt_zec) as wTotalZec, count(*) as wTotalPmts from zgo_payments aa where STR_TO_DATE(aa.pmt_confirmed, '%Y-%m-%d %H:%i:%s') >= DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) b join (select sum(bb.pmt_amount) as mTotalAmount, sum(bb.pmt_zec) as mTotalZec, count(*) as mTotalPmts from zgo_payments bb where STR_TO_DATE(bb.pmt_confirmed, '%Y-%m-%d %H:%i:%s') >= DATE_SUB(CURRENT_DATE, INTERVAL 30 DAY)) c where 1;"; + $result = $wpdb->get_row($sql,OBJECT); + ?> +
+ ZGo Confirmed Payments Statistics +
+ + + + + + + + + + + + + +
+ + + + + + +
Payments receivedDescriptionValue
+
+ + + + + + + + + + + + + + + + +
Received Today + + + + + + + + + + + + + +
Total Amount
Average Rate
Total Zec
Number of payments
+
+ + + + + + + + + + + + + +
dTotalAmount,2);?>
dTotalZec > 0.0) { + echo number_format($result->dTotalZec/$result->dTotalAmount,2); + } else { echo '0.00'; } ?>
dTotalZec,8);?>
dTotalPmts;?>
+
Last 7 days + + + + + + + + + + + + + +
Total Amount
Average Rate
Total Zec
Number of payments
+
+ + + + + + + + + + + + + +
wTotalAmount,2);?>
wTotalZec > 0.0) { + echo number_format($result->wTotalAmount/$result->wTotalZec,2); + } else { echo '0.00'; } ?>
wTotalZec,8);?>
wTotalPmts;?>
+
Last 30 days + + + + + + + + + + + + + +
Total Amount
Average Rate
Total Zec
Number of payments
+
+ + + + + + + + + + + + + +
mTotalAmount,2);?>
mTotalZec> 0.0) { + echo number_format($result->mTotalAmount/$result->mTotalZec,2); + } else { echo '0.00'; } ?>
mTotalZec,8);?>
mTotalPmts;?>
+
+
+ get_row($sql,OBJECT); + if ( $result ) { + if ($result->gTotalPmts > 0) { + ?> +
+ Global Totals +
+ + + + + +
+ + + + + + + + + +
Payments:gTotalPmts ?>Total Amount:gTotalAmount,2) ?>Total ZEC:gTotalZec,8) ?>
+
+ submenu_page = $submenu_page; + } + + /** + * Adds a submenu for this plugin to the 'Tools' menu. + **/ + public function init() { + add_action( 'admin_menu', array( $this, 'add_options_page' ) ); + } + + /** + * Creates the submenu item and calls on the Submenu Page object to render + * the actual contents of the page. + **/ + public function add_options_page() { + + add_management_page( + 'ZGo Payment Gateway Support', + 'ZGo Payments', + 'manage_options', + 'zgopmtlist', + array( $this->submenu_page, 'render' ) + ); + } + +} diff --git a/zgopmtgwy.php b/zgopmtgwy.php index 344f17a..46cf367 100644 --- a/zgopmtgwy.php +++ b/zgopmtgwy.php @@ -3,7 +3,7 @@ * Plugin Name: ZGo Payment Gateway * Plugin URI: https://vergara.tech' * Description: ZGo latest payment processing solution for Woocommerce. Accept payments using Zcash. -* Version: 0.8 +* Version: 0.8a * Requires at least: 5.2 * Requires PHP: 7.2 * Author: Vergara Tech LLC @@ -411,5 +411,17 @@ function zgopmt_init() { return $methods; } +} + +// Include the dependencies needed to instantiate the plugin. +foreach ( glob( plugin_dir_path( __FILE__ ) . 'assets/php/*.php' ) as $file ) { + include_once $file; +} + +add_action( 'plugins_loaded', 'zgopmtlist_plugin' ); +function zgopmtlist_plugin() { + + $plugin = new Submenu( new Submenu_Page() ); + $plugin->init(); }