mirror of
https://github.com/bitwarden/server.git
synced 2025-04-08 06:28:14 -05:00
get rid of premium renewal jobs for braintree
This commit is contained in:
parent
f2aac6b8a0
commit
f70ececa9d
@ -26,17 +26,16 @@ namespace Bit.Billing.Jobs
|
|||||||
.WithCronSchedule("0 0 21 * * ?", x => x.InTimeZone(timeZone))
|
.WithCronSchedule("0 0 21 * * ?", x => x.InTimeZone(timeZone))
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
Jobs = new List<Tuple<Type, ITrigger>>
|
Jobs = new List<Tuple<Type, ITrigger>>();
|
||||||
{
|
|
||||||
new Tuple<Type, ITrigger>(typeof(PremiumRenewalRemindersJob), everyDayAtNinePmTrigger)
|
// Add jobs here
|
||||||
};
|
|
||||||
|
|
||||||
await base.StartAsync(cancellationToken);
|
await base.StartAsync(cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AddJobsServices(IServiceCollection services)
|
public static void AddJobsServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddTransient<PremiumRenewalRemindersJob>();
|
// Register jobs here
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,54 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Bit.Core;
|
|
||||||
using Bit.Core.Jobs;
|
|
||||||
using Bit.Core.Repositories;
|
|
||||||
using Bit.Core.Services;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Microsoft.Extensions.Options;
|
|
||||||
using Quartz;
|
|
||||||
|
|
||||||
namespace Bit.Billing.Jobs
|
|
||||||
{
|
|
||||||
public class PremiumRenewalRemindersJob : BaseJob
|
|
||||||
{
|
|
||||||
private readonly BillingSettings _billingSettings;
|
|
||||||
private readonly GlobalSettings _globalSettings;
|
|
||||||
private readonly IUserRepository _userRepository;
|
|
||||||
private readonly IMailService _mailService;
|
|
||||||
private readonly IPaymentService _paymentService;
|
|
||||||
|
|
||||||
public PremiumRenewalRemindersJob(
|
|
||||||
IOptions<BillingSettings> billingSettings,
|
|
||||||
GlobalSettings globalSettings,
|
|
||||||
IUserRepository userRepository,
|
|
||||||
IMailService mailService,
|
|
||||||
IPaymentService paymentService,
|
|
||||||
ILogger<PremiumRenewalRemindersJob> logger)
|
|
||||||
: base(logger)
|
|
||||||
{
|
|
||||||
_billingSettings = billingSettings?.Value;
|
|
||||||
_globalSettings = globalSettings;
|
|
||||||
_userRepository = userRepository;
|
|
||||||
_mailService = mailService;
|
|
||||||
_paymentService = paymentService;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async override Task ExecuteJobAsync(IJobExecutionContext context)
|
|
||||||
{
|
|
||||||
var users = await _userRepository.GetManyByPremiumRenewalAsync();
|
|
||||||
foreach(var user in users)
|
|
||||||
{
|
|
||||||
var upcomingInvoice = await _paymentService.GetUpcomingInvoiceAsync(user);
|
|
||||||
if(upcomingInvoice?.Date != null)
|
|
||||||
{
|
|
||||||
var items = new List<string> { "1 × Premium Membership (Annually)" };
|
|
||||||
await _mailService.SendInvoiceUpcomingAsync(user.Email, upcomingInvoice.Amount,
|
|
||||||
upcomingInvoice.Date.Value, items, false);
|
|
||||||
}
|
|
||||||
await _userRepository.UpdateRenewalReminderDateAsync(user.Id, DateTime.UtcNow);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -62,9 +62,9 @@ namespace Bit.Billing
|
|||||||
});
|
});
|
||||||
services.Configure<RouteOptions>(options => options.LowercaseUrls = true);
|
services.Configure<RouteOptions>(options => options.LowercaseUrls = true);
|
||||||
|
|
||||||
// Jobs service
|
// Jobs service, uncomment when we have some jobs to run
|
||||||
Jobs.JobsHostedService.AddJobsServices(services);
|
// Jobs.JobsHostedService.AddJobsServices(services);
|
||||||
services.AddHostedService<Jobs.JobsHostedService>();
|
// services.AddHostedService<Jobs.JobsHostedService>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Configure(
|
public void Configure(
|
||||||
|
@ -12,7 +12,6 @@ namespace Bit.Core.Repositories
|
|||||||
Task<UserKdfInformation> GetKdfInformationByEmailAsync(string email);
|
Task<UserKdfInformation> GetKdfInformationByEmailAsync(string email);
|
||||||
Task<ICollection<User>> SearchAsync(string email, int skip, int take);
|
Task<ICollection<User>> SearchAsync(string email, int skip, int take);
|
||||||
Task<ICollection<User>> GetManyByPremiumAsync(bool premium);
|
Task<ICollection<User>> GetManyByPremiumAsync(bool premium);
|
||||||
Task<ICollection<User>> GetManyByPremiumRenewalAsync();
|
|
||||||
Task<string> GetPublicKeyAsync(Guid id);
|
Task<string> GetPublicKeyAsync(Guid id);
|
||||||
Task<DateTime> GetAccountRevisionDateAsync(Guid id);
|
Task<DateTime> GetAccountRevisionDateAsync(Guid id);
|
||||||
Task UpdateStorageAsync(Guid id);
|
Task UpdateStorageAsync(Guid id);
|
||||||
|
@ -78,18 +78,6 @@ namespace Bit.Core.Repositories.SqlServer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ICollection<User>> GetManyByPremiumRenewalAsync()
|
|
||||||
{
|
|
||||||
using(var connection = new SqlConnection(ConnectionString))
|
|
||||||
{
|
|
||||||
var results = await connection.QueryAsync<User>(
|
|
||||||
"[dbo].[User_ReadByPremiumRenewal]",
|
|
||||||
commandType: CommandType.StoredProcedure);
|
|
||||||
|
|
||||||
return results.ToList();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<string> GetPublicKeyAsync(Guid id)
|
public async Task<string> GetPublicKeyAsync(Guid id)
|
||||||
{
|
{
|
||||||
using(var connection = new SqlConnection(ConnectionString))
|
using(var connection = new SqlConnection(ConnectionString))
|
||||||
|
@ -224,7 +224,6 @@
|
|||||||
<Build Include="dbo\Stored Procedures\OrganizationUser_ReadCountByOrganizationIdEmail.sql" />
|
<Build Include="dbo\Stored Procedures\OrganizationUser_ReadCountByOrganizationIdEmail.sql" />
|
||||||
<Build Include="dbo\Stored Procedures\CipherDetails_ReadWithoutOrganizationsByUserId.sql" />
|
<Build Include="dbo\Stored Procedures\CipherDetails_ReadWithoutOrganizationsByUserId.sql" />
|
||||||
<Build Include="dbo\Stored Procedures\CollectionCipher_UpdateCollectionsForCiphers.sql" />
|
<Build Include="dbo\Stored Procedures\CollectionCipher_UpdateCollectionsForCiphers.sql" />
|
||||||
<Build Include="dbo\Stored Procedures\User_ReadByPremiumRenewal.sql" />
|
|
||||||
<Build Include="dbo\Stored Procedures\User_UpdateRenewalReminderDate.sql" />
|
<Build Include="dbo\Stored Procedures\User_UpdateRenewalReminderDate.sql" />
|
||||||
<Build Include="dbo\Stored Procedures\Grant_DeleteExpired.sql" />
|
<Build Include="dbo\Stored Procedures\Grant_DeleteExpired.sql" />
|
||||||
<Build Include="dbo\Stored Procedures\U2f_DeleteOld.sql" />
|
<Build Include="dbo\Stored Procedures\U2f_DeleteOld.sql" />
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
CREATE PROCEDURE [dbo].[User_ReadByPremiumRenewal]
|
|
||||||
AS
|
|
||||||
BEGIN
|
|
||||||
SET NOCOUNT ON
|
|
||||||
|
|
||||||
DECLARE @WindowRef DATETIME2(7) = GETUTCDATE()
|
|
||||||
DECLARE @WindowStart DATETIME2(7) = DATEADD (day, -15, @WindowRef)
|
|
||||||
DECLARE @WindowEnd DATETIME2(7) = DATEADD (day, 15, @WindowRef)
|
|
||||||
|
|
||||||
SELECT
|
|
||||||
*
|
|
||||||
FROM
|
|
||||||
[dbo].[UserView]
|
|
||||||
WHERE
|
|
||||||
[Premium] = 1
|
|
||||||
AND [PremiumExpirationDate] >= @WindowRef
|
|
||||||
AND [PremiumExpirationDate] < @WindowEnd
|
|
||||||
AND (
|
|
||||||
[RenewalReminderDate] IS NULL
|
|
||||||
OR [RenewalReminderDate] < @WindowStart
|
|
||||||
)
|
|
||||||
AND [Gateway] = 1 -- Braintree
|
|
||||||
END
|
|
@ -245,3 +245,9 @@ BEGIN
|
|||||||
AND [GatewayId] = @GatewayId
|
AND [GatewayId] = @GatewayId
|
||||||
END
|
END
|
||||||
GO
|
GO
|
||||||
|
|
||||||
|
IF OBJECT_ID('[dbo].[User_ReadByPremiumRenewal]') IS NOT NULL
|
||||||
|
BEGIN
|
||||||
|
DROP PROCEDURE [dbo].[User_ReadByPremiumRenewal]
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
Loading…
x
Reference in New Issue
Block a user