Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bonus credits, bug fixes #31

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions modules/addons/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
if (!defined("WHMCS"))
die("This file cannot be accessed directly");

use Illuminate\Database\Capsule\Manager as Capsule;
use WHMCS\Database\Capsule as Capsule;

// skip checking for fraud order
function moneroEnable ( $vars ) {
$opt1 = Capsule::select("SELECT `value` FROM tbladdonmodules WHERE module = 'moneroEnable' AND setting = 'option1' LIMIT 1")[0]->value;
$opt2 = Capsule::select("SELECT `value` FROM tbladdonmodules WHERE module = 'moneroEnable' AND setting = 'option2' LIMIT 1")[0]->value;
if($opt1 == 'on' && $opt2 > '' && $vars['orderid'] > '') {
$pmtMet = Capsule::select("SELECT paymentmethod FROM tblorders WHERE id = ".$vars['orderid'])[0]->paymentmethod;
if($pmtMet > '') {
if($pmtMet == $opt2) return true;
$option1 = Capsule::select("SELECT `value` FROM tbladdonmodules WHERE module = 'moneroEnable' AND setting = 'option1' LIMIT 1")[0]->value;
$option2 = Capsule::select("SELECT `value` FROM tbladdonmodules WHERE module = 'moneroEnable' AND setting = 'option2' LIMIT 1")[0]->value;
if($option1 == 'on' && $option2 > '' && $vars['orderid'] > '') {
$paymentMethod = Capsule::select("SELECT paymentmethod FROM tblorders WHERE id = ".$vars['orderid'])[0]->paymentmethod;
if($paymentMethod > '') {
if($paymentMethod == $option2) return true;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion modules/addons/moneroenable.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use Illuminate\Database\Capsule\Manager as Capsule;
use WHMCS\Database\Capsule as Capsule;


function moneroEnable_config () {
Expand Down
43 changes: 17 additions & 26 deletions modules/gateways/monero.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
if (!defined("WHMCS")) {
die("This file cannot be accessed directly");
}


use WHMCS\Database\Capsule as Capsule;

function monero_MetaData()
{
Expand All @@ -14,6 +13,7 @@ function monero_MetaData()
'TokenisedStorage' => false,
);
}

function monero_Config(){
return array(
'FriendlyName' => array('Type' => 'System','Value' => 'Monero'),
Expand All @@ -23,26 +23,17 @@ function monero_Config(){
'daemon_port' => array('FriendlyName' => 'Wallet RPC Port','Type' => 'text','Default' => '18081','Description' => ''),
'daemon_user' => array('FriendlyName' => 'Wallet RPC Username','Type' => 'text','Default' => '','Description' => ''),
'daemon_pass' => array('FriendlyName' => 'Wallet RPC Password','Type' => 'text','Default' => '','Description' => ''),
'discount_percentage' => array('FriendlyName' => 'Discount Percentage','Type' => 'text','Default' => '0%','Description' => 'Percentage discount for paying with Monero.')
'bonus_percentage' => array('FriendlyName' => 'Bonus Percentage','Type' => 'text','Default' => '5%','Description' => 'Percentage Bonus for paying with Monero. Applied to clients Credit Balance.')
);
}

/*
*
* Get the current XMR price in several currencies
*
* @param String $currencies List of currency codes separated by comma
*
* @return String A json string in the format {"CURRENCY_CODE":PRICE}
*
*/
function monero_retrivePriceList($currencies = 'BTC,USD,EUR,CAD,INR,GBP,BRL') {

$source = 'https://min-api.cryptocompare.com/data/price?fsym=XMR&tsyms='.$currencies.'&extraParams=monero_woocommerce';

if (ini_get('allow_url_fopen')) {

return file_get_contents($source);
return @file_get_contents($source);

}

Expand Down Expand Up @@ -90,19 +81,19 @@ function monero_retriveprice($currency) {
return $price['USD'];
}
if ($currency == 'EUR') {
$currency_symbol = "";
$currency_symbol = "â¬";
return $price['EUR'];
}
if ($currency == 'CAD'){
$currency_symbol = "$";
return $price['CAD'];
}
if ($currency == 'GBP'){
$currency_symbol = "£";
$currency_symbol = "£";
return $price['GBP'];
}
if ($currency == 'INR'){
$currency_symbol = "";
$currency_symbol = "â¹";
return $price['INR'];
}
if ($currency == 'BRL'){
Expand Down Expand Up @@ -131,10 +122,8 @@ function xmr_to_fiat($amount, $currency){
return $rounded_amount;
}



function monero_link($params){
global $currency_symbol;
$currency_symbol = '';

$gatewaymodule = "monero";
$gateway = getGatewayVariables($gatewaymodule);
Expand All @@ -143,10 +132,12 @@ function monero_link($params){

$invoiceid = $params['invoiceid'];
$amount = $params['amount'];
$discount_setting = $gateway['discount_percentage'];
$discount_percentage = 100 - (preg_replace("/[^0-9]/", "", $discount_setting));
$amount = money_format('%i', $amount * ($discount_percentage / 100));

$bonus_setting = $gateway['bonus_percentage'];
$bonus_percentage = preg_replace("/[^0-9]/", "", $bonus_setting);
$amount = number_format($amount * (1 + $bonus_percentage / 100), 2, '.', '');
$currency = $params['currency'];
$client_id = $params['clientdetails']['id'];
$firstname = $params['clientdetails']['firstname'];
$lastname = $params['clientdetails']['lastname'];
$email = $params['clientdetails']['email'];
Expand All @@ -158,7 +149,6 @@ function monero_link($params){
$systemurl = $params['systemurl'];
// Transform Current Currency into Monero
$amount_xmr = monero_changeto($amount, $currency);

$post = array(
'invoice_id' => $invoiceid,
'systemURL' => $systemurl,
Expand All @@ -173,7 +163,8 @@ function monero_link($params){
'address' => $address,
'amount_xmr' => $amount_xmr,
'amount' => $amount,
'currency' => $currency
'currency' => $currency,
'client_id' => $client_id
);
$form = '<form action="' . $systemurl . '/modules/gateways/monero/createinvoice.php" method="POST">';
foreach ($post as $key => $value) {
Expand All @@ -182,8 +173,8 @@ function monero_link($params){
$form .= '<input type="submit" value="' . $params['langpaynow'] . '" />';
$form .= '</form>';
$form .= '<p>'.$amount_xmr. " XMR (". $currency_symbol . $amount . " " . $currency .')</p>';
if ($discount_setting > 0) {
$form .='<p><small>Discount Applied: ' . preg_replace("/[^0-9]/", "", $discount_setting) . '% </small></p>';
if ($bonus_percentage > 0) {
$form .='<p><small>Bonus to be applied: ' . $bonus_percentage . '% </small></p>';
}
return $form;
}
31 changes: 14 additions & 17 deletions modules/gateways/monero/createinvoice.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
<?php
include("../../../init.php");
include("../../../includes/functions.php");
include("../../../includes/gatewayfunctions.php");
include("../../../includes/invoicefunctions.php");
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
use WHMCS\Database\Capsule as Capsule;
use WHMCS\Module\Gateway\Monero\MoneroLib;

require_once __DIR__ . '/../../../init.php';
require_once __DIR__ . '/../../../includes/gatewayfunctions.php';

$gatewaymodule = "monero";
$GATEWAY = getGatewayVariables($gatewaymodule);
Expand All @@ -16,26 +13,27 @@
$link = $GATEWAY['daemon_host'].":".$GATEWAY['daemon_port']."/json_rpc";


function monero_payment_id(){
if(!isset($_COOKIE['payment_id'])) {
function monero_payment_id($invoice_id){
if(!isset($_COOKIE["payment_id$invoice_id"])) {
$payment_id = bin2hex(openssl_random_pseudo_bytes(8));
setcookie('payment_id', $payment_id, time()+2700);
// create one cookie per invoice_id.
setcookie("payment_id$invoice_id", $payment_id, time()+2700, '/', '', true, true);
} else {
$payment_id = $_COOKIE['payment_id'];
$payment_id = $_COOKIE["payment_id$invoice_id"];
}
return $payment_id;

}

$monero_daemon = new Monero_rpc($link);
$monero_daemon = new MoneroLib($link);

$message = "Waiting for your payment.";
$_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
$currency = stripslashes($_POST['currency']);
$amount_xmr = stripslashes($_POST['amount_xmr']);
$amount = stripslashes($_POST['amount']);
$payment_id = monero_payment_id();
$invoice_id = stripslashes($_POST['invoice_id']);
$client_id = stripslashes($_POST['client_id']);
$payment_id = monero_payment_id($invoice_id);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please improve the security of monero_payment_id function? You will be able to inject potentential and dangerous scripts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how to improve it. :(

$array_integrated_address = $monero_daemon->make_integrated_address($payment_id);
$address = $array_integrated_address['integrated_address'];
$uri = "monero:$address?amount=$amount_xmr";
Expand Down Expand Up @@ -127,11 +125,11 @@ className: 'spinner', // The CSS class to assign to the spinner

$.ajax({ url : 'verify.php',
type : 'POST',
data: { 'amount_xmr' : '".$amount_xmr."', 'payment_id' : '".$payment_id."', 'invoice_id' : '".$invoice_id."', 'amount' : '".$amount."', 'hash' : '".$hash."', 'currency' : '".$currency."'},
data: { 'amount_xmr' : '".$amount_xmr."', 'payment_id' : '".$payment_id."', 'invoice_id' : '".$invoice_id."', 'amount' : '".$amount."', 'hash' : '".$hash."', 'currency' : '".$currency."', 'client_id' : '".$client_id."'},
success: function(msg) {
console.log(msg);
$('#message').text(msg);
if(msg=='Payment has been received.') {
if(msg === 'Payment has been received.') {
//redirect to Paid invoice
window.location.href = '/viewinvoice.php?id=$invoice_id';
}
Expand All @@ -148,4 +146,3 @@ className: 'spinner', // The CSS class to assign to the spinner
verify();
setInterval(function(){ verify()}, 5000);
</script>";
?>
12 changes: 7 additions & 5 deletions modules/gateways/monero/library.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
namespace WHMCS\Module\Gateway\Monero;

/**
* library.php
*
Expand All @@ -10,7 +12,7 @@
* Modified to work with monero-rpc wallet by Serhack and cryptochangements
*/

class Monero_rpc
class MoneroLib
{
protected $url = null, $is_debug = false, $parameters_structure = 'array';

Expand All @@ -33,11 +35,11 @@ class Monero_rpc
503 => '503 Service Unavailable'
);

public function __construct($pUrl, $pUser = null, $pPass = null) {
public function __construct($pUrl = null, $pUser = null, $pPass = null) {

$gatewayx = getGatewayVariables("monero");
$this->validate(false === extension_loaded('curl'), 'The curl extension must be loaded for using this class!');
$this->validate(false === extension_loaded('json'), 'The json extension must be loaded for using this class!');
$this->validate(!extension_loaded('curl'), 'The curl extension must be loaded for using this class!');
$this->validate(!extension_loaded('json'), 'The json extension must be loaded for using this class!');
$this->url = $gatewayx['daemon_host']. ":" .$gatewayx['daemon_port'] . "/json_rpc";
$this->username = $gatewayx['daemon_user'];
$this->password = $gatewayx['daemon_pass'];
Expand Down Expand Up @@ -344,4 +346,4 @@ public function get_bulk_payments($payment_id, $min_block_height)
$get_bulk_payments = $this->_run('get_bulk_payments', $get_bulk_payments_parameters);
return $get_bulk_payments;
}
}
}
Loading