Beispiel #1
0
        public void ShouldCreateDonationBatchObject()
        {
            var timestamp     = DateTime.Now;
            var donationsMock = MpDonationsMock.CreateList();
            var chargesMock   = PaymentDtoMock.CreateList();
            var expectedBatch = new DonationBatchDto
            {
                BatchName           = "depositName",
                SetupDateTime       = timestamp,
                BatchTotalAmount    = 90,
                ItemCount           = 3,
                BatchEntryType      = 10,
                FinalizedDateTime   = timestamp,
                DepositId           = null,
                ProcessorTransferId = "transferId"
            };

            _donationRepository.Setup(r => r.GetDonationByTransactionCode("1a")).Returns(donationsMock[0]);
            _donationRepository.Setup(r => r.GetDonationByTransactionCode("2b")).Returns(donationsMock[0]);
            _donationRepository.Setup(r => r.GetDonationByTransactionCode("3c")).Returns(donationsMock[0]);

            var result = _fixture.CreateDonationBatch(chargesMock, "depositName", timestamp, "transferId");

            Assert.Equal(expectedBatch.SetupDateTime, timestamp);
            Assert.Equal(expectedBatch.FinalizedDateTime, timestamp);
            Assert.Equal(expectedBatch.ItemCount, result.ItemCount);
            Assert.Equal(expectedBatch.BatchTotalAmount, result.BatchTotalAmount);
        }
        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);
        }