public List <PaymentSubscription> GetSubscriptions(string id) { var options = new SubscriptionListOptions() { Created = new AnyOf <DateTime?, DateRangeOptions>(new DateRangeOptions() { GreaterThan = DateTime.UtcNow.AddDays(-1) }) }; var subscriptions = new List <PaymentSubscription>(); foreach (var subscription in _subscriptionService.List(options).Where(s => s.Metadata.ContainsValue(id))) { var customer = _customerService.Get(subscription.CustomerId); subscriptions.Add(new PaymentSubscription() { Cancelled = subscription.CancelAtPeriodEnd, Plan = null, //subscription.Plan.Nickname, EmailAddress = customer.Email, HasValidPayment = customer.DefaultSourceId != null }); } return(subscriptions); }
public IActionResult GetSubscriptionList() { StripeConfiguration.ApiKey = "*****************"; List <object> resultList = new List <object>(); try { var options = new SubscriptionListOptions { }; var service = new SubscriptionService(); StripeList <Stripe.Subscription> subscriptions = service.List( options ); foreach (Stripe.Subscription s in subscriptions) { string id = s.Items.Data[0].Subscription; float amount = (float)s.Items.Data[0].Plan.Amount / 100; resultList.Add(new { id = id, amount = amount, }); } } catch { return(BadRequest()); } return(Ok(new JsonResult(resultList))); }
public IActionResult GetSubscription([FromQuery] string customerId) { StripeConfiguration.ApiKey = API_KEY; List <object> resultList = new List <object>(); try { var options = new SubscriptionListOptions { Customer = customerId }; var service = new SubscriptionService(); StripeList <Stripe.Subscription> subscriptions = service.List( options ); foreach (Stripe.Subscription s in subscriptions) { string id = s.Items.Data[0].Subscription; string productId = s.Items.Data[0].Price.ProductId; string priceId = s.Items.Data[0].Price.Id; resultList.Add(new { id = id, prodId = productId, priceId = priceId }); } } catch { return(BadRequest()); } return(Ok(new JsonResult(resultList))); }
public SubscriptionServiceTest( StripeMockFixture stripeMockFixture, MockHttpClientFixture mockHttpClientFixture) : base(stripeMockFixture, mockHttpClientFixture) { this.service = new SubscriptionService(this.StripeClient); this.cancelOptions = new SubscriptionCancelOptions { InvoiceNow = true, Prorate = true, }; this.createOptions = new SubscriptionCreateOptions { Customer = "cus_123", Items = new List <SubscriptionItemOptions> { new SubscriptionItemOptions { Price = "price_123", Quantity = 2, }, new SubscriptionItemOptions { PriceData = new SubscriptionItemPriceDataOptions { Currency = "usd", Product = "prod_123", Recurring = new SubscriptionItemPriceDataRecurringOptions { Interval = "day", IntervalCount = 15, }, UnitAmountDecimal = 0.01234567890m, // Ensure decimals work }, Quantity = 3, }, }, }; this.updateOptions = new SubscriptionUpdateOptions { Metadata = new Dictionary <string, string> { { "key", "value" }, }, }; this.listOptions = new SubscriptionListOptions { Limit = 1, }; }
// find subscription by plan id public async Task <Subscription> FindSubscriptionByPlan(string planId, string customerId) { var service = new SubscriptionService(); var subscriptionListOptions = new SubscriptionListOptions { Customer = customerId, Plan = planId }; var subscriptions = await service.ListAsync(subscriptionListOptions); return(subscriptions.FirstOrDefault()); }
public async Task <SubscriptionStatus> GetCustomerSubscriptionStatus(string customerId) { var service = new SubscriptionService(); var options = new SubscriptionListOptions() { Customer = customerId, }; var subscriptions = await service.ListAsync(options); if (subscriptions.Any()) { return((SubscriptionStatus)Enum.Parse(typeof(SubscriptionStatus), subscriptions.First().Status, true)); } return(SubscriptionStatus.Unpaid); }
public ActionResult <SubscriptionsResponse> ListSubscriptions() { var customerId = HttpContext.Request.Cookies["customer"]; var options = new SubscriptionListOptions { Customer = customerId, Status = "all", }; options.AddExpand("data.default_payment_method"); var service = new SubscriptionService(); var subscriptions = service.List(options); return(new SubscriptionsResponse { Subscriptions = subscriptions, }); }
public SubscriptionServiceTest( StripeMockFixture stripeMockFixture, MockHttpClientFixture mockHttpClientFixture) : base(stripeMockFixture, mockHttpClientFixture) { this.service = new SubscriptionService(this.StripeClient); this.cancelOptions = new SubscriptionCancelOptions { InvoiceNow = true, Prorate = true, }; this.createOptions = new SubscriptionCreateOptions { Customer = "cus_123", Items = new List <SubscriptionItemOption> { new SubscriptionItemOption { Plan = "plan_123", Quantity = 2, }, new SubscriptionItemOption { Plan = "plan_124", Quantity = 3, }, }, }; this.updateOptions = new SubscriptionUpdateOptions { Metadata = new Dictionary <string, string> { { "key", "value" }, }, }; this.listOptions = new SubscriptionListOptions { Limit = 1, }; }
public SubscriptionServiceTest() { this.service = new SubscriptionService(); this.cancelOptions = new SubscriptionCancelOptions { InvoiceNow = true, Prorate = true, }; this.createOptions = new SubscriptionCreateOptions { CustomerId = "cus_123", Items = new List <SubscriptionItemOption> { new SubscriptionItemOption { PlanId = "plan_123", Quantity = 2 }, new SubscriptionItemOption { PlanId = "plan_124", Quantity = 3 }, }, }; this.updateOptions = new SubscriptionUpdateOptions { Metadata = new Dictionary <string, string> { { "key", "value" }, }, }; this.listOptions = new SubscriptionListOptions { Limit = 1, }; }
public IActionResult GetCustomer([FromQuery] string email) { StripeConfiguration.ApiKey = API_KEY; List <object> resultList = new List <object>(); var options = new CustomerListOptions { Limit = 1, Email = email, }; var service = new CustomerService(); StripeList <Customer> customers = service.List( options ); foreach (Customer cus in customers) { string customerId = cus.Id; string customerName = cus.Name; var subOptions = new SubscriptionListOptions { Limit = 1, Customer = customerId }; var subService = new SubscriptionService(); StripeList <Stripe.Subscription> subscriptions = subService.List( subOptions ); Subscription sub = subscriptions.ElementAt(0); resultList.Add(new { id = customerId, name = customerName, amount = (int)sub.Items.Data[0].Price.UnitAmount }); } return(Ok(new JsonResult(resultList))); }