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

Fixed 500 from invoice.upcoming not having an ID (#3128)

This commit is contained in:
Conner Turnbull 2023-07-21 22:57:23 -04:00 committed by GitHub
parent 10782d55f3
commit 51ee463a71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -512,6 +512,10 @@ public class StripeController : Controller
break; break;
} }
case HandledStripeWebhook.UpcomingInvoice: case HandledStripeWebhook.UpcomingInvoice:
var eventInvoice = await GetInvoiceAsync(parsedEvent);
var customer = await GetCustomerAsync(eventInvoice.CustomerId);
customerRegion = GetCustomerRegionFromMetadata(customer.Metadata);
break;
case HandledStripeWebhook.PaymentSucceeded: case HandledStripeWebhook.PaymentSucceeded:
case HandledStripeWebhook.PaymentFailed: case HandledStripeWebhook.PaymentFailed:
case HandledStripeWebhook.InvoiceCreated: case HandledStripeWebhook.InvoiceCreated:
@ -864,6 +868,23 @@ public class StripeController : Controller
return subscription; return subscription;
} }
private async Task<Customer> GetCustomerAsync(string customerId)
{
if (string.IsNullOrWhiteSpace(customerId))
{
throw new Exception("Customer ID cannot be empty when attempting to get a customer from Stripe");
}
var customerService = new CustomerService();
var customer = await customerService.GetAsync(customerId);
if (customer == null)
{
throw new Exception($"Customer is null. {customerId}");
}
return customer;
}
private async Task<Subscription> VerifyCorrectTaxRateForCharge(Invoice invoice, Subscription subscription) private async Task<Subscription> VerifyCorrectTaxRateForCharge(Invoice invoice, Subscription subscription)
{ {
if (!string.IsNullOrWhiteSpace(invoice?.CustomerAddress?.Country) && !string.IsNullOrWhiteSpace(invoice?.CustomerAddress?.PostalCode)) if (!string.IsNullOrWhiteSpace(invoice?.CustomerAddress?.Country) && !string.IsNullOrWhiteSpace(invoice?.CustomerAddress?.PostalCode))