diff --git a/modules/payment/src/Payment.Application/PaymentRequests/PaymentRequestAppService.cs b/modules/payment/src/Payment.Application/PaymentRequests/PaymentRequestAppService.cs index 8c86837..ecf79db 100644 --- a/modules/payment/src/Payment.Application/PaymentRequests/PaymentRequestAppService.cs +++ b/modules/payment/src/Payment.Application/PaymentRequests/PaymentRequestAppService.cs @@ -13,9 +13,9 @@ namespace Payment.PaymentRequests { public class PaymentRequestAppService : PaymentAppService, IPaymentRequestAppService { - private readonly IPaymentRequestRepository _paymentRequestRepository; - private readonly PaymentOptions _paymentOptions; - private readonly PayPalHttpClient _payPalHttpClient; + protected readonly IPaymentRequestRepository _paymentRequestRepository; + protected readonly PaymentOptions _paymentOptions; + protected readonly PayPalHttpClient _payPalHttpClient; public PaymentRequestAppService( IPaymentRequestRepository paymentRequestRepository, diff --git a/src/EventHub.Domain.Shared/EventHubDomainSharedModule.cs b/src/EventHub.Domain.Shared/EventHubDomainSharedModule.cs index 9cd1cad..25829cb 100644 --- a/src/EventHub.Domain.Shared/EventHubDomainSharedModule.cs +++ b/src/EventHub.Domain.Shared/EventHubDomainSharedModule.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; using EventHub.Localization; -using EventHub.Organizations; using EventHub.Web; using Microsoft.Extensions.DependencyInjection; using Volo.Abp.AuditLogging; @@ -62,21 +60,6 @@ namespace EventHub }); Configure(configuration.GetSection("AppUrls")); - - context.Services.AddOptions>() - .Bind(configuration.GetSection(OrganizationPlanInfoOptions.OrganizationPlanInfo)) - .Validate(config => - { - foreach (var planInfo in config) - { - if (planInfo.IsActive) - { - return planInfo.OnePremiumPeriodAsMonth > planInfo.CanBeExtendedAfterHowManyMonths; - } - } - - return true; - }, "OnePremiumPeriodAsMonth must be greater than CanBeExtendedAfterHowManyMonths."); } } } \ No newline at end of file diff --git a/src/EventHub.Domain.Shared/Organizations/PaymentRequestProductExtraParameterConfiguration.cs b/src/EventHub.Domain.Shared/Organizations/OrganizationPaymentRequestExtraParameterConfiguration.cs similarity index 51% rename from src/EventHub.Domain.Shared/Organizations/PaymentRequestProductExtraParameterConfiguration.cs rename to src/EventHub.Domain.Shared/Organizations/OrganizationPaymentRequestExtraParameterConfiguration.cs index 58eec5a..4954fc3 100644 --- a/src/EventHub.Domain.Shared/Organizations/PaymentRequestProductExtraParameterConfiguration.cs +++ b/src/EventHub.Domain.Shared/Organizations/OrganizationPaymentRequestExtraParameterConfiguration.cs @@ -1,11 +1,11 @@ namespace EventHub.Organizations { - public class PaymentRequestProductExtraParameterConfiguration + public class OrganizationPaymentRequestExtraParameterConfiguration { public string OrganizationName { get; set; } - - public OrganizationPlanType TargetPlanType { get; set; } - + public bool IsExtend { get; set; } + + public int PremiumPeriodAsMonth { get; set; } } } \ No newline at end of file diff --git a/src/EventHub.Domain/Emailing/EmailTemplates.cs b/src/EventHub.Domain/Emailing/EmailTemplates.cs index 087a892..2ba2847 100644 --- a/src/EventHub.Domain/Emailing/EmailTemplates.cs +++ b/src/EventHub.Domain/Emailing/EmailTemplates.cs @@ -12,8 +12,8 @@ namespace EventHub.Emailing public const string EventTimingChanged = "EventHub.Event.EventTimingChanged"; - public const string PaymentRequestCompleted = "EventHub.Event.PaymentRequestCompleted"; + public const string PaymentRequestCompleted = "EventHub.Organization.PaymentRequestCompleted"; - public const string PaymentRequestFailed = "EventHub.Event.PaymentRequestFailed"; + public const string PaymentRequestFailed = "EventHub.Organization.PaymentRequestFailed"; } } \ No newline at end of file diff --git a/src/EventHub.Domain/Emailing/Templates/PaymentRequestCompleted.tpl b/src/EventHub.Domain/Emailing/Templates/PaymentRequestCompleted.tpl index ade6c2e..5cd7d06 100644 --- a/src/EventHub.Domain/Emailing/Templates/PaymentRequestCompleted.tpl +++ b/src/EventHub.Domain/Emailing/Templates/PaymentRequestCompleted.tpl @@ -132,7 +132,7 @@
-

Your organization has been activated.

+

Your organization has been {{model.plan_info}}.

@@ -190,7 +190,7 @@

Organization name

-

{{model.organizationName}}

+

{{model.organization_name}}

@@ -223,7 +223,7 @@

TOTAL

-

{{model.Price}} {{model.Currency}}

+

{{model.price}} {{model.currency}}

@@ -253,7 +253,7 @@
- My Organization + My Organization
diff --git a/src/EventHub.Domain/Emailing/Templates/PaymentRequestFailed.tpl b/src/EventHub.Domain/Emailing/Templates/PaymentRequestFailed.tpl index 6582315..cc5e6c4 100644 --- a/src/EventHub.Domain/Emailing/Templates/PaymentRequestFailed.tpl +++ b/src/EventHub.Domain/Emailing/Templates/PaymentRequestFailed.tpl @@ -76,7 +76,7 @@ @@ -109,7 +109,7 @@
-

We found that your {{model.licenseType}} payment transaction has not been completed. We want to help you take the next step and start your {{model.licenseType}} now.

+

We found that your {{model.license_type}} payment transaction has not been completed. We want to help you take the next step and start your {{model.license_type}} now.

@@ -138,7 +138,7 @@ - + - + diff --git a/src/EventHub.Domain/PaymentRequests/PaymentRequestEventHandler.cs b/src/EventHub.Domain/Organizations/PaymentRequests/PaymentRequestEventHandler.cs similarity index 76% rename from src/EventHub.Domain/PaymentRequests/PaymentRequestEventHandler.cs rename to src/EventHub.Domain/Organizations/PaymentRequests/PaymentRequestEventHandler.cs index f30ab59..5f61b53 100644 --- a/src/EventHub.Domain/PaymentRequests/PaymentRequestEventHandler.cs +++ b/src/EventHub.Domain/Organizations/PaymentRequests/PaymentRequestEventHandler.cs @@ -1,11 +1,7 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; using EventHub.Emailing; -using EventHub.Organizations; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; using Newtonsoft.Json; using Payment.PaymentRequests; using Volo.Abp.DependencyInjection; @@ -15,7 +11,7 @@ using Volo.Abp.EventBus.Distributed; using Volo.Abp.Identity; using Volo.Abp.TextTemplating; -namespace EventHub.PaymentRequests +namespace EventHub.Organizations.PaymentRequests { public class PaymentRequestEventHandler : IDistributedEventHandler, IDistributedEventHandler, ITransientDependency @@ -25,7 +21,6 @@ namespace EventHub.PaymentRequests private readonly IRepository _userRepository; private readonly IRepository _organizationRepository; private readonly IRepository _paymentRequestRepository; - private readonly IOptionsSnapshot> _organizationPlanInfoOptionsSnapshot; private readonly ILogger _logger; public PaymentRequestEventHandler( @@ -34,7 +29,6 @@ namespace EventHub.PaymentRequests IRepository userRepository, IRepository organizationRepository, IRepository paymentRequestRepository, - IOptionsSnapshot> organizationPlanInfoOptionsSnapshot, ILogger logger) { _emailSender = emailSender; @@ -42,20 +36,19 @@ namespace EventHub.PaymentRequests _userRepository = userRepository; _organizationRepository = organizationRepository; _paymentRequestRepository = paymentRequestRepository; - _organizationPlanInfoOptionsSnapshot = organizationPlanInfoOptionsSnapshot; _logger = logger; } public async Task HandleEventAsync(PaymentRequestCompletedEto eventData) { - var isExistExtraProperties = eventData.ExtraProperties.TryGetValue(nameof(PaymentRequestProductExtraParameterConfiguration), out var ExtraProperties); + var isExistExtraProperties = eventData.ExtraProperties.TryGetValue(nameof(OrganizationPaymentRequestExtraParameterConfiguration), out var ExtraProperties); if (!isExistExtraProperties || ExtraProperties is null) { _logger.LogCritical($"{eventData.PaymentRequestId} PaymentRequestId although payment was received, organization could not be upgrade because ExtraProperties do not exist!"); return; } - var paymentRequestProductExtraParameter = JsonConvert.DeserializeObject(ExtraProperties.ToString()); + var paymentRequestProductExtraParameter = JsonConvert.DeserializeObject(ExtraProperties.ToString()); if (paymentRequestProductExtraParameter is null) { _logger.LogCritical($"{eventData.PaymentRequestId} PaymentRequestId although payment was received, organization could not be upgrade because the ExtraProperties cannot be deserialized!"); @@ -70,33 +63,23 @@ namespace EventHub.PaymentRequests _logger.LogCritical($"{eventData.PaymentRequestId} PaymentRequestId although payment was received, mail could not be sent because the user(UserId:{payment.CustomerId}) could not be found!"); return; } - - var organization = await _organizationRepository.FindAsync(o => o.Name == paymentRequestProductExtraParameter.OrganizationName); - if (organization is null) - { - _logger.LogCritical($"{eventData.PaymentRequestId} PaymentRequestId although payment was received, organization could not be upgrade because the organization(OrganizationId:{paymentRequestProductExtraParameter.OrganizationName}) could not be found!"); - return; - } - var targetPlan = _organizationPlanInfoOptionsSnapshot.Value.First(x => x.PlanType == paymentRequestProductExtraParameter.TargetPlanType); - if (paymentRequestProductExtraParameter.IsExtend) - { - organization.UpgradeToPremium(organization.PremiumEndDate!.Value.AddMonths(targetPlan.OnePremiumPeriodAsMonth)); - } - else + var updatedOrganization = await UpgradeOrganizationAsync(paymentRequestProductExtraParameter); + if (updatedOrganization is null) { - organization.UpgradeToPremium(DateTime.Now.AddMonths(targetPlan.OnePremiumPeriodAsMonth)); + _logger.LogCritical($"{eventData.PaymentRequestId} PaymentRequestId although payment was received, organization could not be upgrade! OrganizationName: {paymentRequestProductExtraParameter.OrganizationName}"); + return; } - await _organizationRepository.UpdateAsync(organization, true); var templateModel = new { OrganizationName = paymentRequestProductExtraParameter.OrganizationName, + PlanInfo = paymentRequestProductExtraParameter.IsExtend ? "extended" : "upgraded", Price = payment.Price, Currency = payment.Currency }; - await _emailSender.QueueAsync( + await _emailSender.SendAsync( user.Email, "EventHub: Thank You", await _templateRenderer.RenderAsync(EmailTemplates.PaymentRequestCompleted, templateModel) @@ -105,14 +88,14 @@ namespace EventHub.PaymentRequests public async Task HandleEventAsync(PaymentRequestFailedEto eventData) { - var isExistExtraProperties = eventData.ExtraProperties.TryGetValue(nameof(PaymentRequestProductExtraParameterConfiguration), out var ExtraProperties); + var isExistExtraProperties = eventData.ExtraProperties.TryGetValue(nameof(OrganizationPaymentRequestExtraParameterConfiguration), out var ExtraProperties); if (!isExistExtraProperties || ExtraProperties is null) { _logger.LogCritical($"{eventData.PaymentRequestId} PaymentRequestId although payment was received, mail could not be sent because ExtraProperties do not exist!"); return; } - var paymentRequestProductExtraParameter = JsonConvert.DeserializeObject(ExtraProperties.ToString()); + var paymentRequestProductExtraParameter = JsonConvert.DeserializeObject(ExtraProperties.ToString()); if (paymentRequestProductExtraParameter is null) { _logger.LogCritical($"{eventData.PaymentRequestId} PaymentRequestId although payment was received, mail could not be sent because the ExtraProperties cannot be deserialized!"); @@ -130,15 +113,36 @@ namespace EventHub.PaymentRequests var templateModel = new { OrganizationName = paymentRequestProductExtraParameter.OrganizationName, - LicenseType = paymentRequestProductExtraParameter.TargetPlanType, + LicenseType = OrganizationPlanType.Premium, FailReason = eventData.FailReason }; await _emailSender.QueueAsync( user.Email, "EventHub: Payment Failed", - await _templateRenderer.RenderAsync(EmailTemplates.PaymentRequestCompleted, templateModel) + await _templateRenderer.RenderAsync(EmailTemplates.PaymentRequestFailed, templateModel) ); } + + private async Task UpgradeOrganizationAsync(OrganizationPaymentRequestExtraParameterConfiguration organizationPaymentRequestExtraParameter) + { + var organization = await _organizationRepository.FindAsync(o => o.Name == organizationPaymentRequestExtraParameter.OrganizationName); + if (organization is null) + { + return null; + } + + if (organizationPaymentRequestExtraParameter.IsExtend) + { + organization.UpgradeToPremium( + organization.PremiumEndDate!.Value.AddMonths(organizationPaymentRequestExtraParameter.PremiumPeriodAsMonth)); + } + else + { + organization.UpgradeToPremium(DateTime.Now.AddMonths(organizationPaymentRequestExtraParameter.PremiumPeriodAsMonth)); + } + + return await _organizationRepository.UpdateAsync(organization, true); + } } } \ No newline at end of file diff --git a/src/EventHub.Web/EventHubWebModule.cs b/src/EventHub.Web/EventHubWebModule.cs index a9857ce..05f9382 100644 --- a/src/EventHub.Web/EventHubWebModule.cs +++ b/src/EventHub.Web/EventHubWebModule.cs @@ -10,6 +10,7 @@ using Microsoft.Extensions.Hosting; using Microsoft.IdentityModel.Protocols.OpenIdConnect; using EventHub.Localization; using EventHub.Web.Menus; +using EventHub.Web.PaymentRequests; using EventHub.Web.Theme; using EventHub.Web.Theme.Bundling; using EventHub.Web.Utils; @@ -86,6 +87,23 @@ namespace EventHub.Web ConfigureCookies(context); ConfigureSwaggerServices(context.Services); ConfigureRazorPageOptions(); + ConfigurePremiumPlanInfo(context, configuration); + } + + private void ConfigurePremiumPlanInfo(ServiceConfigurationContext context, IConfiguration configuration) + { + context.Services.AddOptions() + .Bind(configuration.GetSection(PremiumPlanInfoOptions.OrganizationPlanInfo)) + .ValidateDataAnnotations() + .Validate(config => + { + if (config.IsActive) + { + return config.OnePremiumPeriodAsMonth > config.CanBeExtendedAfterHowManyMonths; + } + + return true; + }, "OnePremiumPeriodAsMonth must be greater than CanBeExtendedAfterHowManyMonths."); } private void ConfigureBundles() diff --git a/src/EventHub.Web/Pages/Organizations/Profile.cshtml b/src/EventHub.Web/Pages/Organizations/Profile.cshtml index d0b4987..d600a09 100644 --- a/src/EventHub.Web/Pages/Organizations/Profile.cshtml +++ b/src/EventHub.Web/Pages/Organizations/Profile.cshtml @@ -5,12 +5,14 @@ @using EventHub.Web.Pages.Events.Components.EventsArea @using EventHub.Web.Pages.Organizations.Components.JoinArea @using EventHub.Web.Pages.Organizations.Components.MembersArea +@using EventHub.Web.PaymentRequests @using Microsoft.AspNetCore.Mvc.Localization @using Microsoft.Extensions.Options @using Volo.Abp.Timing @model EventHub.Web.Pages.Organizations.ProfilePageModel @inject IClock Clock @inject IOptions UrlOptions +@inject IOptionsSnapshot PremiumPlanInfoOptionsSnapshot @section scripts { @@ -68,26 +70,36 @@ Edit - - - @if (Model.Organization.IsPremium) - { - Premium end date: @Model.Organization.PremiumEndDate!.Value.ToShortDateString() - @if (Model.Organization.PremiumEndDate!.Value.IsBetween(DateTime.Now, DateTime.Now.AddMonths(12 - 1))) + @if (PremiumPlanInfoOptionsSnapshot.Value.IsActive) + { + + + @if (Model.Organization.IsPremium) + { + Premium end date: @Model.Organization.PremiumEndDate!.Value.ToShortDateString() + @if (PremiumPlanInfoOptionsSnapshot.Value.IsExtendable && Model.Organization.PremiumEndDate!.Value.IsBetween(DateTime.Now, DateTime.Now.AddMonths(12 - 1))) + { + + @L["ExtendNow"].Value + + } + } + else { - - @L["ExtendNow"].Value + + @L["UpgradeToPremium"].Value } - } - else - { - - @L["UpgradeToPremium"].Value - - } - - + + + }else if (Model.Organization.IsPremium) + { + + + Premium end date: @Model.Organization.PremiumEndDate!.Value.ToShortDateString() + + + } } @await Component.InvokeAsync(typeof(JoinAreaViewComponent), new {organizationId = Model.Organization.Id}) @await Component.InvokeAsync(typeof(MembersAreaViewComponent), diff --git a/src/EventHub.Web/Pages/Payment/PostCheckout.cshtml b/src/EventHub.Web/Pages/Payment/PostCheckout.cshtml index 5a8b7d9..64849f0 100644 --- a/src/EventHub.Web/Pages/Payment/PostCheckout.cshtml +++ b/src/EventHub.Web/Pages/Payment/PostCheckout.cshtml @@ -15,18 +15,18 @@ @{ PageLayout.Content.Title = L["PaymentResult"] + L["Enum:PaymentRequestState:" + Model.PaymentRequest.State]; - var isExistExtraProperties = Model.PaymentRequest.ExtraProperties.TryGetValue(nameof(PaymentRequestProductExtraParameterConfiguration), out var ExtraProperties); + var isExistExtraProperties = Model.PaymentRequest.ExtraProperties.TryGetValue(nameof(OrganizationPaymentRequestExtraParameterConfiguration), out var ExtraProperties); if (!isExistExtraProperties) { throw new BadHttpRequestException(""); } - var paymentRequestProductExtraParameterConfiguration = JsonConvert.DeserializeObject(ExtraProperties.ToString()); - if (paymentRequestProductExtraParameterConfiguration is null) + var organizationPaymentExtraParameterConfiguration = JsonConvert.DeserializeObject(ExtraProperties.ToString()); + if (organizationPaymentExtraParameterConfiguration is null) { throw new BadHttpRequestException(""); } - var organizationName = paymentRequestProductExtraParameterConfiguration.OrganizationName; + var organizationName = organizationPaymentExtraParameterConfiguration.OrganizationName; }
diff --git a/src/EventHub.Web/Pages/Payment/PreCheckout.cshtml b/src/EventHub.Web/Pages/Payment/PreCheckout.cshtml index 62117c9..7ffc26b 100644 --- a/src/EventHub.Web/Pages/Payment/PreCheckout.cshtml +++ b/src/EventHub.Web/Pages/Payment/PreCheckout.cshtml @@ -1,5 +1,6 @@ @page @using EventHub.Organizations +@using EventHub.Web.PaymentRequests @using Microsoft.AspNetCore.Http @using Microsoft.Extensions.Options @using Newtonsoft.Json @@ -7,23 +8,22 @@ @using Payment.PaymentRequests @inherits Payment.Web.Pages.PaymentPageBase @model Payment.Web.Pages.Payment.PreCheckoutPageModel -@inject IOptionsSnapshot> OrganizationPlanInfoOptionsSnapshot +@inject IOptionsSnapshot PremiumPlanInfoOptionsSnapshot @{ - var isExistExtraProperties = Model.PaymentRequest.ExtraProperties.TryGetValue(nameof(PaymentRequestProductExtraParameterConfiguration), out var ExtraProperties); + var isExistExtraProperties = Model.PaymentRequest.ExtraProperties.TryGetValue(nameof(OrganizationPaymentRequestExtraParameterConfiguration), out var ExtraProperties); if (!isExistExtraProperties) { throw new BadHttpRequestException(""); } - var paymentRequestProductExtraParameterConfiguration = JsonConvert.DeserializeObject(ExtraProperties.ToString()); - if (paymentRequestProductExtraParameterConfiguration is null) + var organizationPaymentRequestExtraParameterConfiguration = JsonConvert.DeserializeObject(ExtraProperties.ToString()); + if (organizationPaymentRequestExtraParameterConfiguration is null) { throw new BadHttpRequestException(""); } - var organizationName = paymentRequestProductExtraParameterConfiguration.OrganizationName; - var targetPlanType = paymentRequestProductExtraParameterConfiguration.TargetPlanType; - var planInfo = OrganizationPlanInfoOptionsSnapshot.Value.First(o => o.PlanType == targetPlanType); + var organizationName = organizationPaymentRequestExtraParameterConfiguration.OrganizationName; + var planInfo = PremiumPlanInfoOptionsSnapshot.Value; } @section scripts { @@ -53,10 +53,10 @@

@Model.PaymentRequest.ProductName

- @if (!paymentRequestProductExtraParameterConfiguration.IsExtend) + @if (!organizationPaymentRequestExtraParameterConfiguration.IsExtend) { Operation: Upgrade - Target Plan: @targetPlanType + Target Plan: @OrganizationPlanType.Premium End date: @DateTime.Now.AddMonths(planInfo.OnePremiumPeriodAsMonth).ToShortDateString() } else diff --git a/src/EventHub.Web/Pages/Pricing.cshtml b/src/EventHub.Web/Pages/Pricing.cshtml index 4a6496d..e2d7bd8 100644 --- a/src/EventHub.Web/Pages/Pricing.cshtml +++ b/src/EventHub.Web/Pages/Pricing.cshtml @@ -1,6 +1,5 @@ @page @using EventHub.Localization -@using EventHub.Organizations @using Microsoft.AspNetCore.Mvc.Localization @model EventHub.Web.Pages.Pricing @inject IHtmlLocalizer L @@ -23,12 +22,11 @@
-
Normal
+
Normal
$ 0 - / year

1 Organization

@@ -41,12 +39,12 @@
- @foreach (var plan in Model.OrganizationPlanInfos.Where(x => x.IsActive)) + @if(Model.PremiumPlanInfo is not null) {
- @plan.PlanType + @Model.PremiumPlanInfo.PlanType @if (Model.Organization.IsPremium) { Current Plan @@ -55,8 +53,7 @@
$ - @plan.Price - / year + @Model.PremiumPlanInfo.Price

1 Organization

@@ -69,7 +66,7 @@ @if (Model.Organization.IsPremium) {
- + Extend Now @@ -77,9 +74,9 @@ else {
- + - Upgrade To @plan.PlanType + Upgrade To @Model.PremiumPlanInfo.PlanType }
diff --git a/src/EventHub.Web/Pages/Pricing.cshtml.cs b/src/EventHub.Web/Pages/Pricing.cshtml.cs index 476947c..93b7de0 100644 --- a/src/EventHub.Web/Pages/Pricing.cshtml.cs +++ b/src/EventHub.Web/Pages/Pricing.cshtml.cs @@ -1,7 +1,7 @@ -using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; using EventHub.Organizations; +using EventHub.Web.PaymentRequests; +using JetBrains.Annotations; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; using Payment.PaymentRequests; @@ -21,30 +21,34 @@ namespace EventHub.Web.Pages [BindProperty] public OrganizationPlanType TargetPlanToUpgrade { get; set; } - public List OrganizationPlanInfos { get; private set; } + [CanBeNull] + public PremiumPlanInfoOptions PremiumPlanInfo { get; private set; } public OrganizationProfileDto Organization { get; private set; } private readonly IOrganizationAppService _organizationAppService; private readonly IPaymentRequestAppService _paymentRequestAppService; private readonly IPaymentUrlBuilder _paymentUrlBuilder; - private readonly IOptionsSnapshot> _organizationPlanInfoOptionsSnapshot; + private readonly IOptionsSnapshot _premiumPlanInfoOptionsSnapshot; public Pricing( IOrganizationAppService organizationAppService, IPaymentRequestAppService paymentRequestAppService, IPaymentUrlBuilder paymentUrlBuilder, - IOptionsSnapshot> organizationPlanInfoOptionsSnapshot) + IOptionsSnapshot premiumPlanInfoOptionsSnapshot) { _organizationAppService = organizationAppService; _paymentRequestAppService = paymentRequestAppService; _paymentUrlBuilder = paymentUrlBuilder; - _organizationPlanInfoOptionsSnapshot = organizationPlanInfoOptionsSnapshot; + _premiumPlanInfoOptionsSnapshot = premiumPlanInfoOptionsSnapshot; } public async Task OnGetAsync() { - OrganizationPlanInfos = _organizationPlanInfoOptionsSnapshot.Value; + if (_premiumPlanInfoOptionsSnapshot.Value.IsActive) + { + PremiumPlanInfo = _premiumPlanInfoOptionsSnapshot.Value; + } Organization = await _organizationAppService.GetProfileAsync(OrganizationName); @@ -58,8 +62,8 @@ namespace EventHub.Web.Pages { var organization = await GetOrganizationProfileAsync(); - var plan = _organizationPlanInfoOptionsSnapshot.Value.FirstOrDefault(x => x.PlanType == TargetPlanToUpgrade && x.IsActive); - if (plan is null) + var plan = _premiumPlanInfoOptionsSnapshot.Value; + if (plan is null || !plan.IsActive) { Alerts.Danger("Premium plan is currently inactive!"); return Page(); @@ -74,8 +78,8 @@ namespace EventHub.Web.Pages { var organization = await GetOrganizationProfileAsync(); - var plan = _organizationPlanInfoOptionsSnapshot.Value.FirstOrDefault(x => x.PlanType == TargetPlanToUpgrade && x.IsActive); - if (plan is null) + var plan = _premiumPlanInfoOptionsSnapshot.Value; + if (plan is null || !plan.IsActive) { Alerts.Danger("Premium plan is currently inactive!"); return Page(); @@ -98,7 +102,7 @@ namespace EventHub.Web.Pages } private async Task CreatePaymentRequestAsync( - OrganizationPlanInfoOptions plan, + PremiumPlanInfoOptions plan, OrganizationProfileDto organization, bool isExtend = false) { @@ -106,16 +110,16 @@ namespace EventHub.Web.Pages { CustomerId = CurrentUser.GetId().ToString(), Price = plan.Price, - ProductId = OrganizationPlanInfoOptions.GetProductId(plan, isExtend), - ProductName = OrganizationPlanInfoOptions.GetProductName(plan, organization.Name, isExtend), + ProductId = PremiumPlanInfoOptions.GetProductId(plan, isExtend), + ProductName = PremiumPlanInfoOptions.GetProductName(plan, organization.Name, isExtend), ExtraProperties = { { - nameof(PaymentRequestProductExtraParameterConfiguration), - new PaymentRequestProductExtraParameterConfiguration + nameof(OrganizationPaymentRequestExtraParameterConfiguration), + new OrganizationPaymentRequestExtraParameterConfiguration { OrganizationName = OrganizationName, - TargetPlanType = TargetPlanToUpgrade, + PremiumPeriodAsMonth = plan.OnePremiumPeriodAsMonth, IsExtend = isExtend } } diff --git a/src/EventHub.Domain.Shared/Organizations/OrganizationPlanInfoOptions.cs b/src/EventHub.Web/PaymentRequests/PremiumPlanInfoOptions.cs similarity index 66% rename from src/EventHub.Domain.Shared/Organizations/OrganizationPlanInfoOptions.cs rename to src/EventHub.Web/PaymentRequests/PremiumPlanInfoOptions.cs index 771d255..3b2cef2 100644 --- a/src/EventHub.Domain.Shared/Organizations/OrganizationPlanInfoOptions.cs +++ b/src/EventHub.Web/PaymentRequests/PremiumPlanInfoOptions.cs @@ -1,44 +1,44 @@ -using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Text; +using EventHub.Organizations; using Volo.Abp; -namespace EventHub.Organizations +namespace EventHub.Web.PaymentRequests { - public class OrganizationPlanInfoOptions + public class PremiumPlanInfoOptions { private const string ProductNamePrefix = "EventHub"; - public const string OrganizationPlanInfo = "Organization:PlanInfo"; + public const string OrganizationPlanInfo = "PlanInfo:Premium"; - public OrganizationPlanType PlanType { get; set; } + public OrganizationPlanType PlanType { get; private set; } = OrganizationPlanType.Premium; - [DefaultValue(true)] + [DefaultValue(false)] public bool IsActive { get; set; } [Range(1.0, 100.0, ErrorMessage = "Value for {0} must be between {1} and {2}.")] public decimal Price { get; set; } = 1.0M; - [DefaultValue(true)] + [DefaultValue(false)] public bool IsExtendable { get; set; } - [Range(1, 12, ErrorMessage = "Value for {0} must be between {1} and {2}.")] - public int CanBeExtendedAfterHowManyMonths { get; set; } - + [Range(0, 12, ErrorMessage = "Value for {0} must be between {1} and {2}.")] + public int CanBeExtendedAfterHowManyMonths { get; set; } + [Range(1, 24, ErrorMessage = "Value for {0} must be between {1} and {2}.")] - public int OnePremiumPeriodAsMonth { get; set; } + public int OnePremiumPeriodAsMonth { get; set; } = 12; - public static string GetProductId(OrganizationPlanInfoOptions organizationPlan, bool isExtend) + public static string GetProductId(PremiumPlanInfoOptions premiumPlan, bool isExtend) { var productIdStringBuilder = new StringBuilder(ProductNamePrefix); productIdStringBuilder.Append("-"); - productIdStringBuilder.Append(organizationPlan.PlanType.ToString()); + productIdStringBuilder.Append(premiumPlan.PlanType.ToString()); productIdStringBuilder.Append("-"); if (isExtend) { - if (!organizationPlan.IsExtendable) + if (!premiumPlan.IsExtendable) { throw new BusinessException(); } @@ -54,16 +54,16 @@ namespace EventHub.Organizations return productIdStringBuilder.ToString(); } - public static string GetProductName(OrganizationPlanInfoOptions organizationPlan, string organizationName, bool isExtend) + public static string GetProductName(PremiumPlanInfoOptions premiumPlan, string organizationName, bool isExtend) { var productNameStringBuilder = new StringBuilder(ProductNamePrefix); productNameStringBuilder.Append(" "); - productNameStringBuilder.Append(organizationPlan.PlanType.ToString()); + productNameStringBuilder.Append(premiumPlan.PlanType.ToString()); productNameStringBuilder.Append(" "); if (isExtend) { - if (!organizationPlan.IsExtendable) + if (!premiumPlan.IsExtendable) { throw new BusinessException(); } diff --git a/src/EventHub.Web/appsettings.json b/src/EventHub.Web/appsettings.json index 2c4a520..9758b07 100644 --- a/src/EventHub.Web/appsettings.json +++ b/src/EventHub.Web/appsettings.json @@ -7,5 +7,14 @@ "RequireHttpsMetadata": "true", "ClientId": "EventHub_Web", "ClientSecret": "1q2w3e*" + }, + "PlanInfo": { + "Premium": { + "IsActive": true, + "Price": 29.90, + "IsExtendable": true, + "CanBeExtendedAfterHowManyMonths": 9, + "OnePremiumPeriodAsMonth": 12 + } } }