Exemplo n.º 1
0
        public void TestExecuteSuccess()
        {
            var details = new JobDetails <CheckScannerBatch>
            {
                Data = new CheckScannerBatch
                {
                    Name      = "batch123",
                    ProgramId = 111,
                    MinistryPlatformContactId = 222,
                    MinistryPlatformUserId    = 333
                },
                EnqueuedDateTime  = DateTime.Now,
                RetrievedDateTime = DateTime.Now.AddMinutes(1)
            };

            var batchResult = new CheckScannerBatch();

            _checkScannerService.Setup(mocked => mocked.CreateDonationsForBatch(details.Data)).Returns(batchResult);
            _emailService.Setup(
                mocked => mocked.SendEmail(
                    It.Is <EmailCommunicationDTO>(
                        o =>
                        o.FromUserId == 333 && o.FromContactId == 222 && o.TemplateId == 123 && o.ToContactId == 222 && (int)o.MergeData["programId"] == 111 &&
                        o.MergeData["batchName"].Equals("batch123") && o.MergeData.ContainsKey("batch")
                        ),
                    null));

            _fixture.Execute(details);
        }
Exemplo n.º 2
0
        public void TestUpdateBatchStatus()
        {
            var batch = new CheckScannerBatch
            {
                Status = BatchStatus.NotExported
            };

            _checkScannerDao.Setup(mocked => mocked.UpdateBatchStatus("batch123", BatchStatus.Exported)).Returns(batch);

            var result = _fixture.UpdateBatchStatus("batch123", BatchStatus.Exported);

            _checkScannerDao.VerifyAll();

            Assert.IsNotNull(result);
            Assert.AreSame(batch, result);
        }
        public IHttpActionResult CreateDonationsForBatch([FromBody] CheckScannerBatch batch)
        {
            return(Authorized(token =>
            {
                if (!_asynchronous)
                {
                    return (Ok(_checkScannerService.CreateDonationsForBatch(batch)));
                }

                batch.MinistryPlatformContactId = _authenticationService.GetContactId(token);
                batch.MinistryPlatformUserId = _communicationService.GetUserIdFromContactId(token, batch.MinistryPlatformContactId.Value);

                var message = _messageFactory.CreateMessage(batch);
                _donationsQueue.Send(message);
                return (Ok(batch));
            }));
        }
Exemplo n.º 4
0
        public void TestCreateDonationsForBatch()
        {
            var batch = new CheckScannerBatch
            {
                Name      = "batch123",
                ProgramId = 987
            };

            var batchResult = new CheckScannerBatch
            {
                Name      = "batch123",
                ProgramId = 987,
            };

            batchResult.Checks.Add(new CheckScannerCheck
            {
                AccountNumber = "111",
                RoutingNumber = "222"
            });
            batchResult.Checks.Add(new CheckScannerCheck
            {
                AccountNumber = "333",
                RoutingNumber = "444"
            });
            _checkScannerService.Setup(mocked => mocked.CreateDonationsForBatch(batch)).Returns(batchResult);

            var result = _fixture.CreateDonationsForBatch(batch);

            _checkScannerService.VerifyAll();
            _messageFactory.VerifyAll();
            _messageQueueFactory.VerifyAll();
            Assert.NotNull(result);
            Assert.IsInstanceOf <OkNegotiatedContentResult <CheckScannerBatch> >(result);
            var okResult = (OkNegotiatedContentResult <CheckScannerBatch>)result;

            Assert.IsNotNull(okResult.Content);
            Assert.AreSame(batchResult, okResult.Content);
        }
Exemplo n.º 5
0
        public IHttpActionResult CreateDonationsForBatch([FromBody] CheckScannerBatch batch)
        {
            return(Authorized(token =>
            {
                if (!_asynchronous)
                {
                    return (Ok(_checkScannerService.CreateDonationsForBatch(batch)));
                }

                // US6745 - Only finance person receives email instead of the user who imports the batch
                if (_crossroadsFinanceClerkContactId > 0)
                {
                    batch.MinistryPlatformContactId = _crossroadsFinanceClerkContactId;
                    batch.MinistryPlatformUserId = _communicationService.GetUserIdFromContactId(batch.MinistryPlatformContactId.Value);

                    var message = _messageFactory.CreateMessage(batch);

                    _donationsQueue.Send(message);
                }

                return (Ok(batch));
            }));
        }
Exemplo n.º 6
0
        public CheckScannerBatch CreateDonationsForBatch(CheckScannerBatch batchDetails)
        {
            var checks = _checkScannerDao.GetChecksForBatch(batchDetails.Name);

            foreach (var check in checks)
            {
                if (check.Exported)
                {
                    var previousError = string.IsNullOrWhiteSpace(check.Error) ? string.Empty : string.Format("Previous Error: {0}", check.Error);
                    var msg           = string.Format("Not exporting check {0} on batch {1}, it was already exported. {2}", check.Id, batchDetails.Name, previousError);
                    _logger.Info(msg);
                    check.Error = msg;
                    batchDetails.ErrorChecks.Add(check);
                    continue;
                }

                try
                {
                    var contactDonor = CreateDonor(check);

                    var account      = _mpDonorService.DecryptCheckValue(check.AccountNumber);
                    var routing      = _mpDonorService.DecryptCheckValue(check.RoutingNumber);
                    var encryptedKey = _mpDonorService.CreateHashedAccountAndRoutingNumber(account, routing);

                    string donorAccountId = "";

                    if (contactDonor.Account.HasPaymentProcessorInfo() == false)
                    {
                        var stripeCustomer = _paymentService.CreateCustomer(null, contactDonor.DonorId + " Scanned Checks");

                        var stripeCustomerSource = _paymentService.AddSourceToCustomer(stripeCustomer.id, contactDonor.Account.Token);

                        donorAccountId = _mpDonorService.CreateDonorAccount(null,
                                                                            routing,
                                                                            account.Right(4),
                                                                            encryptedKey,
                                                                            contactDonor.DonorId,
                                                                            stripeCustomerSource.id,
                                                                            stripeCustomer.id).ToString();

                        contactDonor.Account = new MpDonorAccount
                        {
                            DonorAccountId     = int.Parse(donorAccountId),
                            ProcessorId        = stripeCustomer.id,
                            ProcessorAccountId = stripeCustomerSource.id
                        };
                    }
                    else
                    {
                        donorAccountId = contactDonor.Account.DonorAccountId.ToString();
                    }

                    //Always use the customer ID and source ID from the Donor Account, if it exists
                    var charge = _paymentService.ChargeCustomer(contactDonor.Account.ProcessorId, contactDonor.Account.ProcessorAccountId, check.Amount, contactDonor.DonorId, check.CheckNumber);

                    var fee = charge.BalanceTransaction != null ? charge.BalanceTransaction.Fee : null;

                    // Mark the check as exported now, so we don't double-charge a community member.
                    // If the CreateDonationAndDistributionRecord fails, we'll still consider it exported, but
                    // it will be in error, and will have to be manually resolved.
                    check.Exported = true;

                    var programId = batchDetails.ProgramId == null ? null : batchDetails.ProgramId + "";

                    var donationAndDistribution = new MpDonationAndDistributionRecord
                    {
                        DonationAmt           = check.Amount,
                        FeeAmt                = fee,
                        DonorId               = contactDonor.DonorId,
                        ProgramId             = programId,
                        ChargeId              = charge.Id,
                        PymtType              = "check",
                        ProcessorId           = contactDonor.Account.ProcessorId,
                        SetupDate             = check.CheckDate ?? (check.ScanDate ?? DateTime.Now),
                        RegisteredDonor       = contactDonor.RegisteredUser,
                        DonorAcctId           = donorAccountId,
                        CheckScannerBatchName = batchDetails.Name,
                        CheckNumber           = (check.CheckNumber ?? string.Empty).TrimStart(' ', '0').Right(MinistryPlatformCheckNumberMaxLength)
                    };

                    var donationId = _mpDonorService.CreateDonationAndDistributionRecord(donationAndDistribution, false);

                    check.DonationId = donationId;

                    _checkScannerDao.UpdateCheckStatus(check.Id, true);

                    batchDetails.Checks.Add(check);
                }
                catch (Exception e)
                {
                    check.Error         = e.ToString();
                    check.AccountNumber = _mpDonorService.DecryptCheckValue(check.AccountNumber);
                    check.RoutingNumber = _mpDonorService.DecryptCheckValue(check.RoutingNumber);
                    batchDetails.ErrorChecks.Add(check);
                    _checkScannerDao.UpdateCheckStatus(check.Id, check.Exported, check.Error);
                }
            }

            batchDetails.Status = BatchStatus.Exported;
            _checkScannerDao.UpdateBatchStatus(batchDetails.Name, batchDetails.Status);

            return(batchDetails);
        }