mirror of
https://git.wownero.com/wownero/wownerowp.git
synced 2024-08-15 01:03:16 +00:00
such wow
This commit is contained in:
parent
572f04dfba
commit
b9e5fcc96e
21 changed files with 152 additions and 157 deletions
|
@ -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 = 'monero_gateway';
|
||||
private static $_title = 'Monero Gateway';
|
||||
private static $_method_title = 'Monero Gateway';
|
||||
private static $_method_description = 'Monero Gateway Plug-in for WooCommerce.';
|
||||
private static $_id = 'wownero_gateway';
|
||||
private static $_title = 'Wownero Gateway';
|
||||
private static $_method_title = 'Wownero Gateway';
|
||||
private static $_method_description = 'Wownero 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/monero-icon.png"/>', $this->id);
|
||||
return apply_filters('woocommerce_gateway_icon', '<img src="'.MONERO_GATEWAY_PLUGIN_URL.'assets/images/wownero-icon.png"/>', $this->id);
|
||||
}
|
||||
|
||||
function __construct($add_action=true)
|
||||
{
|
||||
$this->id = self::$_id;
|
||||
$this->method_title = __(self::$_method_title, 'monero_gateway');
|
||||
$this->method_description = __(self::$_method_description, 'monero_gateway');
|
||||
$this->method_title = __(self::$_method_title, 'wownero_gateway');
|
||||
$this->method_description = __(self::$_method_description, 'wownero_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 == 'monero-wallet-rpc') {
|
||||
require_once('class-monero-wallet-rpc.php');
|
||||
if(self::$confirm_type == 'wownero-wallet-rpc') {
|
||||
require_once('class-wownero-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[] = 'Monero address is invalid';
|
||||
self::$_errors[] = 'Wownero 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 === 'monero-wallet-rpc')
|
||||
if($confirm_type === 'wownero-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 monero-wallet-rpc';
|
||||
self::$log->add('Monero_Payments', '[ERROR] Cannot connect to monero-wallet-rpc');
|
||||
self::$_errors[] = 'Cannot connect to wownero-wallet-rpc';
|
||||
self::$log->add('Monero_Payments', '[ERROR] Cannot connect to wownero-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']).' Monero',
|
||||
'unlocked_balance' => self::format_monero($wallet_amount['unlocked_balance']).' Monero'
|
||||
'balance' => self::format_monero($wallet_amount['balance']).' Wownero',
|
||||
'unlocked_balance' => self::format_monero($wallet_amount['unlocked_balance']).' Wownero'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -213,7 +213,7 @@ class Monero_Gateway extends WC_Payment_Gateway
|
|||
|
||||
$order = wc_get_order($order_id);
|
||||
|
||||
if(self::$confirm_type != 'monero-wallet-rpc') {
|
||||
if(self::$confirm_type != 'wownero-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 Monero could not be retrieved. Please contact the merchant.";
|
||||
$error_message = "The price for Wownero 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', 'monero_gateway'));
|
||||
$order->update_status('on-hold', __('Awaiting offline payment', 'wownero_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('Monero_Payments', "[ERROR] Impossible to write DB. Please check your DB connection or enable Debugging.");
|
||||
self::$log->add('Wownero_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 cryptocompare.com.");
|
||||
self::$log->add('Monero_Payments', "[ERROR] Unable to fetch prices from coingecko.com.");
|
||||
}
|
||||
|
||||
// Get current network/wallet height
|
||||
if(self::$confirm_type == 'monero-wallet-rpc')
|
||||
if(self::$confirm_type == 'wownero-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 == 'monero-wallet-rpc')
|
||||
if(self::$confirm_type == 'wownero-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.', 'monero_gateway'));
|
||||
$order->update_status('completed', __('Payment has been received.', 'wownero_gateway'));
|
||||
} else {
|
||||
$order->update_status('processing', __('Payment has been received.', 'monero_gateway'));
|
||||
$order->update_status('processing', __('Payment has been received.', 'wownero_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.', 'monero_gateway'));
|
||||
$order->update_status('cancelled', __('Payment has expired.', 'wownero_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 == 'monero-wallet-rpc') {
|
||||
if(self::$confirm_type == 'wownero-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 Monero address');
|
||||
return '[ERROR] Merchant has not set Monero address';
|
||||
self::$log->add('Wownero_Gateway', '[ERROR] Merchant has not set Wownero address');
|
||||
return '[ERROR] Merchant has not set Wownero 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 Monero'));
|
||||
self::ajax_output(array('error' => '[ERROR] Order not paid for with Wownero'));
|
||||
|
||||
$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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue