Invoice ISubscriptionService.GetUpcomingInvoice(string customerBillingId) { var invoiceService = new StripeInvoiceService(); StripeInvoice response = null; try { response = invoiceService.Upcoming(customerBillingId); return new Invoice { AmountDueInCents = response.AmountDueInCents, AttemptCount = response.AttemptCount, Attempted = response.Attempted, ChargeId = response.ChargeId, Closed = response.Closed, CustomerId = response.CustomerId, Date = response.Date, EndingBalanceInCents = response.EndingBalanceInCents, Id = response.Id, LiveMode = response.LiveMode, NextPaymentAttempt = response.NextPaymentAttempt, Paid = response.Paid, PeriodEnd = response.PeriodEnd, PeriodStart = response.PeriodStart, StartingBalanceInCents = response.StartingBalanceInCents, SubtotalInCents = response.SubtotalInCents, TotalInCents = response.TotalInCents }; } catch { } return new Invoice(); }
// GET api/customer/5 public HttpResponseMessage Get(string id, int organizationId) { OrganizationId = organizationId; try { if (UserIsAdminOfOrganization) { var subscription = subscriptionService.GetCustomerSubscription(id); if (subscription != null) { var invoiceService = new StripeInvoiceService(); var invoice = subscriptionService.GetUpcomingInvoice(id); subscription.UpcomingInvoice = invoice; } return Request.CreateResponse(HttpStatusCode.OK, subscription); } } catch (StripeException ex) { emailHelper.SendStripeError(ex); } catch (Exception e) { emailHelper.SendErrorEmail(e); } return Request.CreateResponse(HttpStatusCode.InternalServerError); }
// GET api/invoice/5 public HttpResponseMessage GetUpcoming(string id, bool upcoming, int organizationId) { this.OrganizationId = organizationId; try { if (this.UserIsAdminOfOrganization) { var invoiceService = new StripeInvoiceService(); StripeInvoice response; if (upcoming) { var invoice = subscriptionService.GetUpcomingInvoice(id); return Request.CreateResponse(HttpStatusCode.OK, invoice); } else { response = invoiceService.Get(id); } return Request.CreateResponse(HttpStatusCode.OK, response); } } catch (StripeException ex) { emailHelper.SendStripeError(ex); } catch (Exception e) { emailHelper.SendErrorEmail(e); } return Request.CreateResponse(HttpStatusCode.BadRequest); }
// GET: Test public ActionResult Index() { var customerList = new StripeCustomerService().List(); StripeCustomer firstcustomer = customerList.First(); // var invoice = new StripeInvoice(); StripeInvoice firstCusomterInvoice = new StripeInvoiceService().List().FirstOrDefault(x => x.CustomerId == firstcustomer.Id); return View(firstCusomterInvoice); }
// GET: Invoices public ActionResult Index() { //CUS ID For Testing //cus_75PYlPJEmsQb9X var customerList = new StripeCustomerService().List(); StripeCustomer firstcustomer = customerList.First(); // var invoice = new StripeInvoice(); StripeInvoice firstCusomterInvoice = new StripeInvoiceService().List().FirstOrDefault(x => x.CustomerId == firstcustomer.Id); return View(firstCusomterInvoice); }
public ActionResult Payment(string id) { if (String.IsNullOrEmpty(id)) return HttpNotFound(); if (!id.StartsWith("in_")) id = "in_" + id; var invoiceService = new StripeInvoiceService(); StripeInvoice invoice = invoiceService.Get(id); if (invoice == null) return HttpNotFound(); Organization org = _repository.GetByStripeCustomerId(invoice.CustomerId); if (org == null) return HttpNotFound(); if (!CanAccessOrganization(org.Id)) return HttpNotFound(); return View(new InvoiceModel { Invoice = invoice, Organization = org }); }
public void Create(string userName, Plan plan, string stripeToken) { var user = UserManager.FindByName(userName); if (String.IsNullOrEmpty(user.StripeCustomerId)) //first time customer { //create customer which will create subscription if plan is set and cc info via token is provided var customer = new StripeCustomerCreateOptions() { Email = user.Email, Source = new StripeSourceOptions() { TokenId = stripeToken }, PlanId = plan.ExternalId //externalid is stripe plan.id }; StripeCustomer stripeCustomer = StripeCustomerService.Create(customer); user.StripeCustomerId = stripeCustomer.Id; user.ActiveUntil = DateTime.Now.AddDays((double)plan.TrialPeriodDays); UserManager.Update(user); //Invoice Created var invoiceService = new StripeInvoiceService(); // IEnumerable<StripeInvoice> response = invoiceService.List().Where(x=>x.CustomerId == stripeCustomer.Id && x.Paid == true && ; // SendPaymentReceivedFromChargeEmail() } else { var stripeSubscription = StripeSubscriptionService.Create(user.StripeCustomerId, plan.ExternalId); user.ActiveUntil = DateTime.Now.AddDays((double)plan.TrialPeriodDays); UserManager.Update(user); } }