Ejemplo n.º 1
0
        public void ShouldCreateAndReturnDepositObject()
        {
            // Arrange
            var depositName   = "FD20171219";
            var settlementKey = "aaabbb111222";
            var amount        = "1000";

            var settlementEventDto = new SettlementEventDto
            {
                Key         = settlementKey,
                TotalAmount = new AmountDto
                {
                    Amount = amount
                }
            };

            var mpDeposits = new List <MpDeposit>
            {
                new MpDeposit(),
                new MpDeposit()
            };

            _depositRepository.Setup(r => r.GetDepositNamesByDepositName(It.IsAny <string>())).Returns(mpDeposits);

            // Act
            var result = _fixture.CreateDeposit(settlementEventDto, depositName);

            // Assert
            Assert.Equal(settlementKey, result.ProcessorTransferId);
            Assert.Equal(Decimal.Parse(amount), result.DepositTotalAmount);
            Assert.Equal(result.DepositName, depositName + "002");
        }
        public void CreateDeposit(SettlementEventDto settlementEventDto)
        {
            // TODO: Verify logger is working once we get to testing
            //_logger.LogInformation($"Processing transfer.paid event for transfer id: {settlementEventDto.Key}");

            // 1. Check to see if the deposit has already been created.  If we do throw an exception.
            var existingDeposit = _depositService.GetDepositByProcessorTransferId(settlementEventDto.Key);

            if (existingDeposit != null)
            {
                //_logger.LogError($"Deposit already exists for settlement: {settlementEventDto.Key}");
                throw new Exception($"Deposit already exists for settlement: {settlementEventDto.Key}");
            }

            // 2. Get all payments associated with a settlement from Pushpay's API. Throw an exception
            // if none are found.
            var settlementPayments = _pushpayService.GetChargesForTransfer(settlementEventDto.Key);

            if (settlementPayments.items == null || settlementPayments.items.Count <= 0)
            {
                //_logger.LogError($"No charges found for settlement: {settlementEventDto.Key}");
                throw new Exception($"No charges found for settlement: {settlementEventDto.Key}");
            }

            // 3. Create and Save the Batch to MP.
            var donationBatch = _batchService.CreateDonationBatch(settlementPayments.items, settlementEventDto.Name,
                                                                  DateTime.Now, settlementEventDto.Key);
            var savedDonationBatch = _batchService.SaveDonationBatch(donationBatch);

            donationBatch.Id = savedDonationBatch.Id;

            // 4. Update all the donations to have a status of deposited and to be part of the new batch.
            var updateDonations = _donationService.SetDonationStatus(donationBatch.Donations, donationBatch.Id);

            _donationService.Update(updateDonations);

            // 5. Create Deposit with the associated batch (should be one batch for one deposit)
            var deposit = _depositService.CreateDeposit(settlementEventDto, settlementEventDto.Name);

            deposit = _depositService.SaveDeposit(deposit);

            // 6. Update batch with deposit id and name and resave
            donationBatch.DepositId = deposit.Id;
            donationBatch.BatchName = deposit.DepositName + "D";
            _batchService.UpdateDonationBatch(donationBatch);
        }