1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Omnipay\Komerci\Message; |
4
|
|
|
|
5
|
|
|
use Omnipay\Common\Message\AbstractResponse; |
6
|
|
|
use Omnipay\Common\Message\RequestInterface; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Komerci Authorize Response |
10
|
|
|
*/ |
11
|
|
|
class WSConfPreAuthResponse extends AbstractResponse |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
View Code Duplication |
public function __construct(RequestInterface $request, $data) |
|
|
|
|
15
|
|
|
{ |
16
|
|
|
$this->request = $request; |
17
|
|
|
|
18
|
|
|
foreach ($data->root->children() as $childName => $childValue) { |
19
|
|
|
$this->data[strtoupper($childName)] = (string) $childValue; |
20
|
|
|
} |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function isSuccessful() |
24
|
|
|
{ |
25
|
|
|
return ($this->getCode() == '0'); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function getCode() |
29
|
|
|
{ |
30
|
|
|
return isset($this->data['CODRET']) ? $this->data['CODRET'] : '99'; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function getMessage() |
34
|
|
|
{ |
35
|
|
|
return isset($this->data['MSGRET']) ? $this->data['MSGRET'] : 'Unknown'; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function getTransactionReference() |
39
|
|
|
{ |
40
|
|
|
$result = []; |
41
|
|
|
preg_match('/@COMPR:(?<res>\d*?)\+*?V/', $this->getMessage(), $result); |
42
|
|
|
return isset($result['res']) ? $result['res'] : ''; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function getNumAutor() |
46
|
|
|
{ |
47
|
|
|
$result = []; |
48
|
|
|
preg_match('/@AUTORIZACAO\+EMISSOR:\+(?<res>\d*?)\+*?@/', $this->getMessage(), $result); |
49
|
|
|
return isset($result['res']) ? $result['res'] : ''; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function getCard() |
53
|
|
|
{ |
54
|
|
|
$result = []; |
55
|
|
|
preg_match('/@CARTAO:\+(?<res>\w*?)\+*?@/', $this->getMessage(), $result); |
56
|
|
|
return isset($result['res']) ? $result['res'] : ''; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function getAmount() |
60
|
|
|
{ |
61
|
|
|
$result = []; |
62
|
|
|
preg_match('/\+VALOR:\+*?(?<int>[\d\.]*?),(?<dec>\d*?)@/', $this->getMessage(), $result); |
63
|
|
|
return isset($result['int']) ? floatval(str_replace('.', '', $result['int']) . '.' . $result['dec']) : null; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
} |
68
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.