Пример #1
0
        public virtual StripeSubscription CreateSubscription(string customerId, StripeSubscriptionCreateOptions createOptions)
        {
            var url = string.Format(Urls.Subscriptions, customerId);
            url = ParameterBuilder.ApplyAllParameters(createOptions, url);

            var response = Requestor.PostString(url, ApiKey);

            return Mapper<StripeSubscription>.MapFromJson(response);
        }
        public virtual StripeSubscription Create(string customerId, string planId, StripeSubscriptionCreateOptions createOptions = null)
        {
            var url = string.Format(Urls.Subscriptions, customerId);
            url = this.ApplyAllParameters(createOptions, url, false);
            url = ParameterBuilder.ApplyParameterToUrl(url, "plan", planId);

            var response = Requestor.PostString(url, ApiKey);

            return Mapper<StripeSubscription>.MapFromJson(response);
        }
        public virtual async Task<StripeSubscription> CreateAsync(string customerId, string planId, StripeSubscriptionCreateOptions createOptions = null, StripeRequestOptions requestOptions = null)
        {
            var url = string.Format(Urls.Subscriptions, customerId);
            url = this.ApplyAllParameters(createOptions, url, false);

            return Mapper<StripeSubscription>.MapFromJson(
                await Requestor.PostStringAsync(ParameterBuilder.ApplyParameterToUrl(url, "plan", planId),
                SetupRequestOptions(requestOptions))
            );
        }
Пример #4
0
        private void CreateStripeSubscription(string stripeToken, string coupon)
        {
            using (var db = InitializeSettings.DbFactory)
            {
                var data = db.Get <Majorsilence.Vpn.Poco.Users>(_userId);


                var options = new Stripe.StripeSubscriptionCreateOptions();
                options.TokenId = stripeToken;
                if (coupon.Trim() != "")
                {
                    options.CouponId = coupon;
                }

                var subscriptionService = new StripeSubscriptionService();
                StripeSubscription stripeSubscription = subscriptionService.Create(data.StripeCustomerAccount,
                                                                                   Helpers.SiteInfo.StripePlanId, options);


                var subscriptionInfo = new StripeSubscriptionService(Helpers.SiteInfo.StripeAPISecretKey);
                var subscriptionList = subscriptionInfo.List(data.StripeCustomerAccount).ToList();

                if (subscriptionList.Count() > 1)
                {
                    throw new Exceptions.StripeSubscriptionException(
                              string.Format("More then one subscription detected for vpn customer: {0}, stripe customer: {1}",
                                            _userId, data.StripeCustomerAccount)
                              );
                }



                data.StripeSubscriptionId = subscriptionList.First().Id;

                db.Update(data);
            }
        }