feat(payments): integrate cancellation token in payment intent creation and update related tests
This commit is contained in:
@@ -4,7 +4,7 @@ namespace GroundsForSupport.Server.Data;
|
||||
|
||||
internal sealed record ContextOptions
|
||||
{
|
||||
public string DatabaseFilePath { get; init; } = "GroundsForSupport.db";
|
||||
public string DatabaseFilePath { get; init; } = string.Empty;
|
||||
public string GetFullyQualifiedDatabasePath()
|
||||
{
|
||||
return Path.GetFullPath(DatabaseFilePath, AppContext.BaseDirectory);
|
||||
|
||||
@@ -16,6 +16,11 @@
|
||||
<PackageReference Include="Stripe.net" Version="50.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<InternalsVisibleTo Include="$(AssemblyName).Tests" />
|
||||
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="InstallClientDeps" BeforeTargets="Build">
|
||||
<Message Text="Installing client deps..." Importance="high" />
|
||||
<Exec Command="npm install" WorkingDirectory="../GroundsForSupport.Client" />
|
||||
|
||||
@@ -16,7 +16,8 @@ internal static class CreatePaymentIntentEndpoint
|
||||
|
||||
public static async Task<IResult> CreatePaymentIntentHandler(
|
||||
Request request,
|
||||
IStripeService stripeService
|
||||
IStripeService stripeService,
|
||||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
var validationErrors = request.Validate(new ValidationContext(request));
|
||||
@@ -32,7 +33,8 @@ internal static class CreatePaymentIntentEndpoint
|
||||
request.Name,
|
||||
request.Amount,
|
||||
request.Message,
|
||||
request.Email
|
||||
request.Email,
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
if (isSuccess is false)
|
||||
|
||||
@@ -6,6 +6,7 @@ internal interface IStripeService
|
||||
string name,
|
||||
decimal amount,
|
||||
string? message,
|
||||
string? email
|
||||
string? email,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
using GroundsForSupport.Server.Data;
|
||||
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
using Stripe;
|
||||
@@ -15,7 +13,13 @@ internal sealed class StripeService(
|
||||
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)
|
||||
public async Task<(bool IsSuccess, Intent Intent)> CreatePaymentIntentAsync(
|
||||
string name,
|
||||
decimal amount,
|
||||
string? message,
|
||||
string? email,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -40,7 +44,7 @@ internal sealed class StripeService(
|
||||
createOptions.ReceiptEmail = email;
|
||||
}
|
||||
|
||||
var intent = await _client.V1.PaymentIntents.CreateAsync(createOptions);
|
||||
var intent = await _client.V1.PaymentIntents.CreateAsync(createOptions, cancellationToken: cancellationToken);
|
||||
|
||||
return (true, new Intent(intent.ClientSecret));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user