Ejemplo n.º 1
0
        public void ChargeFailed(DateTime?eventTimestamp, StripeCharge charge)
        {
            _logger.Debug("Processing charge.failed event for charge id " + charge.Id);
            var notes = $"{charge.FailureCode ?? "No Stripe Failure Code"}: {charge.FailureMessage ?? "No Stripe Failure Message"}";

            _donationService.UpdateDonationStatus(charge.Id, _donationStatusDeclined, eventTimestamp, notes);
            _donationService.ProcessDeclineEmail(charge.Id);

            // Create a refund if it is a bank account failure
            if (charge.Source != null && "bank_account".Equals(charge.Source.Object) && charge.Refunds?.Data != null && charge.Refunds.Data.Any())
            {
                var refundData = _paymentProcessorService.GetRefund(charge.Refunds.Data[0].Id);
                _donationService.CreateDonationForBankAccountErrorRefund(new StripeRefund {
                    Data = new List <StripeRefundData> {
                        refundData
                    }
                });
            }
        }
Ejemplo n.º 2
0
        private StripeCharge GetStripeCharge(DonationDTO donation)
        {
            if (string.IsNullOrWhiteSpace(donation.Source.PaymentProcessorId))
            {
                return(null);
            }

            // If it is a positive amount, it means it's a Charge, otherwise it's a Refund
            if (donation.Amount >= 0)
            {
                return(_paymentService.GetCharge(donation.Source.PaymentProcessorId));
            }

            var refund = _paymentService.GetRefund(donation.Source.PaymentProcessorId);

            if (refund != null && refund.Charge != null)
            {
                return(refund.Charge);
            }

            return(null);
        }