forked from wysow/wysow-postfinance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AbstractPaymentRequest.php
319 lines (288 loc) · 9.57 KB
/
AbstractPaymentRequest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
<?php
/*
* This file is part of the Wysow PostFinance package.
*
* (c) Gaultier Boniface <[email protected]>
* (c) Marlon BVBA <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PostFinance;
use InvalidArgumentException;
abstract class AbstractPaymentRequest extends AbstractRequest
{
const OPERATION_REQUEST_AUTHORIZATION = 'RES';
const OPERATION_REQUEST_DIRECT_SALE = 'SAL';
const OPERATION_REFUND = 'RFD';
const OPERATION_REQUEST_PRE_AUTHORIZATION = 'PAU';
protected $brandsmap = array(
'Acceptgiro' => 'Acceptgiro',
'AIRPLUS' => 'CreditCard',
'American Express' => 'CreditCard',
'Aurora' => 'CreditCard',
'Aurore' => 'CreditCard',
'Bank transfer' => 'Bank transfer',
'Bank transfer BE' => 'Bank transfer BE',
'Bank transfer DE' => 'Bank transfer DE',
'Bank transfer FR' => 'Bank transfer FR',
'Bank transfer NL' => 'Bank transfer NL',
'BCMC' => 'CreditCard',
'Belfius Direct Net' => 'Belfius Direct Net',
'Billy' => 'CreditCard',
'cashU' => 'cashU',
'CB' => 'CreditCard',
'CBC Online' => 'CBC Online',
'CENTEA Online' => 'CENTEA Online',
'Cofinoga' => 'CreditCard',
'Dankort' => 'CreditCard',
'Dexia Direct Net' => 'Dexia Direct Net',
'Diners Club' => 'CreditCard',
'Direct Debits AT' => 'Direct Debits AT',
'Direct Debits DE' => 'Direct Debits DE',
'Direct Debits NL' => 'Direct Debits NL',
'DirectEbankingDE' => 'DirectEbankingDE',
'DirectEbankingAT' => 'DirectEbankingAT',
'DirectEbankingIT' => 'DirectEbankingIT',
'DirectEbankingBE' => 'DirectEbankingBE',
'DirectEbankingFR' => 'DirectEbankingFR',
'eDankort' => 'eDankort',
'EPS' => 'EPS',
'Fortis Pay Button' => 'Fortis Pay Button',
'giropay' => 'giropay',
'iDEAL' => 'iDEAL',
'ING HomePay' => 'ING HomePay',
'InterSolve' => 'InterSolve',
'JCB' => 'CreditCard',
'KBC Online' => 'KBC Online',
'Maestro' => 'CreditCard',
'MaestroUK' => 'CreditCard',
'MasterCard' => 'CreditCard',
'MiniTix' => 'MiniTix',
'MPASS' => 'MPASS',
'NetReserve' => 'CreditCard',
'Payment on Delivery' => 'Payment on Delivery',
'PAYPAL' => 'PAYPAL',
'paysafecard' => 'paysafecard',
'PingPing' => 'PingPing',
'PostFinance + card' => 'PostFinance Card',
'PostFinance e-finance' => 'PostFinance e-finance',
'PRIVILEGE' => 'CreditCard',
'Sofort Uberweisung' => 'DirectEbanking',
'Solo' => 'CreditCard',
'TUNZ' => 'TUNZ',
'UATP' => 'CreditCard',
'UNEUROCOM' => 'UNEUROCOM',
'VISA' => 'CreditCard',
'Wallie' => 'Wallie',
);
/** Note this is public to allow easy modification, if need be. */
public $allowedcurrencies = array(
'AED',
'ANG',
'ARS',
'AUD',
'AWG',
'BGN',
'BRL',
'BYR',
'CAD',
'CHF',
'CNY',
'CZK',
'DKK',
'EEK',
'EGP',
'EUR',
'GBP',
'GEL',
'HKD',
'HRK',
'HUF',
'ILS',
'ISK',
'JPY',
'KRW',
'LTL',
'LVL',
'MAD',
'MXN',
'MYR',
'NOK',
'NZD',
'PLN',
'RON',
'RUB',
'SEK',
'SGD',
'SKK',
'THB',
'TRY',
'UAH',
'USD',
'XAF',
'XOF',
'XPF',
'ZAR'
);
public function setOrderid($orderid)
{
if (strlen($orderid) > 30) {
throw new InvalidArgumentException("Orderid cannot be longer than 30 characters");
}
if (preg_match('/[^a-zA-Z0-9_-]/', $orderid)) {
throw new InvalidArgumentException("Order id cannot contain special characters");
}
$this->parameters['orderid'] = $orderid;
}
/** Friend alias for setCom() */
public function setOrderDescription($orderDescription)
{
$this->setCom($orderDescription);
}
public function setCom($com)
{
if (strlen($com) > 100) {
throw new InvalidArgumentException("Order description cannot be longer than 100 characters");
}
$this->parameters['com'] = $com;
}
/**
* Set amount in cents, eg EUR 12.34 is written as 1234
*/
public function setAmount($amount)
{
if (!is_int($amount)) {
throw new InvalidArgumentException("Integer expected. Amount is always in cents");
}
if ($amount <= 0) {
throw new InvalidArgumentException("Amount must be a positive number");
}
if ($amount >= 1.0E+15) {
throw new InvalidArgumentException("Amount is too high");
}
$this->parameters['amount'] = $amount;
}
public function setCurrency($currency)
{
if (!in_array(strtoupper($currency), $this->allowedcurrencies)) {
throw new InvalidArgumentException("Unknown currency");
}
$this->parameters['currency'] = $currency;
}
public function setEmail($email)
{
if (strlen($email) > 50) {
throw new InvalidArgumentException("Email is too long");
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
throw new InvalidArgumentException("Email is invalid");
}
$this->parameters['email'] = $email;
}
public function setOwnerAddress($owneraddress)
{
if (strlen($owneraddress) > 35) {
throw new InvalidArgumentException("Owner address is too long");
}
$this->parameters['owneraddress'] = $owneraddress;
}
public function setOwnerZip($ownerzip)
{
if (strlen($ownerzip) > 10) {
throw new InvalidArgumentException("Owner Zip is too long");
}
$this->parameters['ownerzip'] = $ownerzip;
}
public function setOwnerTown($ownertown)
{
if (strlen($ownertown) > 40) {
throw new InvalidArgumentException("Owner town is too long");
}
$this->parameters['ownertown'] = $ownertown;
}
/**
* Alias for setOwnercty
*
* @see http://www.iso.org/iso/country_codes/iso_3166_code_lists/english_country_names_and_code_elements.htm
*/
public function setOwnerCountry($ownercountry)
{
$this->setOwnercty($ownercountry);
}
/**
* @see http://www.iso.org/iso/country_codes/iso_3166_code_lists/english_country_names_and_code_elements.htm
*/
public function setOwnercty($ownercty)
{
if (!preg_match('/^[A-Z]{2}$/', strtoupper($ownercty))) {
throw new InvalidArgumentException("Illegal country code");
}
$this->parameters['ownercty'] = strtoupper($ownercty);
}
/** Alias for setOwnertelno() */
public function setOwnerPhone($ownerphone)
{
$this->setOwnertelno($ownerphone);
}
public function setOwnertelno($ownertelno)
{
if (strlen($ownertelno) > 30) {
throw new InvalidArgumentException("Owner phone is too long");
}
$this->parameters['ownertelno'] = $ownertelno;
}
/** Alias for setComplus() */
public function setFeedbackMessage($feedbackMessage)
{
$this->setComplus($feedbackMessage);
}
public function setComplus($complus)
{
$this->parameters['complus'] = $complus;
}
public function setBrand($brand)
{
if (!array_key_exists($brand, $this->brandsmap)) {
throw new InvalidArgumentException("Unknown Brand [$brand].");
}
$this->setPaymentMethod($this->brandsmap[$brand]);
$this->parameters['brand'] = $brand;
}
public function setPaymentMethod($paymentMethod)
{
$this->setPm($paymentMethod);
}
public function setPm($pm)
{
if (!in_array($pm, $this->brandsmap)) {
throw new InvalidArgumentException("Unknown Payment method [$pm].");
}
$this->parameters['pm'] = $pm;
}
public function setParamvar($paramvar)
{
if (strlen($paramvar) < 2 || strlen($paramvar) > 50) {
throw new InvalidArgumentException("Paramvar must be between 2 and 50 characters in length");
}
$this->parameters['paramvar'] = $paramvar;
}
/** Alias for setTp */
public function setDynamicTemplateUri($uri)
{
$this->setTp($uri);
}
public function setTp($tp)
{
$this->validateUri($tp);
$this->parameters['tp'] = $tp;
}
public function setOperation($operation)
{
if (!in_array($operation, $this->getValidOperations())) {
throw new InvalidArgumentException("Invalid operation [$operation].");
}
$this->parameters['operation'] = $operation;
}
abstract protected function getValidOperations();
}