From f0b6391aa01ede3deec0b5cb0a8f92c857c120c1 Mon Sep 17 00:00:00 2001 From: cryptochangements34 Date: Sun, 16 Jul 2017 23:27:20 -0500 Subject: [PATCH 1/6] Translates some commenting from Italien to English Translates some of serhack's comments to English so that they can be read by others easier. --- monero/include/monero_payments.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/monero/include/monero_payments.php b/monero/include/monero_payments.php index 7006b50..99d6cff 100644 --- a/monero/include/monero_payments.php +++ b/monero/include/monero_payments.php @@ -276,10 +276,10 @@ class Monero_Gateway extends WC_Payment_Gateway public function verify_payment(){ /* - * Algoritmo per verificare i pagamenti - * 1. prendi l'ultima height disponibile - * 2. Get_Bulk_payments con il payment id generato prima (visualizzare a video un avviso per cui l'utente non dovrà aggiornare) - * 3. Verifica se esiste un pagamento con il payment id e se l'amount è aumentato (NOTA: Non serve verificare quanto è aumentato, il payment id è unico) + * function for verifying payments + * 1. Get the latest block height available + * 2. Get_Bulk_payments with the first payment id generated + * 3. Verify that a payment has been made with the given payment id * From 0048b818099d31763b9ad688ff408117b40d3533 Mon Sep 17 00:00:00 2001 From: cryptochangements34 Date: Sun, 16 Jul 2017 23:29:16 -0500 Subject: [PATCH 2/6] Revises "Paying with Monero" Message --- monero/include/monero_payments.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/monero/include/monero_payments.php b/monero/include/monero_payments.php index 99d6cff..b327da4 100644 --- a/monero/include/monero_payments.php +++ b/monero/include/monero_payments.php @@ -232,10 +232,8 @@ class Monero_Gateway extends WC_Payment_Gateway
- Send " . $amount_xmr2 . " XMR to
+ Send " . $amount_xmr2 . " XMR to
or scan QR Code with your mobile device

- If you don't know how to pay with monero, click instructions button.
@@ -274,7 +290,7 @@ class Monero_Gateway extends WC_Payment_Gateway public function verify_payment(){ /* - * function for verifying payments + * fucntion for verifying payments * 1. Get the latest block height available * 2. Get_Bulk_payments with the first payment id generated * 3. Verify that a payment has been made with the given payment id @@ -309,6 +325,5 @@ class Monero_Gateway extends WC_Payment_Gateway } - - + } From f835a9e771b89622134ac8ba068d27229b5bce62 Mon Sep 17 00:00:00 2001 From: cryptochangements34 Date: Mon, 17 Jul 2017 16:25:34 -0500 Subject: [PATCH 5/6] Updates library.php to support more functions Updates library.php to have the full capability of https://github.com/monero-integrations/monerophp --- monero/library.php | 123 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 120 insertions(+), 3 deletions(-) diff --git a/monero/library.php b/monero/library.php index 46ab115..fb0ec80 100644 --- a/monero/library.php +++ b/monero/library.php @@ -9,10 +9,9 @@ * http://implix.com * Modified to work with monero-rpc wallet by Serhack and cryptochangements */ -class jsonRPCClient +class Monero_Library { protected $url = null, $is_debug = false, $parameters_structure = 'array'; - protected $curl_options = array( CURLOPT_CONNECTTIMEOUT => 8, CURLOPT_TIMEOUT => 8 @@ -77,7 +76,7 @@ class jsonRPCClient return $this; } - public function _run($pMethod, $pParams) + private function request($pMethod, $pParams) { static $requestId = 0; // generating uniuqe id per process @@ -217,4 +216,122 @@ class jsonRPCClient } } + 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 + * 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 + */ + + public function address() + { + $address = $this->_run('getaddress'); + return $address; + } + + public function getbalance() + { + $balance = $this->_run('getbalance'); + return $balance; + } + + public function getheight() + { + $height = $this->_run('getheight'); + return $height; + } + + public function incoming_transfer($type) + { + $incoming_parameters = array('transfer_type' => $type); + $incoming_transfers = $this->_run('incoming_transfers', $incoming_parameters); + 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'); + $query_key_method = $this->_run('query_key', $query_key); + 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) + { + $integrate_address_parameters = array('payment_id' => $payment_id); + $integrate_address_method = $this->_run('make_integrated_address', $integrate_address_parameters); + return $integrate_address_method; + } + + public function split_integrated_address($integrated_address) + { + if(!isset($integrated_address)){ + echo "Error: Integrated_Address mustn't be null"; + } + else{ + $split_params = array('integrated_address' => $integrated_address); + $split_methods = $this->_run('split_integrated_address', $split_params); + return $split_methods; + } + } + + public function make_uri($address, $amount, $recipient_name = null, $description = null) + { + // If I pass 1, it will be 0.0000001 xmr. Then + $new_amount = $amount * 100000000; + + $uri_params = array('address' => $address, 'amount' => $new_amount, 'payment_id' => '', 'recipient_name' => $recipient_name, 'tx_description' => $description); + $uri = $this->_run('make_uri', $uri_params); + return $uri; + } + + public function parse_uri($uri) + { + $uri_parameters = array('uri' => $uri); + $parsed_uri = $this->_run('parse_uri', $uri_parameters); + return $parsed_uri; + } + + public function transfer($amount, $address, $mixin = 4) + { + $new_amount = $amount * 1000000000000; + $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_method = $this->_run('transfer', $transfer_parameters); + return $transfer_method; + } + + public function get_payments($payment_id) + { + $get_payments_parameters = array('payment_id' => $payment_id); + $get_payments = $this->_run('get_payments', $get_payments_parameters); + return $get_payments; + } + + 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 = $this->_run('get_bulk_payments', $get_bulk_payments_parameters); + return $get_bulk_payments; + } } From f67eb9afbd4a4a77fd58526ddde9dd9d3e18de8a Mon Sep 17 00:00:00 2001 From: cryptochangements34 Date: Mon, 17 Jul 2017 16:28:09 -0500 Subject: [PATCH 6/6] Updates this to work with updated library class --- monero/include/monero_payments.php | 38 ++++++++++-------------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/monero/include/monero_payments.php b/monero/include/monero_payments.php index 066ffb4..4954505 100644 --- a/monero/include/monero_payments.php +++ b/monero/include/monero_payments.php @@ -3,16 +3,8 @@ class Monero_Gateway extends WC_Payment_Gateway { - private $monero_daemon; - - private function _run($method,$params = null) { - $result = $this->monero_daemon->_run($method, $params); - return $result; - } - private function _print($json){ - $json_encoded = json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); - echo $json_encoded; - } + private $monero_daemon; + function __construct() { @@ -62,7 +54,7 @@ class Monero_Gateway extends WC_Payment_Gateway 'process_admin_options' )); } - $this->monero_daemon = new jsonRPCClient($this->host . ':' . $this->port . '/json_rpc'); + $this->monero_daemon = new Monero_Library($this->host . ':' . $this->port . '/json_rpc'); } public function admin_options() @@ -146,7 +138,8 @@ class Monero_Gateway extends WC_Payment_Gateway { $xmr_live_price = $this->retriveprice($currency); $new_amount = $amount / $xmr_live_price; - return $new_amount; + $rounded_amount = round($new_amount, 12); //the moneo wallet can't handle decimals smaller than 0.000000000001 + return $rounded_amount; } @@ -188,15 +181,8 @@ class Monero_Gateway extends WC_Payment_Gateway return true; } return false; - } + } - public function make_integrated_address($payment_id) - { - $integrate_address_parameters = array('payment_id' => $payment_id); - $integrate_address_method = $this->_run('make_integrated_address', $integrate_address_parameters); - return $integrate_address_method; - } - public function instruction($order_id) { $order = wc_get_order($order_id); @@ -206,7 +192,8 @@ class Monero_Gateway extends WC_Payment_Gateway $address = $this->address; $payment_id = bin2hex(openssl_random_pseudo_bytes(8)); $uri = "monero:$address?amount=$amount?payment_id=$payment_id"; - $array_integrated_address = $this->make_integrated_address($payment_id); + $array_integrated_address = $this->monero_daemon->make_integrated_address($payment_id); + // Generate a QR code echo ""; @@ -223,7 +210,7 @@ class Monero_Gateway extends WC_Payment_Gateway
- Send " . $amount_xmr2 . " XMR to
+ Send " . $amount_xmr2 . " XMR to
or scan QR Code with your mobile device

If you don't know how to pay with monero, click instructions button.
@@ -256,8 +243,7 @@ class Monero_Gateway extends WC_Payment_Gateway - - "; + "; } @@ -324,6 +310,6 @@ class Monero_Gateway extends WC_Payment_Gateway }*/ - } - + } + }