-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathStatementsResponse.php
84 lines (78 loc) · 3.45 KB
/
StatementsResponse.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
<?php
declare(strict_types=1);
namespace SergeyNezbritskiy\PrivatBank\Response;
use SergeyNezbritskiy\PrivatBank\Api\ResponseInterface;
use SergeyNezbritskiy\PrivatBank\Base\AbstractResponse;
use SergeyNezbritskiy\PrivatBank\Base\PrivatBankApiException;
/**
* Class StatementsResponse
* @package SergeyNezbritskiy\PrivatBank\Response
*/
class StatementsResponse extends AbstractResponse implements ResponseInterface
{
/**
* Response sample
* ```xml
* <?xml version="1.0" encoding="UTF-8"?>
* <response version="1.0">
* <merchant>
* <id>75482</id>
* <signature>553995c5ccc8c81815b58cf6374f68f00a28bbd7</signature>
* </merchant>
* <data>
* <oper>cmt</oper>
* <info>
* <statements status="excellent" credit="0.0" debet="0.3" >
* <statement card="5168742060221193" appcode="591969" trandate="2013-09-02" trantime="13:29:00"
* amount="0.10 UAH" cardamount="-0.10 UAH" rest="0.95 UAH"
* terminal="Пополнение мобильного +380139917053 через «Приват24»" description="" />
* <statement card="5168742060221193" appcode="991794" trandate="2013-09-02" trantime="08:50:00"
* amount="0.10 UAH" cardamount="-0.10 UAH" rest="1.05 UAH"
* terminal="Пополнение мобильного +380139917035 через «Приват24»" description="" />
* <statement card="5168742060221193" appcode="801111" trandate="2013-09-02" trantime="13:17:00"
* amount="0.10 UAH" cardamount="-0.10 UAH" rest="1.15 UAH"
* terminal="Пополнение мобильного +380139910008 через «Приват24»" description="" />
* </statements>
* </info>
* </data>
* </response>
* ```
* @return array
*/
public function getData(): array
{
$xml = $this->getXmlContent();
$statements = $xml->getElementsByTagName('statement');
$result = [];
/** @var \DOMElement $statementXml */
foreach ($statements as $statementXml) {
$result[] = [
'card' => $statementXml->getAttribute('card'),
'appcode' => $statementXml->getAttribute('appcode'),
'trandate' => $statementXml->getAttribute('trandate'),
'trantime' => $statementXml->getAttribute('trantime'),
'amount' => $statementXml->getAttribute('amount'),
'cardamount' => $statementXml->getAttribute('cardamount'),
'rest' => $statementXml->getAttribute('rest'),
'terminal' => $statementXml->getAttribute('terminal'),
'description' => $statementXml->getAttribute('description'),
];
}
return $result;
}
/**
* @throws PrivatBankApiException
*/
protected function handleErrors()
{
parent::handleErrors();
$xmlContent = $this->getXmlContent();
/** @var \DOMNodeList $info */
$info = $xmlContent->getElementsByTagName('info');
foreach ($info as $item) {
if (substr($item->textContent, 0, 5) === 'error') {
throw new PrivatBankApiException($item->textContent, 500);
}
}
}
}