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
示例#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();
        }
示例#2
0
        /// <summary>
        /// Subscribes the given user to the given plan, using the payment information already in stripe for that user
        /// NOTE: Save changes on the underlying context for the model after calling this method
        /// </summary>
        /// <param name="subscription"></param>
        public static void Subscribe(IStripeUser user, IStripeSubscription subscription, IStripeSubscriptionPlan plan)
        {
            if (!string.IsNullOrEmpty(subscription.PaymentSystemId))
                return;

            var subscriptionService = new StripeSubscriptionService();
            StripeSubscription stripeSubscription = subscriptionService.Create(user.PaymentSystemId, plan.PaymentSystemId);
            subscription.PaymentSystemId = stripeSubscription.Id;

            System.Diagnostics.Trace.TraceInformation("Subscribed customer in stripe: '{0}' with new subscription id '{1}", user.Email, subscription.PaymentSystemId);
        }