mirror of
https://github.com/bitwarden/server.git
synced 2025-05-23 20:41:04 -05:00
freshdesk webhook improvements
This commit is contained in:
parent
b679c2b2db
commit
726ce2510f
@ -24,6 +24,7 @@ namespace Bit.Billing.Controllers
|
|||||||
private readonly IOrganizationUserRepository _organizationUserRepository;
|
private readonly IOrganizationUserRepository _organizationUserRepository;
|
||||||
private readonly ILogger<AppleController> _logger;
|
private readonly ILogger<AppleController> _logger;
|
||||||
private readonly HttpClient _httpClient = new HttpClient();
|
private readonly HttpClient _httpClient = new HttpClient();
|
||||||
|
private readonly string _freshdeskAuthkey;
|
||||||
|
|
||||||
public FreshdeskController(
|
public FreshdeskController(
|
||||||
IUserRepository userRepository,
|
IUserRepository userRepository,
|
||||||
@ -37,6 +38,8 @@ namespace Bit.Billing.Controllers
|
|||||||
_organizationRepository = organizationRepository;
|
_organizationRepository = organizationRepository;
|
||||||
_organizationUserRepository = organizationUserRepository;
|
_organizationUserRepository = organizationUserRepository;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
_freshdeskAuthkey = Convert.ToBase64String(
|
||||||
|
Encoding.UTF8.GetBytes($"{_billingSettings.FreshdeskApiKey}:X"));
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("webhook")]
|
[HttpPost("webhook")]
|
||||||
@ -85,12 +88,12 @@ namespace Bit.Billing.Controllers
|
|||||||
tags.Add("Premium");
|
tags.Add("Premium");
|
||||||
}
|
}
|
||||||
var orgs = await _organizationRepository.GetManyByUserIdAsync(user.Id);
|
var orgs = await _organizationRepository.GetManyByUserIdAsync(user.Id);
|
||||||
if(orgs.Any())
|
foreach(var org in orgs)
|
||||||
{
|
{
|
||||||
foreach(var org in orgs)
|
var planName = GetAttribute<DisplayAttribute>(org.PlanType).Name.Split(" ").FirstOrDefault();
|
||||||
|
if(!string.IsNullOrWhiteSpace(planName))
|
||||||
{
|
{
|
||||||
tags.Add(string.Format("Org: {0}",
|
tags.Add(string.Format("Org: {0}", planName));
|
||||||
GetAttribute<DisplayAttribute>(org.PlanType).Name.Split(" ").FirstOrDefault()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var hasPaidOrg = orgs.Any(o => o.PlanType != Core.Enums.PlanType.Free &&
|
var hasPaidOrg = orgs.Any(o => o.PlanType != Core.Enums.PlanType.Free &&
|
||||||
@ -124,8 +127,7 @@ namespace Bit.Billing.Controllers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var authKey = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{_billingSettings.FreshdeskApiKey}:X"));
|
request.Headers.Add("Authorization", _freshdeskAuthkey);
|
||||||
request.Headers.Add("Authorization", authKey);
|
|
||||||
var response = await _httpClient.SendAsync(request);
|
var response = await _httpClient.SendAsync(request);
|
||||||
if(response.StatusCode != System.Net.HttpStatusCode.TooManyRequests || retriedCount > 3)
|
if(response.StatusCode != System.Net.HttpStatusCode.TooManyRequests || retriedCount > 3)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user