예제 #1
0
        public void TestCreateDonorWithDonorId()
        {
            var check = new CheckScannerCheck
            {
                Id            = 11111,
                DonorId       = 222,
                AccountNumber = "111",
                Address       = new crds_angular.Models.Crossroads.Stewardship.Address
                {
                    Line1      = "1 line 1",
                    Line2      = "1 line 2",
                    City       = "1 city",
                    State      = "1 state",
                    PostalCode = "1 postal"
                },
                Amount        = 1111,
                CheckDate     = DateTime.Now.AddHours(1),
                CheckNumber   = "11111",
                Name1         = "1 name 1",
                Name2         = "1 name 2",
                RoutingNumber = "1010",
                ScanDate      = DateTime.Now.AddHours(2)
            };

            var contactDonorExisting = new MpContactDonor
            {
                ContactId      = 123,
                ProcessorId    = "111000111",
                DonorId        = 111111,
                RegisteredUser = true,
                Account        = new MpDonorAccount
                {
                    ProcessorId        = "111000111",
                    ProcessorAccountId = "111111"
                }
            };

            _donorService.Setup(mocked => mocked.GetContactDonorForDonorId(check.DonorId.Value)).Returns(contactDonorExisting);
            _donorService.Setup(mocked => mocked.GetContactDonorForDonorAccount(check.AccountNumber, check.RoutingNumber)).Returns(contactDonorExisting);

            var result = _fixture.CreateDonor(check);

            _donorService.VerifyAll();
            Assert.NotNull(result);
            Assert.AreEqual(contactDonorExisting, result);
        }
        public IHttpActionResult CreateDonor([FromBody] CheckScannerCheck checkDetails)
        {
            return(Authorized(token =>
            {
                var authResult = CheckToken(token);
                if (authResult != null)
                {
                    return (authResult);
                }

                try
                {
                    var result = _checkScannerService.CreateDonor(checkDetails);
                    return (Ok(result));
                }
                catch (PaymentProcessorException e)
                {
                    return (RestHttpActionResult <ApiErrorDto> .WithStatus(HttpStatusCode.MethodNotAllowed, new ApiErrorDto("Could not create checking account at payment processor", e)));
                }
            }));
        }
예제 #3
0
        public void TestCreateForCreateDonorAccount()
        {
            var check = new CheckScannerCheck
            {
                Id            = 11111,
                DonorId       = 222,
                AccountNumber = "P/H+3ccB0ZssORkd+YyJzA==",
                Address       = new crds_angular.Models.Crossroads.Stewardship.Address
                {
                    Line1      = "1 line 1",
                    Line2      = "1 line 2",
                    City       = "1 city",
                    State      = "1 state",
                    PostalCode = "1 postal"
                },
                Amount        = 1111,
                CheckDate     = DateTime.Now.AddHours(1),
                CheckNumber   = "11111",
                Name1         = "1 name 1",
                Name2         = "1 name 2",
                RoutingNumber = "TUbiKZ/Vw1l6uyGCYIIUMg==",
                ScanDate      = DateTime.Now.AddHours(2)
            };

            var contactDonorByDonorId = new MpContactDonor
            {
                ProcessorId = "333000333",
                DonorId     = 333333,
                ContactId   = 3333
            };

            var contactDonorNew = new MpContactDonor
            {
                ProcessorId    = "222000222",
                DonorId        = 222222,
                RegisteredUser = false,
                Account        = new MpDonorAccount
                {
                    ProcessorAccountId = "py_dgsttety6737hjjhweiu3"
                }
            };
            var token = new StripeToken
            {
                Id = "12t4token"
            };
            const string encryptedKey = "PH/rty1234";
            const string decrypAcct   = "6015268542";
            const string decryptRout  = "042000314";

            _donorService.Setup(mocked => mocked.GetContactDonorForDonorId(check.DonorId.Value)).Returns(contactDonorByDonorId);
            _donorService.Setup(mocked => mocked.GetContactDonorForDonorAccount(check.AccountNumber, check.RoutingNumber)).Returns((MpContactDonor)null);
            _mpDonorService.Setup(mocked => mocked.DecryptCheckValue(check.AccountNumber)).Returns(decrypAcct);
            _mpDonorService.Setup(mocked => mocked.DecryptCheckValue(check.RoutingNumber)).Returns(decryptRout);
            _paymentService.Setup(mocked => mocked.CreateToken(decrypAcct, decryptRout, check.Name1)).Returns(token);

            _donorService.Setup(
                mocked =>
                mocked.CreateOrUpdateContactDonor(
                    It.Is <MpContactDonor>(
                        o =>
                        o.Details.DisplayName.Equals(check.Name1) && o.Details.Address.Line1.Equals(check.Address.Line1) && o.Details.Address.Line2.Equals(check.Address.Line2) &&
                        o.Details.Address.City.Equals(check.Address.City) && o.Details.Address.State.Equals(check.Address.State) && o.Details.Address.PostalCode.Equals(check.Address.PostalCode) &&
                        o.Account == null),
                    string.Empty,
                    string.Empty,
                    string.Empty,
                    string.Empty,
                    null,
                    It.IsAny <DateTime>()))
            .Returns(contactDonorNew);

            _mpDonorService.Setup(mocked => mocked.CreateHashedAccountAndRoutingNumber(decrypAcct, decryptRout)).Returns(encryptedKey);
            _mpDonorService.Setup(mocked => mocked.UpdateDonorAccount(encryptedKey, contactDonorNew.Account.ProcessorAccountId, contactDonorNew.ProcessorId));

            var result = _fixture.CreateDonor(check);

            _donorService.VerifyAll();
            Assert.NotNull(result);
            Assert.AreEqual(contactDonorNew, result);
            Assert.AreEqual(decryptRout, result.Account.RoutingNumber);
            Assert.AreEqual(decrypAcct, result.Account.AccountNumber);
            Assert.AreEqual(AccountType.Checking, result.Account.Type);
        }
예제 #4
0
        public MpContactDonor CreateDonor(CheckScannerCheck checkDetails)
        {
            MpContactDonor mpContactDonorById = null;

            // If scanned check has a donor id, try to use it to lookup the donor
            if (checkDetails.DonorId != null && checkDetails.DonorId > 0)
            {
                mpContactDonorById = _donorService.GetContactDonorForDonorId(checkDetails.DonorId.Value);
            }

            // Get the MpContactDonor and info based off of the account and routing number to see if we need to create a new one
            var contactDonorByAccount = _donorService.GetContactDonorForDonorAccount(checkDetails.AccountNumber, checkDetails.RoutingNumber) ?? new MpContactDonor();

            // if find by mpContact donor id is used then mpContact donor found by id matches mpContact donor
            // found by account and account has stripe token
            if (mpContactDonorById != null && mpContactDonorById.ContactId == contactDonorByAccount.ContactId &&
                contactDonorByAccount.Account.HasPaymentProcessorInfo())
            {
                return(contactDonorByAccount);
            }
            // if find by mpContact donor id is not used then mpContact donor
            // found by account has stripe token
            else if (mpContactDonorById == null && contactDonorByAccount.Account != null && contactDonorByAccount.Account.HasPaymentProcessorInfo())
            {
                return(contactDonorByAccount);
            }

            var contactDonor = mpContactDonorById ?? contactDonorByAccount;

            var account = _mpDonorService.DecryptCheckValue(checkDetails.AccountNumber);
            var routing = _mpDonorService.DecryptCheckValue(checkDetails.RoutingNumber);

            var token        = _paymentService.CreateToken(account, routing, checkDetails.Name1);
            var encryptedKey = _mpDonorService.CreateHashedAccountAndRoutingNumber(account, routing);

            contactDonor.Details = new MpContactDetails
            {
                DisplayName = checkDetails.Name1,
                Address     = new MpPostalAddress
                {
                    Line1      = checkDetails.Address.Line1,
                    Line2      = checkDetails.Address.Line2,
                    City       = checkDetails.Address.City,
                    State      = checkDetails.Address.State,
                    PostalCode = checkDetails.Address.PostalCode
                }
            };

            var newDonor = _donorService.CreateOrUpdateContactDonor(contactDonor, string.Empty, string.Empty, string.Empty, string.Empty, null, DateTime.Now);

            newDonor.Account = new MpDonorAccount
            {
                AccountNumber    = account,
                RoutingNumber    = routing,
                Type             = AccountType.Checking,
                EncryptedAccount = encryptedKey,
                Token            = token.Id
            };

            return(newDonor);
        }