Wallet > Pay * @copyright Tamaranga */ class PayBlock extends Block { public function init() { parent::init(); $this->setTitle(_t('bills', 'Top Up')); $this->setKey('account.wallet.pay'); $this->setTemplate('account/pay.block', 'bills'); } public function data() { $data = parent::data(); $data['psystems'] = $this->payWaysList(); $data['currency'] = Currency::default(); return $data; } public function payWaysList(&$active = 0) { $list = Bills::getPayWaysList(false); if (! $active || !array_key_exists($active, $list)) { $active = key($list); } foreach ($list as $key => &$v) { $v['active'] = ($key == $active); } unset($v); return $list; } public function onBillsWalletPayAction() { $userId = $this->request->userId(); $userBalance = $this->request->user()->balance(); $amount = round($this->input->getpost('amount', TYPE_UNUM), 2); $ps = $this->input->getpost('ps', TYPE_STR); $payWaysList = $this->payWaysList($ps); do { if (! $userId || ! $this->isRequestValid()) { $this->errors->reloadPage(); break; } if ($amount <= 0) { $this->errors->set(_t('svc', 'Top Up amount is incorrect'), 'amount'); break; } $minimum = $this->config('bills.wallet.topup.minimum', 0, TYPE_UNUM); if ($minimum > 0 && $amount < $minimum) { $this->errors->set(_t('bills', 'Top Up amount should be [minimum] or more', [ 'minimum' => Currency::formatPriceAndCurrency($minimum), ]), 'amount'); break; } $svcSettings = []; $psKey = $payWaysList[$ps]['key']; $psWay = $payWaysList[$ps]['way']; # конвертируем сумму в валюту для оплаты по курсу $pay = Bills::getPayAmount($amount, $ps); $this->app->hook('bills.pay.submit', $amount, $ps, $pay, [ 'ps' => &$ps, 'pay' => &$pay, 'userID' => $userId, 'userBalance' => $userBalance, 'svcSettings' => &$svcSettings ]); # создаем счет: "Пополнение счета" $billId = Bills::createBill_InPay( $userId, $userBalance, $amount, # сумма в валюте сайте $pay['amount'], # сумма к оплате $pay['currency'], # валюта суммы к оплате Bills::STATUS_WAITING, $psKey, $psWay, _t('bills', 'Balance Top Up via [payway]', [ 'payway' => $payWaysList[$ps]['title'], ]), 0, false, 0, $svcSettings ); if (! $billId) { $this->errors->set(_t('svc', 'Top Up error, contact the administration')); break; } # формируем форму запроса для системы оплаты $this->respond('form', Bills::buildPayRequestForm($psKey, $psWay, $billId, $pay['amount'])); } while (false); return $this->getActionResponse([ 'amount' => $amount, ]); } }