1 | <?php |
||
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 |