1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* Copyright (C) 2020 Jan Böhmer |
4
|
|
|
* |
5
|
|
|
* This program is free software: you can redistribute it and/or modify |
6
|
|
|
* it under the terms of the GNU Affero General Public License as published |
7
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
8
|
|
|
* (at your option) any later version. |
9
|
|
|
* |
10
|
|
|
* This program is distributed in the hope that it will be useful, |
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13
|
|
|
* GNU Affero General Public License for more details. |
14
|
|
|
* |
15
|
|
|
* You should have received a copy of the GNU Affero General Public License |
16
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace App\Helpers\SEPAXML; |
20
|
|
|
|
21
|
|
|
class SEPAXMLParser |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Parse various infos needed for SEPA Export from the given string and return info as array |
25
|
|
|
* @param string $xml |
26
|
|
|
* @return array |
27
|
|
|
*/ |
28
|
|
|
public static function parseFromString(string $xml): array |
29
|
|
|
{ |
30
|
|
|
$root = new \SimpleXMLElement($xml); |
31
|
|
|
|
32
|
|
|
$group_header = $root->CstmrCdtTrfInitn->GrpHdr; |
33
|
|
|
$payment_info = $root->CstmrCdtTrfInitn->PmtInf; |
34
|
|
|
|
35
|
|
|
return [ |
36
|
|
|
'msg_id' => (string) ($group_header->MsgId), |
37
|
|
|
'number_of_payments' => (int) ($group_header->NbOfTxs), |
38
|
|
|
'total_sum' => (int) str_replace('.','',$group_header->CtrlSum), |
39
|
|
|
'initiator_iban' => (string) $payment_info->DbtrAcct->Id->IBAN, |
40
|
|
|
'initiator_bic' => (string) $payment_info->DbtrAgt->FinInstnId->BIC, |
41
|
|
|
]; |
42
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Parse various infos needed for SEPA Export from the given file and return info as array |
47
|
|
|
* @param string $xml |
48
|
|
|
* @return array |
49
|
|
|
*/ |
50
|
|
|
public static function parseFromFile(\SplFileInfo $file): array |
51
|
|
|
{ |
52
|
|
|
$xmlstring = file_get_contents($file->getPathname()); |
53
|
|
|
|
54
|
|
|
return self::parseFromString($xmlstring); |
55
|
|
|
} |
56
|
|
|
} |