public ActionResult CreatePlan(int Id) { var service = this._serviceRepo.GetServiceById(Id); var options = new PlanCreateOptions { Product = new PlanProductCreateOptions { Name = "Monthly" }, Amount = (long)(service.Rate * 100), Currency = "usd", Interval = "month", }; var planservice = new PlanService(); if (string.IsNullOrEmpty(service.StripePlanName)) { Plan plan = planservice.Create(options); this._serviceRepo.CreateStripPlanForService(Id, plan.Id); } else { Plan existingPlan = planservice.Get(service.StripePlanName); if (existingPlan == null) { Plan plan = planservice.Create(options); this._serviceRepo.CreateStripPlanForService(Id, plan.Id); } } return(RedirectToAction("Index")); }
private long?GetPlanPrice(string planId) { var service = new PlanService(); Plan plan = service.Get(planId); long?planPrice = plan.Amount; return(planPrice); }
public HttpResponseMessage Get(string id) { try { LoggerUtils.WriteLog("PlansController : GET BY ID - request received"); var plan = planService.Get(id); return(Request.CreateResponse(HttpStatusCode.OK, plan)); } catch (Exception ex) { LoggerUtils.WriteLog("ERROR : PlansController : " + ex.Message + "\r" + "InnerException : " + ex.InnerException); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
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); }
public IActionResult Subscription(CustomerPaymentViewModel payment) { string email = HttpContext.Session.GetString("User"); ViewBag.isLoggedIn = 1; try { NewWebSubContext context = HttpContext.RequestServices.GetService(typeof(new_websub.NewWebSubContext)) as NewWebSubContext; string query = "select * from useraccounts u inner join address a on u.AddressId=a.addresskey where u.Email=@Email"; MySqlConnection conn = context.GetConnection(); conn.Open(); MySqlCommand cmd = new MySqlCommand(query, conn); MySqlParameter param = new MySqlParameter("@Email", email); param.MySqlDbType = MySqlDbType.VarChar; cmd.Parameters.Add(param); MySqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { User user = new User(); user.Email = email; user.Id = reader["UserID"].ToString(); user.FullName = reader["UserName"].ToString(); user.StripeCustomerId = ""; user.AddressLine1 = reader["Address1"].ToString(); user.AddressLine2 = reader["Address2"].ToString(); user.City = reader["City"].ToString(); user.State = reader["State"].ToString(); user.Zip = reader["Zipcode"].ToString(); user.Country = reader["Country"].ToString(); user.HistoryView = true; StripeConfiguration.SetApiKey(_stripeSettings.Value.SecretKey); var tokenoptions = new TokenCreateOptions { Card = new CreditCardOptions { Number = payment.CardNumber, ExpYear = payment.ExpiryYear, ExpMonth = payment.ExpiryMonth, Cvc = payment.Cvc } }; var tokenservice = new TokenService(); Token stripeToken = tokenservice.Create(tokenoptions); payment.cardtoken = stripeToken.Id; CustomerCreateOptions customerCreateOptions = GetCustomerCreateOptions(payment, user); var cusservice = new CustomerService(); var customers = cusservice.Create(customerCreateOptions); Subscription subscription; var plservice = new PlanService(); try { var plplan = plservice.Get(payment.subsctype); var items = new List <SubscriptionItemOption> { new SubscriptionItemOption { PlanId = plplan.Id } }; var suboptions = new SubscriptionCreateOptions { CustomerId = customers.Id, Items = items }; var subservice = new SubscriptionService(); subscription = subservice.Create(suboptions); } catch { var options = new PlanCreateOptions { Product = new PlanProductCreateOptions { Id = payment.subsctype, Name = payment.subsctype }, Amount = payment.Amount, Currency = payment.Currency, Interval = payment.subsctype, Id = payment.subsctype }; var service = new PlanService(); Plan plan = service.Create(options); var items = new List <SubscriptionItemOption> { new SubscriptionItemOption { PlanId = plan.Id } }; var suboptions = new SubscriptionCreateOptions { CustomerId = customers.Id, Items = items }; var subservice = new SubscriptionService(); subscription = subservice.Create(suboptions); } reader.Close(); // insert into subscriptions table query = "insert into subscriptions(Email, CustomerId, SubscriptionId, Subscription_Started, Subscription_Ended) values(@Email," + "@CustomerId, @SubscriptionId, @Subscription_Started, @Subscription_Ended)"; MySqlCommand cmd1 = new MySqlCommand(query, conn); MySqlParameter param1 = new MySqlParameter("@Email", user.Email); param1.MySqlDbType = MySqlDbType.VarChar; cmd1.Parameters.Add(param1); param1 = new MySqlParameter("@CustomerId", subscription.CustomerId); param1.MySqlDbType = MySqlDbType.VarChar; cmd1.Parameters.Add(param1); param1 = new MySqlParameter("@SubscriptionId", subscription.Id); param1.MySqlDbType = MySqlDbType.VarChar; cmd1.Parameters.Add(param1); param1 = new MySqlParameter("@Subscription_Started", subscription.StartDate); param1.MySqlDbType = MySqlDbType.DateTime; cmd1.Parameters.Add(param1); param1 = new MySqlParameter("@Subscription_Ended", subscription.EndedAt); param1.MySqlDbType = MySqlDbType.DateTime; cmd1.Parameters.Add(param1); cmd1.ExecuteNonQuery(); HttpContext.Session.SetInt32("isLoggedIn", 1); payment.massage = "Payment created successfully"; //return View("Success"); // render Success.cshtml return(View(payment)); } else { return(RedirectToAction(nameof(Login))); } } catch (Exception ex) { MailMessage mail = new MailMessage(); mail.From = new MailAddress(_emailSettings.Value.PrimaryEmail); mail.Subject = "Subscription Fail"; mail.IsBodyHtml = true; mail.Body = ex.Message; mail.Sender = new MailAddress(_emailSettings.Value.PrimaryEmail); mail.To.Add(email); SmtpClient smtp = new SmtpClient(); smtp.Host = _emailSettings.Value.PrimaryDomain; //Or Your SMTP Server Address smtp.Port = _emailSettings.Value.PrimaryPort; smtp.UseDefaultCredentials = false; smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.Credentials = new System.Net.NetworkCredential(_emailSettings.Value.PrimaryEmail, _emailSettings.Value.PrimaryPassword); //Or your Smtp Email ID and Password smtp.EnableSsl = _emailSettings.Value.EnableSsl; smtp.Send(mail); payment.massage = ex.Message; return(View(payment)); } }
public UserPlanDetailsDto Get(int userID, string date) { return(planService.Get(userID, date)); }