PatronBase /
omnipay-gocardless
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Omnipay\GoCardless\Message; |
||
| 4 | |||
| 5 | use Omnipay\Common\Message\AbstractRequest as BaseAbstractRequest; |
||
| 6 | use Psr\Http\Message\ResponseInterface; |
||
| 7 | |||
| 8 | /** |
||
| 9 | * Abstract Request |
||
| 10 | */ |
||
| 11 | abstract class AbstractRequest extends BaseAbstractRequest |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * @var string Live endpoint URL |
||
| 15 | */ |
||
| 16 | protected $endpointLive = 'https://api.gocardless.com'; |
||
| 17 | /** |
||
| 18 | * @var string Sandbox/testing endpoint URL |
||
| 19 | */ |
||
| 20 | protected $endpointSandbox = 'https://api-sandbox.gocardless.com'; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var string Action portion of the URL |
||
| 24 | */ |
||
| 25 | protected $action = '/redirect_flows'; |
||
| 26 | |||
| 27 | public function getEndpoint() |
||
| 28 | { |
||
| 29 | return $this->getTestMode() ? $this->endpointSandbox : $this->endpointLive; |
||
| 30 | } |
||
| 31 | |||
| 32 | public function getAccessToken() |
||
| 33 | { |
||
| 34 | return $this->getParameter('access_token'); |
||
| 35 | } |
||
| 36 | |||
| 37 | public function setAccessToken($value) |
||
| 38 | { |
||
| 39 | return $this->setParameter('access_token', $value); |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Send a HTTP request to the gateway |
||
| 44 | * |
||
| 45 | * @param array $data |
||
| 46 | * @param string $method |
||
| 47 | * |
||
| 48 | * @return ResponseInterface |
||
| 49 | */ |
||
| 50 | protected function sendRequest($data, $method = 'POST') |
||
| 51 | { |
||
| 52 | $response = $this->httpClient->request( |
||
| 53 | $method, |
||
| 54 | $this->getEndpoint().$this->action, |
||
| 55 | array( |
||
| 56 | 'Accept' => 'application/json', |
||
| 57 | 'Content-Type' => 'application/json', |
||
| 58 | 'Authorization' => 'Bearer '.$this->getAccessToken(), |
||
| 59 | 'GoCardless-Version' => '2015-07-06', |
||
| 60 | ), |
||
| 61 | $data === null ? null : json_encode($data) |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 62 | ); |
||
| 63 | |||
| 64 | return $response; |
||
| 65 | } |
||
| 66 | } |
||
| 67 |