Ejemplo n.º 1
0
        /// <inheritdoc />
        public Task <string> GetCustomerAsync(string customerId, CancellationToken cancellationToken = default)
        {
            if (IsNullOrWhiteSpace(customerId))
            {
                throw new ArgumentNullException(nameof(customerId));
            }

            async Task <string> GetCustomer()
            {
                var customerService = new CustomerService(_stripeClient);
                var options         = new CustomerGetOptions();
                var customer        = await customerService.GetAsync(customerId, options, default, cancellationToken).ConfigureAwait(false);
Ejemplo n.º 2
0
        public async Task <bool> HasDefaultPaymentMethodAsync(string customerId)
        {
            var options = new CustomerGetOptions
            {
                Expand = new List <string>
                {
                    "invoice_settings.default_payment_method"
                }
            };

            var customer = await this.GetAsync(customerId, options);

            return(customer?.InvoiceSettings?.DefaultPaymentMethod != null);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Load subscription from stripe
        /// </summary>
        /// <param name="user"></param>
        /// <param name="forceRefresh"></param>
        private void LoadStripeSubscription(User user, bool forceRefresh = false)
        {
            var subscriptionStarter      = "price_1HcZm0F6EVrg0l22lVOfn9c8";
            var subscriptionProfessional = "price_1HfvS8F6EVrg0l22KoQlyZp8";
            var subscriptionUltimate     = "price_1HfwJ3F6EVrg0l22NYrfJDO6";

            StripeConfiguration.ApiKey = "sk_test_51HcZiyF6EVrg0l22KUHmhtN6fxfGQvV1yG2vk2My3Dnq6N4zTg3CASy3OKzArWvWij8CL7BwnqGDPY8xke0Hsmq100FLmHAkYc";
            var service            = new CustomerService();
            var customerGetOptions = new CustomerGetOptions();

            customerGetOptions.AddExpand("subscriptions");
            Customer customer = service.Get(Session["userStripeID"].ToString(), customerGetOptions);

            if (customer != null)
            {
                var subscriptions = customer.Subscriptions;
                if (subscriptions == null || subscriptions.Count() <= 0)
                {
                    Session["userPlan"]        = "free";
                    Session["userPlanRenewal"] = DateTime.Now.AddDays(365).ToShortDateString().ToString();
                    return;
                }
                foreach (var sub in subscriptions)
                {
                    var subItem = sub.Items;
                    foreach (var subItem_item in subItem)
                    {
                        if (subItem_item.Price.Id == subscriptionStarter)
                        {
                            Session["userPlan"]        = "starter";
                            Session["userPlanRenewal"] = Convert.ToDateTime(sub.CurrentPeriodEnd.ToString()).ToShortDateString();
                            break;
                        }

                        else if (subItem_item.Price.Id == subscriptionProfessional)
                        {
                            Session["userPlan"]        = "professional";
                            Session["userPlanRenewal"] = Convert.ToDateTime(sub.CurrentPeriodEnd.ToString()).ToShortDateString();
                            break;
                        }
                        else if (subItem_item.Price.Id == subscriptionUltimate)
                        {
                            Session["userPlan"]        = "ultimate";
                            Session["userPlanRenewal"] = Convert.ToDateTime(sub.CurrentPeriodEnd.ToString()).ToShortDateString();
                            break;
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
 public virtual Task <Customer> GetAsync(string customerId, CustomerGetOptions options = null, RequestOptions requestOptions = null, CancellationToken cancellationToken = default)
 {
     return(this.GetEntityAsync(customerId, options, requestOptions, cancellationToken));
 }
Ejemplo n.º 5
0
 public virtual Customer Get(string customerId, CustomerGetOptions options = null, RequestOptions requestOptions = null)
 {
     return(this.GetEntity(customerId, options, requestOptions));
 }