Developer forum

Forum » Development » My CheckoutDoneOrderIsComplete notification is not called after returning from gateway provider

My CheckoutDoneOrderIsComplete notification is not called after returning from gateway provider

Martin Slot
Reply
Hello.

I have this notification for at CartV2
   [Subscribe(Dynamicweb.Ecom7.Cart.Notifications.CheckoutDoneOrderIsComplete)]
    public class EcomOrderStateChangedObserver : Dynamicweb.Extensibility.NotificationSubscriber
    {
        public override void OnNotify(string notification, object[] args)
        {
            try
            {
                System.IO.File.WriteAllText(@"E:\path\to\file.txt", "order completed");
            }
            catch(Exception e) {
                System.IO.File.WriteAllText(@"E:\path\to\file.txt", "order completed" + e.Message + e.StackTrace);
            }
        }
    }
As I understand it, this is called when the customer returns from the gateway provider. But this is not called. I do not get anything written in my folder. Why is this? As I understand, the notification is called right after the user returns, and before any emails is sent.

Keep in mind that I have written a custom checkout handler to a 3 party payment service. Maybe it is this that is causing the trouble? My redirect method looks like this:

        public override string Redirect(Dynamicweb.eCommerce.Orders.Order order)
        {
            string result = null;

            string orderStatus = HttpContext.Current.Request.QueryString["order"];
            if (orderStatus == "complete")
            {
                order.TransactionStatus = "completed";
                base.SetOrderComplete(order);
                base.CheckoutDone(order);
                order.Save();
                LogEvent(order, "complete");

                base.RedirectToCart(order);
            }
            else
            {
                LogError(order, "transaktionen fejlede");
                order.TransactionStatus = "failed";
                order.Save();
                base.CheckoutDone(order);

                result = PrintErrorTemplate(order);
            }

            return result;
        }

I do not call any, or init, any observer collections or so, as I think that it is DWs job. But maybe I am forgetting something? I have tried the same with OrderIsPassedToCheckoutHandler and the same code, and this is not called either.


Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
This post has been marked as an answer

Hi Martin

The reason your subscriber isn't invoked is because you use the "old" OnNotify overload and all CartV2 notifications use the new way. You need to use the overload with NotificationArgs as your second parameter. In you code you then cast this object to a strongly-typed CheckoutDoneOrderIsCompleteArgs object which you can then use.

So something like this
 

[Subscribe(Dynamicweb.Ecom7.Cart.Notifications.CheckoutDoneOrderIsComplete)]
public class EcomOrderStateChangedObserver : Dynamicweb.Extensibility.NotificationSubscriber
{
     public override void OnNotify(string notification, Dynamicweb.Extensibility.NotificationArgs args)
     {
		var myArgs = (Dynamicweb.Ecom7.Cart.Notifications.CheckoutDoneOrderIsCompleteArgs) args;
		var order = myArgs.Order;
	 }
 }
Hope this helps :)

- Jeppe
Votes for this answer: 0

 

You must be logged in to post in the forum