Example #1
0
 public StripeCustomerGateway(IBillingConfig config)
 {
     customerService      = new Stripe.CustomerService();
     subscriptionService  = new Stripe.SubscriptionService();
     paymentMethodService = new Stripe.PaymentMethodService();
     this.config          = config;
 }
        public Subscription Subscribe(string email, string name, string source, string monthlyPlanId, string overagePlanId)
        {
            var customerService = new Stripe.CustomerService();
            var customer        = customerService.Create(new CustomerCreateOptions
            {
                Email       = email,
                Description = name,
                Source      = source
            });

            var subscriptionService = new Stripe.SubscriptionService();

            var items = new List <SubscriptionItemOptions> {
                new SubscriptionItemOptions {
                    Plan = monthlyPlanId
                },
                new SubscriptionItemOptions {
                    Plan = overagePlanId
                }
            };

            var subscription = subscriptionService.Create(new SubscriptionCreateOptions
            {
                Customer = customer.Id,
                Items    = items,
            });

            return(subscription);
        }
Example #3
0
        public bool HasSubscription(string customerId)
        {
            var subscriptionService = new Stripe.SubscriptionService();

            Stripe.StripeList <Stripe.Subscription> response = subscriptionService.List(new Stripe.SubscriptionListOptions
            {
                CustomerId = customerId
            });

            return(response.Count() >= 1);
        }
Example #4
0
        public void DeleteSubscriptions(string customerId)
        {
            var subscriptionService = new Stripe.SubscriptionService();

            Stripe.StripeList <Stripe.Subscription> subscriptions = subscriptionService.List(new Stripe.SubscriptionListOptions
            {
                CustomerId = customerId
            });

            foreach (Stripe.Subscription subscription in subscriptions)
            {
                subscriptionService.Cancel(subscription.Id, null);
            }
        }
 public SubscriptionService(
     StripeSubscriptionItemService stripeSubscriptionItemService,
     StripeSubscriptionService subscriptionService,
     IStripeService stripeService,
     IServiceProvider serviceProvider,
     ILogger <SubscriptionService> logger) : base(serviceProvider)
 {
     _stripeSubscriptionItemService = stripeSubscriptionItemService;
     _subscriptionService           = subscriptionService;
     _stripeService          = stripeService;
     _logger                 = logger;
     _organizationRepository = UnitOfWork.RepositoryAsync <Organization>();
     _plans          = UnitOfWork.RepositoryAsync <StripePlan>();
     _itemRepository = UnitOfWork.RepositoryAsync <StripeSubscriptionItem>();
 }
Example #6
0
        public string GetSubscription(string customerId)
        {
            var subscriptionService = new Stripe.SubscriptionService();

            Stripe.StripeList <Stripe.Subscription> subscriptions = subscriptionService.List(new Stripe.SubscriptionListOptions
            {
                CustomerId = customerId
            });

            if (subscriptions.Count() == 0)
            {
                return("N/A");
            }

            return(subscriptions.First().Plan.Nickname);
        }
        public Subscription Change(string subscriptionId, string subscriptionItemId, string overageSubscriptionItemId, string monthlyPlanId, string overagePlanId)
        {
            var subscriptionService = new Stripe.SubscriptionService();

            var items = new List <SubscriptionItemOptions> {
                new SubscriptionItemOptions {
                    Plan = monthlyPlanId,
                },
                new SubscriptionItemOptions {
                    Plan = overagePlanId,
                }
            };

            var options = new SubscriptionUpdateOptions
            {
                CancelAtPeriodEnd = false,
                Items             = items,
            };

            return(subscriptionService.Update(subscriptionId, options));
        }
        public async Task <int> ImportSubscriptions(int limit)
        {
            _logger.LogInformation(GetLogMessage("Limit: {limit}"), limit);

            var svc = new StripeSubscriptionService();

            var subscriptions = svc.List(new SubscriptionListOptions()
            {
                Limit = limit
            });
            var totals = 0;

            foreach (var customer in subscriptions)
            {
                var returnValue = await PullSubscription(customer);

                totals += returnValue;
            }

            return(totals);
        }
        public Subscription GetSubscription(string subscriptionId)
        {
            var subscriptionService = new Stripe.SubscriptionService();

            return(subscriptionService.Get(subscriptionId));
        }