Code Update

Cleaned up the horribly formatted code into a much more consistant format.

Removed a unused method inside library.php

Added an onion service SSL error suppress option.

Fixed up a couple typos.
This commit is contained in:
Alicesland 2017-09-21 16:11:47 -06:00
parent d6438eba52
commit ca16660639
4 changed files with 583 additions and 612 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*.xml
*.iml

View File

@ -1,421 +1,407 @@
<?php <?php
/* Main Gateway of Monero using a daemon online */ /* Main Gateway of Monero using a daemon online */
class Monero_Gateway extends WC_Payment_Gateway class Monero_Gateway extends WC_Payment_Gateway
{ {
private $reloadTime = 30000; private $reloadTime = 30000;
private $discount; private $discount;
private $confirmed = false; private $confirmed = false;
private $monero_daemon; private $monero_daemon;
function __construct()
{ function __construct()
$this->id = "monero_gateway"; {
$this->method_title = __("Monero GateWay", 'monero_gateway'); $this->id = "monero_gateway";
$this->method_description = __("Monero Payment Gateway Plug-in for WooCommerce. You can find more information about this payment gateway on our website. You'll need a daemon online for your address.", 'monero_gateway'); $this->method_title = __("Monero GateWay", 'monero_gateway');
$this->title = __("Monero Gateway", 'monero_gateway'); $this->method_description = __("Monero Payment Gateway Plug-in for WooCommerce. You can find more information about this payment gateway on our website. You'll need a daemon online for your address.", 'monero_gateway');
$this->version = "0.2"; $this->title = __("Monero Gateway", 'monero_gateway');
// $this->version = "0.21";
$this->icon = apply_filters('woocommerce_offline_icon', ''); //
$this->has_fields = false; $this->icon = apply_filters('woocommerce_offline_icon', '');
$this->has_fields = false;
$this->log = new WC_Logger();
$this->log = new WC_Logger();
$this->init_form_fields();
$this->host = $this->get_option('daemon_host'); $this->init_form_fields();
$this->port = $this->get_option('daemon_port'); $this->host = $this->get_option('daemon_host');
$this->address = $this->get_option('monero_address'); $this->port = $this->get_option('daemon_port');
$this->username = $this->get_option('username'); $this->address = $this->get_option('monero_address');
$this->password = $this->get_option('password'); $this->username = $this->get_option('username');
$this->discount = $this->get_option('discount'); $this->password = $this->get_option('password');
$this->discount = $this->get_option('discount');
// After init_settings() is called, you can get the settings and load them into variables, e.g:
// $this->title = $this->get_option('title' ); // After init_settings() is called, you can get the settings and load them into variables, e.g:
$this->init_settings(); // $this->title = $this->get_option('title' );
$this->init_settings();
// Turn these settings into variables we can use
foreach ($this->settings as $setting_key => $value) { // Turn these settings into variables we can use
$this->$setting_key = $value; foreach ($this->settings as $setting_key => $value) {
} $this->$setting_key = $value;
}
add_action('admin_notices', array($this,'do_ssl_check'));
add_action('admin_notices', array($this,'validate_fields')); add_action('admin_notices', array($this, 'do_ssl_check'));
add_action('woocommerce_thankyou_' . $this->id, array($this,'instruction')); add_action('admin_notices', array($this, 'validate_fields'));
if (is_admin()) { add_action('woocommerce_thankyou_' . $this->id, array($this, 'instruction'));
/* Save Settings */ if (is_admin()) {
add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this,'process_admin_options' /* Save Settings */
)); add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
add_filter('woocommerce_currencies', 'add_my_currency');
add_filter( 'woocommerce_currencies', array($this,'add_my_currency') ); add_filter('woocommerce_currency_symbol', 'add_my_currency_symbol', 10, 2);
add_filter('woocommerce_currency_symbol', 'add_my_currency_symbol', 10, 2); add_action('woocommerce_email_before_order_table', array($this, 'email_instructions'), 10, 2);
add_action('woocommerce_email_before_order_table', array($this, 'email_instructions'), 10, 2); }
$this->monero_daemon = new Monero_Library($this->host . ':' . $this->port . '/json_rpc', $this->username, $this->password);
}
public function init_form_fields()
} {
$this->monero_daemon = new Monero_Library($this->host . ':' . $this->port . '/json_rpc', $this->username, $this->password); $this->form_fields = array(
} 'enabled' => array(
'title' => __('Enable / Disable', 'monero_gateway'),
public function add_my_currency( $currencies ) { 'label' => __('Enable this payment gateway', 'monero_gateway'),
$currencies['XMR'] = __('Monero','woocommerce'); 'type' => 'checkbox',
return $currencies; 'default' => 'no'
} ),
public function add_my_currency_symbol( $currency_symbol, $currency ) {
switch( $currency ) { 'title' => array(
case 'XMR': $currency_symbol = 'XMR'; break; 'title' => __('Title', 'monero_gateway'),
} 'type' => 'text',
return $currency_symbol; 'desc_tip' => __('Payment title the customer will see during the checkout process.', 'monero_gateway'),
} 'default' => __('Monero XMR Payment', 'monero_gateway')
),
'description' => array(
public function admin_options() 'title' => __('Description', 'monero_gateway'),
{ 'type' => 'textarea',
$this->log->add('Monero_gateway', '[SUCCESS] Monero Settings OK'); 'desc_tip' => __('Payment description the customer will see during the checkout process.', 'monero_gateway'),
'default' => __('Pay securely using XMR.', 'monero_gateway')
echo "<h1>Monero Payment Gateway</h1>";
),
echo "<p>Welcome to Monero Extension for WooCommerce. Getting started: Make a connection with daemon <a href='https://reddit.com/u/serhack'>Contact Me</a>"; 'monero_address' => array(
echo "<div style='border:1px solid #DDD;padding:5px 10px;font-weight:bold;color:#223079;background-color:#9ddff3;'>"; 'title' => __('Monero Address', 'monero_gateway'),
$this->getamountinfo(); 'label' => __('Useful for people that have not a daemon online'),
echo "</div>"; 'type' => 'text',
echo "<table class='form-table'>"; 'desc_tip' => __('Monero Wallet Address', 'monero_gateway')
$this->generate_settings_html(); ),
echo "</table>"; 'daemon_host' => array(
echo "<h4>Learn more about using a password with the monero wallet-rpc <a href=\"https://github.com/cryptochangements34/monerowp/blob/master/README.md\">here</a></h4>"; 'title' => __('Daemon Host/ IP', 'monero_gateway'),
} 'type' => 'text',
'desc_tip' => __('This is the Daemon Host/IP to authorize the payment with port', 'monero_gateway'),
'default' => 'localhost',
),
public function init_form_fields() 'daemon_port' => array(
{ 'title' => __('Daemon PORT', 'monero_gateway'),
$this->form_fields = array( 'type' => 'text',
'enabled' => array( 'desc_tip' => __('This is the Daemon Host/IP to authorize the payment with port', 'monero_gateway'),
'title' => __('Enable / Disable', 'monero_gateway'), 'default' => '18080',
'label' => __('Enable this payment gateway', 'monero_gateway'), ),
'type' => 'checkbox', 'username' => array(
'default' => 'no' 'title' => __('Daemon username', 'monero_gateway'),
), 'desc_tip' => __('This is the username that you used with your monero wallet-rpc', 'monero_gateway'),
'type' => __('text'),
'title' => array( 'default' => __('username', 'monero_gateway'),
'title' => __('Title', 'monero_gateway'),
'type' => 'text', ),
'desc_tip' => __('Payment title the customer will see during the checkout process.', 'monero_gateway'), 'password' => array(
'default' => __('Monero XMR Payment', 'monero_gateway') 'title' => __('Daemon password', 'monero_gateway'),
), 'desc_tip' => __('This is the password that you used with your monero wallet-rpc', 'monero_gateway'),
'description' => array( 'description' => __('you can leave these fields empty if you did not set', 'monero_gateway'),
'title' => __('Description', 'monero_gateway'), 'type' => __('text'),
'type' => 'textarea', 'default' => ''
'desc_tip' => __('Payment description the customer will see during the checkout process.', 'monero_gateway'),
'default' => __('Pay securely using XMR.', 'monero_gateway') ),
'discount' => array(
), 'title' => __('% discount for using XMR', 'monero_gateway'),
'monero_address' => array(
'title' => __('Monero Address', 'monero_gateway'), 'desc_tip' => __('Provide a discount to your customers for making a private payment with XMR!', 'monero_gateway'),
'label' => __('Useful for people that have not a daemon online'), 'description' => __('Do you want to spread the word about Monero? Offer a small discount! Leave this empty if you do not wish to provide a discount', 'monero_gateway'),
'type' => 'text', 'type' => __('text'),
'desc_tip' => __('Monero Wallet Address', 'monero_gateway') 'default' => '5%'
),
'daemon_host' => array( ),
'title' => __('Daemon Host/ IP', 'monero_gateway'), 'environment' => array(
'type' => 'text', 'title' => __(' Test Mode', 'monero_gateway'),
'desc_tip' => __('This is the Daemon Host/IP to authorize the payment with port', 'monero_gateway'), 'label' => __('Enable Test Mode', 'monero_gateway'),
'default' => 'localhost', 'type' => 'checkbox',
), 'description' => __('Check this box if you are using testnet', 'monero_gateway'),
'daemon_port' => array( 'default' => 'no'
'title' => __('Daemon PORT', 'monero_gateway'), ),
'type' => 'text', 'onion_service' => array(
'desc_tip' => __('This is the Daemon Host/IP to authorize the payment with port', 'monero_gateway'), 'title' => __(' Onion Service', 'monero_gateway'),
'default' => '18080', 'label' => __('Enable Onion Service', 'monero_gateway'),
), 'type' => 'checkbox',
'username' => array( 'description' => __('Check this box if you are running on an Onion Service (Suppress SSL errors)', 'monero_gateway'),
'title' => __('Daemon username', 'monero_gateway'), 'default' => 'no'
'desc_tip' => __('This is the username that you used with your monero wallet-rpc', 'monero_gateway'), ),
'type' => __('text'), );
'default' => __('username','monero_gateway'), }
), public function add_my_currency($currencies)
'password' => array( {
'title' => __('Daemon password', 'monero_gateway'), $currencies['XMR'] = __('Monero', 'woocommerce');
'desc_tip' => __('This is the password that you used with your monero wallet-rpc', 'monero_gateway'), return $currencies;
'description' => __('you can leave these fields empty if you did not set', 'monero_gateway'), }
'type' => __('text'),
'default' => '' function add_my_currency_symbol($currency_symbol, $currency)
{
), switch ($currency) {
'discount' => array( case 'XMR':
'title' => __('% discount for using XMR', 'monero_gateway'), $currency_symbol = 'XMR';
break;
'desc_tip' => __('Provide a discount to your customers for making a private payment with XMR!', 'monero_gateway'), }
'description' => __('Do you want to spread the word about Monero? Offer a small discount! Leave this empty if you do not wish to provide a discount', 'monero_gateway'), return $currency_symbol;
'type' => __('text'), }
'default' => '5%'
public function admin_options()
), {
'environment' => array( $this->log->add('Monero_gateway', '[SUCCESS] Monero Settings OK');
'title' => __(' Test Mode', 'monero_gateway'),
'label' => __('Enable Test Mode', 'monero_gateway'), echo "<h1>Monero Payment Gateway</h1>";
'type' => 'checkbox',
'description' => __('Check this box if you are using testnet', 'monero_gateway'), echo "<p>Welcome to Monero Extension for WooCommerce. Getting started: Make a connection with daemon <a href='https://reddit.com/u/serhack'>Contact Me</a>";
'default' => 'no' echo "<div style='border:1px solid #DDD;padding:5px 10px;font-weight:bold;color:#223079;background-color:#9ddff3;'>";
), $this->getamountinfo();
); echo "</div>";
} echo "<table class='form-table'>";
$this->generate_settings_html();
echo "</table>";
public function retriveprice($currency) echo "<h4>Learn more about using a password with the monero wallet-rpc <a href=\"https://github.com/cryptochangements34/monerowp/blob/master/README.md\">here</a></h4>";
{ }
$xmr_price = file_get_contents('https://min-api.cryptocompare.com/data/price?fsym=XMR&tsyms=BTC,USD,EUR,CAD,INR,GBP&extraParams=monero_woocommerce');
$price = json_decode($xmr_price, TRUE); public function getamountinfo()
if(!isset($price)){ {
$this->log->add('Monero_Gateway', '[ERROR] Unable to get the price of Monero'); $wallet_amount = $this->monero_daemon->getbalance();
} if (!isset($wallet_amount)) {
if ($currency == 'USD') { $this->log->add('Monero_gateway', '[ERROR] No connection with daemon');
return $price['USD']; $wallet_amount['balance'] = "0";
} $wallet_amount['unlocked_balance'] = "0";
if ($currency == 'EUR') { }
return $price['EUR']; $real_wallet_amount = $wallet_amount['balance'] / 1000000000000;
} $real_amount_rounded = round($real_wallet_amount, 6);
if ($currency == 'CAD'){
return $price['CAD']; $unlocked_wallet_amount = $wallet_amount['unlocked_balance'] / 1000000000000;
} $unlocked_amount_rounded = round($unlocked_wallet_amount, 6);
if ($currency == 'GBP'){
return $price['GBP']; echo "Your balance is: " . $real_amount_rounded . " XMR </br>";
} echo "Unlocked balance: " . $unlocked_amount_rounded . " XMR </br>";
if ($currency == 'INR'){ }
return $price['INR'];
} public function process_payment($order_id)
if($currency == 'XMR'){ {
$price = '1'; $order = wc_get_order($order_id);
return $price; $order->update_status('on-hold', __('Awaiting offline payment', 'monero_gateway'));
} // Reduce stock levels
} $order->reduce_order_stock();
public function changeto($amount, $currency, $payment_id) // Remove cart
{ WC()->cart->empty_cart();
global $wpdb;
// This will create a table named whatever the payment id is inside the database "WordPress" // Return thank you redirect
$create_table = "CREATE TABLE IF NOT EXISTS $payment_id ( return array(
rate INT 'result' => 'success',
)"; 'redirect' => $this->get_return_url($order)
$wpdb->query($create_table); );
$rows_num = $wpdb->get_results("SELECT count(*) as count FROM $payment_id");
if($rows_num[0]->count > 0) // Checks if the row has already been created or not }
{
$stored_rate = $wpdb->get_results("SELECT rate FROM $payment_id"); // Submit payment and handle response
$stored_rate_transformed = $stored_rate[0]->rate / 100; //this will turn the stored rate back into a decimaled number public function validate_fields()
{
if(isset($this->discount)) if ($this->check_monero() != TRUE) {
{ echo "<div class=\"error\"><p>Your Monero Address doesn't seem valid. Have you checked it?</p></div>";
$discount_decimal = $this->discount / 100; }
$new_amount = $amount / $stored_rate_transformed;
$discount = $new_amount * $discount_decimal; }
$final_amount = $new_amount - $discount;
$rounded_amount = round($final_amount, 12);
} // Validate fields
else{
$new_amount = $amount / $stored_rate_transformed; public function check_monero()
$rounded_amount = round($new_amount, 12); //the moneo wallet can't handle decimals smaller than 0.000000000001 {
} $monero_address = $this->settings['monero_address'];
} if (strlen($monero_address) == 95 && substr($monero_address, 1)) {
else // If the row has not been created then the live exchange rate will be grabbed and stored return true;
{ }
$xmr_live_price = $this->retriveprice($currency); return false;
$live_for_storing = $xmr_live_price * 100; //This will remove the decimal so that it can easily be stored as an integer }
$new_amount = $amount / $xmr_live_price;
$rounded_amount = round($new_amount, 12); public function instruction($order_id)
{
$wpdb->query("INSERT INTO $payment_id (rate) $order = wc_get_order($order_id);
VALUES ($live_for_storing)"); $amount = floatval(preg_replace('#[^\d.]#', '', $order->get_total()));
} $payment_id = $this->set_paymentid_cookie();
$currency = $order->get_currency();
return $rounded_amount; $amount_xmr2 = $this->changeto($amount, $currency, $payment_id);
} $address = $this->address;
if (!isset($address)) {
// Submit payment and handle response // If there isn't address (merchant missed that field!), $address will be the Monero address for donating :)
public function process_payment($order_id) $address = "44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A";
{ }
$order = wc_get_order($order_id); $uri = "monero:$address?amount=$amount?payment_id=$payment_id";
$order->update_status('on-hold', __('Awaiting offline payment', 'monero_gateway')); $array_integrated_address = $this->monero_daemon->make_integrated_address($payment_id);
// Reduce stock levels if (!isset($array_integrated_address)) {
$order->reduce_order_stock(); $this->log->add('Monero_Gateway', '[ERROR] Unable to getting integrated address');
// Seems that we can't connect with daemon, then set array_integrated_address, little hack
// Remove cart $array_integrated_address["integrated_address"] = $address;
WC()->cart->empty_cart(); }
$message = $this->verify_payment($payment_id, $amount_xmr2, $order);
// Return thankyou redirect if ($this->confirmed) {
return array( $color = "006400";
'result' => 'success', } else {
'redirect' => $this->get_return_url($order) $color = "DC143C";
); }
echo "<h4><font color=$color>" . $message . "</font></h4>";
} echo "<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'>";
echo "<div class='row'>
<div class='col-sm-12 col-md-12 col-lg-12'>
// Validate fields <div class='panel panel-default' id='PaymentBox_de3a227fb470475'>
public function validate_fields() <div class='panel-body'>
{ <div class='row'>
if ($this->check_monero() != TRUE) { <div class='col-sm-12 col-md-12 col-lg-12'>
echo "<div class=\"error\"><p>Your Monero Address doesn't seem valid. Have you checked it?</p></div>"; <h3> Monero Payment Box</h3>
} </div>
<div class='col-sm-3 col-md-3 col-lg-3'>
} <img src='https://chart.googleapis.com/chart?cht=qr&chs=250x250&chl=" . $uri . "' class='img-responsive'>
</div>
<div class='col-sm-9 col-md-9 col-lg-9' style='padding:10px;'>
public function check_monero() Send <b>" . $amount_xmr2 . " XMR</b> to<br/><input type='text' class='form-control' value='" . $array_integrated_address["integrated_address"] . "'>
{ or scan QR Code with your mobile device<br/><br/>
$monero_address = $this->settings['monero_address']; <small>If you need help with how to pay with Monero or want to learn more about it, please go to the Monero<a href='#'>site</a>. </small>
if (strlen($monero_address) == 95 && substr($monero_address, 1)) { </div>
return true; <div class='col-sm-12 col-md-12 col-lg-12'>
} </div>
return false; </div>
} </div>
</div>
private function set_paymentid_cookie()
{
if(!isset($_COOKIE['payment_id']))
{
$payment_id = bin2hex(openssl_random_pseudo_bytes(8));
setcookie('payment_id', $payment_id, time()+2700);
}
else
$payment_id = $_COOKIE['payment_id'];
return $payment_id;
}
public function instruction($order_id)
{
$order = wc_get_order($order_id);
$amount = floatval(preg_replace('#[^\d.]#', '', $order->get_total()));
$payment_id = $this->set_paymentid_cookie();
$currency = $order->get_currency();
$amount_xmr2 = $this->changeto($amount, $currency, $payment_id);
$address = $this->address;
if(!isset($address)){
// If there isn't address (merchant missed that field!), $address will be the Monero address for donating :)
$address = "44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A";
}
$uri = "monero:$address?amount=$amount?payment_id=$payment_id";
$array_integrated_address = $this->monero_daemon->make_integrated_address($payment_id);
if(!isset($array_integrated_address)){
$this->log->add('Monero_Gateway', '[ERROR] Unable to getting integrated address');
// Seems that we can't connect with daemon, then set array_integrated_address, little hack
$array_integrated_address["integrated_address"] = $address;
}
$message = $this->verify_payment($payment_id, $amount_xmr2, $order);
if($this->confirmed){
$color = "006400";
}
else{
$color = "DC143C";
}
echo "<h4><font color=$color>".$message."</font></h4>";
echo "<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'>";
echo "<div class='row'>
<div class='col-sm-12 col-md-12 col-lg-12'>
<div class='panel panel-default' id='PaymentBox_de3a227fb470475'>
<div class='panel-body'>
<div class='row'>
<div class='col-sm-12 col-md-12 col-lg-12'>
<h3> Monero Payment Box</h3>
</div>
<div class='col-sm-3 col-md-3 col-lg-3'>
<img src='https://chart.googleapis.com/chart?cht=qr&chs=250x250&chl=" . $uri . "' class='img-responsive'>
</div>
<div class='col-sm-9 col-md-9 col-lg-9' style='padding:10px;'>
Send <b>" . $amount_xmr2 . " XMR</b> to<br/><input type='text' class='form-control' value='" . $array_integrated_address["integrated_address"]."'>
or scan QR Code with your mobile device<br/><br/>
<small>If you need help with how to pay with Monero or want to learn more about it, please go to the Monero<a href='#'>site</a>. </small>
</div>
<div class='col-sm-12 col-md-12 col-lg-12'>
</div>
</div>
</div>
</div>
</div>
</div> </div>
</div>
<script type='text/javascript'> <script type='text/javascript'>setTimeout(function () { location.reload(true); }, $this->reloadTime);</script>";
setTimeout(function () { location.reload(true); }, $this->reloadTime); }
</script>";
} private function set_paymentid_cookie()
{
if (!isset($_COOKIE['payment_id'])) {
// Check if we are forcing SSL on checkout pages $payment_id = bin2hex(openssl_random_pseudo_bytes(8));
// Custom function not required by the Gateway setcookie('payment_id', $payment_id, time() + 2700);
public function do_ssl_check() } else
{ $payment_id = $_COOKIE['payment_id'];
if ($this->enabled == "yes") { return $payment_id;
if (get_option('woocommerce_force_ssl_checkout') == "no") { }
echo "<div class=\"error\"><p>" . sprintf(__("<strong>%s</strong> is enabled and WooCommerce is not forcing the SSL certificate on your checkout page. Please ensure that you have a valid SSL certificate and that you are <a href=\"%s\">forcing the checkout pages to be secured.</a>"), $this->method_title, admin_url('admin.php?page=wc-settings&tab=checkout')) . "</p></div>";
} public function changeto($amount, $currency, $payment_id)
} {
} global $wpdb;
// This will create a table named whatever the payment id is inside the database "WordPress"
public function connect_daemon(){ $create_table = "CREATE TABLE IF NOT EXISTS $payment_id (
$host = $this->settings['daemon_host']; rate INT
$port = $this->settings['daemon_port']; )";
$monero_library = new Monero($host, $port); $wpdb->query($create_table);
if( $monero_library->works() == true){ $rows_num = $wpdb->get_results("SELECT count(*) as count FROM $payment_id");
echo "<div class=\"notice notice-success is-dismissible\"><p>Everything works! Congratulations and welcome to Monero. <button type=\"button\" class=\"notice-dismiss\"> if ($rows_num[0]->count > 0) // Checks if the row has already been created or not
{
$stored_rate = $wpdb->get_results("SELECT rate FROM $payment_id");
$stored_rate_transformed = $stored_rate[0]->rate / 100; //this will turn the stored rate back into a decimaled number
if (isset($this->discount)) {
$discount_decimal = $this->discount / 100;
$new_amount = $amount / $stored_rate_transformed;
$discount = $new_amount * $discount_decimal;
$final_amount = $new_amount - $discount;
$rounded_amount = round($final_amount, 12);
} else {
$new_amount = $amount / $stored_rate_transformed;
$rounded_amount = round($new_amount, 12); //the moneo wallet can't handle decimals smaller than 0.000000000001
}
} else // If the row has not been created then the live exchange rate will be grabbed and stored
{
$xmr_live_price = $this->retriveprice($currency);
$live_for_storing = $xmr_live_price * 100; //This will remove the decimal so that it can easily be stored as an integer
$new_amount = $amount / $xmr_live_price;
$rounded_amount = round($new_amount, 12);
$wpdb->query("INSERT INTO $payment_id (rate)
VALUES ($live_for_storing)");
}
return $rounded_amount;
}
// Check if we are forcing SSL on checkout pages
// Custom function not required by the Gateway
public function retriveprice($currency)
{
$xmr_price = file_get_contents('https://min-api.cryptocompare.com/data/price?fsym=XMR&tsyms=BTC,USD,EUR,CAD,INR,GBP&extraParams=monero_woocommerce');
$price = json_decode($xmr_price, TRUE);
if (!isset($price)) {
$this->log->add('Monero_Gateway', '[ERROR] Unable to get the price of Monero');
}
switch ($currency) {
case 'USD':
return $price['USD'];
case 'EUR':
return $price['EUR'];
case 'CAD':
return $price['CAD'];
case 'GBP':
return $price['GBP'];
case 'INR':
return $price['INR'];
case 'XMR':
$price = '1';
return $price;
}
}
public function verify_payment($payment_id, $amount, $order_id)
{
/*
* function for verifying payments
* Check if a payment has been made with this payment id then notify the merchant
*/
$message = "We are waiting for your payment to be confirmed";
$amount_atomic_units = $amount * 1000000000000;
$get_payments_method = $this->monero_daemon->get_payments($payment_id);
if (isset($get_payments_method["payments"][0]["amount"])) {
if ($get_payments_method["payments"][0]["amount"] >= $amount_atomic_units) {
$message = "Payment has been received and confirmed. Thanks!";
$this->log->add('Monero_gateway', '[SUCCESS] Payment has been recorded. Congratulations!');
$this->confirmed = true;
$order = wc_get_order($order_id);
$order->update_status('completed', __('Payment has been received', 'monero_gateway'));
global $wpdb;
$wpdb->query("DROP TABLE $payment_id"); // Drop the table from database after payment has been confirmed as it is no longer needed
$this->reloadTime = 3000000000000; // Greatly increase the reload time as it is no longer needed
}
}
return $message;
}
public function do_ssl_check()
{
if ($this->enabled == "yes" && !$this->settings['onion_service']) {
if (get_option('woocommerce_force_ssl_checkout') == "no") {
echo "<div class=\"error\"><p>" . sprintf(__("<strong>%s</strong> is enabled and WooCommerce is not forcing the SSL certificate on your checkout page. Please ensure that you have a valid SSL certificate and that you are <a href=\"%s\">forcing the checkout pages to be secured.</a>"), $this->method_title, admin_url('admin.php?page=wc-settings&tab=checkout')) . "</p></div>";
}
}
}
public function connect_daemon()
{
$host = $this->settings['daemon_host'];
$port = $this->settings['daemon_port'];
$monero_library = new Monero($host, $port);
if ($monero_library->works() == true) {
echo "<div class=\"notice notice-success is-dismissible\"><p>Everything works! Congratulations and welcome to Monero. <button type=\"button\" class=\"notice-dismiss\">
<span class=\"screen-reader-text\">Dismiss this notice.</span> <span class=\"screen-reader-text\">Dismiss this notice.</span>
</button></p></div>"; </button></p></div>";
} } else {
else{ $this->log->add('Monero_gateway', '[ERROR] Plugin can not reach wallet rpc.');
$this->log->add('Monero_gateway','[ERROR] Plugin can not reach wallet rpc.'); echo "<div class=\" notice notice-error\"><p>Error with connection of daemon, see documentation!</p></div>";
echo "<div class=\" notice notice-error\"><p>Error with connection of daemon, see documentation!</p></div>"; }
} } }
public function verify_payment($payment_id, $amount, $order_id){
/*
* function for verifying payments
* Check if a payment has been made with this payment id then notify the merchant
*/
$amount_atomic_units = $amount * 1000000000000;
$get_payments_method = $this->monero_daemon->get_payments($payment_id);
if(isset($get_payments_method["payments"][0]["amount"]))
{
if($get_payments_method["payments"][0]["amount"] >= $amount_atomic_units)
{
$message = "Payment has been received and confirmed. Thanks!";
$this->log->add('Monero_gateway','[SUCCESS] Payment has been recorded. Congratulations!');
$this->confirmed = true;
$order = wc_get_order($order_id);
$order->update_status('completed', __('Payment has been received', 'monero_gateway'));
global $wpdb;
$wpdb->query("DROP TABLE $payment_id"); // Drop the table from database after payment has been confirmed as it is no longer needed
$this->reloadTime = 3000000000000; // Greatly increase the reload time as it is no longer needed
}
}
else
{
$message = "We are waiting for your payment to be confirmed";
}
return $message;
}
public function getamountinfo(){
$wallet_amount = $this->monero_daemon->getbalance();
if(!isset($wallet_amount)){
$this->log->add('Monero_gateway','[ERROR] No connection with daemon');
$wallet_amount['balance'] = "0";
$wallet_amount['unlocked_balance'] = "0";
}
$real_wallet_amount = $wallet_amount['balance'] / 1000000000000;
$real_amount_rounded = round($real_wallet_amount, 6);
$unlocked_wallet_amount = $wallet_amount['unlocked_balance'] / 1000000000000;
$unlocked_amount_rounded = round($unlocked_wallet_amount, 6);
echo "Your balance is: ".$real_amount_rounded. " XMR </br>";
echo "Unlocked balance: ".$unlocked_amount_rounded." XMR </br>";
}
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* library.php * library.php
* *
@ -12,14 +13,12 @@
class Monero_Library class Monero_Library
{ {
protected $url = null, $is_debug = false, $parameters_structure = 'array'; protected $url = null, $is_debug = false, $parameters_structure = 'array';
private $username;
private $password;
protected $curl_options = array( protected $curl_options = array(
CURLOPT_CONNECTTIMEOUT => 8, CURLOPT_CONNECTTIMEOUT => 8,
CURLOPT_TIMEOUT => 8 CURLOPT_TIMEOUT => 8
); );
private $username;
private $password;
private $httpErrors = array( private $httpErrors = array(
400 => '400 Bad Request', 400 => '400 Bad Request',
401 => '401 Unauthorized', 401 => '401 Unauthorized',
@ -32,62 +31,79 @@ class Monero_Library
502 => '502 Bad Gateway', 502 => '502 Bad Gateway',
503 => '503 Service Unavailable' 503 => '503 Service Unavailable'
); );
public function __construct($pUrl, $pUser, $pPass) public function __construct($pUrl, $pUser, $pPass)
{ {
$this->validate(false === extension_loaded('curl'), 'The curl extension must be loaded to use this class!'); $this->validate(false === extension_loaded('curl'), 'The curl extension must be loaded to use this class!');
$this->validate(false === extension_loaded('json'), 'The json extension must be loaded to use this class!'); $this->validate(false === extension_loaded('json'), 'The json extension must be loaded to use this class!');
$this->url = $pUrl; $this->url = $pUrl;
$this->username = $pUser; $this->username = $pUser;
$this->password = $pPass; $this->password = $pPass;
} }
private function getHttpErrorMessage($pErrorNumber) public function validate($pFailed, $pErrMsg)
{ {
return isset($this->httpErrors[$pErrorNumber]) ? $this->httpErrors[$pErrorNumber] : null; if ($pFailed) {
echo $pErrMsg;
}
} }
public function setDebug($pIsDebug) public function setDebug($pIsDebug)
{ {
$this->is_debug = !empty($pIsDebug); $this->is_debug = !empty($pIsDebug);
return $this; return $this;
} }
/* public function setParametersStructure($pParametersStructure) /* public function setParametersStructure($pParametersStructure)
{ {
if (in_array($pParametersStructure, array('array', 'object'))) if (in_array($pParametersStructure, array('array', 'object')))
{ {
$this->parameters_structure = $pParametersStructure; $this->parameters_structure = $pParametersStructure;
} }
else else
{ {
throw new UnexpectedValueException('Invalid parameters structure type.'); throw new UnexpectedValueException('Invalid parameters structure type.');
} }
return $this; return $this;
} */ } */
public function setCurlOptions($pOptionsArray) public function setCurlOptions($pOptionsArray)
{ {
if (is_array($pOptionsArray)) if (is_array($pOptionsArray)) {
{
$this->curl_options = $pOptionsArray + $this->curl_options; $this->curl_options = $pOptionsArray + $this->curl_options;
} } else {
else
{
echo 'Invalid options type.'; echo 'Invalid options type.';
} }
return $this; return $this;
} }
private function request($pMethod, $pParams) public function _print($json)
{
$json_encoded = json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
echo $json_encoded;
}
public function address()
{
$address = $this->_run('getaddress');
return $address;
}
public function _run($method, $params = null)
{
$result = $this->request($method, $params);
return $result; //the result is returned as an array
}
private function request($pMethod, $pParams)
{ {
static $requestId = 0; static $requestId = 0;
// generating uniuqe id per process // generating uniuqe id per process
$requestId++; $requestId++;
// check if given params are correct // check if given params are correct
$this->validate(false === is_scalar($pMethod), 'Method name has no scalar value'); $this->validate(false === is_scalar($pMethod), 'Method name has no scalar value');
// $this->validate(false === is_array($pParams), 'Params must be given as array'); // $this->validate(false === is_array($pParams), 'Params must be given as array');
// send params as an object or an array // send params as an object or an array
//$pParams = ($this->parameters_structure == 'object') ? $pParams[0] : array_values($pParams); //$pParams = ($this->parameters_structure == 'object') ? $pParams[0] : array_values($pParams);
// Request (method invocation) // Request (method invocation)
@ -102,242 +118,206 @@ class Monero_Library
$responseDecoded = json_decode($responseMessage, true); $responseDecoded = json_decode($responseMessage, true);
// check if decoding json generated any errors // check if decoding json generated any errors
$jsonErrorMsg = $this->getJsonLastErrorMsg(); $jsonErrorMsg = $this->getJsonLastErrorMsg();
$this->validate( !is_null($jsonErrorMsg), $jsonErrorMsg . ': ' . $responseMessage); $this->validate(!is_null($jsonErrorMsg), $jsonErrorMsg . ': ' . $responseMessage);
// check if response is correct // check if response is correct
$this->validate(empty($responseDecoded['id']), 'Invalid response data structure: ' . $responseMessage); $this->validate(empty($responseDecoded['id']), 'Invalid response data structure: ' . $responseMessage);
$this->validate($responseDecoded['id'] != $requestId, 'Request id: ' . $requestId . ' is different from Response id: ' . $responseDecoded['id']); $this->validate($responseDecoded['id'] != $requestId, 'Request id: ' . $requestId . ' is different from Response id: ' . $responseDecoded['id']);
if (isset($responseDecoded['error'])) if (isset($responseDecoded['error'])) {
{
$errorMessage = 'Request have return error: ' . $responseDecoded['error']['message'] . '; ' . "\n" . $errorMessage = 'Request have return error: ' . $responseDecoded['error']['message'] . '; ' . "\n" .
'Request: ' . $request . '; '; 'Request: ' . $request . '; ';
if (isset($responseDecoded['error']['data'])) if (isset($responseDecoded['error']['data'])) {
{
$errorMessage .= "\n" . 'Error data: ' . $responseDecoded['error']['data']; $errorMessage .= "\n" . 'Error data: ' . $responseDecoded['error']['data'];
} }
$this->validate( !is_null($responseDecoded['error']), $errorMessage); $this->validate(!is_null($responseDecoded['error']), $errorMessage);
} }
return $responseDecoded['result']; return $responseDecoded['result'];
} }
protected function & getResponse(&$pRequest)
{
// do the actual connection
$ch = curl_init();
if ( !$ch)
{
throw new RuntimeException('Could\'t initialize a cURL session');
}
curl_setopt($ch, CURLOPT_URL, $this->url);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_setopt($ch, CURLOPT_USERPWD, $this->username . ":" . $this->password);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $pRequest);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
if ( !curl_setopt_array($ch, $this->curl_options))
{
throw new RuntimeException('Error while setting curl options');
}
// send the request
$response = curl_exec($ch);
// check http status code
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (isset($this->httpErrors[$httpCode]))
{
echo 'Response Http Error - ' . $this->httpErrors[$httpCode];
}
// check for curl error
if (0 < curl_errno($ch))
{
echo 'Unable to connect to '.$this->url . ' Error: ' . curl_error($ch);
}
// close the connection
curl_close($ch);
return $response;
}
public function validate($pFailed, $pErrMsg)
{
if ($pFailed)
{
echo $pErrMsg;
}
}
protected function debug($pAdd, $pShow = false) protected function debug($pAdd, $pShow = false)
{ {
static $debug, $startTime; static $debug, $startTime;
// is_debug off return // is_debug off return
if (false === $this->is_debug) if (false === $this->is_debug) {
{
return; return;
} }
// add // add
$debug .= $pAdd; $debug .= $pAdd;
// get starttime // get starttime
$startTime = empty($startTime) ? array_sum(explode(' ', microtime())) : $startTime; $startTime = empty($startTime) ? array_sum(explode(' ', microtime())) : $startTime;
if (true === $pShow and !empty($debug)) if (true === $pShow and !empty($debug)) {
{
// get endtime // get endtime
$endTime = array_sum(explode(' ', microtime())); $endTime = array_sum(explode(' ', microtime()));
// performance summary // performance summary
$debug .= 'Request time: ' . round($endTime - $startTime, 3) . ' s Memory usage: ' . round(memory_get_usage() / 1024) . " kb\r\n"; $debug .= 'Request time: ' . round($endTime - $startTime, 3) . ' s Memory usage: ' . round(memory_get_usage() / 1024) . " kb\r\n";
echo nl2br($debug); echo nl2br($debug);
// send output imidiately // send output immediately
flush(); flush();
// clean static // clean static
$debug = $startTime = null; $debug = $startTime = null;
} }
} }
protected function & getResponse(&$pRequest)
{
// do the actual connection
$ch = curl_init();
if (!$ch) {
throw new RuntimeException('Could\'t initialize a cURL session');
}
curl_setopt($ch, CURLOPT_URL, $this->url);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_setopt($ch, CURLOPT_USERPWD, $this->username . ":" . $this->password);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $pRequest);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
if (!curl_setopt_array($ch, $this->curl_options)) {
throw new RuntimeException('Error while setting curl options');
}
// send the request
$response = curl_exec($ch);
// check http status code
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (isset($this->httpErrors[$httpCode])) {
echo 'Response Http Error - ' . $this->httpErrors[$httpCode];
}
// check for curl error
if (0 < curl_errno($ch)) {
echo 'Unable to connect to ' . $this->url . ' Error: ' . curl_error($ch);
}
// close the connection
curl_close($ch);
return $response;
}
//prints result as json
function getJsonLastErrorMsg() function getJsonLastErrorMsg()
{ {
if (!function_exists('json_last_error_msg')) if (!function_exists('json_last_error_msg')) {
{
function json_last_error_msg() function json_last_error_msg()
{ {
static $errors = array( static $errors = array(
JSON_ERROR_NONE => 'No error', JSON_ERROR_NONE => 'No error',
JSON_ERROR_DEPTH => 'Maximum stack depth exceeded', JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
JSON_ERROR_STATE_MISMATCH => 'Underflow or the modes mismatch', JSON_ERROR_STATE_MISMATCH => 'Underflow or the modes mismatch',
JSON_ERROR_CTRL_CHAR => 'Unexpected control character found', JSON_ERROR_CTRL_CHAR => 'Unexpected control character found',
JSON_ERROR_SYNTAX => 'Syntax error', JSON_ERROR_SYNTAX => 'Syntax error',
JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded' JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded'
); );
$error = json_last_error(); $error = json_last_error();
return array_key_exists($error, $errors) ? $errors[$error] : 'Unknown error (' . $error . ')'; return array_key_exists($error, $errors) ? $errors[$error] : 'Unknown error (' . $error . ')';
} }
} }
// Fix PHP 5.2 error caused by missing json_last_error function // Fix PHP 5.2 error caused by missing json_last_error function
if (function_exists('json_last_error')) if (function_exists('json_last_error')) {
{
return json_last_error() ? json_last_error_msg() : null; return json_last_error() ? json_last_error_msg() : null;
} } else {
else
{
return null; return null;
} }
} }
public function _run($method,$params = null)
{
$result = $this->request($method, $params);
return $result; //the result is returned as an array
}
//prints result as json
public function _print($json)
{
$json_encoded = json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
echo $json_encoded;
}
/* /*
* The following functions can all be called to interact with the monero rpc wallet * The following functions can all be called to interact with the monero rpc wallet
* They will majority of them will return the result as an array * They will majority of them will return the result as an array
* Example: $daemon->address(); where $daemon is an instance of this class, will return the wallet address as string within an array * Example: $daemon->address(); where $daemon is an instance of this class, will return the wallet address as string within an array
*/ */
public function address()
{
$address = $this->_run('getaddress');
return $address;
}
public function getbalance() public function getbalance()
{ {
$balance = $this->_run('getbalance'); $balance = $this->_run('getbalance');
return $balance; return $balance;
} }
public function getheight() public function getheight()
{ {
$height = $this->_run('getheight'); $height = $this->_run('getheight');
return $height; return $height;
} }
public function incoming_transfer($type) public function incoming_transfer($type)
{ {
$incoming_parameters = array('transfer_type' => $type); $incoming_parameters = array('transfer_type' => $type);
$incoming_transfers = $this->_run('incoming_transfers', $incoming_parameters); $incoming_transfers = $this->_run('incoming_transfers', $incoming_parameters);
return $incoming_transfers; return $incoming_transfers;
} }
public function get_transfers($input_type, $input_value) public function get_transfers($input_type, $input_value)
{ {
$get_parameters = array($input_type => $input_value); $get_parameters = array($input_type => $input_value);
$get_transfers = $this->_run('get_transfers', $get_parameters); $get_transfers = $this->_run('get_transfers', $get_parameters);
return $get_transfers; return $get_transfers;
} }
public function view_key() public function view_key()
{ {
$query_key = array('key_type' => 'view_key'); $query_key = array('key_type' => 'view_key');
$query_key_method = $this->_run('query_key', $query_key); $query_key_method = $this->_run('query_key', $query_key);
return $query_key_method; return $query_key_method;
} }
/* A payment id can be passed as a string
A random payment id will be generatd if one is not given */
public function make_integrated_address($payment_id) public function make_integrated_address($payment_id)
{ {
$integrate_address_parameters = array('payment_id' => $payment_id); $integrate_address_parameters = array('payment_id' => $payment_id);
$integrate_address_method = $this->_run('make_integrated_address', $integrate_address_parameters); $integrate_address_method = $this->_run('make_integrated_address', $integrate_address_parameters);
return $integrate_address_method; return $integrate_address_method;
} }
/* A payment id can be passed as a string
A random payment id will be generatd if one is not given */
public function split_integrated_address($integrated_address) public function split_integrated_address($integrated_address)
{ {
if(!isset($integrated_address)){ if (!isset($integrated_address)) {
echo "Error: Integrated_Address mustn't be null"; echo "Error: Integrated_Address mustn't be null";
} } else {
else{ $split_params = array('integrated_address' => $integrated_address);
$split_params = array('integrated_address' => $integrated_address); $split_methods = $this->_run('split_integrated_address', $split_params);
$split_methods = $this->_run('split_integrated_address', $split_params); return $split_methods;
return $split_methods;
} }
} }
public function make_uri($address, $amount, $recipient_name = null, $description = null) public function make_uri($address, $amount, $recipient_name = null, $description = null)
{ {
// If I pass 1, it will be 0.0000001 xmr. Then // If I pass 1, it will be 0.0000001 xmr. Then
$new_amount = $amount * 100000000; $new_amount = $amount * 100000000;
$uri_params = array('address' => $address, 'amount' => $new_amount, 'payment_id' => '', 'recipient_name' => $recipient_name, 'tx_description' => $description); $uri_params = array('address' => $address, 'amount' => $new_amount, 'payment_id' => '', 'recipient_name' => $recipient_name, 'tx_description' => $description);
$uri = $this->_run('make_uri', $uri_params); $uri = $this->_run('make_uri', $uri_params);
return $uri; return $uri;
} }
public function parse_uri($uri) public function parse_uri($uri)
{ {
$uri_parameters = array('uri' => $uri); $uri_parameters = array('uri' => $uri);
$parsed_uri = $this->_run('parse_uri', $uri_parameters); $parsed_uri = $this->_run('parse_uri', $uri_parameters);
return $parsed_uri; return $parsed_uri;
} }
public function transfer($amount, $address, $mixin = 4) public function transfer($amount, $address, $mixin = 4)
{ {
$new_amount = $amount * 1000000000000; $new_amount = $amount * 1000000000000;
$destinations = array('amount' => $new_amount, 'address' => $address); $destinations = array('amount' => $new_amount, 'address' => $address);
$transfer_parameters = array('destinations' => array($destinations), 'mixin' => $mixin, 'get_tx_key' => true, 'unlock_time' => 0, 'payment_id' => ''); $transfer_parameters = array('destinations' => array($destinations), 'mixin' => $mixin, 'get_tx_key' => true, 'unlock_time' => 0, 'payment_id' => '');
$transfer_method = $this->_run('transfer', $transfer_parameters); $transfer_method = $this->_run('transfer', $transfer_parameters);
return $transfer_method; return $transfer_method;
} }
public function get_payments($payment_id) public function get_payments($payment_id)
{ {
$get_payments_parameters = array('payment_id' => $payment_id); $get_payments_parameters = array('payment_id' => $payment_id);
$get_payments = $this->_run('get_payments', $get_payments_parameters); $get_payments = $this->_run('get_payments', $get_payments_parameters);
return $get_payments; return $get_payments;
} }
public function get_bulk_payments($payment_id, $min_block_height) public function get_bulk_payments($payment_id, $min_block_height)
{ {
$get_bulk_payments_parameters = array('payment_id' => $payment_id, 'min_block_height' => $min_block_height); $get_bulk_payments_parameters = array('payment_id' => $payment_id, 'min_block_height' => $min_block_height);
$get_bulk_payments = $this->_run('get_bulk_payments', $get_bulk_payments_parameters); $get_bulk_payments = $this->_run('get_bulk_payments', $get_bulk_payments_parameters);
return $get_bulk_payments; return $get_bulk_payments;
} }
} }

View File

@ -7,54 +7,56 @@ Version: 1.0
Author: SerHack Author: SerHack
Author URI: http://monerointegrations.com Author URI: http://monerointegrations.com
*/ */
if ( ! defined( 'ABSPATH' ) ) { if (!defined('ABSPATH')) {
exit; // Exit if accessed directly exit; // Exit if accessed directly
} }
// Include our Gateway Class and register Payment Gateway with WooCommerce // Include our Gateway Class and register Payment Gateway with WooCommerce
add_action( 'plugins_loaded', 'monero_init', 0 ); add_action('plugins_loaded', 'monero_init', 0);
function monero_init() { function monero_init()
/* If the class doesn't exist (== WooCommerce isn't installed), return NULL */ {
if ( ! class_exists( 'WC_Payment_Gateway' ) ) return; /* If the class doesn't exist (== WooCommerce isn't installed), return NULL */
if (!class_exists('WC_Payment_Gateway')) return;
/* If we made it this far, then include our Gateway Class */
include_once( 'include/monero_payments.php' );
require_once( 'library.php');
// Lets add it too WooCommerce
add_filter( 'woocommerce_payment_gateways', 'monero_gateway' );
function monero_gateway( $methods ) {
$methods[] = 'Monero_Gateway';
return $methods;
}
/* If we made it this far, then include our Gateway Class */
include_once('include/monero_payments.php');
require_once('library.php');
// Lets add it too WooCommerce
add_filter('woocommerce_payment_gateways', 'monero_gateway');
function monero_gateway($methods)
{
$methods[] = 'Monero_Gateway';
return $methods;
}
} }
/* /*
* Add custom link * Add custom link
* The url will be http://yourworpress/wp-admin/admin.php?=wc-settings&tab=checkout * The url will be http://yourworpress/wp-admin/admin.php?=wc-settings&tab=checkout
*/ */
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'monero_payment' ); add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'monero_payment');
function monero_payment( $links ) { function monero_payment($links)
$plugin_links = array( {
'<a href="' . admin_url( 'admin.php?page=wc-settings&tab=checkout' ) . '">' . __( 'Settings', 'monero_payment' ) . '</a>', $plugin_links = array(
); '<a href="' . admin_url('admin.php?page=wc-settings&tab=checkout') . '">' . __('Settings', 'monero_payment') . '</a>',
);
return array_merge( $plugin_links, $links ); return array_merge($plugin_links, $links);
} }
add_action( 'admin_menu', 'monero_create_menu' );
function monero_create_menu(){ add_action('admin_menu', 'monero_create_menu');
add_menu_page( function monero_create_menu()
__( 'Monero', 'textdomain' ), {
add_menu_page(
__('Monero', 'textdomain'),
'Monero', 'Monero',
'manage_options', 'manage_options',
'admin.php?page=wc-settings&tab=checkout&section=monero_gateway', 'admin.php?page=wc-settings&tab=checkout&section=monero_gateway',
'', '',
plugins_url( 'monero/assets/icon.png' ), plugins_url('monero/assets/icon.png'),
56 // Position on menu, woocommerce has 55.5, products has 55.6 56 // Position on menu, woocommerce has 55.5, products has 55.6
); );
} }