Compare commits
No commits in common. "640911a1e2391b06753a5c5600c2e88c8b1c0926" and "c9b077f2255240054db88b7f647aaee225181866" have entirely different histories.
640911a1e2
...
c9b077f225
3 changed files with 244 additions and 389 deletions
|
@ -3,12 +3,6 @@ All notable changes to this project will be documented in this file.
|
|||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
- Security hardening changes to plugin queries.
|
||||
- Re-design of ZGo API callback to support WooCommerce 7.8.0
|
||||
|
||||
## [1.0.0-beta.1] - 2023-01-11
|
||||
|
||||
- Adjust production server integration
|
||||
|
|
|
@ -232,9 +232,9 @@ class zpmt_stats_page {
|
|||
font-weight: 600;">';
|
||||
}
|
||||
$line++;
|
||||
print '<td><a href="https://dev.zgo.cash/invoice/' . htmlentities($row->pmt_orderid, ENT_QUOTES) . '" target="_blank">' . htmlentities($row->pmt_orderid, ENT_QUOTES) . "</a></td>";
|
||||
print '<td><a href="https://dev.zgo.cash/invoice/' . $row->pmt_orderid . '" target="_blank">' . $row->pmt_orderid . "</a></td>";
|
||||
print "<td>" . $row->pmt_wc_order . "</td>";
|
||||
print "<td>" . htmlentities($row->pmt_wc_custname, ENT_QUOTES) . "</td>";
|
||||
print "<td>" . $row->pmt_wc_custname . "</td>";
|
||||
print '<td style="text-align:center;">'. $row->pmt_accepted . "</td>";
|
||||
print '<td style="text-align:center;">'.$row->pmt_confirmed ."</td>";
|
||||
print '<td style="text-align:right;">'. number_format($row->pmt_amount,2) . "</td>";
|
||||
|
|
293
zgopmtgwy.php
293
zgopmtgwy.php
|
@ -1,16 +1,16 @@
|
|||
<?php
|
||||
/**
|
||||
* Plugin Name: ZGo Payment Gateway
|
||||
* Plugin URI: https://vergara.tech'
|
||||
* Description: ZGo latest payment processing solution for Woocommerce. Accept payments using Zcash.
|
||||
* Version: 1.0.0
|
||||
* Requires at least: 5.2
|
||||
* Requires PHP: 7.2
|
||||
* Author: Vergara Tech LLC
|
||||
* Author URI: https://zgo.cash/
|
||||
* License: GPL v2 or later
|
||||
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
||||
**/
|
||||
* Plugin Name: ZGo Payment Gateway
|
||||
* Plugin URI: https://vergara.tech'
|
||||
* Description: ZGo latest payment processing solution for Woocommerce. Accept payments using Zcash.
|
||||
* Version: 1.0.0 beta
|
||||
* Requires at least: 5.2
|
||||
* Requires PHP: 7.2
|
||||
* Author: Vergara Tech LLC
|
||||
* Author URI: https://vergara.tech
|
||||
* License: GPL v2 or later
|
||||
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
||||
**/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
|
@ -93,17 +93,10 @@ function zgopmt_init() {
|
|||
|
||||
if ( ! $this->is_valid_for_use() )
|
||||
$this->enabled = false;
|
||||
|
||||
/**
|
||||
* Add the webhook for payment confirmation from ZGo
|
||||
*/
|
||||
//add_action( 'woocommerce_api_zpmtcallback', array($this,'zconfirm'));
|
||||
}
|
||||
|
||||
public function register_routes() {
|
||||
register_rest_route( 'wc/v3', 'zgocallback', array(
|
||||
'methods' => 'GET',
|
||||
'callback' => array($this,'zgoapicallback')));
|
||||
add_action( 'woocommerce_api_zpmtcallback', array($this,'zconfirm'));
|
||||
}
|
||||
|
||||
public function init_form_fields() {
|
||||
|
@ -181,7 +174,7 @@ function zgopmt_init() {
|
|||
if ( isset($this->zgoownerid) &&
|
||||
($this->zgoownerid !== '') ) {
|
||||
|
||||
$url = 'https://test.zgo.cash/auth?ownerid=' .
|
||||
$url = 'https://api.zgo.cash//auth?ownerid=' .
|
||||
$this->zgoownerid . '&token=' .
|
||||
$this->zgotoken . '&siteurl=' .
|
||||
$this->base64url_encode($this->siteURL);
|
||||
|
@ -197,7 +190,7 @@ function zgopmt_init() {
|
|||
$oid = json_decode($body);
|
||||
$isvalid = $oid->{'authorized'};
|
||||
break;
|
||||
case 202:
|
||||
case 202:git
|
||||
$body = wp_remote_retrieve_body($response );
|
||||
$oid = json_decode($body);
|
||||
break;
|
||||
|
@ -216,11 +209,11 @@ function zgopmt_init() {
|
|||
global $wpdb;
|
||||
|
||||
$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();
|
||||
|
||||
|
||||
$url = 'https://test.zgo.cash/woopayment' .
|
||||
$url = 'https://api.zgo.cash/woopayment' .
|
||||
'?ownerid=' . $this->zgoownerid .
|
||||
'&token=' . $this->zgotoken .
|
||||
'&order_id=' . $order_id .
|
||||
|
@ -242,37 +235,34 @@ function zgopmt_init() {
|
|||
$body = wp_remote_retrieve_body( $response );
|
||||
$oid = json_decode($body);
|
||||
$zgoOrderid = $oid->{'order'};
|
||||
$zgoOrderToken = $oid->{'token'};
|
||||
//
|
||||
// Save ZGo Order ID and Cart order
|
||||
//
|
||||
$sql3 = $wpdb->prepare('replace into zgo_payments (pmt_orderid, pmt_wc_order, pmt_wc_custname, pmt_accepted, pmt_confirmed, pmt_amount, pmt_rate, pmt_zec, pmt_wc_paid) values (%s, %s, %s, %s, %s, %f, 0, 0, 0);',
|
||||
$zgoOrderid, $order_id, $order->get_billing_first_name() . ' ' . $order->get_billing_last_name(), date('Y-m-d H:i:s'), '', $order->get_total());
|
||||
//$sql = "replace into zgo_payments (" .
|
||||
//"pmt_orderid," .
|
||||
//"pmt_wc_order," .
|
||||
//"pmt_wc_custname," .
|
||||
//"pmt_accepted," .
|
||||
//"pmt_confirmed," .
|
||||
//"pmt_amount," .
|
||||
//"pmt_rate," .
|
||||
//"pmt_zec," .
|
||||
//"pmt_wc_paid) values ('" .
|
||||
//$zgoOrderid . "','" .
|
||||
//$order_id . "','" .
|
||||
//$order->get_billing_first_name() . " " .
|
||||
//$order->get_billing_last_name() . "','" .
|
||||
//date('Y-m-d H:i:s') . "','',".
|
||||
//$order->get_total() .
|
||||
//",0,0,0)";
|
||||
$wpdb->query($sql3);
|
||||
$sql = "replace into zgo_payments (" .
|
||||
"pmt_orderid," .
|
||||
"pmt_wc_order," .
|
||||
"pmt_wc_custname," .
|
||||
"pmt_accepted," .
|
||||
"pmt_confirmed," .
|
||||
"pmt_amount," .
|
||||
"pmt_rate," .
|
||||
"pmt_zec," .
|
||||
"pmt_wc_paid) values ('" .
|
||||
$zgoOrderid . "','" .
|
||||
$order_id . "','" .
|
||||
$order->get_billing_first_name() . " " .
|
||||
$order->get_billing_last_name() . "','" .
|
||||
date('Y-m-d H:i:s') . "','',".
|
||||
$order->get_total() .
|
||||
",0,0,0)";
|
||||
$wpdb->query($sql);
|
||||
|
||||
// Remove cart.
|
||||
WC()->cart->empty_cart();
|
||||
|
||||
return array(
|
||||
'result' => 'success',
|
||||
'redirect' => 'https://dev.zgo.cash/invoice/' . $zgoOrderid . '?token=' . $zgoOrderToken,
|
||||
'redirect' => 'https://app.zgo.cash/invoice/' . $zgoOrderid,
|
||||
);
|
||||
break;
|
||||
case 202:
|
||||
|
@ -289,58 +279,53 @@ function zgopmt_init() {
|
|||
/**
|
||||
* Confirm payment and complete order
|
||||
*/
|
||||
//public function zconfirm() {
|
||||
public function zconfirm() {
|
||||
|
||||
//global $wpdb;
|
||||
global $wpdb;
|
||||
|
||||
//$token = $_GET['token'];
|
||||
//$zgoOrderid = $_GET['orderid'];
|
||||
//$orderid = $_GET['wc_orderid'];
|
||||
//$totalzec = $_GET['totalzec'];
|
||||
//$rate = $_GET['rate'];
|
||||
//$order = wc_get_order( $orderid );
|
||||
$token = $_GET['token'];
|
||||
$zgoOrderid = $_GET['orderid'];
|
||||
$orderid = $_GET['wc_orderid'];
|
||||
$totalzec = $_GET['totalzec'];
|
||||
$rate = $_GET['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) ) {
|
||||
$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);
|
||||
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 . "';";
|
||||
$wpdb->query($sql);
|
||||
|
||||
//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...');
|
||||
//}
|
||||
//}
|
||||
update_option('webhook_debug', $_GET);
|
||||
break;
|
||||
default:
|
||||
// $this->console_log('Order ' . $orderid . ' already paid or cancelled...');
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// $this->console_log('Invalid parameters...');
|
||||
}
|
||||
} else {
|
||||
// $this->console_log('Database error...');
|
||||
}
|
||||
}
|
||||
|
||||
public function thankyou_page () {
|
||||
if ( $description = $this->get_description() ) {
|
||||
|
@ -361,66 +346,6 @@ function zgopmt_init() {
|
|||
return $edata;
|
||||
}
|
||||
|
||||
public function zgoapicallback($request) {
|
||||
global $wpdb;
|
||||
|
||||
//$token = $_GET['token'];
|
||||
//$zgoOrderid = $_GET['orderid'];
|
||||
//$orderid = $_GET['wc_orderid'];
|
||||
//$totalzec = $_GET['totalzec'];
|
||||
//$rate = $_GET['rate'];
|
||||
$token = $request->get_param('token');
|
||||
$zgoOrderid = $request->get_param('orderid');
|
||||
$orderid = $request->get_param('wc_orderid');
|
||||
$totalzec = $request->get_param('totalzec');
|
||||
$rate = $request->get_param('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 ( (hash('sha256',$token) == hash('sha256',$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);
|
||||
return array('message' => 'Order '. $orderid . ' mark as paid correctly.');
|
||||
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_filter( 'woocommerce_payment_gateways',
|
||||
|
@ -446,67 +371,3 @@ function zgopmtlist_plugin() {
|
|||
$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->get_param('token');
|
||||
$zgoOrderid = $data->get_param('orderid');
|
||||
$orderid = $data->get_param('wc_orderid');
|
||||
$totalzec = $data->get_param('totalzec');
|
||||
$rate = $data->get_param('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() );
|
||||
}
|
||||
|
||||
function plugin_register_rest_apis() {
|
||||
$zgoPlugin = new WC_ZGopmt_Gateway();
|
||||
$zgoPlugin->register_routes();
|
||||
}
|
||||
add_action( 'rest_api_init', 'plugin_register_rest_apis');
|
||||
|
|
Loading…
Reference in a new issue