/**
 * Покупка ПРО через ЛС
 * 
 * @param type $opcode
 * @param type $redirect
 * @return \xajaxResponse
 */
function quickPROPayAccount($opcode, $redirect, $promo_code)
{
    $objResponse = new xajaxResponse();
    $pro = 0;
    require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/payed.php";
    $proList = payed::getAvailablePayedList(is_emp());
    foreach ($proList as $proItem) {
        if ($proItem['opcode'] == $opcode) {
            $pro = $proItem;
            break;
        }
    }
    if ($pro) {
        $uid = get_uid(false);
        $bill = new billing($uid);
        //Допустимо использование промокодов
        $bill->setPromoCodes('SERVICE_PRO', $promo_code);
        $billReserveId = $bill->addServiceAndCheckout($opcode);
        $payed_sum = $bill->getOrderPayedSum();
        if ($bill->isAllowPayFromAccount()) {
            $complete = $bill->buyOrder($billReserveId);
            if ($complete) {
                $_SESSION['quickbuypro_success_opcode'] = $payed_sum;
                $uri = '?quickpro_ok=1';
                if ($opcode == 164) {
                    $uri = '/profi/?quickprofi_ok=1';
                }
                $objResponse->script("window.location = '{$uri}';");
            }
        }
    }
    return $objResponse;
}
Beispiel #2
0
function quickPRJPayAccount()
{
    $objResponse = new xajaxResponse();
    $uid = get_uid(false);
    ob_start();
    require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/billing.php';
    require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/payed.php';
    $bill = new billing($uid);
    $billReserveId = $bill->checkoutOrder();
    $payed_sum = $bill->getOrderPayedSum();
    if ($bill->isAllowPayFromAccount()) {
        $complete = $bill->buyOrder($billReserveId);
        if ($complete) {
            $_SESSION['quickprj_ok'] = 1;
            $memBuff = new memBuff();
            $project_id = $memBuff->get('bill_ok_project_' . $uid);
            if ($project_id) {
                $is_payed = $memBuff->get('bill_ok_project_payed_' . $uid);
                if ($is_payed) {
                    $memBuff->delete('bill_ok_project_payed_' . $uid);
                    $friendly_url = "/public/?step=2&public={$project_id}";
                } else {
                    $friendly_url = getFriendlyURL('project', $project_id);
                    $_SESSION['quickprj_ok'] = 1;
                    $friendly_url .= '?quickprj_ok=1';
                }
                $objResponse->script("window.location = '{$friendly_url}';");
                $memBuff->delete('bill_ok_project_' . $uid);
            } else {
                $objResponse->script("window.location = '/?quickprj_ok=1';");
            }
        }
    }
    ob_end_clean();
    return $objResponse;
}
Beispiel #3
0
$customerNumber = 120824;
//$_GET['cn'];
$ammount = 569;
//$_GET['ammount'];
$invoiceId = 2000246796791.0;
//$_GET['invoiceId'];
$payments = 3;
$orderId = 367369;
$params['invoiceId'] = $invoiceId;
/*
3 => self::PAYMENT_YD,
6 => self::PAYMENT_AC,
10 => self::PAYMENT_WM,
16 => self::PAYMENT_AB,
17 => self::PAYMENT_SB
*/
$descr = "Платеж через Яндекс.Кассу. Сумма - {$ammount}, номер покупки - {$invoiceId}";
//------------------------------------------------------------------------------
//Заносим деньги на ЛС
$account = new account();
$error = $account->deposit($op_id, $customerNumber, $ammount, $descr, $payments, $ammount, 12);
if (!$error) {
    //Пробуем купить заказ за который занесли деньги выше
    if ($orderId > 0) {
        $billing = new billing($account->uid);
        $billing->buyOrder($orderId, 12, $params);
    }
    exit;
}
echo $error;
exit;
Beispiel #4
0
 /**
  * Выполняет платеж
  */
 private function addOperation()
 {
     global $DB;
     $DB->error_output = false;
     $shopParams = $this->getShopParams();
     $payment = $DB->row('
         SELECT 
             aoy.id,            
             aoy.descr,
             ao.id AS acc_op_id 
         FROM account_operations_yd AS aoy 
         LEFT JOIN account_operations AS ao ON ao.id = aoy.acc_op_id AND ao.billing_id = aoy.billing_id
         WHERE invoice_id = ?', $this->params['invoiceId']);
     //Пополнение и покупка уже были отвечаем успехом
     if ($payment['acc_op_id'] > 0) {
         return 0;
     }
     $DB->start();
     $op_id = 0;
     $data = array();
     $billing = null;
     $account = new account();
     //Заносим деньги на ЛС
     $error = $account->deposit($op_id, $this->params['customerNumber'], $shopParams['ammount'], $payment['descr'], array_search($this->params['paymentType'], $this->payments), $this->params['orderSumAmount'], $shopParams['op_code']);
     //Если все без ошибок и ЛС зачислены то пробуем купить заказ
     if (!$error && $op_id > 0) {
         $success = true;
         $data['acc_op_id'] = $op_id;
         //Пробуем купить заказ за который занесли деньги выше
         //Если заказ уже куплен или отменен то ничего не делаем но получим успех
         if ($this->params['orderId']) {
             $billing = new billing($account->uid);
             if ($success = $billing->buyOrder($this->params['orderId'], $shopParams['op_code'], $this->params)) {
                 $data['bill_reserve_id'] = $this->params['orderId'];
             }
         }
         //Фиксируем ID операции пополнения ЛС и ID купленного заказа при наличии
         if ($success) {
             $DB->update('account_operations_yd', $data, 'id = ?i', $payment['id']);
             $DB->commit();
             return 0;
         } else {
             $this->message = sprintf('Failed to purchase order #%s', $this->params['orderId']);
         }
     } else {
         $this->message = 'Failed deposit to account';
     }
     //Не удалось приобрести заказ откатываем транзакцию
     //и возвращаем ошибку что приводит к возврату средств
     $DB->rollback();
     //Если отказ принять деньги то и отменяем заказ
     //чтобы не висел в истории
     if ($billing && $this->params['orderId'] > 0) {
         $billing->cancelReserveById($this->params['orderId']);
     }
     //Ошибка, возврат средств
     return 100;
 }
 public function actionIndex()
 {
     $limit = 20;
     $do = __paramInit('string', 'do', 'do', '');
     $page = __paramInit('int', 'page', 'page', 1);
     $filter = array();
     $filter_default = array('date' => date('d.m.Y', strtotime('-1 month')) . ' - ' . date('d.m.Y'));
     switch ($do) {
         case 'factura_delete':
             $nums = __paramInit('array', NULL, 'num', null);
             $this->billInvoicesAdminModel->deleteFactura($nums);
             break;
         case 'factura_update':
             $invoice_id = __paramInit('int', NULL, 'invoice_id', null);
             $file = $_FILES['new_file'];
             $this->billInvoicesAdminModel->updateFactura($invoice_id, $file);
             break;
         case 'factura':
             $nums = __paramInit('array', NULL, 'num', null);
             $dates = __paramInit('array', NULL, 'date', null);
             $this->billInvoicesAdminModel->addFactura($nums, $dates);
             break;
         case 'filter':
             $filter['do'] = $do;
             $filter['login'] = __paramInit('string', 'login', 'login', '');
             $filter['date'] = __paramInit('string', 'date', 'date', null);
             break;
             //Операция зачисления средств по счету
         //Операция зачисления средств по счету
         case 'pay':
             require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/users.php';
             require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/account.php';
             require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/billing.php';
             $sums = __paramInit('array', NULL, 'sum', null);
             //@todo: слишком толстый контроллер
             //все ниже нужно было определить в модель
             $account = new account();
             $user = new users();
             if ($sums) {
                 $sAdmin = 'Запись добавил: ' . @$_SESSION['login'];
                 $sDate = date('c');
                 foreach ($sums as $user_id => $invoices) {
                     $user->GetUserByUID($user_id);
                     if (!$user->uid || !$account->GetInfo($user->uid, true) || empty($invoices)) {
                         continue;
                     }
                     $bill = new billing($user->uid);
                     foreach ($invoices as $invoice_id => $sum) {
                         $account_sum = $account->sum;
                         if (!is_numeric($sum) || $sum <= 0 || $account->sum + $sum < 0) {
                             continue;
                         }
                         $comments = sprintf("Безналичный перевод по счету Б-%06d", $invoice_id);
                         if (!$account->depositEx2($acc_op_id, $account->id, $sum, $sAdmin, $comments, 12, $sum, 4, $sDate)) {
                             $this->billInvoicesAdminModel->update($invoice_id, array('acc_op_id' => $acc_op_id));
                             //Автоматическая покупка услуги погашения задолженности
                             if ($account_sum < 0) {
                                 $payed_sum = abs($account_sum);
                                 $option = array('acc_sum' => $payed_sum);
                                 $billReserveId = $bill->addServiceAndCheckout(135, $option);
                                 if ($billReserveId) {
                                     $bill->buyOrder($billReserveId);
                                 }
                             }
                         }
                     }
                 }
                 $this->redirect('.');
             }
             break;
     }
     $this->billInvoicesAdminModel->setPage($limit, $page);
     $list = $this->billInvoicesAdminModel->setFilter($filter)->getInvoices();
     $count = $this->billInvoicesAdminModel->getInvoicesCnt();
     $filter_query = '';
     if (empty($filter)) {
         $filter = $filter_default;
     } else {
         $filter_query = http_build_query($filter) . '&';
     }
     $this->render('index', array('list' => $list, 'limit' => $limit, 'page' => $page, 'page_count' => $count, 'filter_query' => $filter_query, 'filter' => $filter));
 }
Beispiel #6
0
 /**
  * Выполняет покупку.
  */
 public function order()
 {
     //Запрещаем вывод ошибок
     $this->db()->error_output = false;
     $orderid = $_GET['orderid'];
     if (!$orderid) {
         exit;
     }
     $json_data = array('status' => '0', 'time' => time());
     $payment = $this->getPayment($orderid);
     if ($payment) {
         $data = isset($_REQUEST['data']) && is_array($_REQUEST['data']) ? $_REQUEST['data'] : array();
         $sig = $this->getSig($payment['price'], $orderid, $payment['billing_id'], $data);
         if ($sig == $_GET['sig']) {
             $json_data['status'] = '1';
             $op_id = 0;
             //Занесли деньги
             $account = new account();
             $error = $account->deposit($op_id, $payment['billing_id'], $payment['price'], "Платеж через \"Плати потом\". Сумма - {$payment['price']}, номер покупки - {$orderid}", self::PAYMENT_CODE, $payment['price']);
             if (!$error) {
                 //Пробуем купить
                 $billing = new billing($account->uid);
                 $billing->buyOrder($payment['bill_reserve_id'], 12, array());
                 $this->db()->query("DELETE FROM {$this->TABLE} WHERE id = ?", $orderid);
                 $memBuff = new memBuff();
                 $memBuff->delete('platipotom_max_price_' . $account->uid);
             }
         }
     }
     return $json_data;
 }