Пример #1
0
        private IHttpActionResult GetDonorForAuthenticatedUser(string token)
        {
            try
            {
                var donor = _donorService.GetContactDonorForAuthenticatedUser(token);

                if (donor == null || !donor.HasPaymentProcessorRecord)
                {
                    return(NotFound());
                }
                else
                {
                    var defaultSource = _stripePaymentService.GetDefaultSource(donor.ProcessorId);

                    var response = new DonorDTO()
                    {
                        Id            = donor.DonorId,
                        ProcessorId   = donor.ProcessorId,
                        DefaultSource = new DefaultSourceDTO
                        {
                            credit_card = new CreditCardDTO
                            {
                                last4       = defaultSource.last4,
                                brand       = defaultSource.brand,
                                address_zip = defaultSource.address_zip,
                                exp_date    = defaultSource.exp_month + defaultSource.exp_year
                            },
                            bank_account = new BankAccountDTO
                            {
                                last4             = defaultSource.bank_last4,
                                routing           = defaultSource.routing_number,
                                accountHolderName = defaultSource.account_holder_name,
                                accountHolderType = defaultSource.account_holder_type
                            }
                        },
                        RegisteredUser = donor.RegisteredUser,
                        Email          = donor.Email
                    };

                    return(Ok(response));
                }
            }
            catch (PaymentProcessorException stripeException)
            {
                return(stripeException.GetStripeResult());
            }
            catch (Exception exception)
            {
                var apiError = new ApiErrorDto("Donor Get Failed", exception);
                throw new HttpResponseException(apiError.HttpResponseMessage);
            }
        }
Пример #2
0
        public void Verify()
        {
            var appender = VerifyOutput.Logger.Repository.GetAppenders().First(x => x.Name.Equals("VerifyOutputLog"));

            Logger.Info(string.Format("Starting verification process - CSV results will be written to {0}", ((FileAppender)appender).File));
            var markerDateTime   = new DateTime(2001, 01, 01);
            var migratedDateTime = new DateTime(2016, 01, 29);
            var recurringGifts   = _mpContext.RecurringGifts.ToList().Where(gift => !gift.End_Date.HasValue || gift.End_Date.Value.Date.Equals(markerDateTime.Date)).ToList();
            var giftsToProcess   = recurringGifts.Count();

            Logger.Info(string.Format("Verifying {0} recurring gifts", giftsToProcess));

            VerifyOutput.Info("mpRecurringGiftId,stripeSubscriptionId,mpAmount,stripeAmount,mpFrequency,stripeFrequency,mpRepeat,stripeRepeat,mpDonorAccountType,stripeAccountType,mpAccountLast4,stripeAccountLast4,success,errorMessage");

            var giftsProcessed = 0;

            foreach (var gift in recurringGifts)
            {
                var percentComplete = (int)Math.Round((double)(++giftsProcessed * 100.0) / giftsToProcess);

                Logger.Info(string.Format("Processing gift #{0} ({1}% complete)", giftsProcessed, percentComplete));

                var success      = true;
                var errorMessage = string.Empty;

                StripeSubscription sub = null;
                var mpRecurringGiftId  = gift.Recurring_Gift_ID;
                var mpAmount           = gift.Amount;
                var mpFrequency        = gift.Frequency.ToString();
                var mpRepeat           = gift.Frequency == Frequency.Monthly ? gift.Day_Of_Month + "" : gift.DayOfWeek.ToString();
                var mpDonorAccountType = gift.DonorAccount != null?gift.DonorAccount.AccountType.ToString() : Null;

                var mpAccountLast4 = gift.DonorAccount != null ? gift.DonorAccount.Account_Number : Null;

                if (gift.DonorAccount == null || string.IsNullOrWhiteSpace(gift.DonorAccount.Processor_ID) || string.IsNullOrWhiteSpace(gift.Subscription_ID))
                {
                    success      = false;
                    errorMessage = "Recurring gift is missing Stripe processor information";
                }
                else
                {
                    try
                    {
                        sub = _paymentService.GetSubscription(gift.DonorAccount.Processor_ID, gift.Subscription_ID);
                        if (sub == null || string.IsNullOrWhiteSpace(sub.Id))
                        {
                            success      = false;
                            errorMessage = string.Format("Stripe problem: Nothing returned for subscription {0} for customer {1}", gift.Subscription_ID, gift.DonorAccount.Processor_ID);
                        }
                    }
                    catch (Exception e)
                    {
                        success      = false;
                        errorMessage = string.Format("Stripe exception: Could not lookup subscription for customer {0} subscription {1}: {2}",
                                                     gift.DonorAccount.Processor_ID,
                                                     gift.Subscription_ID,
                                                     e.Message);
                        Logger.Error(errorMessage, e);
                    }
                }

                var stripeSubscriptionId = string.IsNullOrWhiteSpace(gift.Subscription_ID) ? Null : gift.Subscription_ID;
                var stripeAmount         = sub == null || sub.Plan == null ? 0.00M : (decimal)(sub.Plan.Amount / 100.00M);
                var freq = sub == null || sub.Plan == null
                    ? null
                    : sub.Plan.Interval.ToLower().Equals("month") ? Frequency.Monthly : sub.Plan.Interval.ToLower().Equals("week") ? Frequency.Weekly : (Frequency?)null;
                var stripeFrequency = freq == null ? Null : freq.ToString();
                var startDate       = sub == null || string.IsNullOrWhiteSpace(sub.CurrentPeriodEnd) ? (DateTime?)null : StripeEpochTime.ConvertEpochToDateTime(long.Parse(sub.CurrentPeriodEnd));
                var stripeRepeat    = freq != null && freq == Frequency.Monthly && startDate != null
                    ? startDate.Value.Day + ""
                    : freq != null && freq == Frequency.Weekly && startDate != null?startDate.Value.DayOfWeek.ToString() : Null;

                var stripeAccountType  = Null;
                var stripeAccountLast4 = Null;
                if (sub != null && !string.IsNullOrWhiteSpace(sub.Customer))
                {
                    try
                    {
                        var source = _paymentService.GetDefaultSource(sub.Customer);
                        if ("card".Equals(source.@object))
                        {
                            stripeAccountType  = AccountType.CreditCard.ToString();
                            stripeAccountLast4 = source.last4;
                        }
                        else if ("bank_account".Equals(source.@object))
                        {
                            stripeAccountType  = AccountType.Bank.ToString();
                            stripeAccountLast4 = source.bank_last4;
                        }
                    }
                    catch (Exception e)
                    {
                        success      = false;
                        errorMessage = string.Format("Could not lookup default source for customer {0}: {1}", sub.Customer, e.Message);
                        Logger.Error(errorMessage, e);
                    }
                }

                if (success)
                {
                    success = mpAmount == stripeAmount && mpFrequency.Equals(stripeFrequency) && mpRepeat.Equals(stripeRepeat) &&
                              mpDonorAccountType.Equals(stripeAccountType) && mpAccountLast4.Equals(stripeAccountLast4);
                    if (!success)
                    {
                        errorMessage = "Field mismatch";
                    }
                }

                LogRecurringGiftComparison(mpRecurringGiftId,
                                           stripeSubscriptionId,
                                           mpAmount,
                                           stripeAmount,
                                           mpFrequency,
                                           stripeFrequency,
                                           mpRepeat,
                                           stripeRepeat,
                                           mpDonorAccountType,
                                           stripeAccountType,
                                           mpAccountLast4,
                                           stripeAccountLast4,
                                           success,
                                           errorMessage);
            }
        }