private void CreatePlanAndSubscription(RecurringGift gift, StripeAccount account, MinistryPlatformContext mpDB, StripeOnboardingContext stripeDB)
        {
            var plan = _paymentService.CreatePlan(MapToRecurringGiftDto(gift), MapToContactDonor(gift));
            var subscription = _paymentService.CreateSubscription(plan.Id, account.StripeCustomer.CustomerId, GetStartDate(gift));
            UpdateRecurringGiftAndDonorAccount(gift, account, subscription, mpDB, stripeDB);

        }
 private StripeAccount GetStripeAccount(StripeOnboardingContext db, int? personId, string last4)
 {
     return
         (from a in db.StripeAccounts
             where a.StripeCustomer.ExternalPersonId == personId.ToString() && a.Last4 == last4 && a.StripeCustomer.Imported == false
             select a).FirstOrDefault();
 }
 private void CreatePlanAndSubscriptions(MinistryPlatformContext mpDB, StripeOnboardingContext stripeDB)
 {
     foreach (var gift in GetActiveNoneProcessedRecurringGifts(mpDB))
     {
         var account = GetStripeAccount(stripeDB, gift.Donor.C__ExternalPersonID, gift.DonorAccount.Account_Number);
         CreatePlanAndSubscription(gift, account, mpDB, stripeDB);
     }
 }
示例#4
0
 private static void ImportCustomerAndAccounts(StripeOnboardingContext db, Dictionary<string, StripeJsonCustomer> customersMap)
 {
     foreach (var customerDetails in customersMap)
     {
         var customer = ImportCustomer(db, customerDetails.Value);
         ImportAccounts(customerDetails.Value, customer);
         db.SaveChanges();
     }
 }
 public Messages generate()
 {
     using (var stripeDB = new StripeOnboardingContext())
     using (var mpDB = new MinistryPlatformContext())
     {
         CreatePlanAndSubscriptions(mpDB, stripeDB);
         return Messages.PlansAndSubscriptionsSuccess;
     }
 }
示例#6
0
        public static KeyValuePair<Messages, StripeJsonExport> ImportFile(StripeJsonExport jsonExport)
        {
            using (var db = new StripeOnboardingContext())
            {
                DumbDatabaseContent(db);
                ImportCustomerAndAccounts(db, jsonExport.CustomersMap);
            }

            return new KeyValuePair<Messages, StripeJsonExport>(Messages.ImportFileSuccess, jsonExport);
        }
        private void UpdateRecurringGiftAndDonorAccount(RecurringGift gift, StripeAccount account, StripeSubscription subscription,
            MinistryPlatformContext mpDB, StripeOnboardingContext stripeDB)
        {
            gift.Subscription_ID = subscription.Id;
            gift.DonorAccount.Processor_Account_ID = account.NewCardId;
            gift.DonorAccount.Processor_ID = account.StripeCustomer.CustomerId;
            mpDB.SaveChanges();

            account.StripeCustomer.Imported = true;
            stripeDB.SaveChanges();
        }
示例#8
0
        private static StripeCustomer ImportCustomer(StripeOnboardingContext db, StripeJsonCustomer customerDetails)
        {
            var customer = new StripeCustomer
            {
                CustomerId = customerDetails.NewCustomerId,
                ExternalPersonId = customerDetails.OldCustomerId,
                Imported = false,
            };


            db.StripeCustomers.Add(customer);
            return customer;
        }
示例#9
0
 private static void DumbDatabaseContent(StripeOnboardingContext db)
 {
     db.Database.ExecuteSqlCommand("DELETE FROM [StripeAccounts]; DELETE FROM [StripeCustomers];");
 }