mirror of
https://github.com/bitwarden/server.git
synced 2025-05-20 11:04:31 -05:00
added credit email notification
This commit is contained in:
parent
25c8d6d043
commit
c5b2a929d2
@ -117,11 +117,13 @@ namespace Bit.Billing.Controllers
|
|||||||
|
|
||||||
if(isAccountCredit)
|
if(isAccountCredit)
|
||||||
{
|
{
|
||||||
|
string billingEmail = null;
|
||||||
if(tx.OrganizationId.HasValue)
|
if(tx.OrganizationId.HasValue)
|
||||||
{
|
{
|
||||||
var org = await _organizationRepository.GetByIdAsync(tx.OrganizationId.Value);
|
var org = await _organizationRepository.GetByIdAsync(tx.OrganizationId.Value);
|
||||||
if(org != null)
|
if(org != null)
|
||||||
{
|
{
|
||||||
|
billingEmail = org.BillingEmailAddress();
|
||||||
if(await _paymentService.CreditAccountAsync(org, tx.Amount))
|
if(await _paymentService.CreditAccountAsync(org, tx.Amount))
|
||||||
{
|
{
|
||||||
await _organizationRepository.ReplaceAsync(org);
|
await _organizationRepository.ReplaceAsync(org);
|
||||||
@ -133,6 +135,7 @@ namespace Bit.Billing.Controllers
|
|||||||
var user = await _userRepository.GetByIdAsync(tx.UserId.Value);
|
var user = await _userRepository.GetByIdAsync(tx.UserId.Value);
|
||||||
if(user != null)
|
if(user != null)
|
||||||
{
|
{
|
||||||
|
billingEmail = user.BillingEmailAddress();
|
||||||
if(await _paymentService.CreditAccountAsync(user, tx.Amount))
|
if(await _paymentService.CreditAccountAsync(user, tx.Amount))
|
||||||
{
|
{
|
||||||
await _userRepository.ReplaceAsync(user);
|
await _userRepository.ReplaceAsync(user);
|
||||||
@ -140,7 +143,10 @@ namespace Bit.Billing.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Send email about credit added?
|
if(!string.IsNullOrWhiteSpace(billingEmail))
|
||||||
|
{
|
||||||
|
await _mailService.SendAddedCreditAsync(billingEmail, tx.Amount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Catch foreign key violations because user/org could have been deleted.
|
// Catch foreign key violations because user/org could have been deleted.
|
||||||
|
@ -258,11 +258,13 @@ namespace Bit.Billing.Controllers
|
|||||||
|
|
||||||
if(ipnTransaction.IsAccountCredit())
|
if(ipnTransaction.IsAccountCredit())
|
||||||
{
|
{
|
||||||
|
string billingEmail = null;
|
||||||
if(tx.OrganizationId.HasValue)
|
if(tx.OrganizationId.HasValue)
|
||||||
{
|
{
|
||||||
var org = await _organizationRepository.GetByIdAsync(tx.OrganizationId.Value);
|
var org = await _organizationRepository.GetByIdAsync(tx.OrganizationId.Value);
|
||||||
if(org != null)
|
if(org != null)
|
||||||
{
|
{
|
||||||
|
billingEmail = org.BillingEmailAddress();
|
||||||
if(await _paymentService.CreditAccountAsync(org, tx.Amount))
|
if(await _paymentService.CreditAccountAsync(org, tx.Amount))
|
||||||
{
|
{
|
||||||
await _organizationRepository.ReplaceAsync(org);
|
await _organizationRepository.ReplaceAsync(org);
|
||||||
@ -274,6 +276,7 @@ namespace Bit.Billing.Controllers
|
|||||||
var user = await _userRepository.GetByIdAsync(tx.UserId.Value);
|
var user = await _userRepository.GetByIdAsync(tx.UserId.Value);
|
||||||
if(user != null)
|
if(user != null)
|
||||||
{
|
{
|
||||||
|
billingEmail = user.BillingEmailAddress();
|
||||||
if(await _paymentService.CreditAccountAsync(user, tx.Amount))
|
if(await _paymentService.CreditAccountAsync(user, tx.Amount))
|
||||||
{
|
{
|
||||||
await _userRepository.ReplaceAsync(user);
|
await _userRepository.ReplaceAsync(user);
|
||||||
@ -281,7 +284,10 @@ namespace Bit.Billing.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Send email about credit added?
|
if(!string.IsNullOrWhiteSpace(billingEmail))
|
||||||
|
{
|
||||||
|
await _mailService.SendAddedCreditAsync(billingEmail, tx.Amount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Catch foreign key violations because user/org could have been deleted.
|
// Catch foreign key violations because user/org could have been deleted.
|
||||||
|
14
src/Core/MailTemplates/Handlebars/AddedCredit.html.hbs
Normal file
14
src/Core/MailTemplates/Handlebars/AddedCredit.html.hbs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{{#>FullHtmlLayout}}
|
||||||
|
<table width="100%" cellpadding="0" cellspacing="0" style="margin: 0; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; box-sizing: border-box; font-size: 16px; color: #333; line-height: 25px; -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: none;">
|
||||||
|
<tr style="margin: 0; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; box-sizing: border-box; font-size: 16px; color: #333; line-height: 25px; -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: none;">
|
||||||
|
<td class="content-block" style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; box-sizing: border-box; font-size: 16px; color: #333; line-height: 25px; margin: 0; -webkit-font-smoothing: antialiased; padding: 0 0 10px; -webkit-text-size-adjust: none;" valign="top">
|
||||||
|
A <b style="margin: 0; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; box-sizing: border-box; font-size: 16px; color: #333; line-height: 25px; -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: none;">{{usd Amount}}</b> payment has been processed and credited to your account. This credit is now available to make purchases.
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr style="margin: 0; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; box-sizing: border-box; font-size: 16px; color: #333; line-height: 25px; -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: none;">
|
||||||
|
<td class="content-block" style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; box-sizing: border-box; font-size: 16px; color: #333; line-height: 25px; margin: 0; -webkit-font-smoothing: antialiased; padding: 0; -webkit-text-size-adjust: none;" valign="top">
|
||||||
|
You can view your account's available credit by logging into the web vault at {{{link WebVaultUrl}}}. Once logged in, navigate to the Billing page for your account.
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
{{/FullHtmlLayout}}
|
5
src/Core/MailTemplates/Handlebars/AddedCredit.text.hbs
Normal file
5
src/Core/MailTemplates/Handlebars/AddedCredit.text.hbs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{{#>BasicTextLayout}}
|
||||||
|
A {{usd Amount}} payment has been processed and credited to your account. This credit is now available to make purchases.
|
||||||
|
|
||||||
|
You can view your account's available credit by logging into the web vault at {{{WebVaultUrl}}}. Once logged in, navigate to the Billing page for your account.
|
||||||
|
{{/BasicTextLayout}}
|
7
src/Core/Models/Mail/AddedCreditViewModel.cs
Normal file
7
src/Core/Models/Mail/AddedCreditViewModel.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace Bit.Core.Models.Mail
|
||||||
|
{
|
||||||
|
public class AddedCreditViewModel : BaseMailModel
|
||||||
|
{
|
||||||
|
public decimal Amount { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -23,6 +23,7 @@ namespace Bit.Core.Services
|
|||||||
Task SendInvoiceUpcomingAsync(string email, decimal amount, DateTime dueDate, List<string> items,
|
Task SendInvoiceUpcomingAsync(string email, decimal amount, DateTime dueDate, List<string> items,
|
||||||
bool mentionInvoices);
|
bool mentionInvoices);
|
||||||
Task SendPaymentFailedAsync(string email, decimal amount, bool mentionInvoices);
|
Task SendPaymentFailedAsync(string email, decimal amount, bool mentionInvoices);
|
||||||
|
Task SendAddedCreditAsync(string email, decimal amount);
|
||||||
Task SendNewDeviceLoggedInEmail(string email, string deviceType, DateTime timestamp, string ip);
|
Task SendNewDeviceLoggedInEmail(string email, string deviceType, DateTime timestamp, string ip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -251,6 +251,20 @@ namespace Bit.Core.Services
|
|||||||
await _mailDeliveryService.SendEmailAsync(message);
|
await _mailDeliveryService.SendEmailAsync(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task SendAddedCreditAsync(string email, decimal amount)
|
||||||
|
{
|
||||||
|
var message = CreateDefaultMessage("Account Credit Payment Processed", email);
|
||||||
|
var model = new AddedCreditViewModel
|
||||||
|
{
|
||||||
|
WebVaultUrl = _globalSettings.BaseServiceUri.VaultWithHash,
|
||||||
|
SiteName = _globalSettings.SiteName,
|
||||||
|
Amount = amount
|
||||||
|
};
|
||||||
|
await AddMessageContentAsync(message, "AddedCredit", model);
|
||||||
|
message.MetaData.Add("SendGridCategories", new List<string> { "AddedCredit" });
|
||||||
|
await _mailDeliveryService.SendEmailAsync(message);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task SendNewDeviceLoggedInEmail(string email, string deviceType, DateTime timestamp, string ip)
|
public async Task SendNewDeviceLoggedInEmail(string email, string deviceType, DateTime timestamp, string ip)
|
||||||
{
|
{
|
||||||
var message = CreateDefaultMessage($"New Device Logged In From {deviceType}", email);
|
var message = CreateDefaultMessage($"New Device Logged In From {deviceType}", email);
|
||||||
|
@ -78,6 +78,11 @@ namespace Bit.Core.Services
|
|||||||
return Task.FromResult(0);
|
return Task.FromResult(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task SendAddedCreditAsync(string email, decimal amount)
|
||||||
|
{
|
||||||
|
return Task.FromResult(0);
|
||||||
|
}
|
||||||
|
|
||||||
public Task SendNewDeviceLoggedInEmail(string email, string deviceType, DateTime timestamp, string ip)
|
public Task SendNewDeviceLoggedInEmail(string email, string deviceType, DateTime timestamp, string ip)
|
||||||
{
|
{
|
||||||
return Task.FromResult(0);
|
return Task.FromResult(0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user