From df6adb4ab89729d942855bfc8aee2a4f8a9e5a93 Mon Sep 17 00:00:00 2001
From: cryptochangements34
Date: Sat, 14 Apr 2018 13:45:02 -0500
Subject: [PATCH 01/50] allow testnet explorer
---
monero/library.php | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/monero/library.php b/monero/library.php
index a859f64..d62dfd2 100644
--- a/monero/library.php
+++ b/monero/library.php
@@ -322,13 +322,26 @@ class Monero_Library
class NodeTools
{
+ private $url;
+ public function __construct($testnet = false)
+ {
+ if(!testnet)
+ {
+ $this->url = 'https://xmrchain.net'
+ }
+ if(testnet)
+ {
+ $this->url = 'https://testnet.xmrchain.net'
+ }
+ }
+
public function get_last_block_height()
{
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
- CURLOPT_URL => 'https://xmrchain.net/api/networkinfo',
+ CURLOPT_URL => $this->url . 'api/networkinfo',
));
$resp = curl_exec($curl);
curl_close($curl);
@@ -343,7 +356,7 @@ class NodeTools
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
- CURLOPT_URL => 'https://xmrchain.net/api/search/' . $height,
+ CURLOPT_URL => $this->url . '/api/search/' . $height,
));
$resp = curl_exec($curl);
curl_close($curl);
@@ -358,7 +371,7 @@ class NodeTools
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
- CURLOPT_URL => 'https://xmrchain.net/api/outputs?txhash=' .$tx_hash . '&address='. $address . '&viewkey='. $viewKey .'&txprove=0',
+ CURLOPT_URL => $this-url . '/api/outputs?txhash=' .$tx_hash . '&address='. $address . '&viewkey='. $viewKey .'&txprove=0',
));
$resp = curl_exec($curl);
curl_close($curl);
@@ -383,7 +396,7 @@ class NodeTools
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
- CURLOPT_URL => 'https://xmrchain.net/api/mempool',
+ CURLOPT_URL => $this->url . '/api/mempool',
));
$resp = curl_exec($curl);
curl_close($curl);
From 9f8fee17ebae57f21c37f527a94a36e59d877bc6 Mon Sep 17 00:00:00 2001
From: cryptochangements34
Date: Sat, 14 Apr 2018 13:55:25 -0500
Subject: [PATCH 02/50] fix missing semicolons
---
monero/library.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/monero/library.php b/monero/library.php
index d62dfd2..f1cf6d3 100644
--- a/monero/library.php
+++ b/monero/library.php
@@ -327,11 +327,11 @@ class NodeTools
{
if(!testnet)
{
- $this->url = 'https://xmrchain.net'
+ $this->url = 'https://xmrchain.net';
}
if(testnet)
{
- $this->url = 'https://testnet.xmrchain.net'
+ $this->url = 'https://testnet.xmrchain.net';
}
}
From 380cd24527a3b98eb1dada7387cce0cd5c73e0b4 Mon Sep 17 00:00:00 2001
From: cryptochangements34
Date: Sat, 14 Apr 2018 13:55:53 -0500
Subject: [PATCH 03/50] Update monero_payments.php
---
monero/include/monero_payments.php | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/monero/include/monero_payments.php b/monero/include/monero_payments.php
index 4b98c7d..ae226b4 100644
--- a/monero/include/monero_payments.php
+++ b/monero/include/monero_payments.php
@@ -16,6 +16,7 @@ class Monero_Gateway extends WC_Payment_Gateway
private $non_rpc = false;
private $zero_cofirm = false;
private $cryptonote;
+ private $testnet = false;
function __construct()
{
@@ -41,6 +42,8 @@ class Monero_Gateway extends WC_Payment_Gateway
$this->use_viewKey = $this->get_option('use_viewKey');
$this->use_rpc = $this->get_option('use_rpc');
+ $env = $this->get_option('environment');
+
if($this->use_viewKey == 'yes')
{
$this->non_rpc = true;
@@ -53,6 +56,12 @@ class Monero_Gateway extends WC_Payment_Gateway
{
$this->zero_confirm = true;
}
+
+ if($env == 'yes')
+ {
+ $this->testnet = true;
+ }
+
// After init_settings() is called, you can get the settings and load them into variables, e.g:
// $this->title = $this->get_option('title' );
$this->init_settings();
@@ -662,7 +671,7 @@ class Monero_Gateway extends WC_Payment_Gateway
}
public function verify_non_rpc($payment_id, $amount, $order_id)
{
- $tools = new NodeTools();
+ $tools = new NodeTools($this->testnet);
$bc_height = $tools->get_last_block_height();
$block_difference = $this->last_block_seen($bc_height);
@@ -737,7 +746,7 @@ class Monero_Gateway extends WC_Payment_Gateway
public function verify_zero_conf($payment_id, $amount, $order_id)
{
- $tools = new NodeTools();
+ $tools = new NodeTools($this->testnet);
$txs_from_mempool = $tools->get_mempool_txs();;
$tx_count = count($txs_from_mempool['data']['txs']);
$i = 0;
From fa9d6b7162525f8b28ef7da01b3d33747ba67d7b Mon Sep 17 00:00:00 2001
From: cryptochangements34
Date: Fri, 20 Apr 2018 17:52:03 -0400
Subject: [PATCH 04/50] check if *all* cart items are virtual
---
monero/include/monero_payments.php | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/monero/include/monero_payments.php b/monero/include/monero_payments.php
index ae226b4..ab060eb 100644
--- a/monero/include/monero_payments.php
+++ b/monero/include/monero_payments.php
@@ -318,15 +318,22 @@ class Monero_Gateway extends WC_Payment_Gateway
{
$order = wc_get_order( $order_id );
$items = $order->get_items();
-
+ $cart_size = count($items);
+ $virtual_items = 0;
+
foreach ( $items as $item ) {
$product = new WC_Product( $item['product_id'] );
if ( $product->is_virtual() ) {
- return true;
+ $virtual_items += 1;
}
}
-
- return false;
+ if($virtual_items == $cart_size)
+ {
+ return true;
+ }
+ else{
+ return false;
+ }
}
public function instruction($order_id)
From 9e924a1a61c3b19a5a4c2616dcc44fb547e5076e Mon Sep 17 00:00:00 2001
From: pitifultermite <38870971+pitifultermite@users.noreply.github.com>
Date: Tue, 1 May 2018 02:01:02 +0200
Subject: [PATCH 05/50] Update monero_payments.php
---
monero/include/monero_payments.php | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/monero/include/monero_payments.php b/monero/include/monero_payments.php
index ab060eb..87014f0 100644
--- a/monero/include/monero_payments.php
+++ b/monero/include/monero_payments.php
@@ -356,8 +356,7 @@ class Monero_Gateway extends WC_Payment_Gateway
// If there isn't address (merchant missed that field!), $address will be the Monero address for donating :)
$address = "44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A";
}
- $uri = "monero:$address?tx_payment_id=$payment_id";
-
+ $uri = urlencode("monero:".$address."?tx_amount=".$amount_xmr2."&tx_payment_id=".$payment_id);
if($this->zero_confirm){
$this->verify_zero_conf($payment_id, $amount_xmr2, $order_id);
}
@@ -440,7 +439,7 @@ class Monero_Gateway extends WC_Payment_Gateway
$order->update_meta_data( "Amount requested (XMR)", $amount_xmr2);
$order->save();
- $uri = "monero:$address?tx_payment_id=$payment_id";
+ $uri = urlencode("monero:".$address."?tx_amount=".$amount_xmr2."&tx_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 get integrated address');
From 903bd8b2d796fcadb4236a0e3ddb4a9f1e30bb09 Mon Sep 17 00:00:00 2001
From: cameleater <34056915+cameleater@users.noreply.github.com>
Date: Fri, 18 May 2018 10:57:33 +0800
Subject: [PATCH 06/50] update monero_payments.php
should now support all the woocommerce currencies as long as the currency is also supported cryptocompare api
---
monero/include/monero_payments.php | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/monero/include/monero_payments.php b/monero/include/monero_payments.php
index ab060eb..2e5fb44 100644
--- a/monero/include/monero_payments.php
+++ b/monero/include/monero_payments.php
@@ -583,7 +583,8 @@ class Monero_Gateway extends WC_Payment_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,COP,SGD&extraParams=monero_woocommerce');
+ $api_link = 'https://min-api.cryptocompare.com/data/price?fsym=XMR&tsyms=BTC,USD,EUR,CAD,INR,GBP,COP,SGD' . ',' . $currency . '&extraParams=monero_woocommerce';
+ $xmr_price = file_get_contents($api_link);
$price = json_decode($xmr_price, TRUE);
if (!isset($price)) {
$this->log->add('Monero_Gateway', '[ERROR] Unable to get the price of Monero');
@@ -603,6 +604,8 @@ class Monero_Gateway extends WC_Payment_Gateway
return $price['COP'];
case 'SGD':
return $price['SGD'];
+ case $currency:
+ return $price[$currency];
case 'XMR':
$price = '1';
return $price;
From 8def077ba45344a0a824e1339b325dcdc25b4d17 Mon Sep 17 00:00:00 2001
From: Dimitris Apostolou
Date: Sun, 20 May 2018 22:17:38 +0300
Subject: [PATCH 07/50] Fix typos
---
README.md | 26 +++++++++++++-------------
monero/include/ed25519.php | 2 +-
monero/include/monero_payments.php | 26 +++++++++++++-------------
monero/library.php | 4 ++--
readme.txt | 4 ++--
5 files changed, 31 insertions(+), 31 deletions(-)
diff --git a/README.md b/README.md
index edc0f26..b9fdee1 100644
--- a/README.md
+++ b/README.md
@@ -1,15 +1,15 @@
# MoneroWP
A WooCommerce extension for accepting Monero
-## Dependancies
-This plugin is rather simple but there are a few things that need to be set up before hand.
+## Dependencies
+This plugin is rather simple but there are a few things that need to be set up beforehand.
* A web server! Ideally with the most recent versions of PHP and mysql
* A Monero wallet. You can find the official wallet [here](https://getmonero.org/downloads/)
* [WordPress](https://wordpress.org)
-Wordpress is the backend tool that is needed to use WooCommerce and this Monero plugin
+WordPress is the backend tool that is needed to use WooCommerce and this Monero plugin
* [WooCommerce](https://woocommerce.com)
This Monero plugin is an extension of WooCommerce, which works with WordPress
@@ -19,7 +19,7 @@ This Monero plugin is an extension of WooCommerce, which works with WordPress
* Unzip the file monerowp_release.zip if you downloaded the zip from the releases page [here](https://github.com/monero-integrations/monerowp/releases).
-* Put the plugin in the correct directory: You will need to put the folder named `monero` from this repo/unzipped release into the wordpress plugins directory. This can be found at `path/to/wordpress/folder/wp-content/plugins`
+* Put the plugin in the correct directory: You will need to put the folder named `monero` from this repo/unzipped release into the WordPress plugins directory. This can be found at `path/to/wordpress/folder/wp-content/plugins`
* Activate the plugin from the WordPress admin panel: Once you login to the admin panel in WordPress, click on "Installed Plugins" under "Plugins". Then simply click "Activate" where it says "Monero - WooCommerce Gateway"
@@ -28,20 +28,20 @@ This Monero plugin is an extension of WooCommerce, which works with WordPress
* Get your Monero wallet address starting with '4'
* Get your wallet secret viewkey from your wallet
-A note on privacy: When you validate transactions with your private viewkey, your viewkey is sent to (but not stored on) xmrchain.net over HTTPS. This could potentally allow an attacker to see your incoming, but not outgoing, transactions if he were to get his hands on your viewkey. Even if this were to happen, your funds would still be safe and it would be impossible for somebody to steal your money. For maximum privacy use your own monero-wallet-rpc instance.
+A note on privacy: When you validate transactions with your private viewkey, your viewkey is sent to (but not stored on) xmrchain.net over HTTPS. This could potentially allow an attacker to see your incoming, but not outgoing, transactions if he were to get his hands on your viewkey. Even if this were to happen, your funds would still be safe and it would be impossible for somebody to steal your money. For maximum privacy use your own monero-wallet-rpc instance.
-## Step 2 Option 2: Get a monero daemon to connect to
+## Step 2 Option 2: Get a Monero daemon to connect to
### Option 1: Running a full node yourself
-To do this: start the monero daemon on your server and leave it running in the background. This can be accomplished by running `./monerod` inside your monero downloads folder. The first time that you start your node, the monero daemon will download and sync the entire monero blockchain. This can take several hours and is best done on a machine with at least 4GB of ram, an SSD hard drive (with at least 40GB of free space), and a high speed internet connection.
+To do this: start the Monero daemon on your server and leave it running in the background. This can be accomplished by running `./monerod` inside your Monero downloads folder. The first time that you start your node, the Monero daemon will download and sync the entire Monero blockchain. This can take several hours and is best done on a machine with at least 4GB of ram, an SSD hard drive (with at least 40GB of free space), and a high speed internet connection.
### Option 2: Connecting to a remote node
The easiest way to find a remote node to connect to is to visit [moneroworld.com](https://moneroworld.com/#nodes) and use one of the nodes offered. It is probably easiest to use node.moneroworld.com:18089 which will automatically connect you to a random node.
-### Setup your monero wallet-rpc
+### Setup your Monero wallet-rpc
-* Setup a monero wallet using the monero-wallet-cli tool. If you do not know how to do this you can learn about it at [getmonero.org](https://getmonero.org/resources/user-guides/monero-wallet-cli.html)
+* Setup a Monero wallet using the monero-wallet-cli tool. If you do not know how to do this you can learn about it at [getmonero.org](https://getmonero.org/resources/user-guides/monero-wallet-cli.html)
* [Create a view-only wallet from that wallet for security.](https://monero.stackexchange.com/questions/3178/how-to-create-a-view-only-wallet-for-the-gui/4582#4582)
@@ -61,17 +61,17 @@ The easiest way to find a remote node to connect to is to visit [moneroworld.com
If You chose to use viewkey:
-* Enter your monero wallet address in the box labled "Monero Address". If you do not know your address, you can run the `address` commmand in your monero wallet
+* Enter your Monero wallet address in the box labeled "Monero Address". If you do not know your address, you can run the `address` command in your Monero wallet
* Enter your secret viewkey in the box labeled "ViewKey"
If you chose to use monero-wallet-rpc:
-* Enter your monero wallet address in the box labled "Monero Address". If you do not know your address, you can run the `address` commmand in your monero wallet
+* Enter your Monero wallet address in the box labeled "Monero Address". If you do not know your address, you can run the `address` command in your Monero wallet
-* Enter the IP address of your server in the box labeled "Monero wallet rpc Host/IP"
+* Enter the IP address of your server in the box labeled "Monero wallet RPC Host/IP"
-* Enter the port number of the Wallet RPC in the box labeled "Monero wallet rpc port" (will be `18082` if you used the above example).
+* Enter the port number of the Wallet RPC in the box labeled "Monero wallet RPC port" (will be `18082` if you used the above example).
Finally:
diff --git a/monero/include/ed25519.php b/monero/include/ed25519.php
index 9852b68..e6d443b 100644
--- a/monero/include/ed25519.php
+++ b/monero/include/ed25519.php
@@ -48,7 +48,7 @@ class ed25519
public $B;
- private $gmp; // Is the GMP extention available?
+ private $gmp; // Is the GMP extension available?
public function __construct()
{
diff --git a/monero/include/monero_payments.php b/monero/include/monero_payments.php
index 2e5fb44..1ad6468 100644
--- a/monero/include/monero_payments.php
+++ b/monero/include/monero_payments.php
@@ -136,17 +136,17 @@ class Monero_Gateway extends WC_Payment_Gateway
'title' => __('Use monero-wallet-rpc', 'monero_gateway'),
'label' => __(' Verify transactions with the monero-wallet-rpc ', 'monero_gateway'),
'type' => 'checkbox',
- 'description' => __('This must be setup seperatly', 'monero_gateway'),
+ 'description' => __('This must be setup seperately', 'monero_gateway'),
'default' => 'no'
),
'daemon_host' => array(
- 'title' => __('Monero wallet rpc Host/ IP', 'monero_gateway'),
+ 'title' => __('Monero wallet RPC Host/ IP', 'monero_gateway'),
'type' => 'text',
'desc_tip' => __('This is the Daemon Host/IP to authorize the payment with port', 'monero_gateway'),
'default' => 'localhost',
),
'daemon_port' => array(
- 'title' => __('Monero wallet rpc port', 'monero_gateway'),
+ 'title' => __('Monero wallet RPC port', 'monero_gateway'),
'type' => 'text',
'desc_tip' => __('This is the Daemon Host/IP to authorize the payment with port', 'monero_gateway'),
'default' => '18080',
@@ -222,9 +222,9 @@ class Monero_Gateway extends WC_Payment_Gateway
{
$wallet_amount = $this->monero_daemon->getbalance();
if (!isset($wallet_amount)) {
- $this->log->add('Monero_gateway', '[ERROR] Can not connect to monero-wallet-rpc');
- echo "Your balance is: Not Avaliable ";
- echo "Unlocked balance: Not Avaliable";
+ $this->log->add('Monero_gateway', '[ERROR] Cannot connect to monero-wallet-rpc');
+ echo "Your balance is: Not Available ";
+ echo "Unlocked balance: Not Available";
}
else
{
@@ -386,7 +386,7 @@ class Monero_Gateway extends WC_Payment_Gateway
-
+
@@ -419,7 +419,7 @@ class Monero_Gateway extends WC_Payment_Gateway
-
+
@@ -467,7 +467,7 @@ class Monero_Gateway extends WC_Payment_Gateway
-
+
@@ -498,7 +498,7 @@ class Monero_Gateway extends WC_Payment_Gateway
-
+
@@ -552,7 +552,7 @@ class Monero_Gateway extends WC_Payment_Gateway
$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
+ $rounded_amount = round($new_amount, 12); //the Monero 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
{
@@ -665,7 +665,7 @@ class Monero_Gateway extends WC_Payment_Gateway
}
return $message;
}
- public function last_block_seen($height) // sometimes 2 blocks are mined within a few seconds of eacher. Make sure we don't miss one
+ public function last_block_seen($height) // sometimes 2 blocks are mined within a few seconds of each other. Make sure we don't miss one
{
if (!isset($_COOKIE['last_seen_block']))
{
@@ -810,7 +810,7 @@ class Monero_Gateway extends WC_Payment_Gateway
-
-
- ";
-
- echo "
- ";
- }
- }
-
- private function set_paymentid_cookie($size)
- {
- if (!isset($_COOKIE['payment_id'])) {
- $payment_id = bin2hex(openssl_random_pseudo_bytes($size));
- setcookie('payment_id', $payment_id, time() + 2700);
- }
- else{
- $payment_id = $this->sanatize_id($_COOKIE['payment_id']);
- }
- return $payment_id;
- }
-
- public function sanatize_id($payment_id)
- {
- // Limit payment id to alphanumeric characters
- $sanatized_id = preg_replace("/[^a-zA-Z0-9]+/", "", $payment_id);
- return $sanatized_id;
- }
-
- public function changeto($amount, $currency, $payment_id)
- {
- global $wpdb;
- // This will create a table named whatever the payment id is inside the database "WordPress"
- $create_table = "CREATE TABLE IF NOT EXISTS $payment_id (
- rate INT
- )";
- $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");
-
- $stored_rate_transformed = $stored_rate[0]->rate / 100; //this will turn the stored rate back into a decimaled number
-
- if (isset($this->discount)) {
- $sanatized_discount = preg_replace('/[^0-9]/', '', $this->discount);
- $discount_decimal = $sanatized_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 Monero 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
-
- $wpdb->query("INSERT INTO $payment_id (rate) VALUES ($live_for_storing)");
- if(isset($this->discount))
- {
- $new_amount = $amount / $xmr_live_price;
- $discount = $new_amount * $this->discount / 100;
- $discounted_price = $new_amount - $discount;
- $rounded_amount = round($discounted_price, 12);
- }
- else
- {
- $new_amount = $amount / $xmr_live_price;
- $rounded_amount = round($new_amount, 12);
- }
- }
-
- return $rounded_amount;
- }
-
-
- // Check if we are forcing SSL on checkout pages
- // Custom function not required by the Gateway
-
- public function retriveprice($currency)
- {
- $api_link = 'https://min-api.cryptocompare.com/data/price?fsym=XMR&tsyms=BTC,USD,EUR,CAD,INR,GBP,COP,SGD' . ',' . $currency . '&extraParams=monero_woocommerce';
- $xmr_price = file_get_contents($api_link);
- $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 'COP':
- return $price['COP'];
- case 'SGD':
- return $price['SGD'];
- case $currency:
- return $price[$currency];
- case 'XMR':
- $price = '1';
- return $price;
- }
- }
-
- private function on_verified($payment_id, $amount_atomic_units, $order_id)
- {
- $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);
-
- if($this->is_virtual_in_cart($order_id) == true){
- $order->update_status('completed', __('Payment has been received.', 'monero_gateway'));
- }
- else{
- $order->update_status('processing', __('Payment has been received.', 'monero_gateway')); // Show payment id used for order
- }
- 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 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 = $this->on_verified($payment_id, $amount_atomic_units, $order_id);
- }
- if ($get_payments_method["payments"][0]["amount"] < $amount_atomic_units)
- {
- $totalPayed = $get_payments_method["payments"][0]["amount"];
- $outputs_count = count($get_payments_method["payments"]); // number of outputs recieved with this payment id
- $output_counter = 1;
-
- while($output_counter < $outputs_count)
- {
- $totalPayed += $get_payments_method["payments"][$output_counter]["amount"];
- $output_counter++;
- }
- if($totalPayed >= $amount_atomic_units)
- {
- $message = $this->on_verified($payment_id, $amount_atomic_units, $order_id);
- }
- }
- }
- return $message;
- }
- public function last_block_seen($height) // sometimes 2 blocks are mined within a few seconds of each other. Make sure we don't miss one
- {
- if (!isset($_COOKIE['last_seen_block']))
- {
- setcookie('last_seen_block', $height, time() + 2700);
- return 0;
- }
- else{
- $cookie_block = $_COOKIE['last_seen_block'];
- $difference = $height - $cookie_block;
- setcookie('last_seen_block', $height, time() + 2700);
- return $difference;
- }
- }
-
- public function verify_non_rpc($payment_id, $amount, $order_id, $accept_zero_conf = false)
- {
- $tools = new NodeTools($this->testnet);
-
- $amount_atomic_units = $amount * 1000000000000;
-
- $outputs = $tools->get_outputs($this->address, $this->viewKey, $accept_zero_conf);
- $outs_count = count($outputs);
-
- $i = 0;
- $tx_hash;
- if($outs_count != 0)
- {
- while($i < $outs_count )
- {
- if($outputs[$i]['payment_id'] == $payment_id)
- {
- if($outputs[$i]['amount'] >= $amount_atomic_units)
- {
- $this->on_verified($payment_id, $amount_atomic_units, $order_id);
- return true;
- }
- }
- $i++;
- }
- }
- return false;
- }
-
- public function do_ssl_check()
- {
- if ($this->enabled == "yes" && !$this->get_option('onion_service')) {
- if (get_option('woocommerce_force_ssl_checkout') == "no") {
- echo "
" . sprintf(__("%s 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 forcing the checkout pages to be secured."), $this->method_title, admin_url('admin.php?page=wc-settings&tab=checkout')) . "
";
- }
- }
- }
-
- 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 "
Everything works! Congratulations and welcome to Monero.
+
+
+
+
\ No newline at end of file
diff --git a/templates/monero-gateway/customer/order-email-block.php b/templates/monero-gateway/customer/order-email-block.php
new file mode 100644
index 0000000..57b1e85
--- /dev/null
+++ b/templates/monero-gateway/customer/order-email-block.php
@@ -0,0 +1,56 @@
+
+
+
+
+
+
+
Your order has been confirmed. Thank you for paying with Monero!
+
+
+
+
+
+
+
+
Your order has expired. Please place another order to complete your purchase.
+
+
+
+
+
+
+
+
Please pay the amount due to complete your transactions. Your order will expire in if payment is not received.
+
+
+
+
+
+
+ PAY TO:
+
+
+
+
+
+
+
+ TOTAL DUE:
+
+ XMR
+
+
+
+
+
+ EXCHANGE RATE:
+
+ 1 XMR =
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/templates/monero-gateway/customer/order-email-error-block.php b/templates/monero-gateway/customer/order-email-error-block.php
new file mode 100644
index 0000000..f07b613
--- /dev/null
+++ b/templates/monero-gateway/customer/order-email-error-block.php
@@ -0,0 +1,5 @@
+
+
+
+
+
Payment method not available, please contact the store owner for manual payment
Payment method not available, please contact the store owner for manual payment
+
\ No newline at end of file
diff --git a/templates/monero-gateway/customer/order-page.php b/templates/monero-gateway/customer/order-page.php
new file mode 100644
index 0000000..8e809a2
--- /dev/null
+++ b/templates/monero-gateway/customer/order-page.php
@@ -0,0 +1,100 @@
+
+
+
+
+
+
+ Please pay the amount due to complete your transactions. Your order will expire in if payment is not received.
+
+ We have received partial payment. Please pay the remaining amount to complete your transactions. Your order will expire in if payment is not received.
+
+ We have received your payment in full. Please wait while amount is confirmed. Approximate confirm time is . You can check your payment status anytime in your account dashboard.
+
+ Your order has been confirmed. Thank you for paying with Monero!
+
+ Your order has expired. Please place another order to complete your purchase.
+
+ Your order has expired. Please contact the store owner to receive refund on your partial payment.
+
+
+
+
+
+ Pay to:
+
+
+
+
+
+
+
+
+
+
+
+ Total due:
+
+
+ XMR
+
+
+
+
+
+
+
+ Total order amount:
+
+ XMR
+
+
+
+ Total paid:
+
+ XMR
+
+
+
+ Exchange rate:
+
+
+
+
+
+
+
+
+
Transaction id
+
Height
+
Amount
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
From 1b2c66a75b5721615744dcd732cac3a4122568eb Mon Sep 17 00:00:00 2001
From: mosu forge
Date: Sat, 22 Sep 2018 08:35:41 -0700
Subject: [PATCH 18/50] removed donation address
---
README.md | 2 --
1 file changed, 2 deletions(-)
diff --git a/README.md b/README.md
index aea0a99..f714348 100644
--- a/README.md
+++ b/README.md
@@ -103,5 +103,3 @@ This will display a badge showing that you accept Monero-currency.
## Donations
monero-integrations: 44krVcL6TPkANjpFwS2GWvg1kJhTrN7y9heVeQiDJ3rP8iGbCd5GeA4f3c2NKYHC1R4mCgnW7dsUUUae2m9GiNBGT4T8s2X
-
-mosu-forge: 4A6BQp7do5MTxpCguq1kAS27yMLpbHcf89Ha2a8Shayt2vXkCr6QRpAXr1gLYRV5esfzoK3vLJTm5bDWk5gKmNrT6s6xZep
From a17af45bd87a9c6682e4c49ffedf2ac49db2b3fb Mon Sep 17 00:00:00 2001
From: SerHack <27734319+serhack@users.noreply.github.com>
Date: Sat, 24 Nov 2018 21:47:27 +0100
Subject: [PATCH 19/50] Update LICENSE
---
LICENSE | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/LICENSE b/LICENSE
index 1dba848..528fd46 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,7 +1,6 @@
MIT License
-Copyright (c) 2018, Ryo Currency Project
-Portions Copyright (c) 2017-2018, Monero Integrations
+Copyright (c) 2017-2018, Monero Integrations
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
From 53463e9111312b42b842ab4d3939757d54eafbd4 Mon Sep 17 00:00:00 2001
From: SerHack <27734319+serhack@users.noreply.github.com>
Date: Sat, 24 Nov 2018 21:51:01 +0100
Subject: [PATCH 20/50] Update readme.txt
---
readme.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/readme.txt b/readme.txt
index ee5ac56..7fdcf7b 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,5 +1,5 @@
=== Monero WooCommerce Extension ===
-Contributors: serhack, mosu-forge
+Contributors: Monero Integrations Team
Donate link: http://monerointegrations.com/donate.html
Tags: monero, woocommerce, integration, payment, merchant, cryptocurrency, accept monero, monero woocommerce
Requires at least: 4.0
From ccb387095d3ed7da45323aa5e411e202e687a646 Mon Sep 17 00:00:00 2001
From: SerHack <27734319+serhack@users.noreply.github.com>
Date: Sun, 25 Nov 2018 18:22:09 +0100
Subject: [PATCH 21/50] Update class-monero-gateway.php
---
include/class-monero-gateway.php | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/include/class-monero-gateway.php b/include/class-monero-gateway.php
index 7cda884..56f9819 100644
--- a/include/class-monero-gateway.php
+++ b/include/class-monero-gateway.php
@@ -519,7 +519,8 @@ class Monero_Gateway extends WC_Payment_Gateway
}
}
- $qrcode_uri = 'monero:'.$address.'?tx_amount='.$amount_due.'&tx_payment_id='.$payment_id;
+ $amount_formatted = self::format_monero($amount_due);
+ $qrcode_uri = 'monero:'.$address.'?tx_amount='.$amount_formatted.'&tx_payment_id='.$payment_id;
$my_order_url = wc_get_endpoint_url('view-order', $order_id, wc_get_page_permalink('myaccount'));
$payment_details = array(
From cd06d0303b98ff6b3099e077ebc9c3df533293ba Mon Sep 17 00:00:00 2001
From: mosu forge
Date: Wed, 28 Nov 2018 04:06:19 -0800
Subject: [PATCH 22/50] Re-added Ryo-currency copyright, contributer, and
donation address
---
LICENSE | 1 +
README.md | 2 ++
readme.txt | 2 +-
3 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/LICENSE b/LICENSE
index 528fd46..d4ba96f 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,7 @@
MIT License
Copyright (c) 2017-2018, Monero Integrations
+Copyright (c) 2018, Ryo Currency Project
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/README.md b/README.md
index f714348..8a2fcc1 100644
--- a/README.md
+++ b/README.md
@@ -103,3 +103,5 @@ This will display a badge showing that you accept Monero-currency.
## Donations
monero-integrations: 44krVcL6TPkANjpFwS2GWvg1kJhTrN7y9heVeQiDJ3rP8iGbCd5GeA4f3c2NKYHC1R4mCgnW7dsUUUae2m9GiNBGT4T8s2X
+
+ryo-currency: 4A6BQp7do5MTxpCguq1kAS27yMLpbHcf89Ha2a8Shayt2vXkCr6QRpAXr1gLYRV5esfzoK3vLJTm5bDWk5gKmNrT6s6xZep
diff --git a/readme.txt b/readme.txt
index 7fdcf7b..0338811 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,5 +1,5 @@
=== Monero WooCommerce Extension ===
-Contributors: Monero Integrations Team
+Contributors: Monero Integrations Team, Ryo Currency Project
Donate link: http://monerointegrations.com/donate.html
Tags: monero, woocommerce, integration, payment, merchant, cryptocurrency, accept monero, monero woocommerce
Requires at least: 4.0
From f7fa0b758e013f74ad08f6f9c6e7e6fea5500652 Mon Sep 17 00:00:00 2001
From: mosu forge
Date: Wed, 28 Nov 2018 05:34:47 -0800
Subject: [PATCH 23/50] Updated readme
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index f714348..7dc3607 100644
--- a/README.md
+++ b/README.md
@@ -61,7 +61,7 @@ Note on security: using this option, while the most secure, requires you to run
* `Monero wallet RPC port` (if confirmation type is `monero-wallet-rpc`) - Port the wallet rpc is bound to with the `--rpc-bind-port` argument. (Default 18080)
* `Testnet` - Check this to change the blockchain explorer links to the testnet explorer. (Default: unchecked)
* `SSL warnings` - Check this to silence SSL warnings. (Default: unchecked)
-* `Show QR Code` - Show payment QR codes. There is no Monero software that can read QR codes at this time (Default: unchecked)
+* `Show QR Code` - Show payment QR codes. (Default: unchecked)
* `Show Prices in Monero` - Convert all prices on the frontend to Monero. Experimental feature, only use if you do not accept any other payment option. (Default: unchecked)
* `Display Decimals` (if show prices in Monero is enabled) - Number of decimals to round prices to on the frontend. The final order amount will not be rounded and will be displayed down to the nanoMonero. (Default: 12)
From ad0d9ef004f58b587b6ac2f06da7f78d5415bd70 Mon Sep 17 00:00:00 2001
From: mosu forge
Date: Wed, 28 Nov 2018 07:37:38 -0800
Subject: [PATCH 24/50] modified woocommerce_gateway_icon filter to use two
arguments
---
include/class-monero-gateway.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/class-monero-gateway.php b/include/class-monero-gateway.php
index 56f9819..6f3a45b 100644
--- a/include/class-monero-gateway.php
+++ b/include/class-monero-gateway.php
@@ -42,7 +42,7 @@ class Monero_Gateway extends WC_Payment_Gateway
public function get_icon()
{
- return apply_filters('woocommerce_gateway_icon', '');
+ return apply_filters('woocommerce_gateway_icon', '', $this->id);
}
function __construct($add_action=true)
From 80098195921f45a7455767ab881aaa2aba418393 Mon Sep 17 00:00:00 2001
From: itssteven
Date: Fri, 11 Jan 2019 16:12:58 +0000
Subject: [PATCH 25/50] Subaddresses
Generate subaddress instead of payment id and don't bother creating an integrated address if we're using the rpc.
---
include/class-monero-gateway.php | 32 +++++++++++++++++++-------------
1 file changed, 19 insertions(+), 13 deletions(-)
diff --git a/include/class-monero-gateway.php b/include/class-monero-gateway.php
index 6f3a45b..41a976d 100644
--- a/include/class-monero-gateway.php
+++ b/include/class-monero-gateway.php
@@ -209,12 +209,24 @@ class Monero_Gateway extends WC_Payment_Gateway
$order = wc_get_order($order_id);
- // Generate a unique payment id
- do {
- $payment_id = bin2hex(openssl_random_pseudo_bytes(8));
- $query = $wpdb->prepare("SELECT COUNT(*) FROM $table_name WHERE payment_id=%s", array($payment_id));
- $payment_id_used = $wpdb->get_var($query);
- } while ($payment_id_used);
+ if(self::$confirm_type != 'wownero-wallet-rpc') {
+ // Generate a unique payment id
+ do {
+ $payment_id = bin2hex(openssl_random_pseudo_bytes(8));
+ $query = $wpdb->prepare("SELECT COUNT(*) FROM $table_name WHERE payment_id=%s", array($payment_id));
+ $payment_id_used = $wpdb->get_var($query);
+ } while ($payment_id_used);
+ }
+ else {
+ // Generate subaddress
+ $payment_id = self::$wownero_wallet_rpc->create_address(0, 'Order: ' . $order_id);
+ if(isset($payment_id['address'])) {
+ $payment_id = $payment_id['address'];
+ }
+ else {
+ $this->log->add('Wownero_Gateway', 'Couldn\'t create subaddress for order ' . $order_id);
+ }
+ }
$currency = $order->get_currency();
$rate = self::get_live_rate($currency);
@@ -477,13 +489,7 @@ class Monero_Gateway extends WC_Payment_Gateway
$payment_id = self::sanatize_id($details[0]->payment_id);
if(self::$confirm_type == 'monero-wallet-rpc') {
- $array_integrated_address = self::$monero_wallet_rpc->make_integrated_address($payment_id);
- if (isset($array_integrated_address['integrated_address'])) {
- $integrated_addr = $array_integrated_address['integrated_address'];
- } else {
- self::$log->add('Monero_Gateway', '[ERROR] Unable get integrated address');
- return '[ERROR] Unable get integrated address';
- }
+ $integrated_addr = $payment_id;
} else {
if ($address) {
$decoded_address = self::$cryptonote->decode_address($address);
From 184e740452f0081abf32a012e8c14e76898f369d Mon Sep 17 00:00:00 2001
From: itssteven
Date: Fri, 11 Jan 2019 16:49:08 +0000
Subject: [PATCH 26/50] Subaddresses
`get_address_index` for getting the index number of a specific subaddress, `get_transfers` to get in&pool transfers for that subaddresss index number, `store` required in create_address and create_address required to create new subaddresses
---
include/class-monero-wallet-rpc.php | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/include/class-monero-wallet-rpc.php b/include/class-monero-wallet-rpc.php
index 5940dda..4ff7f58 100644
--- a/include/class-monero-wallet-rpc.php
+++ b/include/class-monero-wallet-rpc.php
@@ -349,4 +349,30 @@ class Monero_Wallet_Rpc
$get_bulk_payments = $this->_run('get_bulk_payments', $get_bulk_payments_parameters);
return $get_bulk_payments;
}
+
+ public function get_transfers($arr)
+ {
+ $get_parameters = $arr;
+ $get_transfers = $this->_run('get_transfers', $get_parameters);
+ return $get_transfers;
+ }
+
+ public function get_address_index($subaddress)
+ {
+ $params = array('address' => $subaddress);
+ return $this->_run('get_address_index', $params);
+ }
+
+ public function store()
+ {
+ return $this->_run('store');
+ }
+
+ public function create_address($account_index = 0, $label = '')
+ {
+ $params = array('account_index' => $account_index, 'label' => $label);
+ $create_address_method = $this->_run('create_address', $params);
+ $save = $this->store(); // Save wallet state after subaddress creation
+ return $create_address_method;
+ }
}
From f7d1f9b968398be311867650e6b4fa095bd0dc51 Mon Sep 17 00:00:00 2001
From: itssteven
Date: Fri, 11 Jan 2019 16:49:38 +0000
Subject: [PATCH 27/50] Update class-monero-wallet-rpc.php
---
include/class-monero-wallet-rpc.php | 7 -------
1 file changed, 7 deletions(-)
diff --git a/include/class-monero-wallet-rpc.php b/include/class-monero-wallet-rpc.php
index 4ff7f58..2f3bb57 100644
--- a/include/class-monero-wallet-rpc.php
+++ b/include/class-monero-wallet-rpc.php
@@ -244,13 +244,6 @@ class Monero_Wallet_Rpc
return $incoming_transfers;
}
- public function get_transfers($input_type, $input_value)
- {
- $get_parameters = array($input_type => $input_value);
- $get_transfers = $this->_run('get_transfers', $get_parameters);
- return $get_transfers;
- }
-
public function view_key()
{
$query_key = array('key_type' => 'view_key');
From ba395d507ee671dede3dff2e96561b2dbf9688c5 Mon Sep 17 00:00:00 2001
From: itssteven
Date: Fri, 11 Jan 2019 16:56:33 +0000
Subject: [PATCH 28/50] Update class-monero-gateway.php
---
include/class-monero-gateway.php | 33 +++++++++++++++++++++++++-------
1 file changed, 26 insertions(+), 7 deletions(-)
diff --git a/include/class-monero-gateway.php b/include/class-monero-gateway.php
index 41a976d..ca9fbe8 100644
--- a/include/class-monero-gateway.php
+++ b/include/class-monero-gateway.php
@@ -404,13 +404,32 @@ class Monero_Gateway extends WC_Payment_Gateway
protected static function check_payment_rpc($payment_id)
{
$txs = array();
- $payments = self::$monero_wallet_rpc->get_all_payments($payment_id);
- foreach($payments as $payment) {
- $txs[] = array(
- 'amount' => $payment['amount'],
- 'txid' => $payment['tx_hash'],
- 'height' => $payment['block_height']
- );
+ $address_index = self::$wownero_wallet_rpc->get_address_index($payment_id);
+ if(isset($address_index['index']['minor'])){
+ $address_index = $address_index['index']['minor'];
+ }
+ else {
+ self::$log->add('Wownero_Gateway', '[ERROR] Couldn\'t get address index of subaddress: ' . $payment_id);
+ return $txs;
+ }
+ $payments = self::$wownero_wallet_rpc->get_transfers(array( 'in' => true, 'pool' => true, 'subaddr_indices' => array($address_index)));
+ if(isset($payments['in'])) {
+ foreach($payments['in'] as $payment) {
+ $txs[] = array(
+ 'amount' => $payment['amount'],
+ 'txid' => $payment['txid'],
+ 'height' => $payment['height']
+ );
+ }
+ }
+ if(isset($payments['pool'])) {
+ foreach($payments['pool'] as $payment) {
+ $txs[] = array(
+ 'amount' => $payment['amount'],
+ 'txid' => $payment['txid'],
+ 'height' => $payment['height']
+ );
+ }
}
return $txs;
}
From 7e485215706c061cc7b1695b98790f49c499ccad Mon Sep 17 00:00:00 2001
From: itssteven
Date: Fri, 11 Jan 2019 17:00:42 +0000
Subject: [PATCH 29/50] Subaddresses
`payment_id` column extended to fit a subaddress over a 16 char payment id
---
monero-woocommerce-gateway.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/monero-woocommerce-gateway.php b/monero-woocommerce-gateway.php
index 10accac..1ef25bb 100644
--- a/monero-woocommerce-gateway.php
+++ b/monero-woocommerce-gateway.php
@@ -209,7 +209,7 @@ function monero_install() {
if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
$sql = "CREATE TABLE $table_name (
order_id BIGINT(20) UNSIGNED NOT NULL,
- payment_id VARCHAR(16) DEFAULT '' NOT NULL,
+ payment_id VARCHAR(100) DEFAULT '' NOT NULL,
currency VARCHAR(6) DEFAULT '' NOT NULL,
rate BIGINT UNSIGNED DEFAULT 0 NOT NULL,
amount BIGINT UNSIGNED DEFAULT 0 NOT NULL,
@@ -226,7 +226,7 @@ function monero_install() {
if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
$sql = "CREATE TABLE $table_name (
id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
- payment_id VARCHAR(16) DEFAULT '' NOT NULL,
+ payment_id VARCHAR(100) DEFAULT '' NOT NULL,
txid VARCHAR(64) DEFAULT '' NOT NULL,
amount BIGINT UNSIGNED DEFAULT 0 NOT NULL,
height MEDIUMINT UNSIGNED NOT NULL DEFAULT 0,
From 8e7d258b5b37604d2dc7db8075c3704fcbf53314 Mon Sep 17 00:00:00 2001
From: itssteven
Date: Fri, 11 Jan 2019 18:13:04 +0000
Subject: [PATCH 30/50] Update class-monero-gateway.php
---
include/class-monero-gateway.php | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/include/class-monero-gateway.php b/include/class-monero-gateway.php
index ca9fbe8..4ba94b0 100644
--- a/include/class-monero-gateway.php
+++ b/include/class-monero-gateway.php
@@ -209,7 +209,7 @@ class Monero_Gateway extends WC_Payment_Gateway
$order = wc_get_order($order_id);
- if(self::$confirm_type != 'wownero-wallet-rpc') {
+ if(self::$confirm_type != 'monero-wallet-rpc') {
// Generate a unique payment id
do {
$payment_id = bin2hex(openssl_random_pseudo_bytes(8));
@@ -219,12 +219,12 @@ class Monero_Gateway extends WC_Payment_Gateway
}
else {
// Generate subaddress
- $payment_id = self::$wownero_wallet_rpc->create_address(0, 'Order: ' . $order_id);
+ $payment_id = self::$monero_wallet_rpc->create_address(0, 'Order: ' . $order_id);
if(isset($payment_id['address'])) {
$payment_id = $payment_id['address'];
}
else {
- $this->log->add('Wownero_Gateway', 'Couldn\'t create subaddress for order ' . $order_id);
+ $this->log->add('Monero_Gateway', 'Couldn\'t create subaddress for order ' . $order_id);
}
}
@@ -404,15 +404,15 @@ class Monero_Gateway extends WC_Payment_Gateway
protected static function check_payment_rpc($payment_id)
{
$txs = array();
- $address_index = self::$wownero_wallet_rpc->get_address_index($payment_id);
+ $address_index = self::$monero_wallet_rpc->get_address_index($payment_id);
if(isset($address_index['index']['minor'])){
$address_index = $address_index['index']['minor'];
}
else {
- self::$log->add('Wownero_Gateway', '[ERROR] Couldn\'t get address index of subaddress: ' . $payment_id);
+ self::$log->add('Monero_Gateway', '[ERROR] Couldn\'t get address index of subaddress: ' . $payment_id);
return $txs;
}
- $payments = self::$wownero_wallet_rpc->get_transfers(array( 'in' => true, 'pool' => true, 'subaddr_indices' => array($address_index)));
+ $payments = self::$monero_wallet_rpc->get_transfers(array( 'in' => true, 'pool' => true, 'subaddr_indices' => array($address_index)));
if(isset($payments['in'])) {
foreach($payments['in'] as $payment) {
$txs[] = array(
From 21df86e4b8eea305a882eb350d5cb688805d3f77 Mon Sep 17 00:00:00 2001
From: itssteven
Date: Sat, 12 Jan 2019 08:57:50 +0000
Subject: [PATCH 31/50] Update class-monero-gateway.php
---
include/class-monero-gateway.php | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/include/class-monero-gateway.php b/include/class-monero-gateway.php
index 4ba94b0..03ae5ff 100644
--- a/include/class-monero-gateway.php
+++ b/include/class-monero-gateway.php
@@ -401,15 +401,15 @@ class Monero_Gateway extends WC_Payment_Gateway
}
}
- protected static function check_payment_rpc($payment_id)
+ protected static function check_payment_rpc($subaddress)
{
$txs = array();
- $address_index = self::$monero_wallet_rpc->get_address_index($payment_id);
+ $address_index = self::$monero_wallet_rpc->get_address_index($subaddress);
if(isset($address_index['index']['minor'])){
$address_index = $address_index['index']['minor'];
}
else {
- self::$log->add('Monero_Gateway', '[ERROR] Couldn\'t get address index of subaddress: ' . $payment_id);
+ self::$log->add('Monero_Gateway', '[ERROR] Couldn\'t get address index of subaddress: ' . $subaddress);
return $txs;
}
$payments = self::$monero_wallet_rpc->get_transfers(array( 'in' => true, 'pool' => true, 'subaddr_indices' => array($address_index)));
From 5fa97a828270ce17091613c31321336fbcabe2f6 Mon Sep 17 00:00:00 2001
From: itssteven
Date: Sat, 12 Jan 2019 09:21:44 +0000
Subject: [PATCH 32/50] Update monero-woocommerce-gateway.php
---
monero-woocommerce-gateway.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/monero-woocommerce-gateway.php b/monero-woocommerce-gateway.php
index 1ef25bb..95429af 100644
--- a/monero-woocommerce-gateway.php
+++ b/monero-woocommerce-gateway.php
@@ -209,7 +209,7 @@ function monero_install() {
if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
$sql = "CREATE TABLE $table_name (
order_id BIGINT(20) UNSIGNED NOT NULL,
- payment_id VARCHAR(100) DEFAULT '' NOT NULL,
+ payment_id VARCHAR(94) DEFAULT '' NOT NULL,
currency VARCHAR(6) DEFAULT '' NOT NULL,
rate BIGINT UNSIGNED DEFAULT 0 NOT NULL,
amount BIGINT UNSIGNED DEFAULT 0 NOT NULL,
@@ -226,7 +226,7 @@ function monero_install() {
if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
$sql = "CREATE TABLE $table_name (
id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
- payment_id VARCHAR(100) DEFAULT '' NOT NULL,
+ payment_id VARCHAR(94) DEFAULT '' NOT NULL,
txid VARCHAR(64) DEFAULT '' NOT NULL,
amount BIGINT UNSIGNED DEFAULT 0 NOT NULL,
height MEDIUMINT UNSIGNED NOT NULL DEFAULT 0,
From 646bcd671ae883cf0a66e4812b38b8226be67210 Mon Sep 17 00:00:00 2001
From: SerHack <27734319+serhack@users.noreply.github.com>
Date: Sun, 3 Mar 2019 13:51:48 +0100
Subject: [PATCH 33/50] Update class-monero-gateway.php
---
include/class-monero-gateway.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/class-monero-gateway.php b/include/class-monero-gateway.php
index 03ae5ff..8322f53 100644
--- a/include/class-monero-gateway.php
+++ b/include/class-monero-gateway.php
@@ -588,7 +588,7 @@ class Monero_Gateway extends WC_Payment_Gateway
$order_id = preg_replace("/[^0-9]+/", "", $_GET['order_id']);
$order = wc_get_order( $order_id );
- if($order->user_id != $user->ID)
+ if($order->user_id() != $user->ID)
self::ajax_output(array('error' => '[ERROR] Order does not belong to this user'));
if($order->get_payment_method() != self::$_id)
From 596a1e29ad0862820eac11013e7646f195793112 Mon Sep 17 00:00:00 2001
From: SerHack <27734319+serhack@users.noreply.github.com>
Date: Sun, 16 Jun 2019 10:00:50 +0200
Subject: [PATCH 34/50] Update readme.txt
---
readme.txt | 52 ++++++++++++++++++++++++++++++++++++----------------
1 file changed, 36 insertions(+), 16 deletions(-)
diff --git a/readme.txt b/readme.txt
index 0338811..87a1e64 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,18 +1,19 @@
=== Monero WooCommerce Extension ===
-Contributors: Monero Integrations Team, Ryo Currency Project
+Contributors: SerHack, mosu-forge
Donate link: http://monerointegrations.com/donate.html
Tags: monero, woocommerce, integration, payment, merchant, cryptocurrency, accept monero, monero woocommerce
Requires at least: 4.0
-Tested up to: 4.9.8
+Tested up to: 5.0.1
Stable tag: trunk
-License: GPLv2 or later
-License URI: http://www.gnu.org/licenses/gpl-2.0.html
+License: MIT license
+License URI: https://github.com/monero-integrations/monerowp/blob/master/LICENSE
-Monero WooCommerce Extension is a Wordpress plugin that allows to accept bitcoins at WooCommerce-powered online stores.
+Monero WooCommerce Extension is a Wordpress plugin that allows to accept monero at WooCommerce-powered online stores.
== Description ==
-An extension to WooCommerce for accepting Monero as payment in your store.
+Your online store must use WooCommerce platform (free wordpress plugin).
+Once you installed and activated WooCommerce, you may install and activate Monero WooCommerce Extension.
= Benefits =
@@ -21,17 +22,15 @@ An extension to WooCommerce for accepting Monero as payment in your store.
* Add monero payments option to your existing online store with alternative main currency.
* Flexible exchange rate calculations fully managed via administrative settings.
* Zero fees and no commissions for monero payments processing from any third party.
-* Automatic conversion to Monero via real time exchange rate feed and calculations.
+* Automatic conversion to Monero via realtime exchange rate feed and calculations.
* Ability to set exchange rate calculation multiplier to compensate for any possible losses due to bank conversions and funds transfer fees.
== Installation ==
-1. Install "Monero WooCommerce extension" WordPress plugin just like any other WordPress plugin.
+1. Install "Monero WooCommerce extension" wordpress plugin just like any other Wordpress plugin.
2. Activate
-3. Setup your monero-wallet-rpc with a view-only wallet
-4. Add your monero-wallet-rpc host address and Monero address in the settings panel
-5. Click “Enable this payment gateway”
-6. Enjoy it!
+3. Configure it with your wallet rpc address, (username or password not requested), your monero address
+4. Enjoy it!
== Remove plugin ==
@@ -47,11 +46,32 @@ An extension to WooCommerce for accepting Monero as payment in your store.
= 0.1 =
* First version ! Yay!
-= 0.2 =
-* Bug fixes
+= 1.0 =
+* Added the view key option
+
+= 2.1 =
+* Verify transactions without monero-wallet-rpc
+* Optionally accept zero confirmation transactions
+* bug fixing
+
+= 2.2 =
+* Fix some bugs
+
+= 2.3 =
+* Bug fixing
+
+= 3.0.0 =
+Huge shoutout to mosu-forge who contributes a lot to make 3.0 possible.
+* Ability to set number of confirms: 0 for zero conf, up to 60.
+* Amount owed in XMR gets locked in after the order for a configurable amount of time after which the order is invalid, default 60 minutes.
+* Shows transactions received along with the number of confirms right on the order success page, auto-updates through AJAX.
+* QR code generation is done with Javascript instead of sending payment details to a 3rd party.
+* Admin page for showing all transactions made to the wallet.
+* Logic is done via cron, instead of the user having to stay on the order page until payment is confirmed.
+* Payment details (along with the txid) are always visible on the customer's account dashboard on the my orders section.
+* Live prices are also run via cron, shortcodes for showing exchange rates.
+* Properly hooks into order confirmation email page.
-= 0.3 =
-* Complete rewrite of how the plugin handles payments
== Upgrade Notice ==
From fea43715ea55b4d4aedb64db4d75c962f694d9dd Mon Sep 17 00:00:00 2001
From: SerHack <27734319+serhack@users.noreply.github.com>
Date: Sun, 16 Jun 2019 10:09:43 +0200
Subject: [PATCH 35/50] Update base_58 library.
---
include/class-monero-base58.php | 677 ++++++++++++++++----------------
1 file changed, 340 insertions(+), 337 deletions(-)
diff --git a/include/class-monero-base58.php b/include/class-monero-base58.php
index 0818996..795f73c 100644
--- a/include/class-monero-base58.php
+++ b/include/class-monero-base58.php
@@ -1,354 +1,357 @@
(https://github.com/monero-integrations)
+ * @copyright 2018
+ * @license MIT
+ *
+ * ============================================================================
+ *
+ * // Initialize class
+ * $base58 = new base58();
+ *
+ * // Encode a hexadecimal (base16) string as base58
+ * $encoded = $base58->encode('0137F8F06C971B168745F562AA107B4D172F336271BC0F9D3B510C14D3460DFB27D8CEBE561E73AC1E11833D5EA40200EB3C82E9C66ACAF1AB1A6BB53C40537C0B7A22160B0E');
+ *
+ * // Decode
+ * $decoded = $base58->decode('479cG5opa54beQWSyqNoWw5tna9sHUNmMTtiFqLPaUhDevpJ2YLwXAggSx5ePdeFrYF8cdbmVRSmp1Kn3t4Y9kFu7rZ7pFw');
*
*/
-
-defined( 'ABSPATH' ) || exit;
-
-class Monero_base58 {
- /**
- * @var string
- */
- static $alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
- static $encoded_block_sizes = [0, 2, 3, 5, 6, 7, 9, 10, 11];
- static $full_block_size = 8;
- static $full_encoded_block_size = 11;
-
- /**
- *
- * Convert a hexadecimal string to a binary array
- *
- * @param string $hex A hexadecimal string to convert to a binary array
- * @return array
- *
- */
- private function hex_to_bin($hex) {
- if (gettype($hex) != 'string') {
- throw new Exception('base58->hex_to_bin(): Invalid input type (must be a string)');
- }
- if (strlen($hex) % 2 != 0) {
- throw new Exception('base58->hex_to_bin(): Invalid input length (must be even)');
- }
-
- $res = array_fill(0, strlen($hex) / 2, 0);
- for ($i = 0; $i < strlen($hex) / 2; $i++) {
- $res[$i] = intval(substr($hex, $i * 2, $i * 2 + 2 - $i * 2), 16);
- }
- return $res;
+use Exception;
+class Monero_base58
+{
+ static $alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
+ static $encoded_block_sizes = [0, 2, 3, 5, 6, 7, 9, 10, 11];
+ static $full_block_size = 8;
+ static $full_encoded_block_size = 11;
+ /**
+ *
+ * Convert a hexadecimal string to a binary array
+ *
+ * @param string $hex A hexadecimal string to convert to a binary array
+ *
+ * @return array
+ *
+ */
+ private function hex_to_bin($hex)
+ {
+ if (gettype($hex) != 'string') {
+ throw new Exception('base58->hex_to_bin(): Invalid input type (must be a string)');
}
-
- /**
- *
- * Convert a binary array to a hexadecimal string
- *
- * @param array $bin A binary array to convert to a hexadecimal string
- * @return string
- *
- */
- private function bin_to_hex($bin) {
- if (gettype($bin) != 'array') {
- throw new Exception('base58->bin_to_hex(): Invalid input type (must be an array)');
- }
-
- $res = [];
- for ($i = 0; $i < count($bin); $i++) {
- $res[] = substr('0'.dechex($bin[$i]), -2);
- }
- return join($res);
+ if (strlen($hex) % 2 != 0) {
+ throw new Exception('base58->hex_to_bin(): Invalid input length (must be even)');
}
-
- /**
- *
- * Convert a string to a binary array
- *
- * @param string $str A string to convert to a binary array
- * @return array
- *
- */
- private function str_to_bin($str) {
- if (gettype($str) != 'string') {
- throw new Exception('base58->str_to_bin(): Invalid input type (must be a string)');
- }
-
- $res = array_fill(0, strlen($str), 0);
- for ($i = 0; $i < strlen($str); $i++) {
- $res[$i] = ord($str[$i]);
- }
- return $res;
+ $res = array_fill(0, strlen($hex) / 2, 0);
+ for ($i = 0; $i < strlen($hex) / 2; $i++) {
+ $res[$i] = intval(substr($hex, $i * 2, $i * 2 + 2 - $i * 2), 16);
}
-
- /**
- *
- * Convert a binary array to a string
- *
- * @param array $bin A binary array to convert to a string
- * @return string
- *
- */
- private function bin_to_str($bin) {
- if (gettype($bin) != 'array') {
- throw new Exception('base58->bin_to_str(): Invalid input type (must be an array)');
- }
-
- $res = array_fill(0, count($bin), 0);
- for ($i = 0; $i < count($bin); $i++) {
- $res[$i] = chr($bin[$i]);
- }
- return preg_replace('/[[:^print:]]/', '', join($res)); // preg_replace necessary to strip errant non-ASCII characters eg. ''
+ return $res;
+ }
+ /**
+ *
+ * Convert a binary array to a hexadecimal string
+ *
+ * @param array $bin A binary array to convert to a hexadecimal string
+ *
+ * @return string
+ *
+ */
+ private function bin_to_hex($bin)
+ {
+ if (gettype($bin) != 'array') {
+ throw new Exception('base58->bin_to_hex(): Invalid input type (must be an array)');
}
-
- /**
- *
- * Convert a UInt8BE (one unsigned big endian byte) array to UInt64
- *
- * @param array $data A UInt8BE array to convert to UInt64
- * @return number
- *
- */
- private function uint8_be_to_64($data) {
- if (gettype($data) != 'array') {
- throw new Exception ('base58->uint8_be_to_64(): Invalid input type (must be an array)');
- }
-
- $res = 0;
- $i = 0;
- switch (9 - count($data)) {
- case 1:
- $res = bcadd(bcmul($res, bcpow(2, 8)), $data[$i++]);
- case 2:
- $res = bcadd(bcmul($res, bcpow(2, 8)), $data[$i++]);
- case 3:
- $res = bcadd(bcmul($res, bcpow(2, 8)), $data[$i++]);
- case 4:
- $res = bcadd(bcmul($res, bcpow(2, 8)), $data[$i++]);
- case 5:
- $res = bcadd(bcmul($res, bcpow(2, 8)), $data[$i++]);
- case 6:
- $res = bcadd(bcmul($res, bcpow(2, 8)), $data[$i++]);
- case 7:
- $res = bcadd(bcmul($res, bcpow(2, 8)), $data[$i++]);
- case 8:
- $res = bcadd(bcmul($res, bcpow(2, 8)), $data[$i++]);
- break;
- default:
- throw new Exception('base58->uint8_be_to_64: Invalid input length (1 <= count($data) <= 8)');
- }
- return $res;
+ $res = [];
+ for ($i = 0; $i < count($bin); $i++) {
+ $res[] = substr('0'.dechex($bin[$i]), -2);
}
-
- /**
- *
- * Convert a UInt64 (unsigned 64 bit integer) to a UInt8BE array
- *
- * @param number $num A UInt64 number to convert to a UInt8BE array
- * @param integer $size Size of array to return
- * @return array
- *
- */
- private function uint64_to_8_be($num, $size) {
- if (gettype($num) != ('integer' || 'double')) {
- throw new Exception ('base58->uint64_to_8_be(): Invalid input type ($num must be a number)');
- }
- if (gettype($size) != 'integer') {
- throw new Exception ('base58->uint64_to_8_be(): Invalid input type ($size must be an integer)');
- }
- if ($size < 1 || $size > 8) {
- throw new Exception ('base58->uint64_to_8_be(): Invalid size (1 <= $size <= 8)');
- }
-
- $res = array_fill(0, $size, 0);
- for ($i = $size - 1; $i >= 0; $i--) {
- $res[$i] = bcmod($num, bcpow(2, 8));
- $num = bcdiv($num, bcpow(2, 8));
- }
- return $res;
+ return join($res);
+ }
+ /**
+ *
+ * Convert a string to a binary array
+ *
+ * @param string $str A string to convert to a binary array
+ *
+ * @return array
+ *
+ */
+ private function str_to_bin($str)
+ {
+ if (gettype($str) != 'string') {
+ throw new Exception('base58->str_to_bin(): Invalid input type (must be a string)');
}
-
- /**
- *
- * Convert a hexadecimal (Base16) array to a Base58 string
- *
- * @param array $data
- * @param array $buf
- * @param number $index
- * @return array
- *
- */
- private function encode_block($data, $buf, $index) {
- if (gettype($data) != 'array') {
- throw new Exception('base58->encode_block(): Invalid input type ($data must be an array)');
- }
- if (gettype($buf) != 'array') {
- throw new Exception('base58->encode_block(): Invalid input type ($buf must be an array)');
- }
- if (gettype($index) != ('integer' || 'double')) {
- throw new Exception('base58->encode_block(): Invalid input type ($index must be a number)');
- }
- if (count($data) < 1 or count($data) > self::$full_encoded_block_size) {
- throw new Exception('base58->encode_block(): Invalid input length (1 <= count($data) <= 8)');
- }
-
- $num = self::uint8_be_to_64($data);
- $i = self::$encoded_block_sizes[count($data)] - 1;
- while ($num > 0) {
- $remainder = bcmod($num, 58);
- $num = bcdiv($num, 58);
- $buf[$index + $i] = ord(self::$alphabet[$remainder]);
- $i--;
- }
- return $buf;
+ $res = array_fill(0, strlen($str), 0);
+ for ($i = 0; $i < strlen($str); $i++) {
+ $res[$i] = ord($str[$i]);
}
-
- /**
- *
- * Encode a hexadecimal (Base16) string to Base58
- *
- * @param string $hex A hexadecimal (Base16) string to convert to Base58
- * @return string
- *
- */
- public function encode($hex) {
- if (gettype($hex) != 'string') {
- throw new Exception ('base58->encode(): Invalid input type (must be a string)');
- }
-
- $data = self::hex_to_bin($hex);
- if (count($data) == 0) {
- return '';
- }
-
- $full_block_count = floor(count($data) / self::$full_block_size);
- $last_block_size = count($data) % self::$full_block_size;
- $res_size = $full_block_count * self::$full_encoded_block_size + self::$encoded_block_sizes[$last_block_size];
-
- $res = array_fill(0, $res_size, 0);
- for ($i = 0; $i < $res_size; $i++) {
- $res[$i] = self::$alphabet[0];
- }
-
- for ($i = 0; $i < $full_block_count; $i++) {
- $res = self::encode_block(array_slice($data, $i * self::$full_block_size, ($i * self::$full_block_size + self::$full_block_size) - ($i * self::$full_block_size)), $res, $i * self::$full_encoded_block_size);
- }
-
- if ($last_block_size > 0) {
- $res = self::encode_block(array_slice($data, $full_block_count * self::$full_block_size, $full_block_count * self::$full_block_size + $last_block_size), $res, $full_block_count * self::$full_encoded_block_size);
- }
-
- return self::bin_to_str($res);
+ return $res;
+ }
+ /**
+ *
+ * Convert a binary array to a string
+ *
+ * @param array $bin A binary array to convert to a string
+ *
+ * @return string
+ *
+ */
+ private function bin_to_str($bin)
+ {
+ if (gettype($bin) != 'array') {
+ throw new Exception('base58->bin_to_str(): Invalid input type (must be an array)');
}
-
- /**
- *
- * Convert a Base58 input to hexadecimal (Base16)
- *
- * @param array $data
- * @param array $buf
- * @param integer $index
- * @return array
- *
- */
- private function decode_block($data, $buf, $index) {
- if (gettype($data) != 'array') {
- throw new Exception('base58->decode_block(): Invalid input type ($data must be an array)');
- }
- if (gettype($buf) != 'array') {
- throw new Exception('base58->decode_block(): Invalid input type ($buf must be an array)');
- }
- if (gettype($index) != ('integer' || 'double')) {
- throw new Exception('base58->decode_block(): Invalid input type ($index must be a number)');
- }
-
- $res_size = self::index_of(self::$encoded_block_sizes, count($data));
- if ($res_size <= 0) {
- throw new Exception('base58->decode_block(): Invalid input length ($data must be a value from base58::$encoded_block_sizes)');
- }
-
- $res_num = 0;
- $order = 1;
- for ($i = count($data) - 1; $i >= 0; $i--) {
- $digit = strpos(self::$alphabet, chr($data[$i]));
- if ($digit < 0) {
- throw new Exception("base58->decode_block(): Invalid character ($digit \"{$digit}\" not found in base58::$alphabet)");
- }
-
- $product = bcadd(bcmul($order, $digit), $res_num);
- if ($product > bcpow(2, 64)) {
- throw new Exception('base58->decode_block(): Integer overflow ($product exceeds the maximum 64bit integer)');
- }
-
- $res_num = $product;
- $order = bcmul($order, 58);
- }
- if ($res_size < self::$full_block_size && bcpow(2, 8 * $res_size) <= 0) {
- throw new Exception('base58->decode_block(): Integer overflow (bcpow(2, 8 * $res_size) exceeds the maximum 64bit integer)');
- }
-
- $tmp_buf = self::uint64_to_8_be($res_num, $res_size);
- for ($i = 0; $i < count($tmp_buf); $i++) {
- $buf[$i + $index] = $tmp_buf[$i];
- }
- return $buf;
+ $res = array_fill(0, count($bin), 0);
+ for ($i = 0; $i < count($bin); $i++) {
+ $res[$i] = chr($bin[$i]);
}
-
- /**
- *
- * Decode a Base58 string to hexadecimal (Base16)
- *
- * @param string $hex A Base58 string to convert to hexadecimal (Base16)
- * @return string
- *
- */
- public function decode($enc) {
- if (gettype($enc) != 'string') {
- throw new Exception ('base58->decode(): Invalid input type (must be a string)');
- }
-
- $enc = self::str_to_bin($enc);
- if (count($enc) == 0) {
- return '';
- }
- $full_block_count = floor(bcdiv(count($enc), self::$full_encoded_block_size));
- $last_block_size = bcmod(count($enc), self::$full_encoded_block_size);
- $last_block_decoded_size = self::index_of(self::$encoded_block_sizes, $last_block_size);
-
- $data_size = $full_block_count * self::$full_block_size + $last_block_decoded_size;
-
- $data = array_fill(0, $data_size, 0);
- for ($i = 0; $i < $full_block_count; $i++) {
- $data = self::decode_block(array_slice($enc, $i * self::$full_encoded_block_size, ($i * self::$full_encoded_block_size + self::$full_encoded_block_size) - ($i * self::$full_encoded_block_size)), $data, $i * self::$full_block_size);
- }
-
- if ($last_block_size > 0) {
- $data = self::decode_block(array_slice($enc, $full_block_count * self::$full_encoded_block_size, $full_block_count * self::$full_encoded_block_size + $last_block_size), $data, $full_block_count * self::$full_block_size);
- }
-
- return self::bin_to_hex($data);
+ return preg_replace('/[[:^print:]]/', '', join($res)); // preg_replace necessary to strip errant non-ASCII characters eg. ''
+ }
+ /**
+ *
+ * Convert a UInt8BE (one unsigned big endian byte) array to UInt64
+ *
+ * @param array $data A UInt8BE array to convert to UInt64
+ *
+ * @return number
+ *
+ */
+ private function uint8_be_to_64($data)
+ {
+ if (gettype($data) != 'array') {
+ throw new Exception ('base58->uint8_be_to_64(): Invalid input type (must be an array)');
}
-
- /**
- *
- * Search an array for a value
- * Source: https://stackoverflow.com/a/30994678
- *
- * @param array $haystack An array to search
- * @param string $needle A string to search for
- * @return number The index of the element found (or -1 for no match)
- *
- */
- private function index_of($haystack, $needle) {
- if (gettype($haystack) != 'array') {
- throw new Exception ('base58->decode(): Invalid input type ($haystack must be an array)');
- }
- // if (gettype($needle) != 'string') {
- // throw new Exception ('base58->decode(): Invalid input type ($needle must be a string)');
- // }
-
- foreach ($haystack as $key => $value) if ($value === $needle) return $key;
- return -1;
+ $res = 0;
+ $i = 0;
+ switch (9 - count($data)) {
+ case 1:
+ $res = bcadd(bcmul($res, bcpow(2, 8)), $data[$i++]);
+ case 2:
+ $res = bcadd(bcmul($res, bcpow(2, 8)), $data[$i++]);
+ case 3:
+ $res = bcadd(bcmul($res, bcpow(2, 8)), $data[$i++]);
+ case 4:
+ $res = bcadd(bcmul($res, bcpow(2, 8)), $data[$i++]);
+ case 5:
+ $res = bcadd(bcmul($res, bcpow(2, 8)), $data[$i++]);
+ case 6:
+ $res = bcadd(bcmul($res, bcpow(2, 8)), $data[$i++]);
+ case 7:
+ $res = bcadd(bcmul($res, bcpow(2, 8)), $data[$i++]);
+ case 8:
+ $res = bcadd(bcmul($res, bcpow(2, 8)), $data[$i++]);
+ break;
+ default:
+ throw new Exception('base58->uint8_be_to_64: Invalid input length (1 <= count($data) <= 8)');
+ }
+ return $res;
+ }
+ /**
+ *
+ * Convert a UInt64 (unsigned 64 bit integer) to a UInt8BE array
+ *
+ * @param number $num A UInt64 number to convert to a UInt8BE array
+ * @param integer $size Size of array to return
+ *
+ * @return array
+ *
+ */
+ private function uint64_to_8_be($num, $size)
+ {
+ if (gettype($num) != ('integer' || 'double')) {
+ throw new Exception ('base58->uint64_to_8_be(): Invalid input type ($num must be a number)');
}
+ if (gettype($size) != 'integer') {
+ throw new Exception ('base58->uint64_to_8_be(): Invalid input type ($size must be an integer)');
+ }
+ if ($size < 1 || $size > 8) {
+ throw new Exception ('base58->uint64_to_8_be(): Invalid size (1 <= $size <= 8)');
+ }
+ $res = array_fill(0, $size, 0);
+ for ($i = $size - 1; $i >= 0; $i--) {
+ $res[$i] = bcmod($num, bcpow(2, 8));
+ $num = bcdiv($num, bcpow(2, 8));
+ }
+ return $res;
+ }
+ /**
+ *
+ * Convert a hexadecimal (Base16) array to a Base58 string
+ *
+ * @param array $data
+ * @param array $buf
+ * @param number $index
+ *
+ * @return array
+ *
+ */
+ private function encode_block($data, $buf, $index)
+ {
+ if (gettype($data) != 'array') {
+ throw new Exception('base58->encode_block(): Invalid input type ($data must be an array)');
+ }
+ if (gettype($buf) != 'array') {
+ throw new Exception('base58->encode_block(): Invalid input type ($buf must be an array)');
+ }
+ if (gettype($index) != ('integer' || 'double')) {
+ throw new Exception('base58->encode_block(): Invalid input type ($index must be a number)');
+ }
+ if (count($data) < 1 or count($data) > self::$full_encoded_block_size) {
+ throw new Exception('base58->encode_block(): Invalid input length (1 <= count($data) <= 8)');
+ }
+ $num = self::uint8_be_to_64($data);
+ $i = self::$encoded_block_sizes[count($data)] - 1;
+ while ($num > 0) {
+ $remainder = bcmod($num, 58);
+ $num = bcdiv($num, 58);
+ $buf[$index + $i] = ord(self::$alphabet[$remainder]);
+ $i--;
+ }
+ return $buf;
+ }
+ /**
+ *
+ * Encode a hexadecimal (Base16) string to Base58
+ *
+ * @param string $hex A hexadecimal (Base16) string to convert to Base58
+ *
+ * @return string
+ *
+ */
+ public function encode($hex)
+ {
+ if (gettype($hex) != 'string') {
+ throw new Exception ('base58->encode(): Invalid input type (must be a string)');
+ }
+ $data = self::hex_to_bin($hex);
+ if (count($data) == 0) {
+ return '';
+ }
+ $full_block_count = floor(count($data) / self::$full_block_size);
+ $last_block_size = count($data) % self::$full_block_size;
+ $res_size = $full_block_count * self::$full_encoded_block_size + self::$encoded_block_sizes[$last_block_size];
+ $res = array_fill(0, $res_size, ord(self::$alphabet[0]));
+ for ($i = 0; $i < $full_block_count; $i++) {
+ $res = self::encode_block(array_slice($data, $i * self::$full_block_size, ($i * self::$full_block_size + self::$full_block_size) - ($i * self::$full_block_size)), $res, $i * self::$full_encoded_block_size);
+ }
+ if ($last_block_size > 0) {
+ $res = self::encode_block(array_slice($data, $full_block_count * self::$full_block_size, $full_block_count * self::$full_block_size + $last_block_size), $res, $full_block_count * self::$full_encoded_block_size);
+ }
+ return self::bin_to_str($res);
+ }
+ /**
+ *
+ * Convert a Base58 input to hexadecimal (Base16)
+ *
+ * @param array $data
+ * @param array $buf
+ * @param integer $index
+ *
+ * @return array
+ *
+ */
+ private function decode_block($data, $buf, $index)
+ {
+ if (gettype($data) != 'array') {
+ throw new Exception('base58->decode_block(): Invalid input type ($data must be an array)');
+ }
+ if (gettype($buf) != 'array') {
+ throw new Exception('base58->decode_block(): Invalid input type ($buf must be an array)');
+ }
+ if (gettype($index) != ('integer' || 'double')) {
+ throw new Exception('base58->decode_block(): Invalid input type ($index must be a number)');
+ }
+ $res_size = self::index_of(self::$encoded_block_sizes, count($data));
+ if ($res_size <= 0) {
+ throw new Exception('base58->decode_block(): Invalid input length ($data must be a value from base58::$encoded_block_sizes)');
+ }
+ $res_num = 0;
+ $order = 1;
+ for ($i = count($data) - 1; $i >= 0; $i--) {
+ $digit = strpos(self::$alphabet, chr($data[$i]));
+ if ($digit < 0) {
+ throw new Exception("base58->decode_block(): Invalid character ($digit \"{$digit}\" not found in base58::$alphabet)");
+ }
+ $product = bcadd(bcmul($order, $digit), $res_num);
+ if ($product > bcpow(2, 64)) {
+ throw new Exception('base58->decode_block(): Integer overflow ($product exceeds the maximum 64bit integer)');
+ }
+ $res_num = $product;
+ $order = bcmul($order, 58);
+ }
+ if ($res_size < self::$full_block_size && bcpow(2, 8 * $res_size) <= 0) {
+ throw new Exception('base58->decode_block(): Integer overflow (bcpow(2, 8 * $res_size) exceeds the maximum 64bit integer)');
+ }
+
+ $tmp_buf = self::uint64_to_8_be($res_num, $res_size);
+ for ($i = 0; $i < count($tmp_buf); $i++) {
+ $buf[$i + $index] = $tmp_buf[$i];
+ }
+ return $buf;
+ }
+ /**
+ *
+ * Decode a Base58 string to hexadecimal (Base16)
+ *
+ * @param string $hex A Base58 string to convert to hexadecimal (Base16)
+ *
+ * @return string
+ *
+ */
+ public function decode($enc)
+ {
+ if (gettype($enc) != 'string') {
+ throw new Exception ('base58->decode(): Invalid input type (must be a string)');
+ }
+ $enc = self::str_to_bin($enc);
+ if (count($enc) == 0) {
+ return '';
+ }
+ $full_block_count = floor(bcdiv(count($enc), self::$full_encoded_block_size));
+ $last_block_size = bcmod(count($enc), self::$full_encoded_block_size);
+ $last_block_decoded_size = self::index_of(self::$encoded_block_sizes, $last_block_size);
+ $data_size = $full_block_count * self::$full_block_size + $last_block_decoded_size;
+ if ($data_size == -1) {
+ return '';
+ }
+ $data = array_fill(0, $data_size, 0);
+ for ($i = 0; $i <= $full_block_count; $i++) {
+ $data = self::decode_block(array_slice($enc, $i * self::$full_encoded_block_size, ($i * self::$full_encoded_block_size + self::$full_encoded_block_size) - ($i * self::$full_encoded_block_size)), $data, $i * self::$full_block_size);
+ }
+ if ($last_block_size > 0) {
+ $data = self::decode_block(array_slice($enc, $full_block_count * self::$full_encoded_block_size, $full_block_count * self::$full_encoded_block_size + $last_block_size), $data, $full_block_count * self::$full_block_size);
+ }
+ return self::bin_to_hex($data);
+ }
+ /**
+ *
+ * Search an array for a value
+ * Source: https://stackoverflow.com/a/30994678
+ *
+ * @param array $haystack An array to search
+ * @param string $needle A string to search for
+ *)
+ * @return number The index of the element found (or -1 for no match)
+ *
+ */
+ private function index_of($haystack, $needle)
+ {
+ if (gettype($haystack) != 'array') {
+ throw new Exception ('base58->decode(): Invalid input type ($haystack must be an array)');
+ }
+ // if (gettype($needle) != 'string') {
+ // throw new Exception ('base58->decode(): Invalid input type ($needle must be a string)');
+ // }
+ foreach ($haystack as $key => $value) if ($value === $needle) return $key;
+ return -1;
+ }
}
From a29b4d00b61c937ad972702eb3436de14e45f268 Mon Sep 17 00:00:00 2001
From: SerHack <27734319+serhack@users.noreply.github.com>
Date: Wed, 19 Jun 2019 21:30:50 +0200
Subject: [PATCH 36/50] Update class-monero-base58.php
---
include/class-monero-base58.php | 1 -
1 file changed, 1 deletion(-)
diff --git a/include/class-monero-base58.php b/include/class-monero-base58.php
index 795f73c..574d337 100644
--- a/include/class-monero-base58.php
+++ b/include/class-monero-base58.php
@@ -26,7 +26,6 @@
* $decoded = $base58->decode('479cG5opa54beQWSyqNoWw5tna9sHUNmMTtiFqLPaUhDevpJ2YLwXAggSx5ePdeFrYF8cdbmVRSmp1Kn3t4Y9kFu7rZ7pFw');
*
*/
-use Exception;
class Monero_base58
{
static $alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
From 9af67ae75df499143dd849927b6cbdd394640923 Mon Sep 17 00:00:00 2001
From: SerHack <27734319+serhack@users.noreply.github.com>
Date: Wed, 19 Jun 2019 21:31:50 +0200
Subject: [PATCH 37/50] Update monero-woocommerce-gateway.php
---
monero-woocommerce-gateway.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/monero-woocommerce-gateway.php b/monero-woocommerce-gateway.php
index 95429af..1c7e3b5 100644
--- a/monero-woocommerce-gateway.php
+++ b/monero-woocommerce-gateway.php
@@ -3,7 +3,7 @@
Plugin Name: Monero Woocommerce Gateway
Plugin URI: https://github.com/monero-integrations/monerowp
Description: Extends WooCommerce by adding a Monero Gateway
-Version: 3.0.0
+Version: 3.0.1
Tested up to: 4.9.8
Author: mosu-forge, SerHack
Author URI: https://monerointegrations.com/
From a3e10ab36f7ca17cb511efe77b758374b2a2a36e Mon Sep 17 00:00:00 2001
From: SerHack <27734319+serhack@users.noreply.github.com>
Date: Sun, 30 Jun 2019 10:43:03 +0200
Subject: [PATCH 38/50] Add a error message if it is unable to fetch prices
---
include/class-monero-gateway.php | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/include/class-monero-gateway.php b/include/class-monero-gateway.php
index 8322f53..c95e281 100644
--- a/include/class-monero-gateway.php
+++ b/include/class-monero-gateway.php
@@ -1,7 +1,7 @@
query($query);
}
}
+ else{
+ self::$log->add('Monero_Payments', "[ERROR] Unable to fetch prices from cryptocompare.com.");
+ }
// Get current network/wallet height
if(self::$confirm_type == 'monero-wallet-rpc')
From 25416473eb84ae2d9085b2cf88b51ed8437519ac Mon Sep 17 00:00:00 2001
From: SerHack <27734319+serhack@users.noreply.github.com>
Date: Wed, 3 Jul 2019 10:40:26 +0200
Subject: [PATCH 39/50] Update class-monero-gateway.php
---
include/class-monero-gateway.php | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/include/class-monero-gateway.php b/include/class-monero-gateway.php
index c95e281..6d0f68d 100644
--- a/include/class-monero-gateway.php
+++ b/include/class-monero-gateway.php
@@ -87,6 +87,10 @@ class Monero_Gateway extends WC_Payment_Gateway
$explorer_url = self::$testnet ? MONERO_GATEWAY_TESTNET_EXPLORER_URL : MONERO_GATEWAY_MAINNET_EXPLORER_URL;
defined('MONERO_GATEWAY_EXPLORER_URL') || define('MONERO_GATEWAY_EXPLORER_URL', $explorer_url);
+ // Add the currency of the shop to $currencies array. Needed for do_update_event() function
+ $currency_shop = get_woocommerce_currency();
+ array_push(self::$currencies, $currency_shop);
+
if($add_action)
add_action('woocommerce_update_options_payment_gateways_'.$this->id, array($this, 'process_admin_options'));
From 009f1d0594f5380eff994002c7744d24afc5b982 Mon Sep 17 00:00:00 2001
From: SerHack <27734319+serhack@users.noreply.github.com>
Date: Sun, 5 Jan 2020 22:26:35 +0100
Subject: [PATCH 40/50] Update monero-gateway-admin-settings.php
---
include/admin/monero-gateway-admin-settings.php | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/include/admin/monero-gateway-admin-settings.php b/include/admin/monero-gateway-admin-settings.php
index 0a02d40..b0eac2f 100644
--- a/include/admin/monero-gateway-admin-settings.php
+++ b/include/admin/monero-gateway-admin-settings.php
@@ -84,6 +84,12 @@ return array(
'description' => __('Advanced usage only', 'monero_gateway'),
'default' => 'no'
),
+ 'javascript' => array(
+ 'title' => __(' Javascript', 'monero_gateway'),
+ 'label' => __(' Check this to ENABLE Javascript in Checkout page ', 'monero_gateway'),
+ 'type' => 'checkbox',
+ 'default' => 'no'
+ ),
'onion_service' => array(
'title' => __(' SSL warnings ', 'monero_gateway'),
'label' => __(' Check to Silence SSL warnings', 'monero_gateway'),
From b45b9625fb44084f50ca8fb5c4414b6ee1c325d6 Mon Sep 17 00:00:00 2001
From: SerHack <27734319+serhack@users.noreply.github.com>
Date: Wed, 18 Mar 2020 10:44:17 +0100
Subject: [PATCH 41/50] Update monero-woocommerce-gateway.php
---
monero-woocommerce-gateway.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/monero-woocommerce-gateway.php b/monero-woocommerce-gateway.php
index 1c7e3b5..1b10f4d 100644
--- a/monero-woocommerce-gateway.php
+++ b/monero-woocommerce-gateway.php
@@ -209,7 +209,7 @@ function monero_install() {
if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
$sql = "CREATE TABLE $table_name (
order_id BIGINT(20) UNSIGNED NOT NULL,
- payment_id VARCHAR(94) DEFAULT '' NOT NULL,
+ payment_id VARCHAR(95) DEFAULT '' NOT NULL,
currency VARCHAR(6) DEFAULT '' NOT NULL,
rate BIGINT UNSIGNED DEFAULT 0 NOT NULL,
amount BIGINT UNSIGNED DEFAULT 0 NOT NULL,
@@ -226,7 +226,7 @@ function monero_install() {
if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
$sql = "CREATE TABLE $table_name (
id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
- payment_id VARCHAR(94) DEFAULT '' NOT NULL,
+ payment_id VARCHAR(95) DEFAULT '' NOT NULL,
txid VARCHAR(64) DEFAULT '' NOT NULL,
amount BIGINT UNSIGNED DEFAULT 0 NOT NULL,
height MEDIUMINT UNSIGNED NOT NULL DEFAULT 0,
From 954eb92785cef79aa74e4c63614ca17ba3729cd1 Mon Sep 17 00:00:00 2001
From: xiphon
Date: Fri, 19 Jun 2020 17:21:54 +0000
Subject: [PATCH 42/50] monero-explorer-tools: explorer url - strip trailing
slashes
---
include/class-monero-explorer-tools.php | 1 +
1 file changed, 1 insertion(+)
diff --git a/include/class-monero-explorer-tools.php b/include/class-monero-explorer-tools.php
index e43b00f..8f8d2c1 100644
--- a/include/class-monero-explorer-tools.php
+++ b/include/class-monero-explorer-tools.php
@@ -19,6 +19,7 @@ class Monero_Explorer_Tools
public function __construct($testnet = false)
{
$this->url = $testnet ? MONERO_GATEWAY_TESTNET_EXPLORER_URL : MONERO_GATEWAY_MAINNET_EXPLORER_URL;
+ $this->url = preg_replace("/\/+$/", "", $this->url);
}
private function call_api($endpoint)
From 90e058baeb6883f50d9bdabc7c5c9421a5961981 Mon Sep 17 00:00:00 2001
From: xiphon
Date: Sat, 20 Jun 2020 23:55:13 +0000
Subject: [PATCH 43/50] monero-gateway: fix AJAX status updates - use
get_customer_id()
---
include/class-monero-gateway.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/class-monero-gateway.php b/include/class-monero-gateway.php
index 6d0f68d..2187d4a 100644
--- a/include/class-monero-gateway.php
+++ b/include/class-monero-gateway.php
@@ -595,7 +595,7 @@ class Monero_Gateway extends WC_Payment_Gateway
$order_id = preg_replace("/[^0-9]+/", "", $_GET['order_id']);
$order = wc_get_order( $order_id );
- if($order->user_id() != $user->ID)
+ if($order->get_customer_id() != $user->ID)
self::ajax_output(array('error' => '[ERROR] Order does not belong to this user'));
if($order->get_payment_method() != self::$_id)
From fcedf21b3046ea409d54dd5609c591ee6a643209 Mon Sep 17 00:00:00 2001
From: Cactii1 <37589158+Cactii1@users.noreply.github.com>
Date: Fri, 18 Dec 2020 05:44:11 +0100
Subject: [PATCH 44/50] Remove Extra / in URI
Fix extra / in URI that makes link to tx fail on block explorer.
---
templates/monero-gateway/admin/order-history-page.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/templates/monero-gateway/admin/order-history-page.php b/templates/monero-gateway/admin/order-history-page.php
index cfdb47a..c57719e 100644
--- a/templates/monero-gateway/admin/order-history-page.php
+++ b/templates/monero-gateway/admin/order-history-page.php
@@ -72,7 +72,7 @@