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
1 ACCEPTED SOLUTION

Accepted Solutions

For future reference, the problem ended up being the length of the order.invoiceNumber field.  It's supposed to be a maximum of 20 characters.  If you set it to something longer than that, the request will fail (even though the field itself will hold longer strings without complaint).

View solution in original post

12 REPLIES 12

guess no one knows? :'(

muddywaters
Member

Hi @muddywaters,

 

Glancing over things, I don't see any obvious problems, so I'm just trying to follow up with general questions. Can you clarify when you do get a response? You get a response when you try these parameters in the "Try it" section, correct? And you do get a response when you work through the SDK? Do you mean you get a response using the sample code, but not when using your own code against the SDK?

 

One useful step might be trying to do a more simple request like just an "Authentication" request. If that works, start adding piece by piece until you figure out where it breaks.

Aaron
All Star

Yes, I get a response in the "try It" section and I get a response on the SDK, however in mycode The response is null. Authentication is working fine, I can post transactions and settle them. But when I try to mess with it using invalid data like cvv being "xyz" I get a null response.

well any suggestions? 

I got this same NULL response when my test order.invoiceNumber was set to "679--" and the number of seconds since 1/1/1970 (a large number with five decimals).  Removing one of the - signs made it work.  So, I would suspect that there's something about your invoice number that Auth.Net magically doesn't like.  Try changing it (or temporarily removing it) and see if you get a non-null response.

For future reference, the problem ended up being the length of the order.invoiceNumber field.  It's supposed to be a maximum of 20 characters.  If you set it to something longer than that, the request will fail (even though the field itself will hold longer strings without complaint).

Hi @daves0,

 

I noticed that some of the entries in our API Reference have the format documented as max 20 characters, but other entries for invoiceNumber don't have that specific format defined. I'm going through documentation now to make sure that every usage of invoiceNumber is all documented consistently.

 

Longer term, I'm trying to make sure things are better documented in the API itself, and that if there's an API limitation on the format of a field, the SDK can enforce or warn on that limitation as well.

 

Thanks for bringing this to our attention.

I was initially confused to read that Authorize.Net ALWAYS returns a response. I couldn't figure out why my response was null. Turns out, the controller object has an errors collection you can view. This usually explains why the response is null. Typically, the request is invalid. But the Errors will tell you *why*.

jkshay
Member

Can you provide sample code of using this error collection? 

I am getting back a null response, but looking at the controller object, I don't see any property that is a collection of errors. 

 

thanks!