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, }; }
public async Task <List <SubscriptionPlan> > GetAll() { var products = await productService.ListAsync(); var plans = new List <SubscriptionPlan>(); for (int i = 0; i < products.Count(); i++) { var product = products.ElementAt(i); // Check to see if we've given it an ID yet. if (!product.Metadata.ContainsKey("Id")) { var updateOpts = new ProductUpdateOptions(); updateOpts.Metadata = new Dictionary <string, string>(); updateOpts.Metadata["Id"] = Guid.NewGuid().ToString(); product = await productService.UpdateAsync(product.Id, updateOpts); } var plan = new SubscriptionPlan( Guid.Parse(product.Metadata["Id"]), product.Name, product.Description, BillingReference.Product(product.Id), await GetPrices(product.Id) ); plans.Add(plan); } return(plans); }
public async Task <ActionResult> Edit(SubscriptionPlanViewModel viewModel) { if (ModelState.IsValid) { var productService = new ProductService(); var prod = await productService.GetAsync(viewModel.ProductId); if (prod == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var planService = new PlanService(); var plan = await planService.GetAsync(viewModel.PlanId); if (plan == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var options = new ProductUpdateOptions { Name = viewModel.Name }; Product product = productService.Update(prod.Id, options); return(RedirectToAction("Index")); } return(View(viewModel)); }
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 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))); }
public bool UpdateProduct(ProductUpdateOptions options, string productId) { if (options == null) { return(false); } var product = SearchProduct(new ProductSearchOptions() { ProductId = productId }).SingleOrDefault(); if (product == null) { return(false); } if (!string.IsNullOrWhiteSpace(options.Name)) { product.Name = options.Name; } if (!string.IsNullOrWhiteSpace(options.Description)) { product.Description = options.Description; } if (options.Price != null) { product.Price = options.Price.Value; } if (options.Category != null) { product.Category = options.Category.Value; } if (dbContext.SaveChanges() > 0) { return(true); } return(false); }