Developer forum

Forum » Development » ProcessOrder in custom shipping provider not working

ProcessOrder in custom shipping provider not working

Unnsteinn Garðarsson
Unnsteinn Garðarsson
Reply

Hello! I am debugging a strange issue that is caused by the fact that the order.shippingProviderValues dictionary is not initialized correctly in my shipping provider in some cases on our production environment.

 

- I cannot reproduce this bug on my dev/staging environments and I have verified that the DLLs are the same as on Production.

- All environments are using DW 9.10.11

- I have verified that all environments do have the Shipping provider applied for the shipping methods, and the values set.

- And after looking into the database I notice that the OrderShippingProviderData column is NULL in these cases but I cannot find any link between the data.

 

I lost my Forti Client credentials so I cannot look at the DW source code but I am suspecting an error causing the ProcessOrder function not being called.

I know this is a long shot and not an easy bug, but worth a shot. Anything that you guys can think of that might be causing this? 


Replies

 
Nicolai Pedersen
Reply

This is the code in our base class in ProcessOrder:

var fields = GetFieldValues();
            foreach (var item in fields)
                order.ShippingProviderValues[item.Key] = item.Value;

And the GetFieldValues:

protected Dictionary<string, string> GetFieldValues()
        {
            var request = Context.Current.Request;
            var fields = new Dictionary<string, string>();
            var collection = request.QueryString;
            foreach (string key in collection.AllKeys)
            {
                if (key.StartsWith(FieldPrefix))
                {
                    fields.Add(key.Substring(FieldPrefix.Length), collection[key]);
                }
            }

            collection = request.Form;
            foreach (string key in collection.AllKeys)
            {
                if (key.StartsWith(FieldPrefix))
                {
                    fields.Add(key.Substring(FieldPrefix.Length), collection[key]);
                }
            }

            return fields;
        }

My guess is that your code sometimes run in context that is not a httpcontext. I.e. callback, live integration or similar. And that will cause some bad behavior.

Could that be it?

 
Unnsteinn Garðarsson
Unnsteinn Garðarsson
Reply

Sorry for not being clear, but I have my custom provider with an override of the ProcessOrder where I just add all the values for the provider in the dictionary, which works for the majority of the time but fails for some cases. 

- It could be some browser related issue and I am adding logging to try and detect that

- I have also verified that the ProcessOrder is called when navigating from Cart Step0 to Cart Step1, and there is no redirect there and the HttpContext should be the same

        public override void ProcessOrder(Order order)
        {   
            order.ShippingProviderValues[Constants.Shipping.ShippingProviderKeys.DW_SHIPPING_METHOD_ID] = DWShippingMethodID;
            order.ShippingProviderValues[Constants.Shipping.ShippingProviderKeys.ERP_SHIPPING_METHOD_ID] = NavTenderTypeID;
            order.ShippingProviderValues[Constants.Shipping.ShippingProviderKeys.DELIVERY_PICKUP_DESCRIPTION] = DeliveryPickupDescription;
            order.ShippingProviderValues[Constants.Shipping.ShippingProviderKeys.ORDER_TEMPLATE_TAG_TO_APPEND] = OrderTemplateTagToAppend;
        }

 

 
Unnsteinn Garðarsson
Unnsteinn Garðarsson
Reply

Hello Nicolai, some followup and new information.

I noticed that for these cases the OrderCheckoutPageID field does not contain the cart app page. And observing the logs I notice that it appears that the user is navigating to these pages after the cart page 0, but is then redirected back to the cart, and I know that because of this line in the logs. Order RedirectToCheckoutHandler callback

Now when I try to reproduce this I see the logs are very similar from when I navigate from cart page 0 to some other page, but I am not redirected back to the cart, and I have to go there manually and when I do so everything is fine. The OrderCheckoutPageID is the cart page ID and the data is not missing.

 

I have set up some logging in the ProcessOrder to see if I can get some more information about this but I am thinking if there could be a case where DW is redirecting the user to the cart page without being a redirect from an external payment provider ?

 

Regards.

 
Nicolai Pedersen
Reply

I think I know what that can be. It is the callback as I was suspecting. 6 days ago we actually made an update of the checkouthandler callback that handles exactly that property (OrderCheckoutPageID). You need one of the latest ecommerce packages:

https://www.nuget.org/packages/Dynamicweb.Ecommerce/

 
Unnsteinn Garðarsson
Unnsteinn Garðarsson
Reply

Ok so you made an update to fix this issue ?

Also we are not using nuget packages but rather downloading the whole application zip, is this fix in DW 9.10.12?

 
Nicolai Pedersen
Reply

The new ecommerce package has that fix. But if it fixes this particular problem I cannot be 100% sure of. But they seem to be related.

 
Unnsteinn Garðarsson
Unnsteinn Garðarsson
Reply

Ok and to clarify, I can download DW 9.10.12 and this includes the fix? Since we are not using nuget packages.

 
Nicolai Pedersen
Reply

Yes. And maybe after 9.10.12, download the nuget package, rename it to .zip instead of .nupack and open it, and then get the dll from inside the zip file. Nuget packages are just zip files with another name.

 
Unnsteinn Garðarsson
Unnsteinn Garðarsson
Reply

Thanks for the quick assistance, I will try this and inform you of the results. Have a nice day!

 
Anders Ebdrup
Anders Ebdrup
Reply

Dear Unnsteinn,

 

We see the same issue on some of our solutions. Did you find the root cause here?

Often the information are missing on orders paid with "MobilePay".

 

Best regards, Anders

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Anders

Callback not received? And do any of these websites use Cloudflare and WAF?

 
Anders Ebdrup
Anders Ebdrup
Reply

Nope, I can see callbacks from then all, but common for orders missing data in: shippingProviderValues is that all have an issue with: "Dynamicweb.Ecommerce.Common.Context The Context.GetCart() is not a cart and cannot be updated."

Please see OrderDebuggingInfos here:

fr, 25 nov 2022 07:04:46    Dynamicweb.Ecommerce.CheckoutHandlers.QuickPayPaymentWindow.QuickPayPaymentWindow Callback completed successfully (OrderID:ORDER1553 (IsCart:False, Complete:True) Total:398,95, orderline total:369,95 kr.; Orderlines:2 - Products:1, Discounts:1, Taxes:0, BOM:0, (IP:193.162.142.211, Url:/Default.aspx?ID=7407&CheckoutHandlerOrderID=ORDER1553&QuickPayState=Callback&redirect=false), Thread:176, HashCode:265176.)    
fr, 25 nov 2022 07:04:48    Dynamicweb.Ecommerce.Common.Context The Context.GetCart() is not a cart and cannot be updated. Order.AutoId = 4938, SessionCartKey = EcomCart) (OrderID:ORDER1553 (IsCart:False, Complete:True) Total:398,95, orderline total:369,95 kr.; Orderlines:2 - Products:1, Discounts:1, Taxes:0, BOM:0, (IP:87.49.147.94, Url:/Default.aspx?ID=7407&CheckoutHandlerOrderID=ORDER1553&QuickPayState=Ok), Thread:46, HashCode:265176.)

 

fr, 25 nov 2022 06:48:45    Dynamicweb.Ecommerce.CheckoutHandlers.QuickPayPaymentWindow.QuickPayPaymentWindow Callback completed successfully (OrderID:ORDER1552 (IsCart:False, Complete:True) Total:499,95, orderline total:499,95 kr.; Orderlines:2 - Products:1, Discounts:1, Taxes:0, BOM:0, (IP:193.162.142.211, Url:/Default.aspx?ID=7407&CheckoutHandlerOrderID=ORDER1552&QuickPayState=Callback&redirect=false), Thread:247, HashCode:31846792.)    
fr, 25 nov 2022 06:48:48    Dynamicweb.Ecommerce.Common.Context The Context.GetCart() is not a cart and cannot be updated. Order.AutoId = 4933, SessionCartKey = EcomCart) (OrderID:ORDER1552 (IsCart:False, Complete:True) Total:499,95, orderline total:499,95 kr.; Orderlines:2 - Products:1, Discounts:1, Taxes:0, BOM:0, (IP:217.71.0.193, Url:/Default.aspx?ID=7407&CheckoutHandlerOrderID=ORDER1552&QuickPayState=Ok), Thread:244, HashCode:31846792.)

 


fr, 25 nov 2022 05:13:21    Dynamicweb.Ecommerce.Common.Context The Context.GetCart() is not a cart and cannot be updated. Order.AutoId = 4915, SessionCartKey = EcomCart) (OrderID:ORDER1548 (IsCart:False, Complete:True) Total:499,95, orderline total:499,95 kr.; Orderlines:2 - Products:1, Discounts:1, Taxes:0, BOM:0, (IP:91.100.242.27, Url:/Default.aspx?ID=7407&CheckoutHandlerOrderID=ORDER1548&QuickPayState=Ok), Thread:163, HashCode:65913860.)    
fr, 25 nov 2022 05:13:21    Order RedirectToCheckoutHandler callback - CheckoutHandlerOrderId: 'ORDER1548'/order.Id: ORDER1548 (IsCart:False, UserID/name/secondaryid:0//0, Complete:True), (IP:91.100.242.27, Url:/Default.aspx?ID=7407&CheckoutHandlerOrderID=ORDER1548&QuickPayState=Ok), Thread:163, HashCode:65913860)

 
Anders Ebdrup
Anders Ebdrup
Reply

A thought here, can it be caused if the callback takes some time due to e.g. integration to an ERP system, and the user hits the receipt page before the callback is executed?

 

Best regards, Anders

 

You must be logged in to post in the forum