Completed
Push — master ( fdca80...2de24b )
by Vladimir
08:54 queued 03:35
created

AbstractRequest   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 146
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 5

Test Coverage

Coverage 96.67%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
c 1
b 0
f 0
lcom 3
cbo 5
dl 0
loc 146
ccs 29
cts 30
cp 0.9667
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
getRequestToken() 0 1 ?
A getMerchantId() 0 4 1
A setMerchantId() 0 4 1
A getProductId() 0 4 1
A setProductId() 0 4 1
A getSecretWord() 0 4 1
A setSecretWord() 0 4 1
A sendData() 0 21 2
A getEndpoint() 0 4 2
A createResponse() 0 4 1
1
<?php
2
3
namespace Omnipay\AcquiroPay\Message;
4
5
use Omnipay\Common\Exception\RuntimeException;
6
use Omnipay\Common\Message\AbstractRequest as BaseAbstractRequest;
7
use Omnipay\Common\Message\ResponseInterface;
8
9
/**
10
 * AcquiroPay Abstract Request.
11
 *
12
 * This is the parent class for all AcquiroPay requests.
13
 */
14
abstract class AbstractRequest extends BaseAbstractRequest
15
{
16
    /**
17
     * Live Endpoint URL.
18
     *
19
     * @var string URL
20
     */
21
    protected $liveEndpoint = 'https://gateway.acquiropay.com';
22
23
    /**
24
     * Test Endpoint URL.
25
     *
26
     * @var string URL
27
     */
28
    protected $testEndpoint = 'https://gateway.acqp.co';
29
30
    /**
31
     * Get merchant id.
32
     *
33
     * @return string|null
34
     */
35 141
    public function getMerchantId()
36
    {
37 141
        return $this->getParameter('merchantId');
38
    }
39
40
    /**
41
     * Set merchant id.
42
     *
43
     * @param string $value
44
     *
45
     * @throws RuntimeException
46
     *
47
     * @return BaseAbstractRequest|AbstractRequest
48
     */
49 102
    public function setMerchantId($value)
50
    {
51 102
        return $this->setParameter('merchantId', $value);
52
    }
53
54
    /**
55
     * Get product id.
56
     *
57
     * @return string|null
58
     */
59 78
    public function getProductId()
60
    {
61 78
        return $this->getParameter('productId');
62
    }
63
64
    /**
65
     * Set product id.
66
     *
67
     * @param string $value
68
     *
69
     * @throws RuntimeException
70
     *
71
     * @return BaseAbstractRequest|AbstractRequest
72
     */
73 93
    public function setProductId($value)
74
    {
75 93
        return $this->setParameter('productId', $value);
76
    }
77
78
    /**
79
     * Get a secret word.
80
     *
81
     * @return string|null
82
     */
83 141
    public function getSecretWord()
84
    {
85 141
        return $this->getParameter('secretWord');
86
    }
87
88
    /**
89
     * Set product secret word.
90
     *
91
     * @param string $value
92
     *
93
     * @throws RuntimeException
94
     *
95
     * @return BaseAbstractRequest
96
     */
97 102
    public function setSecretWord($value)
98
    {
99 102
        return $this->setParameter('secretWord', $value);
100
    }
101
102
    /**
103
     * Send the request with specified data.
104
     *
105
     * @param mixed $data The data to send
106
     *
107
     * @return ResponseInterface
108
     */
109 45
    public function sendData($data)
110
    {
111 45
        $url = $this->getEndpoint();
112
113 45
        $options = array();
114
115 45
        if ($this->getTestMode()) {
116
            $options = array(
117 18
                'verify' => false,
118 18
            );
119 18
        }
120
121 45
        $httpResponse = $this->httpClient
122 45
            ->post($url, array(), $data, $options)
123 45
            ->send();
124
125 45
        $contents = $httpResponse->getBody(true);
126 45
        $xml = simplexml_load_string($contents);
127
128 45
        return $this->createResponse($xml);
129
    }
130
131
    /**
132
     * Get endpoint.
133
     *
134
     * @return string
135
     */
136 45
    protected function getEndpoint()
137
    {
138 45
        return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint;
139
    }
140
141
    /**
142
     * Create response.
143
     *
144
     * @param $data
145
     *
146
     * @return Response
147
     */
148 45
    protected function createResponse($data)
149
    {
150 45
        return $this->response = new Response($this, $data);
151
    }
152
153
    /**
154
     * Get a request token.
155
     *
156
     * @return string
157
     */
158
    abstract public function getRequestToken();
159
}
160