/** * Pushes user payment with some payment system * * @param string $login * @param float $cash * @param string $paysys * * @return void */ public function cashAdd($login, $cash, $paysys) { $note = 'OP:' . $paysys; zb_CashAdd($login, $cash, 'add', $this->altCfg['OPENPAYZ_CASHTYPEID'], $note); }
public function makeFreezeMonthFee() { $cost = $this->alterConf['FREEZEMONTH_COST']; $cashType = $this->alterConf['FREEZEMONTH_CASHTYPE']; if (!empty($this->allUserData)) { foreach ($this->allUserData as $eachUser) { if ($eachUser['Passive'] == 1) { zb_CashAdd($eachUser['login'], -1 * $cost, 'add', $cashType, 'FROZEN:' . $cost); } } } }
/** * Signup payments processing and addcash function inside * * @global object $ubillingConfig Ubilling config helper object * @param string $login Existing users login * @param float $cash Amount of money to put/set on user login * @param string $operation Operation type: add, correct,set,mock * @param int $cashtype Existing cashtype ID for payment registry * @param string $note Payment notes * * @return void */ function zb_CashAddWithSignup($login, $cash, $operation, $cashtype, $note) { switch ($operation) { case 'add': $signup_payment = zb_UserGetSignupPrice($login); $signup_paid = zb_UserGetSignupPricePaid($login); $signup_left = $signup_payment - $signup_paid; if ($signup_left > 0 && $cash > 0) { global $ubillingConfig; $alter = $ubillingConfig->getAlter(); if ($cash > $signup_left) { $signup_cash = $signup_left; $balance_cash = $cash - $signup_cash; zb_CashAdd($login, $signup_cash, $operation, $alter['SIGNUP_TYPEID'], __('Signup payment')); zb_CashAdd($login, $balance_cash, $operation, $cashtype, $note); } else { zb_CashAdd($login, $cash, $operation, $alter['SIGNUP_TYPEID'], __('Signup payment')); } } else { zb_CashAdd($login, $cash, $operation, $cashtype, $note); } break; default: zb_CashAdd($login, $cash, $operation, $cashtype, $note); break; } }
$cashinputs .= wf_TextInput('newpaymentnote', 'Payment note', '', true, 35); $cashinputs .= '<br>'; $cashinputs .= wf_Submit('Add cash'); $cashform = wf_Form('', 'POST', $cashinputs, 'glamour'); show_window(__('Add cash'), $cashform); show_window('', web_UserControls($parent_login)); //if someone adds cash if (wf_CheckPost(array('newcash'))) { $operation = vf($_POST['operation']); $cashtype = vf($_POST['cashtype']); $cash = $_POST['newcash']; if (isset($_POST['newpaymentnote'])) { $note = mysql_real_escape_string($_POST['newpaymentnote']); } //add cash to parent user zb_CashAdd($parent_login, $cash, $operation, $cashtype, $note); // add cash to all child users if (!empty($allchildusers)) { foreach ($allchildusers as $eachchild) { //adding cash if ($operation == 'add') { $billing->addcash($eachchild, $cash); } //correcting balance if ($operation == 'correct') { $billing->addcash($eachchild, $cash); } //setting cash if ($operation == 'set') { $billing->setcash($eachchild, $cash); }
/** * Do some user finance data changes * * @param array $changeParams * * @return array */ protected function changeUserFinance($changeParams) { $result = array(); if (isset($changeParams['customerid'])) { if (isset($this->allUserData[$changeParams['customerid']])) { if (isset($changeParams['value'])) { if (zb_checkMoney($changeParams['value'])) { $paymentNotes = isset($changeParams['comment']) ? $changeParams['comment'] : ''; zb_CashAdd($changeParams['customerid'], $changeParams['value'], 'add', 1, $paymentNotes); $result = array('result' => 'ok'); } else { $result = array('result' => 'error', 'error' => $this->errorNotices['EX_BAD_MONEY_FORMAT'] . ': ' . $changeParams['value']); } } else { $result = array('result' => 'error', 'error' => $this->errorNotices['EX_PARAM_MISSED'] . ': value'); } } else { $result = array('result' => 'error', 'error' => $this->errorNotices['EX_USER_NOT_EXISTS'] . ': ' . $changeParams['customerid']); } } else { $result = array('result' => 'error', 'error' => $this->errorNotices['EX_PARAM_MISSED'] . ': customer_id'); } return $result; }
function bs_ProcessHash($hash) { global $billing; $alterconf = rcms_parse_ini_file(CONFIG_PATH . "alter.ini"); //corporate users handling if ($alterconf['USER_LINKING_ENABLED']) { $allparentusers = cu_GetAllParentUsers(); } $query = "SELECT `id`,`summ`,`login` from `bankstaparsed` WHERE `hash`='" . $hash . "' AND `state`='0' AND `login` !=''"; $allinprocessed = simple_queryall($query); if (!empty($allinprocessed)) { log_register("BANKSTA PROCESSING " . $hash . " START"); foreach ($allinprocessed as $io => $eachrow) { //setting payment variables $operation = 'add'; $cashtype = $alterconf['BS_CASHTYPE']; $cash = $eachrow['summ']; $note = mysql_real_escape_string("BANKSTA:" . $eachrow['id']); // CU filter subroutine if ($alterconf['USER_LINKING_ENABLED']) { if (!bs_cu_IsParent($eachrow['login'], $allparentusers)) { //normal user cash zb_CashAdd($eachrow['login'], $cash, $operation, $cashtype, $note); simple_update_field('bankstaparsed', 'state', '1', "WHERE `id`='" . $eachrow['id'] . "'"); } else { //corporate user $userlink = $allparentusers[$eachrow['login']]; $allchildusers = cu_GetAllChildUsers($userlink); // adding natural payment to parent user zb_CashAdd($eachrow['login'], $cash, $operation, $cashtype, $note); simple_update_field('bankstaparsed', 'state', '1', "WHERE `id`='" . $eachrow['id'] . "'"); if (!empty($allchildusers)) { foreach ($allchildusers as $eachchild) { //adding quiet payments for child users $billing->addcash($eachchild, $cash); log_register("BANKSTA GROUPBALANCE " . $eachchild . " " . $operation . " ON " . $cash); } } // end of processing with linking } } else { // standalone user cash push zb_CashAdd($eachrow['login'], $cash, $operation, $cashtype, $note); simple_update_field('bankstaparsed', 'state', '1', "WHERE `id`='" . $eachrow['id'] . "'"); // end of processing without linking } } log_register("BANKSTA PROCESSING " . $hash . " END"); } else { log_register("BANKSTA PROCESSING " . $hash . " EMPTY"); } }
/** * Performs available tasks processing * * @return void */ public function tasksProcessing() { global $billing; $curdate = curdate(); $rawUsers = zb_UserGetAllStargazerData(); $allUsers = array(); if (!empty($rawUsers)) { foreach ($rawUsers as $io => $each) { $allUsers[$each['login']] = $each; } } if (!empty($this->allTasks)) { foreach ($this->allTasks as $io => $each) { if ($each['date'] == $curdate) { if (isset($allUsers[$each['login']])) { $login = $each['login']; $param = $each['param']; switch ($each['action']) { case 'addcash': zb_CashAdd($login, $param, 'add', 1, 'SCHEDULED'); break; case 'corrcash': zb_CashAdd($login, $param, 'correct', 1, 'SCHEDULED'); break; case 'setcash': zb_CashAdd($login, $param, 'set', 1, 'SCHEDULED'); break; case 'credit': $billing->setcredit($login, $param); log_register('CHANGE Credit (' . $login . ') ON ' . $param); break; case 'creditexpire': $billing->setcreditexpire($login, $param); log_register('CHANGE CreditExpire (' . $login . ') ON ' . $param); break; case 'tariffchange': $billing->settariff($login, $param); log_register('CHANGE Tariff (' . $login . ') ON `' . $param . '`'); //optional user reset if ($this->altCfg['TARIFFCHGRESET']) { $billing->resetuser($login); log_register('RESET User (' . $login . ')'); } break; case 'tagadd': stg_add_user_tag($login, $param); break; case 'tagdel': stg_del_user_tagid($login, $param); break; case 'freeze': $billing->setpassive($login, 1); log_register('CHANGE Passive (' . $login . ') ON 1'); break; case 'unfreeze': $billing->setpassive($login, 0); log_register('CHANGE Passive (' . $login . ') ON 0'); break; case 'reset': $billing->resetuser($login); log_register('RESET User (' . $login . ')'); break; case 'setspeed': zb_UserDeleteSpeedOverride($login); zb_UserCreateSpeedOverride($login, $param); $billing->resetuser($login); log_register("RESET User (" . $login . ")"); break; case 'down': $billing->setdown($login, 1); log_register('CHANGE Down (' . $login . ') ON 1'); break; case 'undown': $billing->setdown($login, 0); log_register('CHANGE Down (' . $login . ') ON 0'); break; case 'ao': $billing->setao($login, 1); log_register('CHANGE AlwaysOnline (' . $login . ') ON 1'); break; case 'unao': $billing->setao($login, 0); log_register('CHANGE AlwaysOnline (' . $login . ') ON 0'); break; } //flush task from database $this->setTaskIsDone($each['id']); } else { log_register('SCHEDULER FAIL ID [' . $taskId . '] USER (' . $each['login'] . ') NON EXISTS'); $this->deleteTask($taskId); } } } } }
/** * Performs an punishment * * @param string $login */ protected function punish($login) { if (isset($this->capData[$login])) { $penalty = '-' . $this->penalty; zb_CashAdd($login, $penalty, 'add', $this->payId, 'PENALTY:' . $this->capData[$login]['days']); $this->debugLog("CAP PENALTY (" . $login . ") DAYS:" . $this->capData[$login]['days'] . " PENALTY:" . $this->penalty); } }
/** * Do the processing of discounts by the payments * * @param bool $debug */ function zb_DiscountProcessPayments($debug = false) { $alterconf = rcms_parse_ini_file(CONFIG_PATH . "alter.ini"); $cashtype = $alterconf['DISCOUNT_CASHTYPEID']; $operation = $alterconf['DISCOUNT_OPERATION']; if (isset($alterconf['DISCOUNT_PREVMONTH'])) { if ($alterconf['DISCOUNT_PREVMONTH']) { $targetMonth = prevmonth(); } else { $targetMonth = curmonth(); } } else { $targetMonth = curmonth(); } $alldiscountusers = zb_DiscountsGetAllUsers(); $monthpayments = zb_DiscountsGetMonthPayments($targetMonth); if (!empty($alldiscountusers) and !empty($monthpayments)) { foreach ($monthpayments as $login => $eachpayment) { //have this user discount? if (isset($alldiscountusers[$login])) { //yes it have $discount_percent = $alldiscountusers[$login]; $payment_summ = $eachpayment; $discount_payment = $payment_summ / 100 * $discount_percent; if ($operation == 'CORR') { zb_CashAdd($login, $discount_payment, 'correct', $cashtype, 'DISCOUNT:' . $discount_percent); } if ($operation == 'ADD') { zb_CashAdd($login, $discount_payment, 'add', $cashtype, 'DISCOUNT:' . $discount_percent); } if ($debug) { print 'USER:'******' SUMM:' . $payment_summ . ' DISCOUNT:' . $discount_percent . ' PAYMENT:' . $discount_payment . "\n"; log_register("DISCOUNT " . $operation . " (" . $login . ") ON " . $discount_payment); } } } } }
/** * Performs available active subscriptions fee processing * * @return string */ public function subscriptionFeeProcessing() { $result = ''; $megogoApi = new MegogoApi(); if (!empty($this->allSubscribers)) { foreach ($this->allSubscribers as $io => $each) { if (!$each['freeperiod']) { //active subscription - normal fee $tariffFee = $this->getTariffFee($each['tariffid']); if ($this->altCfg['MG_SPREAD']) { //possible spread fee charge $tariffFee = $this->getDaylyFee($tariffFee); } if ($each['active']) { $userBalance = $this->getUserBalance($each['login']); if ($userBalance >= 0) { if ($userBalance - $tariffFee >= 0) { zb_CashAdd($each['login'], '-' . $tariffFee, 'add', 1, 'MEGOGO:' . $each['tariffid']); log_register('MEGOGO FEE (' . $each['login'] . ') -' . $tariffFee); $result .= $each['login'] . ' FEE ' . $tariffFee . "\n"; } else { $this->deleteSubscribtion($each['login'], $each['tariffid']); $result .= $each['login'] . ' UNSUB [' . $each['tariffid'] . ']' . "\n"; } } else { $this->deleteSubscribtion($each['login'], $each['tariffid']); $result .= $each['login'] . ' UNSUB [' . $each['tariffid'] . ']' . "\n"; } } } else { if ($this->altCfg['MG_SPREAD']) { $freePeriodStart = strtotime($each['date']); //delete subscribtion if 30 days past if (time() > $freePeriodStart + 86400 * 30) { $this->deleteSubscribtion($each['login'], $each['tariffid']); log_register('MEGOGO (' . $each['login'] . ') FREE PERIOD EXPIRED'); $result .= $each['login'] . ' UNSUB [' . $each['tariffid'] . '] FREE' . "\n"; } } else { //finish free period at the start of new month $this->deleteSubscribtion($each['login'], $each['tariffid']); log_register('MEGOGO (' . $each['login'] . ') FREE PERIOD EXPIRED'); $result .= $each['login'] . ' UNSUB [' . $each['tariffid'] . '] FREE' . "\n"; } } } } return $result; }
$alter = $ubillingConfig->getAlter(); $login = vf($_GET['username']); // Change finance state if need: if (isset($_POST['newcash'])) { // Init $cash = $_POST['newcash']; $operation = vf($_POST['operation']); $cashtype = vf($_POST['cashtype']); $note = isset($_POST['newpaymentnote']) ? mysql_real_escape_string($_POST['newpaymentnote']) : ''; // Empty cash hotfix: if ($cash != '') { if (zb_checkMoney($cash)) { if (isset($alter['SIGNUP_PAYMENTS']) && !empty($alter['SIGNUP_PAYMENTS'])) { zb_CashAddWithSignup($login, $cash, $operation, $cashtype, $note); } else { zb_CashAdd($login, $cash, $operation, $cashtype, $note); } rcms_redirect("?module=addcash&username=" . $login); } else { show_window('', wf_modalOpened(__('Error'), __('Wrong format of a sum of money to pay'), '400', '200')); log_register('BALANCEADDFAIL (' . $login . ') WRONG SUMM `' . $cash . '`'); } } else { show_window('', wf_modalOpened(__('Error'), __('You have not completed the required amount of money to deposit into account. We hope next time you will be more attentive.'), '400', '150')); log_register('BALANCEADDFAIL (' . $login . ') EMPTY SUMM `' . $cash . '`'); } } // Profile: $profile = new UserProfile($login); show_window(__('User profile'), $profile->render()); $user_data = $profile->extractUserData();
/** * Performs friends yesterday payments processing * * @return void */ public function friendsDailyProcessing() { $this->loadDailyPayments(); if (!empty($this->rawPayments)) { foreach ($this->rawPayments as $paymentId => $eachPayment) { if (isset($this->allFriends[$eachPayment['login']])) { $friendLogin = $eachPayment['login']; $parentLogin = $this->allFriends[$eachPayment['login']]; $originalSum = $eachPayment['summ']; $percent = zb_Percent($originalSum, $this->percent); zb_CashAdd($parentLogin, $percent, 'add', $this->payid, 'FRIENDSHIP:' . $eachPayment['id']); } } } }
/** * Adds cash for user * * @param string $login * * @return void */ protected function pushDiscount($login) { if (isset($this->allUsers[$login])) { $discountData = $this->getDiscountData($login); if (!empty($discountData)) { $userTariff = $this->allUsers[$login]['Tariff']; if (isset($this->tariffPrices[$userTariff])) { $tariffPrice = $this->tariffPrices[$userTariff]; if ($tariffPrice != 0) { $discountPercent = $discountData['discount']; $discountPayment = $tariffPrice / 100 * $discountPercent; zb_CashAdd($login, $discountPayment, 'add', $this->discountPayId, 'DISCOUNT:' . $discountPercent); $this->debugLog('CUDISCOUNTS PUSH (' . $login . ') PERCENT:' . $discountPercent . ' DAYS:' . $discountData['days'] . ' CASH:' . $discountPayment . ' TARIFF:' . $userTariff); } else { $this->debugLog('CUDISCOUNTS IGNORE (' . $login . ') TARIFF ' . $userTariff . ' ZERO PRICE'); } } else { $this->debugLog('CUDISCOUNTS IGNORE (' . $login . ') TARIFF ' . $userTariff . ' NOT EXISTS'); } } else { $this->debugLog('CUDISCOUNTS IGNORE (' . $login . ') EMPTY DISCOUNT DATA'); } } else { $this->debugLog('CUDISCOUNTS IGNORE (' . $login . ') LOGIN NOT EXISTS'); } }
/** * Performs an virtual services payments processing * * @param int $debug * @param bool $log_payment * @param bool $charge_frozen * * @return void */ function zb_VservicesProcessAll($debug = 0, $log_payment = true, $charge_frozen = true) { $frozenUsers = array(); $query_services = "SELECT * from `vservices` ORDER by `priority` DESC"; if ($debug) { print ">>" . curdatetime() . "\n"; print ">>Searching virtual services\n"; print $query_services . "\n"; } $allservices = simple_queryall($query_services); if (!empty($allservices)) { if ($debug) { print ">>Virtual services found!\n"; print_r($allservices); } if ($charge_frozen) { if ($debug) { print '>>Charge fee from frozen users too' . "\n"; } } else { if ($debug) { print '>>Frozen users will be skipped' . "\n"; } $frozen_query = "SELECT `login` from `users` WHERE `Passive`='1';"; if ($debug) { print $frozen_query . "\n"; } $allFrozen = simple_queryall($frozen_query); if (!empty($allFrozen)) { foreach ($allFrozen as $ioFrozen => $eachFrozen) { $frozenUsers[$eachFrozen['login']] = $eachFrozen['login']; } if ($debug) { print_r($frozenUsers); } } } foreach ($allservices as $io => $eachservice) { $users_query = "SELECT `login` from `tags` WHERE `tagid`='" . $eachservice['tagid'] . "'"; if ($debug) { print ">>Searching users with this services\n"; print $users_query . "\n"; } $allusers = simple_queryall($users_query); if (!empty($allusers)) { if ($debug) { print ">>Users found!\n"; print_r($allusers); } foreach ($allusers as $io2 => $eachuser) { if ($debug) { print ">>Processing user:"******"\n"; } if ($debug) { print ">>service:" . $eachservice['id'] . "\n"; print ">>price:" . $eachservice['price'] . "\n"; print ">>processing cashtype:" . $eachservice['cashtype'] . "\n"; } if ($eachservice['cashtype'] == 'virtual') { if ($debug) { $current_cash = zb_VserviceCashGet($eachuser['login']); print ">>current cash:" . $current_cash . "\n"; } if ($debug != 2) { zb_VserviceCashFee($eachuser['login'], $eachservice['price'], $eachservice['id']); } } if ($eachservice['cashtype'] == 'stargazer') { if ($debug) { $current_cash = zb_UserGetStargazerData($eachuser['login']); $current_cash = $current_cash['Cash']; print ">>current cash:" . $current_cash . "\n"; } if ($debug != 2) { $fee = "-" . $eachservice['price']; if ($log_payment) { $method = 'add'; } else { $method = 'correct'; } if ($charge_frozen) { zb_CashAdd($eachuser['login'], $fee, $method, '1', 'Service:' . $eachservice['id']); } else { if (isset($frozenUsers[$eachuser['login']])) { if ($debug) { print '>>user frozen - skipping him' . "\n"; } } else { zb_CashAdd($eachuser['login'], $fee, $method, '1', 'Service:' . $eachservice['id']); } } } } } } } } }