/** * @param string $key * @param Api $api * @param Customer $customer * * @throws ApiException * @throws Exception */ public function update($key, $api, $customer) { $this->info('начинаем сбор информации о клиенте: ' . $customer->id . ' [' . $customer->agbis_id . ']'); Reporter::aggregateExternalInfoStart($key, $customer->agbis_id, $customer->id); $client = $api->ContrInfo($key); $this->line('... общая информация'); $client['key'] = $key; try { $promo = $api->PromoCodeUse($key); $this->line('... промокод'); } catch (ApiException $e) { if ($e->isDataError()) { $promo = null; } else { throw $e; } } $client['promo'] = $promo; $client['bonus'] = $api->Bonus($key)['bonus']; $this->line('... бонус'); $client['deposit'] = $api->Deposit($key)['deposit']; $this->line('... депозитный счет'); $client['orders'] = $api->Orders($key)['orders']; $this->line('... заказы'); $client['history'] = $api->OrdersHistory($key)['orders']; $this->line('... история заказов'); $client['tokens'] = $api->TokenPayList($key)['tokens']; $this->line('... токены платежей'); Reporter::aggregateExternalInfoEnd($customer->id); $component = \Dryharder\Components\Customer::instance()->initByExternalId($client['id']); $this->line('... обновляем информацию в нашей базе данных'); $component->updateExternalInfo($client); $this->info('закончили работу с клиентом'); }
/** * 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 orders($cid) { $customer = Customer::instance()->initByExternalId($cid); $api = new Api(); $password = $customer->get()->credential->agbis_password; if (!$password) { $this->log('Customer password is not exists', ['customer_id' => $cid]); return Response::json('Customer password is not exists', 500); } $key = 'users.agbis.sessions.customer' . $cid; $sessionId = Cache::get($key); if ($sessionId) { $this->log('session found', ['customer' => $customer->get()->id, 'session' => $sessionId]); } if (!$sessionId) { $sessionId = $this->initSessionKey($customer, $password, $key); } try { $orders = $api->Orders($sessionId); } catch (ApiException $e) { $this->log('session inactive, try new session'); $sessionId = $this->initSessionKey($customer, $password, $key); $orders = $api->Orders($sessionId); } foreach ($orders['orders'] as &$order) { $order['status_name'] = Order::statusName($order['status']); $order['autopay'] = $order['status'] >= 1 && $order['amount'] > 0; $lastPay = OrderAutopay::getLastPay($cid, $order['id']); $order['order_autopay'] = $lastPay['lastPay']; $order['payTotal'] = $lastPay['total']; } $orders = array_reverse($orders['orders']); return $orders; }
/** * данные для оплаты через CloudPayments * * @param string $target * @param string $id * @param boolean $reset * * @return \Illuminate\Http\JsonResponse */ public function pay($id, $target, $reset) { $id = $this->parsePayTarget($target, $id); try { $api = new Api(); $orders = $api->Orders()['orders']; } catch (ApiException $e) { return $this->responseException($e); } Reporter::payInit($id, $api->id()); $order = null; foreach ($orders as $item) { if ($item['id'] == $id) { $order = $item; } } // нет такого заказа if (!$order) { Reporter::payInitOrderLost($id, $api->id()); return $this->responseErrorMessage('заказ не найден', 404); } // проверим, что заказ не находится в процессинге оплаты $check = $this->isOrderPayWaiting($id); if ($check !== true) { // флаг $reset требует сброса состояния оплаты заказа // поэтому мы делаем ему fail чтобы можно было приступить к новой оплате if ($reset) { Reporter::payInitOrderReset($id, $api->id()); PaymentCloud::failOrder($id); } else { return $check; } } // проверим, что есть сумма к оплате if ($order['amount'] <= 0) { return $this->responseErrorMessage('Заказ уже оплачен', 403); } $api->id(); $data = ['publicId' => Config::get('cloud.PublicId'), 'description' => 'Оплата в dryharder.me заказа №' . $order['doc_number'], 'amount' => $order['amount'], 'currency' => 'RUB', 'invoiceId' => $order['id'], 'accountId' => $api->id(), 'data' => ['type' => 'pay_order', 'contr_id' => $api->id(), 'order_id' => $order['id'], 'order_num' => $order['doc_number'], 'amount' => $order['amount']]]; Reporter::payInitReady($id, $api->id(), $data); return Response::json(['data' => $data, 'message' => 'данные для оплаты заказа']); }