public void TestInvoicePaymentSucceeded() { var eventTimestamp = DateTime.Now; const string processorId = "cus_123"; const string subscriptionId = "sub_123"; const string chargeId = "ch_123"; var invoice = new StripeInvoice { Subscription = subscriptionId, Amount = 12300, Charge = chargeId, Customer = processorId, }; const int chargeAmount = 45600; int? feeAmount = 987; var charge = new StripeCharge { Amount = chargeAmount, BalanceTransaction = new StripeBalanceTransaction { Amount = 78900, Fee = feeAmount }, Status = "succeeded" }; _paymentService.Setup(mocked => mocked.GetCharge(chargeId)).Returns(charge); const int donorId = 321; const string programId = "3"; const string paymentType = "Bank"; const int recurringGiftId = 654; const int donorAccountId = 987; const int donationStatus = 4; const decimal amt = 789; var recurringGift = new CreateDonationDistDto { Amount = amt, DonorAccountId = donorAccountId, DonorId = donorId, PaymentType = paymentType, ProgramId = programId, RecurringGiftId = recurringGiftId }; _donorService.Setup(mocked => mocked.GetRecurringGiftForSubscription(subscriptionId)).Returns(recurringGift); _mpDonorService.Setup(mocked => mocked.UpdateRecurringGiftFailureCount(recurringGift.RecurringGiftId.Value, Constants.ResetFailCount)); _mpDonorService.Setup( mocked => mocked.CreateDonationAndDistributionRecord( It.Is<DonationAndDistributionRecord>( d => d.DonationAmt == (int) (chargeAmount/Constants.StripeDecimalConversionValue) && d.FeeAmt == feeAmount && d.DonorId == donorId && d.ProgramId.Equals(programId) && d.PledgeId == null && d.ChargeId.Equals(chargeId) && d.PymtType.Equals(paymentType) && d.ProcessorId.Equals(processorId) && d.RegisteredDonor && !d.Anonymous && d.RecurringGift && d.RecurringGiftId == recurringGiftId && d.DonorAcctId.Equals(donorAccountId+"") && d.CheckScannerBatchName == null && d.DonationStatus == donationStatus && d.CheckNumber == null))).Returns(123); _fixture.InvoicePaymentSucceeded(eventTimestamp, invoice); _paymentService.VerifyAll(); _mpDonorService.VerifyAll(); _donorService.VerifyAll(); }
public void SetDonationSource(DonationDTO donation, StripeCharge charge) { if (donation.Source.SourceType == PaymentType.Cash) { donation.Source.Name = "cash"; } else if (charge != null && charge.Source != null) { donation.Source.AccountNumberLast4 = charge.Source.AccountNumberLast4; if (donation.Source.SourceType != PaymentType.CreditCard || charge.Source.Brand == null) { return; } switch (charge.Source.Brand) { case CardBrand.AmericanExpress: donation.Source.CardType = CreditCardType.AmericanExpress; break; case CardBrand.Discover: donation.Source.CardType = CreditCardType.Discover; break; case CardBrand.MasterCard: donation.Source.CardType = CreditCardType.MasterCard; break; case CardBrand.Visa: donation.Source.CardType = CreditCardType.Visa; break; default: donation.Source.CardType = null; break; } } }
public void testPostToCreateDonationAndDistributionUnauthenticated() { var contactId = 999999; var donationId = 6186818; var charge = new StripeCharge() { Id = "ch_crdscharge86868", BalanceTransaction = new StripeBalanceTransaction() { Fee = 987 } }; var createDonationDTO = new CreateDonationDTO { ProgramId = "3", //crossroads Amount = 86868, DonorId = 394256, EmailAddress = "*****@*****.**", PaymentType = "bank" }; var donor = new ContactDonor { ContactId = contactId, DonorId = 424242, SetupDate = new DateTime(), StatementFreq = "1", StatementMethod = "2", StatementType = "3", ProcessorId = "cus_test1234567", Email = "moc.tset@tset" }; fixture.Request.Headers.Authorization = null; gatewayDonorServiceMock.Setup(mocked => mocked.GetContactDonorForEmail(createDonationDTO.EmailAddress)).Returns(donor); stripeServiceMock.Setup(mocked => mocked.ChargeCustomer(donor.ProcessorId, createDonationDTO.Amount, donor.DonorId)). Returns(charge); donorServiceMock.Setup(mocked => mocked. CreateDonationAndDistributionRecord(It.Is<DonationAndDistributionRecord>( d => d.DonationAmt == createDonationDTO.Amount && d.FeeAmt == charge.BalanceTransaction.Fee && d.DonorId == donor.DonorId && d.ProgramId.Equals(createDonationDTO.ProgramId) && d.PledgeId == null && d.ChargeId.Equals(charge.Id) && d.PymtType.Equals(createDonationDTO.PaymentType) && d.ProcessorId.Equals(donor.ProcessorId) && !d.RegisteredDonor && !d.Anonymous && !d.RecurringGift && d.RecurringGiftId == null && d.DonorAcctId == null && d.CheckScannerBatchName == null && d.DonationStatus == null && d.CheckNumber == null))) .Returns(donationId); IHttpActionResult result = fixture.Post(createDonationDTO); donorServiceMock.VerifyAll(); stripeServiceMock.VerifyAll(); donorServiceMock.VerifyAll(); Assert.IsNotNull(result); Assert.IsInstanceOf(typeof(OkNegotiatedContentResult<DonationDTO>), result); var okResult = (OkNegotiatedContentResult<DonationDTO>)result; Assert.AreEqual(6186818, donationId); var resultDto = ((OkNegotiatedContentResult<DonationDTO>)result).Content; Assert.IsNotNull(resultDto); Assert.AreEqual(donor.Email, resultDto.Email); }
public void testPostToCreateDonationAndDistributionWithPledgeAuthenticated() { var contactId = 999999; var donationId = 6186818; var charge = new StripeCharge() { Id = "ch_crdscharge86868", BalanceTransaction = new StripeBalanceTransaction() { Fee = 987 } }; var createDonationDTO = new CreateDonationDTO { ProgramId = "3", //crossroads Amount = 86868, DonorId = 394256, EmailAddress = "*****@*****.**", PledgeCampaignId = 23, PledgeDonorId = 42, GiftMessage = "Don't look a Gift Horse in the Mouth!", PaymentType = "junk bonds" }; var donor = new ContactDonor { ContactId = contactId, DonorId = 424242, SetupDate = new DateTime(), StatementFreq = "1", StatementMethod = "2", StatementType = "3", ProcessorId = "cus_test1234567", Email = "moc.tset@tset" }; var pledgeId = 3456; var pledge = new Pledge { DonorId = 1, PledgeCampaignId = 2, PledgeId = pledgeId, PledgeStatusId = 1 }; authenticationServiceMock.Setup(mocked => mocked.GetContactId(authType + " " + authToken)).Returns(contactId); donorServiceMock.Setup(mocked => mocked.GetContactDonor(contactId)) .Returns(donor); mpPledgeService.Setup(mocked => mocked.GetPledgeByCampaignAndDonor(createDonationDTO.PledgeCampaignId.Value, createDonationDTO.PledgeDonorId.Value)).Returns(pledge); mpDonationService.Setup(mocked => mocked.SendMessageFromDonor(pledgeId, createDonationDTO.GiftMessage)); stripeServiceMock.Setup( mocked => mocked.ChargeCustomer(donor.ProcessorId, createDonationDTO.Amount, donor.DonorId)) .Returns(charge); donorServiceMock.Setup(mocked => mocked. CreateDonationAndDistributionRecord(It.Is<DonationAndDistributionRecord>( d => d.DonationAmt == createDonationDTO.Amount && d.FeeAmt == charge.BalanceTransaction.Fee && d.DonorId == donor.DonorId && d.ProgramId.Equals(createDonationDTO.ProgramId) && d.PledgeId == pledgeId && d.ChargeId.Equals(charge.Id) && d.PymtType.Equals(createDonationDTO.PaymentType) && d.ProcessorId.Equals(donor.ProcessorId) && d.RegisteredDonor && !d.Anonymous && !d.RecurringGift && d.RecurringGiftId == null && d.DonorAcctId == null && d.CheckScannerBatchName == null && d.DonationStatus == null && d.CheckNumber == null))) .Returns(donationId); IHttpActionResult result = fixture.Post(createDonationDTO); authenticationServiceMock.VerifyAll(); donorServiceMock.VerifyAll(); stripeServiceMock.VerifyAll(); donorServiceMock.VerifyAll(); mpPledgeService.VerifyAll(); Assert.IsNotNull(result); Assert.IsInstanceOf(typeof(OkNegotiatedContentResult<DonationDTO>), result); var okResult = (OkNegotiatedContentResult<DonationDTO>)result; Assert.AreEqual(6186818, donationId); var resultDto = ((OkNegotiatedContentResult<DonationDTO>)result).Content; Assert.IsNotNull(resultDto); Assert.AreEqual(donor.Email, resultDto.Email); }
public void TestCreateDonationsForBatch() { var checks = new List<CheckScannerCheck> { new CheckScannerCheck { Id = 11111, 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 = 111100, CheckDate = DateTime.Now.AddHours(1), CheckNumber = " 0 0 00000222111111111111111", Name1 = "1 name 1", Name2 = "1 name 2", RoutingNumber = "1010", ScanDate = DateTime.Now.AddHours(2) }, new CheckScannerCheck { Id = 22222, AccountNumber = "222", Address = new crds_angular.Models.Crossroads.Stewardship.Address { Line1 = "2 line 1", Line2 = "2 line 2", City = "2 city", State = "2 state", PostalCode = "2 postal" }, Amount = 222200, CheckDate = DateTime.Now.AddHours(3), CheckNumber = "22222", Name1 = "2 name 1", Name2 = "2 name 2", RoutingNumber = "2020", ScanDate = DateTime.Now.AddHours(4) } }; var contactDonorExisting = new ContactDonor { ProcessorId = "111000111", DonorId = 111111, RegisteredUser = true, Account = new DonorAccount { ProcessorAccountId = "py_dgsttety6737hjjhweiu3" } }; const string encryptedKey = "PH/rty1234"; const string decrypAcct = "6015268542"; const string decryptRout = "042000314"; const string donorAcctId = "4321"; _checkScannerDao.Setup(mocked => mocked.GetChecksForBatch("batch123")).Returns(checks); _checkScannerDao.Setup(mocked => mocked.UpdateBatchStatus("batch123", BatchStatus.Exported)).Returns(new CheckScannerBatch()); _checkScannerDao.Setup(mocked => mocked.UpdateCheckStatus(11111, true, null)); _checkScannerDao.Setup(mocked => mocked.UpdateCheckStatus(22222, true, null)); _donorService.Setup(mocked => mocked.GetContactDonorForDonorAccount(checks[0].AccountNumber, checks[0].RoutingNumber)).Returns(contactDonorExisting); _paymentService.Setup(mocked => mocked.ChargeCustomer(contactDonorExisting.ProcessorId, contactDonorExisting.Account.ProcessorAccountId, checks[0].Amount, contactDonorExisting.DonorId)).Returns(new StripeCharge { Id = "1020304", Source = new StripeSource() { id = "py_dgsttety6737hjjhweiu3" }, BalanceTransaction = new StripeBalanceTransaction { Fee = 123 } }); _mpDonorService.Setup(mocked => mocked.DecryptCheckValue(checks[1].AccountNumber)).Returns(decrypAcct); _mpDonorService.Setup(mocked => mocked.DecryptCheckValue(checks[1].RoutingNumber)).Returns(decryptRout); _mpDonorService.Setup(mocked => mocked.CreateHashedAccountAndRoutingNumber(decrypAcct, decryptRout)).Returns(encryptedKey); _mpDonorService.Setup(mocked => mocked.DecryptCheckValue(checks[0].AccountNumber)).Returns(decrypAcct); _mpDonorService.Setup(mocked => mocked.DecryptCheckValue(checks[0].RoutingNumber)).Returns(decryptRout); _mpDonorService.Setup(mocked => mocked.CreateHashedAccountAndRoutingNumber(decrypAcct, decryptRout)).Returns(encryptedKey); _mpDonorService.Setup(mocked => mocked.UpdateDonorAccount(encryptedKey, contactDonorExisting.Account.ProcessorAccountId, contactDonorExisting.ProcessorId)).Returns(donorAcctId); _mpDonorService.Setup( mocked => mocked.CreateDonationAndDistributionRecord( It.Is<DonationAndDistributionRecord>(d => d.DonationAmt == checks[0].Amount && d.FeeAmt == 123 && d.DonorId == contactDonorExisting.DonorId && d.ProgramId.Equals("9090") && d.ChargeId.Equals("1020304") && d.PymtType.Equals("check") && d.ProcessorId.Equals(contactDonorExisting.ProcessorId) && d.SetupDate.Equals(checks[0].CheckDate) && d.RegisteredDonor && d.DonorAcctId == donorAcctId && d.CheckScannerBatchName.Equals("batch123") && d.CheckNumber.Equals("111111111111111")))) .Returns(321); var contactDonorNew = new ContactDonor { ProcessorId = "222000222", DonorId = 222222, RegisteredUser = false, Account = new DonorAccount { ProcessorAccountId = "cus_123456789" } }; var mockCharge = new StripeCharge { Id = "40302010", Source = new StripeSource() { id = "ba_dgsttety6737hjjhweiu3" } }; _donorService.Setup(mocked => mocked.GetContactDonorForDonorAccount(checks[1].AccountNumber, checks[1].RoutingNumber)).Returns((ContactDonor) null); _mpDonorService.Setup(mocked => mocked.DecryptCheckValue(checks[1].AccountNumber)).Returns(decrypAcct); _mpDonorService.Setup(mocked => mocked.DecryptCheckValue(checks[1].RoutingNumber)).Returns(decryptRout); _paymentService.Setup(mocked => mocked.CreateToken(decrypAcct, decryptRout)).Returns("tok123"); _donorService.Setup( mocked => mocked.CreateOrUpdateContactDonor( It.Is<ContactDonor>( o => o.Details.DisplayName.Equals("2 name 1") && o.Details.Address.Line1.Equals("2 line 1") && o.Details.Address.Line2.Equals("2 line 2") && o.Details.Address.City.Equals("2 city") && o.Details.Address.State.Equals("2 state") && o.Details.Address.PostalCode.Equals("2 postal") && o.Account.RoutingNumber.Equals(decryptRout) && o.Account.AccountNumber.Equals(decrypAcct) && o.Account.Type == AccountType.Checking), It.IsAny<string>(), string.Empty, "tok123", It.IsAny<DateTime>())) .Returns(contactDonorNew); _paymentService.Setup(mocked => mocked.ChargeCustomer(contactDonorNew.ProcessorId, contactDonorNew.Account.ProcessorAccountId, checks[1].Amount, contactDonorNew.DonorId)).Returns(mockCharge); _mpDonorService.Setup(mocked => mocked.CreateHashedAccountAndRoutingNumber(decrypAcct, decryptRout)).Returns(encryptedKey); _mpDonorService.Setup(mocked => mocked.UpdateDonorAccount(encryptedKey, mockCharge.Source.id, contactDonorNew.ProcessorId)).Returns(donorAcctId); _mpDonorService.Setup( mocked => mocked.CreateDonationAndDistributionRecord( It.Is<DonationAndDistributionRecord>(d => d.DonationAmt == checks[1].Amount && d.FeeAmt == null && d.DonorId == contactDonorNew.DonorId && d.ProgramId.Equals("9090") && d.ChargeId.Equals("40302010") && d.PymtType.Equals("check") && d.ProcessorId.Equals(contactDonorNew.ProcessorId) && d.SetupDate.Equals(checks[1].CheckDate) && !d.RegisteredDonor && d.DonorAcctId == donorAcctId && d.CheckScannerBatchName.Equals("batch123") && d.CheckNumber.Equals("22222")))) .Returns(654); var result = _fixture.CreateDonationsForBatch(new CheckScannerBatch { Name = "batch123", ProgramId = 9090 }); _checkScannerDao.VerifyAll(); _donorService.VerifyAll(); _mpDonorService.VerifyAll(); _paymentService.VerifyAll(); Assert.NotNull(result); Assert.NotNull(result.Checks); Assert.AreEqual(2, result.Checks.Count); Assert.AreEqual(BatchStatus.Exported, result.Status); }
public void ShouldChargeCustomer() { var charge = new StripeCharge { Id = "90210", BalanceTransaction = new StripeBalanceTransaction { Id = "txn_123", Fee = 145 } }; var stripeResponse = new Mock<IRestResponse<StripeCharge>>(MockBehavior.Strict); stripeResponse.SetupGet(mocked => mocked.ResponseStatus).Returns(ResponseStatus.Completed).Verifiable(); stripeResponse.SetupGet(mocked => mocked.StatusCode).Returns(HttpStatusCode.OK).Verifiable(); stripeResponse.SetupGet(mocked => mocked.Data).Returns(charge).Verifiable(); _restClient.Setup(mocked => mocked.Execute<StripeCharge>(It.IsAny<IRestRequest>())).Returns(stripeResponse.Object); var response = _fixture.ChargeCustomer("cust_token", 9090, 98765); _restClient.Verify(mocked => mocked.Execute<StripeCharge>( It.Is<IRestRequest>(o => o.Method == Method.POST && o.Resource.Equals("charges") && o.Parameters.Matches("amount", 909000) && o.Parameters.Matches("currency", "usd") && o.Parameters.Matches("customer", "cust_token") && o.Parameters.Matches("description", "Donor ID #98765") && o.Parameters.Matches("expand[]", "balance_transaction") ))); _restClient.VerifyAll(); stripeResponse.VerifyAll(); Assert.AreSame(charge, response); }