1
|
|
|
<?php |
2
|
|
|
namespace Omnipay\Pelecard\Message; |
3
|
|
|
|
4
|
|
|
use Omnipay\Common\Exception\InvalidRequestException; |
5
|
|
|
use Omnipay\Common\Message\AbstractRequest as BaseAbstractRequest; |
6
|
|
|
use RuntimeException; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Abstract Request |
10
|
|
|
*/ |
11
|
|
|
abstract class AbstractRequest extends BaseAbstractRequest |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
protected $liveEndpoint = 'https://gateway20.pelecard.biz/PaymentGW/init'; |
15
|
|
|
|
16
|
|
|
protected $request = []; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Build the request object |
20
|
|
|
* |
21
|
|
|
* @return array |
22
|
|
|
*/ |
23
|
|
|
public function getData() |
24
|
|
|
{ |
25
|
|
|
$this->request = array(); |
26
|
|
|
if($this->getTestMode()){ |
27
|
|
|
$this->request['user'] = 'testpelecard3'; |
28
|
|
|
$this->request['password'] = 'Q3EJB8Ah'; |
29
|
|
|
$this->request['terminal'] = '0962210'; |
30
|
|
|
} |
31
|
|
|
else{ |
32
|
|
|
$this->request['user'] = $this->getParameter('user'); |
33
|
|
|
$this->request['password'] = $this->getParameter('password'); |
34
|
|
|
$this->request['terminal'] = $this->getParameter('terminal'); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
return $this->request; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Get user |
43
|
|
|
* |
44
|
|
|
* Use the User assigned by Pelecard. |
45
|
|
|
* |
46
|
|
|
* @return string |
47
|
|
|
*/ |
48
|
|
|
public function getUser() |
49
|
|
|
{ |
50
|
|
|
if (empty($this->getParameter('user'))) { |
51
|
|
|
throw new InvalidRequestException('user must be set.'); |
52
|
|
|
} |
53
|
|
|
return $this->getParameter('user'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Set user |
58
|
|
|
* |
59
|
|
|
* Use the User assigned by Pelecard. |
60
|
|
|
* |
61
|
|
|
* @param string $value |
62
|
|
|
*/ |
63
|
|
|
public function setUser($value) |
64
|
|
|
{ |
65
|
|
|
return $this->setParameter('user', $value); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Get password |
70
|
|
|
* |
71
|
|
|
* Use the Password assigned by Pelecard. |
72
|
|
|
* |
73
|
|
|
* @return string |
74
|
|
|
*/ |
75
|
|
|
public function getPassword() |
76
|
|
|
{ |
77
|
|
|
if (empty($this->getParameter('password'))) { |
78
|
|
|
throw new InvalidRequestException('password must be set.'); |
79
|
|
|
} |
80
|
|
|
return $this->getParameter('password'); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Set password |
85
|
|
|
* |
86
|
|
|
* Use the Password assigned by Pelecard. |
87
|
|
|
* |
88
|
|
|
* @param string $value |
89
|
|
|
*/ |
90
|
|
|
public function setPassword($value) |
91
|
|
|
{ |
92
|
|
|
return $this->setParameter('password', $value); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Get terminal |
97
|
|
|
* |
98
|
|
|
* Use the terminal assigned by Pelecard. |
99
|
|
|
* |
100
|
|
|
* @return string |
101
|
|
|
*/ |
102
|
|
|
public function getTerminal() |
103
|
|
|
{ |
104
|
|
|
if (empty($this->getParameter('terminal'))) { |
105
|
|
|
throw new InvalidRequestException('terminal must be set.'); |
106
|
|
|
} |
107
|
|
|
return $this->getParameter('terminal'); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Set terminal |
112
|
|
|
* |
113
|
|
|
* Use the terminal assigned by Pelecard. |
114
|
|
|
* |
115
|
|
|
* @param string $value |
116
|
|
|
*/ |
117
|
|
|
public function setTerminal($value) |
118
|
|
|
{ |
119
|
|
|
return $this->setParameter('terminal', $value); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function sendData($data) |
123
|
|
|
{ |
124
|
|
|
$httpRequest = $this->httpClient->post($this->getEndpoint(), [ |
125
|
|
|
'Content-Type' => 'application/json; charset=utf-8', |
126
|
|
|
'Accept' => 'application/json', |
127
|
|
|
'json' => json_encode($data) |
128
|
|
|
], json_encode($data)); |
129
|
|
|
$httpResponse = $httpRequest->send(); |
130
|
|
|
return $this->createResponse($httpResponse->json()); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Sets the payment currency code. |
135
|
|
|
* |
136
|
|
|
* @param string $value |
137
|
|
|
* @return AbstractRequest Provides a fluent interface |
138
|
|
|
*/ |
139
|
|
|
public function setCurrency($value) |
140
|
|
|
{ |
141
|
|
|
if ($value !== null) { |
|
|
|
|
142
|
|
|
$value = strtoupper($value); |
143
|
|
|
} |
144
|
|
|
if ($value == 'NIS') |
145
|
|
|
return $this->setParameter('currency', 1); |
146
|
|
|
if ($value == 'USD') |
147
|
|
|
return $this->setParameter('currency', 2); |
148
|
|
|
if ($value == 'EUR') |
149
|
|
|
return $this->setParameter('currency', 978); |
150
|
|
|
throw new RuntimeException('Unknown currency'); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
protected function getEndpoint() |
154
|
|
|
{ |
155
|
|
|
return $this->liveEndpoint; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
protected function createResponse($data) |
159
|
|
|
{ |
160
|
|
|
return $this->response = new Response($this, $data); |
161
|
|
|
} |
162
|
|
|
}
|
163
|
|
|
|