mirror of
https://github.com/bitwarden/server.git
synced 2025-07-03 00:52:49 -05:00
premium renewal reminders job for braintree
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
{
|
||||
public class BillingSettings
|
||||
{
|
||||
public virtual string JobsKey { get; set; }
|
||||
public virtual string StripeWebhookKey { get; set; }
|
||||
public virtual string StripeWebhookSecret { get; set; }
|
||||
public virtual string BraintreeWebhookKey { get; set; }
|
||||
|
57
src/Billing/Controllers/JobsController.cs
Normal file
57
src/Billing/Controllers/JobsController.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using Bit.Core;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bit.Billing.Controllers
|
||||
{
|
||||
[Route("jobs")]
|
||||
public class JobsController : Controller
|
||||
{
|
||||
private readonly BillingSettings _billingSettings;
|
||||
private readonly GlobalSettings _globalSettings;
|
||||
private readonly IUserRepository _userRepository;
|
||||
private readonly IMailService _mailService;
|
||||
|
||||
public JobsController(
|
||||
IOptions<BillingSettings> billingSettings,
|
||||
GlobalSettings globalSettings,
|
||||
IUserRepository userRepository,
|
||||
IMailService mailService)
|
||||
{
|
||||
_billingSettings = billingSettings?.Value;
|
||||
_globalSettings = globalSettings;
|
||||
_userRepository = userRepository;
|
||||
_mailService = mailService;
|
||||
}
|
||||
|
||||
[HttpPost("premium-renewal-reminders")]
|
||||
public async Task<IActionResult> GetPremiumRenewalReminders([FromQuery] string key)
|
||||
{
|
||||
if(key != _billingSettings.JobsKey)
|
||||
{
|
||||
return new BadRequestResult();
|
||||
}
|
||||
|
||||
var users = await _userRepository.GetManyByPremiumRenewalAsync();
|
||||
foreach(var user in users)
|
||||
{
|
||||
var paymentService = user.GetPaymentService(_globalSettings);
|
||||
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);
|
||||
}
|
||||
|
||||
return new OkResult();
|
||||
}
|
||||
}
|
||||
}
|
@ -46,6 +46,7 @@
|
||||
}
|
||||
},
|
||||
"billingSettings": {
|
||||
"jobsKey": "SECRET",
|
||||
"stripeWebhookKey": "SECRET",
|
||||
"stripeWebhookSecret": "SECRET",
|
||||
"braintreeWebhookKey": "SECRET"
|
||||
|
Reference in New Issue
Block a user