public StripeInvoiceServiceTest() { this.service = new StripeInvoiceService(); this.createOptions = new StripeInvoiceCreateOptions() { TaxPercent = 12.5m, }; this.updateOptions = new StripeInvoiceUpdateOptions() { Metadata = new Dictionary <string, string>() { { "key", "value" }, }, }; this.listOptions = new StripeInvoiceListOptions() { Limit = 1, }; this.listLineItemsOptions = new StripeInvoiceListLineItemsOptions() { Limit = 1, }; this.upcomingOptions = new StripeUpcomingInvoiceOptions() { SubscriptionId = "sub_123", }; }
public IEnumerable <StripeInvoice> ListInvoices(int companyId) { var subscription = GetSubscription(companyId); if (subscription.StripeCustomerId != null) { var invoiceService = new StripeInvoiceService(); var stripeInvoiceListOptions = new StripeInvoiceListOptions { CustomerId = subscription.StripeCustomerId }; return(invoiceService.List(stripeInvoiceListOptions)); } return(new List <StripeInvoice>()); }
public async Task <IHttpActionResult> GetInvoicesAsync(string id, string before = null, string after = null, int limit = 12) { if (!Settings.Current.EnableBilling) { return(NotFound()); } var organization = await GetModelAsync(id); if (organization == null) { return(NotFound()); } if (String.IsNullOrWhiteSpace(organization.StripeCustomerId)) { return(Ok(new List <InvoiceGridModel>())); } if (!String.IsNullOrEmpty(before) && !before.StartsWith("in_")) { before = "in_" + before; } if (!String.IsNullOrEmpty(after) && !after.StartsWith("in_")) { after = "in_" + after; } var invoiceService = new StripeInvoiceService(Settings.Current.StripeApiKey); var invoiceOptions = new StripeInvoiceListOptions { CustomerId = organization.StripeCustomerId, Limit = limit + 1, EndingBefore = before, StartingAfter = after }; var invoices = (await MapCollectionAsync <InvoiceGridModel>(await invoiceService.ListAsync(invoiceOptions), true)).ToList(); return(OkWithResourceLinks(invoices.Take(limit).ToList(), invoices.Count > limit, i => i.Id)); }