Version 0.9 - log calls removed
This commit is contained in:
parent
93658f1e3c
commit
4e3a32f5d1
2 changed files with 7 additions and 76 deletions
|
@ -5,7 +5,6 @@
|
||||||
* This class creates the statistics page for the plugin.
|
* This class creates the statistics page for the plugin.
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
|
|
||||||
class zpmt_stats_page {
|
class zpmt_stats_page {
|
||||||
|
|
||||||
public $_limit;
|
public $_limit;
|
||||||
|
@ -79,15 +78,13 @@ class zpmt_stats_page {
|
||||||
|
|
||||||
$sql = "select count(*) as npmts from zgo_payments";
|
$sql = "select count(*) as npmts from zgo_payments";
|
||||||
$result = $wpdb->get_var($sql);
|
$result = $wpdb->get_var($sql);
|
||||||
$this->console_log('getPmtsCount() -> ' . $result);
|
return $result;
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function pmtLstRdy() {
|
public function pmtLstRdy() {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
$sql = 'select count(*) as nrecs from zgo_pmtlst;';
|
$sql = 'select count(*) as nrecs from zgo_pmtlst;';
|
||||||
$result = $wpdb->get_var($sql);
|
$result = $wpdb->get_var($sql);
|
||||||
$this->console_log("pmtLstRdy() -> " . $result);
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,10 +92,6 @@ class zpmt_stats_page {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
$sql = 'select * from zgo_pmtlst where pg_ix=1;';
|
$sql = 'select * from zgo_pmtlst where pg_ix=1;';
|
||||||
$result = $wpdb->get_row($sql,OBJECT);
|
$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;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,23 +110,16 @@ class zpmt_stats_page {
|
||||||
//
|
//
|
||||||
// Navigation button pressed
|
// Navigation button pressed
|
||||||
//
|
//
|
||||||
$sql = 'select * from zgo_pmtlst where pg_ix=1;';
|
$sql = 'select * from zgo_pmtlst where pg_ix=1;';
|
||||||
$result = $wpdb->get_row($sql,OBJECT);
|
$result = $wpdb->get_row($sql,OBJECT);
|
||||||
$this->_page = $result->pg_page;
|
$this->_page = $result->pg_page;
|
||||||
$this->console_log("_page -> " . $this->_page);
|
|
||||||
$this->_limit = $result->pg_limit;
|
$this->_limit = $result->pg_limit;
|
||||||
$this->console_log("_limit -> " . $this->_limit);
|
|
||||||
$this->_npages = $result->pg_npages;
|
$this->_npages = $result->pg_npages;
|
||||||
$this->console_log("_npages -> " . $this->_npages);
|
|
||||||
$this->_nrows = $this->getPmtsCount();
|
$this->_nrows = $this->getPmtsCount();
|
||||||
$this->console_log("_nrows -> " . $this->_nrows);
|
|
||||||
if ( $this->_nrows > ($this->_npages*$this->_limit) ) {
|
if ( $this->_nrows > ($this->_npages*$this->_limit) ) {
|
||||||
$this->console_log('_nrows > ' . ($this->_npages*$this->_limit));
|
|
||||||
$this->_npages = intdiv($this->_nrows,$this->_limit);
|
$this->_npages = intdiv($this->_nrows,$this->_limit);
|
||||||
$this->console_log('_npages > ' . $this->_npages );
|
|
||||||
if ( $this->_nrows > ($this->_npages*$this->_limit) ) {
|
if ( $this->_nrows > ($this->_npages*$this->_limit) ) {
|
||||||
$this->_npages++;
|
$this->_npages++;
|
||||||
$this->console_log('Page number increased to ' . $this->_npages);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,7 +152,6 @@ class zpmt_stats_page {
|
||||||
$sql = 'update zgo_pmtlst set pg_page=' . $this->_page .
|
$sql = 'update zgo_pmtlst set pg_page=' . $this->_page .
|
||||||
', pg_npages=' . $this->_npages .
|
', pg_npages=' . $this->_npages .
|
||||||
', pg_offset=' . $this->_offset . ' where pg_ix=1;';
|
', pg_offset=' . $this->_offset . ' where pg_ix=1;';
|
||||||
$this->console_log( $sql );
|
|
||||||
$wpdb->query($sql);
|
$wpdb->query($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,10 +45,6 @@ function zgopmt_init() {
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
|
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
$this->console_log("Gateway constructor accesed.");
|
|
||||||
|
|
||||||
$this->console_log('Create zgo_payments table if not exists...');
|
|
||||||
//
|
//
|
||||||
// Create payments table in WordPress database
|
// Create payments table in WordPress database
|
||||||
//
|
//
|
||||||
|
@ -63,15 +59,12 @@ function zgopmt_init() {
|
||||||
'pmt_zec double (12,8) not null default 0.0,' .
|
'pmt_zec double (12,8) not null default 0.0,' .
|
||||||
'pmt_wc_paid int not null default 0,' .
|
'pmt_wc_paid int not null default 0,' .
|
||||||
'unique pmt_orderix (pmt_orderid, pmt_wc_order) )';
|
'unique pmt_orderix (pmt_orderid, pmt_wc_order) )';
|
||||||
$this->console_log('Create table Query -> ' . $sql);
|
|
||||||
$wpdb->query($sql);
|
$wpdb->query($sql);
|
||||||
$this->console_log('zgopayments Table created in MySQL ...');
|
|
||||||
|
|
||||||
$iconurl = plugin_dir_url( __FILE__ ) .
|
$iconurl = plugin_dir_url( __FILE__ ) .
|
||||||
'assets/img/zgo-icon-full_6pct.png';
|
'assets/img/zgo-icon-full_6pct.png';
|
||||||
|
|
||||||
$this->siteURL = get_site_url();
|
$this->siteURL = get_site_url();
|
||||||
$this->console_log("Site URL: " . $this->siteURL);
|
|
||||||
|
|
||||||
$this->domain = 'zgopmtgwy';
|
$this->domain = 'zgopmtgwy';
|
||||||
|
|
||||||
|
@ -186,28 +179,22 @@ function zgopmt_init() {
|
||||||
$this->zgotoken . '&siteurl=' .
|
$this->zgotoken . '&siteurl=' .
|
||||||
$this->base64url_encode($this->siteURL);
|
$this->base64url_encode($this->siteURL);
|
||||||
|
|
||||||
$this->console_log('URL -> ' . $url );
|
|
||||||
|
|
||||||
$response = wp_remote_get($url);
|
$response = wp_remote_get($url);
|
||||||
$this->console_log(json_encode($response));
|
|
||||||
|
|
||||||
$httpcode = wp_remote_retrieve_response_code( $response );
|
$httpcode = wp_remote_retrieve_response_code( $response );
|
||||||
$this->console_log('Status Code -> ' . $httpcode );
|
|
||||||
|
|
||||||
switch ( $httpcode ) {
|
switch ( $httpcode ) {
|
||||||
case 200:
|
case 200:
|
||||||
$body = wp_remote_retrieve_body( $response );
|
$body = wp_remote_retrieve_body( $response );
|
||||||
$oid = json_decode($body);
|
$oid = json_decode($body);
|
||||||
$this->console_log('Body -> ' . $body);
|
|
||||||
$isvalid = $oid->{'authorized'};
|
$isvalid = $oid->{'authorized'};
|
||||||
break;
|
break;
|
||||||
case 202:
|
case 202:
|
||||||
$body = wp_remote_retrieve_body($response );
|
$body = wp_remote_retrieve_body($response );
|
||||||
$oid = json_decode($body);
|
$oid = json_decode($body);
|
||||||
$this->console_log('message -> ' . $oid->{'message'});
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$this->console_log('Conection error..');
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -221,14 +208,10 @@ function zgopmt_init() {
|
||||||
|
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
$this->console_log('Site URL ->' . $this->siteURL);
|
|
||||||
$this->console_log('Processing payment for order ' . $order_id);
|
|
||||||
|
|
||||||
$order = wc_get_order( $order_id );
|
$order = wc_get_order( $order_id );
|
||||||
// $wc_order = wc_get_product($order_id);
|
// $wc_order = wc_get_product($order_id);
|
||||||
$wc_order_key = $order->get_order_key();
|
$wc_order_key = $order->get_order_key();
|
||||||
|
|
||||||
$this->console_log('Order ' . $order_id . ' key = ' . $wc_order_key);
|
|
||||||
|
|
||||||
$url = 'https://test.zgo.cash/woopayment' .
|
$url = 'https://test.zgo.cash/woopayment' .
|
||||||
'?ownerid=' . $this->zgoownerid .
|
'?ownerid=' . $this->zgoownerid .
|
||||||
|
@ -242,29 +225,19 @@ function zgopmt_init() {
|
||||||
|
|
||||||
//'&orderkey=' . ;
|
//'&orderkey=' . ;
|
||||||
|
|
||||||
$this->console_log('ZGoPayment URL -> ' . $url);
|
|
||||||
$this->console_log('Calling wp_remote_get()');
|
|
||||||
$response = wp_remote_get($url);
|
$response = wp_remote_get($url);
|
||||||
$httpcode = wp_remote_retrieve_response_code( $response );
|
$httpcode = wp_remote_retrieve_response_code( $response );
|
||||||
|
|
||||||
$this->console_log('Status Code ->' . $httpcode );
|
|
||||||
|
|
||||||
switch ( $httpcode ) {
|
switch ( $httpcode ) {
|
||||||
case 200:
|
case 200:
|
||||||
wc_add_notice( 'Order on hold, please wait for confirmation');
|
wc_add_notice( 'Order on hold, please wait for confirmation');
|
||||||
$order->update_status('on_hold',__('Awaiting payment confirmation','woocommerce'));
|
$order->update_status('on_hold',__('Awaiting payment confirmation','woocommerce'));
|
||||||
$this->console_log('Order ' . $order_id . ' status set to ON_HOLD');
|
|
||||||
|
|
||||||
$body = wp_remote_retrieve_body( $response );
|
$body = wp_remote_retrieve_body( $response );
|
||||||
$this->console_log('res. body = ' . $body);
|
|
||||||
|
|
||||||
$oid = json_decode($body);
|
$oid = json_decode($body);
|
||||||
$zgoOrderid = $oid->{'order'};
|
$zgoOrderid = $oid->{'order'};
|
||||||
$this->console_log('ZGo order = ' . $zgoOrderid);
|
|
||||||
//
|
//
|
||||||
// Save ZGo Order ID and Cart order
|
// Save ZGo Order ID and Cart order
|
||||||
//
|
//
|
||||||
$this->console_log("Preparing SQL insert statement");
|
|
||||||
$sql = "replace into zgo_payments (" .
|
$sql = "replace into zgo_payments (" .
|
||||||
"pmt_orderid," .
|
"pmt_orderid," .
|
||||||
"pmt_wc_order," .
|
"pmt_wc_order," .
|
||||||
|
@ -282,14 +255,11 @@ function zgopmt_init() {
|
||||||
date('Y-m-d H:i:s') . "','',".
|
date('Y-m-d H:i:s') . "','',".
|
||||||
$order->get_total() .
|
$order->get_total() .
|
||||||
",0,0,0)";
|
",0,0,0)";
|
||||||
$this->console_log($sql);
|
|
||||||
$wpdb->query($sql);
|
$wpdb->query($sql);
|
||||||
|
|
||||||
// Remove cart.
|
// Remove cart.
|
||||||
WC()->cart->empty_cart();
|
WC()->cart->empty_cart();
|
||||||
|
|
||||||
$this->console_log($this->get_return_url( $order ));
|
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'result' => 'success',
|
'result' => 'success',
|
||||||
'redirect' => 'https://dev.zgo.cash/invoice/' . $zgoOrderid,
|
'redirect' => 'https://dev.zgo.cash/invoice/' . $zgoOrderid,
|
||||||
|
@ -297,11 +267,7 @@ function zgopmt_init() {
|
||||||
break;
|
break;
|
||||||
case 202:
|
case 202:
|
||||||
$body = wp_remote_retrieve_body( $response );
|
$body = wp_remote_retrieve_body( $response );
|
||||||
$this->console_log('res. body = ' . $body);
|
|
||||||
|
|
||||||
$msg = json_decode($body);
|
$msg = json_decode($body);
|
||||||
$this->console_log('Order ' . $order_id . ' -> ZGo Order Generation Error : ' . $msg->{'message'});
|
|
||||||
|
|
||||||
$order->update_status('failed',__('Order ' . $order_id . ' -> ZGo Order Generation Error : ' . $msg->{'message'},'woocommerce'));
|
$order->update_status('failed',__('Order ' . $order_id . ' -> ZGo Order Generation Error : ' . $msg->{'message'},'woocommerce'));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -317,8 +283,6 @@ function zgopmt_init() {
|
||||||
|
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
$this->console_log('zconfirm called ');
|
|
||||||
|
|
||||||
$token = $_GET['token'];
|
$token = $_GET['token'];
|
||||||
$zgoOrderid = $_GET['orderid'];
|
$zgoOrderid = $_GET['orderid'];
|
||||||
$orderid = $_GET['wc_orderid'];
|
$orderid = $_GET['wc_orderid'];
|
||||||
|
@ -327,28 +291,15 @@ function zgopmt_init() {
|
||||||
$order = wc_get_order( $orderid );
|
$order = wc_get_order( $orderid );
|
||||||
|
|
||||||
$sql = "select * from zgo_payments where pmt_wc_order = '" . $orderid . "';";
|
$sql = "select * from zgo_payments where pmt_wc_order = '" . $orderid . "';";
|
||||||
$this->console_log('SQL -> ' . $sql);
|
|
||||||
$result = $wpdb->get_row($sql,OBJECT);
|
$result = $wpdb->get_row($sql,OBJECT);
|
||||||
if ( ! is_null($result) ) {
|
if ( ! is_null($result) ) {
|
||||||
|
|
||||||
$this->console_log('Query successfull...');
|
|
||||||
$this->console_log('totalzec -> ', $totalzec);
|
|
||||||
$this->console_log('rate -> ', $rate);
|
|
||||||
$this->console_log('pmt_wc_paid=' . $result->pmt_wc_paid);
|
|
||||||
$this->console_log('local token -> ' . $this->zgotoken);
|
|
||||||
$this->console_log('received token -> ' . $token);
|
|
||||||
$this->console_log('zgoOrderid -> ' . $zgoOrderid);
|
|
||||||
$this->console_log('pmt_orderid -> ' . $result->pmt_orderid);
|
|
||||||
|
|
||||||
if ( ( $token == $this->zgotoken )
|
if ( ( $token == $this->zgotoken )
|
||||||
&& ( $result->pmt_orderid == $zgoOrderid )
|
&& ( $result->pmt_orderid == $zgoOrderid )
|
||||||
&& ( $result->pmt_wc_paid == '0' ) ) {
|
&& ( $result->pmt_wc_paid == '0' ) ) {
|
||||||
$this->console_log('Test successfull...');
|
|
||||||
$this->console_log('Order status -> ' . $order->get_status());
|
|
||||||
switch ( $order->get_status() ) {
|
switch ( $order->get_status() ) {
|
||||||
case 'pending':
|
case 'pending':
|
||||||
case 'failed':
|
case 'failed':
|
||||||
$this->console_log('Confirming payment for order ' . $orderid);
|
|
||||||
$order->payment_complete();
|
$order->payment_complete();
|
||||||
$order->reduce_order_stock();
|
$order->reduce_order_stock();
|
||||||
//
|
//
|
||||||
|
@ -360,24 +311,19 @@ function zgopmt_init() {
|
||||||
", pmt_zec=" . $totalzec .
|
", pmt_zec=" . $totalzec .
|
||||||
", pmt_wc_paid=1 " .
|
", pmt_wc_paid=1 " .
|
||||||
" where pmt_wc_order='" . $orderid . "';";
|
" where pmt_wc_order='" . $orderid . "';";
|
||||||
/*
|
|
||||||
$this->zpmtdb->exec($sql);
|
|
||||||
*/
|
|
||||||
$this->console_log($sql);
|
|
||||||
$wpdb->query($sql);
|
$wpdb->query($sql);
|
||||||
$this->console_log('Order marked as paid in zgo_payments table...');
|
|
||||||
|
|
||||||
update_option('webhook_debug', $_GET);
|
update_option('webhook_debug', $_GET);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$this->console_log('Order ' . $orderid . ' already paid or cancelled...');
|
// $this->console_log('Order ' . $orderid . ' already paid or cancelled...');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->console_log('Invalid parameters...');
|
// $this->console_log('Invalid parameters...');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->console_log('Database error...');
|
// $this->console_log('Database error...');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -421,7 +367,7 @@ foreach ( glob( plugin_dir_path( __FILE__ ) . 'assets/php/*.php' ) as $file ) {
|
||||||
add_action( 'plugins_loaded', 'zgopmtlist_plugin' );
|
add_action( 'plugins_loaded', 'zgopmtlist_plugin' );
|
||||||
function zgopmtlist_plugin() {
|
function zgopmtlist_plugin() {
|
||||||
$path = plugin_dir_path( __FILE__ );
|
$path = plugin_dir_path( __FILE__ );
|
||||||
$plugin = new Submenu( new Submenu_Page($path) );
|
$plugin = new zpmt_stats( new zpmt_stats_page($path) );
|
||||||
$plugin->init();
|
$plugin->init();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue