Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.57 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. namespace GeoMonitoring\Base\Providers\Billing;
  5.  
  6. use GeoMonitoring\Base\Adapters\CurlAdapter;
  7. use Exception;
  8. use GeoMonitoring\Base\Exceptions\CustomerFailAuthException;
  9. use GuzzleHttp\Exception\ClientException;
  10. use GuzzleHttp\Exception\GuzzleException;
  11. use Illuminate\Support\Facades\Log;
  12.  
  13. class CustomerProvider extends BillingBaseProvider
  14. {
  15.  
  16.     private $authUri = 'customer/auth/login';
  17.     private $message = null;
  18.     /**
  19.      * @var CurlAdapter
  20.      */
  21.     private $curlAdapter;
  22.  
  23.     public function __construct(CurlAdapter $curlAdapter)
  24.     {
  25.         $this->curlAdapter = $curlAdapter;
  26.     }
  27.  
  28.     /**
  29.      * @param string $email
  30.      * @param string $password
  31.      * @return mixed
  32.      * @throws CustomerFailAuthException
  33.      */
  34.     public function authorise(string $email, string $password): array
  35.     {
  36.         $url = $this->makeUrl($this->authUri);
  37.  
  38.         try {
  39.  
  40.             $response =  $this->curlAdapter->acceptJson()->setHeader('Accept-Language', app()->getLocale())->post($url, ['email' => $email, 'password' => $password]);
  41.             return json_decode((string) $response->getBody(), true);
  42.         } catch (ClientException $exception) {
  43.  
  44.             /**
  45.              * TODO: Логировать ошибку запроса.
  46.              * $exception->getRequest()
  47.              * $exception->getResponse()
  48.              */
  49.  
  50.             if ($exception->getResponse()->getStatusCode() == 403) {
  51.                 throw new CustomerFailAuthException($exception->getResponse()->getBody());
  52.             }
  53.         }
  54.  
  55.  
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement