Skip to content

Commit

Permalink
replaced Poloniex per Binance
Browse files Browse the repository at this point in the history
  • Loading branch information
magnussolution committed May 18, 2023
1 parent e8a6beb commit 300ceff
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 367 deletions.
Binary file modified build/MagnusBilling-current.tar.gz
Binary file not shown.
47 changes: 31 additions & 16 deletions protected/commands/CryptocurrencyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,48 @@ class CryptocurrencyCommand extends CConsoleCommand
{
public function run($args)
{

$modelMethodPay = Methodpay::model()->find('payment_method = :key', array(':key' => 'cryptocurrency'));
if (!isset($modelMethodPay->id)) {
echo 'No method found';
exit;
}
$poloniex = new Poloniex($modelMethodPay->client_id, $modelMethodPay->client_secret);
//'1314121820'
$ticker = $poloniex->get_deposits_and_withdrawals(time() - 18000, time());
foreach ($ticker as $type => $payment) {
if ($type == 'deposits') {
foreach ($payment as $key => $value) {
$modelCryptocurrency = Cryptocurrency::model()->find('amountCrypto = :key AND date > :key1',
array(':key' => $value['amount'], ':key1' => date('Y-m-d')));
if (isset($modelCryptocurrency->id_user)) {
if (Refill::model()->countRefill($value['txid'], $modelCryptocurrency->id_user) == 0) {
$description = 'CriptoCurrency ' . $value['currency'] . ', txid: ' . $value['txid'];
echo ($modelCryptocurrency->id_user . ' ' . $modelCryptocurrency->amount . ' ' . $description . ' ' . $value['txid']);
Yii::log($modelCryptocurrency->id_user . ' ' . $modelCryptocurrency->amount . ' ' . $description . ' ' . $value['txid'], 'error');
UserCreditManager::releaseUserCredit($modelCryptocurrency->id_user, $modelCryptocurrency->amount, $description, 1, $value['txid']);

$last_30_minutes = time() - 38000;
$modelCryptocurrency = Cryptocurrency::model()->findAll('date > :key1 AND status = 1',
array(':key1' => date('Y-m-d')));

foreach ($modelCryptocurrency as $key => $payment) {

$result = '';

echo "try get payments\n";
exec('python3.9 /var/www/html/mbilling/protected/commands/crypto.py ' . $modelMethodPay->client_id . ' ' . $modelMethodPay->client_secret . ' ' . $payment->currency . ' ' . $last_30_minutes, $result);
$result = implode("\n", $result);
$result = json_decode($result);

foreach ($result as $key => $value) {

if ($value->amount == $payment->amountCrypto) {

if (isset($payment->id_user)) {

if (Refill::model()->countRefill($value->txId, $payment->id_user) == 0) {
Cryptocurrency::model()->updateByPk($payment->id, array('status' => 0));
$description = 'CriptoCurrency ' . $value->coin . ', txid: ' . $value->txId;

echo ($payment->id_user . ' ' . $payment->amount . ' ' . $description . ' ' . $value->txId);
Yii::log($payment->id_user . ' ' . $payment->amount . ' ' . $description . ' ' . $value->txId, 'error');

UserCreditManager::releaseUserCredit($payment->id_user, $payment->amount, $description, 1, $value->txId);
} else {
echo "Paymente already released\n";
}
} else {
echo "Receive new deposit in your wallet but not found any refill in your MagnusBilling\n";
}

}
} else {
echo "Not found deposit in your wallet\n";
}

}
Expand Down
9 changes: 9 additions & 0 deletions protected/commands/UpdateMysqlCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -1920,6 +1920,15 @@ public function run($args)
$version = '7.8.3.7';
$this->update($version);
}

//2023-05-18
if ($version == '7.8.3.7') {
$sql = "ALTER TABLE `pkg_user` CHANGE `prefix_local` `prefix_local` VARCHAR(500) NOT NULL DEFAULT '';";
$this->executeDB($sql);

$version = '7.8.3.8';
$this->update($version);
}
}

public function executeDB($sql)
Expand Down
36 changes: 36 additions & 0 deletions protected/commands/crypto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""
DEBIAN 11
sudo apt install wget build-essential libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev
sudo apt install python3
sudo apt install python3.9-pip
python3.9 -m pip install python-binance
CENTOS 7
yum install libffi-devel -y
curl -O https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tgz
tar -xzf Python-3.9.1.tgz
cd Python-3.9.1
./configure --enable-optimizations
make altinstall
python3.9 -m pip install --upgrade pip
pip3.9 install urllib3==1.26.6
python3.9 -m pip install python-binance
python3.9 /var/www/html/mbilling/protected/commands/crypto.py
"""
import sys
import getopt
from binance.client import Client
import json
from binance.client import Client
import json
client = Client(sys.argv[1], sys.argv[2])


res = client.get_deposit_history(coin=sys.argv[3],startTime=sys.argv[4]+'000')
print(json.dumps(res, indent=2))
2 changes: 2 additions & 0 deletions protected/components/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class Controller extends BaseController
'invoices',
'statusSystem',
'firewall',
'trunkGroup',
'callSummaryPerDay',
);

//Allowed controllers to no admin users use updateall
Expand Down
268 changes: 0 additions & 268 deletions protected/components/Poloniex.php

This file was deleted.

Loading

0 comments on commit 300ceff

Please sign in to comment.