40 lines
1.2 KiB
PHP
40 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\BusProNet\XmlParser;
|
|
|
|
use App\BusProNet\Model\VoucherPaymentMethod;
|
|
use Symfony\Component\DomCrawler\Crawler;
|
|
|
|
/**
|
|
* Parses GUTSCHEINZAHLUNGSARTEN responses.
|
|
*
|
|
* Expected XML structure (test system, 2026-10-01):
|
|
* <ergebnis>
|
|
* <satz typ="GUTSCHEINZAHLUNGSARTEN"></satz>
|
|
* <zahlungsarten>
|
|
* <zahlungsart id="2" bezeichnung="Überweisung" art="UEBERW"></zahlungsart>
|
|
* </zahlungsarten>
|
|
* </ergebnis>
|
|
*/
|
|
final class VoucherPaymentMethodsParser extends AbstractParser
|
|
{
|
|
/**
|
|
* @return list<VoucherPaymentMethod>
|
|
*/
|
|
public function parse(Crawler $node): array
|
|
{
|
|
$paymentMethods = [];
|
|
$node->filterXPath('//zahlungsarten/zahlungsart')->each(function (Crawler $methodNode) use (&$paymentMethods): void {
|
|
$paymentMethods[] = new VoucherPaymentMethod(
|
|
id: (int) $this->getRequiredAttrValue($methodNode, 'id', 'voucher payment method'),
|
|
label: $this->getRequiredAttrValue($methodNode, 'bezeichnung', 'voucher payment method'),
|
|
type: $this->getRequiredAttrValue($methodNode, 'art', 'voucher payment method'),
|
|
);
|
|
});
|
|
|
|
return $paymentMethods;
|
|
}
|
|
}
|