Beispiel #1
0
        public async Task RefundAmountCanEqualAmountPaid()
        {
            await refundTransaction.Save(notificationId, new DateTime(2016, 1, 1), 100, "comment");

            A.CallTo(() => transactionRepository.Add(A <ImportNotificationTransaction> .Ignored))
            .MustHaveHappened(Repeated.Exactly.Once);
        }
        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);
        }
Beispiel #3
0
        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);
        }