feat: voucher purchase flow
This commit is contained in:
1 parent
a628e96d06
commit
f3dd122678
70 files changed
+3672
-122
No files matched your search
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\BusProNet\XmlParser;
|
||||
|
||||
use App\BusProNet\Model\VoucherSaleResponse;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
/**
|
||||
* Parses GUTSCHEINBUCHUNG responses that are not a HINWEIS.
|
||||
*
|
||||
* Dry run (buchungsart Anfrage, measured on the test system 2026-10-01):
|
||||
* <ergebnis><satz typ="GUTSCHEINBUCHUNG"></satz><buchung>möglich</buchung></ergebnis>
|
||||
*
|
||||
* Purchase (buchungsart Buchung, as documented by the vendor):
|
||||
* <ergebnis>
|
||||
* <satz typ="GUTSCHEINBUCHUNG"/>
|
||||
* <buchung>erfolgt</buchung>
|
||||
* <idgutschein/><gutscheinnummer/><einloesecode/><preis/><rechnungsnummer/><email/>
|
||||
* </ergebnis>
|
||||
*/
|
||||
final class VoucherSaleResponseParser extends AbstractParser
|
||||
{
|
||||
public function parse(Crawler $node): VoucherSaleResponse
|
||||
{
|
||||
$status = trim($this->getStringOrNullValue($node->filterXPath('//buchung')) ?? '');
|
||||
if ('' === $status) {
|
||||
throw new \InvalidArgumentException('Missing required status in voucher sale response.');
|
||||
}
|
||||
|
||||
return new VoucherSaleResponse(
|
||||
status: $status,
|
||||
voucherId: $this->getIntOrNullValue($node->filterXPath('//idgutschein')),
|
||||
voucherNumber: $this->trimmedOrNull($node->filterXPath('//gutscheinnummer')),
|
||||
redemptionCode: $this->trimmedOrNull($node->filterXPath('//einloesecode')),
|
||||
price: $this->getFloatOrNullValue($node->filterXPath('//preis')),
|
||||
invoiceNumber: $this->trimmedOrNull($node->filterXPath('//rechnungsnummer')),
|
||||
email: $this->trimmedOrNull($node->filterXPath('//email')),
|
||||
);
|
||||
}
|
||||
|
||||
private function trimmedOrNull(Crawler $node): ?string
|
||||
{
|
||||
$value = trim($this->getStringOrNullValue($node) ?? '');
|
||||
|
||||
return '' !== $value ? $value : null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user