Clearing out the payment path

This commit is contained in:
2025-04-17 00:18:17 -04:00
parent 910c5572a1
commit 9d2a00a928
4 changed files with 37 additions and 43 deletions

View File

@@ -31,21 +31,7 @@ public static class DependencyInjection
return services; 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, public static IServiceCollection AddAuthorizationAndAuthentication(this IServiceCollection services,
ConfigurationManager configuration) ConfigurationManager configuration)
{ {

View File

@@ -44,7 +44,8 @@ public class SendTipRequestValidator : Validator<SendTipRequest>
[PublicAPI] [PublicAPI]
public class SendTipHandler( public class SendTipHandler(
MembershipDbContext dbContext, MembershipDbContext dbContext,
StripeService stripeService) StripeService stripeService,
ILogger<SendTipHandler> logger)
: Endpoint<SendTipRequest, SendTipResponse> : Endpoint<SendTipRequest, SendTipResponse>
{ {
public override void Configure() public override void Configure()
@@ -59,29 +60,36 @@ public class SendTipHandler(
SendTipRequest req, SendTipRequest req,
CancellationToken ct) CancellationToken ct)
{ {
var creator = await dbContext.Creators.FindAsync( try
[req.CreatorId],
cancellationToken: ct);
if (creator == null)
{ {
await SendNotFoundAsync(ct); var creator = await dbContext.Creators.FindAsync(
return; [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);
} }
} }

View File

@@ -17,8 +17,11 @@ var builder = WebApplication.CreateBuilder(args);
if (!builder.Environment.IsDevelopment()) if (!builder.Environment.IsDevelopment())
{ {
var keyVaultEndpoint = new Uri(Environment.GetEnvironmentVariable("VaultUri") ?? ""); var vaultUri = Environment.GetEnvironmentVariable("VaultUri");
builder.Configuration.AddAzureKeyVault(keyVaultEndpoint, new DefaultAzureCredential());
if (vaultUri is null) throw new InvalidOperationException("Missing VaultUri configuration setting");
builder.Configuration.AddAzureKeyVault(new Uri(vaultUri), new DefaultAzureCredential());
} }
builder.Services.AddCors(options => builder.Services.AddCors(options =>
@@ -34,7 +37,6 @@ builder.Services.AddCors(options =>
}); });
// Add services to the container. // Add services to the container.
builder.Services.AddKeyVaultIfConfigured(builder.Configuration);
builder.Services.AddWebServices(); builder.Services.AddWebServices();
builder.Services.AddAuthorizationAndAuthentication(builder.Configuration); builder.Services.AddAuthorizationAndAuthentication(builder.Configuration);

View File

@@ -3,8 +3,6 @@
"PostgresConnection": "Server=hutopypostgress.postgres.database.azure.com,5432;Database=hutopy;User Id=hutopy;Password=General2024!;Ssl Mode=Require;" "PostgresConnection": "Server=hutopypostgress.postgres.database.azure.com,5432;Database=hutopy;User Id=hutopy;Password=General2024!;Ssl Mode=Require;"
}, },
"Stripe": { "Stripe": {
"SecretKey": "",
"WebhookSecret": "",
"HutopyRate": 0.05 "HutopyRate": 0.05
} }
} }