|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Omnipay\PaypalRest\Message; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* @author Ivan Kerin <[email protected]> |
|
7
|
|
|
* @copyright 2014, Clippings Ltd. |
|
8
|
|
|
* @license http://spdx.org/licenses/BSD-3-Clause |
|
9
|
|
|
*/ |
|
10
|
|
|
class TokenRequest extends AbstractRequest |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @return string |
|
14
|
|
|
*/ |
|
15
|
|
|
public function getEndpoint() |
|
16
|
|
|
{ |
|
17
|
|
|
return '/oauth2/token'; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @param string $value |
|
22
|
|
|
*/ |
|
23
|
|
|
public function setClientId($value) |
|
24
|
|
|
{ |
|
25
|
|
|
return $this->setParameter('clientId', $value); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @return string |
|
30
|
|
|
*/ |
|
31
|
|
|
public function getClientId() |
|
32
|
|
|
{ |
|
33
|
|
|
return $this->getParameter('clientId'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param string $value |
|
38
|
|
|
*/ |
|
39
|
|
|
public function setSecret($value) |
|
40
|
|
|
{ |
|
41
|
|
|
return $this->setParameter('secret', $value); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @return string |
|
46
|
|
|
*/ |
|
47
|
|
|
public function getSecret() |
|
48
|
|
|
{ |
|
49
|
|
|
return $this->getParameter('secret'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @return array |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getData() |
|
56
|
|
|
{ |
|
57
|
|
|
return array(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @return \Guzzle\Http\Message\Response |
|
62
|
|
|
*/ |
|
63
|
|
|
public function sendHttpRequest() |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->getHttpRequest()->send(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @return \Guzzle\Http\Message\EntityEnclosingRequestInterface |
|
70
|
|
|
*/ |
|
71
|
|
|
public function getHttpRequest() |
|
72
|
|
|
{ |
|
73
|
|
|
$httpRequest = $this->httpClient->post( |
|
74
|
|
|
$this->getServer().$this->getEndpoint(), |
|
75
|
|
|
array('Accept' => 'application/json'), |
|
76
|
|
|
array('grant_type' => 'client_credentials') |
|
77
|
|
|
); |
|
78
|
|
|
|
|
79
|
|
|
$httpRequest->setAuth($this->getClientId(), $this->getSecret()); |
|
80
|
|
|
|
|
81
|
|
|
return $httpRequest; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @param mixed $data |
|
86
|
|
|
* @return TokenResponse |
|
87
|
|
|
*/ |
|
88
|
|
|
public function sendData($data) |
|
89
|
|
|
{ |
|
90
|
|
|
$httpResponse = $this->sendHttpRequest(); |
|
91
|
|
|
|
|
92
|
|
|
return $this->response = new TokenResponse( |
|
93
|
|
|
$this, |
|
94
|
|
|
$httpResponse->json(), |
|
95
|
|
|
$httpResponse->getStatusCode() |
|
96
|
|
|
); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|