CPayment unexpected exceptions and workaround

The following NUnit-driven demos demonstrate that setting CPayment's CashAccountCode before setting the CreditCardNumber will lead to unexpected errors:

    [TestFixture, Explicit("demos")]   
    public class UnexpectedExceptions
    {
        [TestFixtureSetUp]
        public void TestFixtureSetUp()
        {
            iboAdmin.InitializeSystem(ConfigurationManager.ConnectionStrings["DataSource.iMIS.Connection"].ConnectionString);
        }

        [Test]
        [ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void Demo_Setting_CreditCardNumber_After_CashAccountCode_CausesUnhandledException_1()
        {
            var payment = new CPayment(CStaffUser.GetDefaultStaffUser())
            {
                CashAccountCode = cashAccountCode,
                CreditCardNumber = "4007000000027"  // VISA test number, eh?
            };
        }

        [ExpectedException(typeof(Asi.iBO.InvalidCardNumberException))]
        public void Demo_Setting_CreditCardNumber_After_CashAccountCode_CausesUnhandledException_2()
        {
            var payment = new CPayment(CStaffUser.GetDefaultStaffUser())
            {
                CashAccountCode = cashAccountCode,
                CreditCardNumber = "011201539123"   // it's irrelevant how I came up with this number.
            };
        }  
    }

This happens with Asi.iBO version 15.1.0.2782.  Setting CashAccountCode _after_ setting CreditCardNumber seems to resolve the issue.

Has anyone else encountered anything similar or contradictory, or found more info on this elsewhere?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

I'm seeing somethign similar

I'm seeing somethign similar but can't get around it  - when I set the credit card number it always gives a null expception regardless of where I set the CashAccountCode :

CPayment payment = myOrder.Payment;
payment.PaymentType = EnumPaymentType.CreditCard;
payment.CashAccountCode = "VISA";
payment.CreditCardSecurityCode = "123";
payment.CreditDebitCardHoldersName = "Test Person";
payment.CreditCardExpiration = "1212";
payment.Amount = 101;
payment.CreditCardNumber = "4111111111111111";

It wil hit that last line and crash : "Object reference not set to an instance of an object".  This is with iBO 15.1.3.6699.

 

What is the stack trace?

The stack trace may give us clues as to what iMIS is trying to do when you set the CC number.

This may not be related, but check to make sure you have your cash account and authorization account properly configured at some point:

private CReferenceData referenceThingy;

[TestFixtureSetUp]
public void TestFixtureSetUp()
{
    iboAdmin.InitializeSystem(your connect string);
    referenceThingy = iboAdmin.ReferenceData;
}

[Test]
public void Test_CanGetConfiguredCreditCardCashAccount()
{
    var code = ConfigurationManager.AppSettings["CreditCardCashAccountCode"];

    var cashAccount = referenceThingy.GetCashAccount(code);

    Assert.IsNotNull(cashAccount, code + " not found via GetCashAccount.  These are found via CashAccount property:\n" + ReportCashAccountCodes());
    Assert.AreEqual(CashAccountType.CreditCard, cashAccount.AccountType, "The configured credit card cash account for these tests is of the wrong type.");
}

[Test]
public void Test_ConfiguredCreditCardCashAccount_isAssociatedWith_AuthorizeDotNet_PaymentAuthorizationAccount()
{           
    var code = ConfigurationManager.AppSettings["CreditCardCashAccountCode"];
    var cashAccount = referenceThingy.GetCashAccount(code);

    var authAccountCode = cashAccount.AuthorizationAccountCode;

    Assert.AreEqual("appropriate auth account code", authAccountCode);
}

RE: Object reference error on credit card

Matt,

Change

 user =  Asi.iBO.ContactManagement.CContactUser.LoginByWebLogin(userID, userPW);

to

 user =  Asi.iBO.ContactManagement.CContactUser.LoginByWebLogin(userID);

Thanks,

Randy Richter

rrichter@atsol.org

More errors

when I change to the username-only overload then I get this error at that login:

The ConnectionString property has not been initialized.

but if I user the password it works fine...

 

RE: loginbyweblogin

Use the staffuser variable you create instead of the user variable.

thanks,

Randy

No User works without password

I've tried staffuser and user in LoginByWebLogin but without the password it fails on connectionstring property not initialized. 

Error Creating CPayment CreditCard

I am having similar problem. I am trying to create a Payment but when I set the CreditCardnumber for the payment I get the null reference error

 

   at Asi.Utilities.Utilities.LogPciEvent(String eventType, Int32 originationCode, Boolean result, String decryptedValue, String encryptedValue)
   at Asi.iBO.CCrypto.Encrypt(String clear)
   at Asi.iBO.Financials.CPayment.set_CreditCardNumber(String value)
   at MSTA_Online.join.imisPayment.btnSubmit_Click(Object sender, EventArgs e) in~\imisPayment.aspx.cs:line 47
   at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
   at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
   at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
   at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
   at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

here is the code

Asi.iBO.IiMISUser user;
            Asi.iBO.IiMISUser staffuser;
           
            string connectionstring = ConfigurationManager.ConnectionStrings["iMIS"].ConnectionString.ToString();
            Asi.iBO.iboAdmin.InitializeSystem(connectionstring);
            staffuser = Asi.iBO.CStaffUser.Login(staffID, staffPW);
            user =  Asi.iBO.ContactManagement.CContactUser.LoginByWebLogin(userID, userPW);

            string contactId = ((CContactUser)user).ContactId;

            // instantiate the contact by ID
            CContact contact = new CContact(user, contactId);

            //Set payment details
            CPayment payment = new CPayment(user);
            payment.PaymentType = EnumPaymentType.CreditCard;
            payment.CreditCardNumber = txtCardNumber.Text; - error here" Object reference not set to an instance of an object."

 

this is pretty nearly the same as the example code here

http://www.imiscommunity.com/dues_and_orders_code

 

im using iMIS 15.1.3

Haven't found any way to instantiate the payment and when debugging the CreditCardNumber is set.

Is there a missing step,  like a requirement to encrypt?

Since the error involves PCICompliance I imagine it has something to do with the card number.

 

have you tried 4111111111111111?

(the VISA test number)?   The CreditCardNumber setter in CPayment does a Luhn check, so maybe it's failing there.  Also, is the Credit Card Auth and Cash Account setup in Desktop correct - can you do a CC auth from desktop from, say, A/R Cash Receipts, hitting the same db?