/** * 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) { } }
public function start($order_id, $customer_id) { if (!$this->isNotPaidOrder($customer_id, $order_id)) { return Response::json(['message' => 'Заказ находится в процессе оплаты'], 500); } $customer = Customer::instance()->initByExternalId($customer_id); if (!$customer) { return Response::json(['message' => 'Клиент не найден'], 500); } $autopayCard = PaymentCloud::getCustomerAutopayCard($customer_id); if (!$autopayCard) { return Response::json(['message' => 'Автоплатежи клиента выключены'], 500); } $key = 'users.agbis.sessions.customer' . $customer_id; $sessionId = $this->initSessionKey($customer, $customer->get()->credential->agbis_password, $key); if (!$sessionId) { return Response::json(['message' => 'Сессия клиента не найдена'], 500); } $api = new Api(); $order = $api->getOrder($order_id, $sessionId); if (!$order) { return Response::json(['message' => 'Заказ клиента не найден'], 500); } if ($autopayCard->token == '') { return Response::json(['message' => 'Токен привязанной карты не найден'], 500); } OrderAutopay::unguard(); $pay = OrderAutopay::create(['order_id' => $order_id, 'customer_id' => $customer_id, 'state' => 0]); $result = $api->payByToken($order_id, $autopayCard->token, $order['amount'], $order['doc_number'], $sessionId); $pay->comment = $result->message; $pay->save(); if ($result->success) { $pay->state = 1; $pay->save(); Mailer::succesAutoPay($customer, $order, $autopayCard); return Response::json(['amount' => $order['amount']]); } Mailer::errorAutoPay($customer, $order, $autopayCard); return Response::json(['message' => $result->message], 500); }
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' => 'Ошибка! Карта не найдена!']); }