1
0
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:
Kyle Spearrin
2018-07-12 23:23:41 -04:00
parent 476ee53931
commit 938b7f1230
12 changed files with 221 additions and 0 deletions

View File

@ -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; }

View 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();
}
}
}

View File

@ -46,6 +46,7 @@
}
},
"billingSettings": {
"jobsKey": "SECRET",
"stripeWebhookKey": "SECRET",
"stripeWebhookSecret": "SECRET",
"braintreeWebhookKey": "SECRET"