Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mike Masey 39 posts 253 karma points MVP 5x c-trib
    Jun 27, 2023 @ 10:38
    Mike Masey
    0

    PaymentMethod.CalculatePrice() always returns 0 in Vendr Checkout

    Hello,

    I'm currently experiencing an odd issues when using Vendr Checkout alongside the Stripe Payment provider. Here some info on the versions of things being used

    • Umbraco - 8.17.2
    • Vendr - 2.1.0
    • Vendr.PaymentProviders.Stripe - 2.1.1
    • Vendr.Checkout - 2.1.0

    In the VendrCheckoutPaymentMethodPage.cshtml there is the following code (this is an unchanged copy from the package) from line 44

     if (currentOrder.TransactionAmount.Value > 0 || zeroValuePaymentMethod == null)
    {
        <ul class="border border-gray-300 rounded">
            @foreach (var item in paymentMethods.Where(x => zeroValuePaymentMethod == null || x.Alias != zeroValuePaymentMethod.Alias)
               .Select((pm, i) => new { PaymentMethod = pm, Index = i }))
            {
                <li class="border-gray-300 @(item.Index > 0 ? "border-t " : "")">
                    <label class="flex items-center py-4 px-4 cursor-pointer hover:bg-gray-50">
                        <input name="paymentMethod" type="radio" value="@item.PaymentMethod.Id" class="mr-3" @Html.Raw(currentPaymentMethodId.HasValue && currentPaymentMethodId.Value == item.PaymentMethod.Id ? "checked=\"checked\"" : "") required />
                        <span class="font-medium">@(item.PaymentMethod.Name)</span>
    
                       @* The following always returns 0 *@
                        <span class="flex-1 text-right">@(item.PaymentMethod.CalculatePrice()?.Formatted())</span>
                    </label>
                </li>
            }
        </ul>
    }
    

    I'm expecting the item.PaymentMethod.CalculatePrice() to return the total order value, but it always returns 0. I've had a look through the Vendr Checkout source code, and the Stripe source code, and can't find any reference to then CalculatePrice() method, and i couldn't find it in the docs for the main Vendr package either.

    I've been able to pop a breakpoint into the compiled code and have found something at Vendr.Extensions.PaymentMethodExtensions, and when trying to debug I can see that the currentOrder value (OrderReadOnly) is being populated, but I can't quite work out where it's going wrong.

    Has anyone else experienced this issue? I feel I could probably just change it to use the currentOrder.TotalPrice value, but as this is code directly from the package, i'm assuming it is like it is for a reason.

    Thanks in advance.

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Jun 27, 2023 @ 13:13
    Nik
    101

    Hey Mike,

    My first thought is that I wouldn't expect item.PaymentMethod.CalculatePrice() to return the total order price, but instead the price for that item, as item is a payment method.

    The price it is trying to show would be the price of using said payment provider (in the CMS you can set a price to charge uplifts for the provider).

    So showing 0 seems correct to me.

    Thanks

    Nik

  • Mike Masey 39 posts 253 karma points MVP 5x c-trib
    Jun 27, 2023 @ 14:34
    Mike Masey
    0

    Thanks Nik,

    That's exactly it! 100% a case of me not understanding it completely. I got blinkered by some other legacy code that had been added by someone else which used the values from that payment method for some analytics stuff, but based on this, it appears it was done incorrectly in the first place.

    Cheers, Mike

Please Sign in or register to post replies

Write your reply to:

Draft