static void TestCreatePlanGetPlan(StripePayment payment) { StripePlan plan = CreatePlan(payment); var plans = payment.GetPlans(10, 10); Console.WriteLine(plans.Total); }
public decimal GetPlanPrice(string planId) { StripePlan plan = GetPlan(planId); decimal result = ((decimal)plan.Amount) / 100; return(result); }
public static async Task <string> CreateInitialPlanAsync(StripePlanCreateOptions options) { StripeConfiguration.SetApiKey("sk_test_5nCTR2UZmnOPWgZASvirbYDy"); StripePlanCreateOptions planOptions = new StripePlanCreateOptions() { Product = new StripePlanProductCreateOptions() { Name = "Initial_test_04_10_18_(1)" }, Active = options.Active, Amount = 1190, BillingScheme = options.BillingScheme, Currency = options.Currency, Interval = options.Interval, IntervalCount = options.IntervalCount, Nickname = options.Nickname, TrialPeriodDays = options.TrialPeriodDays, UsageType = options.UsageType }; StripePlanService planService = new StripePlanService(); StripePlan plan = await planService.CreateAsync(planOptions); return(plan.StripeResponse.ResponseJson); }
private StripePlan GetPlan(string planId) { StripePlanService service = new StripePlanService(); StripePlan result = service.Get(planId); return(result); }
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 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); }
static void TestInvoices2(StripePayment payment) { StripeCustomer cust = payment.GetCustomer("cus_ulcOcy5Seu2dpq"); StripePlanInfo planInfo = new StripePlanInfo { Amount = 1999, ID = "testplan", Interval = StripePlanInterval.Month, Name = "The Test Plan", //TrialPeriod = 7 }; //payment.DeletePlan (planInfo.ID); StripePlan plan = payment.CreatePlan(planInfo); StripeSubscriptionInfo subInfo = new StripeSubscriptionInfo { Card = GetCC(), Plan = planInfo.ID, Prorate = true }; StripeSubscription sub = payment.Subscribe(cust.ID, subInfo); payment.CreateInvoiceItem(new StripeInvoiceItemInfo { CustomerID = cust.ID, Amount = 1337, Description = "Test single charge" }); var invoices = payment.GetInvoices(0, 10, cust.ID); StripeInvoice upcoming = payment.GetUpcomingInvoice(cust.ID); payment.Unsubscribe(cust.ID, true); payment.DeletePlan(planInfo.ID); foreach (StripeLineItem line in upcoming) { Console.WriteLine("{0} for type {1}", line.Amount, line.GetType()); } }
private void StripePlanToPlan(StripePlan stripePlan, Plan plan) { plan.Name = stripePlan.Name; plan.AmountInCents = stripePlan.Amount; plan.Currency = stripePlan.Currency; plan.Interval = stripePlan.Interval; plan.TrialPeriodDays = stripePlan.TrialPeriodDays; }
static void TestCreatePlanGetPlan(StripePayment payment) { StripePlan plan = CreatePlan(payment); int total; List <StripePlan> plans = payment.GetPlans(10, 10, out total); Console.WriteLine(total); }
static StripePlan CreatePlan(StripePayment payment) { StripePlan plan = payment.CreatePlan(GetPlanInfo()); StripePlan plan2 = payment.GetPlan(plan.ID); //DeletePlan (plan2, payment); return(plan2); }
public void UpdateSubscription(string id, string planName) { var updatedPlan = new StripePlanUpdateOptions(); updatedPlan.Name = planName; var planService = new StripePlanService(); StripePlan response = planService.Update(id, updatedPlan); }
public Plan(StripePlan plan) { this.PlanId = plan.Id; this.Amount = plan.Amount / 100; this.Created = plan.Created; this.Currency = plan.Currency; this.Interval = plan.Interval; this.IntervalCount = plan.IntervalCount; this.Name = plan.Name; this.TrialPeriodDays = plan.TrialPeriodDays; }
private static SubscriptionPlan SubscriptionPlanMapper(StripePlan stripePlan) { return(new SubscriptionPlan { Id = stripePlan.Id, Name = stripePlan.Name, Currency = stripePlan.Currency, Interval = GetInterval(stripePlan.Interval), Price = stripePlan.Amount, TrialPeriodInDays = stripePlan.TrialPeriodDays ?? 0, }); }
/// <summary> /// Updates the given plan /// NOTE: Due to limitatons with Stripe, this can only update the name of the plan /// </summary> /// <param name="plan"></param> public static StripePlan UpdatePlan(IPlanEntity plan) { StripePlanUpdateOptions options = new StripePlanUpdateOptions(); options.Name = plan.Title; StripePlanService planService = new StripePlanService(); StripePlan updatedPlan = planService.Update(plan.PaymentSystemId, options); Logger.Log <StripeManager>("Updated plan in stripe: '{0}' with id '{1}'", LogLevel.Information, plan.Title, plan.PaymentSystemId); return(updatedPlan); }
public StripePlan GetPlansByPlanId(string planId) { try { var planService = new StripePlanService(); StripePlan plan = planService.Get(planId); return(plan); } catch (Exception ex) { throw ex; } }
public void Setup() { _client = new StripeClient(Constants.ApiKey); var id = Guid.NewGuid().ToString(); var card = new CreditCard { Number = "4111111111111111", ExpMonth = 3, ExpYear = 2015 }; _plan = _client.CreatePlan(id, 400M, "usd", PlanFrequency.Month, id); _customer = _client.CreateCustomer(card); }
public static StripePlan CreatePlan(StripePlanCreateOptions planOptions) { var invoiceSevice = new StripeInvoiceService(); try { var planService = new StripePlanService(); StripePlan plan = planService.Create(planOptions); return(plan); } catch (Exception ex) { return(null); } }
public static StripePlan GetPlan(string PlanId) { var plan = new StripePlan(); try { var planService = new StripePlanService(); plan = planService.Get(PlanId); return(plan); } catch { return(null); } }
private static Invoice.Plan Map(StripePlan stripePlan) { return(new Invoice.Plan { AmountInCents = stripePlan.Amount, Created = stripePlan.Created, Currency = stripePlan.Currency, StatementDescriptor = stripePlan.StatementDescriptor, Interval = stripePlan.Interval, IntervalCount = stripePlan.IntervalCount, Name = stripePlan.Name, StripePlanId = stripePlan.Id, TrialPeriodDays = stripePlan.TrialPeriodDays }); }
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); }
/**** FROM STRIPE ****/ public static SubscriptionPlan ToSubscriptionPlan(this StripePlan stripePlan) { var plan = new SubscriptionPlan { Id = stripePlan.Id, Name = stripePlan.Nickname, Amount = ((int)stripePlan.Amount).ToDecimalAmount(), Currency = stripePlan.Currency, IntervalCount = stripePlan.IntervalCount, Interval = StripeHelpers.ToStripeInterval(stripePlan.Interval), ProductId = stripePlan.ProductId }; //Product doesn't expand here, but can be contained. return(plan); }
public ActionResult AjaxAddPlan(string PlanName, string PlanType, string PlanPrice, string Features) { objResponse Response = new objResponse(); string planID = Guid.NewGuid().ToString(); try { Response = objSubscriptionManager.AddPlans(PlanName, PlanPrice, PlanType, "usd", planID); if (Response.ErrorCode == 0) { var myPlan = new StripePlanCreateOptions(); myPlan.Id = planID; myPlan.Amount = Convert.ToInt32(PlanPrice) * 100; // all amounts on Stripe are in cents, pence, etc myPlan.Currency = "usd"; // "usd" only supported right now myPlan.Interval = PlanType; // "month" or "year" //myPlan.IntervalCount = 1; // optional myPlan.Name = PlanName; myPlan.TrialPeriodDays = 0; // amount of time that will lapse before the customer is billed var planService = new StripePlanService(); StripePlan response = planService.Create(myPlan); List <string> temp = Features.Split(',').ToList <string>(); foreach (var feature in temp) { Response = objSubscriptionManager.AddPlanFeature(Convert.ToInt32(Response.ErrorMessage), feature); if (Response.ErrorCode != 0) { break; } } PlanModel objPlanModel = new PlanModel(); objPlanModel.plans = objSubscriptionManager.GetPlans(); return(View(objPlanModel)); } else { return(Json("", JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { return(Json("", JsonRequestBehavior.AllowGet)); } }
static void TestCreateSubscription(StripePayment payment) { StripeCustomer cust = payment.CreateCustomer(new StripeCustomerInfo { Card = GetCC() }); //StripePlan temp = new StripePlan { ID = "myplan" }; //DeletePlan (temp, payment); StripePlan plan = CreatePlan(payment); StripeSubscription sub = payment.Subscribe(cust.ID, new StripeSubscriptionInfo { Card = GetCC(), Plan = "myplan", Prorate = true }); StripeSubscription sub2 = payment.GetSubscription(sub.CustomerID); TestDeleteSubscription(cust, payment); DeletePlan(plan, payment); }
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)); }
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); }
public void RetreivePlan(string Api_Key, string planId, ref string Response, ref string Errors, ref int ErrorCode) { try { StripeConfiguration.SetApiKey(Api_Key); var stripePlanService = new StripePlanService(); StripePlan stripePlan = stripePlanService.Get(planId); Response = stripePlan.StripeResponse.ResponseJson; ErrorCode = 0; } catch (StripeException e) { ErrorCode = 1; Serializer serializer = new Serializer(); StripeError stripeError = e.StripeError; Errors = serializer.Serialize <StripeError>(stripeError); } }
/// <summary> /// Creates a new plan inside of Stripe, using the given subscription plan's information /// </summary> /// <param name="plan"></param> public static void CreatePlan(IStripeSubscriptionPlan plan) { // Save it to Stripe StripePlanCreateOptions newStripePlanOptions = new StripePlanCreateOptions(); newStripePlanOptions.Amount = Convert.ToInt32(plan.Price * 100.0); // all amounts on Stripe are in cents, pence, etc newStripePlanOptions.Currency = string.IsNullOrEmpty(plan.Currency) ? "usd" : plan.Currency; // "usd" only supported right now newStripePlanOptions.Interval = "month"; // "month" or "year" newStripePlanOptions.IntervalCount = 1; // optional newStripePlanOptions.Name = plan.Title; newStripePlanOptions.TrialPeriodDays = plan.TrialDays; // amount of time that will lapse before the customer is billed newStripePlanOptions.Id = plan.PaymentSystemId; StripePlanService planService = new StripePlanService(); StripePlan newPlan = planService.Create(newStripePlanOptions); plan.PaymentSystemId = newPlan.Id; System.Diagnostics.Trace.TraceInformation("Created new plan in stripe: '{0}' with id {1}", plan.Title, plan.PaymentSystemId); }
/// <summary> /// Creates a new plan inside of Stripe, using the given subscription plan's information /// NOTE: Unlike other method calls, this requires that the plan object already have a defined PaymentSystemId property set /// </summary> /// <param name="plan"></param> public static StripePlan CreatePlan(IPlanEntity plan) { // Save it to Stripe StripePlanCreateOptions newStripePlanOptions = new StripePlanCreateOptions(); newStripePlanOptions.Amount = Convert.ToInt32(plan.Price * 100.0); // all amounts on Stripe are in cents, pence, etc newStripePlanOptions.Currency = "usd"; // "usd" only supported right now newStripePlanOptions.Interval = "month"; // "month" or "year" newStripePlanOptions.IntervalCount = 1; // optional newStripePlanOptions.Name = plan.Title; newStripePlanOptions.TrialPeriodDays = plan.TrialDays; // amount of time that will lapse before the customer is billed newStripePlanOptions.Id = plan.PaymentSystemId; StripePlanService planService = new StripePlanService(); StripePlan newPlan = planService.Create(newStripePlanOptions); Logger.Log <StripeManager>("Created new plan in stripe: '{0}' with id {1}", LogLevel.Information, plan.Title, plan.PaymentSystemId); return(newPlan); }
public void CreatePlan(string Api_Key, string stripePlanCreateOptionsJSON, ref string Response, ref string Errors, ref int ErrorCode) { try { StripeConfiguration.SetApiKey(Api_Key); Serializer serializer = new Serializer(); StripePlanCreateOptions stripePlanCreateOptions = serializer.Deserialize <StripePlanCreateOptions>(stripePlanCreateOptionsJSON); var stripePlanService = new StripePlanService(); StripePlan stripePlan = stripePlanService.Create(stripePlanCreateOptions); Response = stripePlan.StripeResponse.ResponseJson; ErrorCode = 0; } catch (StripeException e) { ErrorCode = 1; Serializer serializer = new Serializer(); StripeError stripeError = e.StripeError; Errors = serializer.Serialize <StripeError>(stripeError); } }
public void TestPlans() { // Arrange EnsureTestPlansDeleted(); IPlanEntity plan = CreateMockPlanA(); plan.GeneratePaymentSystemId(); // Act - create StripePlan createdPlan = StripeManager.CreatePlan(plan); // Assert - create Assert.IsNotNull(createdPlan); // Act - update plan.Title = "Unit Test Plan - Name Changed"; StripePlan updatedPlan = StripeManager.UpdatePlan(plan); // Assert - update Assert.IsNotNull(updatedPlan); // Act - Delete StripeManager.DeletePlan(plan); // Assert try { StripePlanService planService = new StripePlanService(); planService.Get(TestPlanA_Id); Assert.Fail(); // We should not get to this line } catch (Exception ex) { // We should get an exception that says "No such plan" Assert.IsTrue(ex.Message.Contains("No such plan")); } }