public function update() { /** * @var SubSipAccount $model */ $model = $this->getSubSipAccountModel(); $remoteAcctUpdated = new ApiRemoteUpdateBalance($model->password, $model->username, $model->parentSip->password, $model->parentSip->username, $this->amount); return $remoteAcctUpdated->update(); }
/** * Tops-up sub sip using main SIP account * @return void [type] [description] */ public function actionSubSip() { header("Content-Type: application/json"); $jsonMessage = array("success" => false, "message" => "incomplete data/parameter"); $postedData = json_decode(file_get_contents("php://input"), true); if (isset($postedData['mainUsername']) && isset($postedData['mainPassword']) && isset($postedData['subUsername']) && isset($postedData['subPassword']) && isset($postedData['credits'])) { $remoteAcctUpdated = new ApiRemoteUpdateBalance($postedData['subPassword'], $postedData['subUsername'], $postedData['mainPassword'], $postedData['mainUsername'], $postedData['credits']); $remoteAcctUpdated->update(); $jsonMessage = array("success" => true, "message" => "Main SIP Updated"); } echo json_encode($jsonMessage); }
/** * * @throws Exception * @return integer Returns number of updated accounts */ public function topupAccounts() { $accountsAffectedInt = 0; $accountsArr = explode(",", $this->accounts); $groupId = uniqid(); foreach ($accountsArr as $key => $currentAccountName) { /** * @var $model RemoteDataCache */ $model = RemoteDataCache::model()->findByAttributes(array('sub_user' => $currentAccountName)); if ($model) { //topup the main account /** * @var $topUpMainAccount TopUpMainAccount */ $topUpMainAccount = Yii::app()->topUpMainAccount; $topUpMainAccount->topUp($this->freeVoipAccountUsername, $this->topupvalue, $model); //$this->topUpMainAccount($model); // topup the main account , old implementation //TOPUP the sub accounts /** * @TODO - use Yii component , put this to yii component */ $remoteAcctUpdated = new ApiRemoteUpdateBalance($model->sub_pass, $model->sub_user, $model->main_pass, $model->main_user, $this->topupvalue); /** * Logger */ ViciActionLogger::logAction("SUB_ACCOUNT_TOPUP", "Top upping {$model->sub_user} with {$this->topupvalue}", $this->topupvalue, $groupId, time()); /** * @TODO - use Yii component */ if ($remoteAcctUpdated->update()) { if ($this->andActivate) { /** * @TODO - use Yii component */ $activator = new ActivationFormModel(); $activator->activateAccount($model); } } /** * Force the RemoteDataCache instance to update its current campaign */ $campaignForcer = Yii::app()->campaignForcer; $campaignForcer->update($this->forceAgent, $model->sub_user); /** * Get the latest data from remote api */ $lastBalance = $model->balance; $voipInfoRetriever = new BestVOIPInformationRetriever(); $remoteVoipResult = $voipInfoRetriever->getInfo($model->main_user, $model->main_pass, $model->sub_user, $model->sub_pass); /** * Checking */ if ($model->last_balance_since_topup !== 0 && !is_null($model->last_balance_since_topup)) { /** * Create a charge log for certain remote data cache */ $newChargeLog = new AccountChargeLog(); $newChargeLog->account_id = $model->id; $newChargeLog->charge = doubleval($model->last_balance_since_topup) - doubleval($model->exact_balance); if (!$newChargeLog->save()) { throw new Exception(CHtml::errorSummary($newChargeLog)); } } $model->balance = doubleval($remoteVoipResult->getBalance()); $model->exact_balance = doubleval($remoteVoipResult->getSpecificBalance()); $model->last_balance = $lastBalance; $model->last_balance_since_topup = $remoteVoipResult->getSpecificBalance(); $model->save(); /** * Update the counter */ $accountsAffectedInt++; } } return $accountsAffectedInt; }