Developer forum

Forum » Development » Change the amount sent to DIBS

Change the amount sent to DIBS

Magni J. Hansen
Reply
Can i change the amount sent to DIBS gateway ?

Replies

 
Nicolai Høeg Pedersen
Reply
Only by changing the order total before checkout step.

The amount is part of a checksum sent to DIBS, and if you change amount, checksum will not match and payment will fail.

 
Magni J. Hansen
Reply

Is the eCommerce.Order.Steps.Confimed the way to change the amount or is there one BeforeSentToGateway method ?
We use Cart v2 on this posta.fo solution.

 
Nicolai Høeg Pedersen
Reply
Ecom7.Cart.Notifications.OrderIsPassedToCheckoutHandler in cartv2
 
Magni J. Hansen
Reply

Is there an equivalent method for order object like the one on orderline SetUnitPrice() ? 

 
Nicolai Høeg Pedersen
Reply
No...

You can set AllowOverridePrices on the order to true stopping the order object from calculating... But you cannot overwrite the .Price priceinfo instance, so that does not help you alot.

So adding an orderline is the only way...

 
Magni J. Hansen
Reply

This is my code so far, but it is not working correctly:

public override void OnNotify(string notification, Dynamicweb.Extensibility.NotificationArgs args)
{
    Dynamicweb.Ecom7.Cart.Notifications.OrderIsPassedToCheckoutHandlerArgs handler =
(Dynamicweb.Ecom7.Cart.Notifications.OrderIsPassedToCheckoutHandlerArgs)args;

    Order o = handler.Order;
    string cc = Base.ChkString(o.CustomerCountryCode).ToLower().Trim();
    LogEvent(o, "Country code for order is: " + cc + " in shop: " + o.ShopID);
    if ((cc == "dk" || cc == "fr") && o.ShopID == "SHOP5")
    {
        if (o.PriceBeforeFees.Price < 80)
        {
            foreach (OrderLine ol in o.OrderLines)
            {
                ol.SetUnitPrice(ol.Price.PriceWithoutVAT);
                ol.Save();
                LogEvent(o, "Update product price for " + ol.ProductName + " to " + ol.Price.Price + " (" + ol.Price.PriceWithoutVAT + ")");
            }
            o.UpdateVAT(0.0);
            o.Save();
        }
    }
    handler.Order = o;
    handler.Order.Save();
    LogEvent(o, "Order price is updated to " + o.Price.Price);
    base.OnNotify(notification, handler);
}

private void LogEvent(Order order, string message)
{
    string str2 = string.Format("Order {0}: {1}", order.ID, message);
    LogToFile.Log(str2, "/eCom/CartV2/Events", LogToFile.LogType.ManyEntriesPerFile);
    if (order != null)
    {
        order.DebuggingInfos.Add(new Order.DebuggingInfo(str2));
        order.SaveDebuggingInfos();
    }
}
 

 
Nicolai Høeg Pedersen
Reply
What is not working?

You should not do like this:
base.OnNotify(notification, handler);

Think that will trigger the notification to be executed again.

 
Magni J. Hansen
Reply

The order vat is not set to zero when order price without fees is under 80 kr.
In my code i have tried (loop of products) to set all product prices to without vat prices. This should be removed if i get Update(0.0) to work.

 
Magni J. Hansen
Reply
Here a better overview of what im trying:

Dynamicweb.Ecom7.Cart.Notifications.OrderIsPassedToCheckoutHandlerArgs handler =
                (Dynamicweb.Ecom7.Cart.Notifications.OrderIsPassedToCheckoutHandlerArgs)args;

            string cc = Base.ChkString(handler.Order.CustomerCountryCode).ToLower().Trim();

            LogEvent(handler.Order, "Country code for order is: " + cc + " in shop: " + handler.Order.ShopID);
            if ((cc == "dk" || cc == "fr") && handler.Order.ShopID == "SHOP5")
            {
                if (handler.Order.PriceBeforeFees.Price < 80)
                {
                    handler.Order.UpdateVAT(0.0);
                    handler.Order.Save();
                }
            }

            handler.Order.Save();


 
Magni J. Hansen
Reply

I have tried to execute sql query (order and orderline objects) for doing the updates, but this does not override the order price, they must be recalculated at a latter stage.

 
Magni J. Hansen
Reply

If i read the order log lines there is a line where it updates the price after the OrderIsPassedToCheckoutHandler is called. This is the line:
Order ORDER2194: Order price is updated to 58,6

My order price should be 57,0. How can i change this price to 57,0 ??

 
Magni J. Hansen
Reply
It should be possible to set some kind of flag for no further price updates at the checkout handler stage.
 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
This post has been marked as an answer
Hi Magni

You can use AllowOverridePrices to completely control the PriceInfo on the order. Do some like this:

// Assume o is your Order object
if (o.PriceBeforeFees.Price < 80.0)
{
    // Set VAT for the Order
    o.AllowOverridePrices = true;
    o.Price.VAT = 0.0;
    
    // Set VAT for all OrderLines
    foreach (Orderline ol in o.Orderlines)
    {
        ol.AllowOverridePrices = true;
        ol.Price.VAT = 0.0;
    }

    // Save Order
    o.Save();
}

The properties AllowOverridePrices were added in 19.2.2.4.

Hope this helps :)

- Jeppe
Votes for this answer: 0
 
Magni J. Hansen
Reply

AllowOverridePrices setting was the flag i was looking for, thx. The last price update is not called while AllowOverridePrices is set to true.

What is now the best practice to override Order.Price.Price ? sql queries ?
This property is readonly.

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
The PriceInfo object on the order contains prices both with and without VAT. PriceInfo.Price returns the price with VAT. In order to change that value, you simply need to do something like this:

// Assume o is your Order object
o.AllowOverridePrices = true;
o.Price.PriceWithVAT = o.Price.PriceWithoutVAT;
o.VAT = 0.0;
o.Save();

Now your o.Price.Price will return the correct price without VAT.

- Jeppe
 
Magni J. Hansen
Reply

Just changing the Order object values in the OrderIsPassedToCheckoutHandler is not enough. The Order object is only modified until the next Order is called or recalculated. I needed to set this code into my OrderTemplateExtender as well. 
Now it works. 

Thanks for inputs. I would like it to be more simple to manage such a simple requirement.

 

You must be logged in to post in the forum