Skip to content

Commit d2b7b83

Browse files
improve Transfertomobile module
1 parent b1a4130 commit d2b7b83

35 files changed

+3179
-622
lines changed

build/MagnusBilling-current.tar.gz

3.45 KB
Binary file not shown.

protected/commands/BDServiceCommand.php

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,91 @@ public function run($args)
3838
}
3939
$log = DEBUG >= 1 ? Log::writeLog(LOGFILE, ' line:' . __LINE__ . " START NOTIFY CLIENT ") : null;
4040

41+
$this->tanaSend();
42+
43+
$this->ezzeapi();
44+
45+
}
46+
47+
public function tanaSend()
48+
{
49+
50+
$config = LoadConfig::getConfig();
51+
52+
$userBD = $config['global']['BDService_username'];
53+
$keyBD = $config['global']['BDService_token'];
54+
55+
$modelSendCreditSummary = SendCreditSummary::model()->findAll('confirmed = 0 AND service != :key AND date > :key1 AND provider = :key2', [
56+
':key' => 'international',
57+
':key1' => date('Y-m-d'),
58+
':key2' => 'TanaSend',
59+
]);
60+
61+
foreach ($modelSendCreditSummary as $key => $sendCredit) {
62+
$url = "http://takasend.org/ezzeapi/status?id=" . $sendCredit->id . "&user=" . $userBD . "&key=" . $keyBD . "";
63+
if (!$result = @file_get_contents($url, false)) {
64+
$result = '';
65+
}
66+
echo $result . " $sendCredit->id \n";
67+
$modelRefill = Refill::model()->find('invoice_number = :key AND id_user = :key1',
68+
array(
69+
':key' => $sendCredit->id,
70+
':key1' => $sendCredit->id_user,
71+
));
72+
73+
if (preg_match("/ERROR|CANCELLED/", strtoupper($result))) {
74+
75+
$result = explode(':', $result);
76+
77+
$sendCredit->confirmed = 3;
78+
$sendCredit->save();
79+
80+
if (isset($modelRefill->id)) {
81+
82+
$modelRefill->description = $modelRefill->description . '. Status: ' . $result[0] . '. Ref:' . $result[1];
83+
$modelRefill->payment = 0;
84+
try {
85+
$modelRefill->save();
86+
} catch (Exception $e) {
87+
88+
}
89+
90+
$modelUser = User::model()->findByPk($sendCredit->id_user);
91+
$modelUser->credit = $modelUser->credit + ($modelRefill->credit * -1);
92+
93+
try {
94+
$modelUser->save();
95+
} catch (Exception $e) {
96+
97+
}
98+
}
99+
100+
} else if (preg_match("/SUCCESS|COMPLETED|ERROR/", $result)) {
101+
102+
$result = explode(':', $result);
103+
104+
$sendCredit->confirmed = 1;
105+
$sendCredit->save();
106+
107+
if (isset($modelRefill->id)) {
108+
109+
$modelRefill->description = @$modelRefill->description . '. Status: ' . $result[0] . '. Ref:' . $result[1];
110+
$modelRefill->payment = 1;
111+
try {
112+
$modelRefill->save();
113+
} catch (Exception $e) {
114+
115+
}
116+
}
117+
118+
}
119+
120+
}
121+
122+
}
123+
public function ezzeapi()
124+
{
125+
41126
/*$_POST = array(
42127
43128
"refid" => 23597,
@@ -57,7 +142,10 @@ public function run($args)
57142
Configuration::model()->updateAll(array('config_value' => $result), 'config_key = :key',
58143
array(':key' => 'BDService_credit_provider'));
59144

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

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

protected/commands/CallChartCommand.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public function user_cdr_show($calls)
191191

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

347347
if (count($callShopIds)) {
348-
if (in_array($modelSip->id_user, $callShopIds)) {
348+
if (in_array($id_user, $callShopIds)) {
349+
350+
if (!isset($modelSip->id)) {
351+
$modelSip = Sip::model()->find('name =:key', array(':key' => $sip_account));
352+
}
349353
$modelSip->status = 3;
350354
$modelSip->callshopnumber = $ndiscado;
351355
$modelSip->callshoptime = $cdr;

protected/components/AsteriskAccess.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,13 @@ public function writeAsteriskFile($model, $file, $head_field = 'name')
278278
$line .= 'context=slave' . "\n";
279279
} else if ($data['type'] == 'sipproxy') {
280280

281-
$line = "\n\n[sipproxy-" . preg_replace('/ /', '', strtolower($data['name'])) . "]\n";
281+
$line = "\n\n[sipproxy-" . preg_replace('/ /', '', strtolower($data['name'])) . "-" . $data['id'] . "]\n";
282282
$line .= 'host=' . $data['host'] . "\n";
283283
$line .= 'fromdomain=' . $data['host'] . "\n";
284284
$line .= 'accountcode=sipproxy' . "\n";
285285
$line .= 'context=proxy' . "\n";
286-
$line .= 'directmedia=yes' . "\n";
287-
$line .= 'nat=no' . "\n";
286+
$line .= 'directmedia=no' . "\n";
287+
$line .= 'nat=force_rport,comedia' . "\n";
288288
} else if ($data['type'] == 'mbilling') {
289289

290290
$line = "\n\n[mbilling]\n";

protected/components/SendCreditDingConnect.php

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,20 @@ public function getKey()
2121
return $config['global']['ding_api'];
2222
}
2323

24-
public static function sendCredit($number, $send_value, $SkuCode, $test)
24+
public static function sendCredit($number, $modelSendCreditRates, $SkuCode, $test)
2525
{
2626

27+
$send_value = $modelSendCreditRates->idProduct->send_value;
28+
$SkuCode = $modelSendCreditRates->idProduct->SkuCode;
29+
2730
if ($send_value == 0) {
2831

2932
$post = [[
3033

3134
"SendValue" => 5,
3235
"SendCurrencyIso" => "EUR",
3336
"ReceiveValue" => 0,
34-
"SkuCode" => "BD_AX_TopUp",
37+
"SkuCode" => $SkuCode,
3538
"BatchItemRef" => "string",
3639
]];
3740

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

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

57-
$send_value = number_format(5 / $result->Items[0]->Price->ReceiveValue * $_POST['TransferToMobile']['amountValuesBDT'], 2);
58-
$end_value = number_format($send_value * 1.01);
60+
if (isset($_POST['TransferToMobile']['amountValuesBDT']) && $_POST['TransferToMobile']['amountValuesBDT'] > 0) {
61+
$send_value = ((5 / $result->Items[0]->Price->ReceiveValue) * $_POST['TransferToMobile']['amountValuesBDT']) * 1.01;
62+
} else {
63+
$send_value = ((5 / $result->Items[0]->Price->ReceiveValue) * $modelSendCreditRates->idProduct->product) * 1.01;
64+
}
65+
$send_value_to_api = $send_value;
66+
$send_value = number_format($send_value, 2);
5967

6068
} else {
6169
exit('invalid amount receiveValue');
6270
}
71+
/*
72+
echo '<pre>';
73+
echo '<pre>';
74+
print_r($modelSendCreditRates->getAttributes());
75+
print_r($modelSendCreditRates->idProduct->getAttributes());
76+
print_r($result);
77+
78+
echo '((5 / ' . $result->Items[0]->Price->ReceiveValue . ') *' . $_POST['TransferToMobile']['amountValuesBDT'] . ') + 1%)<br>';
79+
echo 'send_value = ' . $send_value . "<br>";
6380
81+
exit;
82+
*/
83+
84+
} else {
85+
$send_value_to_api = $send_value;
6486
}
87+
6588
//SendCreditDingConnect::getProducts('VOBR');
6689
if (preg_match('/^00/', $number)) {
6790
$number = substr($number, 2);
6891
}
6992
$post = array(
7093
"SkuCode" => $SkuCode,
71-
"SendValue" => $send_value,
94+
"SendValue" => $send_value_to_api,
7295
"AccountNumber" => $number,
7396
"DistributorRef" => $number,
7497
"ValidateOnly" => $test,
@@ -97,6 +120,11 @@ public static function sendCredit($number, $send_value, $SkuCode, $test)
97120
print_r($result);
98121
}
99122

123+
if ($result->TransferRecord->ProcessingState == 'Failed') {
124+
unset($result->TransferRecord->ReceiptParams);
125+
126+
}
127+
100128
return $result->TransferRecord->ProcessingState == 'Complete' ? 'error_txt=Transaction successful' : 'error_txt=' . $result->ErrorCodes[0]->Code . ' ' . $result->ErrorCodes[0]->Context;
101129

102130
}

0 commit comments

Comments
 (0)