diff --git a/backend/src/Web/DependencyInjection.cs b/backend/src/Web/DependencyInjection.cs index 1bbb520..5038cee 100644 --- a/backend/src/Web/DependencyInjection.cs +++ b/backend/src/Web/DependencyInjection.cs @@ -31,21 +31,7 @@ public static class DependencyInjection return services; } - - public static IServiceCollection AddKeyVaultIfConfigured(this IServiceCollection services, - ConfigurationManager configuration) - { - var keyVaultUri = configuration["KeyVaultUri"]; - if (!string.IsNullOrWhiteSpace(keyVaultUri)) - { - configuration.AddAzureKeyVault( - new Uri(keyVaultUri), - new DefaultAzureCredential()); - } - - return services; - } - + public static IServiceCollection AddAuthorizationAndAuthentication(this IServiceCollection services, ConfigurationManager configuration) { diff --git a/backend/src/Web/Features/Memberships/Handlers/SendTip.cs b/backend/src/Web/Features/Memberships/Handlers/SendTip.cs index f58ee81..7311311 100644 --- a/backend/src/Web/Features/Memberships/Handlers/SendTip.cs +++ b/backend/src/Web/Features/Memberships/Handlers/SendTip.cs @@ -44,7 +44,8 @@ public class SendTipRequestValidator : Validator [PublicAPI] public class SendTipHandler( MembershipDbContext dbContext, - StripeService stripeService) + StripeService stripeService, + ILogger logger) : Endpoint { public override void Configure() @@ -59,29 +60,36 @@ public class SendTipHandler( SendTipRequest req, CancellationToken ct) { - var creator = await dbContext.Creators.FindAsync( - [req.CreatorId], - cancellationToken: ct); - - if (creator == null) + try { - await SendNotFoundAsync(ct); - return; + var creator = await dbContext.Creators.FindAsync( + [req.CreatorId], + cancellationToken: ct); + + if (creator == null) + { + await SendNotFoundAsync(ct); + return; + } + + var checkoutSession = await stripeService.CreateTipCheckoutSessionAsync( + creator.Id, + creator.Name, + req.Amount, + req.Currency, + req.Message, + creator.StripeAccountId!, + req.CheckoutSuccessUrl, + req.CheckoutCancelledUrl, + ct); + + await SendAsync( + new SendTipResponse("Pending", checkoutSession.Url), + cancellation: ct); + } + catch (Exception e) + { + logger.LogError(e.Message); } - - var checkoutSession = await stripeService.CreateTipCheckoutSessionAsync( - creator.Id, - creator.Name, - req.Amount, - req.Currency, - req.Message, - creator.StripeAccountId!, - req.CheckoutSuccessUrl, - req.CheckoutCancelledUrl, - ct); - - await SendAsync( - new SendTipResponse("Pending", checkoutSession.Url), - cancellation: ct); } } diff --git a/backend/src/Web/Program.cs b/backend/src/Web/Program.cs index 75e1141..563f11d 100644 --- a/backend/src/Web/Program.cs +++ b/backend/src/Web/Program.cs @@ -17,8 +17,11 @@ var builder = WebApplication.CreateBuilder(args); if (!builder.Environment.IsDevelopment()) { - var keyVaultEndpoint = new Uri(Environment.GetEnvironmentVariable("VaultUri") ?? ""); - builder.Configuration.AddAzureKeyVault(keyVaultEndpoint, new DefaultAzureCredential()); + var vaultUri = Environment.GetEnvironmentVariable("VaultUri"); + + if (vaultUri is null) throw new InvalidOperationException("Missing VaultUri configuration setting"); + + builder.Configuration.AddAzureKeyVault(new Uri(vaultUri), new DefaultAzureCredential()); } builder.Services.AddCors(options => @@ -34,7 +37,6 @@ builder.Services.AddCors(options => }); // Add services to the container. -builder.Services.AddKeyVaultIfConfigured(builder.Configuration); builder.Services.AddWebServices(); builder.Services.AddAuthorizationAndAuthentication(builder.Configuration); diff --git a/backend/src/Web/appsettings.Production.json b/backend/src/Web/appsettings.Production.json index 416a981..92f848f 100644 --- a/backend/src/Web/appsettings.Production.json +++ b/backend/src/Web/appsettings.Production.json @@ -3,8 +3,6 @@ "PostgresConnection": "Server=hutopypostgress.postgres.database.azure.com,5432;Database=hutopy;User Id=hutopy;Password=General2024!;Ssl Mode=Require;" }, "Stripe": { - "SecretKey": "", - "WebhookSecret": "", "HutopyRate": 0.05 } } \ No newline at end of file