public async Task <IsTenantAvailableOutput> IsTenantAvailable(IsTenantAvailableInput input) { var tenant = await TenantManager.FindByTenancyNameAsync(input.TenancyName); if (tenant == null) { return(new IsTenantAvailableOutput(TenantAvailabilityState.NotFound)); } if (!tenant.IsActive) { return(new IsTenantAvailableOutput(TenantAvailabilityState.InActive)); } return(new IsTenantAvailableOutput(TenantAvailabilityState.Available, tenant.Id)); }
private async Task <Tenant> GetActiveTenantAsync(string tenancyName) { var tenant = await _tenantManager.FindByTenancyNameAsync(tenancyName); if (tenant == null) { throw new UserFriendlyException(L("ThereIsNoTenantDefinedWithName{0}", tenancyName)); } if (!tenant.IsActive) { throw new UserFriendlyException(L("TenantIsNotActive", tenancyName)); } return(tenant); }
public async Task <ApiKeyDto> GetApiKey(string tenancyName) { var tenant = await _tenantManager.FindByTenancyNameAsync(tenancyName); if (tenant.IsNull()) { throw new HozaruException("Api Key not found."); } var apiKey = _apiKeyRepository.FirstOrDefault(i => i.TenantId == tenant.Id).Key; return(new ApiKeyDto() { TenancyName = tenant.TenancyName, ApiKey = apiKey }); }
public async Task HandleInvoicePaymentSucceededAsync(Invoice invoice) { var customerService = new CustomerService(); var customer = await customerService.GetAsync(invoice.CustomerId); int tenantId; int editionId; PaymentPeriodType?paymentPeriodType = null; using (CurrentUnitOfWork.SetTenantId(null)) { var tenant = await _tenantManager.FindByTenancyNameAsync(customer.Description); tenantId = tenant.Id; editionId = tenant.EditionId.Value; using (CurrentUnitOfWork.SetTenantId(tenantId)) { var lastPayment = GetLastCompletedSubscriptionPayment(tenantId); paymentPeriodType = lastPayment.GetPaymentPeriodType(); } await _tenantManager.UpdateTenantAsync( tenant.Id, isActive : true, isInTrialPeriod : false, paymentPeriodType, tenant.EditionId.Value, EditionPaymentType.Extend); } await _subscriptionPaymentRepository.InsertAsync(new SubscriptionPayment { TenantId = tenantId, Amount = ConvertFromStripePrice(invoice.AmountPaid), DayCount = (int)paymentPeriodType, PaymentPeriodType = paymentPeriodType, EditionId = editionId, ExternalPaymentId = invoice.ChargeId, Gateway = SubscriptionPaymentGatewayType.Stripe, IsRecurring = true, Status = SubscriptionPaymentStatus.Paid }); }