@ -1,7 +1,7 @@
<?php
/*
* Main Gateway of Monero using either a local daemon or the explorer
* Authors: SerHack, cryptochangements, mosu-forge
* Authors: SerHack, cryptochangements
*/
defined( 'ABSPATH' ) || exit;
@ -10,10 +10,10 @@ require_once('class-monero-cryptonote.php');
class Monero_Gateway extends WC_Payment_Gateway
{
private static $_id = 'mo nero_gateway';
private static $_title = 'Mo nero Gateway';
private static $_method_title = 'Mo nero Gateway';
private static $_method_description = 'Mo nero Gateway Plug-in for WooCommerce.';
private static $_id = 'wow nero_gateway';
private static $_title = 'Wow nero Gateway';
private static $_method_title = 'Wow nero Gateway';
private static $_method_description = 'Wow nero Gateway Plug-in for WooCommerce.';
private static $_errors = [];
private static $discount = false;
@ -35,21 +35,21 @@ class Monero_Gateway extends WC_Payment_Gateway
private static $monero_explorer_tools;
private static $log;
private static $currencies = array('BTC', 'USD','EUR','CAD','INR','GBP','COP','SGD','JPY') ;
private static $currencies = 'USD';
private static $rates = array();
private static $payment_details = array();
public function get_icon()
{
return apply_filters('woocommerce_gateway_icon', '< img src = "'.MONERO_GATEWAY_PLUGIN_URL.'assets/images/ mo nero-icon.png"/ > ', $this->id);
return apply_filters('woocommerce_gateway_icon', '< img src = "'.MONERO_GATEWAY_PLUGIN_URL.'assets/images/ wow nero-icon.png"/ > ', $this->id);
}
function __construct($add_action=true)
{
$this->id = self::$_id;
$this->method_title = __(self::$_method_title, 'mo nero_gateway');
$this->method_description = __(self::$_method_description, 'mo nero_gateway');
$this->method_title = __(self::$_method_title, 'wow nero_gateway');
$this->method_description = __(self::$_method_description, 'wow nero_gateway');
$this->has_fields = false;
$this->supports = array(
'products',
@ -96,8 +96,8 @@ class Monero_Gateway extends WC_Payment_Gateway
// Initialize helper classes
self::$cryptonote = new Monero_Cryptonote();
if(self::$confirm_type == 'mo nero-wallet-rpc') {
require_once('class-mo nero-wallet-rpc.php');
if(self::$confirm_type == 'wow nero-wallet-rpc') {
require_once('class-wow nero-wallet-rpc.php');
self::$monero_wallet_rpc = new Monero_Wallet_Rpc(self::$host, self::$port);
} else {
require_once('class-monero-explorer-tools.php');
@ -118,7 +118,7 @@ class Monero_Gateway extends WC_Payment_Gateway
if (strlen($address) == 95 & & substr($address, 0, 1) == '4')
if(self::$cryptonote->verify_checksum($address))
return $address;
self::$_errors[] = 'Mo nero address is invalid';
self::$_errors[] = 'Wow nero address is invalid';
}
return $address;
}
@ -153,7 +153,7 @@ class Monero_Gateway extends WC_Payment_Gateway
public function admin_options()
{
$confirm_type = self::$confirm_type;
if($confirm_type === 'mo nero-wallet-rpc')
if($confirm_type === 'wow nero-wallet-rpc')
$balance = self::admin_balance_info();
$settings_html = $this->generate_settings_html(array(), false);
@ -173,8 +173,8 @@ class Monero_Gateway extends WC_Payment_Gateway
$wallet_amount = self::$monero_wallet_rpc->getbalance();
$height = self::$monero_wallet_rpc->getheight();
if (!isset($wallet_amount)) {
self::$_errors[] = 'Cannot connect to mo nero-wallet-rpc';
self::$log->add('Monero_Payments', '[ERROR] Cannot connect to mo nero-wallet-rpc');
self::$_errors[] = 'Cannot connect to wow nero-wallet-rpc';
self::$log->add('Monero_Payments', '[ERROR] Cannot connect to wow nero-wallet-rpc');
return array(
'height' => 'Not Available',
'balance' => 'Not Available',
@ -183,8 +183,8 @@ class Monero_Gateway extends WC_Payment_Gateway
} else {
return array(
'height' => $height,
'balance' => self::format_monero($wallet_amount['balance']).' Mo nero',
'unlocked_balance' => self::format_monero($wallet_amount['unlocked_balance']).' Mo nero'
'balance' => self::format_monero($wallet_amount['balance']).' Wow nero',
'unlocked_balance' => self::format_monero($wallet_amount['unlocked_balance']).' Wow nero'
);
}
}
@ -213,7 +213,7 @@ class Monero_Gateway extends WC_Payment_Gateway
$order = wc_get_order($order_id);
if(self::$confirm_type != 'mo nero-wallet-rpc') {
if(self::$confirm_type != 'wow nero-wallet-rpc') {
// Generate a unique payment id
do {
$payment_id = bin2hex(openssl_random_pseudo_bytes(8));
@ -241,7 +241,7 @@ class Monero_Gateway extends WC_Payment_Gateway
else{
// Critical, the price has not been retrivied.
$monero_amount = -1;
$error_message = "The price for Mo nero could not be retrieved. Please contact the merchant.";
$error_message = "The price for Wow nero could not be retrieved. Please contact the merchant.";
self::$log->add('Monero_Payments', "[ERROR] Impossible to retrieve price for order: ".$order_id);
wc_add_notice( __('Payment error:', 'woothemes') . $error_message, 'error' );
return;
@ -255,7 +255,7 @@ class Monero_Gateway extends WC_Payment_Gateway
$query = $wpdb->prepare("INSERT INTO $table_name (order_id, payment_id, currency, rate, amount) VALUES (%d, %s, %s, %d, %d)", array($order_id, $payment_id, $currency, $rate, $monero_amount));
$wpdb->query($query);
$order->update_status('on-hold', __('Awaiting offline payment', 'mo nero_gateway'));
$order->update_status('on-hold', __('Awaiting offline payment', 'wow nero_gateway'));
wc_reduce_stock_levels( $order_id );
WC()->cart->empty_cart(); // Remove cart
@ -275,7 +275,7 @@ class Monero_Gateway extends WC_Payment_Gateway
// Get Live Price
$currencies = implode(',', self::$currencies);
$api_link = 'https://min-api.cryptocompare.com/data/price?fsym=XMR&tsyms='.$currencies.'&extraParams=monero_woocommerce';
$api_link = 'https://api.coingecko.com/api/v3/coins/wownero/tickers?page=1';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
@ -283,7 +283,8 @@ class Monero_Gateway extends WC_Payment_Gateway
));
$resp = curl_exec($curl);
curl_close($curl);
$price = json_decode($resp, true);
$json = json_decode($resp, true);
$price = $json['tickers'][0]['converted_last']['usd'];
if(!isset($price['Response']) || $price['Response'] != 'Error') {
$table_name = $wpdb->prefix.'monero_gateway_live_rates';
@ -293,17 +294,17 @@ class Monero_Gateway extends WC_Payment_Gateway
$query = $wpdb->prepare("INSERT INTO `$table_name` (currency, rate, updated) VALUES (%s, %d, NOW()) ON DUPLICATE KEY UPDATE rate=%d, updated=NOW()", array( $currency, $rate, $rate));
$result = $wpdb->query($query);
if(!$result){
self::$log->add('Mo nero_Payments', "[ERROR] Impossible to write DB. Please check your DB connection or enable Debugging.");
self::$log->add('Wow nero_Payments', "[ERROR] Impossible to write DB. Please check your DB connection or enable Debugging.");
}
}
}
else{
self::$log->add('Monero_Payments', "[ERROR] Unable to fetch prices from crypt ocompare .com.");
self::$log->add('Monero_Payments', "[ERROR] Unable to fetch prices from coinge ck o.com.");
}
// Get current network/wallet height
if(self::$confirm_type == 'mo nero-wallet-rpc')
if(self::$confirm_type == 'wow nero-wallet-rpc')
$height = self::$monero_wallet_rpc->getheight();
else
$height = self::$monero_explorer_tools->getheight();
@ -339,7 +340,7 @@ class Monero_Gateway extends WC_Payment_Gateway
$payment_id = self::sanatize_id($quote->payment_id);
$amount_monero = $quote->amount_total;
if(self::$confirm_type == 'mo nero-wallet-rpc')
if(self::$confirm_type == 'wow nero-wallet-rpc')
$new_txs = self::check_payment_rpc($payment_id);
else
$new_txs = self::check_payment_explorer($payment_id);
@ -393,9 +394,9 @@ class Monero_Gateway extends WC_Payment_Gateway
unset(self::$payment_details[$order_id]);
if(self::is_virtual_in_cart($order_id) == true){
$order->update_status('completed', __('Payment has been received.', 'mo nero_gateway'));
$order->update_status('completed', __('Payment has been received.', 'wow nero_gateway'));
} else {
$order->update_status('processing', __('Payment has been received.', 'mo nero_gateway'));
$order->update_status('processing', __('Payment has been received.', 'wow nero_gateway'));
}
} else if($paid) {
@ -416,7 +417,7 @@ class Monero_Gateway extends WC_Payment_Gateway
unset(self::$payment_details[$order_id]);
$order->update_status('cancelled', __('Payment has expired.', 'mo nero_gateway'));
$order->update_status('cancelled', __('Payment has expired.', 'wow nero_gateway'));
}
}
}
@ -528,7 +529,7 @@ class Monero_Gateway extends WC_Payment_Gateway
$address = self::$address;
$payment_id = self::sanatize_id($details[0]->payment_id);
if(self::$confirm_type == 'mo nero-wallet-rpc') {
if(self::$confirm_type == 'wow nero-wallet-rpc') {
$integrated_addr = $payment_id;
} else {
if ($address) {
@ -537,8 +538,8 @@ class Monero_Gateway extends WC_Payment_Gateway
$pub_viewkey = $decoded_address['viewkey'];
$integrated_addr = self::$cryptonote->integrated_addr_from_keys($pub_spendkey, $pub_viewkey, $payment_id);
} else {
self::$log->add('Monero_Gateway', '[ERROR] Merchant has not set Mo nero address');
return '[ERROR] Merchant has not set Mo nero address';
self::$log->add('Wownero_Gateway', '[ERROR] Merchant has not set Wow nero address');
return '[ERROR] Merchant has not set Wow nero address';
}
}
@ -614,7 +615,7 @@ class Monero_Gateway extends WC_Payment_Gateway
self::ajax_output(array('error' => '[ERROR] Order does not belong to this user'));
if($order->get_payment_method() != self::$_id)
self::ajax_output(array('error' => '[ERROR] Order not paid for with Mo nero'));
self::ajax_output(array('error' => '[ERROR] Order not paid for with Wow nero'));
$details = self::get_payment_details($order);
if(!is_array($details))
@ -725,7 +726,7 @@ class Monero_Gateway extends WC_Payment_Gateway
< span class = "woocommerce-Price-amount amount" data-price = "$price" data-currency = "$currency"
data-rate="$rate" data-rate-type="live">
$monero_amount_formatted
< span class = "woocommerce-Price-currencySymbol" > XMR < / span >
< span class = "woocommerce-Price-currencySymbol" > WOW < / span >
< / span >
HTML;
@ -756,7 +757,7 @@ HTML;
< span class = "woocommerce-Price-amount amount" data-price = "$price" data-currency = "$currency"
data-rate="$rate" data-rate-type="fixed">
$monero_amount_formatted
< span class = "woocommerce-Price-currencySymbol" > XMR < / span >
< span class = "woocommerce-Price-currencySymbol" > WOW < / span >
< / span >
HTML;