Esempio n. 1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     ob_start();
     $txn = $data = [];
     //$payment = Payment::select('txn')->where('proc', false)->get();
     foreach (Payment::select(['sum', 'txn'])->where('proc', false)->get() as $payment) {
         $txn[$payment->txn] = ['txn' => $payment->txn, 'sum' => $payment->sum];
     }
     foreach ($txn as $tx) {
         $data[] = $this->getPay($tx);
     }
     //var_dump($txn);
     //var_dump($this->curl('https://ya.ru/'));
     //var_dump($this->getPay());
     Payment::select()->whereIn('txn', $data)->update(['proc' => true]);
     //var_dump($data);
     //var_dump($this->curl('http://laravel.tur8.ru/hermes'));
     $ob = ob_get_clean();
     $this->comment($ob);
 }
 public function postIn(\Request $request)
 {
     $post = $request::all();
     //dd($post);
     $method = null;
     $params = null;
     $variables = $errors = array();
     $transaction = null;
     $method = $post['method'];
     $params = $post['params'];
     $pointId = $post['point'];
     if (!$method) {
         $errors[] = "POST variable [method] undefined";
     }
     if (!$params) {
         $errors[] = "POST variable [params] undefined";
     }
     if (!$pointId) {
         $errors[] = "POST variable [point] undefined";
     }
     if (count($errors) > 0) {
         $variables['result'] = "error";
         $variables['transaction'] = null;
         $variables['message'] = array("message" => implode(", ", $errors));
     } else {
         $variables['result'] = "200";
         $variables['message'] = array("message" => "method=" . $method . ", params=" . $params);
         $json = json_decode($params, 1);
         $entity = [];
         $number = uniqid();
         $variables['transaction'] = $number;
         if ($method == 'payment') {
             $old = \Modules\Hermes\Models\Payment::select()->where(['txn' => $json['txn']])->get();
             if (count($old) === 0) {
                 $payment = ['number' => $number, 'userId' => 0, 'created' => Carbon::now('Europe/Moscow'), 'pointId' => $pointId, 'type' => $json['type'], 'txn' => $json['txn'], 'date' => $json['date'], 'sum' => $json['sum'], 'order' => $json['order']];
                 //dd($payment);
                 $variables['id'] = \Modules\Hermes\Models\Payment::insertGetId($payment);
             } else {
                 $variables['id'] = 0;
             }
             //dd(\Modules\Hermes\Models\Payment::select()->get($variables['id']));
         } elseif ($method == 'incass') {
             $json['previousDate'] = isset($json['previousDate']) ? $json['previousDate'] : null;
             $incass = ['number' => $number, 'userId' => 0, 'created' => Carbon::now('Europe/Moscow'), 'pointId' => $pointId, 'currentDate' => $json['currentDate'], 'previousDate' => $json['previousDate'], 'sum' => $json['sum'], 'banknotes' => $json['banknotes']];
             unset($json['currentDate'], $json['previousDate'], $json['sum'], $json['banknotes']);
             $incass['variables'] = json_encode($json);
             $variables['id'] = \Modules\Hermes\Models\Incass::insertGetId($incass);
         } elseif ($method == 'state') {
             $state = ['number' => $number, 'state' => $json['state'], 'userId' => 0, 'created' => Carbon::now('Europe/Moscow'), 'pointId' => $pointId, 'banknotes' => $json['banknotes']];
             unset($json['state'], $json['banknotes']);
             $state['variables'] = json_encode($json);
             $variables['id'] = \Modules\Hermes\Models\State::insertGetId($state);
         } else {
             $old = Entity::select()->where(['method' => 'payment', 'param' => 'txn', 'value' => $json['txn']])->get();
             if (count($old) === 0) {
                 $json['process'] = 'process';
                 foreach ($json as $k => $v) {
                     $entity[] = ['method' => $method, 'userId' => 0, 'created' => Carbon::now('Europe/Moscow'), 'param' => $k, 'value' => $method == 'test' && $k == 'type' ? 'test' : $v, 'number' => $number, 'pointId' => $pointId];
                 }
                 $variables['result'] = Entity::insert($entity) ? '200' : 'error';
             }
             $variables['id'] = Entity::lastId();
         }
     }
     return response()->json($variables);
 }
 public function getPayment(\Request $request)
 {
     $id = $request::get('id');
     $sum = $request::get('sum');
     $num = $request::get('num');
     $data['id'] = $id == "" ? null : $id;
     $data['sum'] = $sum == "" ? null : $sum;
     $data['num'] = $num == "" ? null : $num;
     $data['date'] = $request::get('date');
     if (!isset($data['date'])) {
         $data['date']['start'] = date("Y-m-d");
         $data['date']['end'] = date("Y-m-d");
     }
     $states = Payment::log($data);
     return view('hermes::payment', ['state' => $states, 'data' => $data]);
 }