Stripe.StripeSubscriptionService.Create C# (CSharp) Method

Create() public method

public Create ( string customerId, string planId, Stripe.StripeSubscriptionCreateOptions createOptions = null, Stripe.StripeRequestOptions requestOptions = null ) : Stripe.StripeSubscription
customerId string
planId string
createOptions Stripe.StripeSubscriptionCreateOptions
requestOptions Stripe.StripeRequestOptions
return Stripe.StripeSubscription
        public virtual StripeSubscription Create(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(
                Requestor.PostString(ParameterBuilder.ApplyParameterToUrl(url, "plan", planId),
                SetupRequestOptions(requestOptions))
            );
        }

Usage Example

示例#1
0
        /// <summary>
        /// Before calling this method - make sure you have saved the box to the database
        /// </summary>
        public void Create(PawzeUser pawzeUser, Box box, string token)
        {
            if (string.IsNullOrEmpty(pawzeUser.StripeCustomerId))
            {
                var customerService = new StripeCustomerService(APIKey);

                var customer = customerService.Create(new StripeCustomerCreateOptions
                {
                    Email = pawzeUser.Email
                });

                pawzeUser.StripeCustomerId = customer.Id;
            }

            var subscriptionService = new Stripe.StripeSubscriptionService(APIKey);

            StripeSubscription subscription = subscriptionService.Create(pawzeUser.StripeCustomerId, "box", new StripeSubscriptionCreateOptions
            {
                Card = new StripeCreditCardOptions
                {
                    TokenId = token
                }
            });

            var pawzeSubscription = new Subscription
            {
                PawzeUserId          = pawzeUser.Id,
                StartDate            = DateTime.Now,
                StripeSubscriptionId = subscription.Id
            };

            pawzeSubscription.Boxes.Add(box);

            _subscriptionRepository.Add(pawzeSubscription);

            _unitOfWork.Commit();
        }
All Usage Examples Of Stripe.StripeSubscriptionService::Create