Remove password fields, a view-only wallet should instead be used. Improve some of the text.
This commit is contained in:
cryptochangements34 2017-12-27 18:44:13 -06:00 committed by GitHub
parent f561d4badf
commit 76602ebc3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -30,8 +30,6 @@ class Monero_Gateway extends WC_Payment_Gateway
$this->host = $this->get_option('daemon_host'); $this->host = $this->get_option('daemon_host');
$this->port = $this->get_option('daemon_port'); $this->port = $this->get_option('daemon_port');
$this->address = $this->get_option('monero_address'); $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'); $this->discount = $this->get_option('discount');
// After init_settings() is called, you can get the settings and load them into variables, e.g: // 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_filter('woocommerce_currency_symbol', 'add_my_currency_symbol', 10, 2);
add_action('woocommerce_email_before_order_table', array($this, 'email_instructions'), 10, 2); add_action('woocommerce_email_before_order_table', array($this, 'email_instructions'), 10, 2);
} }
$this->monero_daemon = new Monero_Library($this->host . ':' . $this->port . '/json_rpc', $this->username, $this->password); $this->monero_daemon = new Monero_Library($this->host, $this->port);
} }
public function init_form_fields() 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'), 'desc_tip' => __('This is the Daemon Host/IP to authorize the payment with port', 'monero_gateway'),
'default' => '18080', '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( 'discount' => array(
'title' => __('% discount for using XMR', 'monero_gateway'), 'title' => __('% discount for using XMR', 'monero_gateway'),
@ -122,15 +105,15 @@ class Monero_Gateway extends WC_Payment_Gateway
), ),
'environment' => array( 'environment' => array(
'title' => __(' Test Mode', 'monero_gateway'), 'title' => __(' Testnet', 'monero_gateway'),
'label' => __('Enable Test Mode', 'monero_gateway'), 'label' => __(' Check this if you are using testnet ', 'monero_gateway'),
'type' => 'checkbox', 'type' => 'checkbox',
'description' => __('Check this box if you are using testnet', 'monero_gateway'), 'description' => __('Check this box if you are using testnet', 'monero_gateway'),
'default' => 'no' 'default' => 'no'
), ),
'onion_service' => array( 'onion_service' => array(
'title' => __(' Onion Service', 'monero_gateway'), 'title' => __(' SSL warnings ', 'monero_gateway'),
'label' => __('Enable Onion Service', 'monero_gateway'), 'label' => __(' Check to Silence SSL warnings', 'monero_gateway'),
'type' => 'checkbox', 'type' => 'checkbox',
'description' => __('Check this box if you are running on an Onion Service (Suppress SSL errors)', 'monero_gateway'), 'description' => __('Check this box if you are running on an Onion Service (Suppress SSL errors)', 'monero_gateway'),
'default' => 'no' 'default' => 'no'
@ -174,10 +157,12 @@ class Monero_Gateway extends WC_Payment_Gateway
{ {
$wallet_amount = $this->monero_daemon->getbalance(); $wallet_amount = $this->monero_daemon->getbalance();
if (!isset($wallet_amount)) { if (!isset($wallet_amount)) {
$this->log->add('Monero_gateway', '[ERROR] No connection with daemon'); $this->log->add('Monero_gateway', '[ERROR] Can not connect to monero-wallet-rpc');
$wallet_amount['balance'] = "0"; echo "</br>Your balance is: Not Avaliable </br>";
$wallet_amount['unlocked_balance'] = "0"; echo "Unlocked balance: Not Avaliable";
} }
else
{
$real_wallet_amount = $wallet_amount['balance'] / 1000000000000; $real_wallet_amount = $wallet_amount['balance'] / 1000000000000;
$real_amount_rounded = round($real_wallet_amount, 6); $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 "Your balance is: " . $real_amount_rounded . " XMR </br>";
echo "Unlocked balance: " . $unlocked_amount_rounded . " XMR </br>"; echo "Unlocked balance: " . $unlocked_amount_rounded . " XMR </br>";
} }
}
public function process_payment($order_id) 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"; $uri = "monero:$address?amount=$amount?payment_id=$payment_id";
$array_integrated_address = $this->monero_daemon->make_integrated_address($payment_id); $array_integrated_address = $this->monero_daemon->make_integrated_address($payment_id);
if (!isset($array_integrated_address)) { 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 // Seems that we can't connect with daemon, then set array_integrated_address, little hack
$array_integrated_address["integrated_address"] = $address; $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 $stored_rate_transformed = $stored_rate[0]->rate / 100; //this will turn the stored rate back into a decimaled number
if (isset($this->discount)) { 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; $new_amount = $amount / $stored_rate_transformed;
$discount = $new_amount * $discount_decimal; $discount = $new_amount * $discount_decimal;
$final_amount = $new_amount - $discount; $final_amount = $new_amount - $discount;