예제 #1
0
        // GET: Subscription
        public ActionResult Index()
        {
            List <SubscriptionProductPlans> prodPlans = new List <SubscriptionProductPlans>();

            var productService = new ProductService();
            var productOptions = new ProductListOptions
            {
                Limit = 5,
            };

            foreach (var prod in productService.List(productOptions))
            {
                var planService = new PlanService();
                var planOptions = new PlanListOptions
                {
                    Limit     = 5,
                    ProductId = prod.Id
                };

                prodPlans.Add(new SubscriptionProductPlans
                {
                    Product = prod,
                    Plan    = planService.List(planOptions)
                });
            }

            return(View(prodPlans));
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <ActionResult> Edit(string id)
        {
            var productService = new ProductService();
            var prod           = await productService.GetAsync(id);

            if (prod == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var planService = new PlanService();
            var planOptions = new PlanListOptions
            {
                Limit     = 3,
                ProductId = prod.Id
            };

            var prodPlans = await planService.ListAsync(planOptions);

            var plan = prodPlans.Data.Find(x => x.ProductId.Equals(prod.Id));

            var model = new SubscriptionPlanViewModel()
            {
                ProductId = prod.Id,
                PlanId    = plan.Id,
                Name      = prod.Name,
                Amount    = Convert.ToString(Convert.ToDecimal(plan.Amount) / 100).ToString(),
                Currency  = plan.Currency,
                Interval  = plan.Interval
            };

            return(View(model));
        }
예제 #3
0
        public PlanServiceTest()
        {
            this.service = new PlanService();

            this.createOptions = new PlanCreateOptions
            {
                Amount   = 123,
                Currency = "usd",
                Interval = "month",
                Nickname = "Plan Nickmame",
                Product  = new PlanProductCreateOptions
                {
                    Name = "Product Name",
                },
            };

            this.updateOptions = new PlanUpdateOptions
            {
                Metadata = new Dictionary <string, string>
                {
                    { "key", "value" },
                },
            };

            this.listOptions = new PlanListOptions
            {
                Limit = 1,
            };
        }
예제 #4
0
        public PlanServiceTest(
            StripeMockFixture stripeMockFixture,
            MockHttpClientFixture mockHttpClientFixture)
            : base(stripeMockFixture, mockHttpClientFixture)
        {
            this.service = new PlanService(this.StripeClient);

            this.createOptions = new PlanCreateOptions
            {
                Amount   = 123,
                Currency = "usd",
                Interval = "month",
                Nickname = "Plan Nickmame",
                Product  = new PlanProductCreateOptions
                {
                    Name = "Product Name",
                },
            };

            this.updateOptions = new PlanUpdateOptions
            {
                Metadata = new Dictionary <string, string>
                {
                    { "key", "value" },
                },
            };

            this.listOptions = new PlanListOptions
            {
                Limit = 1,
            };
        }
예제 #5
0
        public static Stripe.StripeList <Stripe.Plan> ListSubscriptionPlans()
        {
            PlanListOptions options = new PlanListOptions {
                Active = true
            };
            PlanService service = new PlanService();

            return(service.List(options));
        }
예제 #6
0
        public PlanServiceTest(
            StripeMockFixture stripeMockFixture,
            MockHttpClientFixture mockHttpClientFixture)
            : base(stripeMockFixture, mockHttpClientFixture)
        {
            this.service = new PlanService(this.StripeClient);

            this.createOptions = new PlanCreateOptions
            {
                AmountDecimal = 0.01234567890m, // Ensure decimals work
                Currency      = "usd",
                Interval      = "month",
                Nickname      = "Plan Nickmame",
                Product       = new PlanProductCreateOptions
                {
                    Name = "Product Name",
                },
            };

            this.createDecimalTierOptions = new PlanCreateOptions
            {
                Currency = "usd",
                Interval = "month",
                Nickname = "Plan Nickmame",
                Product  = new PlanProductCreateOptions
                {
                    Name = "Product Name",
                },
                Tiers = new List <PlanTierOptions>
                {
                    new PlanTierOptions
                    {
                        UnitAmountDecimal = 0.04m,
                        UpTo = 10,
                    },
                    new PlanTierOptions
                    {
                        UnitAmountDecimal = 0.03m,
                        UpTo = PlanTierUpTo.Inf,
                    },
                },
            };

            this.updateOptions = new PlanUpdateOptions
            {
                Metadata = new Dictionary <string, string>
                {
                    { "key", "value" },
                },
            };

            this.listOptions = new PlanListOptions
            {
                Limit = 1,
            };
        }
예제 #7
0
        public dynamic Listplan()
        {
            StripeConfiguration.ApiKey = APIKey;

            var options = new PlanListOptions {
            };
            var service = new PlanService();

            return(service.List(options));
        }
예제 #8
0
        private StripeList <Plan> GetProductPlans(string productId)
        {
            var service        = new PlanService();
            var serviceOptions = new PlanListOptions
            {
                Product = productId
            };
            StripeList <Plan> plans = service.List(serviceOptions);

            return(plans);
        }
        public List <Plan> StripePlanList()
        {
            var options = new PlanListOptions {
                Limit = 3
            };
            var service = new PlanService();
            //StripeList<Plan> plans = service.List(options);
            var plans = service.List(options).Data;

            return(plans);
        }
예제 #10
0
        public static Subscription CreateCustomer(string email, string payment_method)
        {
            // creating a customer with Stripe API information (https://stripe.com/docs/api/customers/create)
            // below options are sample data
            var options = new CustomerCreateOptions
            {
                Email           = email,
                PaymentMethod   = payment_method,
                InvoiceSettings = new CustomerInvoiceSettingsOptions
                {
                    DefaultPaymentMethod = payment_method,
                },
            };

            //create the customer with above options
            var service = new CustomerService();

            Customer customer;

            try
            {
                customer = service.Create(options);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            // At this point, you may associate the ID of the Customer object with your
            // own internal representation of a customer, if you have one.
            string sample_internal_customerid = "1";
            string StripeCustomerId           = customer.Id;
            string AccountInfoEmail           = customer.Email;

            //connect to the database
            string        cs  = WebConfigurationManager.ConnectionStrings["StripeDatabaseConnectionString"].ConnectionString;
            SqlConnection con = new SqlConnection(cs);

            //insert in db
            string sql = "INSERT INTO [CUSTOMERS](CustomerId, StripeCustomerId, AccountInfoEmail) VALUES('" + sample_internal_customerid + "', '" + StripeCustomerId + "', '" + AccountInfoEmail + "');";

            con.Open();
            SqlCommand cmd = new SqlCommand(sql, con);

            cmd.ExecuteNonQuery();
            con.Close();

            // find all plans (temporary)
            var planListOptions = new PlanListOptions {
                Limit = 3
            };
            var    planListService = new PlanService();
            var    allPlans        = planListService.List(planListOptions);
            string planId          = allPlans.Select(x => x.Id).First(); // for now just retrieving the first plan available. A dropdown will allow selecting the plan

            // get plan by plan id
            var planService = new PlanService();
            var plan        = planService.Get(planId);

            // Subscribe the user to the subscription created
            var items = new List <SubscriptionItemOption> {
                new SubscriptionItemOption {
                    Plan = plan.Id
                }
            };

            var subscriptionOptions = new SubscriptionCreateOptions
            {
                Customer = customer.Id,
                Items    = items
            };

            var          subscriptionService = new SubscriptionService();
            Subscription subscription        = subscriptionService.Create(subscriptionOptions);

            // return subscription object as JSON back to web method
            // return JsonConvert.SerializeObject(subscription);
            return(subscription);
        }