|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the Marlon Ogone package. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Marlon BVBA <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Ogone; |
|
12
|
|
|
|
|
13
|
|
|
use InvalidArgumentException; |
|
14
|
|
|
|
|
15
|
|
|
abstract class AbstractPaymentResponse extends AbstractResponse implements PaymentResponse |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @return int Amount in cents |
|
19
|
|
|
*/ |
|
20
|
18 |
|
public function getAmount() |
|
21
|
|
|
{ |
|
22
|
18 |
|
if (!isset($this->parameters['AMOUNT'])) { |
|
23
|
|
|
throw new InvalidArgumentException('Parameter AMOUNT does not exist'); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
18 |
|
$value = trim($this->parameters['AMOUNT']); |
|
27
|
|
|
|
|
28
|
18 |
|
$withoutDecimals = '#^\d*$#'; |
|
29
|
18 |
|
$oneDecimal = '#^\d*\.\d$#'; |
|
30
|
18 |
|
$twoDecimals = '#^\d*\.\d\d$#'; |
|
31
|
|
|
|
|
32
|
18 |
|
if (preg_match($withoutDecimals, $value)) { |
|
33
|
3 |
|
return (int) ($value.'00'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
15 |
|
if (preg_match($oneDecimal, $value)) { |
|
37
|
2 |
|
return (int) (str_replace('.', '', $value).'0'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
13 |
|
if (preg_match($twoDecimals, $value)) { |
|
41
|
12 |
|
return (int) (str_replace('.', '', $value)); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
1 |
|
throw new \InvalidArgumentException("Not a valid currency amount"); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
2 |
|
public function isSuccessful() |
|
48
|
|
|
{ |
|
49
|
2 |
|
return in_array($this->getParam('STATUS'), array( |
|
50
|
2 |
|
PaymentResponse::STATUS_AUTHORISED, |
|
51
|
2 |
|
PaymentResponse::STATUS_PAYMENT_REQUESTED, |
|
52
|
2 |
|
PaymentResponse::STATUS_PAYMENT_BY_MERCHANT |
|
53
|
|
|
)); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|