AbstractRequest::getHttpMethod()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Omnipay\Heidelpay\Message;
4
5
use Omnipay\Common\Message\AbstractRequest as BaseAbstractRequest;
6
7
/**
8
 * Abstract Request
9
 *
10
 */
11
abstract class AbstractRequest extends BaseAbstractRequest
12
{
13
    protected $sdkVersion = '3.0.0';
14
15
    protected $liveEndpoint = 'https://api.heidelpay.com/v1/';
16
17
18
    public function getApiKey()
19
    {
20
        return $this->getParameter('key');
21
    }
22
23
    public function setApiKey($value)
24
    {
25
        return $this->setParameter('key', $value);
26
    }
27
28
    protected function getHttpMethod()
29
    {
30
        return 'POST';
31
    }
32
33
    public function sendData($data)
34
    {
35
        $body = $data ? http_build_query($data, '', '&') : null;
36
        $response = $this->httpClient->request(
37
            $this->getHttpMethod(),
38
            $this->getEndpoint(),
39
            [
40
                'SDK-TYPE' => 'Omnipay-SDK',
41
                'SDK-VERSION' => $this->sdkVersion,
42
                'Authorization' => 'Basic '.base64_encode($this->getApiKey().':'),
43
                'Content-Type' => 'application/x-www-form-urlencoded'
44
            ],
45
            $body
46
        );
47
48
        $data = json_decode($response->getBody(), true);
49
50
        return $this->createResponse($data);
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    protected function getEndpoint()
57
    {
58
        return $this->liveEndpoint;
59
    }
60
61
    protected function createResponse($data)
62
    {
63
        return $this->response = new Response($this, $data);
64
    }
65
}
66