fix: account for discounts applied by bpn api in validation request
This commit is contained in:
@@ -102,4 +102,45 @@ class BookingResponse
|
||||
2
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets API-applied discounts that cannot be predicted by the local price calculator.
|
||||
*
|
||||
* The BusProNet API may apply automatic discounts based on business rules that
|
||||
* are not known to the local application, such as:
|
||||
* - ERM/GRU: Gruppenrabatt (group discount for large bookings)
|
||||
* - Other ERM subtypes: Various automatic discounts
|
||||
*
|
||||
* These discounts appear as negative price items and must be accounted for when
|
||||
* comparing the API total price against the locally calculated price.
|
||||
*
|
||||
* Note: Voucher discounts (AKTION, KULANZGUTSCHEIN) are handled separately via
|
||||
* getVoucherDiscountFromPrices() as they are user-initiated, not automatic.
|
||||
*
|
||||
* @return array<PriceItem> Price items representing API-applied automatic discounts
|
||||
*/
|
||||
public function getApiAppliedDiscounts(): array
|
||||
{
|
||||
return array_filter(
|
||||
$this->priceItems,
|
||||
fn (PriceItem $item) => $item->totalPrice < 0
|
||||
&& false === \in_array($item->type, ['AKTION', 'KULANZGUTSCHEIN'], true)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets total discount from API-applied automatic discounts.
|
||||
*
|
||||
* Returns the absolute sum of negative price items that represent automatic
|
||||
* discounts applied by the API (excluding voucher discounts which are handled separately).
|
||||
*/
|
||||
public function getApiAppliedDiscountTotal(): float
|
||||
{
|
||||
$discount = 0.0;
|
||||
foreach ($this->getApiAppliedDiscounts() as $item) {
|
||||
$discount += abs($item->totalPrice);
|
||||
}
|
||||
|
||||
return round($discount, 2);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user