I'm calculating the displayed payment amount for an order receipt, I want to reduce those conditions to the max:
private double CalculateFinalTotal(bool hasPrommoCode,
double promoCodeValue,
double finalTotal,
double? tip)
{
if (!hasPrommoCode) return finalTotal;
if (promoCodeValue > finalTotal && tip.HasValue) return tip.Value;
else if (promoCodeValue > finalTotal) return 0;
else if (tip.HasValue)
{
var totalWithoutTip = finalTotal - tip.Value;
return (totalWithoutTip > promoCodeValue ? totalWithoutTip - promoCodeValue : 0) + tip.Value;
}
else return finalTotal - promoCodeValue;
}