· 6 years ago · Jan 20, 2020, 08:56 AM
1<?php
2
3/**
4 * Description of Async Controller
5 *
6 * @author khizarahmed
7 */
8class AsyncController extends Controller {
9 //put your code here
10
11// For maintainence
12// public function __construct($id, $module = null) {
13// if($_SERVER['REMOTE_ADDR']!='14.97.129.170')
14// {
15// throw new CHttpException(500);exit;
16// }
17// parent::__construct($id, $module);
18// }
19
20 /**
21 * for callback
22 */
23 public function actionCallback()
24 {
25// error_reporting(E_ALL);
26// ini_set('display_errors', 'ON');
27 $request=$_REQUEST;
28 $request['_type']='callback';
29 $request['datetime'] = new MongoDate();
30 $request['_partner'] = 'vodaIn';
31 $request['_response']='ERROR';
32 $callback=Yii::app()->mongodb->callback_log;
33 $id= $this->getProductId();
34 if($id == 0){
35 $errorNo=805;
36 $msg_respo='RESPONSE_STATUS:'.$errorNo.':'.time().rand(1111,9999).':Error. Do not retry.';
37 echo $msg_respo;
38 $request['errorMsg']=$msg_respo;
39 $callback->insert($request);
40 exit;
41 }
42 try
43 {
44 $_response=$this->VodaCallBack($id);
45 echo $_response;
46 $request['_response']=$_response;
47 $callback->insert($request);
48 //echo "RESPONSE_STATUS:800:".$_REQUEST['REQUEST_ID'].":Service Successfully Activated.";
49 } catch (Exception $e)
50 {
51 $callback->insert($request);
52 throw new CHttpException(500, 'something went wrong, please try after some time');
53
54 }
55
56 }
57
58 public function actionQooredoo_mo()
59 {
60
61
62 echo $this->actionMoprocess();
63
64 //echo "|ACCEPTED";
65 }
66
67 public function actionQooredoo_mt()
68 {
69 echo "ACCEPTED";
70 }
71
72 private function VodaCallBack($product_id)
73 {
74 $obj=new VodaFoneCallBack();
75 $obj->msisdn=$_REQUEST['MSISDN'];
76 $obj->service_id=$_REQUEST['SERVICE_ID'];
77 $obj->class=$_REQUEST['CLASS'];
78 $obj->txn_id=$_REQUEST['TXNID'];
79 $obj->action=$_REQUEST['ACTION'];
80 $obj->status=$_REQUEST['STATUS'];
81 $obj->charging_mode=$_REQUEST['CHARGING_MODE'];
82 $obj->request_mode=$_REQUEST['REQUEST_MODE'];
83 $obj->request_id=$_REQUEST['REQUEST_ID'];
84 $obj->circle_id=$_REQUEST['CIRCLE_ID'];
85 if($obj->circle_id!=FALSE)
86 {
87 $obj->circle_id=(new VodafoneCircle())->getCircleId()[$obj->circle_id];
88 }
89 else
90 {
91 $obj->circle_id=(new Circle())->getCircleCode($obj->msisdn);
92 }
93 $obj->product_id=$product_id;
94 if($obj->validate())
95 {
96 $status=$obj->subscribe();
97 }
98 else
99 {
100 throw new CHttpException(500, print_r($obj->errors,1));
101 }
102 return $status;
103 }
104
105 /**
106 * $_id= (int) time().mt_rand(0, 9999);
107 $obj=new VodaFoneCallBack();
108 $obj->_id=$_id;
109 $obj->msisdn=$_GET['MSISDN'];
110 $obj->service_id=$_GET['serviceid'];
111 $obj->class=$_GET['CLASS'];
112 $obj->txn_id=$_GET['TXNID'];
113 $obj->action=$_GET['ACTION'];
114 $obj->status=$_GET['STATUS'];
115 $obj->charging_mode=$_GET['CHARGING_MODE'];
116 $obj->request_mode=$_GET['REQMODE'];
117 $obj->request_id=$_GET['REQUESTID'];
118
119 if($obj->validate())
120 {
121 $obj->subscribe();
122 }
123 else
124 {
125 $error_code=805;
126 }
127
128 $obj->save(false);
129
130 echo "RESPONSE_STATUS:";
131 echo $error_code,':';
132 echo $_id,':';
133 echo $obj->errorCode()[$error_code];
134 */
135
136 /**
137 *
138 * url for update call
139 */
140 public function actionCallUpdate()
141 {
142 $request=$_REQUEST;
143 $request['_type']='update';
144 $request['_partner'] = 'vodaIn';
145 $request['datetime'] = new MongoDate();
146 $id= $this->getProductId();
147 if($id == 0){
148 $errorNo=905;
149 $msg_respo='RESPONSE_STATUS:'.$errorNo.':'.time().rand(1111,9999).':Error. Do not retry.';
150 echo $msg_respo;
151 exit;
152 }
153 $_response=$status=$this->VodafoneUpdate($id);
154 $callback=Yii::app()->mongodb->callback_log;
155 echo $_response;
156 try {
157 $request['_response']=$_response;
158 $callback->insert($request);
159 //echo "RESPONSE_STATUS:904:1234:there is some problem, please try later.";
160 } catch (Exception $exc) {
161 echo $exc->getMessage();
162 }
163 }
164
165 private function VodafoneUpdate($id)
166 {
167 $obj=new VodafoneCallUpdate();
168 $obj->msisdn=$_REQUEST['MSISDN'];
169 $obj->service_id=$_REQUEST['SERVICE_ID'];
170 $obj->class=$_REQUEST['CLASS'];
171 $obj->txnid=$_REQUEST['TXNID'];
172 $obj->charging_mode=$_REQUEST['CHARGING_MODE'];
173 $obj->circle_id=$_REQUEST['CIRCLE_ID'];
174 if($obj->circle_id!=FALSE)
175 {
176 $obj->circle_id=(new VodafoneCircle())->getCircleId()[$obj->circle_id];
177 }
178 else
179 {
180 $obj->circle_id=(new Circle)->getCircleCode($obj->msisdn);
181 }
182 $obj->product_id=$id;
183 return $obj->update();
184 }
185
186 /**
187 * IDEA callback API
188 */
189 public function actionIdea_sub()
190 {
191 $req=$_REQUEST;
192 $req=json_encode($req,1);
193 $fp=fopen('/tmp/json_req','a+');
194 fwrite($fp,$req);
195 fclose($fp);
196 $getParams= W::getRequestParams();
197 $getParams['datetime']= new MongoDate();
198 $getParams['_type']='callback';
199 $callbackLog = Yii::app()->mongodb->callback_log;
200 $paramStatus=(new IdeaCommon)->checkRequestParams();
201 //check parameter are correct
202 if($paramStatus!== false){
203 $response=$paramStatus;
204
205 }else{
206 $productId = $this->getProductId();
207 //check product is available or not
208 if($productId == 0){
209 $errorNo=703;
210 $response=$errorNo.'|ERROR|'. IdeaCommon::errorCode()[$errorNo];
211 }else{
212 $response = (new IdeaCb)->ideaCback($productId);
213 }
214 }
215 echo $response;
216 try
217 {
218 $getParams['_response']=$response;
219 $callbackLog->insert($getParams);
220 }
221 catch (Exception $e)
222 {
223 throw $e->getMessage();
224 }
225
226 }
227
228 /**
229 * Etisalat UAE callback API
230 */
231 public function actionEtisalatsub()
232 {
233 $req= trim(file_get_contents('php://input'));
234 $getParams=(new Common())->xmlToArray($req);
235 $getParams['datetime']= new MongoDate();
236 $getParams['_type']='callback';
237 $callbackLog = Yii::app()->mongodb->callback_log;
238 if($getParams['package_id']!== ''){
239 $productId = $this->productId($getParams['package_id']);
240 //check product is available or not
241 if($productId == false){
242 $response= "Package id not found.!";
243 }else{
244 $getParams['product_id'] = $productId;
245 $response = (new EtisalatCb)->EtisalatCback($getParams);
246 }
247 }else{
248 $response=FALSE;
249 }
250 print_r($response);
251 try
252 {
253 $getParams['_response']=$response;
254 $callbackLog->insert($getParams);
255 }
256 catch (Exception $e)
257 {
258 throw $e->getMessage();
259 }
260
261 }
262
263 /**
264 * Oxy8 SA callback API
265 */
266 public function actionOxy8cb($partner='oxy8sa_cb') {
267
268 $getParams = W::getRequestParams();
269 $getParams['extrainfo'] = json_decode($getParams['extrainfo'], true);
270 $getParams = array_change_key_case($getParams, CASE_LOWER);
271 $getParams['datetime'] = new MongoDate();
272 $getParams['_type'] = 'callback';
273
274 // For testing purpose START
275 $this->storeLog('oxy8_cb','cb');
276 // For testing purpose STOP
277
278 $callbackLog = Yii::app()->mongodb->callback_log;
279
280 if(isset($getParams['campaignid']) && !empty($getParams['campaignid'])){
281 $productId = $this->productId($getParams['campaignid']);
282 //check product is available or not
283 if ($productId == false) {
284 $response = "Campaign ID not listed.!";
285 } else {
286 $getParams['product_id'] = $productId;
287 $response = (new Oxy8SaCb())->Oxy8SaCback($getParams);
288 }
289 }else{
290 $response = "Campaign ID not found.!";
291 }
292 print_r($response);
293 try {
294 $getParams['_response'] = $response;
295 $getParams['_partner'] = "$partner";
296 $callbackLog->insert($getParams);
297 } catch (Exception $e) {
298 throw $e->getMessage();
299 }
300 }
301
302 /**
303 * Oxy8 SA receipt API
304 */
305 public function actionOxy8dr($partner='oxy8sa_dr') {
306
307 $getParams = W::getRequestParams();
308 $getParams['extrainfo'] = json_decode($getParams['extrainfo'], true);
309 $getParams['time'] = new MongoDate();
310 $getParams['_type'] = 'callback';
311 $getParams['_partner'] = "$partner";
312
313 // START
314 $this->storeLog('oxy8_dr','dr');
315 // STOP
316
317 $response='FAIL';
318 if(isset($getParams['msisdn']) && is_numeric($getParams['msisdn'])){
319 $msisdn = $getParams['msisdn'];
320 $ref=$getParams['reference'];
321 $oxy8cb=new Oxy8SaCb;
322 $detail=$oxy8cb->getRefCollection()->findOne(['_id'=>$ref]);
323 //print_r($detail);
324 $subid=$detail['detail']['subid'];
325 if($subid)
326 {
327 $sub=(new SubscriptionEx)->findByPk($subid);
328 if($sub)
329 {
330 echo "sub=",$sub->id,':product='.$sub->product->id,'|';
331 $product=$sub->product;
332 }
333 else{
334 $product=(new ProductEx)->findByPk((new SubOxy8sa())->getRProductId($msisdn));
335 }
336
337 }else{ //for fresh user
338 $product=(new ProductEx)->findByPk((new SubOxy8sa())->getRProductId($msisdn));
339 $sub = (new SubscriptionEx)->getSubscription($msisdn, $product->id, Oxy8SaCb::graceTime());
340 if($sub){
341 $detail['detail']=json_decode($sub->transaction->description, 1);
342 $subid = $sub->id;
343 }
344 }
345 if($product){
346 $priceVal=$product->getPriceNValidity();
347 $price=$priceVal['price'];
348 $validity=$priceVal['validity'];
349
350 if($getParams['status']=='PRMRJCT' and $sub)
351 {
352 $type = MongoCampaignLog::TYPE_SUSPEND;
353 $price=0;
354 $tranx=$sub->transaction;
355 $jsonData = json_decode($tranx->description, 1);
356 $jsonData['isSoftLocked']='Y';
357 $tranx->description = json_encode($jsonData);
358 $tranx->save();
359
360 }else{
361 if($sub)
362 {
363 $tranx=$sub->transaction;
364 $jsonData = json_decode($tranx->description, 1);
365 $jsonData['isSoftLocked']='N';
366 $tranx->description = json_encode($jsonData);
367 $tranx->save();
368 }
369 if($getParams['status']=='OUTCRED' || $getParams['status']=='EXPIRED'){
370 $date=date(W::getDateFormat());
371 $subDate=date(W::getDateFormat(),strtotime($sub->created_at));
372 if((!$subid or $detail['type']=='F') and $date==$subDate)
373 {
374 $type= MongoCampaignLog::TYPE_PARK;
375 $isFresh='F';
376 }
377 else {
378 $type= MongoCampaignLog::TYPE_GRACE;
379 $isFresh='R';
380 }
381 if($detail['detail']["carrier"] == "mtn-za" and !isset($detail['rebill']) and 0) //no more needed for MTN-rebill
382 {
383 //if user older then 7days, apply increamental billing
384 if(strtotime($sub->created_at) <= (time()-(3600*24*7)))
385 {
386 $oxy8cb->callReBilling($msisdn, $product, $detail['detail'],$isFresh);
387 $type= MongoCampaignLog::TYPE_REBILLING;
388 echo "REBILL|";
389 }
390 }
391 $price=0;
392// if(!$subid && !in_array($sub->status,[SubscriptionEx::TYPE_PARK,SubscriptionEx::TYPE_GRACE]))
393// {
394// $sub->status= SubscriptionEx::TYPE_PARK;
395// $sub->expire_at = date(W::getDatetimeFormat(), (Oxy8SaCb::graceTime()*3600*24));
396// $sub->save();
397// }
398 echo "PARK|";
399 }elseif ($getParams['status']=='DELIVRD' ){
400
401 //for fallback price update
402 if(isset($getParams['pricepoint']) && !(in_array($getParams['pricepoint'],[0,10,15])))
403 $price=($getParams['pricepoint']/100);
404
405 if($detail['type']=='F')
406 {
407 if($sub)
408 {
409// $sub->expire_at = date(W::getDatetimeFormat(), (time()+($validity*3600*24)));
410 $expire_at=(time()+($validity*3600*24))-(3600*24);
411 $sub->expire_at = date(W::getDateFormat(), $expire_at).' 23:59:59';
412 $sub->status= SubscriptionEx::TYPE_ACTIVE;
413 $sub->save();
414 $type=MongoCampaignLog::TYPE_PARK_ACT;
415 $date=date(W::getDateFormat());
416 $subDate=date(W::getDateFormat(),strtotime($sub->created_at));
417 if($date==$subDate)
418 {
419 $type=MongoCampaignLog::TYPE_FRESH;
420 }
421 echo "new act|";
422 }else{
423 $type=FALSE;
424 }
425 }
426 else
427 {
428 $sub=(new SubscriptionEx)->findByPk($subid);
429 $type = MongoCampaignLog::TYPE_RENEW;
430 if($sub->status==Subscription::TYPE_PARK)
431 {
432 $type=MongoCampaignLog::TYPE_PARK_ACT;
433 }
434// $expire_at=($detail['time']->sec+($validity*3600*24))-(3600*24);
435 $expire_at=(time()+($validity*3600*24))-(3600*24);
436 $sub->status=Subscription::TYPE_ACTIVE;
437 $sub->expire_at = date(W::getDateFormat(), $expire_at).' 23:59:59';
438 $sub->save();
439 echo "renew|";
440 }
441 }
442 elseif($getParams['status']=='PRMFAIL')
443 {
444 $type= MongoCampaignLog::TYPE_CANCEL;
445 $price=0;
446 if($sub)
447 {
448 $sub->status= SubscriptionEx::TYPE_INACTIVE;
449 $sub->save();
450 echo "unsub|";
451 }
452 else {
453 echo "error on unsub - sub not found|";
454 }
455 }
456 elseif($getParams['status']=='INVALID' || $getParams['status']=='UNDELIV' || $getParams['status']=='REJECTD')
457 {
458 $type= MongoCampaignLog::TYPE_SUSPEND;
459 $price=0;
460 }
461 else{
462 $type=FALSE;
463 }
464 } //end PRMRJCT else
465 if($type){
466 $campToken=['camp'=>NULL,'token'=>NULL];
467 if(isset($detail['detail']["reference"]))
468 {
469 $campToken = (new MongoLogReq())->getLatestCampTkn($detail['detail']["reference"]);
470 if($campToken['camp']!='none' and $campToken['token']!='tkn' and $type == MongoCampaignLog::TYPE_FRESH)
471 CampTransaction::givePostback($campToken['camp'], $campToken['token'], $product->id);
472 }
473 (new MongoCampaignLog)->LOG($price, $product->id, $campToken['camp'], $campToken['token'], $msisdn, $type,'xx');
474 $response='SUCCESS';
475 }
476 }else{
477 echo 'no service found';
478 }
479 }
480
481 $getParams['product_id'] = (isset($product->id))?(string)$product->id:'NOTFOUND';
482 $callbackLog = Yii::app()->mongodb->callback_log;
483 try {
484 $getParams['_response'] = $response;
485 $callbackLog->insert($getParams);
486 } catch (Exception $e) {
487 throw $e->getMessage();
488 }
489 echo $response;
490 }
491 /**
492 * Oxy8 mobpair Mo
493 * @param type $param
494 */
495 public function actionOxy8MO($type='callbackMo',$partner='oxy8KY') {
496
497 $getParams = W::getRequestParams();
498 if (empty($getParams)) {
499 throw new CHttpException(404, 'No parameters found.');
500 }
501 $getParams = array_change_key_case($getParams, CASE_LOWER);
502 $getParams['time'] = new MongoDate();
503 $getParams['_type'] = "$type";
504 $getParams['_partner'] = "$partner";
505 $callbackLog = Yii::app()->mongodb->callback_log;
506
507 // For Testing purpose START
508// $this->storeLog("$partner","$type");
509 // For Testing purpose STOP
510
511 if(isset($getParams['campaignid']) && !empty($getParams['campaignid'])){
512 $productId = $this->productId($getParams['campaignid']);
513 //check product is available or not
514 if ($productId == false) {
515 $response = "Campaign ID not listed.!";
516 } else {
517 $getParams['product_id'] = $productId;
518 // subscribe_type : optin
519 // trigger (keyword)
520
521 $sub_type = strtolower($getParams['content']);
522 // sub
523 $subscribe_type = 'optin';
524 if(strpos($sub_type, 'unsub') !== false){
525 // unsub
526 $subscribe_type = 'optout';
527 }
528 if(strpos($sub_type, 'stop') !== false){
529 // unsub
530 $subscribe_type = 'optout';
531 }
532 $getParams['subscribe_type'] = $subscribe_type;
533 if($partner == 'oxy8TZ'){
534 // For TNZ
535 $response = (new Oxy8SaMoTNZCb())->Oxy8SaCback($getParams);
536 }else{
537 // FOR KNY
538 $response = (new Oxy8SaMoCb())->Oxy8SaCback($getParams);
539 }
540 }
541 }else{
542 $response = "Campaign ID not found.!";
543 }
544 print_r($response);
545 try {
546 $getParams['_response'] = $response;
547// $getParams['_partner'] = 'oxy8sa_cb';
548 $callbackLog->insert($getParams);
549 } catch (Exception $e) {
550 throw $e->getMessage();
551 }
552
553 }
554 /**
555 * Oxy8 mobpair Dn
556 * @param type $param
557 */
558 public function actionOxy8DN($type='callbackDN',$partner='oxy8KY') {
559
560 $getParams = W::getRequestParams();
561 $getParams = array_change_key_case($getParams,CASE_LOWER); // Lower case
562
563 $getParams['time'] = new MongoDate();
564 $getParams['_type'] = "$type";
565 $getParams['_partner'] = "$partner";
566
567 // For Testing purpose START
568// $this->storeLog("$partner","$type");
569 // For Testing purpose STOP
570
571 $response='FAIL';
572 if(isset($getParams['reference'])){
573
574// if(isset($getParams['msisdn']) && is_numeric($getParams['msisdn'])){
575// $msisdn = $getParams['msisdn'];
576 $ref=$getParams['reference'];
577 $oxy8cb=new Oxy8SaMoCb;
578 $detail=$oxy8cb->getRefCollection()->findOne(['_id'=>$ref]);
579 //print_r($detail);
580// if($getParams['reference']=='18.2541.1524808105.18'){
581// $detail['type'] = 'FreeMTRef';
582// }
583 if($detail['type'] == 'FreeMTRef'){
584 $response = 'SUCCESS';
585 $getParams['msgtype'] = 'FreeMT';
586 }
587
588 $subid=$detail['detail']['subid'];
589 $msisdn = $detail['detail']['msisdn'];
590
591 if($detail['type'] != 'FreeMTRef'){
592
593 if($msisdn){
594 $getParams['msisdn'] = $msisdn;
595 if($subid)
596 {
597 $sub=(new SubscriptionEx)->findByPk($subid);
598 if($sub)
599 {
600 echo "sub=",$sub->id,':product='.$sub->product->id,'|';
601 $product=$sub->product;
602 }
603 else{
604 $product=(new ProductEx)->findByPk((new SubOxy8sa())->getRProductId($msisdn));
605 }
606
607 }else{ //for fresh user
608 $product=(new ProductEx)->findByPk((new SubOxy8sa())->getRProductId($msisdn));
609 $sub = (new SubscriptionEx)->getSubscription($msisdn, $product->id, Oxy8SaCb::graceTime());
610 if($sub){
611 $detail['detail']=json_decode($sub->transaction->description, 1);
612 }
613 }
614 if($product){
615 $priceVal=$product->getPriceNValidity();
616 $price=$priceVal['price'];
617 $validity=$priceVal['validity'];
618
619 if($getParams['status']=='PRMRJCT' and $sub)
620 {
621 $type = MongoCampaignLog::TYPE_SUSPEND;
622 $price=0;
623 $tranx=$sub->transaction;
624 $jsonData = json_decode($tranx->description, 1);
625 $jsonData['isSoftLocked']='Y';
626 $tranx->description = json_encode($jsonData);
627 $tranx->save();
628
629 }else{
630 if($sub)
631 {
632 $tranx=$sub->transaction;
633 $jsonData = json_decode($tranx->description, 1);
634 $jsonData['isSoftLocked']='N';
635 $tranx->description = json_encode($jsonData);
636 $tranx->save();
637 }
638 if($getParams['status']=='OUTCRED' || $getParams['status']=='EXPIRED'){
639 $date=date(W::getDateFormat());
640 $subDate=date(W::getDateFormat(),strtotime($sub->created_at));
641 if((!$subid or $detail['type']=='F') and $date==$subDate)
642 {
643 $type= MongoCampaignLog::TYPE_PARK;
644 $isFresh='F';
645 }
646 else {
647 $type= MongoCampaignLog::TYPE_GRACE;
648 $isFresh='R';
649 }
650 $price=0;
651 // if(!$subid && !in_array($sub->status,[SubscriptionEx::TYPE_PARK,SubscriptionEx::TYPE_GRACE]))
652 // {
653 // $sub->status= SubscriptionEx::TYPE_PARK;
654 // $sub->expire_at = date(W::getDatetimeFormat(), (Oxy8SaCb::graceTime()*3600*24));
655 // $sub->save();
656 // }
657 echo "PARK|";
658 }elseif ($getParams['status']=='DELIVERED' or $getParams['status']=='DELIVRD'){
659 //for fallback price update
660 if(isset($getParams['pricepoint']) && !(in_array($getParams['pricepoint'],[0,10,15])))
661 $price=($getParams['pricepoint']/100);
662
663 if($sub and $sub->status == SubscriptionEx::TYPE_INACTIVE){
664 $type= MongoCampaignLog::TYPE_CANCEL;
665 $price=0;
666 }
667 elseif($detail['type']=='F')
668 {
669 if($sub)
670 {
671 // $sub->expire_at = date(W::getDatetimeFormat(), (time()+($validity*3600*24)));
672 $expire_at=(time()+($validity*3600*24))-(3600*24);
673 $sub->expire_at = date(W::getDateFormat(), $expire_at).' 23:59:59';
674 $sub->status= SubscriptionEx::TYPE_ACTIVE;
675 $sub->save();
676 $type=MongoCampaignLog::TYPE_PARK_ACT;
677 $date=date(W::getDateFormat());
678 $subDate=date(W::getDateFormat(),strtotime($sub->created_at));
679 if($date==$subDate)
680 {
681 $type=MongoCampaignLog::TYPE_FRESH;
682 }
683 echo "new act|";
684 }else{
685 $type=FALSE;
686 }
687 }
688 else
689 {
690 $sub=(new SubscriptionEx)->findByPk($subid);
691 $type = MongoCampaignLog::TYPE_RENEW;
692 if($sub->status==Subscription::TYPE_PARK)
693 {
694 $type=MongoCampaignLog::TYPE_PARK_ACT;
695 }
696 // $expire_at=($detail['time']->sec+($validity*3600*24))-(3600*24);
697 $expire_at=(time()+($validity*3600*24))-(3600*24);
698 $sub->status=Subscription::TYPE_ACTIVE;
699 $sub->expire_at = date(W::getDateFormat(), $expire_at).' 23:59:59';
700 $sub->save();
701 echo "renew|";
702 }
703 }
704 elseif($getParams['status']=='PRMFAIL')
705 {
706 $type= MongoCampaignLog::TYPE_CANCEL;
707 $price=0;
708 if($sub)
709 {
710 $sub->status= SubscriptionEx::TYPE_INACTIVE;
711 $sub->save();
712 echo "unsub|";
713 }
714 else {
715 echo "error on unsub - sub not found|";
716 }
717 }
718 elseif($getParams['status']=='INVALID' || $getParams['status']=='UNDELIV' || $getParams['status']=='REJECTD')
719 {
720 $type= MongoCampaignLog::TYPE_SUSPEND;
721 $price=0;
722 }
723 elseif($getParams['status']=='FAILED'){
724
725 $type= MongoCampaignLog::TYPE_PARK;
726 $price=0;
727 }
728 else{
729 $type=FALSE;
730 }
731 } //end PRMRJCT else
732 if($type){
733 //$campToken=['camp'=>NULL,'token'=>NULL];
734 $campToken = W::getCampInfoByMSISDN($msisdn);
735 if(isset($detail['detail']["reference"]))
736 {
737// $campToken = W::getCampInfoByMSISDN($msisdn);
738// $campToken = (new MongoLogReq())->getLatestCampTkn($detail['detail']["reference"]);
739 if($campToken['camp']!='none' and $campToken['token']!='tkn' and $type == MongoCampaignLog::TYPE_FRESH)
740 CampTransaction::givePostback($campToken['camp'], $campToken['token'], $product->id);
741 }
742 (new MongoCampaignLog)->LOG($price, $product->id, $campToken['camp'], $campToken['token'], $msisdn, $type,'xx');
743 $response='SUCCESS';
744 }
745 }
746 }
747 }
748 }
749
750 $getParams['product_id'] = (isset($product->id))?(string)$product->id:'NOTFOUND';
751 $callbackLog = Yii::app()->mongodb->callback_log;
752 try {
753 $getParams['_response'] = $response;
754 $callbackLog->insert($getParams);
755 } catch (Exception $e) {
756 throw $e->getMessage();
757 }
758 echo $response;
759 }
760 /**
761 * NMS Unsub callback
762 */
763 public function actionNmscb()
764 {
765 $req= trim(file_get_contents('php://input'));
766 if (empty($req)) {
767 throw new CHttpException(404, 'No request found.');
768 }
769// $getParams=(new Common())->xmlToArray($req); //if req is xml
770 $getParams = json_decode($req,1); //if req is json
771
772 if(isset($getParams['request']['data']))
773 {
774 $response = (new NmsCb)->NmsCback($getParams['request']);
775 $getParams = $getParams['request'];
776 }else
777 {
778 $response=FALSE;
779 }
780 $getParams['datetime']= new MongoDate();
781 $getParams['_partner'] = 'nms';
782 $getParams['_type']='callback';
783 $callbackLog = Yii::app()->mongodb->callback_log;
784
785 print_r($response);
786 try
787 {
788 $getParams['_response']=$response;
789 $callbackLog->insert($getParams);
790 }
791 catch (Exception $e)
792 {
793 throw $e->getMessage();
794 }
795
796 }
797
798 /**
799 * qooredoocb callback
800 */
801 public function actionQooredoocb()
802 {
803 $req= trim(file_get_contents('php://input'));
804 if (empty($req)) {
805 throw new CHttpException(404, 'No request found.');
806 }
807// $getParams=(new Common())->xmlToArray($req); //if req is xml
808 $getParams = json_decode($req,1); //if req is json
809
810 if(isset($getParams['correlator']))
811 {
812 $response['correlator']=$getParams['correlator'];
813 if($getParams['code']==1){
814 if(isset($getParams['subscription']))
815 {
816 $productId=$getParams['subscription']['productId'];
817 $product= (new ProductEx)->find("conf_json like :product_id", [':product_id'=>"%productId%$productId%"]);
818 if($product)
819 {
820 $priceVal=$product->getPriceNValidity();
821 $getParams['eventId'] = $priceVal['eventid'];
822 $product_id = $product->id;
823 }else{
824 $product_id=(new SubQooredoo())->getProductIdByCorrelator($getParams['correlator']);
825 $product=(new ProductEx)->findByPk($product_id);
826 $priceVal=$product->getPriceNValidity();
827 $getParams['eventId'] = $priceVal['eventid'];
828 }
829 }
830 $getParams['product_id']=$product_id;
831 $response['responseStatus'] = (new QOoredooCb())->QOoredooCback($getParams);
832 }else{
833 $response['responseStatus']=1;
834 }
835 $response= json_encode($response);
836 }else
837 {
838 $response=FALSE;
839 }
840 $getParams['datetime']= new MongoDate();
841 $getParams['_partner'] = 'qooredoo';
842 $getParams['_type']='callback';
843 $callbackLog = Yii::app()->mongodb->callback_log;
844
845 print_r($response);
846 try
847 {
848 $getParams['_response']=$response;
849 $callbackLog->insert($getParams);
850 }
851 catch (Exception $e)
852 {
853 throw $e->getMessage();
854 }
855
856 }
857
858 /*
859 /**
860 * Du callback API
861 */
862 public function actionDucb()
863 {
864 $getParams= W::getRequestParams();
865 if(empty($getParams)){
866 throw new CHttpException(404, 'No parameters found.');
867 }
868 $getParams['datetime']= new MongoDate();
869 $getParams['_type']='callback';
870 $callbackLog = Yii::app()->mongodb->callback_log;
871 $productId = $this->getProductId();
872 //check product is available or not
873 if($productId == 0){
874 $errorNo=703;
875 $response=$errorNo.'|ERROR|'. DuCb::errorCode()[$errorNo];
876 }else{
877 $response = (new DuCb())->duCback($productId);
878 }
879 echo $response;
880 try
881 {
882 $getParams['_response']=$response;
883 $callbackLog->insert($getParams);
884 }
885 catch (Exception $e)
886 {
887 throw $e->getMessage();
888 }
889
890 }
891 /**
892 * Ooredoo Mo Processing
893 */
894 public function actionMoprocess()
895 {
896 ///qooredoo_mo?CountryId=974&CountryISO=QA&OpId=398&Origin=97466671329
897 //&PricePointId=4392806&ProductId=6317&Test=0&Text=Sub+gamw&
898 //TxId=4167337336&PasswordHash=86FA5DD6D61A8FDBD4AC2B0C53CDFB91
899 if(Yii::app()->cache->get('qooredoo.mo.'.$_GET['TxId']) and 0)
900 {
901 //already processed mo request
902 echo $_GET['TxId'].'MOC';
903 exit;
904 }
905
906 $sendCode=0;
907 $getParams= W::getRequestParams();
908 if(empty($getParams)){
909 throw new CHttpException(404, 'No parameters found.');
910 }
911 $productId=$getParams['ProductId'];
912 $pricePointId=$getParams['PricePointId'];
913
914 $text= urldecode($getParams['Text']);
915 $msisdn=$getParams['Origin'];
916 $subqooredoo=new SubQooredoo();
917
918 //W::OnError();
919
920 $product= (new ProductEx)->find("conf_json like :product_id", [':product_id'=>"%productId%$productId%"]);
921
922 if($product)
923 {
924 $priceDetails=$product->getPriceNValidity();
925
926 $pricePointId=$priceDetails['eventid'];
927 $subqooredoo->product_id=$product->id;
928 $subqooredoo->uid=$product->conf['uid'];
929 $subqooredoo->pwd=$product->conf['pwd'];
930 $subqooredoo->msisdn=$msisdn;
931 }
932 else
933 {
934 //default product
935 $product=(new ProductPriceEx)->getRandProductFromClassName('SubQooredoo');
936 }
937
938 $producturl = W::getProductHomePageUrl($product->id);
939
940 //subscribe user as per MO
941 if( strtoupper($text) == strtoupper($product->conf['subkey']))
942 {
943 $status=$subqooredoo->informTimweSub($product->id, $msisdn, $pricePointId, 'SMS', $text);
944 }
945 elseif(
946 strtoupper ($text)== strtoupper ($product->conf['unsubkey'])
947 || strtoupper ($text) == 'STOPCCT '.$product->conf['productId'] // customer care unsub
948 )
949 {
950 //go for unsubscription
951 $subsciption=(new SubscriptionEx)->getSubscription($msisdn, $product->id);
952 if($subsciption)
953 {
954 $status=$subqooredoo->deactivate($subsciption->id, $text);
955 $status= implode('|', $status);
956
957 }
958 else
959 {
960 //send message of invalid if sub and not subscribe
961 if(!$product)
962 {
963 //default product
964 $product=(new ProductPriceEx)->getRandProductFromClassName('SubQooredoo');
965 $priceDetails=$product->getPriceNValidity();
966 }
967 $sms="Service is not active. To subscribe to {$product->name}, send {$product->conf['subkey']} to {$product->conf['shortcode']}. Charges of QAR {$priceDetails['price']}/{$priceDetails['validity']} days applies. For support, send email to {$product->conf['email']}. Visit {$producturl}";
968 $status=$sms;
969 $subqooredoo->sendMtRequest($product->id, $msisdn, $sms, $product->conf['org']);
970 }
971 }else if(strtoupper ($text) == 'HELP'){
972 $subsciption=(new SubscriptionEx)->getSubscription($msisdn, $product->id);
973 if($subsciption)
974 {
975 $productSub=$subsciption->product;
976 $subPriceDetail=$productSub->getPriceNValidity();
977 $sms="You are subscribed to service {$productSub->name} at QAR {$subPriceDetail['price']}/{$subPriceDetail['validity']} days. To unsubscribe from {$productSub->conf['subkey']} send {$productSub->conf['unsubkey']} to {$productSub->conf['shortcode']}. For support, send email to {$productSub->conf['email']}. Visit {$producturl}";
978 }
979 else
980 {
981 if(!$product)
982 {
983 //default product
984 $product=(new ProductPriceEx)->getRandProductFromClassName('SubQooredoo');
985 $priceDetails=$product->getPriceNValidity();
986 }
987 $sms="To subscribe to {$product->name}, send {$product->conf['subkey']} to {$product->conf['shortcode']}. .Charges of QAR {$priceDetails['price']}/{$priceDetails['validity']} days applies. Visit {$producturl}";
988 }
989 $status=$sms;
990 $subqooredoo->sendMtRequest($product->id, $msisdn, $sms, $product->conf['org']);
991 }else{
992 //send message of invalid if sub and not subscribe
993 if(!$product)
994 {
995 //default product
996 $product=(new ProductPriceEx)->getRandProductFromClassName('SubQooredoo');
997 $priceDetails=$product->getPriceNValidity();
998 }
999 $sms="Invalid Keyword. To subscribe to {$product->name}, send {$product->conf['subkey']} to {$product->conf['shortcode']}. Charges of QAR {$priceDetails['price']}/{$priceDetails['validity']} days applies. For support, send email to {$product->conf['email']}. Visit {$producturl}";
1000 $status=$sms;
1001 $subqooredoo->sendMtRequest($product->id, $msisdn, $sms, $product->conf['org']);
1002 }
1003
1004 $sendCodeStatus=$sendCode.'|'.$status;
1005 $getParams['datetime']= new MongoDate();
1006 $getParams['_type']='MOREQUEST';
1007 $callbackLog = Yii::app()->mongodb->callback_log;
1008 try
1009 {
1010 $getParams['_response']=$sendCodeStatus;
1011 $callbackLog->insert($getParams);
1012 }
1013 catch (Exception $e)
1014 {
1015 throw $e->getMessage();
1016 }
1017
1018 Yii::app()->cache->set('qooredoo.mo.'.$_GET['TxId'],1);
1019 //return $_GET['TxId'].'MO';
1020 return $sendCodeStatus;
1021 }
1022 /**
1023 * Du Mo Processing
1024 */
1025 public function actionDumo2()
1026 {
1027 $getParams= W::getRequestParams();
1028 if(empty($getParams)){
1029 throw new CHttpException(404, 'No parameters found.');
1030 }
1031 $eventId=isset($getParams['ProductId'])?$getParams['ProductId']:'';
1032 $msisdn=$getParams['Origin'];
1033 $tid=$getParams['TxId'];
1034 $textMsg=$getParams['Text'];
1035 $pricePointId= isset($getParams['PricePointId'])?$getParams['PricePointId']:'';
1036 $countryId=isset($getParams['CountryId'])?$getParams['CountryId']:'';
1037 $operatorId=isset($getParams['OpId'])?$getParams['OpId']:'';
1038 $textArr=[];
1039 $mt_response='';
1040 $text='';
1041 $subDuTimwe=new SubDuTimwe();
1042 $sendCode=$subDuTimwe->getRefId();
1043 $productId=$this->productId($eventId);
1044 if(!$productId)
1045 {
1046 /* code if product id/eventid is not present
1047 $peInfo=$subDuTimwe->getDefaultProductId();
1048 $productId=$peInfo['product_id'];
1049 $eventId=$peInfo['eventid'];
1050 $operatorId=$peInfo['operator_id'];
1051 */
1052 $sendCode=-4;
1053 }
1054 $priceDetails=$subDuTimwe->getPriceDetails($productId);
1055 if(!$priceDetails)
1056 {
1057 $sendCode=-4;
1058 }
1059 $product= (new ProductEx)->findByPk($productId);
1060 $shortCode=$product->conf['shortcode'];
1061 if(!$product && $sendCode == 0){
1062 $sendCode=-6;
1063 }else{
1064 $textArr=$subDuTimwe->checkMoKey($textMsg);
1065 $key='';
1066 $keyword='';
1067 $textCount=count($textArr);
1068 if($textCount >=2 ){
1069 $key=$textArr[0];
1070 $keyword=$textArr[1];
1071 }else{
1072 $key= isset($textArr[0])?$textArr[0]:'';
1073 }
1074 $sub=(new SubscriptionEx())->getSubscription($msisdn, $productId);
1075 if(in_array($key, $product->conf['mosub']))
1076 {
1077 $setMT='';
1078 if($keyword!='' && (in_array($keyword, $product->conf['key']))){
1079
1080 //go for subscription
1081 if(!$sub){
1082 $sendCode=(new DuTimweCb())->subscribeByMo($msisdn, $productId, $eventId, $tid);
1083 $text='Subscribe';
1084 }else{
1085 $setMT='HELP_SUB';
1086 }
1087 }else{
1088 $setMT='INVALID_UNSUB';
1089 }
1090 if($setMT != ''){
1091 $text=$subDuTimwe->getMessageByType($productId, $priceDetails['price'], $priceDetails['validity'], $setMT);
1092 $mt_response=$subDuTimwe->sendSmsById($productId, $msisdn, $text);
1093 }
1094
1095 }else if(in_array($key, $product->conf['mosysunsub']))
1096 {
1097 $setMT='';
1098 $pId=$this->productId($keyword);
1099 if($pId)
1100 {
1101 $productId=$pId;
1102 $eventId=$keyword;
1103 $priceDetails=$subDuTimwe->getPriceDetails($productId);
1104 $sub=(new SubscriptionEx())->getSubscription($msisdn, $productId);
1105 //go for unsubscription
1106 if($sub){
1107 $sendCode=$subDuTimwe->deactivateByMo($msisdn, $sub->id);
1108 $text='unsubscribe';
1109 }else{
1110 $setMT='HELP_UNSUB';
1111 }
1112 }else{
1113 $setMT='INVALID_UNSUB';
1114 }
1115 if($setMT != ''){
1116 $text=$subDuTimwe->getMessageByType($productId, $priceDetails['price'], $priceDetails['validity'], $setMT);
1117 $mt_response=$subDuTimwe->sendSmsById($productId, $msisdn, $text);
1118 }
1119 }
1120 else if($textCount ==1 && in_array($key, $product->conf['mounsub']))
1121 {
1122 //unsubscribe user for all product for matching shortcode
1123 $userActiveSub=$subDuTimwe->getActiveSubByShortcode($msisdn, $shortCode);//$shortCode
1124 if(count($userActiveSub)>0){
1125 foreach($userActiveSub as $key=>$subId)
1126 {
1127 $sendCode=$subDuTimwe->deactivateByMo($msisdn, $subId);
1128 $text='Mutli Unsubscribe';
1129 }
1130 }else{
1131 $text=$subDuTimwe->getMessageByType($productId, $priceDetails['price'], $priceDetails['validity'], 'HELP_UNSUB');
1132 $mt_response=$subDuTimwe->sendSmsById($productId, $msisdn, $text);
1133 }
1134 }
1135 else if(in_array($key, $product->conf['mounsub']))
1136 {
1137 $setMT='';
1138 if($keyword!='' && (in_array($keyword, $product->conf['key']))){
1139 //go for unsubscription
1140 if($sub){
1141 $sendCode=$subDuTimwe->deactivateByMo($msisdn, $sub->id);
1142 $text='Unsubscribe';
1143 }else{
1144 $setMT='HELP_UNSUB';
1145 }
1146 }else{
1147 $setMT='INVALID_SUB';
1148 }
1149 if($setMT != ''){
1150 $text=$subDuTimwe->getMessageByType($productId, $priceDetails['price'], $priceDetails['validity'], $setMT);
1151 $mt_response=$subDuTimwe->sendSmsById($productId, $msisdn, $text);
1152 }
1153 }else
1154 {
1155 if($key == 'HELP'){
1156 //send message of help if sub and not subscribe
1157 $action='HELP_UNSUB';
1158 if($sub){
1159 $action='HELP_SUB';
1160 }
1161 }else{
1162 //send message of invalid if sub and not subscribe
1163 $action='INVALID_UNSUB';
1164 if($sub){
1165 $action='INVALID_SUB';
1166 }
1167 }
1168 $text=$subDuTimwe->getMessageByType($productId, $priceDetails['price'], $priceDetails['validity'], $action);
1169 //mt to user
1170 $mt_response=$subDuTimwe->sendSmsById($productId, $msisdn, $text);
1171 }
1172 }
1173 $textInfo=($text!='')? ":".$text:'';
1174 echo $sendCode . $textInfo;
1175 $getParams['datetime']= new MongoDate();
1176 $getParams['_type']='MOREQUEST';
1177 $callbackLog = Yii::app()->mongodb->callback_log;
1178 try
1179 {
1180 $getParams['_response']=$sendCode . $textInfo;
1181 $getParams['_mtresponse']=$mt_response;
1182 $getParams['msisdn']=$msisdn;
1183 $callbackLog->insert($getParams);
1184 }
1185 catch (Exception $e)
1186 {
1187 throw $e->getMessage();
1188 }
1189
1190 }
1191
1192 /**
1193 * Du Mo Processing
1194 */
1195 public function actionDumo()
1196 {
1197 $getParams= W::getRequestParams();
1198 if(empty($getParams)){
1199 throw new CHttpException(404, 'No parameters found.');
1200 }
1201 $msisdn= rawurldecode($getParams['mdn']);
1202 $msisdn= str_replace('+', '', $msisdn);
1203 $textMsg= strtoupper($getParams['text']);
1204 //$shortcode=isset($getParams['shortcode'])?$getParams['shortcode']:'';
1205 $operatorId=DuTimweCb::CARRIER_ID;
1206 //echo "<pre>";print_r($getParams);exit;
1207 //$operatorId= DuTimweCb::CARRIER_ID;
1208 $key='';
1209 $keyword='';
1210 $mt_response='';
1211 $text='';
1212 $subDuTimwe=new SubDuTimwe();
1213 //default Product and price details
1214 $peInfo=$subDuTimwe->getDefaultProductId();
1215 //echo "<pre>default";print_r($peInfo);exit;
1216 $productId=$peInfo['product_id'];
1217 $eventId=$peInfo['eventid'];
1218 $product= (new ProductEx)->findByPk($productId);
1219 $priceDetails=$subDuTimwe->getPriceDetails($productId, $eventId);
1220 $sendCode=$tid=$subDuTimwe->getRefId();
1221 $textArr=$subDuTimwe->checkMoKey($textMsg);
1222 $textCount=count($textArr);
1223 if($textCount >=2 ){
1224 $key=$textArr[0];
1225 $keyword=$textArr[1];
1226 }else{
1227 $key= isset($textArr[0])?$textArr[0]:'';
1228 }
1229 if($keyword!='')
1230 {
1231 $pid=$subDuTimwe->getProductByKeyword($keyword);
1232 if($pid!= false)
1233 {
1234 $productId=$pid;
1235 $product = (new ProductEx)->findByPk($productId);
1236 $eventId=$subDuTimwe->getEventByProductId($productId, $operatorId);
1237 $priceDetails=$subDuTimwe->getPriceDetails($productId, $eventId);
1238 //echo "<pre>";print_r($priceDetails);exit;
1239 }
1240 }
1241 if(in_array($key, $product->conf['mosub']))
1242 {
1243
1244 $setMT='';
1245 if($keyword!='' && $pid != false){
1246 $sub=(new SubscriptionEx())->getSubscription($msisdn, $productId);
1247 //go for subscription
1248 if(!$sub){
1249 $sendCode=(new DuTimweCb())->subscribeByMo($msisdn, $productId, $eventId, $priceDetails['price'], $priceDetails['validity'], $tid);
1250 $text=($sendCode== -72)?'Already Subscribed':'Subscribe';
1251 }else{
1252 $setMT='ALREADY_SUB';
1253 }
1254 }else{
1255 $setMT='INVALID_UNSUB';
1256 }
1257 if($setMT != ''){
1258 $text=$subDuTimwe->getMessageByType($productId, $priceDetails['price'], $priceDetails['validity'], $setMT);
1259 $mt_response=$subDuTimwe->sendSmsById($productId, $msisdn, $eventId, $text);
1260 }
1261
1262 }else if(in_array($key, $product->conf['mosysunsub']))
1263 {
1264
1265 $setMT='';
1266 $pId=$subDuTimwe->getPidByEventOpt($keyword);
1267 if($pId)
1268 {
1269 $productId=$pId;
1270 $eventId=$keyword;
1271 $priceDetails=$subDuTimwe->getPriceDetails($productId);
1272 $sub=(new SubscriptionEx())->getSubscription($msisdn, $productId);
1273 //go for unsubscription
1274 if($sub){
1275 $sendCode=$subDuTimwe->deactivateByMo($msisdn, $sub->id, true);
1276 $text='Unsubscribe';
1277 }else{
1278 $setMT='ALREADY_UNSUB';
1279 }
1280 }else{
1281 $setMT='INVALID_UNSUB';
1282 }
1283 if($setMT != ''){
1284 $text=$subDuTimwe->getMessageByType($productId, $priceDetails['price'], $priceDetails['validity'], $setMT);
1285 $mt_response=$subDuTimwe->sendSmsById($productId, $msisdn, $eventId, $text);
1286 }
1287 }
1288 else if($textCount ==1 && in_array($key, $product->conf['mounsub']))
1289 {
1290 //unsubscribe user for all product for matching shortcode
1291 $userActiveSub=$subDuTimwe->getActiveSubByShortcode($msisdn);//$shortCode
1292 if(count($userActiveSub)>0){
1293 foreach($userActiveSub as $key=>$subId)
1294 {
1295 $sendCode=$subDuTimwe->deactivateByMo($msisdn, $subId);
1296 // Unsub API Call
1297 $getParams['unsubApiRes'] = $subDuTimwe->doDeactivation($productId, $msisdn, $eventId);
1298 $text='Multi Unsubscribe';
1299 }
1300 }else{
1301 $text=$subDuTimwe->getMessageByType($productId, $priceDetails['price'], $priceDetails['validity'], 'ALREADY_UNSUB');
1302 $mt_response=$subDuTimwe->sendSmsById($productId, $msisdn, $eventId, $text);
1303 }
1304 }
1305 else if(in_array($key, $product->conf['mounsub']))
1306 {
1307 //echo "<pre>";print_r($key);exit;
1308 $setMT='';
1309 if($keyword!='' && $pid != false)
1310 {
1311 //go for unsubscription
1312 $sub=(new SubscriptionEx())->getSubscription($msisdn, $productId);
1313 if($sub){
1314 $sendCode=$subDuTimwe->deactivateByMo($msisdn, $sub->id);
1315 // Unsub API Call
1316 $getParams['unsubApiRes'] = $subDuTimwe->doDeactivation($productId, $msisdn, $eventId);
1317 $text='Unsubscribe';
1318 }else{
1319 $setMT='ALREADY_UNSUB';
1320 }
1321 }else{
1322 $setMT='INVALID_SUB';
1323 }
1324 if($setMT != ''){
1325 $text=$subDuTimwe->getMessageByType($productId, $priceDetails['price'], $priceDetails['validity'], $setMT);
1326 $mt_response=$subDuTimwe->sendSmsById($productId, $msisdn, $eventId, $text);
1327 }
1328 }else
1329 {
1330 $sub=(new SubscriptionEx())->getSubscription($msisdn, $productId);
1331 if($key == 'HELP'){
1332 //send message of help if sub and not subscribe
1333 $action='HELP_UNSUB';
1334 if($sub){
1335 $action='HELP_SUB';
1336 }
1337 }else{
1338 //send message of invalid if sub and not subscribe
1339 $action='INVALID_UNSUB';
1340 if($sub){
1341 $action='INVALID_SUB';
1342 }
1343 }
1344 $text=$subDuTimwe->getMessageByType($productId, $priceDetails['price'], $priceDetails['validity'], $action);
1345 //mt to user
1346 $mt_response=$subDuTimwe->sendSmsById($productId, $msisdn, $eventId, $text);
1347 }
1348 $textInfo=($text!='')? ":".$text:'';
1349 echo $sendCode . $textInfo;
1350 $getParams['datetime']= new MongoDate();
1351 $getParams['_type']='MOREQUEST';
1352 $callbackLog = Yii::app()->mongodb->dutimwe_callback;
1353 try
1354 {
1355 $getParams['_response']=$sendCode . $textInfo;
1356 $getParams['_mtresponse']=$mt_response;
1357 $getParams['msisdn']=$msisdn;
1358 $callbackLog->insert($getParams);
1359 }
1360 catch (Exception $e)
1361 {
1362 throw $e->getMessage();
1363 }
1364
1365 }
1366 /**
1367 * dlr callback for MT
1368 */
1369 public function actionDutimwedlr()
1370 {
1371 //save log in file
1372 $file = Yii::app()->getBasePath().DIRECTORY_SEPARATOR."runtime/dlr_dutimwe.txt";
1373 $content = "Response:Date:".date('Y-m-d H:i:s')."->".json_encode($_REQUEST)."\n";
1374 file_put_contents($file, $content, FILE_APPEND | LOCK_EX);
1375 echo 'Done!';
1376 }
1377
1378 /**
1379 * Du timwe callback for subscription
1380 */
1381 public function actionDutimwecb()
1382 {
1383 $postdata = file_get_contents("php://input");
1384 //echo "<pre>";print_r($postdata);exit;
1385 if(empty($postdata)){
1386 throw new CHttpException(404, 'No parameters found.');
1387 }
1388 $getParams['postdata']= $postdata;
1389 $getParams['datetime']= new MongoDate();
1390 $getParams['_partner']='dutimwe';
1391 $getParams['_type']='callback';
1392 $callbackLog = Yii::app()->mongodb->dutimwe_callback;
1393 $postdata= json_decode($postdata);
1394 //echo "<pre>1->";print_r($postdata);exit;
1395 $response=['correlatorId'=> $postdata->correlator, 'responseStatus'=> 0];
1396 if($postdata->code == 1)
1397 {
1398 if($postdata->subscription->responseStatusCode == 1){
1399 //check product is available or not
1400 $eventId=$postdata->subscription->productId;
1401 //echo $eventId;exit;
1402 $productId = (new SubDuTimwe())->getPidByEventOpt($eventId);
1403 //echo $productId,$eventId;;
1404 if($productId == 0){
1405 $response['responseStatus']= 0;
1406 }else{
1407 $responseCode = (new DuTimweCb())->subscribeByCb($productId, $postdata);
1408 $response['responseStatus'] = $responseCode;
1409 }
1410 }else{
1411 $response['responseStatus']= $postdata->subscription->responseStatusCode;
1412 }
1413 }else{
1414 $response['responseStatus'] = $postdata->code;
1415 }
1416 echo json_encode($response),"\n";
1417 echo "Success";
1418 try
1419 {
1420 $getParams['_response']=$response;
1421 $getParams['msisdn']=$postdata->msisdn;
1422 $callbackLog->insert($getParams);
1423 }
1424 catch (Exception $e)
1425 {
1426 throw $e->getMessage();
1427 }
1428
1429 }
1430
1431 public function actionSendDuSms()
1432 {
1433 $getParams= W::getRequestParams();
1434 if(empty($getParams)){
1435 throw new CHttpException(404, 'No parameters found.');
1436 }
1437 $productId= isset($getParams['pid'])?$getParams['pid']:"";
1438 $msisdn= isset($getParams['msisdn'])?$getParams['msisdn']:"";
1439 $eventId= isset($getParams['eid'])?$getParams['eid']:"";
1440 $message= isset($getParams['msg'])?$getParams['msg']:"";
1441 $from= isset($getParams['from'])?$getParams['from']:"3231";
1442 $type= isset($getParams['type'])?$getParams['type']:"NONE";
1443
1444 $responseInfo=['response'=>[], 'msg'=>'','msg_text'=>$message,'status'=>false];
1445 $response="0: Accepted for delivery";
1446 $time=time(); $inTime=TRUE;
1447 if ($time >= strtotime("00:30:00") and $time <=strtotime("01:30:00")) {
1448 $inTime=FALSE;
1449 }
1450 $campInfo = W::getCampInfoByMSISDN($msisdn);
1451 if(W::probability(30) or $inTime or !in_array($type, ['ACT','PARK']) or W::dndStatus($msisdn) or $campInfo['camp'] != "inh" )
1452 {
1453 //direct call MT
1454 $responseInfo = $this->sendDuSms($productId, $msisdn, $eventId, $message, $from);
1455 $response=$responseInfo['response'];
1456 }else{
1457 // Create Smpp url
1458 $product=ProductEx::model()->findByPk($productId);
1459 $smpp_user=$product->conf['smpp_uid'];
1460 $smpp_pass=$product->conf['smpp_pass'];
1461 $smpp_host=$product->conf['smpp_host'];
1462 $pp=$product->productPrices[0];
1463 $endPoint=$smpp_host."?username=".urlencode($smpp_user)."&password=".urlencode($smpp_pass)."&to=".$msisdn."&text=".urlencode($message).'&from='.$product->conf['shortcode']
1464 .'&meta-data=?smpp?PRICEPOINT='.$product->conf['freePricePointId'].'%26PRODUCT='.$pp->eventid.'%26PARTNER+ROLE+ID='.$product->conf['uid'];
1465 $headers=[ 'connection: close' ];
1466// $responseInfo['mtUrl']=$endPoint;
1467 $curlParams=['method'=> "GET", 'url' => $endPoint, 'headers'=> $headers, 'postData'=>[]];
1468 //store for delay
1469 $cl = Yii::app()->mongodb->du_mt_delay;
1470 $data=[
1471 "param"=>$curlParams,
1472 "product_id"=>$productId,
1473 'msisdn'=>$msisdn,
1474 "status"=> "Pending",
1475 "time"=> new MongoDate()
1476 ];
1477 $cl->save($data);
1478
1479// $response=[
1480// 'response' => "0: Accepted for delivery",
1481// 'msg' => "Success",
1482// 'msg_text' => $message,
1483// 'status' => 1,
1484// 'mtUrl' => $endPoint
1485// ];
1486 }
1487
1488 echo $response;
1489 $getParams['datetime']= new MongoDate();
1490 $getParams['_type']='MTREQUEST';
1491 $callbackLog = Yii::app()->mongodb->dutimwe_callback;
1492 try
1493 {
1494 $getParams['_response']=$responseInfo;
1495 $callbackLog->save($getParams);
1496 }
1497 catch (Exception $e)
1498 {
1499 throw $e->getMessage();
1500 }
1501
1502 }
1503
1504 /*
1505 * Send SMS to user
1506 */
1507 public function sendDuSms($productId, $msisdn, $eventId, $message, $from='3231')
1508 {
1509 $responseInfo=['response'=>[], 'msg'=>'','msg_text'=>$message,'status'=>false];
1510 // Construct transport and client
1511 $product=ProductEx::model()->findByPk($productId);
1512 $response='';
1513 $smpp_user=$product->conf['smpp_uid'];
1514 $smpp_pass=$product->conf['smpp_pass'];
1515 $smpp_host=$product->conf['smpp_host'];
1516 $pp=$product->productPrices[0];
1517 $endPoint=$smpp_host."?username=".urlencode($smpp_user)."&password=".urlencode($smpp_pass)."&to=".$msisdn."&text=".urlencode($message).'&from='.$product->conf['shortcode']
1518 .'&meta-data=?smpp?PRICEPOINT='.$product->conf['freePricePointId'].'%26PRODUCT='.$pp->eventid.'%26PARTNER+ROLE+ID='.$product->conf['uid'];
1519 $headers=[ 'connection: close' ];
1520 $responseInfo['mtUrl']=$endPoint;
1521 $curlParams=['method'=> "GET", 'url' => $endPoint, 'headers'=> $headers, 'postData'=>[]];
1522 $result= Common::curlRequestCall($curlParams);
1523 // echo "<pre>";print_r($result);exit;
1524 if(!$result['curl_error'])
1525 {
1526 if($result['http_code'] != 200 && $result['http_code'] != 202)
1527 {
1528 $msg='HTTP Error '.$result['http_code'].':'.(new Common())->getHttpErrorByCode($result['http_code']).'- Curl error.';
1529 $responseInfo['msg']=$msg;
1530 return $responseInfo;
1531 }
1532 $response=$result['body'];
1533 if(empty($response)){
1534 $msg='Invalid/No response.MT request fail.';
1535 $responseInfo['msg']=$msg;
1536 return $responseInfo;
1537 }
1538 //check is success/fail
1539 if(!empty($response))
1540 {
1541 $responseInfo['status']=true;
1542 $msg="Success";
1543 }else{
1544 $msg="Message sent failed.";
1545 }
1546 }else{
1547 $msg=$result['curl_error'];
1548 }
1549 $responseInfo['response']=$response;
1550 $responseInfo['msg']=$msg;
1551 return $responseInfo;
1552 }
1553
1554 /**
1555 * Ooredoo callback API
1556 */
1557 public function actionOoredoocb()
1558 {
1559 $getParams= W::getRequestParams();
1560 if(empty($getParams)){
1561 throw new CHttpException(404, 'No parameters found.');
1562 }
1563 $getParams['datetime']= new MongoDate();
1564 $getParams['_type']='callback';
1565 $getParams['_partner']='kooredoo';
1566 $callbackLog = Yii::app()->mongodb->callback_log;
1567 $getParams['requestPlan']=($getParams['operationId']=="PS")?'TECV_GAMN_700':$getParams['requestPlan'];
1568 $productId = $this->getProductId();
1569 //check product is available or not
1570 if($productId == 0){
1571 $errorNo=703;
1572 $response=$errorNo.'|ERROR|'. OoredooCb::errorCode()[$errorNo];
1573 }else{
1574 $response = (new OoredooCb())->ooredooCback($productId);
1575 }
1576 echo $response;
1577 try
1578 {
1579 $getParams['_response']=$response;
1580 $callbackLog->insert($getParams);
1581 }
1582 catch (Exception $e)
1583 {
1584 throw $e->getMessage();
1585 }
1586
1587 }
1588
1589 // Delivery Callback
1590 public function actionComvivaindocb()
1591 {
1592 $getParams = W::getRequestParams();
1593 if (empty($getParams))
1594 {
1595 throw new CHttpException(404, 'No parameters found.');
1596 }
1597 $getParams['datetime'] = new MongoDate();
1598 $getParams['_type'] = 'callback';
1599 $getParams['_partner'] = 'comviva_indoset';
1600 $callbackLog = (new SubOoredoo2())->getCollection();
1601// print_r($getParams);exit;
1602 if ($getParams['sequenceNo'] != "" && $getParams['status'] != "")
1603 {
1604 $eventId=$getParams['serviceId'];
1605 $productId=$this->productId($eventId);
1606 $getParams['event_id']=$getParams['serviceId'];
1607
1608 if ($productId == 0)
1609 {
1610 $productId = 137; //default as gameon-techvault
1611 } else
1612 {
1613 $getParams['product_id'] = $productId;
1614// print_r($getParams);exit;
1615 }
1616 $response = (new OoredooCb2())->ooredooCback($getParams);
1617 //$response = (new OoredooCb2())->ooredooSubparkCback($getParams);
1618
1619 } else
1620 {
1621 $response = "Some parameters are missing";
1622 }
1623
1624 echo $response;
1625 try {
1626 $getParams['_response'] = $response;
1627 $callbackLog->insert($getParams);
1628 } catch (Exception $e) {
1629 throw $e->getMessage();
1630 }
1631 }
1632// Comvivaindodlr
1633 public function actionComvivaindodlr()
1634 {
1635 $getParams = W::getRequestParams();
1636 if (empty($getParams))
1637 {
1638 throw new CHttpException(404, 'No parameters found.');
1639 }
1640 $getParams['datetime'] = new MongoDate();
1641 $getParams['_type'] = 'callback';
1642 $getParams['_partner'] = 'comviva_indoset';
1643 $callbackLog = (new SubOoredoo2())->getCollection();
1644
1645 $eventId=$getParams['serviceId'];
1646 $productId=$this->productId($eventId);
1647
1648 //check product is available or not
1649// $productId = $this->productId($getParams['serviceId']);
1650 if ($productId == 0)
1651 {
1652 $productId = 137; //default as gameon-techvault
1653 } else
1654 {
1655 $getParams['event_id']=$eventId;
1656 $getParams['product_id'] = $productId;
1657 }
1658// $response = (new OoredooCb2())->ooredooCback($getParams);
1659 $response = (new OoredooCb2())->ooredooSubparkCback($getParams);
1660 echo $response;
1661 try {
1662 $getParams['_response'] = $response;
1663 $callbackLog->insert($getParams);
1664 } catch (Exception $e) {
1665 throw $e->getMessage();
1666 }
1667 }
1668 /*HE return comviva smartfren
1669 */
1670 public function actionComvivareturn(){
1671
1672 $getParams= W::getRequestParams();
1673 $getParams['datetime']= new MongoDate();
1674 $getParams['_type']='callback';
1675 $getParams['_partner']='smartfren_return_HE';
1676
1677 $callbackLog = (new SubOoredoo3())->getCollection();
1678 $msisdn=(new SubOoredoo3())->getCustomMsisdn();
1679// echo "<pre>";
1680// print_r($save);exit;
1681 if(!empty($msisdn)){
1682 echo "msisdn is successfully Store";
1683 }
1684 try{
1685 $getParams['msisdn']=$msisdn;
1686 $callbackLog->insert($getParams);
1687 }
1688 catch(Exception $e){
1689 throw $e->getMessage();
1690 }
1691 }
1692 public function actionMH_Ooredoocb()
1693 {
1694 $req= trim(file_get_contents('php://input'));
1695 $getParams = json_decode($req, true); // for json request check
1696 if(empty($getParams)){
1697 $getParams=(new Common())->xmlToArray($req); //if req is xml
1698 if(empty($getParams)){
1699// $getParams= W::getRequestParams();
1700 throw new CHttpException(404, 'No request found.');
1701 }
1702 }
1703
1704 $getParams['datetime']= new MongoDate();
1705 $getParams['_type']='callback';
1706 $getParams['_partner']='ComvivaMHooredoo';
1707 $callbackLog = Yii::app()->mongodb->callback_log;
1708 $getParams['requestPlan']=($getParams['operationId']=="PS")?'TECV_GAMN_700':$getParams['requestPlan'];
1709
1710 if($getParams['transId']!=''){
1711
1712 $tran_logs=(new SubOoredoo3())->getTransIDCollection();
1713 $findAll=['_id'=>$getParams['transId']];
1714 $Data=$tran_logs->findOne($findAll);
1715 $getParams['msisnd']=$Data['msisdn'];
1716 $getParams['product_id']=$Data['product_id'];
1717 $getParams['event_id']=$Data['event_id'];
1718 }
1719 $productId=$getParams['product_id'];
1720 //check product is available or not
1721 if($productId == 0){
1722 $errorNo=703;
1723 $response=$errorNo.'|ERROR|'. OoredooCb::errorCode()[$errorNo];
1724 }else{
1725 $response = (new OoredooCb())->ooredooMhCback($productId);
1726 }
1727 echo $response;
1728 try
1729 {
1730 $getParams['_response']=$response;
1731 $callbackLog->insert($getParams);
1732 }
1733 catch (Exception $e)
1734 {
1735 throw $e->getMessage();
1736 }
1737
1738 }
1739 /**
1740 * Airtel notification callback API
1741 */
1742 public function actionAirtelnotify()
1743 {
1744 $getParams = (new AirtelCb)->readXmlData();
1745 $callbackLog = SubAirtel2::getCollection();
1746 //assign to the request
1747 if(empty($getParams)){
1748 echo $response = 'No input Xml found';
1749 $getParams['datetime']= new MongoDate();
1750 $getParams['_type']='callback';
1751 }
1752 else{
1753 $getParams['datetime'] = new MongoDate();
1754 $getParams['_type']='callback';
1755 $productId = $this->productId($getParams['productId']);
1756 //check product is available or not
1757 if($productId == 0){
1758 $errorNo=3004;
1759 $response=['errorCode'=> $errorNo, 'errorMsg'=> AirtelCb::errorCode()[$errorNo]];
1760 }else{
1761 $getParams['product_id']=$productId;
1762 $response = (new AirtelCb())->airtelCback($getParams);
1763 }
1764 echo (new AirtelCb())->responseXml($response);
1765 }
1766 try
1767 {
1768 $getParams['_response']=$response;
1769 $callbackLog->insert($getParams);
1770 }
1771 catch (Exception $e)
1772 {
1773 throw $e->getMessage();
1774 }
1775 }
1776 /**
1777 * Airtel callback API
1778 */
1779 public function actionAirnot()
1780 {
1781 $this->airtelCallback();
1782
1783 }
1784 /* call the airtel callback */
1785 public function airtelCallback()
1786 {
1787 $getParams=(new AirtelCb)->readXmlData();
1788 //assign to the request
1789 if(empty($getParams)){
1790 $response='No input Xml found';
1791 echo 'No Xml found';die();
1792 }
1793 else{
1794 $_REQUEST=$getParams;
1795 $getParams['datetime']= new MongoDate();
1796 $getParams['_type']='callback';
1797 $callbackLog = Yii::app()->mongodb->callback_log;
1798 $productId = $this->getProductId();
1799 //check product is available or not
1800 if($productId == 0){
1801 $errorNo=3004;
1802 $response=['errorCode'=> $errorNo, 'errorMsg'=> AirtelCb::errorCode()[$errorNo]];
1803 }else{
1804 $response = (new AirtelCb())->airtelCback($productId);
1805 }
1806 echo (new AirtelCb())->responseXml($response);
1807 }
1808 try
1809 {
1810 $getParams['_response']=$response;
1811 $callbackLog->insert($getParams);
1812 }
1813 catch (Exception $e)
1814 {
1815 throw $e->getMessage();
1816 }
1817 }
1818
1819 /**
1820 * Dialog (Sri Lanka) callback API
1821 */
1822 public function actionDialogcb()
1823 {
1824 $getParams = W::getRequestParams();
1825 if (empty($getParams)) {
1826 throw new CHttpException(404, 'No parameters found.');
1827 }
1828 $getParams = array_change_key_case($getParams, CASE_LOWER);
1829 $getParams['datetime'] = new MongoDate();
1830 $getParams['_partner'] = 'dialog';
1831 $getParams['_type'] = 'callback';
1832 $callbackLog = Yii::app()->mongodb->callback_log;
1833 $header='HTTP/1.1 ';
1834 $body = 'Operation successful';
1835 if(isset($getParams['packageid']) && !empty($getParams['packageid'])){
1836 $productId = $this->productId($getParams['packageid']);
1837 //check product is available or not
1838 if ($productId == false) {
1839 $response = "Package ID not listed.!";
1840 $header.='404 '.$response;
1841 } else {
1842 $getParams['product_id'] = $productId;
1843 $code = (new DialogCb())->DialogCback($getParams);
1844 $response = (new DialogCb())->responseCode()[$code];
1845 $header.="$code $response";
1846 }
1847 }else{
1848 $response = "Package ID not found.!";
1849 $header.='404 '.$response;
1850 }
1851 header($header);
1852 print_r($body);
1853 try {
1854 $getParams['_response'] = $response;
1855 $callbackLog->insert($getParams);
1856 } catch (Exception $e) {
1857 throw $e->getMessage();
1858 }
1859 }
1860
1861 /**
1862 * Dialog (Sri Lanka) SMS Notification API
1863 */
1864 public function actionDialogsms()
1865 {
1866 echo 'ACCEPT';
1867 }
1868
1869 /**
1870 * Validate Dialog via authkey
1871 */
1872 public function actionValidatedialog()
1873 {
1874 $req= trim(file_get_contents('php://input'));
1875 $data = json_decode($req,1);
1876 $response='FAIL';
1877 if(isset($data['authkey']))
1878 {
1879 if((new SubDialog)->validateAuthKey($data['authkey']))
1880 {
1881 $response = 'validate success';
1882// exit;
1883 }
1884 }
1885 $data['_response'] = $response;
1886 $data['datetime'] = new MongoDate();
1887 $data['_partner'] = 'dialog';
1888 $data['_type'] = 'validate';
1889 Yii::app()->mongodb->callback_log->insert($data);
1890 //remove for test
1891// if($response=='FAIL'){
1892// throw new CHttpException(404,'Authkey not found');
1893// }else{
1894 echo $response;
1895// }
1896 }
1897
1898 public function actionOrangeCB() {
1899 $this->orangeEgyptCallback();
1900 }
1901 public function actionMondiamediacb() {
1902 $this->orangeEgyptCallback();
1903 }
1904 /**
1905 * Mobpair MM callback
1906 */
1907 public function actionMmCb(){
1908 $this->orangeEgyptCallback();
1909 }
1910 /* call the airtel callback */
1911
1912 public function orangeEgyptCallback() {
1913 $getParams = (new MMOrangeCb())->readXmlData();
1914
1915 //assign to the request
1916 if (empty($getParams)) {
1917 $response = 'No input Xml found';
1918 echo 'No Xml found';
1919 die();
1920 } else {
1921
1922 $callbackLog = new MMOrangeCb();
1923 $callbackLog->msisdn = $getParams['CustomerID'];
1924 $callbackLog->service_id = $getParams['ServiceID'];
1925
1926 $callbackLog->errorCode = isset($getParams['errorCode']) ? $getParams['errorCode'] : 0;
1927 $callbackLog->errorMsg = isset($getParams['errorMsg']) ? $getParams['errorMsg'] : '';
1928
1929 $_REQUEST['SERVICE_ID']=$callbackLog->service_id;
1930 $callbackLog->product_id = $this->productId($getParams['ServiceID'],'SubMMOrange');
1931 $callbackLog->product_code = $getParams['ProductCode'];
1932 $callbackLog->action = $getParams['Action'];
1933 $callbackLog->channel = $getParams['Channel'];
1934
1935 if(in_array($getParams['OperatorName'],['OOREDOO ALGERIA','ORANGE BOTSWANA','ORANGE MADAGASCAR']))
1936 {
1937 if(isset($getParams['Price']))
1938 {
1939 $callbackLog->price = $getParams['Price'];
1940 }else {
1941 $priceDetailArr = $callbackLog->getPriceDetails();
1942 $callbackLog->price = isset($priceDetailArr['price']) ? $priceDetailArr['price'] : 0;
1943 }
1944 }else{
1945 //for fallback price update
1946 if(isset($getParams['Price']) && $getParams['Price'] > 0)
1947 {
1948 $callbackLog->price=($getParams['Price']/100);
1949 }
1950 else
1951 {
1952 $priceDetailArr = $callbackLog->getPriceDetails();
1953 $callbackLog->price = isset($priceDetailArr['price']) ? $priceDetailArr['price'] : 0;
1954 }
1955 }
1956
1957 $callbackLog->transactionId = $getParams['TransactionId'];
1958 $callbackLog->subscriptionId = $getParams['SubscriptionID'];
1959 $callbackLog->subscriptionStatus = $getParams['SubscriptionStatus'];
1960 $callbackLog->nextAction = $getParams['NextAction'];
1961 $callbackLog->nextActionDate = $getParams['NextActionDate'];
1962 $response = $callbackLog->subscribe();
1963 echo $response;
1964// echo 'Callback updation done....';
1965 }
1966 try {
1967 $getParams['_response'] = $response;
1968 $getParams['datetime'] = new MongoDate();
1969 $getParams['_partner'] = 'mondiamedia';
1970 $getParams['_type'] = 'callback';
1971 Yii::app()->mongodb->callback_log->insert($getParams);
1972 } catch (Exception $e) {
1973 throw $e->getMessage();
1974 }
1975 }
1976 /**
1977 * Info Bip (SERBIA) callback call
1978 */
1979 public function actionIbserbiacb() {
1980 $this->infoBipCallback('ibserbia');
1981 }
1982 /**
1983 * Info Bip (ZA) callback call
1984 */
1985 public function actionIbzacb() {
1986 $this->infoBipCallback('ibza');
1987 }
1988
1989 /**
1990 * Info Bip (Spain) callback call
1991 */
1992 public function actionIbspaincb() {
1993 $this->infoBipCallback('ibspain');
1994 }
1995
1996 /**
1997 * Info Bip callback API
1998 */
1999 public function infoBipCallback($partner='ib')
2000 {
2001 $getParams = W::getRequestParams();
2002 if (empty($getParams)) {
2003 throw new CHttpException(404, 'No parameters found.');
2004 }
2005 $getParams = array_change_key_case($getParams, CASE_LOWER);
2006
2007 $getParams['datetime'] = new MongoDate();
2008 $getParams['_partner'] = $partner;
2009 $getParams['_type'] = 'callback';
2010
2011 $callbackLog = Yii::app()->mongodb->callback_log;
2012 $header='HTTP/1.1 ';
2013 $body = 'Operation Successful';
2014 if(isset($getParams['service']) && !empty($getParams['service'])){
2015 $d=($getParams['country']=='za')?'DAY':'WEEK';
2016 $interval=(isset($getParams['interval']))?trim($getParams['interval']):$d;
2017 $event_id=$getParams['service'].'_'. substr($interval, 0,1);
2018 $productId = $this->productId($event_id);
2019
2020 //check product is available or not
2021 if ($productId == false) {
2022 $response = "Service not Found!";
2023 $header.='406 '.$response;
2024 } else {
2025 $getParams['event_id']=$event_id;
2026 $getParams['product_id'] = $productId;
2027 $code = (new InfoBipCb())->InfoBipCback($getParams);
2028 $response = (new InfoBipCb())->responseCode()[$code];
2029 $header.="$code $response";
2030 }
2031 }else{
2032 $response = (new InfoBipCb())->responseCode()[406];
2033 $header.='406 '.$response;
2034 }
2035 header($header);
2036 print_r($body);
2037 try {
2038 $getParams['_response'] = $header;
2039 $callbackLog->insert($getParams);
2040 } catch (Exception $e) {
2041 throw $e->getMessage();
2042 }
2043 }
2044
2045 /**
2046 * Oman Ooredoo Timwe Mo Processing
2047 */
2048 // http://205.147.98.6/async/omanTimweMO?Origin=%p&Text=%a&shortcode=%P
2049 public function actionOmanTimweMO()
2050 {
2051 $getParams = W::getRequestParams();
2052 $file = Yii::app()->getBasePath().DIRECTORY_SEPARATOR."runtime/callback_omanTimwe.txt";
2053 $content = "Response:Date:".date('Y-m-d H:i:s')."->".json_encode($getParams)."\n";
2054 file_put_contents($file, $content, FILE_APPEND | LOCK_EX);
2055
2056 // check params
2057 if(empty($getParams)){
2058 throw new CHttpException(404, 'No parameters found.');
2059 }
2060
2061 // get two params only
2062 $msisdn = $getParams['Origin'];
2063 $textMsg = $getParams['Text'];
2064 $shortcode = $getParams['shortcode'];
2065
2066 $msisdn = ltrim(str_replace(' ', '', $msisdn ), '+');
2067
2068 $subOmanTimwe = new SubOmanTimwe();
2069 $omanTimwecb = new OmanTimweCb();
2070
2071 $product = (new ProductEx)->find("conf_json like :shortcode", [':shortcode'=>"%shortcode%$shortcode%"]);
2072 $productId = $product->id;
2073
2074 $peInfo = $subOmanTimwe->getValidityByProductId($productId);
2075 $eventId = $peInfo['eventid'];
2076 $priceDetails = $peInfo;
2077 $sendCode = $tid = $subOmanTimwe->getRefId();
2078 $sysproductId = $product->conf['productId'];
2079
2080 $key = '';
2081 $keyword = '';
2082 $mt_response = '';
2083 $text = '';
2084
2085 $textArr = $subOmanTimwe->checkMoKey($textMsg);
2086 $textCount = count($textArr);
2087 if($textCount >=2 ){
2088 $key = strtoupper($textArr[0]);
2089 $keyword = strtoupper($textArr[1]);
2090 $sep_unsub = $key.$keyword;
2091 }else{
2092 $key = isset($textArr[0])?strtoupper($textArr[0]):'';
2093 }
2094
2095
2096 // var_dump($msisdn, $productId,$key,$keyword,$textArr, in_array($key, $product->conf['mosub']) );die;
2097
2098 $file = Yii::app()->getBasePath().DIRECTORY_SEPARATOR."runtime/callback_omanTimwe.txt";
2099 $content = "keyword :".$key."->".$keyword."\n";
2100 file_put_contents($file, $content, FILE_APPEND | LOCK_EX);
2101
2102 if(in_array($key, $product->conf['mosub']))
2103 {
2104 // die('mosub');
2105 $setMT = '';
2106 if( $keyword!=''){
2107 $sub = (new SubscriptionEx())->getSubscription($msisdn, $productId);
2108 if(!$sub){
2109 // subscription user and send MT billing
2110 $sendCode = $omanTimwecb->subscribeByMo($msisdn, $productId, $priceDetails, $tid);
2111 $text = "subscribe";
2112 if($sendCode=="sub already exists"){
2113 $setMT = 'ALREADY_SUB';
2114 }
2115 }else{
2116 $checkSubStatus = $subOmanTimwe->checkSubscriptionStatus($productId, $msisdn);
2117 if($checkSubStatus == 'Success'){
2118 $setMT='ALREADY_SUB';
2119 }else{
2120 $setMT = 'HELP_UNSUB';
2121 }
2122 }
2123 }
2124 else if( $keyword ==''){
2125 $sub = (new SubscriptionEx())->getSubscription($msisdn, $productId);
2126 if(!$sub){
2127 // subscription user and send MT billing
2128 $sendCode = $omanTimwecb->subscribeByMo($msisdn, $productId, $priceDetails, $tid);
2129 $text = "subscribe";
2130 if($sendCode=="sub already exists"){
2131 $setMT = 'ALREADY_SUB';
2132 }
2133 }else{
2134 $checkSubStatus = $subOmanTimwe->checkSubscriptionStatus($productId, $msisdn);
2135 if($checkSubStatus == 'Success'){
2136 $setMT='ALREADY_SUB';
2137 }else{
2138 $setMT = 'HELP_UNSUB';
2139 }
2140 }
2141 }
2142 else{
2143 $setMT = 'INVALID_SUB';
2144 }
2145 }else if(in_array($key, $product->conf['mosysunsub']))
2146 {
2147 // die($keyword.' mosysunsub');
2148 $setMT = '';
2149 $sysProductId = $keyword;
2150
2151 $file = Yii::app()->getBasePath().DIRECTORY_SEPARATOR."runtime/callback_omanTimwe.txt";
2152 $content = "keyword 2 :".$keyword."->".$key."\n";
2153 file_put_contents($file, $content, FILE_APPEND | LOCK_EX);
2154
2155 $priceDetails = $subOmanTimwe->getProductBySysProductId($sysProductId);
2156 $productId = $priceDetails['product_id'];
2157 if($productId)
2158 {
2159 $sub = (new SubscriptionEx())->getSubscription($msisdn, $productId);
2160 // var_dump($sub,$msisdn, $productId);die;
2161 if($sub){
2162 $sendCode= $subOmanTimwe->deactivateMultipleByMo($msisdn, $sub->id, $priceDetails);
2163 $text ='Unsubscribe';
2164 }else{
2165 $checkSubStatus = $subOmanTimwe->checkSubscriptionStatus($productId, $msisdn);
2166 if($checkSubStatus == 'already_cancel'){
2167 $setMT='ALREADY_UNSUB';
2168 }else{
2169 $setMT = 'HELP_UNSUB';
2170 }
2171 }
2172 }else{
2173 $setMT = 'INVALID_UNSUB';
2174 }
2175 }
2176 else if($textCount ==1 && in_array($key, $product->conf['mounsub']))
2177 {
2178 //die('1 mounssub');
2179 //unsubscribe user for all product for matching shortcode
2180 $userActiveSub = $subOmanTimwe->getActiveSubByShortcode($msisdn, $product->conf['shortcode'] );//$shortCode
2181 if(count($userActiveSub)>0){
2182 foreach($userActiveSub as $key=>$subId)
2183 {
2184 $sendCode = $subOmanTimwe->deactivateMultipleByMo($msisdn, $subId, $priceDetails);
2185 $text = 'Multi Unsubscribe';
2186 }
2187 $sms_text = $subOmanTimwe->getMessageByType($product->id, $priceDetails['price'], $priceDetails['validity'], 'STOP_ALL');
2188 $mt_response = $subOmanTimwe->mtBilling($product, $msisdn, $product->conf['mt_pricepoint'], $sms_text, 'DCT', false);
2189 }else{
2190 $setMT = 'HELP_UNSUB';
2191 }
2192 }
2193 else if(in_array($key, $product->conf['mounsub']))
2194 {
2195 $setMT='';
2196 if($keyword!=''){
2197 $sub=(new SubscriptionEx())->getSubscription($msisdn, $productId);
2198 if($sub){
2199 // save deactivation
2200 $sendCode=$subOmanTimwe->deactivateByMo($msisdn, $sub->id, $priceDetails);
2201 $text='Unsubscribe';
2202 }else{
2203 $checkSubStatus = $subOmanTimwe->checkSubscriptionStatus($productId, $msisdn);
2204 if($checkSubStatus == 'already_cancel'){
2205 $setMT='ALREADY_UNSUB';
2206 }else{
2207 $setMT = 'HELP_UNSUB';
2208 }
2209 }
2210 }else{
2211 $setMT='INVALID_SUB';
2212 }
2213
2214 }else
2215 {
2216 if($textCount ==2 && in_array($sep_unsub, $product->conf['mounsub']))
2217 {
2218 $userActiveSub = $subOmanTimwe->getActiveSubByShortcode($msisdn, $product->conf['shortcode'] );//$shortCode
2219 if(count($userActiveSub)>0){
2220 foreach($userActiveSub as $key=>$subId)
2221 {
2222 $sendCode = $subOmanTimwe->deactivateMultipleByMo($msisdn, $subId, $priceDetails);
2223 $text = 'Multi Unsubscribe';
2224 }
2225 $sms_text = $subOmanTimwe->getMessageByType($product->id, $priceDetails['price'], $priceDetails['validity'], 'STOP_ALL');
2226 $mt_response = $subOmanTimwe->mtBilling($product, $msisdn, $product->conf['mt_pricepoint'], $sms_text, 'DCT', false);
2227 }else{
2228 $setMT = 'HELP_UNSUB';
2229 }
2230 }
2231 else{
2232 $sub = (new SubscriptionEx())->getSubscription($msisdn, $productId);
2233 if( strtoupper ($key) == 'HELP'){
2234 //send message of help if sub and not subscribe
2235 $setMT = 'HELP_UNSUB';
2236 if($sub){
2237 $setMT = 'HELP_SUB';
2238 }
2239 }else{
2240 //send message of invalid if sub and not subscribe
2241 $setMT = 'INVALID_UNSUB';
2242 if($sub){
2243 $setMT = 'INVALID_SUB';
2244 }
2245 }
2246 }
2247 }
2248
2249 if($setMT != ''){
2250 $text = $subOmanTimwe->getMessageByType($productId, $priceDetails['price'], $priceDetails['validity'], $setMT);
2251 $mt_response= $subOmanTimwe->mtBilling($product, $msisdn, $product->conf['mt_pricepoint'], $text, $setMT, false);
2252 }
2253
2254 $textInfo=($text!='')? ":".$text:'';
2255 echo $sendCode . $textInfo;
2256
2257 if($setMT != '')
2258 {
2259 $omanTimwe_log = Yii::app()->mongodb->OmanTimwe_log;
2260 $getParams['response'] = $sendCode . $textInfo;
2261 $getParams['msisdn'] = $msisdn;
2262 $getParams['product_id'] = $productId;
2263 $getParams['typeMT'] = $setMT;
2264 $getParams['type'] = 'MOREQUEST';
2265 $getParams['priceDetails'] = $priceDetails;
2266 $getParams['mtResponse'] = $mt_response;
2267 $getParams['time'] = new MongoDate();
2268 $omanTimwe_log->insert($getParams);
2269 }
2270
2271 $callbackLog = Yii::app()->mongodb->callback_log;
2272 try
2273 {
2274 $getParams['datetime'] = new MongoDate();
2275 $getParams['_type'] = 'MOREQUEST';
2276 $getParams['productId'] = $productId;
2277 $getParams['typeMT'] = $setMT;
2278 $getParams['_response'] = $sendCode . $textInfo;
2279 $getParams['msisdn'] = $msisdn;
2280 $callbackLog->insert($getParams);
2281 }
2282 catch (Exception $e)
2283 {
2284 throw $e->getMessage();
2285 }
2286
2287 }
2288
2289
2290 /**
2291 * Oman Ooredoo Timwe Mo callback
2292 */
2293 // http://play.tech-vault.com/async/url?id=%F&reportValue=%d&reply=%A&mdn=%p
2294 // %F the foreign (smsc-provided) message ID. Only relevant on DLR url's
2295 // %d the delivery report value
2296 // %A the delivery report SMSC reply, if any
2297 // %p the phone number of the sender of the SMS message
2298 public function actionOmanTimweBillCb()
2299 {
2300 $file = Yii::app()->getBasePath().DIRECTORY_SEPARATOR."runtime/callback_omanTimwe.txt";
2301 $content = "DLR Response:Date:".date('Y-m-d H:i:s')."->".json_encode($_REQUEST)."\n";
2302 file_put_contents($file, $content, FILE_APPEND | LOCK_EX);
2303
2304 $getParams = W::getRequestParams();
2305 if ( empty($getParams)) {
2306 throw new CHttpException(404, 'No parameters found.');
2307 }
2308
2309 $id = $getParams['id'];
2310 $reportVal = (int) $getParams['reportValue'];
2311 $msisdn = $getParams['mdn'];
2312 $reply = $getParams['reply'];
2313
2314 $mttext= explode("text:", $reply)[1];
2315 if( ($reportVal!=1) && ($reportVal!=2) ||
2316 !(stristr(SubOmanTimwe::$smstexts['ACT'], $mttext))
2317 )
2318 {
2319 echo $response="This DLR Response is not required. Params : ";
2320 print_r($getParams);
2321// return ;
2322 }else
2323 {
2324 $statustxt = false;
2325 $errCode = false;
2326 $statusCode = false;
2327 $stat = explode("stat:", $reply);
2328
2329 if( !empty($stat) ){
2330 $status = explode(" ", $stat[1]);
2331 $statustxt = $status[0];
2332 $errCode = $status[1];
2333 if ( $statustxt == "DELIVRD"){
2334 $statusCode = 10;
2335 }else if( $statustxt == "UNDELIV"){
2336 $statusCode = 21;
2337 }
2338 }
2339
2340 $billingMongoInfo = Yii::app()->mongodb->oman_billing_log;
2341 $billingMongData = $billingMongoInfo->find(['msisdn' => $msisdn, 'charge' => true, 'billing_status'=>false])->sort(array('_id' =>-1))->limit(1)->getNext();
2342 //var_dump("<pre>",$statusCode, $errCode, $billingMongData);die;
2343
2344 $allResponse['billingCbParam'] = $getParams;
2345 if(!empty($billingMongData)){
2346 // save data in subs and tran
2347 $timweCb = new OmanTimweCb();
2348 $timweCb->product_id = $billingMongData['product_id'];
2349 $timweCb->msisdn = $msisdn;
2350 $timweCb->eventId = $billingMongData['pricePointId'];
2351 $timweCb->action = $billingMongData['type'];
2352 $txn_id = $billingMongData['txn_id'];
2353 if($txn_id !=null){
2354 $timweCb->txn_id = $txn_id;
2355 }
2356 $allResponse['billingStatusCode'] = $statusCode;
2357 $allResponse['billingReportResponce'] = $statusCode.' '.$statustxt.' '.$errCode;
2358 echo $response= $timweCb->mtBillingCb($allResponse);
2359 }else{
2360 echo $response="Not Get Data. Params : ";
2361 print_r($allResponse);
2362 }
2363 }
2364 $getParams['datetime'] = new MongoDate();
2365 $getParams['_partner'] = 'omantimwe';
2366 $getParams['_type'] = 'billreport';
2367 $getParams['_response']=$response;
2368 $callbackLog = Yii::app()->mongodb->callback_log;
2369 try {
2370 $getParams['allResponse'] = $allResponse;
2371 $callbackLog->insert($getParams);
2372 } catch (Exception $e) {
2373 throw $e->getMessage();
2374 }
2375
2376 }
2377
2378 /**
2379 * Oman timwe callback for subscription
2380 */
2381 public function actionOmanTmwCb ()
2382 {
2383 $postdata = file_get_contents("php://input");
2384// echo "<pre>";print_r($postdata);exit;
2385 if(empty($postdata)){
2386 throw new CHttpException(404, 'No parameters found.');
2387 }
2388 $getParams['postdata']= $postdata;
2389 $getParams['datetime']= new MongoDate();
2390 $getParams['_partner']='omantimwe';
2391 $getParams['_type']='callback';
2392 $callbackLog = Yii::app()->mongodb->callback_log;
2393 $postdata= json_decode($postdata);
2394 //echo "<pre>1->";print_r($postdata);exit;
2395 $response=['correlatorId'=> $postdata->correlator, 'responseStatus'=> 0];
2396 if($postdata->code == 1)
2397 {
2398 if($postdata->subscription->responseStatusCode == 1){
2399 //check product is available or not
2400 $productId = (new SubOmanTimwe())->getProductIdByMap($postdata->correlator);
2401// echo $productId;exit;
2402 if($productId == 0){
2403 $response['responseStatus']= 0;
2404 }else{
2405 $responseCode = (new OmanTimweCb())->subscribeByCb($productId, $postdata);
2406 $response['responseStatus'] = $responseCode;
2407 }
2408 }else{
2409 $response['responseStatus']= $postdata->subscription->responseStatusCode;
2410 }
2411 }else{
2412 $response['responseStatus'] = $postdata->code;
2413 }
2414 echo json_encode($response);
2415// echo "\n","Success";
2416 try
2417 {
2418 $getParams['_response']=$response;
2419 $getParams['msisdn']=$postdata->msisdn;
2420 $callbackLog->insert($getParams);
2421 }
2422 catch (Exception $e)
2423 {
2424 throw $e->getMessage();
2425 }
2426
2427 }
2428
2429 /**
2430 *
2431 * Nigeria(MTN) callback API
2432 */
2433 public function actionNigeriaMTNCb()
2434 {
2435 $getParams = W::getRequestParams();
2436 if (empty($getParams)) {
2437 throw new CHttpException(404, 'No parameters found.');
2438 }
2439 $getParams = array_change_key_case($getParams, CASE_LOWER);
2440 $getParams['datetime'] = new MongoDate();
2441 $getParams['_partner'] = 'nigeriaMTN';
2442 $getParams['_type'] = 'callback';
2443 $callbackLog = Yii::app()->mongodb->callback_log;
2444 if((isset($getParams['productid']) && !empty($getParams['productid']))and (isset($getParams['userid']) && !empty($getParams['userid'])))
2445 {
2446 $productId = $this->productId($getParams['productid']);
2447 //check product is available or not
2448 if ($productId == false) {
2449 $response = "Product ID not found.!";
2450 } else {
2451 $getParams['product_id'] = $productId;
2452 $code=(new NigeriaMTNCb())->NigeriaMTNCback($getParams);
2453
2454 $response =(new NigeriaMTNCb())->responseCode()[$code];
2455 }
2456 }else{
2457 $response = "Parameter not found.!";
2458 }
2459 print_r($response);
2460 try {
2461 $getParams['_response'] = $response;
2462 $callbackLog->insert($getParams);
2463 } catch (Exception $e) {
2464 throw $e->getMessage();
2465 }
2466 }
2467
2468 /**
2469 *
2470 * Portugal callback API
2471 */
2472 public function actionGo4MobilityCb()
2473 {
2474 $getParams = W::getRequestParams('get');
2475 if (empty($getParams)) {
2476 throw new CHttpException(404, 'No parameters found.');
2477 }
2478 $getParams = array_change_key_case($getParams, CASE_LOWER);
2479 $getParams['datetime'] = new MongoDate();
2480 $getParams['_partner'] = 'Go4Mobility';
2481 $getParams['_type'] = 'callback';
2482 $callbackLog = Yii::app()->mongodb->callback_log;
2483 if((isset($getParams['type']) && !empty($getParams['type'])) and (isset($getParams['service']) && !empty($getParams['service'])))
2484 {
2485 $getParams['eventid'] =$getParams['service']."_".$getParams['mcc'].$getParams['mnc'];
2486 $productId = $this->productId($getParams['eventid']); // Set eventid
2487 //check product is available or not
2488 if ($productId == false) {
2489 $response = "service not found.!";
2490 } else {
2491 $getParams['product_id'] = $productId;
2492 $code=(new Go4MobilityCb())->Go4MobilityCback($getParams);
2493 $response =(new Go4MobilityCb())->responseCode()[$code];
2494 }
2495 }else{
2496 $response = "Parameter not found.!";
2497 }
2498 print_r($response);
2499 try {
2500 $getParams['_response'] = $response;
2501 $callbackLog->insert($getParams);
2502 } catch (Exception $e) {
2503 throw $e->getMessage();
2504 }
2505 }
2506
2507 public function actionIndoCom()
2508 {
2509 $getParams = W::getRequestParams();
2510 $getParams = array_change_key_case($getParams, CASE_LOWER);
2511 $getParams['datetime'] = new MongoDate();
2512 $getParams['_partner'] = 'indo_com';
2513 $getParams['_type'] = 'callback';
2514 $callbackLog = Yii::app()->mongodb->callback_log;
2515 $callbackLog->insert($getParams);
2516 echo "OK";
2517 }
2518
2519 public function actionId_com(){
2520
2521 $this->IndoSmartfrenCb();
2522 }
2523
2524 public function actionId_com_dlr(){
2525
2526 $this->IndoSmartfrenDlr();
2527 }
2528
2529 /**
2530 * Indonesia Smartfren Cb
2531 * @throws CHttpException
2532 * @throws type
2533 */
2534 public function IndoSmartfrenCb()
2535 {
2536 $getParams = W::getRequestParams('get');
2537 if (empty($getParams)) {
2538 throw new CHttpException(404, 'No parameters found.');
2539 }
2540 $getParams = array_change_key_case($getParams, CASE_LOWER);
2541 $getParams['datetime'] = new MongoDate();
2542 $getParams['_partner'] = 'indoSmart_cb';
2543 $getParams['_type'] = 'callback';
2544 if(1){
2545 $para = $getParams;
2546 $cl = Yii::app()->mongodb->indoreq_log;
2547 $cl->insert($para);
2548 }
2549 $callbackLog = Yii::app()->mongodb->callback_log;
2550
2551 if((isset($getParams['requestplan']) && !empty($getParams['requestplan'])))
2552 {
2553 //$getParams['eventid'] =$getParams['service'];
2554 $productId = $this->productId($getParams['requestplan']); // Set serviceid
2555 //check product is available or not
2556 if ($productId == false) {
2557 $response = "service not found.!";
2558 } else {
2559 $getParams['product_id'] = $productId;
2560 $code=(new IndoSmartfrenCb())->IndoSmartfrenCback($getParams);
2561 $response =(new IndoSmartfrenCb())->responseCode()[$code];
2562 if(!$response)
2563 $response="OK";
2564 }
2565 }else{
2566 $response = "Parameter not found.!";
2567 }
2568 print_r($response);
2569 try {
2570 $getParams['_response'] = $response;
2571 $callbackLog->insert($getParams);
2572 } catch (Exception $e) {
2573 throw $e->getMessage();
2574 }
2575 }
2576
2577 /**
2578 * Indonesia Smartfren Cb
2579 * @throws CHttpException
2580 * @throws type
2581 */
2582 public function IndoSmartfrenDlr()
2583 {
2584 $getParams = W::getRequestParams('get');
2585 if (empty($getParams)) {
2586 throw new CHttpException(404, 'No parameters found.');
2587 }
2588 $getParams = array_change_key_case($getParams, CASE_LOWER);
2589 $getParams['datetime'] = new MongoDate();
2590 $getParams['_partner'] = 'indoSmart_dlr';
2591 $getParams['_type'] = 'callback';
2592
2593 if(1){
2594 $para = $getParams;
2595 $cl = Yii::app()->mongodb->indoreq_log;
2596 $cl->insert($para);
2597 }
2598
2599 $product=false;
2600// $tr_id= $getParams['seqno'];
2601 //transaction already exist in db
2602// if($model=(new TransactionEx)->find('o_transac=:tr_id',[':tr_id'=>$tr_id]) and $tr_id!=false)
2603// {
2604// $product = $model->product;
2605// }
2606 $shortcode = $getParams['shortcode'];
2607 $product = (new ProductEx)->find("conf_json like :shortcode", [':shortcode'=>"%shortcode%$shortcode%"]);
2608 if($product=='')
2609 {
2610 $defProduct=[
2611 '99999'=>76,
2612 '99000'=>75
2613 ];
2614 $productId = isset($defProduct[$getParams['shortcode']])?($defProduct[$getParams['shortcode']]):75;
2615 $product= Product::model()->findByPk($productId);
2616 }
2617 if($product!==FALSE)
2618 {
2619 //$getParams['eventid'] =$getParams['service'];
2620// $productId = $this->productId($getParams['requestplan']); // Set serviceid
2621 $productId = $product->id;
2622 //check product is available or not
2623 if ($productId == false) {
2624 $response = "service not found.!";
2625 } else {
2626 $getParams['product_id'] = $productId;
2627 $getParams['requestPlan'] = $product->conf['planId'];
2628 $code=(new IndoSmartfrenCb())->Id_com_dlr($getParams);
2629 $response =(new IndoSmartfrenCb())->responseCode()[$code];
2630 }
2631 }else{
2632 $response = "Parameter not found.!";
2633 }
2634 print_r($response);
2635 try {
2636 $getParams['_response'] = $response;
2637 $callbackLog->insert($getParams);
2638 } catch (Exception $e) {
2639 throw $e->getMessage();
2640 }
2641 }
2642
2643 public function actionId_sf_com(){
2644
2645// $this->IndoSmartfrenCb();
2646 echo 'OK';
2647 $getParams = W::getRequestParams();
2648 $getParams['datetime'] = new MongoDate();
2649 $getParams['_partner'] = 'id_sf_com';
2650// $request['']='id_sf_com';
2651 $getParams['_type']='test';
2652 $callback=Yii::app()->mongodb->callback_log;
2653 try {
2654 $callback->insert($getParams);
2655 // echo "sms template";
2656 } catch (Exception $exc) {
2657
2658 }
2659
2660 }
2661
2662 /** # for Smartfren intgr
2663 *
2664 * Comviva callback url (SDP Call Back URL)
2665 */
2666 public function actionComvivacb()
2667 {
2668 $getParams= W::getRequestParams();
2669 if(empty($getParams)){
2670 throw new CHttpException(404, 'No parameters found.');
2671 }
2672 $getParams['datetime']= new MongoDate();
2673 $getParams['_type']='callback';
2674 $getParams['_partner']='cv_smartfren';
2675 $callbackLog = Yii::app()->mongodb->callback_log;
2676 $getParams['requestedPlan']=($getParams['operationId']=="PS")?'GAMEON_DD':$getParams['requestedPlan'];
2677 $productId = $this->productId($getParams['requestedPlan']);
2678 //check product is available or not
2679 if($productId == 0){
2680 $errorNo=703;
2681 $response=$errorNo.'|ERROR|'. OoredooCb3::errorCode()[$errorNo];
2682 }else{
2683 $data = SubOoredoo::mapMSISDN($getParams['msisdn']);
2684 $getParams['map_msisdn'] = $data['msisdn'];
2685 $getParams['productId'] = $productId;
2686 $response = (new OoredooCb3())->ooredooCback($getParams);
2687 }
2688 echo $response;
2689 try
2690 {
2691 $getParams['_response']=$response;
2692 $callbackLog->insert($getParams);
2693 }
2694 catch (Exception $e)
2695 {
2696 throw $e->getMessage();
2697 }
2698
2699 }
2700
2701 /** #
2702 * CG Notification URL (MDN Query) comviva
2703 */
2704 public function actionComvivacg()
2705 {
2706 $getParams = W::getRequestParams();
2707 $getParams = array_change_key_case($getParams, CASE_LOWER);
2708 $getParams['datetime'] = new MongoDate();
2709 $getParams['_partner'] = 'comviva';
2710 $getParams['_type'] = 'callback_cg';
2711 $callbackLog = Yii::app()->mongodb->callback_log;
2712 $callbackLog->insert($getParams);
2713 echo "OK";
2714 }
2715
2716 /**
2717 * Tanla Cb
2718 * @throws CHttpException
2719 * @throws type
2720 */
2721 public function actionTanlaInCb()
2722 {
2723 $getParams = W::getRequestParams();
2724 if (empty($getParams)) {
2725 throw new CHttpException(404, 'No parameters found.');
2726 }
2727 $getParams = array_change_key_case($getParams, CASE_LOWER);
2728 $getParams['datetime'] = new MongoDate();
2729 $getParams['_partner'] = 'Tanla';
2730 $getParams['_type'] = 'callback';
2731 $callbackLog = Yii::app()->mongodb->callback_log;
2732 if((isset($getParams['pid']) && !empty($getParams['pid']))and (isset($getParams['sid']) && !empty($getParams['sid'])))
2733 {
2734 //$getParams['eventid'] =$getParams['service'];
2735 $productId = $this->productId($getParams['sid']); // Set product_id
2736 //check product is available or not
2737 if ($productId == false) {
2738 $response = "service not found.!";
2739 } else {
2740 $getParams['product_id'] = $productId;
2741 $code=(new TanlaCb())->TanlaCback($getParams);
2742 $response =(new TanlaCb())->responseCode()[$code];
2743 }
2744 }else{
2745 $response = "Parameter not found.!";
2746 }
2747 print_r($response);
2748 try {
2749 $getParams['_response'] = $response;
2750 $callbackLog->insert($getParams);
2751 } catch (Exception $e) {
2752 throw $e->getMessage();
2753 }
2754 }
2755
2756 /**
2757 * Malaysia Intg - Celcom callback
2758 */
2759 public function actionCelcomCb() {
2760
2761 $json_string= trim(file_get_contents('php://input'));
2762 $getParams = json_decode($json_string, TRUE);
2763 if(empty($getParams)){
2764 $getParams = W::getRequestParams();
2765 if (empty($getParams)) {
2766 //throw new CHttpException(404, 'No parameters found.');
2767 }
2768 }
2769 $getParams = array_change_key_case($getParams, CASE_LOWER);
2770 $getParams['datetime'] = new MongoDate();
2771 $getParams['_partner'] = 'celcom';
2772 $getParams['_type'] = 'callback';
2773 $callbackLog1 = SubCelcom::getCollection();
2774 //$getParams['_response'] = $response;
2775 $callbackLog1->insert($getParams);
2776// print_r('success');exit();
2777 // temp exit below code
2778 $getParams = W::getRequestParams();
2779 if (empty($getParams)) {
2780 throw new CHttpException(404, 'No parameters found.');
2781 }
2782
2783 $getParams = array_change_key_case($getParams, CASE_LOWER);
2784 $getParams['datetime'] = new MongoDate();
2785 $getParams['_partner'] = 'celcom';
2786 $getParams['_type'] = 'callback';
2787// $callbackLog = Yii::app()->mongodb->callback_log;
2788 $callbackLog = SubCelcom::getCollection();
2789 if(isset($getParams['msisdn']) && !empty($getParams['msisdn']))
2790 {
2791 $getParams['msisdn']=str_replace("+",'',$getParams['msisdn']);
2792 $clientCorrelator=$getParams['clientcorrelator'];
2793 $data=SubCelcom::mapCLIENTCORRELATOR($clientCorrelator);
2794 if(isset($data['msg']))
2795 {
2796 $response = "service not found.!";
2797 }
2798 else{
2799 $getParams['product_id']=$data['productId'];
2800 $getParams['event_id']=$data['eventId'];
2801 $code=(new CelcomCb())->CelcomCback($getParams);
2802 $response =(new CelcomCb())->responseCode()[$code];
2803 }
2804 }else{
2805 $response = "Parameter not found.!";
2806 }
2807 print_r($response);
2808 try {
2809 $getParams['_response'] = $response;
2810 $callbackLog->insert($getParams);
2811 } catch (Exception $e) {
2812 throw $e->getMessage();
2813 }
2814 }
2815
2816 /**
2817 * Malaysia Intg - Celcom SMS callback
2818 */
2819 public function actionCelcomSmsCb() {
2820
2821 $getParams = W::getRequestParams();
2822 $getParams['time'] = new MongoDate();
2823 $getParams['_partner'] = 'celcom';
2824 $getParams['_type'] = 'smsreminder';
2825 $getParams['content'] = file_get_contents("php://input");
2826 $callbackLog = SubCelcom::getCollection();
2827
2828 try {
2829 $callbackLog->insert($getParams);
2830 } catch (Exception $e) {
2831 throw $e->getMessage();
2832 }
2833 }
2834 /**
2835 * IraqActel Intg callback
2836 */
2837 public function actionIraqActelCb() {
2838
2839 $getParams = W::getRequestParams();
2840 if (empty($getParams)) {
2841 throw new CHttpException(404, 'No parameters found.');
2842 }
2843
2844 $getParams = array_change_key_case($getParams, CASE_LOWER);
2845 $getParams['time'] = new MongoDate();
2846 $getParams['_partner'] = 'IraqActel';
2847 $getParams['_type'] = 'callback';
2848 $callbackLog = SubIraqActel::getCollection(); //Yii::app()->mongodb->callback_log;
2849 if(isset($getParams['destination']) && !empty($getParams['destination']))
2850 {
2851 //$getParams['eventid'] =$getParams['service'];
2852 $productId = $this->productId($getParams['destination']); // Set product_id
2853 //check product is available or not
2854 if ($productId == false) {
2855 $response = "service not found.!";
2856 } else {
2857 $getParams['product_id'] = $productId;
2858 $code=(new IraqActelCb())->IraqActelCback($getParams);
2859 $response =(new IraqActelCb())->responseCode()[$code];
2860 }
2861 }else{
2862 $response = "shortcode not found.!";
2863 }
2864 print_r($response);
2865 try {
2866 $getParams['_response'] = $response;
2867 $callbackLog->insert($getParams);
2868 } catch (Exception $e) {
2869 throw $e->getMessage();
2870 }
2871 }
2872 /**
2873 * IraqActel msg callback
2874 */
2875 public function actionIraqActelMsgDLR(){
2876
2877 $getParams = W::getRequestParams();
2878 if (empty($getParams)) {
2879// throw new CHttpException(404, 'No parameters found.');
2880 }
2881 $getParams = array_change_key_case($getParams, CASE_LOWER);
2882 $getParams['time'] = new MongoDate();
2883 $getParams['_partner'] = 'IraqActel';
2884 $getParams['_type'] = 'callbackDLR';
2885 $callbackLog = SubIraqActel::getCollection();
2886 if(isset($getParams['shortcode']) && !empty($getParams['shortcode']))
2887 {
2888 //$getParams['eventid'] =$getParams['service'];
2889 $productId = $this->productId($getParams['shortcode']); // Set product_id
2890 //check product is available or not
2891 if ($productId == false) {
2892 $response = "service not found.!";
2893 } else {
2894 $getParams['product_id'] = $productId;
2895 $code=(new IraqActelCb())->IraqActelCback($getParams);
2896 $response =(new IraqActelCb())->responseCode()[$code];
2897 }
2898 }else{
2899 $response = "shortcode not found.!";
2900 }
2901 print_r($response);
2902 $getParams['_response'] = $response;
2903 try {
2904 $getParams['_response'] = $response;
2905 $callbackLog->insert($getParams);
2906 } catch (Exception $e) {
2907 throw $e->getMessage();
2908 }
2909
2910 }
2911 /**
2912 * Jordan callabck
2913 */
2914 public function actionJordanActCb() {
2915
2916 $getParams = W::getRequestParams();
2917 if (empty($getParams)) {
2918// throw new CHttpException(404, 'No parameters found.');
2919 }
2920
2921 $getParams = array_change_key_case($getParams, CASE_LOWER);
2922 $getParams['time'] = new MongoDate();
2923 $getParams['_partner'] = 'JordanActel';
2924 $getParams['_type'] = 'callback';
2925 $callbackLog = SubIraqActel::getCollection(); //Yii::app()->mongodb->callback_log;
2926 $getParams['data'] = 'withoutprocess';
2927 $callbackLog->insert($getParams);
2928// print_r('success');
2929
2930 if(isset($getParams['destination']) && !empty($getParams['destination']))
2931 {
2932 $Eid = $getParams['destination']."_GMS";
2933 if(strpos(strtoupper($getParams['smstext']), 'BEB') !== false){
2934 $Eid = $getParams['destination']."_BEB";
2935 }
2936
2937 $getParams['shortcode']= $Eid;
2938 $getParams['smslangtype']= 'eng';
2939 //$getParams['eventid'] =$getParams['service'];
2940 $productId = $this->productId($Eid); // Set product_id
2941 //check product is available or not
2942 if ($productId == false) {
2943 $response = "service not found.!";
2944 } else {
2945 $getParams['data'] = 'withprocess';
2946 $getParams['product_id'] = $productId;
2947 $code=(new IraqActelCb())->IraqActelCback($getParams);
2948 $response =(new IraqActelCb())->responseCode()[$code];
2949 }
2950 }else{
2951 $response = "shortcode not found.!";
2952 }
2953 print_r($response);
2954 try {
2955 $getParams['_response'] = $response;
2956 $callbackLog->insert($getParams);
2957 } catch (Exception $e) {
2958 throw $e->getMessage();
2959 }
2960 }
2961 /**
2962 * Jordan Orange Dlr mobpair
2963 */
2964 public function actionJordanOrgDLR(){
2965
2966 $getParams = W::getRequestParams();
2967 if (empty($getParams)) {
2968// throw new CHttpException(404, 'No parameters found.');
2969 }
2970 $getParams = array_change_key_case($getParams, CASE_LOWER);
2971 $getParams['time'] = new MongoDate();
2972 $getParams['_partner'] = 'JordanActel';
2973 $getParams['_type'] = 'callbackDLR';
2974
2975 $this->storeLog('jordan_dlr_mp','dlr');
2976// print_r('success');
2977 $callbackLog = SubIraqActel::getCollection();
2978
2979 if(isset($getParams['billedshortcode']) && !empty($getParams['billedshortcode']))
2980 {
2981 $Eid = $getParams['billedshortcode']."_GMS";
2982 if($getParams['id_application']=='4431'){
2983 $Eid = $getParams['billedshortcode']."_BEB";
2984 }
2985 $getParams['shortcode']= $Eid;
2986 $getParams['smslangtype']= 'eng';
2987 //$getParams['eventid'] =$getParams['service'];
2988 $productId = $this->productId($Eid); // Set product_id
2989 //check product is available or not
2990 if ($productId == false) {
2991 $response = "service not found.!";
2992 } else {
2993 $getParams['product_id'] = $productId;
2994// $code=(new IraqActelCb())->IraqActelCback($getParams);
2995 $code=(new IraqActelMPCb())->IraqActelCback($getParams);
2996 $response =(new IraqActelCb())->responseCode()[$code];
2997 }
2998 }else{
2999 $response = "shortcode not found.!";
3000 }
3001 print_r($response);
3002// $getParams['_response'] = $response;
3003 try {
3004 $getParams['data'] = 'withprocess';
3005 $getParams['_response'] = $response;
3006 $callbackLog->insert($getParams);
3007 } catch (Exception $e) {
3008 throw $e->getMessage();
3009 }
3010
3011 }
3012
3013 /** Function
3014 * Iraq actel cb for mp
3015 */
3016 public function IraqCbMP($partner='IraqActel'){
3017
3018 $getParams = W::getRequestParams();
3019 if (empty($getParams)) {
3020// throw new CHttpException(404, 'No parameters found.');
3021 }
3022
3023 // for check DLR params
3024 $this->storeLog('iraq_cb_mp','cb');
3025
3026 $getParams = array_change_key_case($getParams, CASE_LOWER);
3027 $getParams['time'] = new MongoDate();
3028 $getParams['_partner'] = "$partner";
3029 $getParams['_type'] = 'callbackMP';
3030 $callbackLog = SubIraqActel::getCollection(); //Yii::app()->mongodb->callback_log;
3031 if(isset($getParams['destination']) && !empty($getParams['destination']))
3032 {
3033 $eventid = $getParams['destination'].'_MO';
3034 $getParams['eventid'] = $eventid;
3035 $productId = $this->productId($eventid); // Set product_id
3036 //check product is available or not
3037 if ($productId == false) {
3038 $response = "service not found.!";
3039 } else {
3040 $getParams['product_id'] = $productId;
3041 $code=(new IraqActelCb())->IraqActelCback($getParams);
3042 $response =(new IraqActelCb())->responseCode()[$code];
3043 }
3044 }else{
3045 $response = "shortcode not found.!";
3046 }
3047 print_r($response);
3048 try {
3049 $getParams['EXE'] = 'afterExecution';
3050 $getParams['_response'] = $response;
3051 $callbackLog->insert($getParams);
3052 } catch (Exception $e) {
3053 throw $e->getMessage();
3054 }
3055 }
3056 /** Function
3057 * Iraq actel dlr mp
3058 */
3059 public function IraqDLRMP($partner='IraqActel'){
3060
3061 $getParams = W::getRequestParams();
3062 if (empty($getParams)) {
3063// throw new CHttpException(404, 'No parameters found.');
3064 }
3065 $getParams = array_change_key_case($getParams, CASE_LOWER);
3066 $getParams['time'] = new MongoDate();
3067 $getParams['_partner'] = "$partner";
3068 $getParams['_type'] = 'callbackDLRMP';
3069
3070 // for check DLR params
3071 $this->storeLog('iraq_dlr_mp','dlr');
3072
3073 $callbackLog = SubIraqActel::getCollection();
3074 if(isset($getParams['shortcode']) && !empty($getParams['shortcode']) or isset($getParams['billedshortcode']) && !empty($getParams['billedshortcode']))
3075 {
3076 $shortcode = isset($getParams['shortcode'])?$getParams['shortcode']:$getParams['billedshortcode'];
3077
3078 // To Check which flow user have select mo or pin flow 1 equals mo and 2 equals pin flow
3079 if($getParams['flow'] == '1' and ($partner == 'IraqActel' or $partner == 'Bahrain_batelco' or $partner == 'Bahrain')){
3080 $shortcode = $shortcode.'_MO';
3081 }
3082
3083 $productId = $this->productId($shortcode); // Set product_id
3084
3085 //check product is available or not
3086 if($productId == false){
3087 $response = "service not found.!";
3088 }else{
3089 $getParams['product_id'] = $productId;
3090 $getParams['shortcode'] = $shortcode;
3091 $code=(new IraqActelMPCb())->IraqActelCback($getParams);
3092 $response =(new IraqActelCb())->responseCode()[$code];
3093
3094 // For Unsub
3095 if($getParams['action'] == 'UNSUB'){
3096
3097 $shortcode = $shortcode.'_MO';
3098 $productId = $this->productId($shortcode);
3099
3100 $getParams['product_id'] = $productId;
3101 $getParams['shortcode'] = $shortcode;
3102
3103 $code=(new IraqActelMPCb())->IraqActelCback($getParams);
3104 $response =(new IraqActelCb())->responseCode()[$code];
3105 }
3106 }
3107 }else{
3108 $response = "shortcode not found.!";
3109 }
3110 print_r($response);
3111 $getParams['_response'] = $response;
3112 try {
3113 $getParams['_response'] = $response;
3114 $getParams['EXE'] = 'afterExecution';
3115 $callbackLog->insert($getParams);
3116 } catch (Exception $e) {
3117 throw $e->getMessage();
3118 }
3119 }
3120 /**
3121 * Iraq actel dlr mp
3122 */
3123 public function actionIraqDLRMP(){
3124 $this->IraqDLRMP('IraqActel');
3125 }
3126 /**
3127 * Iraq actel cb for mp
3128 */
3129 public function actionIraqCbMP(){
3130 $this->IraqCbMP('IraqActel');
3131 }
3132 /**
3133 * For KSA Billing callback MP
3134 */
3135 public function actionKSADLRMP(){
3136
3137 $getParams = W::getRequestParams();
3138// if (empty($getParams)) {
3139// throw new CHttpException(404, 'No parameters found.');
3140// }
3141
3142 $getParams = array_change_key_case($getParams, CASE_LOWER);
3143 $getParams['time'] = new MongoDate();
3144 $getParams['_partner'] = 'KSA_MP';
3145 $getParams['_type'] = 'callbackDLRMP';
3146
3147 // For only testing purpose START
3148 $this->storeLog('ksa_dlr_mp','dlr');
3149 // For only testing purpose END
3150
3151 $callbackLog = SubIraqActel::getCollection();
3152 if(isset($getParams['shortcode']) && !empty($getParams['shortcode']) or isset($getParams['billedshortcode']) && !empty($getParams['billedshortcode']))
3153 {
3154 $shortcode = isset($getParams['shortcode'])?$getParams['shortcode']:$getParams['billedshortcode'];
3155// if($shortcode == '608144'){
3156// $shortcode = '801420';
3157// }
3158
3159 $productId = $this->productId($shortcode); // Set product_id
3160
3161 //check product is available or not
3162 if ($productId == false) {
3163 $response = "service not found.!";
3164 }else{
3165 $getParams['product_id'] = $productId;
3166 $getParams['shortcode'] = $shortcode;
3167
3168 $code=(new IraqActelMPCb())->IraqActelCback($getParams);
3169// $code=(new IraqActelCb())->IraqActelCback($getParams);
3170 $response =(new IraqActelCb())->responseCode()[$code];
3171 }
3172 }else{
3173 $response = "shortcode not found.!";
3174 }
3175 print_r($response);
3176// $getParams['_response'] = $response;
3177 try {
3178 $getParams['_response'] = $response;
3179// $getParams['exe_type'] = 'AfterExecution';
3180 $callbackLog->insert($getParams);
3181 } catch (Exception $e) {
3182 throw $e->getMessage();
3183 }
3184 }
3185 /**
3186 * TPay Intg callback
3187 */
3188 public function actionTPayCb() {
3189
3190 $getParams = W::getRequestParams();
3191 if (empty($getParams)) {
3192 throw new CHttpException(404, 'No parameters found.');
3193 }
3194
3195 $getParams = array_change_key_case($getParams, CASE_LOWER);
3196 $getParams['time'] = new MongoDate();
3197 $getParams['_partner'] = 'TPay';
3198 $getParams['_type'] = 'callback';
3199// $callbackLog = Yii::app()->mongodb->callback_log;
3200 $callbackLog = SubTPay::getCollection();
3201 if(isset($getParams['action']) && !empty($getParams['action']))
3202 {
3203 $datamap['subscriptioncontractid']=(string)$getParams['subscriptioncontractid'];
3204 $Data = (new SubTPay())->mapEventid($datamap);
3205 //check product is available or not
3206 if(isset($Data)){
3207 $getParams['product_id'] = $Data['product_id']; // Set product_id
3208
3209 if(!isset($getParams['msisdn'])){
3210 $getParams['msisdn'] = $Data['msisdn'];
3211 }
3212 if(!isset($getParams['eventid'])){
3213 $getParams['eventid'] = $Data['eventid'];
3214 }
3215 $getParams['operatorcode'] = $Data['operatorcode'];
3216 $code=(new TPayCb())->TPayCback($getParams);
3217 $response =(new TPayCb())->responseCode()[$code];
3218 }else{
3219 $response = "service not found.!";
3220 }
3221 }else{
3222 $response = "Parameter not found.!";
3223 }
3224 print_r($response);
3225 try {
3226 $getParams['_response'] = $response;
3227 $callbackLog->insert($getParams);
3228 } catch (Exception $e) {
3229 throw $e->getMessage();
3230 }
3231 }
3232 /**
3233 * UK Intg callback
3234 */
3235 public function actionUkCb() {
3236
3237 $getParams = W::getRequestParams();
3238 if(empty($getParams)){
3239 throw new CHttpException(404, 'No parameters found.');
3240 }
3241
3242 $getParams = array_change_key_case($getParams, CASE_LOWER);
3243 $getParams['time'] = new MongoDate();
3244 $getParams['_partner'] = 'ukfitguru';
3245 $getParams['_type'] = 'callback';
3246 $callbackLog = SubUkFitguru::getCollection();
3247
3248 if(isset($getParams['msisdn']) && !empty($getParams['msisdn']))
3249 {
3250 $eventid = 'uk_test-evnt';
3251 $productId = $this->productId($eventid); // Set product_id
3252 //check product is available or not
3253 if ($productId == false) {
3254 $response = "service not found.!";
3255 } else {
3256 $getParams['product_id'] = $productId;
3257 $getParams['event_id'] = $eventid;
3258 $code=(new UkFitguruCb())->UkFitguruCback($getParams);
3259 $response =(new UkFitguruCb())->responseCode()[$code];
3260 }
3261 }else{
3262 $response = "parameter not found.!";
3263 }
3264 print_r($response);
3265 try {
3266 $getParams['_response'] = $response;
3267 $callbackLog->insert($getParams);
3268 } catch (Exception $e) {
3269 throw $e->getMessage();
3270 }
3271 }
3272 /**
3273 * TPAY pin and msisdn set
3274 */
3275 public function actionTpayPinMgmt() {
3276
3277 $getParams = W::getRequestParams();
3278 if(empty($getParams)){
3279 //$json_string= trim(file_get_contents('php://input'));
3280 $getParams = [];
3281 }
3282 $getParams = array_change_key_case($getParams, CASE_LOWER);
3283 if(isset($getParams['resendpin']) and $getParams['resendpin']=='rpin'){
3284 // resend pin
3285 (new SubTPay())->ResendUserPin();
3286 }
3287 elseif(isset($getParams['pin']) and $getParams['pin']=='pin'){
3288 // pin verify
3289 (new SubTPay())->VerifyUserPin($getParams);
3290 }
3291 elseif(isset($getParams['type']) and $getParams['type']=='sendotp'){
3292 // send otp
3293 (new SubTPay())->sendOtp($getParams);
3294 }
3295 elseif(isset($getParams['type']) and $getParams['type']=='setmsisdn'){
3296 // set msisdn
3297 (new SubTPay())->setMsisdn($getParams);
3298 }
3299 elseif(isset($getParams['type']) and $getParams['type']=='verifycontract'){
3300 // Verify Subscription Contract
3301 (new SubTPay())->verifySubscription($getParams);
3302 }
3303 elseif(isset($getParams['type']) and $getParams['type']=='resendcpin'){
3304 // resend contract pin
3305 (new SubTPay())->resendPinSubscription($getParams);
3306 }
3307 elseif(isset($getParams['type']) and $getParams['type']=='getmsisdn'){
3308 // get msisdn
3309 (new SubTPay())->mapEventid($getParams);
3310 }
3311 elseif(isset($getParams['type']) and $getParams['type']=='sentaccessurl'){
3312 // get msisdn
3313 (new SubTPay())->sentAccessUrl($getParams);
3314 }
3315 else{
3316 // Store in mongo
3317 $toStore = [
3318 'type' => 'error',
3319 'getParams' => $getParams,
3320 'time' => new MongoDate()
3321 ];
3322 SubTPay::getCollection()->save($toStore);
3323 }
3324 }
3325 /**
3326 * TPay Intg callback Qatar Vodafone tpayqatarcb
3327 */
3328 public function actionTPayQatarCb() {
3329
3330 $getParams = W::getRequestParams();
3331 if (empty($getParams)) {
3332 throw new CHttpException(404, 'No parameters found.');
3333 }
3334
3335 $getParams = array_change_key_case($getParams, CASE_LOWER);
3336 $getParams['time'] = new MongoDate();
3337 $getParams['_partner'] = 'TPayQatar';
3338 $getParams['_type'] = 'callback';
3339// $callbackLog = Yii::app()->mongodb->callback_log;
3340 $callbackLog = SubTPay::getCollection();
3341 if(isset($getParams['action']) && !empty($getParams['action']))
3342 {
3343 $datamap['subscriptioncontractid']=(string)$getParams['subscriptioncontractid'];
3344 $Data = (new SubTPay())->mapEventid($datamap);
3345 //check product is available or not
3346 if(isset($Data)){
3347 $getParams['product_id'] = $Data['product_id']; // Set product_id
3348 $getParams['eventid'] = $Data['eventid'];
3349 if(!isset($getParams['msisdn'])){
3350 $getParams['msisdn'] = $Data['msisdn'];
3351 }
3352 $code=(new TPayCb())->TPayCback($getParams);
3353 $response =(new TPayCb())->responseCode()[$code];
3354 }else{
3355 $response = "service not found.!";
3356 }
3357 }else{
3358 $response = "Parameter not found.!";
3359 }
3360 print_r($response);
3361 try {
3362 $getParams['_response'] = $response;
3363 $callbackLog->insert($getParams);
3364 } catch (Exception $e) {
3365 throw $e->getMessage();
3366 }
3367 }
3368 /**
3369 * Thailand Macro MO callback
3370 * @throws CHttpException
3371 * @throws type
3372 */
3373 public function actionMacroMo(){
3374 $this->MacroMo('thailand');
3375 }
3376 /**
3377 * Thailand Macro DN callback
3378 * @throws CHttpException
3379 * @throws type
3380 */
3381 public function actionMacroDn(){
3382 $this->MacroDn('thailand');
3383 }
3384 /**
3385 * Thailand Macro MO callback
3386 * @throws CHttpException
3387 * @throws type
3388 */
3389 public function actionMacroIndoMo(){
3390 $this->MacroMo('indo');
3391 }
3392 /**
3393 * Thailand Macro DN callback
3394 * @throws CHttpException
3395 * @throws type
3396 */
3397 public function actionMacroIndoDn(){
3398 $this->MacroDn('indo');
3399 }
3400
3401 private function MacroMo($partner="thailand")
3402 {
3403 $getParams = W::getRequestParams();
3404 if(empty($getParams)){
3405// throw new CHttpException(404, 'No parameters found.');
3406 }
3407 $getParams = array_change_key_case($getParams, CASE_LOWER);
3408 $getParams['rettime'] = $getParams['time'];
3409 $getParams['time'] = new MongoDate();
3410 $getParams['_partner'] = $partner;
3411 $getParams['_type'] = 'MO';
3412// print_r($getParams);
3413 $callbackLog = SubThailand::getCollection();
3414
3415 if(isset($getParams['shortcode']) and isset($getParams['text']))
3416 {
3417 $KWs = explode(" ", $getParams['text']);
3418 if(isset($KWs[1]))
3419 {
3420 $getParams['event_id'] = $getParams['shortcode']."_".strtoupper($KWs[1]);
3421 }else{
3422 $getParams['event_id'] = $getParams['shortcode']."_".strtoupper($KWs[0]);
3423 }
3424 $productId = $this->productId($getParams['event_id']);
3425
3426 if ($productId == false) {
3427 $response = "service not found.!";
3428 } else {
3429 $getParams['product_id'] = $productId;
3430// print_r($getParams);
3431 $product=(new ProductEx())->findByPk($productId);
3432 $productSubkeyArr=$product->conf['subkey'];
3433 $key=$getParams['text'];
3434// $key="SUB1";
3435// if($getParams['telcoid']==1){ // DTAC so in parking mode
3436//
3437 if(in_array($key,$productSubkeyArr)){
3438 $getParams['action']="PARK";
3439 }
3440 else{
3441 $getParams['action']="UNSUB";
3442 }
3443//
3444// }else
3445// {
3446// if(in_array($key,$productSubkeyArr)){
3447// $getParams['action']="SUB";
3448// }
3449// else{
3450// $getParams['action']="UNSUB";
3451// }
3452// }
3453// print_r(new ThaiCb());
3454 $code=(new ThaiCb())->ThaiCback($getParams);
3455 $response =(new ThaiCb())->responseCode()[$code];
3456 }
3457 }else{
3458 $response = "shortcode not found.!";
3459 }
3460
3461 try {
3462 $getParams['_response'] = $response;
3463 $callbackLog->insert($getParams);
3464 $response="-1";
3465 print_r($response);
3466 } catch (Exception $e) {
3467 throw $e->getMessage();
3468 }
3469 }
3470
3471 private function MacroDn($partner="thailand")
3472 {
3473 $getParams=W::getRequestParams();
3474 if(empty($getParams)){
3475// throw new CHttpException(404,'No parameters Found.');
3476 }
3477 $getParams = array_change_key_case($getParams, CASE_LOWER);
3478 $getParams['time']=new MongoDate();
3479 $getParams['_partner']=$partner;
3480 $getParams['_type']='DN';
3481
3482 $callbackLog = SubThailand::getCollection();
3483 if(isset($getParams['shortcode']) && isset($getParams['keyword']))
3484 {
3485 $getParams['event_id'] = $getParams['shortcode']."_".strtoupper($getParams['keyword']);
3486 $productId = $this->productId($getParams['event_id']);
3487
3488 if($productId == false){
3489 $response="service not found.!";
3490 }
3491 else{
3492 $getParams['product_id'] = $productId;
3493 $code=(new ThaiCb())->ThaiCbackDN($getParams);
3494 $response =(new ThaiCb())->responseCode()[$code];
3495 }
3496 }
3497 else{
3498 $response = "shortcode not found.!";
3499 }
3500 try{
3501 $getParams['_response'] = $response;
3502 $callbackLog->insert($getParams);
3503 print_r($response);
3504 } catch (Exception $e) {
3505 throw $e->getMessage();
3506 }
3507 }
3508 public function actionfortumoDN()
3509 {
3510 $getParams=W::getRequestParams();
3511 if(empty($getParams)){
3512 throw new CHttpException(404,'No Parameters Found...');
3513 }
3514 $getParams = array_change_key_case($getParams,CASE_LOWER);
3515 $getParams['time']=new MongoDate();
3516 $getParams['_partner']='Fortumo';
3517 $getParams['type']='callbackDN';
3518
3519 // For Testing purpose only
3520 $this->storeLog('fortumo_dn_mp','dn');
3521 // For Testing purpose only
3522
3523 $callbackLog= SubFortumo::getCollection();
3524
3525 if(isset($getParams['service_id'])&& !empty($getParams['service_id'])){
3526// $id=$getParams['service_id'].'_'.round($getParams['price']);
3527 $id=$getParams['service_id'];
3528 $getParams['event_id']=$id;
3529 $productId=$this->productId($id);
3530 if($productId==FALSE){
3531 $response="product not found";
3532 }
3533 else{
3534 $getParams['product_id'] = $productId;
3535 $code=(new FortumoCB())->FortumoCallback($getParams);
3536 $response=(new FortumoCB())->responseCodes()[$code];
3537 }
3538 }
3539 else{
3540 $response="parameter not found";
3541 }
3542 try{
3543 $getParams['_response'] = $response;
3544 $getParams['Exetype'] = 'After execution';
3545 $callbackLog->insert($getParams);
3546 $response=200;
3547 print_r($response);
3548 }catch (Exception $e) {
3549 throw $e->getMessage();
3550 }
3551 }
3552 /**
3553 * fortumo callback
3554 * @throws CHttpException
3555 * @throws type
3556 */
3557 public function actionFortumoCb()
3558 {
3559 $getParams=W::getRequestParams();
3560 if(empty($getParams)){
3561 throw new CHttpException(404,'No Parameters Found...');
3562 }
3563 $getParams = array_change_key_case($getParams,CASE_LOWER);
3564// $ID = 'heee';
3565// $getParams['ID1']=$ID;
3566 $getParams['time']=new MongoDate();
3567 $getParams['_partner']='Fortumo';
3568 $getParams['type']='callback';
3569
3570 $callbackLog= SubFortumo::getCollection();
3571 if(isset($getParams['service_id'])&& !empty($getParams['service_id'])){
3572
3573 $productId=$this->productId($getParams['service_id']);
3574 if($productId==FALSE){
3575 $response="product not found";
3576 }
3577 else{
3578 $getParams['product_id'] = $productId;
3579// $code=(new FortumoCB())->FortumoCback($getParams);
3580 $code=(new FortumoCB())->FortumoCallback($getParams);
3581 $response=(new FortumoCB())->responseCodes()[$code];
3582// print_r($response);
3583 }
3584 }
3585 else{
3586 $response="parameter not found";
3587 }
3588 try {
3589 $getParams['_response'] = $response;
3590 $callbackLog->insert($getParams);
3591 print_r($response);
3592 } catch (Exception $e) {
3593 throw $e->getMessage();
3594 }
3595 }
3596 public function actionTPayUaeCb()
3597 {
3598 $this->TpayCallback('tpayuaecb_mp');
3599
3600// $getParams = W::getRequestParams();
3601// if (empty($getParams)) {
3602// throw new CHttpException(404, 'No parameters found.');
3603// }
3604//
3605// $getParams = array_change_key_case($getParams, CASE_LOWER);
3606// $getParams['time'] = new MongoDate();
3607// $getParams['_partner'] = 'TPayUae';
3608// $getParams['_type'] = 'callback';
3609//// $callbackLog = Yii::app()->mongodb->callback_log;
3610// $callbackLog = SubTPay::getCollection();
3611// if(isset($getParams['action']) && !empty($getParams['action']))
3612// {
3613// $datamap['subscriptioncontractid']=(string)$getParams['subscriptioncontractid'];
3614// $Data = (new SubTPay())->mapEventid($datamap);
3615// //check product is available or not
3616// if(isset($Data)){
3617// $getParams['product_id'] = $Data['product_id']; // Set product_id
3618// $getParams['eventid'] = $Data['eventid'];
3619// if(!isset($getParams['msisdn'])){
3620// $getParams['msisdn'] = $Data['msisdn'];
3621// }
3622// $code=(new TPayCb())->TPayCback($getParams);
3623// $response =(new TPayCb())->responseCode()[$code];
3624// }else{
3625// $response = "service not found.!";
3626// }
3627// }else{
3628// $response = "Parameter not found.!";
3629// }
3630// print_r($response);
3631// try {
3632// $getParams['_response'] = $response;
3633// $callbackLog->insert($getParams);
3634// } catch (Exception $e) {
3635// throw $e->getMessage();
3636// }
3637 }
3638 /**
3639 * Indo Macro MO callback mobpair
3640 * @throws CHttpException
3641 * @throws type
3642 */
3643 public function actionIndoMacroMoMp(){
3644
3645 $getParams = W::getRequestParams();
3646 $getParams = array_change_key_case($getParams, CASE_LOWER);
3647 $getParams['rettime'] = $getParams['time'];
3648 $getParams['time'] = new MongoDate();
3649 $getParams['_partner'] = 'mk_indo_mp';
3650 $getParams['_type'] = "callback_mo";
3651
3652 // for log
3653 $this->storeLog('indomk_mo_mp','mo_mp');
3654
3655 $callbackLog = SubIndoPsms::getCollection();
3656 // check which servcie is arrive Gamesta or bebeauty
3657 $keyword = strtolower($getParams['text']);
3658
3659 if(strpos($keyword, 'stop') !== false or strpos($keyword, 'unreg') !== false){
3660 // unsub
3661 $getParams['action'] = 'UNSUB';
3662 // unsub gsta
3663 $eventid = '95799_GSTA';
3664 if(strpos($keyword, 'beb') !== false){
3665 // unsub beb
3666 $eventid = '95799_BEB';
3667 }
3668 }
3669 else{
3670 // sub
3671 $getParams['action'] = 'PARK';
3672 // Gamesta
3673 $eventid = '95799_GSTA';
3674 if(strpos($keyword, 'beb') !== false){
3675 // sub beb
3676 $eventid = '95799_BEB';
3677 }
3678 }
3679
3680 if(isset($getParams['shortcode']) && !empty($getParams['shortcode']))
3681 {
3682 $productId=$this->productId($eventid);
3683
3684 if($productId==FALSE){
3685 $response="product not found";
3686 }
3687 else{
3688 $getParams['product_id'] = $productId;
3689 $getParams['event_id'] = $eventid;
3690
3691 $code=(new IndoMKCb())->IndoMKCbCback($getParams);
3692 $response=(new IndoMKCb())->responseCode()[$code];
3693 }
3694 }else{
3695 $response = "Parameter not found.!";
3696 }
3697 print_r($response);
3698 try {
3699 $getParams['_response'] = $response;
3700 $getParams['Exetype'] = 'After execution';
3701 $callbackLog->insert($getParams);
3702 } catch (Exception $e) {
3703 throw $e->getMessage();
3704 }
3705
3706 }
3707 /**
3708 * Indo Macro DN callback mobpair
3709 * @throws CHttpException
3710 * @throws type
3711 */
3712 public function actionIndoMacroDnMp(){
3713
3714 $getParams = W::getRequestParams();
3715 if (empty($getParams)) {
3716 throw new CHttpException(404, 'No parameters found.');
3717 }
3718
3719 $getParams = array_change_key_case($getParams, CASE_LOWER);
3720 $getParams['time'] = new MongoDate();
3721 $getParams['_partner'] = 'indodnmp';
3722 $getParams['_type'] = 'callback';
3723
3724// Just for testing pupose START
3725 $this->storeLog('indomk_dn_mp','dn');
3726// Just for testing purpose END
3727
3728 $ref=$getParams['mtid'];
3729
3730 if(isset($ref)){
3731 $subVeocb=new SubIndoPsms();
3732 $detail=$subVeocb->mapCollection()->findOne(['mtid'=>$ref]);
3733
3734 if(isset($detail['event_id'])){
3735
3736 $productId=$this->productId($detail['event_id']);
3737
3738 if($productId==FALSE){
3739 $response="product not found";
3740 }
3741 else{
3742
3743 $getParams['product_id'] = $productId;
3744 $getParams['event_id'] = $detail['event_id'];
3745
3746 // DN CallBack
3747 $code=(new IndoMKCb())->IndoMKCbackDN($getParams);
3748 $response=(new IndoMKCb())->responseCode()[$code];
3749 }
3750 }else{
3751 $response="event_id not found";
3752 }
3753 }else{
3754 $response="mtid and event id not found";
3755 }
3756
3757 $callbackLog = SubIndoPsms::getCollection();
3758 try {
3759 $getParams['_response'] = $response;
3760 $getParams['Exetype'] = 'After execution';
3761 $callbackLog->insert($getParams);
3762 } catch (Exception $e) {
3763 throw $e->getMessage();
3764 }
3765 print_r('Success');
3766 }
3767 /**
3768 * Thailand Macro MO callback mobpair
3769 * @throws CHttpException
3770 * @throws type
3771 */
3772 public function actionThaiMacroMoMp(){
3773
3774 $getParams = W::getRequestParams();
3775// if (empty($getParams)) {
3776// throw new CHttpException(404, 'No parameters found.');
3777// }
3778
3779 $getParams = array_change_key_case($getParams, CASE_LOWER);
3780 $getParams['time'] = new MongoDate();
3781 $getParams['_partner'] = 'thaimomp';
3782 $getParams['_type'] = 'callback';
3783 $callbackLog = SubThailand::getCollection();
3784 print_r('-1');
3785 $callbackLog->insert($getParams);
3786 }
3787 /**
3788 * Thailand Macro DN callback mobpair
3789 * @throws CHttpException
3790 * @throws type
3791 */
3792 public function actionThaiMacroDnMp(){
3793
3794 $getParams = W::getRequestParams();
3795// if (empty($getParams)) {
3796// throw new CHttpException(404, 'No parameters found.');
3797// }
3798
3799 $getParams = array_change_key_case($getParams, CASE_LOWER);
3800 $getParams['time'] = new MongoDate();
3801 $getParams['_partner'] = 'thaidnmp';
3802 $getParams['_type'] = 'callback';
3803 $callbackLog = SubThailand::getCollection();
3804 print_r("Success");
3805 $callbackLog->insert($getParams);
3806 }
3807 /**
3808 * Veoo-Mobpair Mo
3809 */
3810 public function VeooMo($country='veoo'){
3811
3812 $getParams = W::getRequestParams();
3813 $getParams = array_change_key_case($getParams, CASE_LOWER);
3814 $getParams['time'] = new MongoDate();
3815 $getParams['_partner'] = 'veoomp';
3816 $getParams['country'] = $country;
3817 $getParams['_type'] = 'callbackmo';
3818
3819 // for log
3820 $this->storeLog('veoo_mo_mp','mo');
3821
3822 $callbackLog = SubVeoo::getCollection();
3823
3824 if(isset($getParams['service_id']) && !empty($getParams['service_id']))
3825 {
3826 $productId=$this->productId($getParams['service_id']);
3827
3828 if($productId==FALSE){
3829 $response="product not found";
3830 }
3831 else{
3832
3833 $getParams['product_id'] = $productId;
3834 $getParams['eventid'] = $getParams['service_id'];
3835
3836 $subHaystack=['retos','belleza','gamesta','beb']; //BELLEZA
3837 $Unhaystack=['salir','baja','dejar','cancelar','no','stop'];
3838
3839 $getParams['action'] = "";
3840 $SubType = strtolower($getParams['keyword']);
3841
3842 if(in_array($SubType, $Unhaystack))
3843 { // for unsubscribe
3844 $getParams['action'] = "UNSUB";
3845 }
3846 else{
3847 // for subscribe
3848 foreach($subHaystack as $key => $value)
3849 {
3850 if((strpos($SubType,$value) !== false))
3851 {
3852 $getParams['action'] = "SUBPARK";
3853 }
3854 }
3855 }
3856
3857// if(in_array($SubType, $haystack)){
3858// $getParams['action'] = "SUBPARK";
3859// }
3860// if( (strpos($SubType,'retos') !== false) || (strpos($SubType, 'belleza') !== false) || (strpos($SubType, 'gamesta') !== false) || (strpos($SubType, 'beb') !== false) ){
3861// $getParams['action'] = "SUBPARK";
3862// }
3863
3864 $code=(new VeooCb())->VeooCback($getParams);
3865 $response=(new VeooCb())->responseCode()[$code];
3866 }
3867 }else{
3868 $response = "Parameter not found.!";
3869 }
3870 print_r($response);
3871 try {
3872 $getParams['_response'] = $response;
3873 $getParams['Exetype'] = 'After execution';
3874 $callbackLog->insert($getParams);
3875 } catch (Exception $e) {
3876 throw $e->getMessage();
3877 }
3878 }
3879 /**
3880 * Veoo-Mobpair DN
3881 */
3882 public function VeooDn($country='veoo'){
3883
3884 $getParams = W::getRequestParams();
3885 $getParams = array_change_key_case($getParams, CASE_LOWER);
3886 $getParams['time'] = new MongoDate();
3887 $getParams['_partner'] = 'veoomp';
3888 $getParams['country'] = $country;
3889 $getParams['_type'] = 'callbackdn';
3890
3891// Just for testing pupose START
3892 $this->storeLog('veoo_dn_mp','dn');
3893// Just for testing purpose END
3894
3895 $response='FAIL';
3896 if(isset($getParams['id'])){
3897 $ref=$getParams['id'];
3898
3899 $subVeocb=new SubVeoo();
3900 $detail=$subVeocb->getRefCollection()->findOne(['_id'=>$ref]);
3901 $getParams['msgtype'] = 'MT';
3902
3903 if(isset($detail['mt_type']) and $detail['mt_type'] == 'free'){
3904 $response = 'Success';
3905 $getParams['msgtype'] = 'FreeMT';
3906 }
3907
3908 if(isset($detail['mt_type']) and $detail['mt_type'] != 'free'){
3909
3910 // Product id and event id set
3911 if(isset($detail['service_id'])){
3912
3913 $productId=$this->productId($detail['service_id']);
3914
3915 if($productId==FALSE){
3916 $response="product not found";
3917 }
3918 else{
3919
3920 $getParams['product_id'] = $productId;
3921 $getParams['eventid'] = $detail['service_id'];
3922
3923 // DN CallBack
3924 $code=(new VeooCb())->VeooCback($getParams);
3925 $response=(new VeooCb())->responseCode()[$code];
3926 }
3927 }else{
3928 $response="event_id not found";
3929 }
3930 }
3931 }else{
3932 $response = 'Ref_id not found';
3933 }
3934
3935 $callbackLog = SubVeoo::getCollection();
3936 try {
3937 $getParams['_response'] = $response;
3938 $getParams['Exetype'] = 'After execution';
3939 $callbackLog->insert($getParams);
3940 } catch (Exception $e) {
3941 throw $e->getMessage();
3942 }
3943 print_r('Success');
3944 }
3945 /**
3946 * Veoo-Costa_Rica MO
3947 */
3948 public function actionVeooCRicaMO() {
3949 $this->VeooMo('Costa_Rica');
3950 }
3951 /**
3952 * Veoo-Costa_Rica DN
3953 */
3954 public function actionVeooCRicaDN() {
3955 $this->VeooDn('Costa_Rica');
3956 }
3957 /**
3958 * Veoo-Cyprus Mo
3959 */
3960 public function actionVeooCyprusMO() {
3961 $this->VeooMo('Cyprus');
3962 }
3963 /**
3964 * Veoo-Cyprus DN
3965 */
3966 public function actionVeooCyprusDN() {
3967 $this->VeooDn('Cyprus');
3968 }
3969 /**
3970 * Veoo-Greece Mo
3971 */
3972 public function actionVeooGreeceMO() {
3973 $this->VeooMo('Greece');
3974 }
3975 /**
3976 * Veoo-Greece Dn
3977 */
3978 public function actionVeooGreeceDN() {
3979 $this->VeooDn('Greece');
3980 }
3981 /**
3982 * Veoo-Hungary Mo
3983 */
3984 public function actionVeooHugyMO() {
3985 $this->VeooMo('Hungary');
3986 }
3987 /**
3988 * Veoo-Hungary Dn
3989 */
3990 public function actionVeooHugyDN() {
3991 $this->VeooDn('Hungary');
3992 }
3993 /**
3994 * Veoo-Paraguay Mo
3995 */
3996 public function actionVeooParaMO() {
3997 $this->VeooMo('Paraguay');
3998 }
3999 /**
4000 * Veoo-Paraguay Dn
4001 */
4002 public function actionVeooParaDN() {
4003 $this->VeooDn('Paraguay');
4004 }
4005 /**
4006 * Veoo-Thailand Mo
4007 */
4008 public function actionVeooThaiMO() {
4009 $this->VeooMo('Thailand');
4010 }
4011 /**
4012 * Veoo-Thailand Dn
4013 */
4014 public function actionVeooThaiDN() {
4015 $this->VeooDn('Thailand');
4016 }
4017 /** ITALY
4018 * notify of billing and refund transactions
4019 */
4020 public function actionBillingResp()
4021 {
4022 $this->callItalyCB('billing');
4023 }
4024 /** ITALY
4025 * notify of deactivation of a Subscriber
4026 */
4027 public function actionExtDeactivate()
4028 {
4029 $this->callItalyCB('unsub');
4030 }
4031 /** ITALY
4032 * notify of successful and failed activation requests
4033 */
4034 public function actionExtActivate()
4035 {
4036 $this->callItalyCB('optin');
4037 }
4038
4039 /** ITALY
4040 * handle callback request
4041 *
4042 * @param string $call_type optin | billing | unsub
4043 * @throws type
4044 */
4045 public function callItalyCB($call_type = 'optin')
4046 {
4047 $req = trim(file_get_contents('php://input'));
4048 $getParams = json_decode($req, true); //if req is json
4049 if(empty($getParams))
4050 $getParams=(new Common())->xmlToArray($req); //if req is xml
4051 if(empty($getParams))
4052 $getParams = W::getRequestParams(); // if get or post request
4053
4054 $getParams = array_change_key_case($getParams, CASE_LOWER);
4055 $getParams['time'] = new MongoDate();
4056 $getParams['_partner'] = 'Lanc_Italy_MP';
4057 $getParams['action'] = $call_type;
4058
4059 header('Content-Type:application/json');
4060 $responseData = '{"RetCode":1000}';
4061 print_r($responseData);
4062
4063 $callbackLog = SubItaly::getCollection();
4064 //$getParams['ReceiveData'] = "WithoutconfigAct";
4065
4066 if(isset($getParams['serviceid']) && !empty($getParams['serviceid']))
4067 {
4068 $productId=$this->productId($getParams['serviceid']);
4069 if($productId==FALSE){
4070 $response="product not found";
4071 }
4072 else
4073 {
4074 $msisdn = $getParams['tmpenduserid'];
4075 if($getParams['carrid'] and $getParams['carrid'] == 4){ // for only H3G operator
4076 $msisdn = $getParams['enduserid'];
4077 }
4078
4079 // mapping msisdn based on subscribe id
4080 $callbackMap = Yii::app()->mongodb->callback_map_italy;
4081 try
4082 {
4083 $mapData['_id'] = $getParams['subscriberid'];
4084 $mapData['subscriberid'] = $getParams['subscriberid'];
4085 $mapData['msisdn'] = $msisdn;
4086 $mapData['product_id'] = $productId;
4087 $mapData['txnid'] = $getParams['transactionid'];
4088 $mapData['time'] = new MongoDate();
4089 $callbackMap->insert($mapData);
4090 } catch (Exception $exc) {
4091 //echo $exc->getTraceAsString();
4092 }
4093
4094 $getParams['product_id'] = $productId;
4095 $getParams['msisdn'] = $msisdn;
4096 $code = (new ItalyCb())->ItalyCback($getParams);
4097 $response = (new ItalyCb())->responseCode()[$code];
4098 }
4099 }else{
4100 $response = "Parameter not found.!";
4101 }
4102
4103 try {
4104 $getParams['_response'] = $response;
4105 $callbackLog->insert($getParams);
4106 }catch (Exception $e) {
4107 throw $e->getMessage();
4108 }
4109
4110 }
4111
4112 /**
4113 * Bahrain-viva direct notification
4114 * @param type $type
4115 */
4116 public function bahrainnotify($operator='Viva',$country='Bahrain',$partner='bahrain_viva'){
4117
4118 $req= trim(file_get_contents('php://input'));
4119 $getparams = json_decode($req,1); //if req is json
4120
4121 $getparams = array_change_key_case($getparams, CASE_LOWER);
4122 $this->storeLog("$partner",'callback_renew');
4123 $getparams['time'] = new MongoDate();
4124 $getparams['_partner'] = $partner;
4125 $getparams['_type'] = "Callback_renew";
4126 $getparams['operator'] = $operator;
4127 $getparams['country'] = $country;
4128
4129 $callbackLog = (new SubBahTWViva())->getCollection();
4130 // For Event_id START
4131 $getparams['event_id'] = isset($getparams['productid'])?$getparams['productid']:0;
4132
4133 if(isset($getparams['entrychannel']) and $getparams['entrychannel']=='SMS'){
4134 $getparams['event_id'] = $getparams['productid'].'_MO';
4135 }
4136
4137 if(isset($getparams['event_id']) && $getparams['event_id']!=""){
4138
4139 $product_id = $this->productId($getparams['event_id']);
4140 if(!empty($product_id)){
4141 $getparams['product_id'] = $product_id;
4142 $getparams['event_id'] = $getparams['event_id'];
4143 $getparams['requesttype'] = $type;
4144 $getparams['action'] = "Park";
4145 if ($getparams['mnodeliverycode']=='DELIVERED') {
4146 $getparams['action'] = "Renew";
4147 }
4148 $code = (new BahVivaCb())->BahVivaCback($getparams);
4149 $response = (new BahVivaCb())->notifyResponse($code);
4150 }else{
4151 $response=['transactionUUID'=>$getparams['transactionuuid'],'message'=>'No service Found.','inError'=>true,'code'=>'INVALID_PRODUCT_ID'];
4152 $response = (new BahVivaCb())->notifyResponse($response);
4153 }
4154 }else{
4155 $response=['transactionUUID'=>$getparams['transactionuuid'],'message'=>'Parameter Missing.','inError'=>true,'code'=>'INVALID_PRODUCT_ID'];
4156 $response = (new BahVivaCb())->notifyResponse($response);
4157 }
4158 print_r($response);
4159 try{
4160 $getparams['_response'] =$response;
4161 $callbackLog->insert($getparams);
4162 } catch (Exception $e){
4163 throw $e->getMessage();
4164 }
4165 }
4166 public function bahrainmo($operator='Viva',$country='Bahrain',$partner='bahrain_viva'){
4167
4168// $getparams = W::getRequestParams();
4169// $getparams = json_decode($getparams);
4170
4171 $req= trim(file_get_contents('php://input'));
4172 $getparams = json_decode($req, true); // for json request check
4173
4174 $getparams = array_change_key_case($getparams, CASE_LOWER);
4175 $getparams['time'] = new MongoDate();
4176 $getparams['_partner'] = $partner;
4177 $getparams['_type'] = "Callback_Mo";
4178 $getparams['operator'] = $operator;
4179 $getparams['country'] = $country;
4180
4181 $this->storeLog("$partner",'callback_mo');
4182 $callbackLog = (new SubBahTWViva())->getCollection();
4183 if(isset($getparams['productid']) && $getparams['productid']!=""){
4184
4185 $product_id = $this->productId($getparams['productid'].'_MO');
4186 if(!empty($product_id)){
4187 $getparams['product_id'] = $product_id;
4188 $getparams['event_id'] = $getparams['productid'].'_MO';
4189 $getparams['action'] = "SUBPARK";
4190 if (strpos($getparams['text'], 'Unsub') !== false) {
4191 $getparams['action'] = "Unsub";
4192 }
4193 $code = (new BahVivaCb())->BahVivaCback($getparams);
4194 $response = (new BahVivaCb())->notifyResponse($code);
4195 }else{
4196 $response=['transactionUUID'=>$getparams['transactionuuid'],'message'=>'No service Found.','inError'=>true,'code'=>'INVALID_PRODUCT_ID'];
4197 $response = (new BahVivaCb())->notifyResponse($response);
4198 }
4199 }else{
4200 $response=['transactionUUID'=>$getparams['transactionuuid'],'message'=>'Parameter Missing.','inError'=>true,'code'=>'INVALID_PRODUCT_ID'];
4201 $response = (new BahVivaCb())->notifyResponse($response);
4202 }
4203 print_r($response);
4204 try{
4205 $getparams['_response'] =$response;
4206 $callbackLog->insert($getparams);
4207 } catch (Exception $e){
4208 throw $e->getMessage();
4209 }
4210 }
4211
4212 public function bahrainoptin($operator='Viva',$country='Bahrain',$partner='bahrain_viva'){
4213 // $getparams = W::getRequestParams();
4214 $req= trim(file_get_contents('php://input'));
4215 $getparams = json_decode($req, true); // for json request check
4216
4217 $getparams = array_change_key_case($getparams, CASE_LOWER);
4218 $getparams['time'] = new MongoDate();
4219 $getparams['_partner'] = $partner;
4220 $getparams['_type'] = "Callback_OptIn";
4221 $getparams['operator'] = $operator;
4222 $getparams['country'] = $country;
4223
4224 $this->storeLog("$partner",'callback_optin');
4225 $callbackLog = (new SubBahTWViva())->getCollection();
4226 // For Event_id START
4227 $getparams['event_id'] = isset($getparams['productid'])?$getparams['productid']:0;
4228
4229 if(isset($getparams['entrychannel']) and ($getparams['entrychannel']=='SMS' or $getparams['entrychannel']=='CCTOOL')){
4230 $getparams['event_id'] = $getparams['productid'].'_MO';
4231 }
4232 if(isset($getparams['event_id']) && $getparams['event_id']!=""){
4233
4234 $product_id = $this->productId($getparams['event_id']);
4235 if(!empty($product_id)){
4236 $getparams['product_id'] = $product_id;
4237 $getparams['event_id'] = $getparams['event_id'];
4238 $getparams['action'] = "FREETRIAL";
4239 $code = (new BahVivaCb())->BahVivaCback($getparams);
4240 $response = (new BahVivaCb())->notifyResponse($code);
4241 }else{
4242 $response=['transactionUUID'=>$getparams['transactionuuid'],'message'=>'No service Found.','inError'=>true,'code'=>'INVALID_PRODUCT_ID'];
4243 $response = (new BahVivaCb())->notifyResponse($response);
4244 }
4245 }else{
4246 $response=['transactionUUID'=>$getparams['transactionuuid'],'message'=>'Parameter Missing.','inError'=>true,'code'=>'INVALID_PRODUCT_ID'];
4247 $response = (new BahVivaCb())->notifyResponse($response);
4248 }
4249 print_r($response);
4250 try{
4251 $getparams['_response'] =$response;
4252 $callbackLog->insert($getparams);
4253 } catch (Exception $e){
4254 throw $e->getMessage();
4255 }
4256 }
4257 public function bahrainoptout($operator='Viva',$country='Bahrain',$partner='bahrain_viva'){
4258 // $getparams = W::getRequestParams();
4259 $req= trim(file_get_contents('php://input'));
4260 $getparams = json_decode($req, true); // for json request check
4261
4262 $getparams = array_change_key_case($getparams, CASE_LOWER);
4263 $getparams['time'] = new MongoDate();
4264 $getparams['_partner'] = $partner;
4265 $getparams['_type'] = "Callback_OptOut";
4266 $getparams['operator'] = $operator;
4267 $getparams['country'] = $country;
4268 $this->storeLog("$partner",'callback_optout');
4269 $callbackLog = (new SubBahTWViva())->getCollection();
4270
4271 // For Event_id START
4272 $getparams['event_id'] = isset($getparams['productid'])?$getparams['productid']:0;
4273
4274 if(isset($getparams['entrychannel']) and $getparams['entrychannel']=='SMS'){
4275 $getparams['event_id'] = $getparams['productid'].'_MO';
4276 }
4277
4278 if(isset($getparams['event_id']) && $getparams['event_id']!=""){
4279
4280 $product_id = $this->productId($getparams['event_id']);
4281 if(!empty($product_id)){
4282 $getparams['product_id'] = $product_id;
4283 $getparams['event_id'] = $getparams['event_id'];
4284 $getparams['action'] = "Unsub";
4285 $code = (new BahVivaCb())->BahVivaCback($getparams);
4286 $response = (new BahVivaCb())->notifyResponse($code);
4287 }else{
4288 $response=['transactionUUID'=>$getparams['transactionuuid'],'message'=>'No service Found.','inError'=>true,'code'=>'INVALID_PRODUCT_ID'];
4289 $response = (new BahVivaCb())->notifyResponse($response);
4290 }
4291 }else{
4292 $response=['transactionUUID'=>$getparams['transactionuuid'],'message'=>'Parameter Missing.','inError'=>true,'code'=>'INVALID_PRODUCT_ID'];
4293 $response = (new BahVivaCb())->notifyResponse($response);
4294 }
4295 print_r($response);
4296 try{
4297 $getparams['_response'] =$response;
4298 $callbackLog->insert($getparams);
4299 } catch (Exception $e){
4300 throw $e->getMessage();
4301 }
4302 }
4303
4304 public function bahraindobnotify($operator='Viva',$country='Bahrain',$partner='bahrain_viva') {
4305 $req= trim(file_get_contents('php://input'));
4306 $getParams = json_decode($req,1); //if req is json
4307
4308 if(empty($getParams)){
4309
4310 $getParams=(new Common())->xmlToArray($req); //if req is xml
4311 if(empty($getParams)){
4312
4313 $getParams = W::getRequestParams(); // if get or post request
4314 if(empty($getParams)){
4315 throw new CHttpException(404, 'No request found.');
4316 }
4317 }
4318 }
4319 $getParams = array_change_key_case($getParams, CASE_LOWER);
4320
4321 // For Event_id START
4322 $getParams['event_id'] = isset($getParams['productid'])?$getParams['productid']:0;
4323
4324 if(isset($getParams['entrychannel']) and $getParams['entrychannel']=='SMS'){
4325 $getParams['event_id'] = $getParams['productid'].'_MO';
4326 }
4327 // For Event_id END
4328
4329 $getParams['time'] = new MongoDate();
4330 $getParams['_partner'] = $partner;
4331 $getParams['_type'] = "dobnotify";
4332 $getParams['operator'] = $operator;
4333 $getParams['country'] = $country;
4334
4335 $callbackLog = SubBahTWViva::getCollection() ;
4336 // For Only testing purpose START
4337 $this->storeLog("$partner",'callback_notify');
4338 // For Only testing purpose STOP
4339 $productId=$this->productId($getParams['event_id']);
4340 if($productId==FALSE){
4341 $response=['transactionUUID'=>$getParams['transactionuuid'],'message'=>'No service Found.','inError'=>true,'code'=>'INVALID_PRODUCT_ID'];
4342 $response = (new BahVivaCb())->notifyResponse($response);
4343 }
4344 else{
4345
4346 $getParams['product_id'] = $productId;
4347 $getParams['action'] = "Park";
4348 if ($getParams['mnodeliverycode']=='DELIVERED') {
4349 $getParams['action'] = "Sub";
4350 }
4351 $code=(new BahVivaCb())->BahVivaCback($getParams);
4352 $response=(new BahVivaCb())->notifyResponse($code);
4353 $getParams['EXETYPE'] = "AfterExecution";
4354 }
4355
4356 print_r($response);
4357 try {
4358 $getParams['_response'] = $response;
4359 $callbackLog->insert($getParams);
4360 }catch (Exception $e) {
4361 throw $e->getMessage();
4362 }
4363 }
4364 /**
4365 * For mo result
4366 */
4367 public function actionBahmo(){
4368 $this->bahrainmo('Viva','Bahrain','bahrain_viva');
4369 }
4370 /**
4371 * opt-in result store
4372 */
4373 public function actionBahoptin(){
4374 $this->bahrainoptin('Viva','Bahrain','bahrain_viva');
4375 }
4376 /**
4377 * opt-out result store
4378 */
4379 public function actionBahoptout(){
4380 $this->bahrainoptout('Viva','Bahrain','bahrain_viva');
4381 }
4382 /**
4383 * renew result store
4384 */
4385 public function actionBahrenew(){
4386 $this->bahrainnotify('Viva','Bahrain','bahrain_viva');
4387 }
4388 /**
4389 * DOB notifition store
4390 */
4391 public function actionBahdobnotify(){
4392 $this->bahraindobnotify('Viva','Bahrain','bahrain_viva');
4393 }
4394 /*
4395 * Bahrain Batelco Option Mo
4396 */
4397 public function actionBhrbtelmo(){
4398 $this->bahrainoptin('Batelco','Bahrain','bahrain_btelco');
4399 }
4400 /*
4401 * Bahrain Batelco Dn For MT
4402 */
4403 public function actionBhrbteloptin(){
4404 $this->bahrainmo('Batelco','Bahrain','bahrain_btelco');
4405 }
4406 /*
4407 * Bahrain Batelco OptOut
4408 */
4409 public function actionBhrbteloptout(){
4410 $this->bahrainoptout('Batelco','Bahrain','bahrain_btelco');
4411 }
4412 /*
4413 * Bahrain Batelco Renew
4414 */
4415 public function actionBhrbtelrenew(){
4416 $this->bahrainnotify('Batelco','Bahrain','bahrain_btelco');
4417 }
4418 /*
4419 * Bahrain Batelco DOB Charge
4420 */
4421 public function actionBhrbteldob(){
4422 $this->bahraindobnotify('Batelco','Bahrain','bahrain_btelco');
4423 }
4424 /**
4425 *
4426 * @param type $id Product id
4427 */
4428 public function actionTpaytestlog()
4429 {
4430 $request=$_REQUEST;
4431 $request['_type']='tpaylog';
4432 $request['_IP']= isset($_SERVER['REMOTE_ADDR'])?$_SERVER['REMOTE_ADDR']:'';
4433 $request['time']=new MongoDate();
4434 $callback=Yii::app()->mongodb->tpaytestlog;
4435 try {
4436 $callback->insert($request);
4437 echo "tpaytestlog";
4438 } catch (Exception $exc) {
4439
4440 }
4441 }
4442 /**
4443 * nPay callback - mobpair
4444 */
4445 public function actionNpayDN()
4446 {
4447 $req= trim(file_get_contents('php://input'));
4448 $getParams = json_decode($req, true);
4449
4450 if(empty($getParams)){
4451
4452 $getParams=(new Common())->xmlToArray($req); //if req is xml
4453 if(empty($getParams)) {
4454
4455 $getParams = W::getRequestParams(); // if get or post request
4456 if(empty($getParams)){
4457 throw new CHttpException(404, 'No request found.');
4458 }
4459 }
4460 }
4461
4462 $getParams['time'] = new MongoDate();
4463 $getParams['_partner'] = 'npay_mp';
4464 $getParams['_type'] = "callback_dn";
4465
4466// For only testing purpose START
4467 $this->storeLog('npay_dn_mp','dn');
4468// For only testing purpose END
4469
4470 $callbackLog = SubNPay::getCollection();
4471 if($getParams['id_service'] != ''){
4472 $productId = $this->productId($getParams['id_service']);
4473 //check product is available or not
4474 if($productId == false){
4475 $response= "Package id not found.!";
4476 }else{
4477 $getParams['product_id'] = $productId;
4478 $response = (new NPayCb())->NPayCback($getParams);
4479 }
4480 }else{
4481 $response=FALSE;
4482 }
4483 print_r($response);
4484 try
4485 {
4486 $getParams['_response']=$response;
4487 $getParams['Exetype'] = "AfterExecution";
4488 $callbackLog->insert($getParams);
4489 }
4490 catch (Exception $e)
4491 {
4492 throw $e->getMessage();
4493 }
4494 }
4495 /**
4496 * nth callback MO - mobpair
4497 */
4498 public function actionNTHMO(){
4499
4500 $getParams = W::getRequestParams();
4501 $getParams = array_change_key_case($getParams, CASE_LOWER);
4502 $getParams['motime'] = $getParams['time'];
4503 $getParams['time'] = new MongoDate();
4504 $getParams['_partner'] = 'nth_mp';
4505 $getParams['_type'] = "callback_mo";
4506
4507 // for log
4508// $this->storeLog('nth_mo_mp','mo');
4509
4510 $callbackLog = SubNTH::getCollection();
4511 // check which servcie is arrive Gamesta or bebeauty
4512 $keyword = strtolower($getParams['keyword']);
4513
4514 if(strpos($keyword, 'stop') !== false){
4515 // unsub
4516 $getParams['action'] = 'UNSUB';
4517 $eventid = 'nth_456';
4518 if(strpos($keyword, 'play') !== false){
4519 // unsub gsta
4520 $eventid = 'RS040034';
4521 }
4522 }
4523 else{
4524 // sub
4525 $getParams['action'] = 'SUBPARK';
4526 $eventid = 'nth_456';
4527 if(strpos($keyword, 'play') !== false){
4528 // sub gsta
4529 $eventid = 'RS040034';
4530 }
4531 }
4532
4533 if(isset($getParams['msisdn']) && !empty($getParams['msisdn']))
4534 {
4535 $productId=$this->productId($eventid);
4536
4537 if($productId==FALSE){
4538 $response="product not found";
4539 }
4540 else{
4541 $getParams['product_id'] = $productId;
4542 $getParams['eventid'] = $eventid;
4543
4544 $code=(new NTHCb())->NTHCback($getParams);
4545 $response=(new NTHCb())->responseCode()[$code];
4546 }
4547 }else{
4548 $response = "Parameter not found.!";
4549 }
4550 print_r($response);
4551 try {
4552 $getParams['_response'] = $response;
4553 $getParams['Exetype'] = 'After execution';
4554 $callbackLog->insert($getParams);
4555 } catch (Exception $e) {
4556 throw $e->getMessage();
4557 }
4558 }
4559 /**
4560 * nth callback DN - mobpair
4561 */
4562 public function actionNTHDN(){
4563
4564 $getParams = W::getRequestParams();
4565 $getParams = array_change_key_case($getParams, CASE_LOWER);
4566 $getParams['time'] = new MongoDate();
4567 $getParams['_partner'] = 'nth_mp';
4568 $getParams['_type'] = "callback_dn";
4569 $callbackLog = SubNTH::getCollection();
4570
4571 // temp data store for testing start
4572// $this->storeLog('nth_dn_mp','dn');
4573 // temp data store for testing stop
4574
4575 if(isset($getParams['msisdn']) && !empty($getParams['msisdn']) && isset($getParams['messageid']) && !empty($getParams['messageid']))
4576 {
4577 $Event_coll = Yii::app()->mongodb->nth_eventIdMap;
4578 $ResData = [];
4579 $ResData = $Event_coll->find(['messageid' => $getParams['messageid']])->getNext();
4580
4581 if(!empty($ResData) and $ResData['contentmsg'] != 'FREE'){
4582
4583 $productId = $ResData['productid'];
4584 $eventid = $ResData['eventid'];
4585 if($productId == ''){
4586 $productId=$this->productId($eventid);
4587 }
4588
4589 if($productId == FALSE){
4590 $response="product not found";
4591 }
4592 else{
4593 $getParams['product_id'] = $productId;
4594 $getParams['eventid'] = $eventid;
4595
4596 $code=(new NTHCb())->NTHCback($getParams);
4597 $response=(new NTHCb())->responseCode()[$code];
4598 }
4599 }else{
4600 $response="product and id not found";
4601 }
4602 }else{
4603 $response = "Parameter not found.!";
4604 }
4605
4606 print_r($response);
4607 try {
4608 $getParams['_response'] = $response;
4609 $getParams['Exetype'] = 'After execution';
4610 $callbackLog->insert($getParams);
4611 } catch (Exception $e) {
4612 throw $e->getMessage();
4613 }
4614 }
4615 /**
4616 * nth callback DN - mobpair
4617 */
4618 public function actionNTHDCB(){
4619
4620 $getParams = W::getRequestParams();
4621 $getParams = array_change_key_case($getParams, CASE_LOWER);
4622 $getParams['cbtime'] = $getParams['time'];
4623 $getParams['time'] = new MongoDate();
4624 $getParams['_partner'] = 'nth_mp';
4625 $getParams['_type'] = "callback_dcb";
4626
4627 // temp data store for testing start
4628// $this->storeLog('nth_DCB_mp','dcb');
4629 // temp data store for testing stop
4630
4631 $callbackLog = SubNTH::getCollection();
4632 if(isset($getParams['statusnumber']) && !empty($getParams['statusnumber']) && isset($getParams['msisdn']) && !empty($getParams['msisdn'])){
4633
4634 $eventid = $getParams['servicecode'].'_HE';
4635 $productId=$this->productId($eventid);
4636
4637 if($productId == FALSE){
4638
4639 $eventid = 'nth_789';//$getParams['servicecode'];
4640 $productId=$this->productId($eventid);
4641
4642 if($productId == FALSE){
4643
4644 $response="product not found";
4645 }else{
4646 $getParams['product_id'] = $productId;
4647 $getParams['eventid'] = $eventid;
4648
4649 $code=(new NTHCb())->NTHCbackDCB($getParams);
4650 $response=(new NTHCb())->responseCode()[$code];
4651 }
4652 }
4653 else{
4654 $getParams['product_id'] = $productId;
4655 $getParams['eventid'] = $eventid;
4656
4657 $code=(new NTHCb())->NTHCbackDCB($getParams);
4658 $response=(new NTHCb())->responseCode()[$code];
4659 }
4660 }elseif(isset($getParams['command']) && $getParams['command']=='deliverSessionState'){
4661 // for unsub notification
4662 $statusnumberArr = ['4','5','-11','3','-2'];
4663 if(in_array($getParams['statusnumber'], $statusnumberArr)){
4664
4665 $eventid = $getParams['servicecode'].'_HE';
4666 $productId=$this->productId($eventid);
4667
4668 if($productId == FALSE){
4669
4670 $eventid = 'nth_789';//$getParams['servicecode'];
4671 $productId=$this->productId($eventid);
4672
4673 if($productId == FALSE){
4674
4675 $response="product not found";
4676 }else{
4677 $getParams['product_id'] = $productId;
4678 $getParams['eventid'] = $eventid;
4679
4680 $code=(new NTHCb())->NTHCbackDCB($getParams);
4681 $response=(new NTHCb())->responseCode()[$code];
4682 }
4683 }
4684 else{
4685 $getParams['product_id'] = $productId;
4686 $getParams['eventid'] = $eventid;
4687
4688 $code=(new NTHCb())->NTHCbackDCB($getParams);
4689 $response=(new NTHCb())->responseCode()[$code];
4690 }
4691 }
4692 }elseif(isset($getParams['statusnumber']) && !empty($getParams['statusnumber'])){
4693 $response = "Success";
4694 }else{
4695 $response = "Parameter not found.!";
4696 }
4697
4698 print_r($response);
4699 try {
4700 $getParams['_response'] = $response;
4701 $getParams['Exetype'] = 'After execution';
4702 $callbackLog->insert($getParams);
4703 } catch (Exception $e) {
4704 throw $e->getMessage();
4705 }
4706 }
4707 /**
4708 * Italy NTH
4709 */
4710 public function actionItnthdcb(){
4711
4712 $this->storeLog('nth_italy','cb_mp');
4713 print_r('success');
4714
4715 }
4716 /**
4717 * Oxy8 SA_MP_CB
4718 */
4719 public function actionOxy8SACB(){
4720
4721 // For testing purpose only START
4722 $getParams = W::getRequestParams();
4723 $getParams = array_change_key_case($getParams, CASE_LOWER);
4724 $getParams['time'] = new MongoDate();
4725 $getParams['_partner'] = 'oxy8sa_mp';
4726 $getParams['_type'] = "callback";
4727 $callbackLog = Yii::app()->mongodb->callback_log;
4728 $callbackLog->insert($getParams);
4729 // For testing purpose only END
4730
4731 $this->actionOxy8cb('oxy8sa_mp');
4732 }
4733 /**
4734 * Oxy8 SA_MP_MO
4735 */
4736 public function actionOxy8SAMO(){
4737
4738 // For testing purpose only START
4739 $getParams = W::getRequestParams();
4740 $getParams = array_change_key_case($getParams, CASE_LOWER);
4741 $getParams['time'] = new MongoDate();
4742 $getParams['_partner'] = 'oxy8sa_mp';
4743 $getParams['_type'] = "callback_mo";
4744 $callbackLog = Yii::app()->mongodb->callback_log;
4745 $callbackLog->insert($getParams);
4746 // For testing purpose only END
4747
4748 $this->actionOxy8dr('oxy8sa_mp');
4749 }
4750 /**
4751 * Oxy8 SA_MP_DLR
4752 */
4753 public function actionOxy8SADLR(){
4754
4755 // For testing purpose only START
4756 $getParams = W::getRequestParams();
4757 $getParams = array_change_key_case($getParams, CASE_LOWER);
4758 $getParams['time'] = new MongoDate();
4759 $getParams['_partner'] = 'oxy8sa_mp';
4760 $getParams['_type'] = "callback_dlr";
4761 $callbackLog = Yii::app()->mongodb->callback_log;
4762 $callbackLog->insert($getParams);
4763 // For testing purpose only END
4764
4765 $this->actionOxy8dr('oxy8sa_mp');
4766 }
4767 /**
4768 * Callback Moldova MP
4769 */
4770 public function actionMdvaCB(){
4771
4772 $getParams = W::getRequestParams();
4773 $getParams = array_change_key_case($getParams, CASE_LOWER);
4774 $getParams['time'] = new MongoDate();
4775 $getParams['_partner'] = 'Moldova_mp';
4776 $getParams['_type'] = "callback";
4777 $callbackLog = Yii::app()->mongodb->callback_log;
4778 $this->storeLog('Moldova_mp','callback');
4779 print_r("Success");
4780 $callbackLog->insert($getParams);
4781 }
4782 /**
4783 * DLR Moldova MP
4784 */
4785 public function actionMdvaDLR(){
4786
4787 $getParams = W::getRequestParams();
4788 $getParams = array_change_key_case($getParams, CASE_LOWER);
4789 $getParams['time'] = new MongoDate();
4790 $getParams['_partner'] = 'Moldova_mp';
4791 $getParams['_type'] = "callback_dlr";
4792 $callbackLog = Yii::app()->mongodb->callback_log;
4793 $this->storeLog('Moldova_mp','callback_dlr');
4794 print_r("Success");
4795 $callbackLog->insert($getParams);
4796 }
4797 public function actionBambooKZCB() {
4798 print_r('success');exit;
4799 $getparams = W::getRequestParams();
4800 $getparams = array_change_key_case($getparams,CASE_LOWER);
4801 $getparams['time'] = new MongoDate();
4802 $getparams['_partner'] = 'bamboo_KZ';
4803 $getparams['_type'] = 'bamboo_cb';
4804
4805 // for log
4806 $this->storeLog('bamboo_KZ','bamboo_cb');
4807
4808 $callbackLog = (new SubBamBoo())->getCollection();
4809 if(isset($getparams['rubric_id']) && $getparams['rubric_id']!=""){
4810 $event_id =$getparams['rubric_id'];
4811 }else{
4812 $event_id = (new BamBooCb())->getEventBySubscriberId($getparams['subscriber_id']);
4813// $getparams['action'] = 'Unsub';
4814 }
4815 if(isset($event_id) && $event_id!=""){
4816 (new BamBooCb())->saveEventId($getparams);
4817
4818 $product_id = $this->productId($event_id);
4819 if(!empty($product_id)){
4820 $getparams['product_id'] = $product_id;
4821 $getparams['event_id'] = $event_id;
4822 $code = (new BamBooCb())->BamBooCback($getparams);
4823 $response = (new BamBooCb())->responseCode()[$code];
4824 }else{
4825 $response="No Service Found.";
4826 }
4827 }else{
4828 $response = (new BamBooCb())->responseCode()[$code];
4829 }
4830 print_r($response);
4831 try{
4832 $getparams['_response'] =$response;
4833 $callbackLog->insert($getparams);
4834 } catch (Exception $e){
4835 throw $e->getMessage();
4836 }
4837
4838 }
4839 public function actionBambooKZBill() {
4840 print_r('success');exit;
4841 $getparams = W::getRequestParams();
4842 $getparams = array_change_key_case($getparams,CASE_LOWER);
4843 $getparams['time'] = new MongoDate();
4844 $getparams['_partner'] = 'bamboo_KZ';
4845 $getparams['_type'] = 'bamboo_bill';
4846
4847 // for log
4848 $this->storeLog('baboo_KZ','bamboo_bill');
4849
4850 $callbackLog = (new SubBamBoo())->getCollection();
4851 $getparams['rubric_id'] = (new BamBooCb())->getEventBySubscriberId($getparams['subscriber_id']);
4852 if($getparams['rubric_id']!=""){
4853 $product_id = $this->productId($getparams['rubric_id']);
4854 if(!empty($product_id)){
4855 $getparams['product_id'] = $product_id;
4856 $getparams['event_id'] = $getparams['rubric_id'];
4857 $getparams['payment']='failed';
4858 if($getparams['tarifficated']=='1'){
4859 $getparams['payment']='success';
4860 }
4861 $code = (new BamBooCb())->BamBooBill($getparams);
4862 $response = (new BamBooCb())->responseCode()[$code];
4863 }else{
4864 $response="No Service Found.";
4865 }
4866 }else{
4867 $response = 'Parameter Missing';
4868 }
4869 print_r($response);
4870 try{
4871 $getparams['_response'] =$response;
4872 $callbackLog->insert($getparams);
4873 } catch (Exception $e){
4874 throw $e->getMessage();
4875 }
4876
4877 }
4878 public function actionBambooCB() {
4879 $getparams = W::getRequestParams();
4880 $getparams = array_change_key_case($getparams,CASE_LOWER);
4881 $getparams['time'] = new MongoDate();
4882 $getparams['_partner'] = 'bamboo_moldova';
4883 $getparams['_type'] = 'callback_bamboo';
4884
4885 // for log
4886 $this->storeLog('moldova_bamboo_cb','cb');
4887
4888 $callbackLog = (new SubBamBoo())->getCollection();
4889 if(isset($getparams['rubric_id']) && $getparams['rubric_id']!=""){
4890 $event_id =$getparams['rubric_id'];
4891 }else{
4892 $event_id = (new BamBooCb())->getEventBySubscriberId($getparams['subscriber_id']);
4893 $getparams['action'] = 'Unsub';
4894 }
4895 if(isset($event_id) && $event_id!=""){
4896 (new BamBooCb())->saveEventId($getparams);
4897
4898 $product_id = $this->productId($event_id);
4899 if(!empty($product_id)){
4900 $getparams['product_id'] = $product_id;
4901 $getparams['event_id'] = $event_id;
4902 $code = (new BamBooCb())->BamBooCback($getparams);
4903 $response = (new BamBooCb())->responseCode()[$code];
4904 }else{
4905 $response="No Service Found.";
4906 }
4907 }else{
4908 $response = (new BamBooCb())->responseCode()[$code];
4909 }
4910 print_r($response);
4911 try{
4912 $getparams['_response'] =$response;
4913 $callbackLog->insert($getparams);
4914 } catch (Exception $e){
4915 throw $e->getMessage();
4916 }
4917
4918 }
4919 public function actionBambooBilling() {
4920 $getparams = W::getRequestParams();
4921 $getparams = array_change_key_case($getparams,CASE_LOWER);
4922 $getparams['time'] = new MongoDate();
4923 $getparams['_partner'] = 'bamboo_indo';
4924 $getparams['_type'] = 'billing_bamboo';
4925
4926 // for log
4927 $this->storeLog('maldova_baboo_mp','bill');
4928
4929 $callbackLog = (new SubBamBoo())->getCollection();
4930 $getparams['rubric_id'] = (new BamBooCb())->getEventBySubscriberId($getparams['subscriber_id']);
4931 if($getparams['rubric_id']!=""){
4932 $product_id = $this->productId($getparams['rubric_id']);
4933 if(!empty($product_id)){
4934 $getparams['product_id'] = $product_id;
4935 $getparams['event_id'] = $getparams['rubric_id'];
4936 $getparams['payment']='failed';
4937 if($getparams['tarifficated']=='1'){
4938 $getparams['payment']='success';
4939 }
4940 $code = (new BamBooCb())->BamBooBill($getparams);
4941 $response = (new BamBooCb())->responseCode()[$code];
4942 }else{
4943 $response="No Service Found.";
4944 }
4945 }else{
4946 $response = 'Parameter Missing';
4947 }
4948 print_r($response);
4949 try{
4950 $getparams['_response'] =$response;
4951 $callbackLog->insert($getparams);
4952 } catch (Exception $e){
4953 throw $e->getMessage();
4954 }
4955
4956 }
4957
4958 public function actionMiraZaCB() {
4959
4960 $getparams = W::getRequestParams();
4961 $getparams = array_change_key_case($getparams,CASE_LOWER);
4962 $getparams['time'] = new MongoDate();
4963 $getparams['_partner'] = 'MiraZa';
4964 $getparams['_type'] = 'callback_MiraZa';
4965
4966 // temp data store for testing start
4967 $this->storeLog('miraza_cb','cb_mp');
4968 // temp data store for testing stop
4969
4970 $callbackLog = (new SubMiraZa())->getCollection();
4971 if(isset($getparams['from']) && $getparams['from']!=""){
4972
4973 $product_id = $this->productId($getparams['from']);
4974 if(!empty($product_id)){
4975 $getparams['product_id'] = $product_id;
4976 $getparams['event_id'] = $getparams['from'];
4977 $getparams['action'] = "Unsub";
4978 if (strpos($getparams['msg'], 'Sub') !== false) {
4979 $getparams['action'] = "Park";
4980 }
4981 $code = (new MiraSaCb())->MiraZaCback($getparams);
4982 $response = (new MiraSaCb())->responseCode()[$code];
4983 }else{
4984 $response="No Service Found.";
4985 }
4986 }else{
4987 $response = 'Parameter Missing.';
4988 }
4989 print_r($response);
4990 try{
4991 $getparams['_response'] =$response;
4992 $getParams['ExeType'] = 'AfterExecution';
4993 $callbackLog->insert($getparams);
4994 } catch (Exception $e){
4995 throw $e->getMessage();
4996 }
4997
4998 }
4999 public function actionMiraZaBilling() {
5000 $getparams = W::getRequestParams();
5001 $getparams = array_change_key_case($getparams,CASE_LOWER);
5002 $getparams['time'] = new MongoDate();
5003 $getparams['_partner'] = 'MiraZa';
5004 $getparams['_type'] = 'billing_MiraZa';
5005
5006 // temp data store for testing start
5007 $this->storeLog('mira_zabil','bill_mp');
5008 // temp data store for testing stop
5009
5010 $callbackLog = (new SubMiraZa())->getCollection();
5011
5012 $getparams['msisdn']= (isset($getparams['msisdn'])?$getparams['msisdn']:$getparams['to']);
5013
5014 if(isset($getparams['from']) && $getparams['from']!=""){
5015 $product_id = $this->productId($getparams['from']);
5016 if(!empty($product_id)){
5017 $getparams['product_id'] = $product_id;
5018 $getparams['event_id'] = $getparams['from'];
5019 $code = (new MiraSaCb())->MiraZaBilling($getparams);
5020 $response = (new MiraSaCb())->responseCode()[$code];
5021 }else{
5022 $response="No Service Found.";
5023 }
5024 }else{
5025 $code = (new MiraSaCb())->MiraZaBilling($getparams);
5026 $response = (new MiraSaCb())->responseCode()[$code];
5027 }
5028 print_r($response);
5029 try{
5030 $getparams['_response'] =$response;
5031 $getParams['ExeType'] = 'AfterExecution';
5032 $callbackLog->insert($getparams);
5033 } catch (Exception $e){
5034 throw $e->getMessage();
5035 }
5036
5037 }
5038
5039 /**
5040 * ZA Integration - Vodacom direct callback
5041 */
5042 public function actionVodacomCb() {
5043
5044 $json_string= trim(file_get_contents('php://input'));
5045 $getParams = (new Common())->xmlToArray($json_string);
5046
5047 $evdata = [];
5048 if(isset($getParams['@attributes']['external-trans-id']))
5049 {
5050 $getParams['transactionId'] = $getParams['@attributes']['external-trans-id'];
5051 $evdata = explode("_", $getParams['transactionId']);
5052 $getParams['msisdn'] = $evdata[1];
5053 }
5054
5055 //set product and eventId
5056 if(isset($getParams['payload']['usage-authorisation']['package']))
5057 {
5058 $getParams['eventid'] = $getParams['payload']['usage-authorisation']['package']['simple-package-id']."_".$evdata[2];
5059 //p-techvault-androgames-c-01_STAG
5060 $getParams['product_id'] = $this->productId($getParams['eventid']);
5061 }
5062
5063 if(!$getParams['product_id'] and $evdata)
5064 {
5065 $product_price_id = (int)$evdata[3];
5066 if($ppmodel = $this->getProductPriceByPk($product_price_id))
5067 {
5068 $getParams['eventid'] = $ppmodel->eventid;
5069 $getParams['product_id'] = $ppmodel->product_id;
5070 }
5071 }
5072 $_response = (new ZaVodafoneCb())->resPurchase($getParams);
5073
5074 $getParams['_xmlData'] = $json_string;
5075 $getParams['_response'] = $_response;
5076 $getParams['time'] = new MongoDate();
5077 $getParams['_partner'] = 'vodacom_direct';
5078 $getParams['_type'] = 'callback';
5079 $callbackLog = SubZaVodafone2::getCollection();
5080 //$getParams['_response'] = $response;
5081 $response = "OK";
5082 print_r($response);
5083 try {
5084 $getParams['_response'] = $response;
5085 $callbackLog->insert($getParams);
5086 } catch (Exception $e) {
5087 throw $e->getMessage();
5088 }
5089 }
5090
5091 /**
5092 * ZA Integration - Vodacom direct auto refresh check
5093 */
5094 public function actionChecksub()
5095 {
5096 $msisdn = $_REQUEST['msisdn'];
5097 $product_id = $_REQUEST['product_id'];
5098 $sub = (new SubscriptionEx())->getSubscription($msisdn, $product_id);
5099// print_r($sub);
5100 if($sub){
5101 echo "YES";exit;
5102 }
5103 echo "NO";
5104 }
5105
5106 /**
5107 * Dimoco Netherlands callback
5108 */
5109 public function actionDimocoNLDCb()
5110 {
5111 $this->actionDimocoCb('dimoco_nld');
5112 }
5113
5114 /** #####
5115 * Dimoco Integration - SWZ callback
5116 */
5117 public function actionDimocoCb($partner='dimoco')
5118 {
5119 $post_string = trim(file_get_contents('php://input'));
5120 parse_str($post_string,$postData);
5121 $getParams = (new Common())->xmlToArray($postData['data']);
5122 //set cache for billing purpose
5123 if(isset($getParams['reference']) and in_array($getParams['action'], ['identify','start-subscription']))
5124 {
5125 Yii::app()->cache->set($getParams['reference'], json_encode($getParams), 60*30); //30 minutes
5126 }
5127 //set productId and eventId
5128 if(isset($getParams['payment_parameters']['order']))
5129 {
5130 $getParams['eventid'] = $getParams['payment_parameters']['order'];
5131 $getParams['product_id'] = $this->productId($getParams['eventid']);
5132
5133 $_response = (new DimocoSWZ())->DimocoSWZCback($getParams);
5134
5135 }else{
5136 $_response = (new DimocoSWZ())->responseCode()[404];
5137 }
5138 $getParams['_xmlData'] = $post_string;
5139 $getParams['time'] = new MongoDate();
5140 $getParams['_partner'] = $partner;
5141 $getParams['_type'] = 'callback';
5142 echo $response = "OK";
5143 $callbackLog = SubDimocoSWZ::getCollection();
5144 try {
5145 $getParams['_response'] = $_response;
5146 $callbackLog->insert($getParams);
5147 } catch (Exception $e) {
5148 throw $e->getMessage();
5149 }
5150 }
5151
5152 /**
5153 * Mira ZA Subscribe Events
5154 */
5155 public function actionMiraEveCB(){
5156
5157 $getParams = W::getRequestParams();
5158 $getParams = array_change_key_case($getParams, CASE_LOWER);
5159 $getParams['time'] = new MongoDate();
5160 $getParams['_partner'] = 'Mira_mp';
5161 $getParams['_type'] = "callback";
5162 $callbackLog = Yii::app()->mongodb->callback_log;
5163 print_r("Success");
5164 $callbackLog->insert($getParams);
5165 }
5166 /**
5167 * Bahrain - ACTEL - MO
5168 * @param type $type
5169 */
5170 public function actionBahMOMP(){
5171
5172 $this->IraqCbMP('Bahrain');
5173 }
5174 /**
5175 * Bahrain - ACTEL - DLR
5176 * @param type $type
5177 */
5178 public function actionBahDLRMP(){
5179
5180 $this->IraqDLRMP('Bahrain');
5181 }
5182 /**
5183 * Jordan-ZAIN-ACTEL-MO
5184 * @param type $type
5185 */
5186 public function actionJZMOMP(){
5187
5188 $getParams = W::getRequestParams();
5189 if (empty($getParams)) {
5190// throw new CHttpException(404, 'No parameters found.');
5191 }
5192 // for check DLR params only for testing purpose
5193 $this->storeLog('jordan_zain_mp', 'callback_mo');
5194
5195 $getParams = array_change_key_case($getParams, CASE_LOWER);
5196 $getParams['time'] = new MongoDate();
5197 $getParams['_partner'] = 'jordan_zain_mp';
5198 $getParams['_type'] = 'callbackMP';
5199 $callbackLog = SubIraqActel::getCollection(); //Yii::app()->mongodb->callback_log;
5200 if(isset($getParams['destination']) && !empty($getParams['destination']))
5201 {
5202 $eventID = $getParams['id_application'].'_'.$getParams['destination'];
5203 $productId = $this->productId($eventID); // Set product_id
5204 //check product is available or not
5205 if($productId == false){
5206 $response = "service not found.!";
5207 }else{
5208 $getParams['destination'] = $eventID;
5209 $getParams['product_id'] = $productId;
5210 $code=(new IraqActelCb())->IraqActelCback($getParams);
5211 $response =(new IraqActelCb())->responseCode()[$code];
5212 }
5213 }else{
5214 $response = "shortcode not found.!";
5215 }
5216 print_r($response);
5217 try{
5218 $getParams['_response'] = $response;
5219 $callbackLog->insert($getParams);
5220 }catch(Exception $e){
5221 throw $e->getMessage();
5222 }
5223 }
5224 /**
5225 * Jordan-ZAIN-ACTEL-DLR
5226 * @param type $type
5227 */
5228 public function actionJZDLRMP(){
5229
5230 $getParams = W::getRequestParams();
5231 if (empty($getParams)) {
5232// throw new CHttpException(404, 'No parameters found.');
5233 }
5234 $getParams = array_change_key_case($getParams, CASE_LOWER);
5235 $getParams['time'] = new MongoDate();
5236 $getParams['_partner'] = 'jordan_zain_mp';
5237 $getParams['_type'] = 'callback_dn';
5238
5239 // for check DLR params only testing purpose
5240 $this->storeLog('jordan_zain_mp', 'callback_dn');
5241
5242 $callbackLog = SubIraqActel::getCollection();
5243 if(isset($getParams['shortcode']) && !empty($getParams['shortcode']) or isset($getParams['billedshortcode']) && !empty($getParams['billedshortcode']))
5244 {
5245 $shortcode = isset($getParams['shortcode'])?$getParams['shortcode']:$getParams['billedshortcode'];
5246
5247 // To Check which flow user have select mo or pin flow 1 equals mo and 2 equals pin flow
5248 $eventID = $getParams['id_application'].'_'.$shortcode;
5249// if($getParams['flow'] == 1){
5250// $eventID = $getParams['id_application'].'_'.$shortcode;
5251// }
5252
5253 $productId = $this->productId($eventID); // Set product_id
5254
5255 //check product is available or not
5256 if($productId == false){
5257 $response = "service not found.!";
5258 }else{
5259
5260 $getParams['product_id'] = $productId;
5261 $getParams['shortcode'] = $eventID;
5262 $getParams['smslangtype']= 'eng';
5263
5264 $code=(new IraqActelMPCb())->IraqActelCback($getParams);
5265 $response =(new IraqActelCb())->responseCode()[$code];
5266
5267 // For Unsub
5268 if($getParams['action'] == 'UNSUB'){
5269
5270 $shortcode = $eventID;
5271 $productId = $this->productId($shortcode);
5272
5273 $getParams['product_id'] = $productId;
5274 $getParams['shortcode'] = $shortcode;
5275
5276 $code=(new IraqActelMPCb())->IraqActelCback($getParams);
5277 $response =(new IraqActelCb())->responseCode()[$code];
5278 }
5279 }
5280 }else{
5281 $response = "shortcode not found.!";
5282 }
5283 print_r($response);
5284 $getParams['_response'] = $response;
5285 try {
5286 $getParams['_response'] = $response;
5287 $getParams['EXE'] = 'afterExecution';
5288 $callbackLog->insert($getParams);
5289 } catch (Exception $e) {
5290 throw $e->getMessage();
5291 }
5292 }
5293 /**
5294 * Mira MP notification
5295 */
5296 public function miraNotification($type='DLR_MP'){
5297
5298 $getParams = W::getRequestParams();
5299 $getParams = array_change_key_case($getParams, CASE_LOWER);
5300 $getParams['time'] = new MongoDate();
5301 $getParams['_partner'] = 'mira_mp';
5302 $getParams['_type'] = "$type";
5303 $callbackLog = Yii::app()->mongodb->callback_log;
5304 print_r("Success");
5305 $callbackLog->insert($getParams);
5306 }
5307 public function actionMiraDLR(){
5308 $this->miraNotification('dlr_mp');
5309 }
5310 /**
5311 * // DLR of msg after sent MTs
5312 * @throws type
5313 */
5314 public function actionMiraBLFDK(){
5315
5316 $getParams = W::getRequestParams();
5317 $getParams = array_change_key_case($getParams, CASE_LOWER);
5318 $getParams['time'] = new MongoDate();
5319 $getParams['_partner'] = 'mira_mp';
5320 $getParams['_type'] = "billing_mp";
5321
5322 // temp data store for testing start
5323 $this->storeLog('mira_mp','bfdk_mp');
5324 // temp data store for testing stop
5325
5326 $callbackLog = SubMiraZa::getCollection();
5327 if(isset($getParams['to']) && !empty($getParams['to']) && isset($getParams['clientref']) && !empty($getParams['clientref'])){
5328
5329 $subVeocb=new SubMiraZa();
5330 $detail=$subVeocb->getRefCollection()->findOne(['clientref'=>$getParams['clientref']]);
5331 $getParams['msgtype'] = 'MT';
5332
5333 if(isset($detail['mt_type']) and $detail['mt_type'] == 'FreeMT'){
5334 $response = 'Success';
5335 $getParams['msgtype'] = 'FreeMT';
5336 }
5337
5338 if(isset($detail['mt_type']) and $detail['mt_type'] != 'FreeMT'){
5339
5340 // Product id and event id set
5341 if(isset($detail['event_id'])){
5342
5343 $eventid = $detail['event_id'];
5344 $productId = $detail['product_id'];
5345 //$productId=$this->productId($eventid);
5346
5347 if($productId == FALSE){
5348 $response="product not found";
5349 }
5350 else{
5351 $getParams['product_id'] = $productId;
5352 $getParams['event_id'] = $eventid;
5353 $getParams['msisdn'] = $getParams['to'];
5354 // Sent callback class
5355 $code=(new MiraSaCb())->MiraZaDLR($getParams);
5356 $response=(new MiraSaCb())->responseCode()[$code];
5357 }
5358 }
5359 }
5360
5361 }else{
5362 $response = "Parameter not found.!";
5363 }
5364
5365 print_r($response);
5366 try {
5367 $getParams['_response'] = $response;
5368 $getParams['ExeType'] = 'After execution';
5369 $callbackLog->insert($getParams);
5370 } catch (Exception $e) {
5371 throw $e->getMessage();
5372 }
5373 }
5374
5375 public function actionMiraSUBFDK(){
5376 $this->miraNotification('subfeedback_mp');
5377 }
5378 public function actionMiraMO(){
5379
5380 // send welcome msg and content msg and user send to park
5381// $this->miraNotification('mo_mp');
5382
5383 $getParams = W::getRequestParams();
5384 $getParams = array_change_key_case($getParams, CASE_LOWER);
5385 $getParams['time'] = new MongoDate();
5386 $getParams['_partner'] = 'mira_mp';
5387 $getParams['_type'] = "mo_mp";
5388
5389 // temp data store for testing start
5390 $this->storeLog('mira_mo','mo_mp');
5391 // temp data store for testing stop
5392
5393 $callbackLog = SubMiraZa::getCollection();
5394 if(isset($getParams['msisdn']) && !empty($getParams['msisdn']) && isset($getParams['from']) && !empty($getParams['from'])){
5395
5396 $eventid = $getParams['from'];
5397 $productId=$this->productId($eventid);
5398
5399 if($productId == FALSE){
5400 $response="product not found";
5401 }
5402 else{
5403 $getParams['product_id'] = $productId;
5404 $getParams['event_id'] = $eventid;
5405
5406 $msg = trim(strtolower($getParams['msg']));
5407 $explodeMsg = explode(' ',$msg);
5408
5409 // msg set
5410 $Actionmsg = $explodeMsg[0];
5411
5412 // ID set
5413 if(isset($explodeMsg[1])){
5414 $getParams['id'] = $explodeMsg[1];
5415 }
5416
5417 if($Actionmsg == 'wapjoin'){
5418 $getParams['action'] = 'SUBPARK';
5419 }else{
5420// (strpos($Actionmsg, 'stop') !== false){
5421// $getParams['action'] = 'UNSUB';
5422 $haystack=['stop','cancel','quit','unsubscribe','end'];
5423
5424 if(in_array($Actionmsg, $haystack)){
5425 $getParams['action'] = 'UNSUB';
5426 }
5427 }
5428
5429 $code=(new MiraSaCb())->MiraZaCback($getParams);
5430 $response=(new MiraSaCb())->responseCode()[$code];
5431 }
5432 }else{
5433 $response = "Parameter not found.!";
5434 }
5435
5436 print_r($response);
5437 try {
5438 $getParams['_response'] = $response;
5439 $getParams['Exetype'] = 'After execution';
5440 $callbackLog->insert($getParams);
5441 } catch (Exception $e) {
5442 throw $e->getMessage();
5443 }
5444
5445 }
5446 /**
5447 * For testing configuartion cb set
5448 */
5449 public function storeLog($partner='mp',$type='cb_mp') {
5450
5451 $req= trim(file_get_contents('php://input'));
5452 $getParams = json_decode($req, true); // for json request check
5453 if(empty($getParams)){
5454
5455 $getParams=(new Common())->xmlToArray($req); //if req is xml
5456 if(empty($getParams)) {
5457
5458 $getParams = W::getRequestParams(); // if get or post request
5459 if(empty($getParams)){
5460// throw new CHttpException(404, 'No request found.');
5461 }
5462 }
5463 }
5464 $getParams = array_change_key_case($getParams, CASE_LOWER);
5465 $getParams['time'] = new MongoDate();
5466 $getParams['_partner'] = "$partner";
5467 $getParams['_type'] = "$type";
5468 $getParams['request_Ip'] = $_SERVER['REMOTE_ADDR'];
5469 $callbackLog = Yii::app()->mongodb->cb_logs;
5470// print_r("Success");
5471 $callbackLog->insert($getParams);
5472 }
5473 /**
5474 * Malaysia Callback
5475 */
5476 public function actionMKMalysaMPCb($partner = "mk_malysa_mp",$type = "maly_cb"){
5477
5478 $getParams = W::getRequestParams();
5479 $getParams = array_change_key_case($getParams, CASE_LOWER);
5480
5481 if(empty($getParams)){
5482 print_r('Success');
5483 exit();
5484 throw new CHttpException(404, 'No parameters found.');
5485 }
5486 $getParams['time'] = new MongoDate();
5487 $getParams['_partner'] = "$partner";
5488 $getParams['_type'] = "$type";
5489
5490 $callbackLog = SubMalaysiaMk::getCollection();
5491 if(isset($getParams['msisdn']) && !empty($getParams['msisdn']) && isset($getParams['servicename']) && !empty($getParams['servicename'])){
5492
5493 $eventid = $getParams['servicename'];
5494 $productId=$this->productId($eventid);
5495
5496 if($productId == FALSE){
5497 $response="product not found";
5498 }
5499 else{
5500 $getParams['product_id'] = $productId;
5501 $getParams['eventid'] = $eventid;
5502
5503 $code=(new CelcomMKCb())->CelcomMKCback($getParams);
5504 $response=(new CelcomMKCb())->responseCode()[$code];
5505 }
5506
5507 }else{
5508 $response = "Parameter not found.!";
5509 }
5510
5511 print_r($response);
5512 try {
5513 $getParams['_response'] = $response;
5514 $getParams['Exetype'] = 'After execution';
5515 $callbackLog->insert($getParams);
5516 } catch (Exception $e) {
5517 throw $e->getMessage();
5518 }
5519 }
5520
5521 public function actionMKMalysaMPDLR(){
5522
5523 $this->actionMKMalysaMPCb();
5524// $this->storeLog('mk_malysa_mp','dn_mp');
5525 }
5526 /**
5527 * Bahrain - ACTEL - MO - batelco
5528 * @param type $type
5529 */
5530 public function actionBahBatMOMP(){
5531
5532 $this->IraqCbMP('Bahrain_batelco');
5533 }
5534 /**
5535 * Bahrain - ACTEL - DLR - batelco
5536 * @param type $type
5537 */
5538 public function actionBahBatDLRMP(){
5539
5540 $this->IraqDLRMP('Bahrain_batelco');
5541 }
5542 /**
5543 * Command Callback for TPAY
5544 * @param type $partner
5545 */
5546 public function TpayCallback($partner='tpaycb'){
5547
5548 $getParams = W::getRequestParams();
5549 if(empty($getParams)){
5550 throw new CHttpException(404, 'No parameters found.');
5551 }
5552
5553 $getParams = array_change_key_case($getParams, CASE_LOWER);
5554 $getParams['time'] = new MongoDate();
5555 $getParams['_partner'] = "$partner";
5556 $getParams['_type'] = 'callback';
5557
5558 // temp data store for testing start
5559 $this->storeLog("$partner",'cb');
5560 // temp data store for testing stop
5561
5562 $callbackLog = SubTPay::getCollection();
5563 if(isset($getParams['action']) && !empty($getParams['action']))
5564 {
5565 sleep(2);
5566 $datamap['subscriptioncontractid']=(string)$getParams['subscriptioncontractid'];
5567 $Data = (new SubTPay())->mapEventid($datamap);
5568 //check product is available or not
5569 if(isset($Data)){
5570 $getParams['product_id'] = $Data['product_id']; // Set product_id
5571
5572 if(!isset($getParams['msisdn'])){
5573 $getParams['msisdn'] = $Data['msisdn'];
5574 }
5575 if(!isset($getParams['eventid'])){
5576 $getParams['eventid'] = $Data['eventid'];
5577 }
5578 if(!isset($getParams['operatorcode'])){
5579 $getParams['operatorcode'] = $Data['operatorcode'];
5580 }
5581
5582 $code=(new TPayCb())->TPayCback($getParams);
5583 $response =(new TPayCb())->responseCode()[$code];
5584 }else{
5585 $response = "service not found.!";
5586 }
5587 }else{
5588 $response = "Parameter not found.!";
5589 }
5590 print_r($response);
5591 try {
5592 $getParams['_response'] = $response;
5593 $getParams['ExeType'] = 'AfterExecution';
5594 $callbackLog->insert($getParams);
5595 } catch (Exception $e) {
5596 throw $e->getMessage();
5597 }
5598 }
5599 /**
5600 * Egypt Callback
5601 */
5602 public function actionTpayEgyptCb(){
5603 $this->TpayCallback('tpayegyptcb_mp');
5604 }
5605 /**
5606 * MO Tan
5607 */
5608 public function actionOxy8TZMO(){
5609// $this->storeLog('oxy8_mp_taz','mo_mp');
5610 $this->actionOxy8MO('callbackMo','oxy8TZ');
5611 }
5612 /**
5613 * DLR
5614 */
5615 public function actionOxy8TZDLR(){
5616// $this->storeLog('oxy8_mp_taz','dlr_mp');
5617 $this->actionOxy8DN('callbackDN','oxy8TZ');
5618 }
5619
5620 /** #
5621 * MO Kenya techvault
5622 */
5623 public function actionOxy8KenyaMO()
5624 {
5625 $this->storeLog('callbackMo','oxy8KY');
5626 //die("OK");
5627 $this->actionOxy8MO('callbackMo', 'oxy8KY');
5628 }
5629
5630 /** #
5631 * DLR Kenya techvault
5632 */
5633 public function actionOxy8KenyaMT()
5634 {
5635 $this->storeLog('callbackMT','oxy8KY');
5636 //die("OK");
5637 $this->actionOxy8DN('callbackMT', 'oxy8KY');
5638 }
5639
5640 /**
5641 * Malaysia Direct carrier Billing api Mo
5642 *
5643 */
5644 public function actionMalaymo() {
5645
5646 $getparams = W::getRequestParams();
5647 $getparams = array_change_key_case($getparams,CASE_LOWER);
5648 $getparams['time'] = new MongoDate();
5649 $getparams['_partner'] = 'MalaysiaMo';
5650 $getparams['_type'] = 'callback_Malaysia_mo';
5651
5652 // temp data store for testing start
5653 $this->storeLog('mk_malay_mp','mo_mp');
5654 // temp data store for testing stop
5655
5656 $callbackLog = (new SubMalaysia())->getCollection();
5657
5658 if(strpos(strtoupper($getparams['text']), 'GAMES') !== false){
5659 $eventId= $getparams['shortcode']."-GMS-15"; // if telcoid 1,5,7
5660 if($getparams['telcoid']=='3'){
5661 $eventId= $getparams['shortcode']."-GMS-3"; // telcoid 3
5662 }
5663 }
5664 if(strpos(strtoupper($getparams['text']), 'BEAUTY') !== false){
5665 $eventId= $getparams['shortcode']."-BEB-15"; // if telcoid 1,5,7
5666 if($getparams['telcoid']=='3'){
5667 $eventId= $getparams['shortcode']."-BEB-3"; // telcoid 3
5668 }
5669 }
5670 if(isset($eventId) && $eventId!=""){
5671 $product_id = $this->productId($eventId);
5672 if(!empty($product_id)){
5673 $getparams['product_id'] = $product_id;
5674 $getparams['event_id'] = $eventId;
5675 $getparams['action'] = "Park";
5676 if (strpos(strtoupper($getparams['text']), 'STOP') !== false) {
5677 $getparams['action'] = "Unsub";
5678 }
5679 $code = (new MalaysiaCb())->MalaysiaCback($getparams);
5680 $response = (new MalaysiaCb())->responseCode()[$code];
5681 }else{
5682 $response="No Service Found.";
5683 }
5684 }else{
5685 $response = 'Parameter Missing.';
5686 }
5687 print_r($response);
5688 try{
5689 $getparams['_response'] =$response;
5690 $callbackLog->insert($getparams);
5691 } catch (Exception $e){
5692 throw $e->getMessage();
5693 }
5694
5695 }
5696 public function actionMalaydlr() {
5697
5698 $getparams = W::getRequestParams();
5699 $getparams = array_change_key_case($getparams,CASE_LOWER);
5700 $getparams['time'] = new MongoDate();
5701 $getparams['_partner'] = 'MalaysiaDn';
5702 $getparams['_type'] = 'callback_Malaysia_dlr';
5703
5704 // temp data store for testing start
5705 $this->storeLog('mk_malay_mp','dlr_mp');
5706 // temp data store for testing stop
5707 $callbackLog = (new SubMalaysia())->getCollection();
5708
5709 $duplicate =$getparams['msisdn'].$getparams['mtid'].$getparams['status'].$getparams['telcoid'];
5710
5711 $KEY= "ML_MP".date(W::getDateFormat()).$duplicate;
5712 $tokenCache = Yii::app()->cache->get($KEY);
5713 if(!$tokenCache){
5714 $token = $getparams['msisdn'];
5715 $KEY = "ML_MP".date(W::getDateFormat()).$duplicate;
5716 Yii::app()->cache->set($KEY, $token, 3600*24*1); // 1 days
5717
5718 if(isset($getparams['category']) && $getparams['category']=="1" && $getparams['telcoid']=="1"){
5719 $eDetail= SubMalaysia::getEventForMaxis()[strtoupper($getparams['keyword'])];
5720 $getparams['event_id'] = $eDetail['event_id'];
5721 $getparams['product_id'] = $eDetail['product_id'];
5722 }elseif(isset($getparams['mtid']) && $getparams['mtid']!=""){
5723 $eDetail= SubMalaysia::getEventFromMoId($getparams['mtid']);
5724 $getparams['event_id'] = $eDetail['event_id'];
5725 $getparams['product_id'] = $eDetail['product_id'];
5726 }
5727 if(isset($getparams['product_id']) && $getparams['product_id']!=""){
5728
5729 if ($getparams['status']== '1') {
5730 $getparams['action'] = "Sub";
5731 }
5732 $code = (new MalaysiaCb())->MalaysiaCbackDN($getparams);
5733 $response = (new MalaysiaCb())->responseCode()[$code];
5734 }else{
5735 $response="No Service Found.";
5736 }
5737
5738 print_r($response);
5739 try{
5740 $getparams['_response'] =$response;
5741 $callbackLog->insert($getparams);
5742 } catch (Exception $e){
5743 throw $e->getMessage();
5744 }
5745 }
5746 }
5747 /**
5748 * Junotel Subscribe Events callback for India
5749 */
5750 public function actionJunoteldlr(){
5751 $this->JunotelCallback("India");
5752 }
5753 /**
5754 * Junotel Subscribe Events infocallback
5755 */
5756 public function actionJunotelinfocb(){
5757 $this->JunotelInfoCallback('India');
5758 }
5759 /**
5760 * Junotel Subscribe Events callback for India
5761 */
5762 public function actionjunoukdlr(){
5763 $this->JunotelCallback("UK");
5764 }
5765 /**
5766 * Junotel Subscribe Events infocallback
5767 */
5768 public function actionjunoukinfo(){
5769 $this->JunotelInfoCallback('UK');
5770 }
5771 /* Handle all Dlr for Junotel */
5772 public function JunotelCallback($country="India"){
5773
5774 $getParams = W::getRequestParams();
5775 $getParams = array_change_key_case($getParams, CASE_LOWER);
5776
5777 $getParams['time'] = new MongoDate();
5778 $getParams['_partner'] = 'Junotel_mp';
5779 $getParams['_type'] = "callback";
5780 $getParams['country'] = "$country";
5781 $getParams['IP'] = $_SERVER['REMOTE_ADDR'];
5782
5783// $duplicate =$getParams['cptxnid'].$getParams['m'].$getParams['status'].$getParams['action'];
5784//
5785// $KEY= "JT_MP".date(W::getDateFormat()).$duplicate;
5786// $tokenCache = Yii::app()->cache->get($KEY);
5787// if(!$tokenCache){
5788// $token = $getParams['m'];
5789// $KEY = "JT_MP".date(W::getDateFormat()).$duplicate;
5790// Yii::app()->cache->set($KEY, $token, 3600*24*6); // 6 days
5791
5792 $callbackLog = (new SubJunotel())->getCollection();
5793
5794 if(isset($getParams['pid']) && $getParams['pid']!=""){
5795 $product_id = $this->productId($getParams['pid']);
5796 if($product_id){
5797 if($getParams['m']=='null'){
5798 $farray = ['cptxnid'=>$getParams['cptxnid'],'product_id'=>$product_id];
5799 $eDetail= SubJunotel::getMSISDNByCptxnid($farray);
5800 if($eDetail && $eDetail['r_msisdn']!="")
5801 $getParams['m']=$eDetail['r_msisdn'];
5802 }
5803 $getParams['product_id'] = $product_id;
5804 $getParams['event_id'] = $getParams['pid'];
5805 $code = (new JunotelCb())->JunotelCback($getParams);
5806 $response = (new JunotelCb())->responseCode()[$code];
5807 }else{
5808 $response="Service Not Found.";
5809 }
5810 }else{
5811 $response="Parameter missing.";
5812 }
5813 print_r($response);
5814 try{
5815 $getParams['_response'] =$response;
5816 $callbackLog->insert($getParams);
5817 } catch (Exception $e){
5818 throw $e->getMessage();
5819 }
5820
5821// }
5822 }
5823
5824 /* Handle all Infocallback for Junotel */
5825 public function JunotelInfoCallback($country='India'){
5826
5827 $getParams = W::getRequestParams();
5828 $getParams = array_change_key_case($getParams, CASE_LOWER);
5829
5830 $getParams['time'] = new MongoDate();
5831 $getParams['_partner'] = 'Junotel_mp';
5832 $getParams['_type'] = "infocallback";
5833 $getParams['country'] = "$country";
5834 $getParams['IP'] = $_SERVER['REMOTE_ADDR'];
5835
5836 if(in_array($getParams['status'], ['J201','J207','J202'])){
5837 $act_status="OPTIN";
5838 }else{
5839 $act_status=$getParams['status'];
5840 }
5841 $duplicate =$getParams['cptxnid'].$getParams['m'].$getParams['action'].$act_status;
5842
5843
5844 $KEY= "JT_MP".date(W::getDateFormat()).$duplicate;
5845 $tokenCache = Yii::app()->cache->get($KEY);
5846 if(!$tokenCache){
5847 $token = $getParams['m'];
5848 $KEY = "JT_MP".date(W::getDateFormat()).$duplicate;
5849 Yii::app()->cache->set($KEY, $token, 3600*24); // 1 hour
5850
5851 $callbackLog = (new SubJunotel())->getCollection();
5852
5853 if(isset($getParams['pid']) && $getParams['pid']!=""){
5854 $product_id = $this->productId($getParams['pid']);
5855 if($product_id){
5856 $getParams['product_id'] = $product_id;
5857 $getParams['event_id'] = $getParams['pid'];
5858 $code = (new JunotelCb())->JunotelCback($getParams);
5859 $response = (new JunotelCb())->responseCode()[$code];
5860 }else{
5861 $response="Service Not Found.";
5862 }
5863 }else{
5864 $response="Parameter missing.";
5865 }
5866 print_r($response);
5867 try{
5868 $getParams['_response'] =$response;
5869 $callbackLog->insert($getParams);
5870 } catch (Exception $e){
5871 throw $e->getMessage();
5872 }
5873 }
5874 }
5875 /**
5876 * Thailand new integration for waplead SVMobi
5877 */
5878 public function actionThaiwplCb()
5879 {
5880 $getParams = W::getRequestParams();
5881 if (empty($getParams)) {
5882 $response = "Parameter not found.!";
5883 }
5884 $getParams = array_change_key_case($getParams, CASE_LOWER);
5885 $getParams['time'] = new MongoDate();
5886 $getParams['_partner'] = 'svmobithai';
5887 $getParams['_type'] = 'postback';
5888// $callback = Yii::app()->mongodb->callback_log;
5889 if(1){
5890 $cltest = Yii::app()->mongodb->req_log_test;
5891 $cltest->insert($getParams);
5892 }
5893 $callback = SubSVMobiThai::getCollection();
5894 if(isset($getParams['status']) && !empty($getParams['status']))
5895 {
5896 $d = explode('_', $getParams['clickid']);
5897 $getParams['eventid'] = $d[0]; //eventId
5898
5899 $productId = (string)$this->productId($getParams['eventid']); //set product_id
5900 //check product is available or not
5901 if ($productId == false) {
5902 $response = "service not found.!";
5903 } else {
5904 $getParams['product_id'] = $productId;
5905 $code=(new SVMobiThaiCb())->SVMobiCback($getParams);
5906 $response =(new SVMobiThaiCb())->responseCode()[$code];
5907 }
5908 }else{
5909 $response = "Parameter not found.!";
5910 }
5911 print_r($response);
5912 $getParams['_response'] = $response;
5913
5914
5915 try {
5916 $callback->insert($getParams);
5917 // echo "sms template";
5918 } catch (Exception $exc) {
5919
5920 }
5921
5922 }
5923/**
5924 * Mo Ooredoo-timwe -Oman -mp in tunnel
5925 */
5926 public function actionOmanTimweMO2(){
5927
5928 // for only testing purpose
5929 $this->storeLog('omantimwe_mp','mo_mp');
5930
5931 $getParams = W::getRequestParams();
5932 $file = Yii::app()->getBasePath().DIRECTORY_SEPARATOR."runtime/callback_omanTimwe2.txt";
5933 $content = "Response:Date:".date('Y-m-d H:i:s')."->".json_encode($getParams)."\n";
5934 file_put_contents($file, $content, FILE_APPEND | LOCK_EX);
5935
5936 // check params
5937 if(empty($getParams)){
5938 throw new CHttpException(404, 'No parameters found.');
5939 }
5940
5941 // get two params only
5942 $msisdn = $getParams['Origin'];
5943 $textMsg = $getParams['Text'];
5944 $shortcode = $getParams['shortcode'];
5945
5946 $msisdn = ltrim(str_replace(' ', '', $msisdn ), '+');
5947
5948 $subOmanOoredoo = new SubOmanTimwe2();
5949 $omanTimwecb2 = new OmanTimweCb2();
5950
5951 $textArr = $subOmanOoredoo->checkMoKey($textMsg);
5952
5953 $key = '';
5954 $keyword = '';
5955 $mt_response = '';
5956 $text = '';
5957
5958 $textCount = count($textArr);
5959 if($textCount >=2 ){
5960 $key = strtoupper($textArr[0]);
5961 $keyword = strtoupper($textArr[1]);
5962 $sep_unsub = $key.$keyword;
5963 }else{
5964 $key = isset($textArr[0])?strtoupper($textArr[0]):'';
5965 $keyword = isset($textArr[1])?strtoupper($textArr[1]):'';
5966 }
5967 $product = (new ProductEx)->find("conf_json like :shortcode and conf_json like :keyword", [':shortcode'=>"%shortcode%$shortcode%",':keyword'=>"%keyword%$keyword%"]);
5968 $productId = $product->id;
5969
5970 $peInfo = $subOmanOoredoo->getValidityByProductId($productId);
5971 $eventId = $peInfo['eventid'];
5972 $priceDetails = $peInfo;
5973 $sendCode = $tid = $subOmanOoredoo->getRefId();
5974 $sysproductId = $product->conf['productId'];
5975
5976
5977 $file = Yii::app()->getBasePath().DIRECTORY_SEPARATOR."runtime/callback_omanTimwe2.txt";
5978 $content = "keyword :".$key."->".$keyword."\n";
5979 file_put_contents($file, $content, FILE_APPEND | LOCK_EX);
5980 $setMT='';
5981 $OmanTimweCb2 = new OmanTimweCb2();
5982 $endSubStatus='';
5983 if(in_array($key, $product->conf['mosub']))
5984 {
5985 if( $keyword!=''){
5986 $sub = (new SubscriptionEx())->getSubscription($msisdn, $productId);
5987 if(!$sub){
5988 $status=$subOmanOoredoo->informTimweSub($product->id, $msisdn, $product->conf['charge_mt_pp'], 'SMS', $textMsg,$priceDetails);
5989 }else{
5990 $checkSubStatus = $subOmanOoredoo->checkSubscriptionStatus($productId, $msisdn);
5991 if($checkSubStatus == 'Success'){
5992 $setMT='ALREADY_SUB';
5993 }else{
5994 $status=$subOmanOoredoo->informTimweSub($product->id, $msisdn, $product->conf['charge_mt_pp'], 'SMS', $textMsg,$priceDetails);
5995 }
5996 }
5997 }else if( $keyword ==''){
5998 $sub = (new SubscriptionEx())->getSubscription($msisdn, $productId);
5999 if(!$sub){
6000 $status=$subOmanOoredoo->informTimweSub($product->id, $msisdn, $product->conf['charge_mt_pp'], 'SMS', $textMsg,$priceDetails);
6001 }else{
6002 $checkSubStatus = $subOmanOoredoo->checkSubscriptionStatus($productId, $msisdn);
6003 if($checkSubStatus == 'Success'){
6004 $setMT='ALREADY_SUB';
6005 }else{
6006 $status=$subOmanOoredoo->informTimweSub($product->id, $msisdn, $product->conf['charge_mt_pp'], 'SMS', $textMsg,$priceDetails);
6007 }
6008 }
6009 }else{
6010 $setMT = 'INVALID_SUB';
6011 }
6012 }elseif(in_array($key,$product->conf['mosysunsub'])){
6013 $setMT = '';
6014 $sysProductId = $keyword;
6015
6016 $file = Yii::app()->getBasePath().DIRECTORY_SEPARATOR."runtime/callback_omanTimwe2.txt";
6017 $content = "keyword 2 :".$keyword."->".$key."\n";
6018 file_put_contents($file, $content, FILE_APPEND | LOCK_EX);
6019
6020 $priceDetails = $subOmanOoredoo->getProductBySysProductId($sysProductId);
6021 $productId = $priceDetails['product_id'];
6022 if($productId)
6023 {
6024 $sub = (new SubscriptionEx())->getSubscription($msisdn, $productId);
6025 // var_dump($sub,$msisdn, $productId);die;
6026 if($sub){
6027
6028 $OmanTimweCb2->msisdn = $msisdn;
6029 $OmanTimweCb2->product_id = $product->id;
6030 $endSubStatus = $OmanTimweCb2->cancelSub();
6031 $msg="You have been successfully unsubscribed from ".$product->conf['servicename']." Service. To re-subscribe anytime, please send ".$product->conf['key']." ".$product->conf['keyword']." to ".$product->conf['shortcode']." Baisa ".round($priceDetails['price'])."/".$priceDetails['validity']."day";
6032 $mt_response= $subOmanOoredoo->sendMtRequest($product->id, $msisdn, $msg, $product->conf['orgid']);
6033 // $status= $subOmanOoredoo->deactivateMultipleByCC($msisdn, $sub->id, $priceDetails);
6034 }else{
6035 $checkSubStatus = $subOmanOoredoo->checkSubscriptionStatus($productId, $msisdn);
6036 if($checkSubStatus == 'already_cancel'){
6037 $setMT='ALREADY_UNSUB';
6038 }else{
6039 $setMT = 'HELP_UNSUB';
6040 }
6041 }
6042 }else{
6043 $setMT = 'INVALID_UNSUB';
6044 }
6045 }else if($textCount ==1 && in_array($key, $product->conf['mounsub'])){
6046 //die('1 mounssub');
6047 //unsubscribe user for all product for matching shortcode
6048 $userActiveSub = $subOmanOoredoo->getActiveSubByShortcode($msisdn, $product->conf['shortcode'] );//$shortCode
6049 if(count($userActiveSub)>0){
6050 foreach($userActiveSub as $key=>$subId)
6051 {
6052 $OmanTimweCb2->msisdn = $msisdn;
6053 $OmanTimweCb2->product_id = $product->id;
6054 $endSubStatus = $OmanTimweCb2->cancelSub();
6055// $status = $subOmanOoredoo->deactivateMultipleByCC($msisdn, $subId, $priceDetails);
6056 $msg="You have been successfully unsubscribed from ".$product->conf['servicename']." Service. To re-subscribe anytime, please send ".$product->conf['key']." ".$product->conf['keyword']." to ".$product->conf['shortcode']." Baisa ".round($priceDetails['price'])."/".$priceDetails['validity']."day";
6057 $mt_response= $subOmanOoredoo->sendMtRequest($product->id, $msisdn, $msg, $product->conf['orgid']);
6058
6059 }
6060 }else{
6061 $setMT = 'HELP_UNSUB';
6062 }
6063 }else if(in_array($key, $product->conf['mounsub'])){
6064 $setMT='';
6065 if($keyword!=''){
6066 $sub=(new SubscriptionEx())->getSubscription($msisdn, $productId);
6067 if($sub){
6068 $OmanTimweCb2->msisdn = $msisdn;
6069 $OmanTimweCb2->product_id = $product->id;
6070 $endSubStatus = $OmanTimweCb2->cancelSub();
6071 // save deactivation
6072// $status=$subOmanOoredoo->deactivateByMo($msisdn, $sub->id, $priceDetails);
6073 $msg="You have been successfully unsubscribed from ".$product->conf['servicename']." Service. To re-subscribe anytime, please send ".$product->conf['key']." ".$product->conf['keyword']." to ".$product->conf['shortcode']." Baisa ".round($priceDetails['price'])."/".$priceDetails['validity']."day";
6074 $mt_response= $subOmanOoredoo->sendMtRequest($product->id, $msisdn, $msg, $product->conf['orgid']);
6075 }else{
6076 $checkSubStatus = $subOmanOoredoo->checkSubscriptionStatus($productId, $msisdn);
6077 if($checkSubStatus == 'already_cancel'){
6078 $setMT='ALREADY_UNSUB';
6079 }else{
6080 $setMT = 'HELP_UNSUB';
6081 }
6082 }
6083 }else{
6084 $setMT='INVALID_SUB';
6085 }
6086
6087 }elseif($textCount ==2 && in_array($sep_unsub, $product->conf['mounsub'])){
6088 $userActiveSub = $subOmanOoredoo->getActiveSubByShortcode($msisdn, $product->conf['shortcode'] );//$shortCode
6089 if(count($userActiveSub)>0){
6090 foreach($userActiveSub as $key=>$subId)
6091 {
6092 $OmanTimweCb2->msisdn = $msisdn;
6093 $OmanTimweCb2->product_id = $product->id;
6094 $endSubStatus = $OmanTimweCb2->cancelSub();
6095// $status = $subOmanOoredoo->deactivateMultipleByMo($msisdn, $subId, $priceDetails);
6096 $msg="You have been successfully unsubscribed from ".$product->conf['servicename']." Service. To re-subscribe anytime, please send ".$product->conf['key']." ".$product->conf['keyword']." to ".$product->conf['shortcode']." Baisa ".round($priceDetails['price'])."/".$priceDetails['validity']."day";
6097 $mt_response= $subOmanOoredoo->sendMtRequest($product->id, $msisdn, $msg, $product->conf['orgid']);
6098 }
6099 }else{
6100 $setMT = 'HELP_UNSUB';
6101 }
6102 }else{
6103 $sub = (new SubscriptionEx())->getSubscription($msisdn, $productId);
6104 if( strtoupper ($key) == 'HELP'){
6105 //send message of help if sub and not subscribe
6106 $setMT = 'HELP_UNSUB';
6107 if($sub){
6108 $setMT = 'HELP_SUB';
6109 }else{
6110 $sub = (new SubscriptionEx())->getSubscription($msisdn, $product->conf['other_pid']);
6111 if($sub){
6112 $setMT = 'HELP_SUB';
6113 $productId=$product->conf['other_pid'];
6114 }
6115 }
6116 }else{
6117 //send message of invalid if sub and not subscribe
6118 $setMT = 'INVALID_UNSUB';
6119 if($sub){
6120 $setMT = 'INVALID_SUB';
6121 }else{
6122 $sub = (new SubscriptionEx())->getSubscription($msisdn, $product->conf['other_pid']);
6123 if($sub){
6124 $setMT = 'INVALID_SUB';
6125 $productId=$product->conf['other_pid'];
6126 }
6127 }
6128 }
6129 }
6130 if($setMT != ''){
6131 $text = $subOmanOoredoo->getMessageByType($productId, round($priceDetails['price']), $priceDetails['validity'], $setMT);
6132 $mt_response= $subOmanOoredoo->sendMtRequest($product->id, $msisdn, $text, $product->conf['orgid']);
6133 }
6134 $sendCodeStatus=$setMT.'|'.$status.'|'.$endSubStatus;
6135 $getParams['time']= new MongoDate();
6136 $getParams['_partner'] = 'OmanOoredoo';
6137 $getParams['_type']='MOREQUEST';
6138 $callbackLog = (new SubOmanTimwe2())->getCollection();
6139 echo $sendCodeStatus;
6140 try
6141 {
6142 $getParams['_response']=$sendCodeStatus;
6143 $getParams['_mtresponse']=$mt_response;
6144 $getParams['msisdn']=$msisdn;
6145 $callbackLog->insert($getParams);
6146 }
6147 catch (Exception $e)
6148 {
6149 throw $e->getMessage();
6150 }
6151
6152 Yii::app()->cache->set('omanooredoo.mo.'.$_GET['TxId'],1);
6153 //return $_GET['TxId'].'MO';
6154 }
6155 /**
6156 * Callback Ooredoo-timwe -Oman -mp in tunnel
6157 */
6158 public function actionOmanTmwCb2(){
6159
6160 // for only testing purpose
6161 $this->storeLog('omantimwe_mp','callback_dlr_mp');
6162 $req= trim(file_get_contents('php://input'));
6163 if (empty($req)) {
6164 throw new CHttpException(404, 'No request found.');
6165 }
6166// $getParams=(new Common())->xmlToArray($req); //if req is xml
6167 $getParams = json_decode($req,1); //if req is json
6168
6169 if(isset($getParams['correlator']))
6170 {
6171 $response['correlator']=$getParams['correlator'];
6172 if($getParams['code']==1){
6173 if(isset($getParams['subscription']))
6174 {
6175 $productId=$getParams['subscription']['productId'];
6176 $product= (new ProductEx)->find("conf_json like :product_id", [':product_id'=>"%productId%$productId%"]);
6177 if($product)
6178 {
6179 $priceVal=$product->getPriceNValidity();
6180 $getParams['eventId'] = $priceVal['eventid'];
6181 $product_id = $product->id;
6182 }else{
6183 $product_id=(new SubOmanTimwe2())->getProductIdByCorrelator($getParams['correlator']);
6184 $product=(new ProductEx)->findByPk($product_id);
6185 $priceVal=$product->getPriceNValidity();
6186 $getParams['eventId'] = $priceVal['eventid'];
6187 }
6188 }
6189 $getParams['product_id']=$product_id;
6190 $response['responseStatus'] = (new OmanTimweCb2())->OmanTimweCback($getParams);
6191 }else{
6192 $response['responseStatus']=1;
6193 }
6194 $response= json_encode($response);
6195 }else
6196 {
6197 $response=FALSE;
6198 }
6199 $getParams['time']= new MongoDate();
6200 $getParams['_partner'] = 'OmanOoredoo';
6201 $getParams['_type']='callback';
6202// $callbackLog = Yii::app()->mongodb->callback_log;
6203 $callbackLog = (new SubOmanTimwe2())->getCollection();
6204 print_r($response);
6205 try
6206 {
6207 $getParams['_response']=$response;
6208 $callbackLog->insert($getParams);
6209 }
6210 catch (Exception $e)
6211 {
6212 throw $e->getMessage();
6213 }
6214 }
6215 /**
6216 * Belgium Veoo DN
6217 */
6218 public function actionBelveoocb(){
6219 $req= trim(file_get_contents('php://input'));
6220 $getparams = json_decode($req, true); // for json request check
6221
6222 $getparams = array_change_key_case($getparams, CASE_LOWER);
6223 $getparams['time'] = new MongoDate();
6224 $getparams['_partner'] = 'belgium_veoo';
6225 $getparams['_type'] = "cb_mp";
6226 $this->storeLog('belgium_veoo','cb_mp');
6227 $callbackLog = (new SubBeVeoo())->getCollection();
6228 $trans = $getparams['transaction'];
6229 if(isset($trans['product_id']) && $trans['product_id']!=""){
6230 $product_id = $this->productId($trans['product_id']);
6231 if($product_id){
6232 $getparams['product_id'] = $product_id;
6233 $getparams['event_id'] = $trans['product_id'];
6234 $code = (new BelVeooCb())->BelVeooCback($getparams);
6235 $response = (new BelVeooCb())->responseCode()[$code];
6236 }else{
6237 $response ="Service Not Found.";
6238 }
6239 }else{
6240 $response ="Parameter Missing!.";
6241 }
6242 print_r($response);
6243 try{
6244 $getparams['_response'] =$response;
6245 $callbackLog->insert($getparams);
6246 } catch (Exception $e){
6247 throw $e->getMessage();
6248 }
6249 }
6250 /**
6251 * DLR in du-timwe - MP
6252 */
6253 public function actiondutimwcbmp(){
6254
6255 // for only testing purpose
6256 $this->storeLog('dutimwe_cb_mp','cb_mp');
6257 $this->actionDutimwedlr();
6258// print_r("Success");
6259 }
6260 /**
6261 * DLR du-timwe -mp in tunnel
6262 */
6263 public function actionDuTDLRmp(){
6264
6265 // for only testing purpose
6266 $this->storeLog('dutimwe_mp','dlr_mp');
6267 print_r("Success");
6268 }
6269 /**
6270 * CB in Du-Timwe - MP
6271 */
6272 public function actiondutimwdlrmp(){
6273
6274 // for only testing purpose
6275 $this->storeLog('dutimwe_dlr_mp','dlr_mp');
6276 $this->actionDutimwecb();
6277// print_r("Success");
6278 }
6279 /**
6280 * for mo flow in du-dubai timwe - mp
6281 */
6282 public function actiondutimwmomp(){
6283
6284 // for only testing purpose
6285 $this->storeLog('dutimw_mo_mp','mo_mp');
6286 $this->actionDumo();
6287// print_r("Success");
6288 }
6289 /**
6290 * XMOB-GR-MP-CB
6291 */
6292 public function actionXMobBRCb($partner='xmobBR_mp_vr'){
6293
6294 $getParams = W::getRequestParams();
6295 $getParams = array_change_key_case($getParams, CASE_LOWER);
6296// $partner = 'xmobBR_mp';
6297 $type = 'cb';
6298 $getParams['_partner'] = "$partner";
6299 $getParams['_type'] = "$type";
6300 $getParams['time'] = new MongoDate();
6301
6302 // Data store for testing purpose START
6303// $this->storeLog("$partner","$type");
6304 // Data store for testing purpose STOP
6305
6306 $callbackLog = SubXMobBrazil::getCollection();
6307// if( (isset($getParams['product_id']) && $getParams['product_id']!="")
6308 if( (isset($getParams['action']) && $getParams['action']!="")
6309 && (isset($getParams['msisdn']) && $getParams['msisdn']!="") )
6310 {
6311 // Set productID
6312// $getParams['pid'] = '';//$getParams['product_id'];
6313 $getParams['eventid'] = $getParams['product_id'];
6314
6315 // Get ProductID
6316 $productId = (string)$this->productId($getParams['eventid']); //set product_id
6317
6318 //check product is available or not
6319 if($productId == false){
6320 $response = "service not found.!";
6321 }else{
6322 $getParams['product_id'] = $productId;
6323 $code=(new XMobBrazilCb())->XMobBrazilCback($getParams);
6324 $response =(new XMobBrazilCb())->responseCode()[$code];
6325 }
6326 }else{
6327 $response = "Parameter not found.!";
6328 }
6329
6330 print_r($response);
6331 try{
6332 $getParams['_response'] = $response;
6333 $callbackLog->insert($getParams);
6334 }catch(Exception $e){
6335 throw $e->getMessage();
6336 }
6337 }
6338 public function actionBnglRobiUnsub(){
6339 $req= trim(file_get_contents('php://input'));
6340 $getparams = json_decode($req, true); // for json request check
6341
6342 $getparams = array_change_key_case($getparams, CASE_LOWER);
6343 $getparams['time'] = new MongoDate();
6344 $getparams['_partner'] = 'purple_robi';
6345 $getparams['_type'] = "Callback_Unsub";
6346
6347
6348 $this->storeLog("purple_robi",'callback_unsub');
6349 $callbackLog = (new SubBangla())->getCollection();
6350 // For Event_id START
6351 $getparams['event_id'] = 'A33F3BCBAE6E';
6352 if($getparams['data']['status']=='unsubscribed'){
6353 $getparams['action'] = "unsub";
6354 }
6355 if(isset($getparams['event_id']) && $getparams['event_id']!=""){
6356
6357 $product_id = $this->productId($getparams['event_id']);
6358 if(!empty($product_id)){
6359 $getparams['product_id'] = $product_id;
6360 $getparams['event_id'] = $getparams['event_id'];
6361 $getparams['msisdn'] = ltrim($getparams['data']['msisdn'],"+");
6362// $getparams['action'] = "unsub";
6363 $code = (new BanglaCb())->BanglaCback($getparams);
6364 $response =(new BanglaCb())->responseCode()[$code];
6365 }else{
6366 $response = "Product Not Found.!";
6367 }
6368 }else{
6369 $response = "Parameter Missing.!";
6370 }
6371 print_r($response);
6372 try{
6373 $getparams['_response'] =$response;
6374 $callbackLog->insert($getparams);
6375 } catch (Exception $e){
6376 throw $e->getMessage();
6377 }
6378 }
6379 /**
6380 * Algeria Callback
6381 */
6382 public function actionTpayAlgCb(){
6383 $this->TpayCallback('tpayalgcb_mp');
6384 }
6385 /**
6386 * Tunisia Callback
6387 */
6388 public function actionTpayTunCb(){
6389 $this->TpayCallback('tpaytuncb_mp');
6390 }
6391 /**
6392 * For Batelco Tracking user through msisdn
6393 */
6394 public function actionBatlcoTrack(){
6395
6396 $getParams = W::getRequestParams();
6397 $getParams = array_change_key_case($getParams, CASE_LOWER);
6398
6399 // data save in mongoCampTransaction
6400 $tokenCamp = new MongoCampTransaction();
6401 $tokenCamp->_id = (new SubIraqActel())->getRefId();
6402 $tokenCamp->camp = isset($getParams['pub'])?$getParams['pub']:'';
6403 $tokenCamp->token = isset($getParams['tkn'])?$getParams['tkn']:'';
6404 $tokenCamp->device_id = isset($getParams['device_id'])?$getParams['device_id']:'';
6405 $tokenCamp->phone = $getParams['msisdn'];
6406 $tokenCamp->datetime = new MongoDate();
6407 $tokenCamp->save();
6408 // Success message print
6409
6410 // data save in mongo
6411 $toStore=[
6412 'getParams' => $getParams,
6413 'country' => 'Bahrain',
6414 'time' => new MongoDate()
6415 ];
6416 SubIraqActel::getCollection()->save($toStore);
6417
6418 echo 'success';
6419 }
6420
6421 /**
6422 * For UK Oxy8
6423 */
6424 public function actionUkOxy8Cb()
6425 {
6426 // for only logging purpose
6427 $this->storeLog('uk_oxy8','notify');
6428 print_r("Success");
6429 }
6430
6431 /**
6432 * Get count of kenya DND no
6433 * @return type
6434 */
6435 public function actionKenyaProfileCount(){
6436
6437 echo $resCount = (new kenya_profile())->getCollection()->count();
6438 return $resCount;
6439 }
6440 /**
6441 * Kenya-Msisdn Failed Msisdn Store
6442 */
6443 public function actionKenyaNumCheck(){
6444
6445 $status = 'failed';
6446 $getParams = W::getRequestParams();
6447 $getParams = array_change_key_case($getParams, CASE_LOWER);
6448 $getParams['time']= new MongoDate();
6449 //ms,reason,status
6450
6451 $msisdn = "254".substr($getParams['msisdn'],-9); // get only last 9 digit
6452
6453 if(isset($getParams['msisdn']) && $getParams['type'] === 'adddnd'){
6454 // record insert
6455 $status = (new kenya_profile())->chkMsisdn($msisdn,$getParams['reason'],$getParams['status']);
6456 }else{
6457 // get result valid or invalid
6458 $status = (new kenya_profile())->getMsisdnStatus($msisdn);
6459 }
6460 echo $status;
6461 }
6462
6463 /**
6464 * For malaysia only for unsub portal
6465 */
6466 public function actionUnsubService(){
6467
6468 // for testing purpose only
6469 $this->storeLog('unsub_mp','unsub_mp');
6470
6471 $getParams = W::getRequestParams();
6472 $getParams = array_change_key_case($getParams, CASE_LOWER);
6473
6474 $statusCode = 500;
6475// $productsArr = [85,72];
6476 $productsArr = [85,72,109,110];
6477 $nthItArr = [109,110];
6478 if(in_array($getParams['product_id'], $productsArr)){
6479
6480 $sub = (new SubscriptionEx())->getSubscription($getParams['msisdn'], $getParams['product_id']);
6481// if($sub){
6482// $sub_id = $sub->id;
6483// (new SubMalaysiaMk())->deactivate($sub_id);
6484// $statusCode = 200;
6485// }
6486 if($sub){
6487 $sub_id = $sub->id;
6488 $Object = (in_array($getParams['product_id'], $nthItArr))? new SubNTHIT(): new SubMalaysiaMk();
6489 $Object->deactivate($sub_id);
6490 $statusCode = 200;
6491 }
6492 }
6493 echo $statusCode;
6494 }
6495 /**
6496 * For MO in OmanTel
6497 */
6498 public function actionOmanTelMO(){
6499
6500 // Data store for testing purpose START
6501 $this->storeLog("omantel","omantel_mo");
6502 // Data store for testing purpose STOP
6503// $this->bahrainmo('OmanTel','Oman','oman_omantel');
6504 }
6505 /**
6506 * OmanTel - MT sent log
6507 */
6508 public function actionOmanTelMT(){
6509
6510 // Data store for testing purpose START
6511 $this->storeLog("omantel","omantel_mt");
6512 // Data store for testing purpose STOP
6513// $this->bahrainmo('OmanTel','Oman','oman_omantel');
6514 }
6515 /**
6516 * Opt-In in OmanTel
6517 */
6518 public function actionOmanTelOptIN(){
6519
6520 // Data store for testing purpose START
6521 $this->storeLog("omantel","omantel_optin");
6522 // Data store for testing purpose STOP
6523// $this->bahrainoptin('OmanTel','Oman','oman_omantel');
6524 }
6525 /**
6526 * Opt-Out in OmanTel
6527 */
6528 public function actionOmanTelOptOut(){
6529
6530 // Data store for testing purpose START
6531 $this->storeLog("omantel","omantel_optout");
6532 // Data store for testing purpose STOP
6533// $this->bahrainoptout('OmanTel','Oman','oman_omantel');
6534 }
6535 /**
6536 * OmanTel - Billing - MP
6537 */
6538 public function actionOmanTelBilling(){
6539
6540 // Data store for testing purpose START
6541 $this->storeLog("omantel","omantel_billing");
6542 // Data store for testing purpose STOP
6543// $this->bahraindobnotify('OmanTel','Oman','oman_omantel');
6544 }
6545 /**
6546 * send postback to user
6547 */
6548 public function actionMfPostbk(){
6549
6550 $getparams = W::getRequestParams(); // if get or post request
6551 $getparams = array_change_key_case($getparams, CASE_LOWER);
6552
6553 if(isset($getparams['camp'])){
6554
6555 $camp = $getparams['camp']; // camp
6556 $token = $getparams['tkn']; // token
6557 $txnid = uniqid(); // uniq id
6558
6559 $campInfo= CampTransaction::model()->find('campaign=:camp', array(':camp'=>$camp));
6560 if(!empty($campInfo))
6561 {
6562// if(W::probability($campInfo->scrubbing))
6563// {
6564 $url= strtr($campInfo->url, ['{token}' => $token, '{pubid}'=> $camp, '{txnid}'=> $txnid]);
6565 $ch = curl_init();
6566 curl_setopt($ch, CURLOPT_URL, $url);
6567 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,3);
6568 curl_setopt($ch,CURLOPT_TIMEOUT, 3);
6569 curl_setopt($ch, CURLOPT_HEADER, FALSE);
6570 curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
6571 $result = curl_exec($ch);
6572 $result = 'moboaff';
6573 $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
6574 curl_close($ch);
6575
6576// }else{
6577// $result='SCRUBBED_moboaff';$httpCode=0;
6578// }
6579
6580 //savelog in mongo
6581 $toStore=[
6582 'camp'=> $camp,
6583 'token' => $token,
6584 'result' => $result,
6585 'product_id'=>'97',
6586 'type'=>'OI',
6587 'txnid' => $txnid,
6588 'httpCode' => (string)$httpCode,
6589 'time'=> new MongoDate(),
6590 ];
6591 Yii::app()->mongodb->camp_scrubbing_log->save($toStore);
6592 }else{
6593 echo 'not found';
6594 exit();
6595 }
6596 }
6597 print_r("success");
6598 exit();
6599 }
6600 /**
6601 * ideaBiz-lk Callback
6602 */
6603 public function actionIdeaBizLKCb(){
6604
6605 $req= trim(file_get_contents('php://input'));
6606 $getparams = json_decode($req, true); // for json request check
6607 if(empty($getparams)){
6608
6609 $getparams=(new Common())->xmlToArray($req); //if req is xml
6610 if(empty($getparams)) {
6611
6612 $getparams = W::getRequestParams(); // if get or post request
6613 if(empty($getparams)){
6614 throw new CHttpException(404, 'No request found.');
6615 }
6616 }
6617 }
6618
6619 $partner = 'ideabizlk_cb';
6620 $cbType = 'callback';
6621 $getparams = array_change_key_case($getparams, CASE_LOWER);
6622 $getparams['time'] = new MongoDate();
6623 $getparams['_partner'] = $partner;
6624 $getparams['_type'] = $cbType;
6625
6626 // Temp log store in collection after testing please commant in this line.
6627 $this->storeLog("$partner","$cbType");
6628 // log collection name
6629 $callbackLog = SubIdeabizLk::getCollection();
6630 if(!isset($getparams['serviceid']) or $getparams['serviceid']==""){
6631 $getparams['serviceid'] = "3f6dd1fe-47ed-4f7a-9ca0-5bf36b861be8";
6632 }
6633 if(isset($getparams['serviceid']) && $getparams['serviceid']!=""){
6634
6635 $event_id = "30-".$getparams['serviceid'];
6636 $product_id = $this->productId($event_id);
6637 if(!empty($product_id)){
6638
6639 $getparams['product_id'] = $product_id;
6640 $getparams['event_id'] = $event_id;
6641
6642 $callbackClass = (new IdeaBizLkCb());
6643 $code = $callbackClass->IdeaBizLkCback($getparams);
6644 $response = $callbackClass->responseCode()[$code];
6645
6646 }else{
6647 $response = "Product Not Found.!";
6648 }
6649 }else{
6650 $response = "Parameter Missing.!";
6651 }
6652 print_r($response);
6653 try{
6654 $getparams['_response'] =$response;
6655 $callbackLog->insert($getparams);
6656 }catch(Exception $e){
6657 throw $e->getMessage();
6658 }
6659 }
6660 /**
6661 * Bebeauty -BR notification URL
6662 * @param type $param
6663 */
6664 public function actionXMobBRBEBCb(){
6665 $this->actionXMobBRCb('xmobBR_mp_beb');
6666 }
6667 /**
6668 * BR-Playup notification URL
6669 * @param type $param
6670 */
6671 public function actionXMobBRPLYUPCb(){
6672 $this->actionXMobBRCb('xmobBR_mp_plyup');
6673 }
6674
6675 /** #
6676 * intg for Oxy8 UK callback of Subscription/optin
6677 */
6678 public function actionOxy8ukCb(){
6679
6680 $getparams = W::getRequestParams(); // if get or post request
6681 $getparams = array_change_key_case($getparams,CASE_LOWER);
6682 $getparams['time'] = new MongoDate();
6683 $getparams['_partner'] = 'xoy8PayForit';
6684 $getparams['_type'] = 'callback';
6685
6686 $callbackLog=(new SubOxy8UkPay())->getCollection();
6687// $msisdn = (new SubOxy8UkPay())->decrypt($getparams['msisdn'], "key");
6688// print_r($msisdn);exit;
6689 if(isset($getparams['transactionid']) && isset($getparams['securecode'])){
6690
6691 $dataCode=(new SubOxy8UkPay())->getTransactionUklog($getparams['transactionid']);
6692 $getparams['msisdn']=$dataCode['msisdn'];
6693 if(!empty($dataCode)){
6694 if($getparams['transactionid']==$dataCode['_id'] && isset($getparams['securecode'])){
6695 $getparams['product_id']=$dataCode['product_id'];
6696 $getparams['event_id']=$dataCode['event_id'];
6697 $getparams['dataCode']=$dataCode;
6698 $code=(new Oxy8ukCb())->Oxy8ukCback($getparams);
6699 $response = (new Oxy8ukCb())->responseCode()[$code];
6700 }
6701 else{
6702 $response="Parameter transactionID and securecode are not match !";
6703 }
6704 }
6705 else{
6706 $response="Parameter transactionID and securecode are not match !";
6707 }
6708 }
6709 else{
6710 $response="Parameter Missing!";
6711 }
6712 print_r($response);
6713 try{
6714 $getparams['_response'] =$response;
6715 $callbackLog->insert($getparams);
6716 }catch (Exception $e){
6717 throw $e->getMessage();
6718 }
6719 }
6720
6721 /** #
6722 * Oxy8PayFor SMS Notification
6723 */
6724 public function actionOxy8PayForSMSCb()
6725 {
6726 $req = trim(file_get_contents('php://input'));
6727 $getparams = json_decode($req, true); // for json request check
6728 if (empty($getparams))
6729 {
6730 $getparams = (new Common())->xmlToArray($req); //if req is xml
6731 if (empty($getparams))
6732 {
6733 $getparams = W::getRequestParams(); // if get or post request
6734 if (empty($getparams))
6735 {
6736 throw new CHttpException(404, 'No request found.');
6737 }
6738 }
6739 }
6740
6741 $getparams = array_change_key_case($getparams, CASE_LOWER);
6742 $getparams['time'] = new MongoDate();
6743 $getparams['_partner'] = 'oxy8UkPay';
6744 $getparams['_type'] = 'callbackSMS';
6745 $callbackLog = (new SubOxy8UkPay())->getCollection();
6746 echo $response = "OK";
6747
6748 try {
6749 $getparams['_response'] = $response;
6750 $callbackLog->insert($getparams);
6751 } catch (Exception $e) {
6752 throw $e->getMessage();
6753 }
6754 }
6755
6756 /**
6757 * Palestine-UT Callback
6758 */
6759 public function actionunitelplcb(){
6760
6761 $getparams = W::getRequestParams();
6762 $getparams = array_change_key_case($getparams,CASE_LOWER);
6763
6764 $getparams['time'] = new MongoDate();
6765 $getparams['_partner'] = 'palestine_ut';
6766 $getparams['_type'] = 'callback';
6767
6768 $callbackLog=(new SubPalestine())->getCollection();
6769
6770 if($getparams['serviceid']!="" && $getparams['msisdn']!=""){
6771 $eventid=$getparams['operatorid']."_".$getparams['serviceid'];
6772 $product_id =$this->productId($eventid);
6773 if($product_id){
6774 $getparams['product_id']=$product_id;
6775 $getparams['event_id']=$eventid;
6776 $code = (new PalestineCB())->PalestineCback($getparams);
6777 $response = (new PalestineCB())->responseCode()[$code];
6778 }else{
6779 $response="Product not found..";
6780 }
6781 }else{
6782 $response="Parameter Missing!";
6783 }
6784 print_r($response);
6785 try{
6786 $getparams['_response'] =$response;
6787 $callbackLog->insert($getparams);
6788 } catch (Exception $e){
6789 throw $e->getMessage();
6790 }
6791 }
6792 /**
6793 *
6794 * @param type $id Product id
6795 */
6796 public function actionSms($id)
6797 {
6798 $request=$_REQUEST;
6799 $request['_type']='update';
6800 $callback=Yii::app()->mongodb->callback_log;
6801 try {
6802 $callback->insert($request);
6803 echo "sms template";
6804 } catch (Exception $exc) {
6805
6806 }
6807 }
6808 /*
6809 * Indo Macrokiosk PlayUp MO
6810 */
6811 public function actionIndoMakmo(){
6812 print_r('success');
6813 exit;
6814 }
6815 /*
6816 * Indo Macrokiosk PlayUp DN
6817 */
6818 public function actionIndoMakdn(){
6819 print_r('success');
6820 exit;
6821 }
6822
6823 /*
6824 * Irenland M-Gage MO
6825 */
6826 public function actionMgageMO(){
6827 print_r('success');
6828 exit;
6829 }
6830 /*
6831 * Irenland M-Gage DR
6832 */
6833 public function actionMgageDR(){
6834 print_r('success');
6835 exit;
6836 }
6837 /**
6838 * ACR Encoded Value
6839 */
6840 public function actionAcr()
6841 {
6842 $acr = SubZaVodafone::getEncodedMsisdn(trim($_REQUEST['msisdn']));
6843 header("X-DATA: ".$acr);
6844 echo $acr;
6845 }
6846
6847 /**
6848 * Check Product capping status
6849 */
6850 public function actionCap()
6851 {
6852 $response = "NOTFOUND";
6853 if($_GET['pid'])
6854 {
6855 $response = "FALSE";
6856 $camp = isset($_GET['camp'])?$_GET['camp']:'';
6857 $time = 60*2; //2 minutes
6858 if(W::getCapStatus($_GET['pid'], $camp, $time) === TRUE)
6859 {
6860 $response = "TRUE";
6861 }
6862 }
6863 echo $response;
6864 }
6865
6866
6867 /** return Vodafone Customer Balance details
6868 *
6869 * @param string $msisdn customer mobile number
6870 */
6871 public function actionBalCheckVodaIn()
6872 {
6873 $request = $_REQUEST;
6874 $request['_type']='balCheck';
6875 $request['time'] = new MongoDate();
6876 $response = '{"error":"Invalid params"}';
6877 if(isset($request['msisdn']) and isset($request['hash']))
6878 {
6879 $passKey = 'T@CH\/@L!HH@';
6880 $date = gmdate(W::getDateFormat()); //format must be Y-m-d
6881 if(md5($date.$passKey.$request['msisdn']) == $request['hash'])
6882 {
6883 $response = W::checkBalanceVodaIN($request['msisdn']);
6884 }else{
6885 $response = '{"error":"Invalid request!"}';
6886 }
6887 }
6888 $callback = Yii::app()->mongodb->voda_bal_check;
6889 echo $request['_response'] = $response;
6890 try {
6891 $callback->insert($request);
6892 } catch (Exception $exc) {
6893
6894 }
6895 }
6896
6897 /**
6898 * Check DND if number has blocked then returns TRUE else FALSE
6899 */
6900 public function actionDndStatus()
6901 {
6902 $request = $_REQUEST;
6903 $response = 'FALSE';
6904 if(W::dndStatus($request["msisdn"], false) === true) //self dnd check
6905 {
6906 $response = 'TRUE';
6907 }
6908 echo $response;
6909 }
6910 /**
6911 * For Add DND numbers
6912 */
6913 public function actionAddDndStatus()
6914 {
6915 $request = $_REQUEST;
6916 $response = 'invalid request';
6917 if(isset($request['msisdn']))
6918 {
6919 $reason = (isset($request['reason']))?$request['reason']:'By Async CB';
6920 $response = W::addInDnd($request['msisdn'], $reason, false);
6921 }
6922 echo $response;
6923 $request['_type']='dndcb';
6924 $request['_response']= $response;
6925 $callback=Yii::app()->mongodb->dnd_req_log;
6926 try {
6927 $callback->save($request);
6928 }catch (Exception $exc) {
6929
6930 }
6931 }
6932
6933 /**
6934 * Check APK block if package blocked then returns TRUE else FALSE
6935 */
6936 public function actionApkBlockStatus()
6937 {
6938 $request = $_REQUEST;
6939 $response = 'FALSE';
6940 if(W::apkBlockStatus($request["pkgname"], false) === true) //self check
6941 {
6942 $response = 'TRUE';
6943 }
6944 echo $response;
6945 }
6946
6947 /**
6948 * Check number already subscribed then returns TRUE else FALSE
6949 */
6950 public function actionMSISDNStatus()
6951 {
6952 if(isset($_REQUEST['msisdn']) and $_REQUEST['msisdn'] != '')
6953 {
6954 $msisdn = $_REQUEST['msisdn'];
6955 }else{
6956 $header=[
6957 'HTTP_X_MSISDN',
6958 'HTTP_Y_MSISDN',
6959 'HTTP_X_NOKIA_MSISDN',
6960 'HTTP_X_UP_CALLING_LINE_ID',
6961 'HTTP_MSISDN',
6962 'HTTP_CLI',
6963 ];
6964 foreach($header as $k=>$v){
6965 if(isset($_SERVER[$v])){
6966 $msisdn = $_SERVER[$v]; break;
6967 }
6968 }
6969 }
6970
6971 $response = 'FALSE';
6972 $pid = isset($_REQUEST['pid']) ? $_REQUEST['pid'] : 0;
6973 if($pid)
6974 $sub = (new SubscriptionEx())->getSubscription($msisdn, $pid, 3);
6975 else
6976 $sub = (new SubscriptionEx())->checkSubByMsisdn($msisdn, 3);
6977 if($sub)
6978 {
6979 $response = 'TRUE';
6980 }
6981 echo $response;
6982 }
6983
6984 /** call for number deactivate if active
6985 *
6986 */
6987 public function actionUnsubNumber()
6988 {
6989 $request = $_REQUEST;
6990 $request['_type']='unsubNumber';
6991 $request['time'] = new MongoDate();
6992 $response = 'Invalid params!';
6993
6994 if(isset($request['msisdn']) and isset($request['hash']))
6995 {
6996 $msisdn = $request['msisdn'];
6997 $passKey = 'T@CH\/@L!HH@';
6998 $date = gmdate(W::getDateFormat()); //format must be Y-m-d
6999 if(md5($date.$passKey.$request['msisdn']) == $request['hash'])
7000 {
7001 $subs = (new SubscriptionEx())->getAllActiveSubs($msisdn, 180);
7002 if($subs)
7003 {
7004 $response = "SubId : PID : Response\n";
7005 foreach ($subs as $key => $value)
7006 {
7007 $return = $value->unsub($value->id);
7008 $response .= $value->id." : ".$value->product_id." : ".$return[3]."\n";
7009 }
7010 $response .= count($subs).' record processed!';
7011 }else{
7012 $response = 'No subs found!';
7013 }
7014 }else{
7015 $response = 'Invalid hash!';
7016 }
7017 }
7018 $callback = Yii::app()->mongodb->unsub_number;
7019 echo $request['_response'] = $response;
7020 try {
7021 $callback->insert($request);
7022 } catch (Exception $exc) {
7023
7024 }
7025 }
7026 private function getProductId()
7027 {
7028 $get=['SERVICE_ID', 'srvkey', 'requestPlan', 'productId', 'pid', 'ProductName'];
7029 foreach($get as $v)
7030 {
7031 $value=isset($_REQUEST[$v])? $_REQUEST[$v]: 0;
7032 if($value)
7033 {
7034 $product_id= $this->productId($value);
7035 if($product_id)
7036 {
7037 return $product_id;
7038 }
7039 }
7040 }
7041 return 0;
7042 }
7043
7044 public function productId($eventId,$className='')
7045 {
7046 $sql="select product_id from product_price where eventid=:eid";
7047 $query=[':eid'=>$eventId];
7048 if($className!=''){
7049 $sql.=" and class_name=:cname";
7050 $query[':cname']=$className;
7051 }
7052 try {
7053 $product_id= Yii::app()->db->createCommand($sql)->queryScalar($query);
7054 } catch (Exception $exc) {
7055 $product_id=false;
7056 }
7057 return $product_id;
7058 }
7059
7060 /**
7061 *
7062 * @param type $id
7063 * @return ProductPrice $model
7064 */
7065 public function getProductPriceByPk($id)
7066 {
7067 $model = ProductPrice::model()->findByPk($id);
7068 return $model;
7069 }
7070
7071 public function filters() {
7072 return [
7073 'listener',
7074 //'checkHost'
7075 ];
7076 }
7077
7078 public function filterListener($fc)
7079 {
7080 error_reporting(0);
7081 $fc->run();
7082 }
7083
7084 public function filterCheckHost($fc)
7085 {
7086 $host=$_SERVER['REMOTE_ADDR'];
7087 if(!in_array($host, $this->hosts))
7088 {
7089 echo "Access Denied";
7090 exit;
7091 }
7092 $fc->run();
7093 }
7094
7095 public function getHosts()
7096 {
7097 return [
7098 '203.88.145.10',
7099 '203.88.146.57',
7100 '203.88.146.38',
7101 '203.88.146.130'
7102 ];
7103 }
7104
7105 public function actionWpg() {
7106 $user_agent = $_GET['ua'];
7107// $user_agent='Mozilla/5.0 (Linux; U; Android 4.0.3; de-de; Galaxy S II Build/GRJ22) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30';
7108 if($user_agent!='')
7109 {
7110 echo $user_agent,"<pre>";
7111 $mdata = W::getTeraNew($user_agent);
7112 print_r($mdata);
7113 exit;
7114 $model = new MongoPriceGroup();
7115 try {
7116
7117
7118 if($mdata)
7119 {
7120 $model->attributes=$mdata;
7121 $model->make= strtoupper($mdata['make']);
7122 $model->model= strtoupper($mdata['model']);
7123 $model->marketing_name=strtoupper($mdata['marketing_name']);
7124 $model->price= 0;
7125 $model->category = 0;
7126 if($model->make =='' || $model-> model =='')
7127 {
7128 echo "Requied";
7129 }
7130 else{
7131// if($model->_id=='')
7132// {
7133 $model->_id= new MongoId();
7134 $data = $model->findOne(['model'=>$model->model,'make'=>$model->make]);
7135 if($data){
7136 echo "Already";
7137 }else{
7138 $model->getCollection()->save($model->attributes);
7139 echo "Inserted";
7140 }
7141// }else{
7142// echo 'Already 2';
7143// }
7144 }
7145 }
7146 } catch (Exception $exc) {
7147// echo $exc->getTraceAsString();
7148 echo "Bad Req";
7149 }
7150 } else {
7151 echo "Requied";
7152 }
7153 }
7154
7155 /**
7156 * Insert User Agent details
7157 */
7158 public function actionAddUa()
7159 {
7160 $user_agent = $_GET['ua'];
7161// $user_agent='Mozilla/5.0 (Linux; U; Android 4.0.3; de-de; Galaxy S II Build/GRJ22) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30';
7162 if($user_agent != '')
7163 {
7164 $mdata = W::getTeraNew($user_agent);
7165 $mdata['_id'] = $user_agent;
7166 $mdata['time'] = new MongoDate();
7167 Yii::app()->mongodb->user_agent_log->save($mdata);
7168 echo "<pre>";
7169 print_r($mdata);
7170 } else {
7171 echo "Required (ua)";
7172 }
7173 }
7174}