// 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(Guid installmentId) { var activeAccount = Installments.Where(x => x.Id == installmentId); var refund = 0M; foreach (var singleInstallment in activeAccount) { if (singleInstallment.IsPaid && !singleInstallment.AccountClosed) { refund = refund + singleInstallment.Amount; singleInstallment.IsPaid = false; } singleInstallment.AccountClosed = true; } var closingAccount = activeAccount.FirstOrDefault(); var refundAccount = new Refund(refund) { Id = closingAccount.Id, Date = DateTime.Now }; return(refund); }
// 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); }