mirror of
https://github.com/bitwarden/server.git
synced 2025-04-06 21:48:12 -05:00
add some logging to stripe webhook
This commit is contained in:
parent
09592fd4d3
commit
c1b271193b
@ -5,6 +5,7 @@ using Bit.Core.Repositories;
|
|||||||
using Bit.Core.Services;
|
using Bit.Core.Services;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using Stripe;
|
using Stripe;
|
||||||
using System;
|
using System;
|
||||||
@ -26,6 +27,7 @@ namespace Bit.Billing.Controllers
|
|||||||
private readonly ITransactionRepository _transactionRepository;
|
private readonly ITransactionRepository _transactionRepository;
|
||||||
private readonly IUserService _userService;
|
private readonly IUserService _userService;
|
||||||
private readonly IMailService _mailService;
|
private readonly IMailService _mailService;
|
||||||
|
private readonly ILogger<StripeController> _logger;
|
||||||
private readonly Braintree.BraintreeGateway _btGateway;
|
private readonly Braintree.BraintreeGateway _btGateway;
|
||||||
|
|
||||||
public StripeController(
|
public StripeController(
|
||||||
@ -36,7 +38,8 @@ namespace Bit.Billing.Controllers
|
|||||||
IOrganizationRepository organizationRepository,
|
IOrganizationRepository organizationRepository,
|
||||||
ITransactionRepository transactionRepository,
|
ITransactionRepository transactionRepository,
|
||||||
IUserService userService,
|
IUserService userService,
|
||||||
IMailService mailService)
|
IMailService mailService,
|
||||||
|
ILogger<StripeController> logger)
|
||||||
{
|
{
|
||||||
_billingSettings = billingSettings?.Value;
|
_billingSettings = billingSettings?.Value;
|
||||||
_hostingEnvironment = hostingEnvironment;
|
_hostingEnvironment = hostingEnvironment;
|
||||||
@ -45,7 +48,7 @@ namespace Bit.Billing.Controllers
|
|||||||
_transactionRepository = transactionRepository;
|
_transactionRepository = transactionRepository;
|
||||||
_userService = userService;
|
_userService = userService;
|
||||||
_mailService = mailService;
|
_mailService = mailService;
|
||||||
|
_logger = logger;
|
||||||
_btGateway = new Braintree.BraintreeGateway
|
_btGateway = new Braintree.BraintreeGateway
|
||||||
{
|
{
|
||||||
Environment = globalSettings.Braintree.Production ?
|
Environment = globalSettings.Braintree.Production ?
|
||||||
@ -74,11 +77,13 @@ namespace Bit.Billing.Controllers
|
|||||||
|
|
||||||
if(string.IsNullOrWhiteSpace(parsedEvent?.Id))
|
if(string.IsNullOrWhiteSpace(parsedEvent?.Id))
|
||||||
{
|
{
|
||||||
|
_logger.LogWarning("No event id.");
|
||||||
return new BadRequestResult();
|
return new BadRequestResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(_hostingEnvironment.IsProduction() && !parsedEvent.Livemode)
|
if(_hostingEnvironment.IsProduction() && !parsedEvent.Livemode)
|
||||||
{
|
{
|
||||||
|
_logger.LogWarning("Getting test events in production.");
|
||||||
return new BadRequestResult();
|
return new BadRequestResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,6 +185,7 @@ namespace Bit.Billing.Controllers
|
|||||||
GatewayType.Stripe, charge.Id);
|
GatewayType.Stripe, charge.Id);
|
||||||
if(chargeTransaction != null)
|
if(chargeTransaction != null)
|
||||||
{
|
{
|
||||||
|
_logger.LogWarning("Charge success already processed. " + charge.Id);
|
||||||
return new OkResult();
|
return new OkResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,6 +226,7 @@ namespace Bit.Billing.Controllers
|
|||||||
|
|
||||||
if(!ids.Item1.HasValue && !ids.Item2.HasValue)
|
if(!ids.Item1.HasValue && !ids.Item2.HasValue)
|
||||||
{
|
{
|
||||||
|
_logger.LogWarning("Charge success has no subscriber ids. " + charge.Id);
|
||||||
return new BadRequestResult();
|
return new BadRequestResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,6 +253,7 @@ namespace Bit.Billing.Controllers
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
_logger.LogWarning("Charge success from unsupported source. " + charge.Id);
|
||||||
return new OkResult();
|
return new OkResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -305,6 +313,10 @@ namespace Bit.Billing.Controllers
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Charge refund amount doesn't seem correct. " + charge.Id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(parsedEvent.Type.Equals("invoice.payment_failed"))
|
else if(parsedEvent.Type.Equals("invoice.payment_failed"))
|
||||||
{
|
{
|
||||||
@ -330,6 +342,10 @@ namespace Bit.Billing.Controllers
|
|||||||
await AttemptToPayInvoiceWithBraintreeAsync(invoice);
|
await AttemptToPayInvoiceWithBraintreeAsync(invoice);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Unsupported event received. " + parsedEvent.Type);
|
||||||
|
}
|
||||||
|
|
||||||
return new OkResult();
|
return new OkResult();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user