示例#1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     try {
         $api = new Api();
         $customers = Customer::all();
         foreach ($customers as $customer) {
             $customerId = $customer->agbis_id;
             $card = PaymentCloud::getCustomerAutopayCard($customerId);
             if ($card) {
                 $phone = '+7' . $customer->phone;
                 $password = $customer->credential->agbis_password;
                 $user = $api->Login_con($phone, $password);
                 $key = $user->key;
                 $orders = $api->Orders($key)['orders'];
                 foreach ($orders as $order) {
                     if ($this->isNotPaidOrder($customerId, $order['id'])) {
                         if ($api->IsGoodOrder($order['id'], $customerId)) {
                             $api->payByToken($order['id'], $card->token, $order['amount'], $order['doc_number'], $key);
                         }
                     }
                 }
             }
         }
     } catch (ApiException $e) {
     }
 }
示例#2
0
 public function autopayAll()
 {
     $result = [];
     $errors = [];
     if (Input::has('customers')) {
         $api = new Api();
         $customers = Input::get('customers');
         foreach ($customers as $customerId) {
             $customer = Customer::instance()->initByExternalId($customerId);
             if ($customer) {
                 $card = PaymentCloud::getCustomerAutopayCard($customerId);
                 if ($card) {
                     $phone = '+7' . $customer->get()->phone;
                     $password = $customer->get()->credential->agbis_password;
                     $user = $api->Login_con($phone, $password);
                     $key = $user->key;
                     $orders = $api->Orders($key)['orders'];
                     foreach ($orders as $order) {
                         if ($this->isNotPaidOrder($customerId, $order['id'])) {
                             if ($api->IsGoodOrder($order['id'], $customerId)) {
                                 if ($this->isNotPaidOrder($customerId, $order['id'])) {
                                     OrderAutopay::unguard();
                                     $pay = OrderAutopay::create(['order_id' => $order['id'], 'customer_id' => $customerId, 'state' => 0]);
                                     $payResult = $api->payByToken($order['id'], $card->token, $order['amount'], $order['doc_number'], $key);
                                     $pay->comment = $payResult->message;
                                     $pay->save();
                                     if ($payResult->success) {
                                         $pay->state = 1;
                                         $pay->save();
                                         Mailer::succesAutoPay($customer, $order, $card);
                                     } else {
                                         $errors[] = ['customer' => $customer->get(), 'order' => $order, 'message' => $payResult->message];
                                         Mailer::errorAutoPay($customer, $order, $card);
                                     }
                                 }
                             }
                         }
                     }
                 }
                 $data = ['phone' => $customer->get()->phone, 'agbisId' => $customerId, 'agbisPassword' => $customer->get()->credential->agbis_password];
                 $this->checkPaidOrders($data);
                 $result[] = ['customerId' => $customerId, 'isGoodOrder' => $this->orderInfo['totalOrder'] > 0 ? true : false];
             }
         }
     }
     return Response::json(['result' => $result, 'errors' => $errors], 200);
 }
示例#3
0
 /**
  * проверяет, что заказ присутствует в системе Агбис
  */
 private function checkOrder()
 {
     $params = $this->parameters();
     try {
         $api = new Api();
         $api->IsGoodOrder((int) $params['order_id'], (int) $params['customer_id']);
         Reporter::payOrderFound($params['customer_id'], $params['order_id']);
     } catch (ApiException $e) {
         Reporter::payOrderLost($params['customer_id'], $params['order_id']);
         if ($e->getCode() == 400) {
             return $this->responseError('Ошибка оплаты заказа', 200);
         }
         return $this->responseError('Ошибка оплаты заказа', 200);
     }
     return true;
 }
示例#4
0
 public function token()
 {
     if (!Input::has('payment_id')) {
         return Response::json(['errors' => [], 'message' => trans('pay.prepayment.search_card_error')]);
     }
     $paymentId = Input::get('payment_id');
     $target = Input::get('target');
     $order_id = $this->parsePayTarget($target, Input::get('id'));
     // проверим id
     $order_id = (int) $order_id;
     if ($order_id <= 0) {
         return $this->responseErrorMessage('Отсутствует id заказа', 400);
     }
     // проверим существование заказа у данного клиента
     $api = new Api();
     $order = $api->getOrder($order_id);
     if (!$order) {
         if ($target == 'subscription') {
             return $this->responseErrorMessage('Вероятно, эта подписка уже была оплачена', 404);
         }
         return $this->responseErrorMessage('Заказ не найден', 404);
     }
     // проверим, что заказ не находится в процессинге оплаты
     $check = $this->isOrderPayWaiting($order_id);
     if ($check !== true) {
         return $check;
     }
     // проверим, что заказ можно оплатить в api
     try {
         $api->IsGoodOrder($order_id, $api->id());
     } catch (ApiException $e) {
         return $this->responseErrorMessage('Оплата заказа не доступна', 403);
     }
     $token = PaymentCloud::getToken($api->id(), $paymentId);
     if ($token) {
         $result = $api->payByToken($order_id, $token->token, $order['amount'], $order['doc_number']);
         if (!$result->success) {
             return $this->responseErrorMessage($result->message, 200);
         }
         return Response::json(['data' => '', 'message' => $result->message]);
     }
     return Response::json(['errors' => [], 'message' => 'Ошибка! Карта не найдена!']);
 }
示例#5
0
 /**
  * проверяет, что заказ присутствует в системе Агбис
  */
 private function checkOrder()
 {
     if ($this->params['order_id'] > '') {
         try {
             $api = new Api();
             $api->IsGoodOrder($this->params['order_id'], $this->params['customer_id']);
             Reporter::payOrderFound($this->params['customer_id'], $this->params['order_id']);
         } catch (ApiException $e) {
             Reporter::payOrderLost($this->params['customer_id'], $this->params['order_id']);
             if ($e->getCode() == 400) {
                 $this->responseError(10);
             }
             $this->responseError(13);
         }
     }
 }