Пример #1
0
        public transform_usage_plan_fixture()
        {
            ProductCreateOptions = new StripeProductCreateOptions
            {
                Name = $"test-product-{ Guid.NewGuid() }",
                Type = "service"
            };

            var productService = new StripeProductService(Cache.ApiKey);
            var product        = productService.Create(ProductCreateOptions);
            var transformUsage = new StripePlanTransformUsageOptions()
            {
                DivideBy = 100,
                Round    = "up"
            };

            PlanCreateOptions = new StripePlanCreateOptions()
            {
                Nickname       = "tiered-plan-name",
                Amount         = 1000,
                Currency       = "usd",
                Interval       = "month",
                ProductId      = product.Id,
                TransformUsage = transformUsage,
            };

            var planService = new StripePlanService(Cache.ApiKey);

            Plan          = planService.Create(PlanCreateOptions);
            PlanRetrieved = planService.Get(Plan.Id);
        }
Пример #2
0
        public ActionResult DeletePlans(string Plan_ID)
        {
            objResponse Response = new objResponse();

            try
            {
                Response = objSubscriptionManager.DeletePlan(Convert.ToInt64(Plan_ID));

                if (Response.ErrorCode == 0)
                {
                    var planService = new StripePlanService();
                    planService.Delete(Plan_ID);

                    PlanModel objPlanModel = new PlanModel();
                    objPlanModel.plans = objSubscriptionManager.GetPlans();
                    return(View("AjaxAddPlan", objPlanModel));
                }
                else
                {
                    return(Json("", JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                BAL.Common.LogManager.LogError("DeletePlan Post method", 1, Convert.ToString(ex.Source), Convert.ToString(ex.StackTrace), Convert.ToString(ex.Message));
                return(Json("", JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult ManageSubscription()
        {
            var model = new ManageSubscriptionViewModel();

            try
            {
                //GetUptodate plan prices from stripe
                var planService = new StripePlanService(SensativeInformation.StripeKeys.SecretKey);
                var ordPlan     = planService.Get(StaticIdentifiers.OrdinaryMemberPlanId);
                var socialPlan  = planService.Get(StaticIdentifiers.SocialMemberPlanId);
                var patronPlan  = planService.Get(StaticIdentifiers.PatronPlanId);
                if (ordPlan != null)
                {
                    model.OrdinaryPrice = (ordPlan.Amount / 100m).ToString("N");
                }
                if (socialPlan != null)
                {
                    model.SocialPrice = (socialPlan.Amount / 100m).ToString("N");
                }
                if (patronPlan != null)
                {
                    model.PatronPrice = (patronPlan.Amount / 100m).ToString("N");
                }
            }
            catch (StripeException e)
            {
                _log.Error($"There was a stripe error whilst trying to load the current subscriptions prices for the manage membership page. The error was {e.Message}.");
            }
            try
            {
                var stripeAccountId = new Member(Members.GetCurrentMember()).StripeUserId;
                var dm = new DataManager();
                if (stripeAccountId.IsNotNullOrEmpty())
                {
                    model.IsStripeUser            = true;
                    model.HasExistingSubscription = false;
                    //Get plan status
                    var subscriptionService = new StripeSubscriptionService(SensativeInformation.StripeKeys.SecretKey);
                    var listOption          = new StripeSubscriptionListOptions {
                        CustomerId = stripeAccountId
                    };
                    var stripeSubscriptions = subscriptionService.List(listOption);

                    if (stripeSubscriptions != null && stripeSubscriptions.Any())
                    {
                        model.IsOrdinaryMember        = stripeSubscriptions.Any(m => m.StripePlan.Id == StaticIdentifiers.OrdinaryMemberPlanId && m.Status == StripeSubscriptionStatuses.Active);
                        model.IsSocialMember          = stripeSubscriptions.Any(m => m.StripePlan.Id == StaticIdentifiers.SocialMemberPlanId && m.Status == StripeSubscriptionStatuses.Active);
                        model.IsPatron                = stripeSubscriptions.Any(m => m.StripePlan.Id == StaticIdentifiers.PatronPlanId && m.Status == StripeSubscriptionStatuses.Active);
                        model.HasExistingSubscription = stripeSubscriptions.Any(m => m.Status == StripeSubscriptionStatuses.Active);
                    }
                }
            }
            catch (StripeException e)
            {
                _log.Error($"There was a stripe error whilst trying to load the current subscriptions for the managemembership page for user {Members.GetCurrentMember().Name} and id {Members.GetCurrentMember().Id}. The error was {e.Message}.");
            }

            return(PartialView("ManageSubscription", model));
        }
Пример #4
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 };
     }));
 }
        public void UpdateSubscription(string id, string planName)
        {
            var updatedPlan = new StripePlanUpdateOptions();

            updatedPlan.Name = planName;

            var        planService = new StripePlanService();
            StripePlan response    = planService.Update(id, updatedPlan);
        }
Пример #6
0
 public StripePlan GetPlansByPlanId(string planId)
 {
     try
     {
         var        planService = new StripePlanService();
         StripePlan plan        = planService.Get(planId);
         return(plan);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public string CreateSubscription(int cost, string planName, string interval)
        {
            string id      = Guid.NewGuid().ToString();
            var    newPlan = new StripePlanCreateOptions();

            newPlan.Id       = id;
            newPlan.Amount   = cost;         // all amounts on Stripe are in cents, pence, etc
            newPlan.Currency = "usd";        // "usd" only supported right now
            newPlan.Interval = interval;     // "month" or "year"
            newPlan.Name     = planName;

            var        planService = new StripePlanService();
            StripePlan response    = planService.Create(newPlan);

            return(id);
        }