Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public ExactlyPaymentProvider(
_urlHelperFactory = urlHelperFactory;
}

public async Task<object> CreatePaymentProviderDataAsync(IPaymentViewModel model, bool isPaymentRequest = false)
public async Task<object> CreatePaymentProviderDataAsync(IPaymentViewModel model, bool isPaymentRequest = false, string shoppingCartId = null)
{
var settings = (await _siteService.GetSiteSettingsAsync())?.As<ExactlySettings>();
return string.IsNullOrEmpty(settings?.ApiKey) || string.IsNullOrEmpty(settings.ProjectId) ? null : new object();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ public StripePaymentProvider(
_stripePaymentIntentService = stripePaymentIntentService;
}

public async Task<object> CreatePaymentProviderDataAsync(IPaymentViewModel model, bool isPaymentRequest = false)
public async Task<object> CreatePaymentProviderDataAsync(IPaymentViewModel model, bool isPaymentRequest = false, string shoppingCartId = null)
{
PaymentIntent paymentIntent;

try
{
paymentIntent = await _stripePaymentIntentService.CreatePaymentIntentAsync(model.SingleCurrencyTotal);
paymentIntent = await _stripePaymentIntentService.CreatePaymentIntentAsync(model.SingleCurrencyTotal, shoppingCartId);
}
catch (StripeException exception) when (exception.Message.StartsWithOrdinal("No API key provided."))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public async Task<string> CreateClientSecretAsync(Amount total, ShoppingCartView
var defaultTotal = totals.SingleOrDefault();

var initPaymentIntent = string.IsNullOrEmpty(paymentIntentId)
? await _stripePaymentIntentService.CreatePaymentIntentAsync(defaultTotal)
? await _stripePaymentIntentService.CreatePaymentIntentAsync(defaultTotal, cart.Id)
: await _stripePaymentIntentService.GetOrUpdatePaymentIntentAsync(paymentIntentId, defaultTotal);

return initPaymentIntent.ClientSecret;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public interface IPaymentProvider
/// Arbitrary data which will be set as the value in <see cref="IPaymentViewModel.PaymentProviderData"/>. If it
/// returns <see langword="null"/> then the shape won't be displayed.
/// </returns>
Task<object?> CreatePaymentProviderDataAsync(IPaymentViewModel model, bool isPaymentRequest = false);
Task<object?> CreatePaymentProviderDataAsync(IPaymentViewModel model, bool isPaymentRequest = false, string? shoppingCartId = null);

/// <summary>
/// Validates the data POSTed to the <see cref="PaymentController.Validate"/> action.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,13 @@ [FromServices] IPaymentService paymentService

public static IEndpointRouteBuilder AddPaymentRequestEndpoint(this IEndpointRouteBuilder builder)
{
builder.MapGetWithDefaultSettings("api/checkout/payment-request/{orderId}", PaymentRequestAsync);
builder.MapGetWithDefaultSettings("api/checkout/payment-request/{orderId}/{shoppingCartId?}", PaymentRequestAsync);
return builder;
}

private static async Task<IResult> PaymentRequestAsync(
[FromRoute] string orderId,
[FromRoute] string? shoppingCartId,
[FromServices] IContentManager contentManager,
[FromServices] IAuthorizationService authorizationService,
[FromServices] IEnumerable<IPaymentProvider> paymentProviders,
Expand Down Expand Up @@ -124,7 +125,7 @@ private static async Task<IResult> PaymentRequestAsync(
}

var viewModel = new PaymentViewModel(orderPart, singleCurrencyTotal, singleCurrencyTotal);
await viewModel.WithProviderDataAsync(paymentProviders, isPaymentRequest: true);
await viewModel.WithProviderDataAsync(paymentProviders, isPaymentRequest: true, shoppingCartId: shoppingCartId);

return TypedResults.Ok(viewModel);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public DummyPaymentProvider(
H = htmlLocalizer;
}

public Task<object?> CreatePaymentProviderDataAsync(IPaymentViewModel model, bool isPaymentRequest = false) =>
public Task<object?> CreatePaymentProviderDataAsync(IPaymentViewModel model, bool isPaymentRequest = false, string? shoppingCartId = null) =>
// This provider doesn't have any special data, and it should only be displayed during development even if the
// feature is enabled. So if the condition is met a blank object is returned, otherwise null which will cause
// the provider to be skipped when used through the viewModel.WithProviderDataAsync(providers) method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,17 @@ await _contentManager.NewAsync(Order),

if (viewModel.SingleCurrencyTotal.Value > 0)
{
await viewModel.WithProviderDataAsync(_paymentProvidersLazy.Value);
await viewModel.WithProviderDataAsync(_paymentProvidersLazy.Value, shoppingCartId: shoppingCartId);

if (!viewModel.PaymentProviderData.Any())
{
await _notifier.WarningAsync(new HtmlString(" ").Join(
H["There are no applicable payment providers for this site."],
H["Please make sure there is at least one enabled and properly configured."]));

_logger.LogWarning(
"There are no applicable payment providers for this site, " +
"Please make sure there is at least one enabled and properly configured.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ public PaymentViewModel(OrderPart orderPart, Amount singleCurrencyTotal, Amount
NetTotal = netTotal;
}

public async Task WithProviderDataAsync(IEnumerable<IPaymentProvider> paymentProviders, bool isPaymentRequest = false)
public async Task WithProviderDataAsync(
IEnumerable<IPaymentProvider> paymentProviders,
bool isPaymentRequest = false,
string? shoppingCartId = null)
{
foreach (var provider in paymentProviders)
{
if (await provider.CreatePaymentProviderDataAsync(this, isPaymentRequest) is { } data)
if (await provider.CreatePaymentProviderDataAsync(this, isPaymentRequest, shoppingCartId) is { } data)
{
PaymentProviderData[provider.Name] = data;
}
Expand Down