Пример #1
0
        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 ImportRefundTransactionTests()
        {
            transactionRepository = A.Fake<IImportNotificationTransactionRepository>();
            transactionCalculator = A.Fake<IImportNotificationTransactionCalculator>();
            refundTransaction = new ImportRefundTransaction(transactionRepository, transactionCalculator);
            notificationId = new Guid("DB476D01-2870-4322-8284-520B34D9667B");

            A.CallTo(() => transactionCalculator.TotalPaid(notificationId)).Returns(100);
            A.CallTo(() => transactionRepository.GetTransactions(notificationId))
                .Returns(new[]
                {
                    ImportNotificationTransaction.PaymentRecord(notificationId, new DateTime(2015, 12, 1), 100,
                        PaymentMethod.Cheque, "12345", "comments"),
                });

            SystemTime.Freeze(new DateTime(2016, 1, 1));
        }
        public async Task <AccountOverviewData> HandleAsync(GetImportNotificationAccountOverview message)
        {
            var assessment = await notificationAssessmentRepository.GetByNotification(message.ImportNotificationId);

            var charge = await chargeCalculator.GetValue(message.ImportNotificationId);

            var transactions = await transactionRepository.GetTransactions(message.ImportNotificationId);

            var totalPaid = await transactionCalculator.TotalPaid(message.ImportNotificationId);

            return(new AccountOverviewData
            {
                TotalCharge = charge,
                TotalPaid = totalPaid,
                Transactions = transactions.Select(t => mapper.Map <TransactionRecordData>(t)).ToArray(),
                PaymentReceived = assessment.Dates.PaymentReceivedDate
            });
        }
Пример #4
0
        public ImportRefundTransactionTests()
        {
            transactionRepository = A.Fake <IImportNotificationTransactionRepository>();
            transactionCalculator = A.Fake <IImportNotificationTransactionCalculator>();
            assessmentRepository  = A.Fake <IImportNotificationAssessmentRepository>();
            refundTransaction     = new ImportRefundTransaction(transactionRepository, transactionCalculator, assessmentRepository);
            notificationId        = new Guid("DB476D01-2870-4322-8284-520B34D9667B");

            A.CallTo(() => transactionCalculator.TotalPaid(notificationId)).Returns(100);
            A.CallTo(() => transactionRepository.GetTransactions(notificationId))
            .Returns(new[]
            {
                ImportNotificationTransaction.PaymentRecord(notificationId, new DateTime(2015, 12, 1), 100,
                                                            PaymentMethod.Cheque, "12345", "comments"),
            });

            var assessment = new ImportNotificationAssessment(notificationId);

            A.CallTo(() => assessmentRepository.GetByNotification(notificationId))
            .Returns(assessment);

            SystemTime.Freeze(new DateTime(2016, 1, 1));
        }
Пример #5
0
 public async Task TotalPaid_ReturnsCorrectValue()
 {
     Assert.Equal(TotalCredits - TotalDebits, await transactionCalculator.TotalPaid(Guid.Empty));
 }