Пример #1
0
        /// <summary>
        /// Deletes a plan from Stripe
        /// NOTE: Delete the model from the underlying context after calling this method
        /// </summary>
        /// <param name="plan"></param>
        public static void DeletePlan(IStripeSubscriptionPlan plan)
        {
            var planService = new StripePlanService();
            planService.Delete(plan.PaymentSystemId);

            System.Diagnostics.Trace.TraceInformation("Deleting plan in stripe: '{0}' with id '{1}", plan.Title, plan.PaymentSystemId);

            plan.PaymentSystemId = null;
        }
Пример #2
0
 public async Task<dynamic> GetPlans()
 {
     return await Task.Factory.StartNew(() =>
     {
         var forPlans = new StripePlanService(Cohort.Site.Stripe.SecretKey);
         var plans = forPlans.List();
         return new { Plans = plans };
     });
 }
Пример #3
0
        /// <summary>
        /// Updates the given plan
        /// NOTE: Due to limitatons with Stripe, this can only update the name of the plan
        /// </summary>
        /// <param name="plan"></param>
        public static void UpdatePlan(IStripeSubscriptionPlan plan)
        {
            StripePlanUpdateOptions options = new StripePlanUpdateOptions();
            options.Name = plan.Title;

            StripePlanService planService = new StripePlanService();
            planService.Update(plan.PaymentSystemId, options);

            System.Diagnostics.Trace.TraceInformation("Updated plan in stripe: '{0}' with id '{1}'", plan.Title, plan.PaymentSystemId);
        }
        // GET: InitPlans
        public ActionResult Index()
        {
            var myFreePlan = new StripePlanCreateOptions();
            myFreePlan.Id = "free_plan";
            myFreePlan.Amount = 0;           // all amounts on Stripe are in cents, pence, etc
            myFreePlan.Currency = "usd";        // "usd" only supported right now
            myFreePlan.Interval = "month";      // "month" or "year"
            myFreePlan.IntervalCount = 1;       // optional
            myFreePlan.Name = "Basic Plan";
            myFreePlan.TrialPeriodDays = 1;    // amount of time that will lapse before the customer is billed

            var myBasicPlan = new StripePlanCreateOptions();
            myBasicPlan.Id = "basic_plan";
            myBasicPlan.Amount = 0;           // all amounts on Stripe are in cents, pence, etc
            myBasicPlan.Currency = "usd";        // "usd" only supported right now
            myBasicPlan.Interval = "month";      // "month" or "year"
            myBasicPlan.IntervalCount = 1;       // optional
            myBasicPlan.Name = "Basic Plan";
            myBasicPlan.TrialPeriodDays = 1;    // amount of time that will lapse before the customer is billed

            var myProfessionalPlan = new StripePlanCreateOptions();
            myProfessionalPlan.Id = "pro_plan";
            myProfessionalPlan.Amount = 999;           // all amounts on Stripe are in cents, pence, etc
            myProfessionalPlan.Currency = "usd";        // "usd" only supported right now
            myProfessionalPlan.Interval = "month";      // "month" or "year"
            myProfessionalPlan.IntervalCount = 1;       // optional
            myProfessionalPlan.Name = "Professional Plan";
            myProfessionalPlan.TrialPeriodDays = 1;    // amount of time that will lapse before the customer is billed

            var myBuinessPlan = new StripePlanCreateOptions();
            myBuinessPlan.Id = "business_plan";
            myBuinessPlan.Amount = 1999;           // all amounts on Stripe are in cents, pence, etc
            myBuinessPlan.Currency = "usd";        // "usd" only supported right now
            myBuinessPlan.Interval = "month";      // "month" or "year"
            myBuinessPlan.IntervalCount = 1;       // optional
            myBuinessPlan.Name = "Business Plan";
            myBuinessPlan.TrialPeriodDays = 1;    // amount of time that will lapse before the customer is billed

            var planService = new StripePlanService();
            StripePlan response = planService.Create(myFreePlan);
            StripePlan response2 = planService.Create(myBasicPlan);
            StripePlan response3 = planService.Create(myProfessionalPlan);
            StripePlan response4 = planService.Create(myBuinessPlan);

            CreateCoupon();

            return View();
        }
Пример #5
0
        /// <summary>
        /// Creates a new plan inside of Stripe, using the given subscription plan's information
        /// </summary>
        /// <param name="plan"></param>
        public static void CreatePlan(IStripeSubscriptionPlan plan)
        {
            // Save it to Stripe
            StripePlanCreateOptions newStripePlanOptions = new StripePlanCreateOptions();
            newStripePlanOptions.Amount = Convert.ToInt32(plan.Price * 100.0); // all amounts on Stripe are in cents, pence, etc
            newStripePlanOptions.Currency = string.IsNullOrEmpty(plan.Currency) ?  "usd" : plan.Currency;                                 // "usd" only supported right now
            newStripePlanOptions.Interval = "month";                               // "month" or "year"
            newStripePlanOptions.IntervalCount = 1;                                // optional
            newStripePlanOptions.Name = plan.Title;
            newStripePlanOptions.TrialPeriodDays = plan.TrialDays;     // amount of time that will lapse before the customer is billed
            newStripePlanOptions.Id = plan.PaymentSystemId;

            StripePlanService planService = new StripePlanService();
            StripePlan newPlan = planService.Create(newStripePlanOptions);
            plan.PaymentSystemId = newPlan.Id;

            System.Diagnostics.Trace.TraceInformation("Created new plan in stripe: '{0}' with id {1}", plan.Title, plan.PaymentSystemId);
        }
        public ActionResult Index()
        {
            StripeConfiguration.SetApiKey("sk_test_JRb9hXgh80838IRQQTUHwJPP");

            var planService = new StripePlanService("sk_test_JRb9hXgh80838IRQQTUHwJPP");
            IEnumerable<StripePlan> plan = planService.List();

            foreach (StripePlan value in plan)
            {
                System.Diagnostics.Debug.Write(value.Name);
            }






            return View();
        }
Пример #7
0
        // GET api/plan
        public HttpResponseMessage Get()
        {
            try
            {
                var planService = new StripePlanService();
                IEnumerable<StripePlan> response = planService.List(50); // can optionally pass count (defaults to 10) and offset
                return Request.CreateResponse(HttpStatusCode.OK, response);
            }
            catch (StripeException ex)
            {
                emailHelper.SendStripeError(ex);
            }
            catch (Exception e)
            {
                emailHelper.SendErrorEmail(e);
            }
            return Request.CreateResponse(HttpStatusCode.BadRequest);

        }
Пример #8
0
        private StripePlan CreatePlan(NewDonationModel model)
        {
            var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
            var currentUser = manager.FindById(User.Identity.GetUserId());


            var myPlan = new StripePlanCreateOptions();
            myPlan.Amount = (int)(model.Amount*100);
            myPlan.Currency = "usd";
            myPlan.Interval = "month";
            myPlan.Name = currentUser.FirstName + "-" + currentUser.LastName + "-" + model.Amount + "-" + model.Category;
            myPlan.Id = currentUser.FirstName + "-" + currentUser.LastName + "-" + model.Amount + "-" + model.Category;

            var planService = new StripePlanService("sk_test_yPi2XADkAP3wiS1i6tkjErxZ");
            return planService.Create(myPlan);
        }
Пример #9
0
 public PlanService(IPaymentsModel paymentsModel, StripePlanService stripePlanService)
 {
     this.db = paymentsModel;
     this.stripePlanService = stripePlanService;
 }