Skip to content

Commit

Permalink
improve Transfertomobile module
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Mar 29, 2021
1 parent b1a4130 commit d2b7b83
Show file tree
Hide file tree
Showing 35 changed files with 3,179 additions and 622 deletions.
Binary file modified build/MagnusBilling-current.tar.gz
Binary file not shown.
90 changes: 89 additions & 1 deletion protected/commands/BDServiceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,91 @@ public function run($args)
}
$log = DEBUG >= 1 ? Log::writeLog(LOGFILE, ' line:' . __LINE__ . " START NOTIFY CLIENT ") : null;

$this->tanaSend();

$this->ezzeapi();

}

public function tanaSend()
{

$config = LoadConfig::getConfig();

$userBD = $config['global']['BDService_username'];
$keyBD = $config['global']['BDService_token'];

$modelSendCreditSummary = SendCreditSummary::model()->findAll('confirmed = 0 AND service != :key AND date > :key1 AND provider = :key2', [
':key' => 'international',
':key1' => date('Y-m-d'),
':key2' => 'TanaSend',
]);

foreach ($modelSendCreditSummary as $key => $sendCredit) {
$url = "http://takasend.org/ezzeapi/status?id=" . $sendCredit->id . "&user=" . $userBD . "&key=" . $keyBD . "";
if (!$result = @file_get_contents($url, false)) {
$result = '';
}
echo $result . " $sendCredit->id \n";
$modelRefill = Refill::model()->find('invoice_number = :key AND id_user = :key1',
array(
':key' => $sendCredit->id,
':key1' => $sendCredit->id_user,
));

if (preg_match("/ERROR|CANCELLED/", strtoupper($result))) {

$result = explode(':', $result);

$sendCredit->confirmed = 3;
$sendCredit->save();

if (isset($modelRefill->id)) {

$modelRefill->description = $modelRefill->description . '. Status: ' . $result[0] . '. Ref:' . $result[1];
$modelRefill->payment = 0;
try {
$modelRefill->save();
} catch (Exception $e) {

}

$modelUser = User::model()->findByPk($sendCredit->id_user);
$modelUser->credit = $modelUser->credit + ($modelRefill->credit * -1);

try {
$modelUser->save();
} catch (Exception $e) {

}
}

} else if (preg_match("/SUCCESS|COMPLETED|ERROR/", $result)) {

$result = explode(':', $result);

$sendCredit->confirmed = 1;
$sendCredit->save();

if (isset($modelRefill->id)) {

$modelRefill->description = @$modelRefill->description . '. Status: ' . $result[0] . '. Ref:' . $result[1];
$modelRefill->payment = 1;
try {
$modelRefill->save();
} catch (Exception $e) {

}
}

}

}

}
public function ezzeapi()
{

/*$_POST = array(
"refid" => 23597,
Expand All @@ -57,7 +142,10 @@ public function run($args)
Configuration::model()->updateAll(array('config_value' => $result), 'config_key = :key',
array(':key' => 'BDService_credit_provider'));

$modelSendCreditSummary = SendCreditSummary::model()->findAll('confirmed = 0 AND service != "international"');
$modelSendCreditSummary = SendCreditSummary::model()->findAll('confirmed = 0 AND service != :key AND date > :key1 ', [
':key' => 'international',
':key1' => date('Y-m-d'),
]);

foreach ($modelSendCreditSummary as $key => $sendCredit) {

Expand Down
8 changes: 6 additions & 2 deletions protected/commands/CallChartCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public function user_cdr_show($calls)

if (!count($modelSip)) {
if ($status == 'Ring') {
$sip_account = $originate;
$sip_account = $originate;
}
if (strlen($sip_account) > 3) {
//echo "check per sip_account $originate\n";
Expand Down Expand Up @@ -345,7 +345,11 @@ public function user_cdr_show($calls)
$sql[] = "(NULL,'" . $uniqueid . "', '$sip_account', $id_user, '$channel', '" . utf8_encode($trunk) . "', '$ndiscado', '" . preg_replace('/\(|\)/', '', $codec) . "', '$status', '$cdr', 'no','no', '" . $call['server'] . "')";

if (count($callShopIds)) {
if (in_array($modelSip->id_user, $callShopIds)) {
if (in_array($id_user, $callShopIds)) {

if (!isset($modelSip->id)) {
$modelSip = Sip::model()->find('name =:key', array(':key' => $sip_account));
}
$modelSip->status = 3;
$modelSip->callshopnumber = $ndiscado;
$modelSip->callshoptime = $cdr;
Expand Down
6 changes: 3 additions & 3 deletions protected/components/AsteriskAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,13 @@ public function writeAsteriskFile($model, $file, $head_field = 'name')
$line .= 'context=slave' . "\n";
} else if ($data['type'] == 'sipproxy') {

$line = "\n\n[sipproxy-" . preg_replace('/ /', '', strtolower($data['name'])) . "]\n";
$line = "\n\n[sipproxy-" . preg_replace('/ /', '', strtolower($data['name'])) . "-" . $data['id'] . "]\n";
$line .= 'host=' . $data['host'] . "\n";
$line .= 'fromdomain=' . $data['host'] . "\n";
$line .= 'accountcode=sipproxy' . "\n";
$line .= 'context=proxy' . "\n";
$line .= 'directmedia=yes' . "\n";
$line .= 'nat=no' . "\n";
$line .= 'directmedia=no' . "\n";
$line .= 'nat=force_rport,comedia' . "\n";
} else if ($data['type'] == 'mbilling') {

$line = "\n\n[mbilling]\n";
Expand Down
38 changes: 33 additions & 5 deletions protected/components/SendCreditDingConnect.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,20 @@ public function getKey()
return $config['global']['ding_api'];
}

public static function sendCredit($number, $send_value, $SkuCode, $test)
public static function sendCredit($number, $modelSendCreditRates, $SkuCode, $test)
{

$send_value = $modelSendCreditRates->idProduct->send_value;
$SkuCode = $modelSendCreditRates->idProduct->SkuCode;

if ($send_value == 0) {

$post = [[

"SendValue" => 5,
"SendCurrencyIso" => "EUR",
"ReceiveValue" => 0,
"SkuCode" => "BD_AX_TopUp",
"SkuCode" => $SkuCode,
"BatchItemRef" => "string",
]];

Expand All @@ -54,21 +57,41 @@ public static function sendCredit($number, $send_value, $SkuCode, $test)

if (isset($result->Items[0]->Price->ReceiveValue)) {

$send_value = number_format(5 / $result->Items[0]->Price->ReceiveValue * $_POST['TransferToMobile']['amountValuesBDT'], 2);
$end_value = number_format($send_value * 1.01);
if (isset($_POST['TransferToMobile']['amountValuesBDT']) && $_POST['TransferToMobile']['amountValuesBDT'] > 0) {
$send_value = ((5 / $result->Items[0]->Price->ReceiveValue) * $_POST['TransferToMobile']['amountValuesBDT']) * 1.01;
} else {
$send_value = ((5 / $result->Items[0]->Price->ReceiveValue) * $modelSendCreditRates->idProduct->product) * 1.01;
}
$send_value_to_api = $send_value;
$send_value = number_format($send_value, 2);

} else {
exit('invalid amount receiveValue');
}
/*
echo '<pre>';
echo '<pre>';
print_r($modelSendCreditRates->getAttributes());
print_r($modelSendCreditRates->idProduct->getAttributes());
print_r($result);
echo '((5 / ' . $result->Items[0]->Price->ReceiveValue . ') *' . $_POST['TransferToMobile']['amountValuesBDT'] . ') + 1%)<br>';
echo 'send_value = ' . $send_value . "<br>";
exit;
*/

} else {
$send_value_to_api = $send_value;
}

//SendCreditDingConnect::getProducts('VOBR');
if (preg_match('/^00/', $number)) {
$number = substr($number, 2);
}
$post = array(
"SkuCode" => $SkuCode,
"SendValue" => $send_value,
"SendValue" => $send_value_to_api,
"AccountNumber" => $number,
"DistributorRef" => $number,
"ValidateOnly" => $test,
Expand Down Expand Up @@ -97,6 +120,11 @@ public static function sendCredit($number, $send_value, $SkuCode, $test)
print_r($result);
}

if ($result->TransferRecord->ProcessingState == 'Failed') {
unset($result->TransferRecord->ReceiptParams);

}

return $result->TransferRecord->ProcessingState == 'Complete' ? 'error_txt=Transaction successful' : 'error_txt=' . $result->ErrorCodes[0]->Code . ' ' . $result->ErrorCodes[0]->Context;

}
Expand Down
Loading

0 comments on commit d2b7b83

Please sign in to comment.