fix: account for discounts applied by bpn api in validation request
This commit is contained in:
@@ -209,4 +209,107 @@ class BookingResponseParserTest extends TestCase
|
||||
$this->assertEquals(125.0, $response->paymentTerms->getPurchaseVoucherDiscount()); // 50 + 75
|
||||
$this->assertEquals(125.0, $response->getTotalVoucherDiscount());
|
||||
}
|
||||
|
||||
public function testParseBookingResponseWithGruppenrabatt(): void
|
||||
{
|
||||
$xmlContent = '<?xml version="1.0" encoding="utf-8"?>
|
||||
<ergebnis>
|
||||
<satz typ="BUCHUNG" />
|
||||
<buchung>möglich</buchung>
|
||||
<vorgang>321530</vorgang>
|
||||
<preise>
|
||||
<preis position="1" art="UNT" unterart="ZIM" bezeichnung="Doppelzimmer Dusche/WC" terminvon="27.03.2026" terminbis="29.03.2026" anzahl="6" zuordnung="1,2,3,4,5,6,7,8,9,10,11,12" preis="229,00" gesamtpreis="2748,00" />
|
||||
<preis position="2" art="UNT" unterart="ZIM" bezeichnung="3er Zimmer Dusche/WC" terminvon="27.03.2026" terminbis="29.03.2026" anzahl="2" zuordnung="13,14,15,16,17,18" preis="219,00" gesamtpreis="1314,00" />
|
||||
<preis position="3" art="ERM" unterart="GRU" bezeichnung="Gruppenrabatt" anzahl="1" preis="-90,00" gesamtpreis="-90,00" />
|
||||
</preise>
|
||||
<gesamtpreis>3972,00</gesamtpreis>
|
||||
<zahlungsbedingungen>
|
||||
<restzahlung betrag="3972,00" termin="02.12.2029"></restzahlung>
|
||||
</zahlungsbedingungen>
|
||||
</ergebnis>';
|
||||
|
||||
$crawler = new Crawler($xmlContent);
|
||||
$response = $this->parser->parse($crawler->filter('ergebnis'));
|
||||
|
||||
$this->assertTrue($response->isInquiryValid());
|
||||
$this->assertEquals(3972.0, $response->totalPrice);
|
||||
|
||||
// Verify Gruppenrabatt is NOT counted as voucher discount
|
||||
$this->assertCount(0, $response->getVoucherDiscountsFromPrices());
|
||||
$this->assertEquals(0.0, $response->getVoucherDiscountFromPrices());
|
||||
|
||||
// Verify Gruppenrabatt IS counted as API-applied discount
|
||||
$apiAppliedDiscounts = $response->getApiAppliedDiscounts();
|
||||
$this->assertCount(1, $apiAppliedDiscounts);
|
||||
|
||||
$gruppenrabatt = array_values($apiAppliedDiscounts)[0];
|
||||
$this->assertEquals('ERM', $gruppenrabatt->type);
|
||||
$this->assertEquals('GRU', $gruppenrabatt->subType);
|
||||
$this->assertEquals('Gruppenrabatt', $gruppenrabatt->label);
|
||||
$this->assertEquals(-90.0, $gruppenrabatt->totalPrice);
|
||||
|
||||
$this->assertEquals(90.0, $response->getApiAppliedDiscountTotal());
|
||||
}
|
||||
|
||||
public function testParseBookingResponseWithGruppenrabattAndVouchers(): void
|
||||
{
|
||||
$xmlContent = '<?xml version="1.0" encoding="utf-8"?>
|
||||
<ergebnis>
|
||||
<satz typ="BUCHUNG" />
|
||||
<buchung>möglich</buchung>
|
||||
<vorgang>321530</vorgang>
|
||||
<preise>
|
||||
<preis position="1" art="UNT" unterart="ZIM" bezeichnung="Doppelzimmer" preis="500,00" gesamtpreis="500,00" />
|
||||
<preis position="2" art="AKTION" unterart="" bezeichnung="PROMO20" anzahl="1" zuordnung="1" preis="-20,00" gesamtpreis="-20,00" />
|
||||
<preis position="3" art="ERM" unterart="GRU" bezeichnung="Gruppenrabatt" anzahl="1" preis="-50,00" gesamtpreis="-50,00" />
|
||||
</preise>
|
||||
<gesamtpreis>430,00</gesamtpreis>
|
||||
<zahlungsbedingungen>
|
||||
<restzahlung betrag="430,00" termin="02.12.2029"></restzahlung>
|
||||
</zahlungsbedingungen>
|
||||
</ergebnis>';
|
||||
|
||||
$crawler = new Crawler($xmlContent);
|
||||
$response = $this->parser->parse($crawler->filter('ergebnis'));
|
||||
|
||||
// Voucher discount should only include AKTION
|
||||
$this->assertEquals(20.0, $response->getVoucherDiscountFromPrices());
|
||||
|
||||
// API-applied discount should only include ERM (Gruppenrabatt)
|
||||
$this->assertEquals(50.0, $response->getApiAppliedDiscountTotal());
|
||||
|
||||
// Verify they are separate and don't overlap
|
||||
$voucherDiscounts = $response->getVoucherDiscountsFromPrices();
|
||||
$apiDiscounts = $response->getApiAppliedDiscounts();
|
||||
|
||||
$this->assertCount(1, $voucherDiscounts);
|
||||
$this->assertCount(1, $apiDiscounts);
|
||||
|
||||
$this->assertEquals('AKTION', array_values($voucherDiscounts)[0]->type);
|
||||
$this->assertEquals('ERM', array_values($apiDiscounts)[0]->type);
|
||||
}
|
||||
|
||||
public function testParseBookingResponseWithNoApiAppliedDiscounts(): void
|
||||
{
|
||||
$xmlContent = '<?xml version="1.0" encoding="utf-8"?>
|
||||
<ergebnis>
|
||||
<satz typ="BUCHUNG" />
|
||||
<buchung>möglich</buchung>
|
||||
<vorgang>321530</vorgang>
|
||||
<preise>
|
||||
<preis position="1" art="UNT" unterart="ZIM" bezeichnung="Bett im Mehrbettzimmer" preis="679,00" gesamtpreis="679,00" />
|
||||
</preise>
|
||||
<gesamtpreis>679,00</gesamtpreis>
|
||||
<zahlungsbedingungen>
|
||||
<restzahlung betrag="679,00" termin="02.12.2029"></restzahlung>
|
||||
</zahlungsbedingungen>
|
||||
</ergebnis>';
|
||||
|
||||
$crawler = new Crawler($xmlContent);
|
||||
$response = $this->parser->parse($crawler->filter('ergebnis'));
|
||||
|
||||
// Verify no API-applied discounts
|
||||
$this->assertCount(0, $response->getApiAppliedDiscounts());
|
||||
$this->assertEquals(0.0, $response->getApiAppliedDiscountTotal());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user