diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c991a48..2f7ec11 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -52,8 +52,8 @@ jobs: script: | TAG=${{ secrets.DOCKERHUB_USERNAME }}/groundsforsupport.stevanfreeborn.com:${{ needs.build.outputs.version }} - docker stop groundsforsupport.stevanfreeborn.com - docker rm groundsforsupport.stevanfreeborn.com + docker stop groundsforsupport.stevanfreeborn.com || true + docker rm groundsforsupport.stevanfreeborn.com || true docker pull $TAG docker run \ diff --git a/src/GroundsForSupport.Server/Migrations/20251230125831_AddPaymentsModel.cs b/src/GroundsForSupport.Server/Migrations/20251230125831_AddPaymentsModel.cs index 92aae8d..7517e46 100644 --- a/src/GroundsForSupport.Server/Migrations/20251230125831_AddPaymentsModel.cs +++ b/src/GroundsForSupport.Server/Migrations/20251230125831_AddPaymentsModel.cs @@ -4,29 +4,29 @@ namespace GroundsForSupport.Server.Migrations { + /// + public partial class AddPaymentsModel : Migration + { /// - public partial class AddPaymentsModel : Migration + protected override void Up(MigrationBuilder migrationBuilder) { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Payments", - columns: table => new - { - Id = table.Column(type: "TEXT", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Payments", x => x.Id); - }); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Payments"); - } + migrationBuilder.CreateTable( + name: "Payments", + columns: table => new + { + Id = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Payments", x => x.Id); + }); } -} + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Payments"); + } + } +} \ No newline at end of file diff --git a/src/GroundsForSupport.Server/Migrations/20251231131814_AddAmountToPaymentModel.cs b/src/GroundsForSupport.Server/Migrations/20251231131814_AddAmountToPaymentModel.cs index 1cb7a51..7e2c095 100644 --- a/src/GroundsForSupport.Server/Migrations/20251231131814_AddAmountToPaymentModel.cs +++ b/src/GroundsForSupport.Server/Migrations/20251231131814_AddAmountToPaymentModel.cs @@ -4,26 +4,26 @@ namespace GroundsForSupport.Server.Migrations { + /// + public partial class AddAmountToPaymentModel : Migration + { /// - public partial class AddAmountToPaymentModel : Migration + protected override void Up(MigrationBuilder migrationBuilder) { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "Amount", - table: "Payments", - type: "INTEGER", - nullable: false, - defaultValue: 0L); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "Amount", - table: "Payments"); - } + migrationBuilder.AddColumn( + name: "Amount", + table: "Payments", + type: "INTEGER", + nullable: false, + defaultValue: 0L); } -} + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Amount", + table: "Payments"); + } + } +} \ No newline at end of file diff --git a/src/GroundsForSupport.Server/Migrations/20260102131600_AddNameMessagePropertiesToPaymentModel.cs b/src/GroundsForSupport.Server/Migrations/20260102131600_AddNameMessagePropertiesToPaymentModel.cs index b1ac7d1..dff6afb 100644 --- a/src/GroundsForSupport.Server/Migrations/20260102131600_AddNameMessagePropertiesToPaymentModel.cs +++ b/src/GroundsForSupport.Server/Migrations/20260102131600_AddNameMessagePropertiesToPaymentModel.cs @@ -4,36 +4,36 @@ namespace GroundsForSupport.Server.Migrations { + /// + public partial class AddNameMessagePropertiesToPaymentModel : Migration + { /// - public partial class AddNameMessagePropertiesToPaymentModel : Migration + protected override void Up(MigrationBuilder migrationBuilder) { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "Message", - table: "Payments", - type: "TEXT", - nullable: true); + migrationBuilder.AddColumn( + name: "Message", + table: "Payments", + type: "TEXT", + nullable: true); - migrationBuilder.AddColumn( - name: "Name", - table: "Payments", - type: "TEXT", - nullable: false, - defaultValue: ""); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "Message", - table: "Payments"); - - migrationBuilder.DropColumn( - name: "Name", - table: "Payments"); - } + migrationBuilder.AddColumn( + name: "Name", + table: "Payments", + type: "TEXT", + nullable: false, + defaultValue: ""); } -} + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Message", + table: "Payments"); + + migrationBuilder.DropColumn( + name: "Name", + table: "Payments"); + } + } +} \ No newline at end of file diff --git a/src/GroundsForSupport.Server/Migrations/20260102140326_AddCreatedAtTimeStampToPaymentsModel.cs b/src/GroundsForSupport.Server/Migrations/20260102140326_AddCreatedAtTimeStampToPaymentsModel.cs index d693557..122ab23 100644 --- a/src/GroundsForSupport.Server/Migrations/20260102140326_AddCreatedAtTimeStampToPaymentsModel.cs +++ b/src/GroundsForSupport.Server/Migrations/20260102140326_AddCreatedAtTimeStampToPaymentsModel.cs @@ -4,26 +4,26 @@ namespace GroundsForSupport.Server.Migrations { + /// + public partial class AddCreatedAtTimeStampToPaymentsModel : Migration + { /// - public partial class AddCreatedAtTimeStampToPaymentsModel : Migration + protected override void Up(MigrationBuilder migrationBuilder) { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "CreatedAtUnix", - table: "Payments", - type: "INTEGER", - nullable: false, - defaultValue: 0L); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "CreatedAtUnix", - table: "Payments"); - } + migrationBuilder.AddColumn( + name: "CreatedAtUnix", + table: "Payments", + type: "INTEGER", + nullable: false, + defaultValue: 0L); } -} + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "CreatedAtUnix", + table: "Payments"); + } + } +} \ No newline at end of file diff --git a/src/GroundsForSupport.Server/Payments/Endpoints/EventsEndpoint.cs b/src/GroundsForSupport.Server/Payments/Endpoints/EventsEndpoint.cs index 7c463be..05feb28 100644 --- a/src/GroundsForSupport.Server/Payments/Endpoints/EventsEndpoint.cs +++ b/src/GroundsForSupport.Server/Payments/Endpoints/EventsEndpoint.cs @@ -29,9 +29,8 @@ internal static class EventsEndpoint try { - var stripeEvent = EventUtility.ParseEvent(json); var signatureHeader = httpContext.Request.Headers[StripeSignatureHeader]; - stripeEvent = EventUtility.ConstructEvent(json, signatureHeader, options.Value.EventsWebhookSecret); + var stripeEvent = EventUtility.ConstructEvent(json, signatureHeader, options.Value.EventsWebhookSecret); if (stripeEvent.Type is not EventTypes.PaymentIntentSucceeded) { @@ -39,8 +38,14 @@ internal static class EventsEndpoint } var paymentIntent = (PaymentIntent)stripeEvent.Data.Object; - var name = paymentIntent.Metadata[nameof(Payment.Name)]; - var message = paymentIntent.Metadata[nameof(Payment.Message)]; + + var name = paymentIntent.Metadata.TryGetValue(nameof(Payment.Name), out var metaName) + ? metaName + : "unknown"; + + var message = paymentIntent.Metadata.TryGetValue(nameof(Payment.Message), out var metaMessage) + ? metaMessage + : string.Empty; var payment = new Payment() { diff --git a/src/GroundsForSupport.Server/Payments/Stripe/StripeService.cs b/src/GroundsForSupport.Server/Payments/Stripe/StripeService.cs index d0a401a..a3662be 100644 --- a/src/GroundsForSupport.Server/Payments/Stripe/StripeService.cs +++ b/src/GroundsForSupport.Server/Payments/Stripe/StripeService.cs @@ -8,10 +8,12 @@ namespace GroundsForSupport.Server.Payments.Stripe; internal sealed class StripeService( IOptions options, - HttpClient httpClient + HttpClient httpClient, + ILogger logger ) : IStripeService { private readonly StripeClient _client = new(options.Value.ApiKey, httpClient: new SystemNetHttpClient(httpClient)); + private readonly ILogger _logger = logger; public async Task<(bool IsSuccess, Intent Intent)> CreatePaymentIntentAsync(string name, decimal amount, string? message, string? email) { @@ -43,7 +45,7 @@ internal sealed class StripeService( } catch (Exception) { - // TODO: Log exception + _logger.LogError("Failed to create Stripe payment intent for {Name} with amount {Amount}", name, amount); return (false, new Intent(string.Empty)); } } diff --git a/src/GroundsForSupport.Server/RateLimiting/FixedRateLimitPolicy.cs b/src/GroundsForSupport.Server/RateLimiting/FixedRateLimitPolicy.cs index b0e9004..dd3e51b 100644 --- a/src/GroundsForSupport.Server/RateLimiting/FixedRateLimitPolicy.cs +++ b/src/GroundsForSupport.Server/RateLimiting/FixedRateLimitPolicy.cs @@ -11,7 +11,7 @@ internal static class FixedRateLimitPolicy partitionKey: context.Connection.RemoteIpAddress?.ToString() ?? "unknown", factory: static partition => new FixedWindowRateLimiterOptions { - PermitLimit = 10, + PermitLimit = 100, Window = TimeSpan.FromHours(1), QueueProcessingOrder = QueueProcessingOrder.OldestFirst, QueueLimit = 0 diff --git a/tests/GroundsForSupport.Server.Tests/Integration/Infra/TestApi.cs b/tests/GroundsForSupport.Server.Tests/Integration/Infra/TestApi.cs index 913d514..5040b23 100644 --- a/tests/GroundsForSupport.Server.Tests/Integration/Infra/TestApi.cs +++ b/tests/GroundsForSupport.Server.Tests/Integration/Infra/TestApi.cs @@ -4,4 +4,4 @@ namespace GroundsForSupport.API.Tests.Integration.Infra; public sealed class TestApi : WebApplicationFactory { -} +} \ No newline at end of file