public ProductServiceTest()
        {
            this.service = new ProductService();

            this.createOptions = new ProductCreateOptions
            {
                Attributes = new []
                {
                    "attr1",
                    "attr2",
                },
                Name = "product name",
                PackageDimensions = new PackageDimensionOptions
                {
                    Height = 100,
                    Length = 100,
                    Weight = 100,
                    Width  = 100,
                },
                Type = "good",
            };

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

            this.listOptions = new ProductListOptions
            {
                Limit = 1,
            };
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Convenience function for running tests. Creates an object and automatically adds it to the queue for deleting after tests finish.
        /// </summary>
        public async Task <Product> Create(bool skipAddToCreateList = false, ProductCreateOptions options = null)
        {
            var obj = await Service.CreateAsync(new Product()
            {
                Title       = Title,
                Vendor      = Vendor,
                BodyHtml    = BodyHtml,
                ProductType = ProductType,
                Handle      = Guid.NewGuid().ToString(),
                Images      = new List <ProductImage>
                {
                    new ProductImage
                    {
                        Attachment = "R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="
                    }
                },
            }, options);

            if (!skipAddToCreateList)
            {
                Created.Add(obj);
            }

            return(obj);
        }
Ejemplo n.º 3
0
        public ProductServiceTest(
            StripeMockFixture stripeMockFixture,
            MockHttpClientFixture mockHttpClientFixture)
            : base(stripeMockFixture, mockHttpClientFixture)
        {
            this.service = new ProductService(this.StripeClient);

            this.createOptions = new ProductCreateOptions
            {
                Name = "product name",
                PackageDimensions = new ProductPackageDimensionsOptions
                {
                    Height = 100,
                    Length = 100,
                    Weight = 100,
                    Width  = 100,
                },
            };

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

            this.listOptions = new ProductListOptions
            {
                Limit = 1,
            };
        }
        public static Product CreateProduct(StripeProductInfoModel model)
        {
            var stripeKey = StripeApiKey();

            var options = new ProductCreateOptions
            {
                Description = model.Description,
                Name        = model.Name,
                Active      = model.Active,
            };

            var service = new ProductService();
            var product = service.Create(options);

            var priceOption = new PriceCreateOptions
            {
                Product    = product.Id,
                UnitAmount = long.Parse(model.Price),
                Currency   = "usd",
            };
            var priceService = new PriceService();
            var price        = priceService.Create(priceOption);

            return(product);
        }
Ejemplo n.º 5
0
        public Task <int> PushProduct(Product product, bool commit = true)
        {
            global::Stripe.Product stripeProduct = null;

            if (!string.IsNullOrWhiteSpace(product.StripeId))
            {
                stripeProduct = _productService.Get(product.StripeId);
            }

            if (stripeProduct != null)
            {
                var options = new ProductUpdateOptions()
                {
                    Url = product.Url,
                    StatementDescriptor = product.StatementDescriptor,
                    Active      = product.IsActive,
                    Caption     = product.Caption,
                    Description = product.Description,
                    Name        = product.Name,
                    Metadata    = new Dictionary <string, string>()
                    {
                        { "ref_id", product.Id.ToString() }
                    },
                };

                stripeProduct = _productService.Update(stripeProduct.Id, options);
            }
            else
            {
                // this is a new product
                var options = new ProductCreateOptions()
                {
                    Type = product.Type,
                    Id   = product.UniqueId,

                    // same as update
                    Name                = product.Name,
                    Url                 = product.Url,
                    Active              = product.IsActive,
                    Caption             = product.Caption,
                    Description         = product.Description,
                    StatementDescriptor = product.StatementDescriptor,
                    Metadata            = new Dictionary <string, string>()
                    {
                        { "ref_id", product.Id.ToString() }
                    }
                };
                stripeProduct = _productService.Create(options);
            }

            product.StripeId    = stripeProduct.Id;
            product.StripeBlob  = JsonConvert.SerializeObject(stripeProduct);
            product.ObjectState = ObjectState.Modified;

            return(Task.FromResult(Repository.InsertOrUpdateGraph(product, commit)));
        }
Ejemplo n.º 6
0
        public Product CreateProduct(Guid clubId, string name)
        {
            var productOptions = new ProductCreateOptions
            {
                Name = clubId + name,
            };
            var productService = new ProductService();
            var product        = productService.Create(productOptions);

            return(product);
        }
Ejemplo n.º 7
0
        // end Charges


        //   step one in subscription process - create a type=service
        //   product [Sm Admin Dashboard ??]
        public Stripe.Product CreateProductTypeService(string ProductName)
        {
            var options = new ProductCreateOptions
            {
                Name = ProductName,
                Type = "service",
            };
            var service = new ProductService();

            return(service.Create(options));
        }
Ejemplo n.º 8
0
        private Stripe.Product CreateStripeProduct(string productName)
        {
            StripeConfiguration.ApiKey = _appKeys.StripeApiKey;
            var options = new ProductCreateOptions
            {
                Name = productName,
            };
            var service = new ProductService();
            var product = service.Create(options);

            return(product);
        }
Ejemplo n.º 9
0
        public IActionResult Post([FromBody] string name)
        {
            var options = new ProductCreateOptions
            {
                Name = name
            };
            var result         = _service.Create(options);
            var serviceGateway = new ServiceGateway();

            serviceGateway.CreateItem(name);
            return(Ok(result));
        }
        public async Task <string> CreateSubcritionProduct()
        {
            StripeConfiguration.ApiKey = this._configuration.GetSection("Stripe")["SecretKey"];


            var productoptions = new ProductCreateOptions
            {
                Name        = "Quick Order Subcription",
                Active      = true,
                Description = "Quick Order Admin System Subcription",
                Type        = "service"
            };


            var productservice = new ProductService();
            var producttoken   = await productservice.CreateAsync(productoptions);


            var priceoptions = new PriceCreateOptions
            {
                UnitAmount = 200,
                Currency   = "usd",
                Recurring  = new PriceRecurringOptions
                {
                    Interval = "month",
                },
                Product = producttoken.Id,
            };
            var priceservice = new PriceService();
            var pricetoken   = await priceservice.CreateAsync(priceoptions);

            if (!string.IsNullOrEmpty(producttoken.Id))
            {
                return(producttoken.Id);
            }
            else
            {
                return(string.Empty);
            }
        }
Ejemplo n.º 11
0
        public ActionResult Create(SubscriptionPlanViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            try
            {
                var productOptions = new ProductCreateOptions
                {
                    Name = viewModel.Name,
                    Type = "service",
                };
                var     productService = new ProductService();
                Product product        = productService.Create(productOptions);

                if (product != null)
                {
                    var planOptions = new PlanCreateOptions();
                    planOptions.Currency  = viewModel.Currency;
                    planOptions.Interval  = viewModel.Interval;
                    planOptions.Nickname  = product.Name;
                    planOptions.Amount    = Convert.ToInt64(Convert.ToDecimal(viewModel.Amount) * 100);
                    planOptions.ProductId = product.Id;

                    var  planService = new PlanService();
                    Plan plan        = planService.Create(planOptions);
                }
            }
            catch (Exception ex)
            {
                var msg = ex.Message;
            }

            return(RedirectToAction("Index"));
        }
        public async Task <string> CreateACustomerSubcription(string customerId)
        {
            try
            {
                StripeConfiguration.ApiKey = this._configuration.GetSection("Stripe")["SecretKey"];

                //==================================================================
                // Create Product Subcription

                var productoptions = new ProductCreateOptions
                {
                    Name        = "Quick Order Subcription",
                    Active      = true,
                    Description = "Quick Order Admin System Subcription",
                    Type        = "service"
                };

                var productservice = new ProductService();
                var producttoken   = await productservice.CreateAsync(productoptions);


                var priceoptions = new PriceCreateOptions
                {
                    UnitAmount = 200,
                    Currency   = "usd",
                    Recurring  = new PriceRecurringOptions
                    {
                        Interval = "month",
                    },
                    Product = producttoken.Id,
                };
                var priceservice      = new PriceService();
                var priceservicetoken = await priceservice.CreateAsync(priceoptions);

                //======================================================================= End Create Product Subcription


                //===================================================================================
                //Create Subcription to store


                var options = new SubscriptionCreateOptions
                {
                    Customer = customerId,
                    Items    = new List <SubscriptionItemOptions>
                    {
                        new SubscriptionItemOptions
                        {
                            Price = priceservicetoken.Id,
                        },
                    },
                };
                var          service      = new SubscriptionService();
                Subscription subscription = await service.CreateAsync(options);

                if (!string.IsNullOrEmpty(subscription.Id))
                {
                    //var newSubcription = new Subcription()
                    //{
                    //    StripeCustomerId = customerId,
                    //    StripeSubCriptionID = subscription.Id
                    //};

                    //_context.Subcriptions.Add(newSubcription);

                    //try
                    //{

                    //_context.SaveChanges();
                    //}
                    //catch (Exception e)
                    //{

                    //    Console.WriteLine(e);
                    //}



                    return(subscription.Id);
                }
                else
                {
                    return(string.Empty);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);

                return(string.Empty);
            }
        }