// Returns: Amount to refund via PaymentProvider public decimal ApplyRefund(Refund refund) { // If we haven't already tried to apply this refund if (Refunds.Select(r => r.IdempotencyKey).Contains(refund.IdempotencyKey)) { throw new Exception(); } refund.AmountRefunded = MaximumRefundAvailable(); Refunds.Add(refund); foreach (Installment installment in Installments) { // Do this so everything gets set as 'paid' installment.SetPaid(Id, DateTime.Now); } return(refund.AmountRefunded); }
// Returns: Amount to refund via PaymentProvider public decimal ApplyRefund(Refund refund) { var refundedAmountAgainstPaidInstallments = Installments .Where(i => i.IsPaid) .Sum(i => i.Amount); Refunds.Add(refund); var refundBalance = refund.Amount; foreach (var installment in Installments) { if (refundBalance >= installment.Amount) { MakePayment(installment.Amount, installment.Id); } refundBalance = refundBalance - installment.Amount; } return(refundedAmountAgainstPaidInstallments); }
// Returns: Amount to refund via PaymentProvider public decimal ApplyRefund(Refund refund) { var refundedAmount = Installments.Where(i => i.IsPaid).Sum(j => j.Amount); if (Refunds == null) { Refunds = new List <Refund>(); } Refunds.Add(refund); var refundBalance = refund.Amount; foreach (var installment in Installments) { if (refundBalance >= installment.Amount) { MakePayment(installment.Amount, installment.Id); } refundBalance = refundBalance - installment.Amount; } return(refundedAmount); }