Exemple #1
0
        public products_fixture()
        {
            ProductCreateOptions = new StripeProductCreateOptions
            {
                Name = $"test-product-{ Guid.NewGuid() }"
            };

            ProductTwoCreateOptions = new StripeProductCreateOptions
            {
                Name = $"test-product-{ Guid.NewGuid() }"
            };

            ProductUpdateOptions = new StripeProductUpdateOptions
            {
                Name = $"test-product-{ Guid.NewGuid() }"
            };

            var service = new StripeProductService(Cache.ApiKey);

            Product          = service.Create(ProductCreateOptions);
            ProductTwo       = service.Create(ProductTwoCreateOptions);
            ProductUpdated   = service.Update(Product.Id, ProductUpdateOptions);
            ProductRetrieved = service.Get(Product.Id);

            ProductListOptions = new StripeProductListOptions
            {
                Url = Product.Url,
                Ids = new [] { Product.Id, ProductTwo.Id }
            };

            ProductList = service.List(ProductListOptions).ToList();
        }
Exemple #2
0
        public add_plan_to_product_fixture()
        {
            ProductCreateOptions = new StripeProductCreateOptions
            {
                Name = $"test-product-{ Guid.NewGuid() }",
                Type = "service"
            };

            var productService = new StripeProductService(Cache.ApiKey);

            Product = productService.Create(ProductCreateOptions);

            PlanCreateOptions = new StripePlanCreateOptions()
            {
                Nickname  = "plan-name",
                Amount    = 5000,
                Currency  = "usd",
                Interval  = "month",
                ProductId = Product.Id
            };

            var planService = new StripePlanService(Cache.ApiKey);

            Plan          = planService.Create(PlanCreateOptions);
            PlanRetrieved = planService.Get(Plan.Id);
        }
Exemple #3
0
        public StripeProductServiceTest()
        {
            this.service = new StripeProductService();

            this.createOptions = new StripeProductCreateOptions()
            {
                Attributes = new string[]
                {
                    "attr1",
                    "attr2",
                },
                Name = "product name",
                PackageDimensions = new StripePackageDimensionOptions
                {
                    Height = 100,
                    Length = 100,
                    Weight = 100,
                    Width  = 100,
                },
                Type = "good",
            };

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

            this.listOptions = new StripeProductListOptions()
            {
                Limit = 1,
            };
        }
Exemple #4
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);
        }
        public IEnumerable <ProductView> GetProducts()
        {
            SetStripeKey();
            var productService = new StripeProductService();
            StripeList <StripeProduct> productItems = productService.List(
                new StripeProductListOptions()
            {
                Limit = _maximumItemsToReturn
            }
                );

            var jsonProducts = productItems
                               .Select(p => new ProductView {
                Id = p.Id, Name = p.Name, Type = p.Type
            });

            return(jsonProducts);
        }
Exemple #6
0
        public products_fixture()
        {
            ProductCreateOptions = new StripeProductCreateOptions
            {
                Name = $"test-product-{ Guid.NewGuid() }",
                Type = "good",
                PackageDimensions = new StripePackageDimensionOptions {
                    Height = 100,
                    Length = 100,
                    Weight = 100,
                    Width  = 100,
                },
                Attributes = new string[] { "color", "size" },
            };

            ProductTwoCreateOptions = new StripeProductCreateOptions
            {
                Name = $"test-product-{ Guid.NewGuid() }",
                Type = "good",
            };

            ProductUpdateOptions = new StripeProductUpdateOptions
            {
                Name = $"test-product-{ Guid.NewGuid() }",
            };

            var service = new StripeProductService(Cache.ApiKey);

            Product          = service.Create(ProductCreateOptions);
            ProductTwo       = service.Create(ProductTwoCreateOptions);
            ProductUpdated   = service.Update(Product.Id, ProductUpdateOptions);
            ProductRetrieved = service.Get(Product.Id);

            ProductListOptions = new StripeProductListOptions
            {
                Url = Product.Url,
                Ids = new [] { Product.Id, ProductTwo.Id }
            };

            ProductList = service.List(ProductListOptions);

            service.Delete(Product.Id);
            service.Delete(ProductTwo.Id);
        }
        public ActionResult Create([Bind(Include = "Id,Name")] Product product)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    product.Id = Guid.NewGuid();
                    StripeConfiguration.SetApiKey("sk_test_ILBG36E21hK6nO8C6fOpQvWs");
                    var service = new StripeProductService();
                    //var products = service.Create(new StripeProductCreateOptions
                    //{
                    //    Name = product.Name,
                    //    Active = true,
                    //    Type= "service"
                    //});
                    //product.StripeProductId = products.Id;
                    var options = new StripePlanCreateOptions
                    {
                        Product = new StripePlanProductCreateOptions
                        {
                            Name = product.Name
                        },
                        Amount   = 5000,
                        Currency = "usd",
                        Interval = "month",
                    };

                    var        services = new StripePlanService();
                    StripePlan plan     = services.Create(options);
                    product.PlanId          = plan.Id;
                    product.StripeProductId = plan.ProductId;
                    db.Products.Add(product);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }


            return(View(product));
        }
Exemple #8
0
        public tiered_plan_fixture()
        {
            ProductCreateOptions = new StripeProductCreateOptions
            {
                Name = $"test-product-{ Guid.NewGuid() }",
                Type = "service"
            };

            var productService = new StripeProductService(Cache.ApiKey);
            var product        = productService.Create(ProductCreateOptions);
            var tiers          = new List <StripePlanTierOptions>
            {
                new StripePlanTierOptions()
                {
                    Amount = 1000,
                    UpTo   = new StripePlanTierOptions.UpToBound()
                    {
                        Bound = 10
                    }
                },
                new StripePlanTierOptions()
                {
                    Amount = 2000,
                    UpTo   = new StripePlanTierOptions.UpToInf()
                }
            };

            PlanCreateOptions = new StripePlanCreateOptions()
            {
                Nickname      = "tiered-plan-name",
                BillingScheme = "tiered",
                TiersMode     = "volume",
                Tiers         = tiers,
                Currency      = "usd",
                Interval      = "month",
                ProductId     = product.Id
            };

            var planService = new StripePlanService(Cache.ApiKey);

            Plan          = planService.Create(PlanCreateOptions);
            PlanRetrieved = planService.Get(Plan.Id);
        }
Exemple #9
0
        public orders_fixture()
        {
            var productService = new StripeProductService(Cache.ApiKey);
            var product        = productService.Create(new StripeProductCreateOptions {
                Name = "T-shirt",
                Type = "good"
            });

            var skuService = new StripeSkuService(Cache.ApiKey);
            var sku        = skuService.Create(new StripeSkuCreateOptions
            {
                Currency  = "usd",
                Inventory = new StripeInventoryOptions {
                    Type = "infinite",
                },
                Price   = 1234,
                Product = product.Id
            });

            OrderCreateOptions = new StripeOrderCreateOptions()
            {
                Currency = "usd",
                Items    = new List <StripeOrderItemOptions>
                {
                    new StripeOrderItemOptions
                    {
                        Amount      = 1,
                        Description = "Blue Shirts",
                        Parent      = sku.Id,
                        Quantity    = 1
                    },
                },
                Shipping = new StripeShippingOptions
                {
                    Name  = "Namey Namerson",
                    Line1 = "123 Main St"
                }
            };

            OrderUpdateOptions = new StripeOrderUpdateOptions
            {
                Metadata = new Dictionary <string, string>()
                {
                    { "some-key", "some-value" }
                }
            };

            var customer = Cache.GetCustomer();

            OrderPayOptions = new StripeOrderPayOptions
            {
                SourceId = "tok_visa",
                Email    = customer.Email,
            };

            var service = new StripeOrderService(Cache.ApiKey);

            Order          = service.Create(OrderCreateOptions);
            OrderUpdated   = service.Update(Order.Id, OrderUpdateOptions);
            OrderRetrieved = service.Get(Order.Id);
            OrderPaid      = service.Pay(Order.Id, OrderPayOptions);

            OrderListOptions = new StripeOrderListOptions()
            {
                Created = Order.Created
            };

            OrderList = service.List(OrderListOptions);
        }
Exemple #10
0
 public SubscriptionService()
 {
     _subscriptionService = new StripeSubscriptionService();
     _planService         = new StripePlanService();
     _productService      = new StripeProductService();
 }
Exemple #11
0
        public skus_fixture()
        {
            var productService = new StripeProductService(Cache.ApiKey);

            Product = productService.Create(new StripeProductCreateOptions {
                Name        = "T-shirt",
                Type        = "good",
                Description = "stripe-dotnet product description",
                Attributes  = new string[] { "size", "color" },
            });

            SkuCreateOptions = new StripeSkuCreateOptions
            {
                Id         = $"test-sku-{ Guid.NewGuid() }",
                Attributes = new Dictionary <string, string>
                {
                    { "size", "medium" },
                    { "color", "red" },
                },
                Currency  = "usd",
                Inventory = new StripeInventoryOptions {
                    Quantity = 100,
                    Type     = "finite",
                },
                PackageDimensions = new StripePackageDimensionOptions {
                    Height = 100,
                    Length = 100,
                    Weight = 100,
                    Width  = 100,
                },
                Price   = 1234,
                Product = Product.Id
            };

            SkuTwoCreateOptions = new StripeSkuCreateOptions
            {
                Id         = $"test-sku-{ Guid.NewGuid() }",
                Attributes = new Dictionary <string, string>
                {
                    { "size", "large" },
                    { "color", "blue" },
                },
                Currency  = "usd",
                Inventory = new StripeInventoryOptions {
                    Type = "infinite",
                },
                Price   = 1345,
                Product = Product.Id
            };

            SkuUpdateOptions = new StripeSkuUpdateOptions
            {
                Price = 9999,
            };

            var service = new StripeSkuService(Cache.ApiKey);

            Sku          = service.Create(SkuCreateOptions);
            SkuTwo       = service.Create(SkuTwoCreateOptions);
            SkuUpdated   = service.Update(Sku.Id, SkuUpdateOptions);
            SkuRetrieved = service.Get(Sku.Id);

            var SkuListOptions = new StripeSkuListOptions
            {
                Attributes = new Dictionary <string, string>
                {
                    { "size", "large" },
                },
                Product = Product.Id
            };

            SkuList = service.List(SkuListOptions);

            service.Delete(Sku.Id);
            service.Delete(SkuTwo.Id);
            productService.Delete(Product.Id);
        }