Open Journal Systems  3.3.0
vendor/omnipay/paypal/src/Message/RestTokenRequest.php
1 <?php
6 namespace Omnipay\PayPal\Message;
7 
19 class RestTokenRequest extends AbstractRestRequest
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  $body = $data ? http_build_query($data, '', '&') : null;
34  $httpResponse = $this->httpClient->request(
35  $this->getHttpMethod(),
36  $this->getEndpoint(),
37  array(
38  'Accept' => 'application/json',
39  'Authorization' => 'Basic ' . base64_encode("{$this->getClientId()}:{$this->getSecret()}"),
40  ),
41  $body
42  );
43  // Empty response body should be parsed also as and empty array
44  $body = (string) $httpResponse->getBody()->getContents();
45  $jsonToArrayResponse = !empty($body) ? json_decode($body, true) : array();
46  return $this->response = new RestResponse($this, $jsonToArrayResponse, $httpResponse->getStatusCode());
47  }
48 }
Omnipay\PayPal\Message\RestTokenRequest\getEndpoint
getEndpoint()
Definition: vendor/omnipay/paypal/src/Message/RestTokenRequest.php:26
Omnipay\PayPal\Message\AbstractRestRequest\getHttpMethod
getHttpMethod()
Definition: lib/vendor/omnipay/paypal/src/Message/AbstractRestRequest.php:121
Omnipay\PayPal\Message\RestTokenRequest\sendData
sendData($data)
Definition: vendor/omnipay/paypal/src/Message/RestTokenRequest.php:31
Omnipay\PayPal\Message\RestTokenRequest\getData
getData()
Definition: 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
Definition: lib/vendor/omnipay/paypal/src/Message/AbstractRequest.php:6