Skip to content

Commit

Permalink
Fix Stripe checkout for real now.
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahelsaig committed Nov 6, 2023
1 parent fa59a8e commit 637f427
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static string GetFormattedPaymentType(this PaymentMethod paymentMethod) =

public static IPayment CreatePayment(this PaymentIntent paymentIntent, Amount amount) =>
new Commerce.Models.Payment(
Kind: paymentIntent.PaymentMethod.GetFormattedPaymentType(),
Kind: paymentIntent.PaymentMethod?.GetFormattedPaymentType() ?? "Unset",
ChargeText: paymentIntent.Description,
TransactionId: paymentIntent.Id,
Amount: amount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,7 @@ public Task<IActionResult> UpdateAndRedirectToFinishedOrderAsync(
CreateChargesProvider(paymentIntent));

private static Func<OrderPart, IEnumerable<IPayment>> CreateChargesProvider(PaymentIntent paymentIntent) =>
orderPart =>
{
// Same here as on the checkout page: Later we have to figure out what to do if there are multiple
// totals i.e., multiple currencies. https://github.com/OrchardCMS/OrchardCore.Commerce/issues/132
var amount = orderPart.Charges.Single().Amount;

return new[] { paymentIntent.CreatePayment(amount) };
};
orderPart => orderPart.Charges.Select(charge => paymentIntent.CreatePayment(charge.Amount));

public async Task UpdateOrderToPaymentFailedAsync(PaymentIntent paymentIntent)
{
Expand Down Expand Up @@ -147,11 +140,8 @@ public async Task<ContentItem> CreateOrUpdateOrderFromShoppingCartAsync(IUpdateM
{
order.Alter<OrderPart>(orderPart =>
{
if (paymentIntent.PaymentMethod != null)
{
orderPart.Charges.Clear();
orderPart.Charges.Add(paymentIntent.CreatePayment(total));
}
orderPart.Charges.Clear();
orderPart.Charges.Add(paymentIntent.CreatePayment(total));

if (cartViewModel is null) return;

Expand Down

0 comments on commit 637f427

Please sign in to comment.