Open Journal Systems  3.3.0
lib/vendor/omnipay/paypal/src/Message/RestTokenRequest.php
1 <?php
6 namespace Omnipay\PayPal\Message;
7 
20 {
21  public function getData()
22  {
23  return array('grant_type' => 'client_credentials');
24  }
25 
26  protected function getEndpoint()
27  {
28  return parent::getEndpoint() . '/oauth2/token';
29  }
30 
31  public function sendData($data)
32  {
33  // don't throw exceptions for 4xx errors
34  $this->httpClient->getEventDispatcher()->addListener(
35  'request.error',
36  function ($event) {
37  if ($event['response']->isClientError()) {
38  $event->stopPropagation();
39  }
40  }
41  );
42 
43  $httpRequest = $this->httpClient->createRequest(
44  $this->getHttpMethod(),
45  $this->getEndpoint(),
46  array('Accept' => 'application/json'),
47  $data
48  );
49 
50  $httpResponse = $httpRequest->setAuth($this->getClientId(), $this->getSecret())->send();
51  // Empty response body should be parsed also as and empty array
52  $body = $httpResponse->getBody(true);
53  $jsonToArrayResponse = !empty($body) ? $httpResponse->json() : array();
54  return $this->response = new RestResponse($this, $jsonToArrayResponse, $httpResponse->getStatusCode());
55  }
56 }
Omnipay\PayPal\Message\RestTokenRequest
Definition: lib/vendor/omnipay/paypal/src/Message/RestTokenRequest.php:19
Omnipay\PayPal\Message\AbstractRestRequest\getSecret
getSecret()
Definition: lib/vendor/omnipay/paypal/src/Message/AbstractRestRequest.php:84
Omnipay\Common\Message\AbstractRequest\$httpRequest
$httpRequest
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/Message/AbstractRequest.php:92
Omnipay\PayPal\Message\RestTokenRequest\getEndpoint
getEndpoint()
Definition: lib/vendor/omnipay/paypal/src/Message/RestTokenRequest.php:26
Omnipay\PayPal\Message\AbstractRestRequest\getClientId
getClientId()
Definition: lib/vendor/omnipay/paypal/src/Message/AbstractRestRequest.php:74
Omnipay\PayPal\Message\AbstractRestRequest\getHttpMethod
getHttpMethod()
Definition: lib/vendor/omnipay/paypal/src/Message/AbstractRestRequest.php:121
Omnipay\PayPal\Message\RestTokenRequest\sendData
sendData($data)
Definition: lib/vendor/omnipay/paypal/src/Message/RestTokenRequest.php:31
Omnipay\PayPal\Message\RestTokenRequest\getData
getData()
Definition: lib/vendor/omnipay/paypal/src/Message/RestTokenRequest.php:21
Omnipay\PayPal\Message\RestResponse
Definition: lib/vendor/omnipay/paypal/src/Message/RestResponse.php:14
Omnipay\PayPal\Message\AbstractRestRequest
Definition: lib/vendor/omnipay/paypal/src/Message/AbstractRestRequest.php:31
Omnipay\PayPal\Message
Definition: lib/vendor/omnipay/paypal/src/Message/AbstractRequest.php:6