public void TestProcessStripeEventNoMatchingEventHandler() { var e = new StripeEvent { LiveMode = true, Type = "not.this.one" }; Assert.IsNull(_fixture.ProcessStripeEvent(e)); _paymentService.VerifyAll(); _donationService.VerifyAll(); }
public void TestProcessStripeEventLiveModeMismatch() { var e = new StripeEvent { LiveMode = false }; var result = _fixture.ProcessStripeEvent(e); Assert.IsInstanceOf<OkResult>(result); _stripeEventService.VerifyAll(); _messageQueueFactory.VerifyAll(); _messageFactory.VerifyAll(); }
public void TestChargeSucceeded() { var e = new StripeEvent { LiveMode = true, Type = "charge.succeeded", Created = DateTime.Now.AddDays(-1), Data = new StripeEventData { Object = JObject.FromObject(new StripeCharge { Id = "9876" }) } }; _donationService.Setup(mocked => mocked.UpdateDonationStatus("9876", 888, e.Created, null)).Returns(123); Assert.IsNull(_fixture.ProcessStripeEvent(e)); _paymentService.VerifyAll(); _donationService.VerifyAll(); }
public void TestChargeFailed() { var e = new StripeEvent { LiveMode = true, Type = "charge.failed", Created = DateTime.Now.AddDays(-1), Data = new StripeEventData { Object = JObject.FromObject(new StripeCharge { Id = "9876", FailureCode = "invalid_routing_number", FailureMessage = "description from stripe" }) } }; _donationService.Setup(mocked => mocked.UpdateDonationStatus("9876", 777, e.Created, "invalid_routing_number: description from stripe")).Returns(123); _donationService.Setup(mocked => mocked.ProcessDeclineEmail("9876")); Assert.IsNull(_fixture.ProcessStripeEvent(e)); _paymentService.VerifyAll(); _donationService.VerifyAll(); }
public void TestInvoicePaymentFailedCancelPlanAndSubscription() { const string processorId = "cus_123"; const string donorAccountProcessorId = "cus_456"; const string subscriptionId = "sub_123"; const int failCount = 3; const int recurringGiftId = 123456; const int donorId = 3421; const int frequency = 2; const string id = "9876"; const string charge = "ch_2468"; const string planId = "Donor ID #3421 weekly"; var e = new StripeEvent { LiveMode = true, Type = "invoice.payment_failed", Created = DateTime.Now.AddDays(-1), Data = new StripeEventData { Object = JObject.FromObject(new StripeInvoice() { Id = id, Customer = processorId, Charge = charge, Subscription = subscriptionId }) } }; var gift = new CreateDonationDistDto { Frequency = frequency, RecurringGiftId = recurringGiftId, SubscriptionId = subscriptionId, ConsecutiveFailureCount = failCount, DonorId = donorId, StripeCustomerId = donorAccountProcessorId }; var plan = new StripePlan { Id = planId }; var subscription = new StripeSubscription { Plan = plan }; _mpDonorService.Setup(mocked => mocked.ProcessRecurringGiftDecline(subscriptionId)); _mpDonorService.Setup(mocked => mocked.GetRecurringGiftForSubscription(subscriptionId)).Returns(gift); _paymentService.Setup(mocked => mocked.CancelSubscription(donorAccountProcessorId, subscriptionId)).Returns(subscription); _paymentService.Setup(mocked => mocked.CancelPlan(subscription.Plan.Id)).Returns(plan); _mpDonorService.Setup(mocked => mocked.CancelRecurringGift(recurringGiftId)); Assert.IsNull(_fixture.ProcessStripeEvent(e)); _fixture.ProcessStripeEvent(e); _donorService.VerifyAll(); _mpDonorService.VerifyAll(); _donorService.VerifyAll(); _paymentService.VerifyAll(); }
public void TestInvoicePaymentFailedNoCancel() { const string processorId = "cus_123"; const string id = "9876"; const string subscriptionId = "sub_123"; const string charge = "ch_2468"; const int recurringGiftId = 123456; var e = new StripeEvent { LiveMode = true, Type = "invoice.payment_failed", Created = DateTime.Now.AddDays(-1), Data = new StripeEventData { Object = JObject.FromObject(new StripeInvoice() { Id = id, Customer = processorId, Charge = charge, Subscription = subscriptionId }) } }; var gift = new CreateDonationDistDto { Frequency = 1, RecurringGiftId = recurringGiftId }; _mpDonorService.Setup(mocked => mocked.ProcessRecurringGiftDecline(subscriptionId)); _mpDonorService.Setup(mocked => mocked.GetRecurringGiftForSubscription(subscriptionId)).Returns(gift); Assert.IsNull(_fixture.ProcessStripeEvent(e)); _fixture.ProcessStripeEvent(e); _mpDonorService.VerifyAll(); }
public void TestTransferPaid() { var e = new StripeEvent { LiveMode = true, Type = "transfer.paid", Created = DateTime.Now.AddDays(-1), Data = new StripeEventData { Object = JObject.FromObject(new StripeTransfer { Id = "tx9876", Amount = 1443 }) } }; var charges = new List<StripeCharge> { new StripeCharge { Id = "ch111", Amount = 111, Fee = 1, Type = "charge" }, new StripeCharge { Id = "ch222", Amount = 222, Fee = 2, Type = "charge" }, new StripeCharge { Id = "ch333", Amount = 333, Fee = 3, Type = "charge" }, new StripeCharge { Id = "ch777", Amount = 777, Fee = 7, Type = "charge" }, new StripeCharge { Id = "ch444", Amount = 444, Fee = 4, Type = "charge" }, new StripeCharge { Id = "ch555", Amount = 555, Fee = 5, Type = "refund" } }; _donationService.Setup(mocked => mocked.GetDonationByProcessorPaymentId("ch111")).Returns(new DonationDTO { Id = "1111", BatchId = null }); _donationService.Setup(mocked => mocked.GetDonationByProcessorPaymentId("ch222")).Returns(new DonationDTO { Id = "2222", BatchId = null }); _donationService.Setup(mocked => mocked.GetDonationByProcessorPaymentId("ch333")).Returns(new DonationDTO { Id = "3333", BatchId = null }); _donationService.Setup(mocked => mocked.GetDonationByProcessorPaymentId("ch444")).Throws(new Exception("Not gonna do it, wouldn't be prudent.")); _paymentService.Setup(mocked => mocked.GetChargeRefund("ch555")).Returns(new StripeRefund { Data = new List<StripeRefundData> { new StripeRefundData() { Id = "ch555", Amount = "987", Charge = new StripeCharge { Id = "re_123456" } } } }); _donationService.Setup(mocked => mocked.GetDonationByProcessorPaymentId("ch555")).Returns(new DonationDTO { Id = "5555", BatchId = 1984 }); _donationService.Setup(mocked => mocked.GetDonationBatch(1984)).Returns(new DonationBatchDTO { Id = 5150, ProcessorTransferId = "OU812" }); _donationService.Setup(mocked => mocked.GetDonationByProcessorPaymentId("ch777")).Returns(new DonationDTO { Id = "7777", BatchId = 2112 }); _donationService.Setup(mocked => mocked.GetDonationBatch(2112)).Returns(new DonationBatchDTO { Id = 2112, ProcessorTransferId = null }); _donationService.Setup(mocked => mocked.GetDonationBatchByProcessorTransferId("tx9876")).Returns((DonationBatchDTO)null); _paymentService.Setup(mocked => mocked.GetChargesForTransfer("tx9876")).Returns(charges); _donationService.Setup( mocked => mocked.CreatePaymentProcessorEventError(e, It.IsAny<StripeEventResponseDTO>())); _donationService.Setup(mocked => mocked.UpdateDonationStatus(1111, 999, e.Created, null)).Returns(1111); _donationService.Setup(mocked => mocked.UpdateDonationStatus(2222, 999, e.Created, null)).Returns(2222); _donationService.Setup(mocked => mocked.UpdateDonationStatus(3333, 999, e.Created, null)).Returns(3333); _donationService.Setup(mocked => mocked.UpdateDonationStatus(7777, 999, e.Created, null)).Returns(7777); _donationService.Setup(mocked => mocked.CreateDeposit(It.IsAny<DepositDTO>())).Returns( (DepositDTO o) => { o.Id = 98765; return (o); }); _donationService.Setup(mocked => mocked.CreateDonationBatch(It.IsAny<DonationBatchDTO>())).Returns((DonationBatchDTO o) => o); var result = _fixture.ProcessStripeEvent(e); Assert.IsNotNull(result); Assert.IsInstanceOf<TransferPaidResponseDTO>(result); var tp = (TransferPaidResponseDTO)result; Assert.AreEqual(6, tp.TotalTransactionCount); Assert.AreEqual(4, tp.SuccessfulUpdates.Count); Assert.AreEqual(charges.GetRange(0, 4).Select(charge => charge.Id), tp.SuccessfulUpdates); Assert.AreEqual(2, tp.FailedUpdates.Count); Assert.AreEqual("ch444", tp.FailedUpdates[0].Key); Assert.AreEqual("Not gonna do it, wouldn't be prudent.", tp.FailedUpdates[0].Value); Assert.AreEqual("ch555", tp.FailedUpdates[1].Key); Assert.IsNotNull(tp.Batch); Assert.IsNotNull(tp.Deposit); Assert.IsNotNull(tp.Exception); _donationService.Verify(mocked => mocked.CreateDonationBatch(It.Is<DonationBatchDTO>(o => o.BatchName.Matches(@"MP\d{12}") && o.SetupDateTime == o.FinalizedDateTime && o.BatchEntryType == 555 && o.ItemCount == 4 && o.BatchTotalAmount == ((111 + 222 + 333 + 777) / Constants.StripeDecimalConversionValue) && o.Donations != null && o.Donations.Count == 4 && o.DepositId == 98765 && o.ProcessorTransferId.Equals("tx9876") ))); _donationService.Verify(mocked => mocked.CreateDeposit(It.Is<DepositDTO>(o => o.DepositName.Matches(@"MP\d{12}") && !o.Exported && o.AccountNumber.Equals(" ") && o.BatchCount == 1 && o.DepositDateTime != null && o.DepositTotalAmount == (1456 / Constants.StripeDecimalConversionValue) && o.ProcessorFeeTotal == (13 / Constants.StripeDecimalConversionValue) && o.DepositAmount == (1443 / Constants.StripeDecimalConversionValue) && o.Notes == null && o.ProcessorTransferId.Equals("tx9876") ))); _paymentService.VerifyAll(); _donationService.VerifyAll(); }
public void TestTransferPaidNoChargesFound() { var e = new StripeEvent { LiveMode = true, Type = "transfer.paid", Created = DateTime.Now.AddDays(-1), Data = new StripeEventData { Object = JObject.FromObject(new StripeTransfer { Id = "tx9876", }) } }; _donationService.Setup(mocked => mocked.GetDonationBatchByProcessorTransferId("tx9876")).Returns((DonationBatchDTO)null); _paymentService.Setup(mocked => mocked.GetChargesForTransfer("tx9876")).Returns(new List<StripeCharge>()); var result = _fixture.ProcessStripeEvent(e); Assert.IsNotNull(_fixture.ProcessStripeEvent(e)); Assert.IsInstanceOf<TransferPaidResponseDTO>(result); var tp = (TransferPaidResponseDTO)result; Assert.AreEqual(0, tp.TotalTransactionCount); Assert.AreEqual(0, tp.SuccessfulUpdates.Count); Assert.AreEqual(0, tp.FailedUpdates.Count); _paymentService.VerifyAll(); _donationService.VerifyAll(); }
public void TestProcessEventSynchronously() { var e = new StripeEvent { LiveMode = true, Type = "charge.succeeded", Created = DateTime.Now.AddDays(-1), Data = new StripeEventData { Object = JObject.FromObject(new StripeCharge { Id = "9876" }) } }; var expectedResponse = new StripeEventResponseDTO(); _stripeEventService.Setup(mocked => mocked.ProcessStripeEvent(e)).Returns(expectedResponse); var result = _fixture.ProcessStripeEvent(e); Assert.IsInstanceOf<RestHttpActionResult<StripeEventResponseDTO>>(result); Assert.AreEqual(HttpStatusCode.OK, ((RestHttpActionResult<StripeEventResponseDTO>)result).StatusCode); var dto = ((RestHttpActionResult<StripeEventResponseDTO>) result).Content; Assert.IsNotNull(dto); Assert.AreSame(expectedResponse, dto); _stripeEventService.VerifyAll(); _messageQueueFactory.VerifyAll(); _messageFactory.VerifyAll(); }
public void TestCreatePaymentProcessorEventError() { var stripeEvent = new StripeEvent { Created = DateTime.Now, Data = new StripeEventData { Object = new StripeTransfer { Amount = 1000 } }, LiveMode = true, Id = "123", Type = "transfer.paid" }; var stripeEventResponse = new StripeEventResponseDTO { Exception = new ApplicationException() }; var eventString = JsonConvert.SerializeObject(stripeEvent, Formatting.Indented); var responseString = JsonConvert.SerializeObject(stripeEventResponse, Formatting.Indented); _mpDonationService.Setup( mocked => mocked.CreatePaymentProcessorEventError(stripeEvent.Created, stripeEvent.Id, stripeEvent.Type, eventString, responseString)); _fixture.CreatePaymentProcessorEventError(stripeEvent, stripeEventResponse); _mpDonationService.VerifyAll(); }
public void CreatePaymentProcessorEventError(StripeEvent stripeEvent, StripeEventResponseDTO stripeEventResponse) { _mpDonationService.CreatePaymentProcessorEventError(stripeEvent.Created, stripeEvent.Id, stripeEvent.Type, JsonConvert.SerializeObject(stripeEvent, Formatting.Indented), JsonConvert.SerializeObject(stripeEventResponse, Formatting.Indented)); }