public async Task Save_PaymentFullyReceived_SetsReceivedDate() { var transactionDate = new DateTime(2018, 1, 1); A.CallTo(() => importNotificationTransactionCalculator.Balance(notificationId)) .Returns(1000); A.CallTo(() => importNotificationTransactionRepository.GetTransactions(notificationId)) .Returns(new List <ImportNotificationTransaction>() { CreateNotificationTransaction(1000, transactionDate) }); await transaction.Save(notificationId, transactionDate, 1000, PaymentMethod.Card, null, null); Assert.Equal(assessment.Dates.PaymentReceivedDate, transactionDate); }
public async Task Save(Guid notificationId, DateTime date, decimal amount, PaymentMethod paymentMethod, string receiptNumber, string comments) { var transaction = ImportNotificationTransaction.PaymentRecord(notificationId, date, amount, paymentMethod, receiptNumber, comments); var balance = await transactionCalculator.Balance(transaction.NotificationId) - transaction.Credit.GetValueOrDefault() + transaction.Debit.GetValueOrDefault(); var transactions = (await transactionRepository.GetTransactions(transaction.NotificationId)).ToList(); transactions.Add(transaction); var paymentDate = CalculatePaymentReceivedDate(transactions, balance); await UpdatePaymentReceivedDate(paymentDate, notificationId); transactionRepository.Add(transaction); }
public async Task Save(Guid notificationId, DateTime date, decimal amount, string comments) { if (date > SystemTime.UtcNow.Date) { throw new InvalidOperationException( string.Format("Refund date cannot be in the future for notification {0}", notificationId)); } var totalPaid = await transactionCalculator.TotalPaid(notificationId); if (amount > totalPaid) { throw new InvalidOperationException( string.Format("Refund amount cannot exceed total amount paid for notification {0}", notificationId)); } var firstPayment = (await transactionRepository.GetTransactions(notificationId)) .OrderBy(x => x.Date) .FirstOrDefault(x => x.Credit != null); if (firstPayment == null) { throw new InvalidOperationException( string.Format("Can't make a refund for notification {0} when no payments have been made", notificationId)); } if (date < firstPayment.Date) { throw new InvalidOperationException( string.Format("Refund date cannot be before the first payment date for notification {0}", notificationId)); } var transaction = ImportNotificationTransaction.RefundRecord(notificationId, date, amount, comments); var balance = await transactionCalculator.Balance(transaction.NotificationId) - transaction.Credit.GetValueOrDefault() + transaction.Debit.GetValueOrDefault(); var transactions = (await transactionRepository.GetTransactions(transaction.NotificationId)).ToList(); transactions.Add(transaction); var paymentDate = CalculatePaymentReceivedDate(transactions, balance); await UpdatePaymentReceivedDate(paymentDate, notificationId); transactionRepository.Add(transaction); }
public ImportPaymentTransactionTests() { importNotificationTransactionRepository = A.Fake <IImportNotificationTransactionRepository>(); importNotificationTransactionCalculator = A.Fake <IImportNotificationTransactionCalculator>(); importNotificationAssessmentRepository = A.Fake <IImportNotificationAssessmentRepository>(); assessment = new ImportNotificationAssessment(notificationId); A.CallTo(() => importNotificationAssessmentRepository.GetByNotification(notificationId)) .Returns(assessment); A.CallTo(() => importNotificationTransactionCalculator.Balance(notificationId)) .Returns(1000); transaction = new ImportPaymentTransaction( importNotificationTransactionRepository, importNotificationTransactionCalculator, importNotificationAssessmentRepository); }
public async Task <decimal> HandleAsync(GetChargeDue message) { return(await transactionCalculator.Balance(message.ImportNotificationId)); }