cancel
Showing results for 
Search instead for 
Did you mean: 

Response is Null c#

Okay, so I tried this on the SDK and the online api 'try it' sections... i changed the cardCode = "xxx" and i get a response. however on what im trying to implement i get a null for the response. I have attached parts of my code and the parameters im passing...I am only trying to authorize a transaction. 

 

Parameters-

{
String ApiLoginID = WebServices.getPreference("authorizenetLoginId");
String ApiTransactionKey =WebServices.getPreference("authorizenetTransKey");
string cc = "4111111111111111";
string expm = "11";
string expy = "16";
string cvv2 = "xxxx";
string order = "Towels";
decimal amount = Decimal.Parse("12345.65789");
string summary = string.Concat(order,"-",amount);
string name = "doggy dog cat";
string addr1 = "Testaddr1";
string addr2 = "Testaddr2";
string city = "Testcity";
string state = "teststate";
string zip = "testzip";
string country = "testCountry";
string email = "Test@email.com";
string phone = "1111117777";
string shipaddr1 = "TestShipaddr1";
string shipaddr2 = "TestShipaddr1";
string shipcity = "Testshipcity";
string shipstate = "testshipstate";
string shipzip = "testzipship";
string shipcountry = "testcountryship";
AuthorizeNetHelper.AuthorizeTransaction(ApiLoginID, ApiTransactionKey, cc,expm,expy,cvv2,order,amount,summary,name,addr1,addr2,city,state,zip,country,email,phone,shipaddr1,shipaddr2,shipcity,shipstate,shipzip,shipcountry);

 

 

authorizeNet response-

public static ANetApiResponse AuthorizeTransaction(String ApiLoginID, String ApiTransactionKey, string cc, string expm, string expy, string cvv2, string order, decimal amount, string summary, string name, string addr1, string addr2, string city, string state, string zip, string country, string email, string phone, string shipaddr1, string shipaddr2, string shipcity, string shipstate, string shipzip, string shipcountry)
{
ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNet.Environment.SANDBOX;

// define the merchant information (authentication / transaction id)
ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
{
name = ApiLoginID,
ItemElementName = ItemChoiceType.transactionKey,
Item = ApiTransactionKey,
};
// Credit Card information to be used for transaction
var cCard = new creditCardType
{
cardNumber = cc,
expirationDate = string.Concat(expm, expy),
cardCode = cvv2
};
//Billing Information to be used for transaction
var billingAddress = new customerAddressType
{
//not sure what to do about fName and lName, we only have "name" in DB, if we leave the name as firstName,
//6It could work but possible problems in finding by name?
firstName = name,
//lastName = "Doe",
address = addr1,
//address2?????
city = city,
state = state,
zip = zip,
email = email,
phoneNumber = phone,
country = country
};
//Shipping Information to be used for transaction
var shippingAddress = new nameAndAddressType
{
firstName = name,
address = shipaddr1,
//Shipaddress2
city = shipcity,
state = shipstate,
zip = shipzip,
country = shipcountry
};

//Order Information for the order
var orderInfo = new orderType
{
invoiceNumber = order,
description = summary
};

//standard api call to retrieve response
var paymentType = new paymentType
{
Item = cCard
};

// // Add line Items
// //var lineItems = new lineItemType[2];
// //lineItems[0] = new lineItemType { itemId = "1", name = "t-shirt", quantity = 2, unitPrice = new Decimal(15.00) };
// //lineItems[1] = new lineItemType { itemId = "2", name = "snowboard", quantity = 1, unitPrice = new Decimal(450.00) };

//Build the Transaction
var transaction = new transactionRequestType
{
transactionType = transactionTypeEnum.authOnlyTransaction.ToString(), // Authorize amount on the card
amount = amount,
billTo = billingAddress,
order = orderInfo,
payment = paymentType,
shipTo = shippingAddress

};
//Make the transaction Request
var request = new createTransactionRequest { transactionRequest = transaction };

// instantiate the contoller that will call the service
var controller = new createTransactionController(request);


controller.Execute();
// get the response from the service (errors contained if any)
var response = controller.GetApiResponse();

 

 

 

 

muddywaters
Member
12 REPLIES 12

After almost two-and-a-half years, here is the answer as to how to get error information from the controller when controller.GetApiResponse() is null.

 

  • Call
    ANetApiResponse errorResponse = controller.GetErrorResponse();
  • then you can get the error code(s) and text(s) from the error response:
    foreach (var message in errorResponse.messages.message) {
       string code = message.code;
       string text = message.text;
    }

In my case, I discovered the problem was in the formatting of the subscription ID. Although it would display as 123456 whenever I would output it for debugging, the error message said that it was '123456       ' instead, because of the way I was storing it in the database.

At first, I found it puzzling to discover that Authorize.Net consistently provides a response, yet I couldn't understand why my response turned out to be null. Later, I realized that the controller object contains an errors collection that can be examined. This collection usually clarifies why the response is null, often indicating an invalid request. By reviewing the Errors, you can find out the specific reason behind the null response.

alex2025
Member

I'm facing the same issue. Did you get solution yet?