Merge pull request #37 from cryptochangements34/master
Use view-only wallet in lieu of username/password
This commit is contained in:
commit
d3aa4f0410
@ -36,7 +36,9 @@ The easiest way to find a remote node to connect to is to visit [moneroworld.com
|
||||
|
||||
* 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)
|
||||
|
||||
* Start the Wallet RPC and leave it running in the background. This can be accomplished by running `./monero-wallet-rpc --rpc-bind-port 18082 --rpc-login username:password --log-level 2 --wallet-file /path/walletfile` where "username:password" is the username and password that you want to use, seperated by a colon and "/path/walletfile" is your actual wallet file. If you wish to use a remote node you can add the `--daemon-address` flag followed by the address of the node. `--daemon-address node.moneroworld.com:18089` for example.
|
||||
* [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)
|
||||
|
||||
* Start the Wallet RPC and leave it running in the background. This can be accomplished by running `./monero-wallet-rpc --rpc-bind-port 18082 --disable-rpc-login --log-level 2 --wallet-file /path/viewOnlyWalletFile` where "/path/viewOnlyWalletFile" is the wallet file for your view-only wallet. If you wish to use a remote node you can add the `--daemon-address` flag followed by the address of the node. `--daemon-address node.moneroworld.com:18089` for example.
|
||||
|
||||
## Step 4: Setup Monero Gateway in WooCommerce
|
||||
|
||||
@ -58,8 +60,5 @@ The easiest way to find a remote node to connect to is to visit [moneroworld.com
|
||||
|
||||
* Click on "Save changes"
|
||||
|
||||
## Info on server authentication
|
||||
It is reccommended that you specify a username/password with your wallet rpc. This can be done by starting your wallet rpc with `monero-wallet-rpc --rpc-bind-port 18082 --rpc-login username:password --wallet-file /path/walletfile` where "username:password" is the username and password that you want to use, seperated by a colon. Alternatively, you can use the `--restricted-rpc` flag with the wallet rpc like so `./monero-wallet-rpc --testnet --rpc-bind-port 18082 --restricted-rpc --wallet-file wallet/path`.
|
||||
|
||||
## Donating Me
|
||||
## Donating to the Devs :)
|
||||
XMR Address : `44krVcL6TPkANjpFwS2GWvg1kJhTrN7y9heVeQiDJ3rP8iGbCd5GeA4f3c2NKYHC1R4mCgnW7dsUUUae2m9GiNBGT4T8s2X`
|
||||
|
@ -30,8 +30,6 @@ class Monero_Gateway extends WC_Payment_Gateway
|
||||
$this->host = $this->get_option('daemon_host');
|
||||
$this->port = $this->get_option('daemon_port');
|
||||
$this->address = $this->get_option('monero_address');
|
||||
$this->username = $this->get_option('username');
|
||||
$this->password = $this->get_option('password');
|
||||
$this->discount = $this->get_option('discount');
|
||||
|
||||
// After init_settings() is called, you can get the settings and load them into variables, e.g:
|
||||
@ -53,7 +51,7 @@ class Monero_Gateway extends WC_Payment_Gateway
|
||||
add_filter('woocommerce_currency_symbol', 'add_my_currency_symbol', 10, 2);
|
||||
add_action('woocommerce_email_before_order_table', array($this, 'email_instructions'), 10, 2);
|
||||
}
|
||||
$this->monero_daemon = new Monero_Library($this->host . ':' . $this->port . '/json_rpc', $this->username, $this->password);
|
||||
$this->monero_daemon = new Monero_Library($this->host, $this->port);
|
||||
}
|
||||
|
||||
public function init_form_fields()
|
||||
@ -97,21 +95,6 @@ class Monero_Gateway extends WC_Payment_Gateway
|
||||
'desc_tip' => __('This is the Daemon Host/IP to authorize the payment with port', 'monero_gateway'),
|
||||
'default' => '18080',
|
||||
),
|
||||
'username' => array(
|
||||
'title' => __('Monero Wallet username', 'monero_gateway'),
|
||||
'desc_tip' => __('This is the username that you used with your monero wallet-rpc', 'monero_gateway'),
|
||||
'type' => __('text'),
|
||||
'default' => __('username', 'monero_gateway'),
|
||||
|
||||
),
|
||||
'password' => array(
|
||||
'title' => __('Monero wallet RPC password', 'monero_gateway'),
|
||||
'desc_tip' => __('This is the password that you used with your monero wallet-rpc', 'monero_gateway'),
|
||||
'description' => __('you can leave these fields empty if you did not set', 'monero_gateway'),
|
||||
'type' => __('text'),
|
||||
'default' => ''
|
||||
|
||||
),
|
||||
'discount' => array(
|
||||
'title' => __('% discount for using XMR', 'monero_gateway'),
|
||||
|
||||
@ -122,15 +105,15 @@ class Monero_Gateway extends WC_Payment_Gateway
|
||||
|
||||
),
|
||||
'environment' => array(
|
||||
'title' => __(' Test Mode', 'monero_gateway'),
|
||||
'label' => __('Enable Test Mode', 'monero_gateway'),
|
||||
'title' => __(' Testnet', 'monero_gateway'),
|
||||
'label' => __(' Check this if you are using testnet ', 'monero_gateway'),
|
||||
'type' => 'checkbox',
|
||||
'description' => __('Check this box if you are using testnet', 'monero_gateway'),
|
||||
'default' => 'no'
|
||||
),
|
||||
'onion_service' => array(
|
||||
'title' => __(' Onion Service', 'monero_gateway'),
|
||||
'label' => __('Enable Onion Service', 'monero_gateway'),
|
||||
'title' => __(' SSL warnings ', 'monero_gateway'),
|
||||
'label' => __(' Check to Silence SSL warnings', 'monero_gateway'),
|
||||
'type' => 'checkbox',
|
||||
'description' => __('Check this box if you are running on an Onion Service (Suppress SSL errors)', 'monero_gateway'),
|
||||
'default' => 'no'
|
||||
@ -174,10 +157,12 @@ class Monero_Gateway extends WC_Payment_Gateway
|
||||
{
|
||||
$wallet_amount = $this->monero_daemon->getbalance();
|
||||
if (!isset($wallet_amount)) {
|
||||
$this->log->add('Monero_gateway', '[ERROR] No connection with daemon');
|
||||
$wallet_amount['balance'] = "0";
|
||||
$wallet_amount['unlocked_balance'] = "0";
|
||||
$this->log->add('Monero_gateway', '[ERROR] Can not connect to monero-wallet-rpc');
|
||||
echo "</br>Your balance is: Not Avaliable </br>";
|
||||
echo "Unlocked balance: Not Avaliable";
|
||||
}
|
||||
else
|
||||
{
|
||||
$real_wallet_amount = $wallet_amount['balance'] / 1000000000000;
|
||||
$real_amount_rounded = round($real_wallet_amount, 6);
|
||||
|
||||
@ -187,6 +172,7 @@ class Monero_Gateway extends WC_Payment_Gateway
|
||||
echo "Your balance is: " . $real_amount_rounded . " XMR </br>";
|
||||
echo "Unlocked balance: " . $unlocked_amount_rounded . " XMR </br>";
|
||||
}
|
||||
}
|
||||
|
||||
public function process_payment($order_id)
|
||||
{
|
||||
@ -243,7 +229,7 @@ class Monero_Gateway extends WC_Payment_Gateway
|
||||
$uri = "monero:$address?amount=$amount?payment_id=$payment_id";
|
||||
$array_integrated_address = $this->monero_daemon->make_integrated_address($payment_id);
|
||||
if (!isset($array_integrated_address)) {
|
||||
$this->log->add('Monero_Gateway', '[ERROR] Unable to getting integrated address');
|
||||
$this->log->add('Monero_Gateway', '[ERROR] Unable get integrated address');
|
||||
// Seems that we can't connect with daemon, then set array_integrated_address, little hack
|
||||
$array_integrated_address["integrated_address"] = $address;
|
||||
}
|
||||
@ -344,7 +330,8 @@ class Monero_Gateway extends WC_Payment_Gateway
|
||||
$stored_rate_transformed = $stored_rate[0]->rate / 100; //this will turn the stored rate back into a decimaled number
|
||||
|
||||
if (isset($this->discount)) {
|
||||
$discount_decimal = $this->discount / 100;
|
||||
$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;
|
||||
|
@ -9,7 +9,6 @@
|
||||
* @author Kacper Rowinski <krowinski@implix.com>
|
||||
* http://implix.com
|
||||
* Modified to work with monero-rpc wallet by Serhack and cryptochangements
|
||||
* This code isn't for Dark Net Markets, please report them to Authority!
|
||||
*/
|
||||
class Monero_Library
|
||||
{
|
||||
@ -18,8 +17,8 @@ class Monero_Library
|
||||
CURLOPT_CONNECTTIMEOUT => 8,
|
||||
CURLOPT_TIMEOUT => 8
|
||||
);
|
||||
private $username;
|
||||
private $password;
|
||||
protected $host;
|
||||
protected $port;
|
||||
private $httpErrors = array(
|
||||
400 => '400 Bad Request',
|
||||
401 => '401 Unauthorized',
|
||||
@ -33,14 +32,14 @@ class Monero_Library
|
||||
503 => '503 Service Unavailable'
|
||||
);
|
||||
|
||||
public function __construct($pUrl, $pUser, $pPass)
|
||||
public function __construct($pHost, $pPort)
|
||||
{
|
||||
$this->validate(false === extension_loaded('curl'), 'The curl extension must be loaded to use this class!');
|
||||
$this->validate(false === extension_loaded('json'), 'The json extension must be loaded to use this class!');
|
||||
|
||||
$this->url = $pUrl;
|
||||
$this->username = $pUser;
|
||||
$this->password = $pPass;
|
||||
$this->host = $pHost;
|
||||
$this->port = $pPort;
|
||||
$this->url = $pHost . ':' . $pPort . '/json_rpc';
|
||||
}
|
||||
|
||||
public function validate($pFailed, $pErrMsg)
|
||||
@ -166,8 +165,6 @@ class Monero_Library
|
||||
throw new RuntimeException('Could\'t initialize a cURL session');
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_URL, $this->url);
|
||||
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
|
||||
curl_setopt($ch, CURLOPT_USERPWD, $this->username . ":" . $this->password);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $pRequest);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
|
||||
@ -187,7 +184,7 @@ class Monero_Library
|
||||
}
|
||||
// check for curl error
|
||||
if (0 < curl_errno($ch)) {
|
||||
echo 'Unable to connect to ' . $this->url . ' Error: ' . curl_error($ch);
|
||||
echo '[ERROR] Failed to connect to monero-wallet-rpc at ' . $this->host . ' port '. $this->port .'</br>';
|
||||
}
|
||||
// close the connection
|
||||
curl_close($ch);
|
||||
|
Loading…
Reference in New Issue
Block a user