mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 16:12:49 -05:00
[PM-212] Sync Organization Billing Email from Stripe Webhook (#3305)
* Add StripeFacade and StripeEventService * Add StripeEventServiceTests * Handle customer.updated event in StripeController
This commit is contained in:
22
test/Billing.Test/Utilities/EmbeddedResourceReader.cs
Normal file
22
test/Billing.Test/Utilities/EmbeddedResourceReader.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System.Reflection;
|
||||
|
||||
namespace Bit.Billing.Test.Utilities;
|
||||
|
||||
public static class EmbeddedResourceReader
|
||||
{
|
||||
public static async Task<string> ReadAsync(string resourceType, string fileName)
|
||||
{
|
||||
var assembly = Assembly.GetExecutingAssembly();
|
||||
|
||||
await using var stream = assembly.GetManifestResourceStream($"Bit.Billing.Test.Resources.{resourceType}.{fileName}");
|
||||
|
||||
if (stream == null)
|
||||
{
|
||||
throw new Exception($"Failed to retrieve manifest resource stream for file: {fileName}.");
|
||||
}
|
||||
|
||||
using var reader = new StreamReader(stream);
|
||||
|
||||
return await reader.ReadToEndAsync();
|
||||
}
|
||||
}
|
33
test/Billing.Test/Utilities/StripeTestEvents.cs
Normal file
33
test/Billing.Test/Utilities/StripeTestEvents.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using Stripe;
|
||||
|
||||
namespace Bit.Billing.Test.Utilities;
|
||||
|
||||
public enum StripeEventType
|
||||
{
|
||||
ChargeSucceeded,
|
||||
CustomerSubscriptionUpdated,
|
||||
CustomerUpdated,
|
||||
InvoiceCreated,
|
||||
InvoiceUpcoming,
|
||||
PaymentMethodAttached
|
||||
}
|
||||
|
||||
public static class StripeTestEvents
|
||||
{
|
||||
public static async Task<Event> GetAsync(StripeEventType eventType)
|
||||
{
|
||||
var fileName = eventType switch
|
||||
{
|
||||
StripeEventType.ChargeSucceeded => "charge.succeeded.json",
|
||||
StripeEventType.CustomerSubscriptionUpdated => "customer.subscription.updated.json",
|
||||
StripeEventType.CustomerUpdated => "customer.updated.json",
|
||||
StripeEventType.InvoiceCreated => "invoice.created.json",
|
||||
StripeEventType.InvoiceUpcoming => "invoice.upcoming.json",
|
||||
StripeEventType.PaymentMethodAttached => "payment_method.attached.json"
|
||||
};
|
||||
|
||||
var resource = await EmbeddedResourceReader.ReadAsync("Events", fileName);
|
||||
|
||||
return EventUtility.ParseEvent(resource);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user