private void InvoicePaymentFailed(DateTime?created, StripeInvoice invoice)
        {
            _mpDonorRepository.ProcessRecurringGiftDecline(invoice.Subscription);
            var gift = _mpDonorRepository.GetRecurringGiftForSubscription(invoice.Subscription);

            if (gift.ConsecutiveFailureCount > 2)
            {
                var subscription = _paymentProcessorService.CancelSubscription(gift.StripeCustomerId, gift.SubscriptionId);
                _paymentProcessorService.CancelPlan(subscription.Plan.Id);
                _mpDonorRepository.CancelRecurringGift(gift.RecurringGiftId.Value);
            }
        }
Example #2
0
        private void InvoicePaymentFailed(DateTime?created, StripeInvoice invoice)
        {
            var charge = _paymentProcessorService.GetCharge(invoice.Charge);
            var notes  = "No Stripe Failure Code";

            if (charge != null)
            {
                notes = $"{charge.FailureCode ?? "No Stripe Failure Code"}: {charge.FailureMessage ?? "No Stripe Failure Message"}";
            }
            _mpDonorRepository.ProcessRecurringGiftDecline(invoice.Subscription, notes);
            var gift = _mpDonorRepository.GetRecurringGiftForSubscription(invoice.Subscription);

            if (gift.ConsecutiveFailureCount > 2)
            {
                var subscription = _paymentProcessorService.CancelSubscription(gift.StripeCustomerId, gift.SubscriptionId);
                _paymentProcessorService.CancelPlan(subscription.Plan.Id);
                _mpDonorRepository.CancelRecurringGift(gift.RecurringGiftId.Value);
            }
        }