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
|
92 |
|
public function getMerchantId() |
36
|
|
|
{ |
37
|
92 |
|
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
|
66 |
|
public function setMerchantId($value) |
50
|
|
|
{ |
51
|
66 |
|
return $this->setParameter('merchantId', $value); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Get product id. |
56
|
|
|
* |
57
|
|
|
* @return string|null |
58
|
|
|
*/ |
59
|
50 |
|
public function getProductId() |
60
|
|
|
{ |
61
|
50 |
|
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
|
54 |
|
public function setProductId($value) |
74
|
|
|
{ |
75
|
54 |
|
return $this->setParameter('productId', $value); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Get a secret word. |
80
|
|
|
* |
81
|
|
|
* @return string|null |
82
|
|
|
*/ |
83
|
92 |
|
public function getSecretWord() |
84
|
|
|
{ |
85
|
92 |
|
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
|
66 |
|
public function setSecretWord($value) |
98
|
|
|
{ |
99
|
66 |
|
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
|
30 |
|
public function sendData($data) |
110
|
|
|
{ |
111
|
30 |
|
$url = $this->getEndpoint(); |
112
|
|
|
|
113
|
30 |
|
$options = array(); |
114
|
|
|
|
115
|
30 |
|
if ($this->getTestMode()) { |
116
|
|
|
$options = array( |
117
|
12 |
|
'verify' => false, |
118
|
12 |
|
); |
119
|
12 |
|
} |
120
|
|
|
|
121
|
30 |
|
$httpResponse = $this->httpClient |
122
|
30 |
|
->post($url, array(), $data, $options) |
123
|
30 |
|
->send(); |
124
|
|
|
|
125
|
30 |
|
$contents = $httpResponse->getBody(true); |
126
|
30 |
|
$xml = simplexml_load_string($contents); |
127
|
|
|
|
128
|
30 |
|
return $this->createResponse($xml); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Get endpoint. |
133
|
|
|
* |
134
|
|
|
* @return string |
135
|
|
|
*/ |
136
|
30 |
|
protected function getEndpoint() |
137
|
|
|
{ |
138
|
30 |
|
return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Create response. |
143
|
|
|
* |
144
|
|
|
* @param $data |
145
|
|
|
* |
146
|
|
|
* @return Response |
147
|
|
|
*/ |
148
|
30 |
|
protected function createResponse($data) |
149
|
|
|
{ |
150
|
30 |
|
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
|
|
|
|