Debug callback
This commit is contained in:
parent
46fc016dc7
commit
53466a6788
1 changed files with 75 additions and 5 deletions
|
@ -93,6 +93,7 @@ function zgopmt_init() {
|
||||||
|
|
||||||
if ( ! $this->is_valid_for_use() )
|
if ( ! $this->is_valid_for_use() )
|
||||||
$this->enabled = false;
|
$this->enabled = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the webhook for payment confirmation from ZGo
|
* Add the webhook for payment confirmation from ZGo
|
||||||
*/
|
*/
|
||||||
|
@ -293,12 +294,12 @@ function zgopmt_init() {
|
||||||
$rate = $_GET['rate'];
|
$rate = $_GET['rate'];
|
||||||
$order = wc_get_order( $orderid );
|
$order = wc_get_order( $orderid );
|
||||||
|
|
||||||
$sql = $wpdb->prepare('select * from zgo_payments where pmt_wc_order = %s;', $orderid);
|
$sql = $wpdb->prepare('select * from zgo_payments where pmt_wc_order = %s ;', $orderid);
|
||||||
//$sql = "select * from zgo_payments where pmt_wc_order = '" . $orderid . "';";
|
//$sql = "select * from zgo_payments where pmt_wc_order = '" . $orderid . "';";
|
||||||
$result = $wpdb->get_row($sql,OBJECT);
|
$result = $wpdb->get_row($sql,OBJECT);
|
||||||
if ( ! is_null($result) ) {
|
if ( ! is_null($result) ) {
|
||||||
|
|
||||||
if ( ( hash('sha256', $token) == hash('sha256', $this->zgotoken) )
|
if ( ($token == $this->zgotoken )
|
||||||
&& ( $result->pmt_orderid == $zgoOrderid )
|
&& ( $result->pmt_orderid == $zgoOrderid )
|
||||||
&& ( $result->pmt_wc_paid == '0' ) ) {
|
&& ( $result->pmt_wc_paid == '0' ) ) {
|
||||||
switch ( $order->get_status() ) {
|
switch ( $order->get_status() ) {
|
||||||
|
@ -321,14 +322,17 @@ function zgopmt_init() {
|
||||||
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...');
|
||||||
|
return array("message" => 'Order ' . $orderid . ' already paid or cancelled...');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// $this->console_log('Invalid parameters...');
|
//$this->console_log('Invalid parameters...');
|
||||||
|
return array("message" => 'Invalid parameters...');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// $this->console_log('Database error...');
|
//$this->console_log('Database error...');
|
||||||
|
return array("message" => 'Database error...');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -351,6 +355,8 @@ function zgopmt_init() {
|
||||||
return $edata;
|
return $edata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
add_filter( 'woocommerce_payment_gateways',
|
add_filter( 'woocommerce_payment_gateways',
|
||||||
|
@ -376,3 +382,67 @@ function zgopmtlist_plugin() {
|
||||||
$plugin->init();
|
$plugin->init();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_custom($data) {
|
||||||
|
global $wpdb;
|
||||||
|
|
||||||
|
//$token = $_GET['token'];
|
||||||
|
//$zgoOrderid = $_GET['orderid'];
|
||||||
|
//$orderid = $_GET['wc_orderid'];
|
||||||
|
//$totalzec = $_GET['totalzec'];
|
||||||
|
//$rate = $_GET['rate'];
|
||||||
|
$token = $data->token;
|
||||||
|
$zgoOrderid = $data->orderid;
|
||||||
|
$orderid = $data->wc_orderid;
|
||||||
|
$totalzec = $data->totalzec;
|
||||||
|
$rate = $data->rate;
|
||||||
|
$order = wc_get_order( $orderid );
|
||||||
|
|
||||||
|
//$sql = $wpdb->prepare('select * from zgo_payments where pmt_wc_order = %s ;', $orderid);
|
||||||
|
$sql = "select * from zgo_payments where pmt_wc_order = '" . $orderid . "';";
|
||||||
|
$result = $wpdb->get_row($sql,OBJECT);
|
||||||
|
if ( ! is_null($result) ) {
|
||||||
|
|
||||||
|
if ( ($token == $this->zgotoken )
|
||||||
|
&& ( $result->pmt_orderid == $zgoOrderid )
|
||||||
|
&& ( $result->pmt_wc_paid == '0' ) ) {
|
||||||
|
switch ( $order->get_status() ) {
|
||||||
|
case 'pending':
|
||||||
|
case 'failed':
|
||||||
|
$order->payment_complete();
|
||||||
|
$order->reduce_order_stock();
|
||||||
|
//
|
||||||
|
// Mark order as completed in ZGo DB
|
||||||
|
//
|
||||||
|
//$sql = "update zgo_payments set " .
|
||||||
|
//"pmt_confirmed='" . date('Y-m-d H:i:s') .
|
||||||
|
//"', pmt_rate=" . $rate .
|
||||||
|
//", pmt_zec=" . $totalzec .
|
||||||
|
//", pmt_wc_paid=1 " .
|
||||||
|
//" where pmt_wc_order='" . $orderid . "';";
|
||||||
|
$sql2 = $wpdb->prepare('update zgo_payments set pmt_confirmed = %s, pmt_rate = %f, pmt_zec = %f, pmt_wc_paid = 1 where pmt_wc_order = %s;', date('Y-m-d H:i:s'), $rate, $totalzec, $orderid );
|
||||||
|
$wpdb->query($sql2);
|
||||||
|
|
||||||
|
//update_option('webhook_debug', $_GET);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
//$this->console_log('Order ' . $orderid . ' already paid or cancelled...');
|
||||||
|
return array("message" => 'Order ' . $orderid . ' already paid or cancelled...');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//$this->console_log('Invalid parameters...');
|
||||||
|
return array("message" => 'Invalid parameters...');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//$this->console_log('Database error...');
|
||||||
|
return array("message" => 'Database error...');
|
||||||
|
}
|
||||||
|
//return array( 'custom' => 'Data', "request" => $data->get_params() );
|
||||||
|
}
|
||||||
|
|
||||||
|
add_action( 'rest_api_init', function () {
|
||||||
|
register_rest_route( 'wc/v3', 'custom', array(
|
||||||
|
'methods' => 'GET',
|
||||||
|
'callback' => 'get_custom'));
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue