Exemple #1
0
        public void SetTariff(int tenantId, Tariff tariff)
        {
            if (tariff == null)
            {
                throw new ArgumentNullException("tariff");
            }

            var q = quotaService.GetTenantQuota(tariff.QuotaId);

            if (q == null)
            {
                return;
            }
            SaveBillingInfo(tenantId, Tuple.Create(tariff.QuotaId, tariff.DueDate));
            if (q.Trial)
            {
                // reset trial date
                var tenant = tenantService.GetTenant(tenantId);
                if (tenant != null)
                {
                    tenant.VersionChanged = DateTime.UtcNow;
                    tenantService.SaveTenant(tenant);
                }
            }

            ClearCache(tenantId);
        }
Exemple #2
0
        public Uri GetShoppingUri(int tenant, int plan)
        {
            var key  = "billing/urls/" + tenant;
            var urls = cache.Get(key) as IDictionary <int, Uri>;

            if (urls == null)
            {
                urls = new Dictionary <int, Uri>();
            }
            if (!urls.ContainsKey(plan))
            {
                try
                {
                    using (var client = new BillingClient())
                    {
                        var q          = quotaService.GetTenantQuota(plan);
                        var avangateId = q.AvangateId;
                        if (!string.IsNullOrEmpty(avangateId))
                        {
                            try
                            {
                                var cached = GetBillingInfo(tenant);
                                if (cached == null || cached.Item1 == plan)
                                {
                                    urls[plan] = new Uri(client.GetPaymentUrl(tenant, avangateId).Value);
                                }
                                else
                                {
                                    urls[plan] = new Uri(client.GetPaymentUpdateUrl(tenant, avangateId).Value);
                                }
                            }
                            catch
                            {
                                // new tariff
                                urls[plan] = new Uri(client.GetPaymentUrl(tenant, avangateId).Value);
                            }
                        }
                        else
                        {
                            urls[plan] = null;
                        }
                    }
                }
                catch (Exception error)
                {
                    log.Error(error);
                    urls[plan] = null;
                }
                cache.Insert(key, urls, DateTime.UtcNow.Add(CacheExpiration));
            }
            return(urls[plan]);
        }
        public TenantQuota GetTenantQuota(int tenant)
        {
            var q = quotaService.GetTenantQuota(tenant) ?? quotaService.GetTenantQuota(Tenant.DEFAULT_TENANT) ?? TenantQuota.Default;

            if (q.Id != tenant && tariffService != null)
            {
                var tariffQuota = quotaService.GetTenantQuota(tariffService.GetTariff(tenant).QuotaId);
                if (tariffQuota != null)
                {
                    return(tariffQuota);
                }
            }
            return(q);
        }
        public TenantQuota GetTenantQuota(int tenant)
        {
            // если в tenants_quota есть строка, с данным идентификатором портала, то в качестве квоты берется именно она
            var q = quotaService.GetTenantQuota(tenant) ?? quotaService.GetTenantQuota(Tenant.DEFAULT_TENANT) ?? TenantQuota.Default;

            if (q.Id != tenant && tariffService != null)
            {
                var tariffQuota = quotaService.GetTenantQuota(tariffService.GetTariff(tenant).QuotaId);
                if (tariffQuota != null)
                {
                    return(tariffQuota);
                }
            }
            return(q);
        }
        public TenantQuota GetTenantQuota(int tenant)
        {
            var defaultQuota = quotaService.GetTenantQuota(tenant) ?? quotaService.GetTenantQuota(Tenant.DEFAULT_TENANT) ?? TenantQuota.Default;

            if (defaultQuota.Id != tenant && tariffService != null)
            {
                var tariff       = tariffService.GetTariff(tenant);
                var currentQuota = quotaService.GetTenantQuota(tariff.QuotaId);
                if (currentQuota != null)
                {
                    currentQuota = (TenantQuota)currentQuota.Clone();

                    if (currentQuota.ActiveUsers == -1)
                    {
                        currentQuota.ActiveUsers   = tariff.Quantity;
                        currentQuota.MaxTotalSize *= currentQuota.ActiveUsers;
                    }

                    return(currentQuota);
                }
            }
            return(defaultQuota);
        }