fix: account for discounts applied by bpn api in validation request
This commit is contained in:
@@ -115,12 +115,15 @@ class Step3Controller extends AbstractController
|
||||
}
|
||||
|
||||
// Validate price match (rounded to cent precision to avoid floating-point errors)
|
||||
// API gesamtpreis includes promotional/goodwill voucher discounts (negative price items),
|
||||
// but NOT purchase vouchers (those reduce restzahlung, not gesamtpreis)
|
||||
// API gesamtpreis includes:
|
||||
// - Promotional/goodwill voucher discounts (negative price items with art=AKTION/KULANZGUTSCHEIN)
|
||||
// - API-applied automatic discounts (e.g., Gruppenrabatt with art=ERM)
|
||||
// - NOT purchase vouchers (those reduce restzahlung, not gesamtpreis)
|
||||
$apiTotal = round($inquiryResponse->totalPrice ?? 0.0, 2);
|
||||
$calculatedSubtotal = round($this->priceCalculator->calculateGrandTotal($bookingCreateDto), 2);
|
||||
$promoGoodwillDiscount = round($inquiryResponse->getVoucherDiscountFromPrices(), 2);
|
||||
$expectedTotal = round($calculatedSubtotal - $promoGoodwillDiscount, 2);
|
||||
$apiAppliedDiscount = round($inquiryResponse->getApiAppliedDiscountTotal(), 2);
|
||||
$expectedTotal = round($calculatedSubtotal - $promoGoodwillDiscount - $apiAppliedDiscount, 2);
|
||||
|
||||
if ((int) round($apiTotal * 100) !== (int) round($expectedTotal * 100)) {
|
||||
return $this->handleApiError(
|
||||
@@ -129,6 +132,7 @@ class Step3Controller extends AbstractController
|
||||
'apiTotal' => $apiTotal,
|
||||
'calculatedSubtotal' => $calculatedSubtotal,
|
||||
'promoGoodwillDiscount' => $promoGoodwillDiscount,
|
||||
'apiAppliedDiscount' => $apiAppliedDiscount,
|
||||
'expectedTotal' => $expectedTotal,
|
||||
'difference' => abs($apiTotal - $expectedTotal),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user