Esempio n. 1
0
 public function getResult()
 {
     $request = $_GET;
     if (empty($request['method']) || empty($request['params']) || !is_array($request['params'])) {
         return $this->getResponseError('Invalid request');
     }
     $method = $request['method'];
     $params = $request['params'];
     if ($params['sign'] != $this->getMd5Sign($params, Config::SECRET_KEY)) {
         return $this->getResponseError('Incorrect digital signature');
     }
     $unitPayModel = UnitPayModel::getInstance();
     if ($method == 'check') {
         if ($unitPayModel->getPaymentByUnitpayId($params['unitpayId'])) {
             // Платеж уже существует
             return $this->getResponseSuccess('Payment already exists');
         }
         $itemsCount = floor($params['sum'] / Config::ITEM_PRICE);
         if ($itemsCount <= 0) {
             return $this->getResponseError('Суммы ' . $params['sum'] . ' руб. не достаточно для оплаты товара ' . 'стоимостью ' . Config::ITEM_PRICE . ' руб.');
         }
         if (!$unitPayModel->createPayment($params['unitpayId'], $params['account'], $params['sum'], $itemsCount)) {
             return $this->getResponseError('Unable to create payment database');
         }
         $checkResult = $this->event->check($params);
         if ($checkResult !== true) {
             return $this->getResponseError($checkResult);
         }
         return $this->getResponseSuccess('CHECK is successful');
     }
     if ($method == 'pay') {
         $payment = $unitPayModel->getPaymentByUnitpayId($params['unitpayId']);
         if ($payment && $payment->status == 1) {
             return $this->getResponseSuccess('Payment has already been paid');
         }
         if (!$unitPayModel->confirmPaymentByUnitpayId($params['unitpayId'])) {
             return $this->getResponseError('Unable to confirm payment database');
         }
         $this->event->pay($params);
         return $this->getResponseSuccess('PAY is successful');
     }
     return $this->getResponseError($method . ' not supported');
 }
Esempio n. 2
0
 public function pay($params)
 {
     $unitPayModel = UnitPayModel::getInstance();
     $countItems = floor($params['sum'] / Config::ITEM_PRICE);
     $unitPayModel->donateForAccount($params['account'], $countItems);
 }
Esempio n. 3
0
 public function pay($params)
 {
     $unitPayModel = UnitPayModel::getInstance();
     $unitPayModel->donateForAccount($params['account'], $params['sum']);
 }