Copied to clipboard

Flag this post as spam?

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


  • Bernard 16 posts 36 karma points
    Aug 01, 2012 @ 09:51
    Bernard
    0

    Finalizing issues

     

    Hi again,

    I've got a couple of odd issues, with finalizing orders.

    1) Recently I've been getting an "Object reference not set to an instance of an object." when manually calling Finalize. See the code below:

     

     

    var orderid = int.Parse(Request["OrderId"]);
    var order = TeaCommerce.Data.Order.GetOrder(orderid);
    var card = eWAYRequest.CardNumber.Remove(0, eWAYRequest.CardNumber.Length - 4).PadLeft(eWAYRequest.CardNumber.Length - 4, 'X');
    order.AddProperty(new OrderProperty("TransactionNumber", eWayResponse.TransactionNumber));
    order.AddProperty(new OrderProperty("AuthorisationCode", eWayResponse.AuthorisationCode));
    var callback = new TeaCommerce.Data.Payment.CallbackInfo(orderReference, Math.Round(eWayResponse.Amount / 100M, 2),eWayResponse.TransactionNumber, TeaCommerce.Data.Payment.PaymentStatus.Captured, "Credit Card (eWay)", card);
    order.Finalize(callback);

     

    Note: The order object is correctly being populated with the order.

    2) WebshopEvents_AfterOrderFinalized isn't being called when manually calling Finalize, however it does get called when Finalize occurs with Paypal.

    Any ideas?

     

     

     

     

     

     

     

     

  • Bernard 16 posts 36 karma points
    Aug 01, 2012 @ 09:59
    Bernard
    0

    In addition to the 1st issue, after the exception occurs it seems to destroy the TeaCommerce object. Giving the following exception every time an order is called up.

    Nullable object must have a value.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.InvalidOperationException: Nullable object must have a value.

    Source Error: 

    [InvalidOperationException: Nullable object must have a value.]
       System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) +52
       System.Nullable`1.get_Value() +1980417
       TeaCommerce.SessionController.get_CurrentOrder() +447
       usercontrols_cart_CartInfo.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\ledcentral-website\usercontrols\LEDCentral\cart\CartContents.ascx.cs:17
       System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
       System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
       System.Web.UI.Control.OnLoad(EventArgs e) +91
       BaseMacro.OnLoad(EventArgs e) in c:\inetpub\wwwroot\ledcentral-website\App_Code\BaseMacro.cs:15
       System.Web.UI.Control.LoadRecursive() +74
       System.Web.UI.Control.LoadRecursive() +146
       System.Web.UI.Control.LoadRecursive() +146
       System.Web.UI.Control.LoadRecursive() +146
       System.Web.UI.Control.LoadRecursive() +146
       System.Web.UI.Control.LoadRecursive() +146
       System.Web.UI.Control.LoadRecursive() +146
       System.Web.UI.Control.LoadRecursive() +146
       System.Web.UI.Control.LoadRecursive() +146
       System.Web.UI.Control.LoadRecursive() +146
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
  • Anders Burla 2560 posts 8256 karma points
    Aug 01, 2012 @ 10:35
    Anders Burla
    0

    Hi Bernard

    First of all the the AfterOrderFinalized event is triggeret by the /base code and not the business logic - so you need to fire that event your self - just do WebshopEvents.SendAfterOrderFinalized( order, callbackInfo );

    The problem with finalize - you should try and see if any of your strings is null that you pass to the constructor of CallbackInfo. Or check what else is null. Here is the code that runs when an order is finalized

          //Only finalize a cart
          if ( !this.IsOrder && callbackInfo.IsValid ) {

            lock ( this ) {
              if ( callbackInfo.OrderName != null )
                this.TransactionOrderName = callbackInfo.OrderName;
              this.TransactionPaymentAmount = callbackInfo.Amount;
              this.PaymentStatus = callbackInfo.PaymentStatus;
              if ( callbackInfo.TransactionId != null )
                this.TransactionPaymentTransactionId = callbackInfo.TransactionId;
              if ( callbackInfo.CardType != null )
                this.TransactionPaymentCardType = callbackInfo.CardType;
              if ( callbackInfo.CardNumber != null )
                this.TransactionPaymentCardNumber = callbackInfo.CardNumber;

              //From the callback we may get a different price because of extra Fee's on the payment provider. Here we add the to the original fee
              this.TransactionPaymentFeeWithoutVAT += ( callbackInfo.Amount - this.TotalPrice ) * ( 1M / ( 1M + this.TransactionPaymentVAT ) );

              foreach ( OrderLine orderLine in this.OrderLines ) {
                //Stock management
                if ( TeaCommerceSettings.IsOptimisticStockManagement ) {
                  NodeStock.ChangeStock( orderLine.NodeId, orderLine.Quantity );
                }
              }

              this.IsOrder = true;
              Save();
            }

            long? emailTemplateId = TeaCommerceSettings.DefaultConfirmationEmailId.ParseToLong();

            if ( emailTemplateId != null )
              EmailTemplate.GetEmailTemplate( emailTemplateId.Value ).Send( this, EmailTemplate.EmailTemplateType.Confirmation );
            else
              Log.Add( LogTypes.Error, -1, "Tea Commerce - Error sending confirmation email for order " + this.Id + ": No default confirmation email template selected" );

    Kind regards
    Anders

  • Bernard 16 posts 36 karma points
    Aug 01, 2012 @ 10:46
    Bernard
    0

    Anders, I cannot find WebshopEvents.SendAfterOrderFinalized (couldn't even find it in the object browser) can you confirm this is the right event? Also assuming we call it from the class which inherits ITeaCommerceExtension.

    I'll get back to you about the NULL issue.

  • Bernard 16 posts 36 karma points
    Aug 01, 2012 @ 10:51
    Bernard
    0

    Anders, nothing in the callback info object apart from Errors is NULL. See the serialization below:

    {TeaCommerce.Data.Payment.CallbackInfo}

        Amount: 35.12

        CardNumber: "XXXXXXXX1111"

        CardType: "Credit Card (eWay)"

        ErrorMessage: null

        IsValid: true

        OrderName: "TeaCommerce Purchase 170"

        PaymentStatus: Captured

        TransactionId: "9858025"

  • Bernard 16 posts 36 karma points
    Aug 01, 2012 @ 10:54
    Bernard
    0

    What sets the Transaction... records in the order?

     TransactionCurrencyCultureName: "en-AU"

        TransactionCurrencyISOCode: "AUD"

        TransactionOrderName: null

        TransactionPaymentAmount: null

        TransactionPaymentCardNumber: null

        TransactionPaymentCardType: null

        TransactionPaymentFee: 0

        TransactionPaymentFeeWithoutVAT: 0

        TransactionPaymentName: "eWay"

        TransactionPaymentTransactionId: null

        TransactionPaymentVAT: 0.1

        TransactionShippingFee: 9.12

        TransactionShippingFeeWithoutVAT: 8.290909090909090909090909091

        TransactionShippingName: "AusPost eParcel"

        TransactionShippingVAT: 0.1

        TransactionVAT: 0.1

  • Anders Burla 2560 posts 8256 karma points
    Aug 01, 2012 @ 10:56
    Anders Burla
    1

    Ahh sorry - you call the AfterOrderFinalized event. Its a static event in TeaCommerce.Data.Extensibility.WebshopEvents

    From the code I posted - could you see if anything else would be null - in the finalize method call?

  • Anders Burla 2560 posts 8256 karma points
    Aug 01, 2012 @ 10:57
    Anders Burla
    0

    Some of the transaction data is set when you call goToPayment - the missing ones - orderName, PaymentAmount, CardNumber etc is in the Finalize event - so when it fails - it won't set the correct info in the DB.

  • Bernard 16 posts 36 karma points
    Aug 01, 2012 @ 11:16
    Bernard
    0

    Ok, the issue was not having an Email Confirmation template. But I can't see how it would error when you're clearing checking to see if the template is set.

    long? emailTemplateId = TeaCommerceSettings.DefaultConfirmationEmailId.ParseToLong();

            if ( emailTemplateId != null )

    ...

    This could be a migration issue, with the database having a set value to an xslt that doesn't exist on the test server.

    Both issues are now closed. Thanks for the great support.

     

  • Anders Burla 2560 posts 8256 karma points
    Aug 01, 2012 @ 15:05
    Anders Burla
    0

    Ahh great you solved it! It should be able to handle not having a email template - but if the xslt the template should use is missing - I think that creates the error :)

    Kind regards
    Anders

  • Bernard 16 posts 36 karma points
    Aug 02, 2012 @ 04:17
    Bernard
    0

    Actually, it's been semi-resolved.

    I'm still getting a NULL exception after finalizing the order. This happens when my mini cart tries to refresh the cart. Specifically the TeaCommerce.SessionController.CurrentOrder object.

    I was under the impression if there is no order, Tea Commerce would create 1.

    Any ideas?

    [InvalidOperationException: Nullable object must have a value.]
       System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) +52
       TeaCommerce.SessionController.get_CurrentOrder() +255
       usercontrols_cart_CartInfo.Page_Load(Object sender, EventArgs e) in c:\inetpub\vhosts\ledcentral.com.au\wwwroot\usercontrols\LEDCentral\cart\CartContents.ascx.cs:17
       System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
       System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
       System.Web.UI.Control.OnLoad(EventArgs e) +91
       BaseMacro.OnLoad(EventArgs e) in c:\inetpub\vhosts\ledcentral.com.au\wwwroot\App_Code\BaseMacro.cs:15
       System.Web.UI.Control.LoadRecursive() +74
       System.Web.UI.Control.LoadRecursive() +146
       System.Web.UI.Control.LoadRecursive() +146
       System.Web.UI.Control.LoadRecursive() +146
       System.Web.UI.Control.LoadRecursive() +146
       System.Web.UI.Control.LoadRecursive() +146
       System.Web.UI.Control.LoadRecursive() +146
       System.Web.UI.Control.LoadRecursive() +146
       System.Web.UI.Control.LoadRecursive() +146
       System.Web.UI.Control.LoadRecursive() +146
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
  • Anders Burla 2560 posts 8256 karma points
    Aug 02, 2012 @ 10:03
    Anders Burla
    0

    If the CurrentOrderId is null this is the code that is running - it creates a new order. Do you have a default order status and can you see if anything of the order stuff might be the reason?

    Order order = new Order( SessionController.CurrentCurrency.Id, SessionController.CurrentCountry.Id, OrderStatus.GetDefaultOrderStatus().Id );
    order.Save();

    SessionController.CurrentOrderId = order.Id;

    Kind regards
    Anders

Please Sign in or register to post replies

Write your reply to:

Draft