Copied to clipboard

Flag this post as spam?

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


  • Tomasz Kowalski 135 posts 445 karma points
    Jul 17, 2020 @ 19:53
    Tomasz Kowalski
    0

    Default payment method is not working

    Hi, It's me. Again. ;)

    I need to make a custom checkout. Very simple, because I have all customer data, one payment method and one shipping method. Easy... I thought that Vendr, just like TC, helps with setting payment and shipping methods from default settings. There is everything set up: default country, default payment method and default shipping method.

    But it does not work. Payment method is null.

    Yes, I can set it up by my selv in code behind (I'm struggling with it now), but I shouldn't have to.

    I checked it out on the demo shop - and this doesn't work here either.

    Currency settings:

    currency settings

    Vendr shop settings:

    shop settings

    And I would expect that Invoicing will be selected as default, but it isn't:

    enter image description here

    Is it a bug, or am I missing something?

    Vendr 1.2.6

    Regards

    Tomasz

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jul 20, 2020 @ 08:59
    Matt Brailsford
    0

    Hey Thomasz

    Hmm, I think there could be something we could do better here for sure.

    In Tea Commerce it did auto set the payment method on the order, but I personally don't think that is the right solution (at least not when there are multiple payment methods available) as setting the payment method on the order could affect it's total calculation which if you set this prior to being on the payment methods selection screen could mean the order summary gives a missleading total if the customer chooses a different payment method with a different price.

    I think we could try giving a better indication of whether a currency is the default for the billing country though as we could say when rendering out the payment method options "Is there a payment method selected, and if not, default to the selection to the default payment method". Maybe this could be as simple as us creating a new extension method for IsDefaultPaymentMethodForCountry(Guid countryId) then the code for rendering the checkbox checked status could become

    @Html.Raw((Model.Order.PaymentInfo.PaymentMethodId.HasValue && Model.Order.PaymentInfo.PaymentMethodId.Value == item.PaymentMethod.Id) || (!Model.Order.PaymentInfo.PaymentMethodId.HasValue && item.IsDefaultPaymentMethodForCountry(Model.Order.PaymentInfo.CountryId))) ? "checked=\"checked\"" : "")
    

    There could be something to be said for auto setting it if there is only one payment method option though, or possibly having a config option somewhere to tell Vendr to automatically do this, but I don't think it should be a default behavior like it was in TC.

    Matt

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jul 20, 2020 @ 09:05
    Matt Brailsford
    0

    PS In the mean time, you could do something like the following to achieve the same

    var billingCountry = VendrApi.Instance.GetCountry(Model.Order.PaymentInfo.CountryId.Value);
    var paymentMethods = VendrApi.Instance.GetPaymentMethods(Model.Order.StoreId);
    
    foreach(var pm in paymentMethods) {
        <input type="radio" name="paymentMethod" value="@(pm.Id)"  
            @Html.Raw((Model.Order.PaymentInfo.PaymentMethodId.HasValue && Model.Order.PaymentInfo.PaymentMethodId.Value == pm.Id) || (!Model.Order.PaymentInfo.PaymentMethodId.HasValue && pm.Id == billingCountry.DefaultPaymentMethodId.Value)) ? "checked=\"checked\"" : "") />
    }
    
  • Tomasz Kowalski 135 posts 445 karma points
    Jul 20, 2020 @ 09:29
    Tomasz Kowalski
    0

    Hey Matt, I disagree a little bit :) I think, when something is marked as "default", this would be set to all new orders as the initial value. Both shiping and payment.

    It is possible in TC to not set this values as default - then nothing is set up in all orders as well:

    enter image description here

    I can see that it isn't in Vendr. But this make no sens, if I can set something as "default" but it will not be used.

    We were using this feature many times in our TC projects. Some customers would like to have payment/shipping method checked "as default" and others would force their customers to do a choice.

    Now I'm struggling with setting payment and shipping method from code behind. I'm adding products to the cart via web API. It works fine. But I have just one-step-checkout: only "Review page". This can't be rendered, because Payment/Shipping are null. I don't know if there is a "place" when I can set shipping/payment method when the new orders gets created?

    I've just tried to set them in my WebApi, same place when I add product to the cart, but it gets cleared when I open "Review page".

    Regards Tomasz

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jul 20, 2020 @ 09:38
    Matt Brailsford
    0

    Hey Thomasz,

    That's a fair point. But I do think there are 2 potential ways to think here. Default could mean "set the order to this currency by default" which is what TC does, or it could mean "don't set the order to it by default, but when we present the options for selection, have this one selected by default". Which I have been leaning towards the latter, but I do see your point.

    RE your implementation, this does sound like you have this setup correctly as you absolutely can set them at the same time as your other updates. Per chance are you building your solution on top of the demo store code? As if you are, the demo store has a bunch of event handlers to clear the shipping / payment method during checkout https://github.com/vendrhub/vendr-demo-store/blob/main/src/Vendr.DemoStore/Events/ResetPaymentAndShippingMethods.cs which are all registered here https://github.com/vendrhub/vendr-demo-store/blob/main/src/Vendr.DemoStore/Composing/DemoStoreComposer.cs#L21-L37 so you may want to disable those if you are.

    /Matt

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jul 20, 2020 @ 09:43
    Matt Brailsford
    0

    In fact, if you are using the demo store code, and these event handlers are in place, I think this may actually be the reason for the payment method not being set as now I think about it, we do have the code that sets the payment method to the default.

  • Tomasz Kowalski 135 posts 445 karma points
    Jul 20, 2020 @ 09:59
    Tomasz Kowalski
    0

    I've seen this code, but I didn't use it in my project. So that's not it.

    I am debugging it now and have some interesting behaviour. I'm going to create a new support case, as it's not about "default" payment/shipping.

    /Tomasz

  • Tomasz Kowalski 135 posts 445 karma points
    Jul 22, 2020 @ 05:54
    Tomasz Kowalski
    0

    A little follow up.

    As it turned out, that all my problems (well, almost all) were caused by event hanldlers in Vendr.Checkout, after uninstalling this package I can see, that paymet method is in fact set up automaticalyy to the default payment method (shipping method isn't). So it's good for now.

    But I still would like to have the possibility to control over setting the default payment/shipping method as it is in TC.

    I understand the problem with totals that could include shipping/payment fees before customer has chosen them. Our solution was to show totals without payment/shipping fees in the ferst steps of checkout.

    Anyway, my problem with default payment method is solved (for now).

    Regards

    Tomasz

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jul 22, 2020 @ 06:17
    Matt Brailsford
    100

    Hi Thomasz

    Thanks for the follow up.

    I’ll definitely take a look at why the shipping method isn’t working the same way as payment method “default” behaviour as these should work the same. Once this is resolved then that should mean it all works as per TC so I think that would be your problem solved.

    Glad you were able to find a solution for your project though 👍🏻

    Matt

Please Sign in or register to post replies

Write your reply to:

Draft