Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace GeoMonitoring\Base\Providers\Billing;
- use GeoMonitoring\Base\Adapters\CurlAdapter;
- use Exception;
- use GeoMonitoring\Base\Exceptions\CustomerFailAuthException;
- use GuzzleHttp\Exception\ClientException;
- use GuzzleHttp\Exception\GuzzleException;
- use Illuminate\Support\Facades\Log;
- class CustomerProvider extends BillingBaseProvider
- {
- private $authUri = 'customer/auth/login';
- private $message = null;
- /**
- * @var CurlAdapter
- */
- private $curlAdapter;
- public function __construct(CurlAdapter $curlAdapter)
- {
- $this->curlAdapter = $curlAdapter;
- }
- /**
- * @param string $email
- * @param string $password
- * @return mixed
- * @throws CustomerFailAuthException
- */
- public function authorise(string $email, string $password): array
- {
- $url = $this->makeUrl($this->authUri);
- try {
- $response = $this->curlAdapter->acceptJson()->setHeader('Accept-Language', app()->getLocale())->post($url, ['email' => $email, 'password' => $password]);
- return json_decode((string) $response->getBody(), true);
- } catch (ClientException $exception) {
- /**
- * TODO: Логировать ошибку запроса.
- * $exception->getRequest()
- * $exception->getResponse()
- */
- if ($exception->getResponse()->getStatusCode() == 403) {
- throw new CustomerFailAuthException($exception->getResponse()->getBody());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement