Error on ProcessPayment Method for authorize.net

Stephen Herz asked on December 20, 2016 20:04

Using Kentico v9

I am trying to create a custom single page checkout. We are trying to use the out of the box Authorize.Net payment gateway. I have everything working up to the point that I try to process the credit card. When I call the ProcessPayment() method, I get the following exception

"Object reference not set to an instance of an object."

There is another forum post with exactly the same issue but no resolution. http://devnet.kentico.com/questions/custom-e-commerce-one-page-checkout-web-part-issues

My order is place correctly. The shopping cart has the proper billing address (shipping is not needed.)

PaymentGatewayProvider.OrderId = ShoppingCart.OrderId;
PaymentGatewayProvider.ShoppingCartInfoObj = ShoppingCart;

I can process the payment thru the dashboard so I know the Authorize.Net portion is set up correctly. Not sure what I am missing in my code. Any suggestions?

Here is my current code in case it helps.

AddItemToCart(_skuId, donationAmount);

SetUpCustomer(firstName, lastName, email, phone, address1, address2, city, stateId, 
    countryId, zipCode, nameOnCard, donationAmount, isRecurring, donationFrequency, subscribeNewsletter);

CurrentShoppingCart.Customer = _customer;
CurrentShoppingCart.RegisterAfterCheckout = true;
CurrentShoppingCart.ShoppingCartBillingAddress = _customerAddress;

ShoppingCartInfoProvider.SetOrder(CurrentShoppingCart);
ShoppingCartInfoProvider.SetShoppingCartInfo(CurrentShoppingCart);

CurrentShoppingCart.PaymentGatewayCustomData[AuthorizeNetParameters.CARD_NUMBER] = txtCardNumber.Text.Trim();
CurrentShoppingCart.PaymentGatewayCustomData[AuthorizeNetParameters.CARD_CCV] = txtSecurityCode.Text.Trim();
CurrentShoppingCart.PaymentGatewayCustomData[AuthorizeNetParameters.CARD_EXPIRATION] = CreditCardExpiration;

if (MyAuthorizePaymentProvider != null)
{
    MyAuthorizePaymentProvider.OrderId = CurrentShoppingCart.OrderId;
    MyAuthorizePaymentProvider.ShoppingCartInfoObj = CurrentShoppingCart;

    // Validate data if web part is not placed in wizard
    string validationMsg = MyAuthorizePaymentProvider.ValidateCustomData();
    if (!string.IsNullOrEmpty(validationMsg))
    {
        // Do not continue if validation failed
        ShowError(validationMsg);
    }

    MyAuthorizePaymentProvider.ProcessCustomData();

    MyAuthorizePaymentProvider.ProcessPayment();
}

   Please, sign in to be able to submit a new answer.