/** * 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); }