Adds support for integrated addresses

Replaces old "regular address + legacy payment id" system with integrated addresses to make payments much simpler for the buyer.
This commit is contained in:
cryptochangements34 2017-07-16 23:44:15 -05:00 committed by GitHub
parent 43fa730ca0
commit bf46a1e735

View File

@ -3,7 +3,16 @@
class Monero_Gateway extends WC_Payment_Gateway 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;
}
function __construct() function __construct()
{ {
@ -53,6 +62,7 @@ class Monero_Gateway extends WC_Payment_Gateway
'process_admin_options' 'process_admin_options'
)); ));
} }
$this->monero_daemon = new jsonRPCClient($this->host . ':' . $this->port . '/json_rpc');
} }
public function admin_options() public function admin_options()
@ -180,6 +190,12 @@ class Monero_Gateway extends WC_Payment_Gateway
return false; 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) public function instruction($order_id)
{ {
@ -188,8 +204,9 @@ class Monero_Gateway extends WC_Payment_Gateway
$currency = $order->currency; $currency = $order->currency;
$amount_xmr2 = $this->changeto($amount, $currency); $amount_xmr2 = $this->changeto($amount, $currency);
$address = $this->address; $address = $this->address;
$payment_id = bin2hex(openssl_random_pseudo_bytes(32)); $payment_id = bin2hex(openssl_random_pseudo_bytes(8));
$uri = "monero:$address?amount=$amount?payment_id=$payment_id"; $uri = "monero:$address?amount=$amount?payment_id=$payment_id";
$array_integrated_address = $this->make_integrated_address($payment_id);
// Generate a QR code // Generate a QR code
echo "<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'>"; echo "<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'>";
@ -206,9 +223,8 @@ class Monero_Gateway extends WC_Payment_Gateway
<img src='https://chart.googleapis.com/chart?cht=qr&chs=150x150&chl=" . $uri . "' class='img-responsive'> <img src='https://chart.googleapis.com/chart?cht=qr&chs=150x150&chl=" . $uri . "' class='img-responsive'>
</div> </div>
<div class='col-sm-9 col-md-9 col-lg-9' style='padding:10px;'> <div class='col-sm-9 col-md-9 col-lg-9' style='padding:10px;'>
Send <b>" . $amount_xmr2 . " XMR</b> to<br/><input type='text' class='form-control' value='" . $this->address . "'> Send <b>" . $amount_xmr2 . " XMR</b> to<br/><input type='text' class='form-control' value='" . $array_integrated_address["integrated_address"] . "'>
or scan QR Code with your mobile device<br/><br/> or scan QR Code with your mobile device<br/><br/>
<input type='text' value='" . $payment_id . "'>
<small>If you don't know how to pay with monero, click instructions button. </small> <small>If you don't know how to pay with monero, click instructions button. </small>
</div> </div>
<div class='col-sm-12 col-md-12 col-lg-12'> <div class='col-sm-12 col-md-12 col-lg-12'>
@ -274,7 +290,7 @@ class Monero_Gateway extends WC_Payment_Gateway
public function verify_payment(){ public function verify_payment(){
/* /*
* function for verifying payments * fucntion for verifying payments
* 1. Get the latest block height available * 1. Get the latest block height available
* 2. Get_Bulk_payments with the first payment id generated * 2. Get_Bulk_payments with the first payment id generated
* 3. Verify that a payment has been made with the given payment id * 3. Verify that a payment has been made with the given payment id
@ -310,5 +326,4 @@ class Monero_Gateway extends WC_Payment_Gateway
} }
} }