1
0
mirror of https://github.com/bitwarden/server.git synced 2024-12-30 18:17:36 +01:00

webhook fixes

This commit is contained in:
Kyle Spearrin 2019-02-15 16:18:53 -05:00
parent fb21b19490
commit dee395960a
3 changed files with 63 additions and 49 deletions

View File

@ -47,7 +47,7 @@ namespace Bit.Billing.Controllers
body = await reader.ReadToEndAsync();
}
if(body == null)
if(string.IsNullOrWhiteSpace(body))
{
return new BadRequestResult();
}

View File

@ -176,30 +176,45 @@ namespace Bit.Billing.Controllers
throw new Exception("Charge is null.");
}
if(charge.InvoiceId == null)
var chargeTransaction = await _transactionRepository.GetByGatewayIdAsync(
GatewayType.Stripe, charge.Id);
if(chargeTransaction != null)
{
return new OkResult();
}
var chargeTransaction = await _transactionRepository.GetByGatewayIdAsync(
GatewayType.Stripe, charge.Id);
if(chargeTransaction == null)
Tuple<Guid?, Guid?> ids = null;
Subscription subscription = null;
var subscriptionService = new SubscriptionService();
if(charge.InvoiceId != null)
{
var invoiceService = new InvoiceService();
var invoice = await invoiceService.GetAsync(charge.InvoiceId);
if(invoice == null)
if(invoice?.SubscriptionId != null)
{
return new OkResult();
subscription = await subscriptionService.GetAsync(invoice.SubscriptionId);
ids = GetIdsFromMetaData(subscription?.Metadata);
}
}
var subscriptionService = new SubscriptionService();
var subscription = await subscriptionService.GetAsync(invoice.SubscriptionId);
if(subscription == null)
if(subscription == null || ids == null || (ids.Item1.HasValue && ids.Item2.HasValue))
{
return new OkResult();
var subscriptions = await subscriptionService.ListAsync(new SubscriptionListOptions
{
CustomerId = charge.CustomerId
});
foreach(var sub in subscriptions)
{
ids = GetIdsFromMetaData(sub.Metadata);
if(ids.Item1.HasValue || ids.Item2.HasValue)
{
subscription = sub;
break;
}
}
}
var ids = GetIdsFromMetaData(subscription.Metadata);
if(ids.Item1.HasValue || ids.Item2.HasValue)
{
var tx = new Transaction
@ -236,7 +251,6 @@ namespace Bit.Billing.Controllers
catch(SqlException e) when(e.Number == 547) { }
}
}
}
else if(parsedEvent.Type.Equals("charge.refunded"))
{
if(!(parsedEvent.Data.Object is Charge charge))
@ -317,7 +331,7 @@ namespace Bit.Billing.Controllers
private Tuple<Guid?, Guid?> GetIdsFromMetaData(IDictionary<string, string> metaData)
{
if(metaData == null)
if(metaData == null || !metaData.Any())
{
return new Tuple<Guid?, Guid?>(null, null);
}

View File

@ -18,7 +18,7 @@
},
"billingSettings": {
"payPal": {
"production": false
"production": true
}
}
}