private async Task Paid_Registratin_Should_Add_N_Days_To_SubscriptionEndDate(PaymentPeriodType paymentPeriodType) { //Arrange var utcNow = Clock.Now.ToUniversalTime(); var trialDayCount = 10; var edition = new SubscribableEdition { DisplayName = "Gold Edition", TrialDayCount = trialDayCount, MonthlyPrice = 19, AnnualPrice = 199 }; await UsingDbContextAsync(async context => { context.SubscribableEditions.Add(edition); await context.SaveChangesAsync(); }); //Don't test payment here. _fakePaymentCache.AddCacheItem(new PaymentCacheItem(SubscriptionPaymentGatewayType.Paypal, paymentPeriodType, samplePaymentId)); _subscriptionPaymentRepository.Insert(new SubscriptionPayment { PaymentPeriodType = paymentPeriodType, EditionId = edition.Id, Amount = edition.MonthlyPrice.Value, Gateway = SubscriptionPaymentGatewayType.Paypal, PaymentId = samplePaymentId, Status = SubscriptionPaymentStatus.Completed, }); var result = await _tenantRegistrationAppService.RegisterTenant(new RegisterTenantInput { EditionId = edition.Id, AdminEmailAddress = "*****@*****.**", AdminPassword = "******", Name = "Volosoft", SubscriptionStartType = SubscriptionStartType.Paid, TenancyName = "Volosoft", Gateway = SubscriptionPaymentGatewayType.Paypal, PaymentId = samplePaymentId }); //Assert await UsingDbContextAsync(async context => { var tenant = await context.Tenants.FirstOrDefaultAsync(t => t.Id == result.TenantId); tenant.ShouldNotBe(null); tenant.SubscriptionEndDateUtc.HasValue.ShouldBe(true); tenant.SubscriptionEndDateUtc.Value.Date.ShouldBe(utcNow.Date.AddDays((int)paymentPeriodType)); }); }
private SubscribableEdition GetHighestEditionOrNullByPaymentPeriodType(PaymentPeriodType paymentPeriodType) { var editions = TenantManager.EditionManager.Editions; if (editions == null || !editions.Any()) { return(null); } return(editions.Cast <SubscribableEdition>() .OrderByDescending(e => e.GetPaymentAmountOrNull(paymentPeriodType) ?? 0) .FirstOrDefault()); }
private void ExtendSubscriptionDate(PaymentPeriodType paymentPeriodType) { if (SubscriptionEndDateUtc == null) { throw new InvalidOperationException("Can not extend subscription date while it's null!"); } if (IsSubscriptionEnded()) { SubscriptionEndDateUtc = Clock.Now.ToUniversalTime(); } SubscriptionEndDateUtc = SubscriptionEndDateUtc.Value.AddDays((int)paymentPeriodType); }
private async Task <string> ExecutePaymentAsync(int editionId, PaymentPeriodType paymentPeriodType, SubscriptionPaymentGatewayType gateway) { var data = Request.Form.ToDictionary(q => q.Key, q => string.Join(",", q.Value)); var result = await _paymentAppService.ExecutePayment(new ExecutePaymentDto { EditionId = editionId, EditionPaymentType = EditionPaymentType.NewRegistration, Gateway = gateway, AdditionalData = data }); var paymentId = result.GetId(); _paymentCache.AddCacheItem(new PaymentCacheItem(gateway, paymentPeriodType, paymentId)); return(paymentId); }
public async Task <ActionResult> ExecutePayment(int editionId, PaymentPeriodType paymentPeriodType, SubscriptionPaymentGatewayType?gateway = null) { Check.NotNull(gateway, nameof(gateway)); var edition = await _tenantRegistrationAppService.GetEdition(editionId); if (edition.IsFree) { throw new Exception("Can not execute payment for free editions!"); } var paymentId = await ExecutePaymentAsync(editionId, paymentPeriodType, gateway.Value); return(RedirectToAction("Register", "TenantRegistration", new { editionId = editionId, subscriptionStartType = SubscriptionStartType.Paid, gateway = gateway, paymentId = paymentId })); }
public string GetPlanId(string editionName, PaymentPeriodType paymentPeriodType) { return(editionName + "_" + paymentPeriodType + "_" + SprintTekConsts.Currency); }
public string GetPlanId(string editionName, PaymentPeriodType paymentPeriodType) { return(editionName + "_" + paymentPeriodType + "_" + AbpZeroTemplateConsts.Currency); }
public PaymentCacheItem(SubscriptionPaymentGatewayType gateWay, PaymentPeriodType paymentPeriodType, string paymentId) { GateWay = gateWay; PaymentId = paymentId; PaymentPeriodType = paymentPeriodType; }
public decimal GetUpgradePrice(SubscribableEdition currentEdition, SubscribableEdition targetEdition, int totalRemainingHourCount, PaymentPeriodType paymentPeriodType) { int numberOfHoursPerDay = 24; var totalRemainingDayCount = totalRemainingHourCount / numberOfHoursPerDay; var unusedPeriodCount = totalRemainingDayCount / (int)paymentPeriodType; var unusedHoursCount = totalRemainingHourCount % ((int)paymentPeriodType * numberOfHoursPerDay); decimal currentEditionPriceForUnusedPeriod = 0; decimal targetEditionPriceForUnusedPeriod = 0; var currentEditionPrice = currentEdition.GetPaymentAmount(paymentPeriodType); var targetEditionPrice = targetEdition.GetPaymentAmount(paymentPeriodType); if (currentEditionPrice > 0) { currentEditionPriceForUnusedPeriod = currentEditionPrice * unusedPeriodCount; currentEditionPriceForUnusedPeriod += (currentEditionPrice / (int)paymentPeriodType) / numberOfHoursPerDay * unusedHoursCount; } if (targetEditionPrice > 0) { targetEditionPriceForUnusedPeriod = targetEditionPrice * unusedPeriodCount; targetEditionPriceForUnusedPeriod += (targetEditionPrice / (int)paymentPeriodType) / numberOfHoursPerDay * unusedHoursCount; } return(targetEditionPriceForUnusedPeriod - currentEditionPriceForUnusedPeriod); }
public void Calculate_Upgrade_To_Edition_Price(decimal currentEditionPrice, decimal targetEditionPrice, int remainingDaysCount, PaymentPeriodType paymentPeriodType, decimal upgradePrice) { // Used same price for easily testing upgrade price calculation. var currentEdition = new SubscribableEdition { DisplayName = "Standard", Name = "Standard", DailyPrice = currentEditionPrice, WeeklyPrice = currentEditionPrice, MonthlyPrice = currentEditionPrice, AnnualPrice = currentEditionPrice }; var targetEdition = new SubscribableEdition { DisplayName = "Premium", Name = "Premium", DailyPrice = targetEditionPrice, WeeklyPrice = targetEditionPrice, MonthlyPrice = targetEditionPrice, AnnualPrice = targetEditionPrice }; var price = _tenantManager.GetUpgradePrice(currentEdition, targetEdition, remainingDaysCount, paymentPeriodType); price.ToString("N2").ShouldBe(upgradePrice.ToString("N2")); }
public string GetPlanId(string editionName, PaymentPeriodType paymentPeriodType) { return(editionName + "_" + paymentPeriodType + "_" + CoreAngularDemoConsts.Currency); }
public string GetPlanId(string editionName, PaymentPeriodType paymentPeriodType) { return(editionName + "_" + paymentPeriodType); }
public string GetPlanId(string editionName, PaymentPeriodType paymentPeriodType) { return(editionName + "_" + paymentPeriodType + "_" + DynasysSolutionConsts.Currency); }
public string GetPlanId(string editionName, PaymentPeriodType paymentPeriodType) { return(editionName + "_" + paymentPeriodType + "_" + PhoneBookDemoConsts.Currency); }
public string GetPlanId(string editionName, PaymentPeriodType paymentPeriodType) { return(editionName + "_" + paymentPeriodType + "_" + FintrakERPIMSDemoConsts.Currency); }