Skip to content

Commit

Permalink
Merge pull request #7 from tittuvarghese/master
Browse files Browse the repository at this point in the history
Modified Readme and Fixed variable reference issue
  • Loading branch information
serhack authored Mar 14, 2018
2 parents 9ca18be + 69f66b4 commit a9fad32
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 67 deletions.
51 changes: 47 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,51 @@
# monerops
Monero Prestashop addon
# MoneroPS
A Prestashop addon for accepting Monero (XMR)

Compatible with the stable version of Prestashop (1.6.x). And working on 1.7.x

## Dependancies
This plugin is rather simple but there are a few things that need to be set up before hand.

* 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/)

* [Prestashop](https://prestashop.com)
Prestashop is open source e-commerce engine to run your own shop and this Monero addon

## Step 1: Activating the plugin
* Downloading: First of all, you will need to download the module. You can download the latest release as a .zip file from https://github.com/monero-integrations/monerops If you wish, you can also download the latest source code from GitHub. This can be done with the command `git clone https://github.com/monero-integrations/monerops.git` or can be downloaded as a zip file from the GitHub web page.

* Unzip the file monerops-master.zip if you downloaded the zip from the master page [here](https://github.com/monero-integrations/monerops).

* Upload the module and activate it. You can refer the official documentation [here](https://addons.prestashop.com/en/content/21-how-to)

## Step 2 : Use your wallet address and connect to an monero daemon

### 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.
You can refer the official documentation for running full node from [here](https://github.com/monero-project/monero).

### 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.

`Note: You must run your JSON RPC on the host server of Prestashop against your wallet`

### 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 [https://github.com/monero-project/monero](https://github.com/monero-project/monero)
You can checkout the monero wallet commands from [here](https://github.com/monero-project/monero/wiki/monero-wallet-cli-commands)


* Start the Wallet RPC and leave it running in the background. This can be accomplished by running `monero-wallet-rpc --wallet-file /path/to/wallet/file --password walletPassword --rpc-bind-port 18082 --disable-rpc-login` where "/path/to/wallet/file" is the wallet file for your monero 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 Prestashop
* Navigate to the "Modules and Services" panel in the Prestashop sidebar and identify `Monero Payments` module and click on `configure`.
* Update `Monero Wallet Address` and `Wallet RPC IP/HOST`
* Note: Wallet RPC IP should start with the protocol and end with port address. `Eg. http://127.0.0.1:18082`
* Save the changes and you are good to go.

Compatible with the latest version of Prestashop (1.6.x).
I'm working on 1.7.x update

## Donating Me
XMR Address : `44krVcL6TPkANjpFwS2GWvg1kJhTrN7y9heVeQiDJ3rP8iGbCd5GeA4f3c2NKYHC1R4mCgnW7dsUUUae2m9GiNBGT4T8s2X`
48 changes: 25 additions & 23 deletions modules/monero/controllers/front/payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,37 @@ class moneropaymentModuleFrontController extends ModuleFrontController
* @see FrontController::initContent()
*/
private $monero_daemon;

public function initContent() {
parent::initContent();

global $currency;
$cart = $this->context->cart;
$c = $currency->iso_code;
$total = $cart->getOrderTotal();
$amount = $this->changeto($total, $c);
$actual = $this->retriveprice($c);
$payment_id = $this->set_paymentid_cookie();

$address = Configuration::get('MONERO_ADDRESS');
$daemon_address = Configuration::get('MONERO_WALLET');

$uri = "monero:$address?tx_amount=$amount?tx_payment_id=$payment_id";
$status = "Awaiting Confirmation...";

$address = Configuration::get('MONERO_ADDRESS');
$daemon_address = Configuration::get('MONERO_WALLET');

$this->monero_daemon = new Monero_Library('http://'. $daemon_address .'/json_rpc'); // example $daemon address 127.0.0.1:18081



$this->monero_daemon = new Monero_Library($daemon_address .'/json_rpc',"",""); // example $daemon address 127.0.0.1:18081

$integrated_address_method = $this->monero_daemon->make_integrated_address($payment_id);
$integrated_address = $integrated_address_method["integrated_address"];

if($this->verify_payment($payment_id, $amount))
{
$status = "Your Payment has been confirmed!";
header("Location: index.php?fc=module&module=monero&controller=validation");

}

$this->context->smarty->assign(array(
'this_path_ssl' => Tools::getShopDomainSsl(true, true) . __PS_BASE_URI__ . 'modules/' . $this->module->name . '/',
'address' => $address,
Expand All @@ -45,30 +47,30 @@ public function initContent() {
'status' => $status,
'integrated_address' => $integrated_address ));
$this->setTemplate('payment_execution.tpl');

echo "<script type='text/javascript'>
setTimeout(function () { location.reload(true); }, 30000);
</script>";
}


private function set_paymentid_cookie()
{
if(!isset($_COOKIE['payment_id']))
{
{
$payment_id = bin2hex(openssl_random_pseudo_bytes(8));
setcookie('payment_id', $payment_id, time()+2700);
}
else
$payment_id = $_COOKIE['payment_id'];
return $payment_id;
}

public function retriveprice($c)
{
$xmr_price = Tools::file_get_contents('https://min-api.cryptocompare.com/data/price?fsym=XMR&tsyms=BTC,USD,EUR,CAD,INR,GBP&extraParams=monero_woocommerce');
$price = json_decode($xmr_price, TRUE);

if ($c== 'USD') {
return $price['USD'];
}
Expand All @@ -88,36 +90,36 @@ public function retriveprice($c)
//return $price['USD'];
}
}

public function changeto($amount, $currency)
{
$xmr_live_price = $this->retriveprice($currency);
$new_amount = $amount / $xmr_live_price;
$rounded_amount = round($new_amount, 12); //the moneo wallet can't handle decimals smaller than 0.000000000001
return $rounded_amount;
}

public function verify_payment($payment_id, $amount)
{
/*
/*
* function for verifying payments
* Check if a payment has been made with this payment id then notify the merchant
*/

$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)
{
$confirmed = true;
}
}
}
else
{
$confirmed = false;
}
return $confirmed;
}

}
Loading

0 comments on commit a9fad32

Please sign in to comment.