Api: added payment/request

This commit is contained in:
pavelbannov 2022-09-04 18:30:32 +03:00
parent 53dc57eed7
commit 36714b4130
10 changed files with 147 additions and 13 deletions

View File

@ -26,7 +26,7 @@
namespace ASC.Web.Api.Routing;
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public class AllowNotPaymentAttribute : Attribute
{

View File

@ -562,6 +562,7 @@ public enum MessageAction
RoomInviteLinkUsed = 7001,
UserCreatedAndAddedToRoom = 7002,
GuestCreatedAndAddedToRoom = 7003,
ContactSalesMailSent = 7004,
#endregion

View File

@ -123,6 +123,7 @@ public class BackupController : ControllerBase
/// <param name="backupMail">Include mail in the backup</param>
/// <category>Backup</category>
/// <returns>Backup Progress</returns>
[AllowNotPayment]
[HttpPost("startbackup")]
public BackupProgress StartBackup(BackupDto backup)
{
@ -149,6 +150,7 @@ public class BackupController : ControllerBase
/// </summary>
/// <category>Backup</category>
/// <returns>Backup Progress</returns>
[AllowNotPayment]
[HttpGet("getbackupprogress")]
public BackupProgress GetBackupProgress()
{

View File

@ -29,6 +29,7 @@ namespace ASC.Web.Api.Controllers;
[Scope]
[DefaultRoute]
[ApiController]
[AllowNotPayment]
[ControllerName("portal")]
public class PaymentController : ControllerBase
{
@ -39,7 +40,12 @@ public class PaymentController : ControllerBase
private readonly SecurityContext _securityContext;
private readonly RegionHelper _regionHelper;
private readonly QuotaHelper _quotaHelper;
private readonly IMemoryCache _memoryCache;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly MessageService _messageService;
private readonly StudioNotifyService _studioNotifyService;
private readonly int _maxCount = 10;
private readonly int _expirationMinutes = 2;
protected Tenant Tenant { get { return _apiContext.Tenant; } }
public PaymentController(
@ -49,8 +55,11 @@ public class PaymentController : ControllerBase
ITariffService tariffService,
SecurityContext securityContext,
RegionHelper regionHelper,
QuotaHelper tariffHelper
)
QuotaHelper tariffHelper,
IMemoryCache memoryCache,
IHttpContextAccessor httpContextAccessor,
MessageService messageService,
StudioNotifyService studioNotifyService)
{
_apiContext = apiContext;
_userManager = userManager;
@ -59,9 +68,12 @@ public class PaymentController : ControllerBase
_securityContext = securityContext;
_regionHelper = regionHelper;
_quotaHelper = tariffHelper;
_memoryCache = memoryCache;
_httpContextAccessor = httpContextAccessor;
_messageService = messageService;
_studioNotifyService = studioNotifyService;
}
[AllowNotPayment]
[HttpPut("payment/url")]
public Uri GetPaymentUrl(PaymentUrlRequestsDto inDto)
{
@ -80,7 +92,6 @@ public class PaymentController : ControllerBase
inDto.BackUrl);
}
[AllowNotPayment]
[HttpPut("payment/update")]
public bool PaymentUpdate(PaymentUrlRequestsDto inDto)
{
@ -93,7 +104,6 @@ public class PaymentController : ControllerBase
return _tariffService.PaymentChange(Tenant.Id, inDto.Quantity);
}
[AllowNotPayment]
[HttpGet("payment/account")]
public Uri GetPaymentAccount(string backUrl)
{
@ -108,7 +118,6 @@ public class PaymentController : ControllerBase
return _tariffService.GetAccountLink(Tenant.Id, backUrl);
}
[AllowNotPayment]
[HttpGet("payment/prices")]
public object GetPrices()
{
@ -118,7 +127,7 @@ public class PaymentController : ControllerBase
return result;
}
[AllowNotPayment]
[HttpGet("payment/currencies")]
public IEnumerable<CurrenciesDto> GetCurrencies()
{
@ -133,10 +142,42 @@ public class PaymentController : ControllerBase
}
}
[AllowNotPayment]
[HttpGet("payment/quotas")]
public IEnumerable<QuotaDto> GetQuotas()
{
return _quotaHelper.GetQuotas();
}
[HttpPost("payment/request")]
public void SendSalesRequest(SalesRequestsDto inDto)
{
if (!inDto.Email.TestEmailRegex())
{
throw new Exception(Resource.ErrorNotCorrectEmail);
}
if (string.IsNullOrEmpty(inDto.Message))
{
throw new Exception(Resource.ErrorEmptyMessage);
}
CheckCache("salesrequest");
_studioNotifyService.SendMsgToSales(inDto.Email, inDto.UserName, inDto.Message);
_messageService.Send(MessageAction.ContactSalesMailSent);
}
internal void CheckCache(string basekey)
{
var key = _httpContextAccessor.HttpContext.Request.GetUserHostAddress() + basekey;
if (_memoryCache.TryGetValue<int>(key, out var count))
{
if (count > _maxCount)
{
throw new Exception(Resource.ErrorRequestLimitExceeded);
}
}
_memoryCache.Set(key, count + 1, TimeSpan.FromMinutes(_expirationMinutes));
}
}

View File

@ -0,0 +1,34 @@
// (c) Copyright Ascensio System SIA 2010-2022
//
// This program is a free software product.
// You can redistribute it and/or modify it under the terms
// of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software
// Foundation. In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended
// to the effect that Ascensio System SIA expressly excludes the warranty of non-infringement of
// any third-party rights.
//
// This program is distributed WITHOUT ANY WARRANTY, without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, see
// the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
//
// You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021.
//
// The interactive user interfaces in modified source and object code versions of the Program must
// display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3.
//
// Pursuant to Section 7(b) of the License you must retain the original Product logo when
// distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under
// trademark law for use of our trademarks.
//
// All the Product's GUI elements, including illustrations and icon sets, as well as technical writing
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
namespace ASC.Web.Api.ApiModels.RequestsDto;
public class SalesRequestsDto
{
public string UserName { get; set; }
public string Email { get; set; }
public string Message { get; set; }
}

View File

@ -34,6 +34,7 @@ public static class Actions
public static readonly INotifyAction SelfProfileUpdated = new NotifyAction("self_profile_updated", "self profile updated");
public static readonly INotifyAction UserHasJoin = new NotifyAction("user_has_join", "user has join");
public static readonly INotifyAction UserMessageToAdmin = new NotifyAction("for_admin_notify", "for_admin_notify");
public static readonly INotifyAction UserMessageToSales = new NotifyAction("for_sales_notify", "for_sales_notify");
public static readonly INotifyAction RequestTariff = new NotifyAction("request_tariff", "request_tariff");
public static readonly INotifyAction RequestLicense = new NotifyAction("request_license", "request_license");

View File

@ -98,6 +98,19 @@ public class StudioNotifyService
_client.SendNoticeAsync(Actions.UserMessageToAdmin, null, new TagValue(Tags.Body, message), new TagValue(Tags.UserEmail, email));
}
public void SendMsgToSales(string email, string userName, string message)
{
var settings = _settingsManager.LoadForDefaultTenant<AdditionalWhiteLabelSettings>();
_client.SendNoticeToAsync(
Actions.UserMessageToSales,
_studioNotifyHelper.RecipientFromEmail(settings.SalesEmail, false),
new[] { EMailSenderName },
new TagValue(Tags.Body, message),
new TagValue(Tags.UserEmail, email),
new TagValue(Tags.UserName, userName));
}
public void SendRequestTariff(bool license, string fname, string lname, string title, string email, string phone, string ctitle, string csize, string site, string message)
{
fname = (fname ?? "").Trim();

View File

@ -1129,6 +1129,21 @@ namespace ASC.Web.Core.PublicResources {
}
}
/// <summary>
/// Looks up a localized string similar to h1.Message from the &quot;${__VirtualRootPath}&quot;:&quot;${__VirtualRootPath}&quot; portal
///
///Name: $UserName
///
///Email: $UserEmail
///
///$Body.
/// </summary>
public static string pattern_for_sales_notify {
get {
return ResourceManager.GetString("pattern_for_sales_notify", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to h1.Invitation to join &quot;${__VirtualRootPath}&quot;:&quot;$InviteLink&quot; portal
///
@ -2870,6 +2885,15 @@ namespace ASC.Web.Core.PublicResources {
}
}
/// <summary>
/// Looks up a localized string similar to Sales department request.
/// </summary>
public static string subject_for_sales_notify {
get {
return ResourceManager.GetString("subject_for_sales_notify", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Invitation to join ${__VirtualRootPath} portal.
/// </summary>

View File

@ -2109,4 +2109,16 @@ Dont want to change your password? Just ignore this message.</value>
<data name="subject_personal_already_exist" xml:space="preserve">
<value>Log in to your ONLYOFFICE Personal account</value>
</data>
<data name="pattern_for_sales_notify" xml:space="preserve">
<value>h1.Message from the "${__VirtualRootPath}":"${__VirtualRootPath}" portal
Name: $UserName
Email: $UserEmail
$Body</value>
</data>
<data name="subject_for_sales_notify" xml:space="preserve">
<value>Sales department request</value>
</data>
</root>

View File

@ -43,6 +43,12 @@
<body styler="ASC.Notify.Textile.MarkDownStyler,ASC.Notify.Textile" resource="|pattern_for_admin_notify_tg|ASC.Web.Core.PublicResources.WebstudioNotifyPatternResource,ASC.Web.Core" />
</pattern>
<!-- for_sales_notify -->
<pattern id="for_sales_notify" sender="email.sender">
<subject resource="|subject_for_sales_notify|ASC.Web.Core.PublicResources.WebstudioNotifyPatternResource,ASC.Web.Core"></subject>
<body styler="ASC.Notify.Textile.TextileStyler,ASC.Notify.Textile" resource="|pattern_for_sales_notify|ASC.Web.Core.PublicResources.WebstudioNotifyPatternResource,ASC.Web.Core" />
</pattern>
<!-- profile_updated -->
<pattern id="profile_updated" sender="email.sender">
<subject resource="|subject_profile_updated|ASC.Web.Core.PublicResources.WebstudioNotifyPatternResource,ASC.Web.Core" />