Copied to clipboard

Flag this post as spam?

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


  • Chris Soto 13 posts 33 karma points
    Feb 27, 2012 @ 13:22
    Chris Soto
    0

    Custom Payment Provider w/ Local FormPostUrl

    Hi All,

    Similar to this incident I am trying to create a payment provider that posts to a local form.  The local form contains a .Net user control that parses the FormPost data, calls Authorize.Net Customer Information Manager (CIM)  CreateCustomerProfileTransaction, and for testing purposes displays the incoming values and CIM call results.

    I seem to be getting the following error in the javascript, now:

    1. Uncaught TypeError: Cannot read property 'form' of null
      1. TeaCommerce.goToPayment
      2. (anonymous function)commerce.js:27
      3. f.event.handlejquery.min.js:3
      4. f.event.add.i.handle.kjquery.min.js:2

    I suspect the problem is in the payment provider. I've set the FormPostUrl to the correct page, and used the following for my GenerateForm:

            public override Dictionary<string, string> GenerateForm(Data.Order order, string teaCommerceContinueUrl, string teaCommerceCancelUrl, string teaCommerceCallBackUrl, Dictionary<string, string> settings)
    {
    List<string> settingsToExclude = new string[] { "API_LOGIN_ID", "TRANSACTION_KEY", "testing" }.ToList();
    Dictionary<string, string> inputFields = settings.Where(i => !settingsToExclude.Contains(i.Key)).ToDictionary(i => i.Key, i => i.Value);

    isTesting = settings["testing"].ParseToBool(false);

    if (isTesting) inputFields["x_test_request"] = "TRUE";

    //CIM Fields
    inputFields["profileid"] = order.GetPropertyValue("profileid");
    inputFields["payprofileid"] = order.GetPropertyValue("paymentprofileid");

    //Transaction Fields
    string amount = order.TotalPrice.ToString("0.00", CultureInfo.InvariantCulture);
    inputFields["amount"] = amount;
    inputFields["tax"] = order.PaymentVAT.ToString("0.00", CultureInfo.InvariantCulture);
    inputFields["edate"] = order.GetPropertyValue("eventDate");
    inputFields["street"] = order.GetPropertyValue("streetAddress") + "\n" + order.GetPropertyValue("streetAddress2");
    inputFields["citystatezip"] = order.GetPropertyValue("city") + ", " + order.GetPropertyValue("state") + " " + order.GetPropertyValue("zip");
    inputFields["orderid"] = order.Name;

    //Workflow Fields
    inputFields["approveUrl"] = teaCommerceContinueUrl;
    inputFields["declineUrl"] = teaCommerceCancelUrl;

    return inputFields;
    }

    Anyone have any ideas, or an idea on tracking down the cause?

    Thanks,

    -Chris

  • Anders Burla 2560 posts 8256 karma points
    Feb 27, 2012 @ 14:18
    Anders Burla
    0

    Hi Chris

    Try and change the Tea Commerce script to the non minified and use the debugger in FireBug to see where the form is wrong. Have a normal starter kit to check against. Maybe you forgot to have a form around the properties the goToPayment generates?

    Kind regards
    Anders

  • Chris Soto 13 posts 33 karma points
    Feb 27, 2012 @ 15:22
    Chris Soto
    0

    Hi Anders,

    Thanks for the quick response. 

    The error is at line 720:

    var rtnData = tcs.callBase('GeneratePaymentForm', parameters, formData, false, null, null);
    var form = jQuery(rtnData.form);
    Uncaught TypeError: Cannot read property 'form' of null

    It appears that I am missing something in the GenerateForm, or I haven't implemented something else that is required, causing tcs.callBase to return null. Stepping into the callBase function, (~line 810) the createBaseUrl returns a url, then it keeps coming back to 808, before it eventually bombs out back at 720.

    Since I can't trace the service call, is there a likely missing object that defines the form, other than the content of GenerateForm?

    -Chris

     

  • Anders Burla 2560 posts 8256 karma points
    Feb 27, 2012 @ 16:02
    Anders Burla
    0

    Hi Chris

    This looks like a server error is happening. Try and have a breakpoint in the error event around line 825. This should give you the description. Or have a look at your server log and see what error your .NET code has logged for you.

    Kind regards
    Anders

  • Chris Soto 13 posts 33 karma points
    Feb 28, 2012 @ 14:21
    Chris Soto
    0

    Hi Anders,

    At this point, it doesn't look like a server error.  The IIS & .Net logs don't display any errors. I have stepped through it several times, but I seem to be missing where the magic happens. I attached the debug process to the IIS and stepped through the payment provider, there were no errors and values were as expected.

    On a whim, I switched to the Authorize.Net payment provider I used earlier to access secure.authorize.net in test mode.  It works fine, generates the form data and directs to the appropriate page. From here, I stepped through the GenerateForm & FormPostUrl without error; but when it returned to the javascript rtnData is a form object, where the CIM payment provider resulted in null.

    From what I can tell, they are both generating the form data in GenerateForm, then grabbing the FormPostUrl; is there another piece that is generating the form object?

    Thanks for any help you can provide

    -Chris

  • Anders Burla 2560 posts 8256 karma points
    Feb 29, 2012 @ 17:27
    Anders Burla
    0

    Hi Chris

    Have you hooked into any of the Tea Commerce events that could maybe cause an error? Try and disable the hooks if you have any.

    The form is generated in the Base method - GeneratePaymentForm - it calls the correct payment provider for the key/values to send to the form post url that the payment provider specifies. This is some of the code that generates the form - so you could try and have a look. Maybe you didnt send a value in the submitInput (the parameter for GeneratePaymentForm? This would cause it to wrap the form into some javascript. But if you just switch the payment provider its pretty weird that it doesnt work. Try and just return no values for your payment provider and have the formpost url say - http://test.com and see if you get a form object.

    //Genereate form
            Dictionary<stringstring> inputFields = paymentProviderInstance.GenerateForm( order, teaCommerceContinueUrl, teaCommerceCancelUrl, teaCommerceCallbackUrl, settings );
    
            StringBuilder sbForm = new StringBuilder();
            string rtnStr;
            sbForm.AppendFormat( @"<form action=""{0}"" method=""post""{1}>", paymentProviderInstance.FormPostUrl, !string.IsNullOrEmpty( paymentProviderInstance.FormAttributes ) ? " " + paymentProviderInstance.FormAttributes : string.Empty );
            foreach ( var kvp in inputFields ) {
              sbForm.AppendFormat( @"<input type=""hidden"" id=""{0}"" name=""{0}"" value=""{1}"" />", kvp.Key, kvp.Value );
            }
            sbForm.Append( submitInput );
            sbForm.Append( @"</form>" );
    
            if ( string.IsNullOrEmpty( submitInput ) ) {
              //If no button is provided we assume we are returning to a javascript
              //All qoutes must be escaped for the javascript
              sbForm = sbForm.Replace( "\"""\\\"" );
              //The Form html is wrapped in a javascript object
              rtnStr = string.Format( @"{{""submitJavascriptFunction"": ""{0}"",""form"":""{1}""}}", paymentProviderInstance.SubmitJavascriptFunction, sbForm.ToString() );
            } else {
              rtnStr = sbForm.ToString();
            }
  • Chris Soto 13 posts 33 karma points
    Mar 01, 2012 @ 16:26
    Chris Soto
    0

    Hi Anders,

    I found the problem, although I am not sure I understand it. I went back to basics and commented every line in the GenerateForm function except creating and returning inputFields. This worked.

    So I uncommented the definitions one by one and found that the culprit was:

    inputFields["tax"] = order.TotalVAT.ToString("0.00", CultureInfo.InvariantCulture);

    I replaced it with:

    string tax = order.TotalVAT.ToString("0.00", CultureInfo.InvariantCulture);
    inputFields["tax"] = tax;

    and now it works. Like I said, I found it, but I'm not sure I understand it.

    Thanks again for all your help.

    -Chris

  • Anders Burla 2560 posts 8256 karma points
    Mar 01, 2012 @ 16:28
    Anders Burla
    0

    Hi Chris

    WHAT! That doesnt make any sense - but, hey, if it works :)

    Kind regards
    Anders

Please Sign in or register to post replies

Write your reply to:

Draft