feat(payments): enhance payment model migrations and update event handling
This commit is contained in:
@@ -4,29 +4,29 @@
|
||||
|
||||
namespace GroundsForSupport.Server.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddPaymentsModel : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddPaymentsModel : Migration
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Payments",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "TEXT", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Payments", x => x.Id);
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Payments");
|
||||
}
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Payments",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "TEXT", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Payments", x => x.Id);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Payments");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,26 +4,26 @@
|
||||
|
||||
namespace GroundsForSupport.Server.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddAmountToPaymentModel : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddAmountToPaymentModel : Migration
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<long>(
|
||||
name: "Amount",
|
||||
table: "Payments",
|
||||
type: "INTEGER",
|
||||
nullable: false,
|
||||
defaultValue: 0L);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Amount",
|
||||
table: "Payments");
|
||||
}
|
||||
migrationBuilder.AddColumn<long>(
|
||||
name: "Amount",
|
||||
table: "Payments",
|
||||
type: "INTEGER",
|
||||
nullable: false,
|
||||
defaultValue: 0L);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Amount",
|
||||
table: "Payments");
|
||||
}
|
||||
}
|
||||
}
|
||||
+29
-29
@@ -4,36 +4,36 @@
|
||||
|
||||
namespace GroundsForSupport.Server.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddNameMessagePropertiesToPaymentModel : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddNameMessagePropertiesToPaymentModel : Migration
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "Message",
|
||||
table: "Payments",
|
||||
type: "TEXT",
|
||||
nullable: true);
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "Message",
|
||||
table: "Payments",
|
||||
type: "TEXT",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "Name",
|
||||
table: "Payments",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
defaultValue: "");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Message",
|
||||
table: "Payments");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Name",
|
||||
table: "Payments");
|
||||
}
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "Name",
|
||||
table: "Payments",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
defaultValue: "");
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Message",
|
||||
table: "Payments");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Name",
|
||||
table: "Payments");
|
||||
}
|
||||
}
|
||||
}
|
||||
+20
-20
@@ -4,26 +4,26 @@
|
||||
|
||||
namespace GroundsForSupport.Server.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddCreatedAtTimeStampToPaymentsModel : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddCreatedAtTimeStampToPaymentsModel : Migration
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<long>(
|
||||
name: "CreatedAtUnix",
|
||||
table: "Payments",
|
||||
type: "INTEGER",
|
||||
nullable: false,
|
||||
defaultValue: 0L);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "CreatedAtUnix",
|
||||
table: "Payments");
|
||||
}
|
||||
migrationBuilder.AddColumn<long>(
|
||||
name: "CreatedAtUnix",
|
||||
table: "Payments",
|
||||
type: "INTEGER",
|
||||
nullable: false,
|
||||
defaultValue: 0L);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "CreatedAtUnix",
|
||||
table: "Payments");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -8,10 +8,12 @@ namespace GroundsForSupport.Server.Payments.Stripe;
|
||||
|
||||
internal sealed class StripeService(
|
||||
IOptions<StripeOptions> options,
|
||||
HttpClient httpClient
|
||||
HttpClient httpClient,
|
||||
ILogger<StripeService> logger
|
||||
) : IStripeService
|
||||
{
|
||||
private readonly StripeClient _client = new(options.Value.ApiKey, httpClient: new SystemNetHttpClient(httpClient));
|
||||
private readonly ILogger<StripeService> _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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user