cancel
Showing results for 
Search instead for 
Did you mean: 

C# display response message for ChargeCreditCard

Hi there...Upgrading to the new ASP.NET code using the ChargeCreditCard AuthNet API. Everything works except I need to display the response message to the user, especially if the transaction fails. The API code only writes the message to the console. How can I display the response message to the user?

 

Note: from my page code behind, I call ChargeCreditCard.Run(strAuthNetLogin, strAuthNetTransKey, CartTotal);

 

The sample code includes "return response;" but I cannot seem to get the proper syntax to access that info outside of the call.

 

Thanks for the help.

pb100
Member
1 ACCEPTED SOLUTION

Accepted Solutions

r is the transaction response

 

https://github.com/AuthorizeNet/sample-code-csharp/blob/cc84949ba884d8f0315a149ac0daf0a3e48f5d1e/Sam...

 

public ANetApiResponse TestAuthorizeCreditCard()
        {
            var response = (createTransactionResponse)AuthorizeCreditCard.Run(apiLoginId, transactionKey, GetAmount());
            return response;
        }

try it as a createtransactionresponse

 

View solution in original post

6 REPLIES 6

when you run debug, what is in "response"?

RaynorC1emen7
Expert

hi there...

"AuthorizeNet.Api.Contracts.V1.ChargeCreditCardResponse"

 

Here is the sample code: https://github.com/AuthorizeNet/sample-code-csharp/blob/master/PaymentTransactions/ChargeCreditCard....

 

I can call the process with var r = ChargeCreditCard.Run(.....) and then display r.messages.message[0].code + "  " + r.messages.message[0].text. There is additional info in the response that I am unable to get to.

 

Is there a more complete example beyond what is on Github?

 

Thanks!

not really, but you got the source code, so you could look at those.

So what is the best way to get at the complete response info? I would like to also retrieve response.transactionResponse.transId.

 

When calling the controller like this:

var r = ChargeCreditCard.Run(strAuthNetLogin, strAuthNetTransKey, CartTotal);

I can only retrieve response info such as r.messages.message[0].text

 

If I try to retrieve r.transactionResponse.transId I get the error: "ANetAPIResponse does not contain a definition for 'transactionResponse'..."

 

Thanks for your help!

pb100
Member

r is the transaction response

 

https://github.com/AuthorizeNet/sample-code-csharp/blob/cc84949ba884d8f0315a149ac0daf0a3e48f5d1e/Sam...

 

public ANetApiResponse TestAuthorizeCreditCard()
        {
            var response = (createTransactionResponse)AuthorizeCreditCard.Run(apiLoginId, transactionKey, GetAmount());
            return response;
        }

try it as a createtransactionresponse

 

Thanks so much! Will give this a try.