<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Error E0007 via C# code in Integration and Testing</title>
    <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/Error-E0007-via-C-code/m-p/62342#M36689</link>
    <description>&lt;P&gt;We are trying to call to the A.NET API via C# code in a website.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I installed the Authorize.Net NuGet package to the project in Visual Studio.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I went to the test form on a.net, and entered my credentials and verified they work here:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://developer.authorize.net/api/reference/index.html#payment-transactions" target="_self"&gt;https://developer.authorize.net/api/reference/index.html#payment-transactions&lt;/A&gt;&lt;/P&gt;&lt;P&gt;It gives me back this response...&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;
&amp;lt;authenticateTestResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"&amp;gt;
  &amp;lt;messages&amp;gt;
    &amp;lt;resultCode&amp;gt;Ok&amp;lt;/resultCode&amp;gt;
    &amp;lt;message&amp;gt;
      &amp;lt;code&amp;gt;I00001&amp;lt;/code&amp;gt;
      &amp;lt;text&amp;gt;Successful.&amp;lt;/text&amp;gt;
    &amp;lt;/message&amp;gt;
  &amp;lt;/messages&amp;gt;
&amp;lt;/authenticateTestResponse&amp;gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I copied the C# demo code found here:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/AuthorizeNet/sample-code-csharp/blob/master/PaymentTransactions/ChargeCreditCard.cs" target="_self"&gt;https://github.com/AuthorizeNet/sample-code-csharp/blob/master/PaymentTransactions/ChargeCreditCard.cs&lt;/A&gt;&lt;/P&gt;&lt;P&gt;and changed it as necessary (filling in values from our forms/databases).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my actual code:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;        public static Result Run(long clientid, decimal chargeAmount, customerAddressType billingAddress, creditCardType creditCard, List&amp;lt;lineItemType&amp;gt; lineItems) {
            Models.ClientAuthorizeNetInfo authInfo = Data.GetClientAuthorizeNetInfo(clientid);

            ApiOperationBase&amp;lt;ANetApiRequest, ANetApiResponse&amp;gt;.RunEnvironment =
                authInfo.UseSandbox ?
                    AuthorizeNet.Environment.SANDBOX :
                    AuthorizeNet.Environment.PRODUCTION;

            //standard api call to retrieve response
            var paymentType = new paymentType { Item = creditCard };

            var transactionRequest = new transactionRequestType {
                transactionType = transactionTypeEnum.authCaptureTransaction.ToString(),    // charge the card
                amount = chargeAmount,
                amountSpecified = true,
                currencyCode = "USD",
                payment = paymentType,
                billTo = billingAddress,
                lineItems = lineItems.ToArray()
            };

            var request = new createTransactionRequest { transactionRequest = transactionRequest };
            request.merchantAuthentication = new merchantAuthenticationType() {
                name = authInfo.ApiLogin,
                ItemElementName = ItemChoiceType.transactionKey,
                Item = authInfo.TransactionKey,
            };
            Library.Log("AuthorizeNetTransaction.Run", JsonConvert.SerializeObject(request));
            Library.Log("AuthorizeNetTransaction.Run", (authInfo.UseSandbox ?
                    AuthorizeNet.Environment.SANDBOX.getBaseUrl() :
                    AuthorizeNet.Environment.PRODUCTION.getBaseUrl()));

            // instantiate the controller that will call the service
            var controller = new createTransactionController(request);
            controller.Execute((authInfo.UseSandbox ?
                    AuthorizeNet.Environment.SANDBOX :
                    AuthorizeNet.Environment.PRODUCTION));

            // get the response from the service (errors contained if any)
            var response = controller.GetApiResponse();
            Library.Log("AuthorizeNetTransaction.Run", JsonConvert.SerializeObject(response));

            Result rv = new Result();

            // validate response
            if (response != null) {
                if (response.messages.resultCode == messageTypeEnum.Ok) {
                    if (response.transactionResponse.messages != null) {
                        rv.success = true;
                        rv.data = $"Transaction ID: {response.transactionResponse.transId}; Authorization Code: {response.transactionResponse.authCode}";
                    } else {
                        if (response.transactionResponse.errors != null) {
                            rv.data = $"({response.transactionResponse.errors[0].errorCode}) {response.transactionResponse.errors[0].errorText}";
                        } else {
                            rv.data = "Failure information unavailable.";
                        }
                    }
                } else {
                    if (response.transactionResponse != null &amp;amp;&amp;amp; response.transactionResponse.errors != null) {
                        rv.data = $"({response.transactionResponse.errors[0].errorCode}) {response.transactionResponse.errors[0].errorText}";
                    } else {
                        rv.data = $"({response.messages.message[0].code}) {response.messages.message[0].text}";
                    }
                }
            } else {
                rv.data = "Null response from merchant account.";
            }

            return rv;
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now right off, I'll state there are a few changes to the code I had to make.&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. I had to set "amountSpecified" on the transactionRequest to true, otherwise my amount never showed up in the request.&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. I had to set the merchantAuthentication directly on the request object, otherwise it never showed up in the request.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I'm kinda suspect on trusting the rest of the code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I call GetApiResponse, it always comes back with the following...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;{
    "transactionResponse": {
        "responseCode": null,
        "rawResponseCode": null,
        "authCode": null,
        "avsResultCode": null,
        "cvvResultCode": null,
        "cavvResultCode": null,
        "transId": null,
        "refTransID": null,
        "transHash": null,
        "testRequest": null,
        "accountNumber": null,
        "entryMode": null,
        "accountType": null,
        "splitTenderId": null,
        "prePaidCard": null,
        "messages": null,
        "errors": null,
        "splitTenderPayments": null,
        "userFields": null,
        "shipTo": null,
        "secureAcceptance": null,
        "emvResponse": null,
        "transHashSha2": null,
        "profile": null
    },
    "profileResponse": null,
    "refId": null,
    "messages": {
        "resultCode": 1,
        "message": [
            {
                "code": "E00007",
                "text": "User authentication failed due to invalid authentication values."
            }
        ]
    },
    "sessionToken": null
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have verified (after changing how I add them) that the correct API login and Transaction Key are being sent in the request. For example, here is one of my requests (actual login values changes)...&lt;/P&gt;&lt;PRE&gt;{
    "transactionRequest": {
        "transactionType": "authCaptureTransaction",
        "amount": 600,
        "amountSpecified": true,
        "currencyCode": "USD",
        "payment": {
            "Item": {
                "cardCode": "987",
                "isPaymentTokenSpecified": false,
                "cryptogram": null,
                "cardNumber": "5424000000000015",
                "expirationDate": "0821"
            }
        },
        "profile": null,
        "solution": null,
        "callId": null,
        "terminalNumber": null,
        "authCode": null,
        "refTransId": null,
        "splitTenderId": null,
        "order": null,
        "lineItems": [
            {
                "itemId": "14",
                "name": " adminsitration",
                "description": " adminsitration",
                "quantity": 1,
                "unitPrice": 600,
                "taxableSpecified": false
            }
        ],
        "tax": null,
        "duty": null,
        "shipping": null,
        "taxExemptSpecified": false,
        "poNumber": null,
        "customer": null,
        "billTo": {
            "phoneNumber": null,
            "faxNumber": null,
            "email": null,
            "firstName": "Joe",
            "lastName": "Schmoe",
            "company": null,
            "address": "123 Sesame Street",
            "city": "New York",
            "state": "NY",
            "zip": "10012",
            "country": null
        },
        "shipTo": null,
        "customerIP": null,
        "cardholderAuthentication": null,
        "retail": null,
        "employeeId": null,
        "transactionSettings": null,
        "userFields": null,
        "surcharge": null,
        "merchantDescriptor": null,
        "subMerchant": null,
        "tip": null
    },
    "merchantAuthentication": {
        "name": "myApiLoginHere",
        "Item": "myTransactionKeyHere",
        "ItemElementName": 6,
        "mobileDeviceId": null
    },
    "clientId": null,
    "refId": null
}&lt;/PRE&gt;&lt;P&gt;I'm using one of the test credit cards shown&amp;nbsp;in the Testing Guide and have verified that I am setting the RunEnvironment to SANDBOX (assuming the code to set it is working, given that the code to set the merchantAuthentication in the original sample code wasn't working).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I'm at a loss for why our credentials DO work when tested online, but through code, they are rejected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 27 Mar 2018 21:36:15 GMT</pubDate>
    <dc:creator>Xiacon140</dc:creator>
    <dc:date>2018-03-27T21:36:15Z</dc:date>
    <item>
      <title>Error E0007 via C# code</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/Error-E0007-via-C-code/m-p/62342#M36689</link>
      <description>&lt;P&gt;We are trying to call to the A.NET API via C# code in a website.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I installed the Authorize.Net NuGet package to the project in Visual Studio.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I went to the test form on a.net, and entered my credentials and verified they work here:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://developer.authorize.net/api/reference/index.html#payment-transactions" target="_self"&gt;https://developer.authorize.net/api/reference/index.html#payment-transactions&lt;/A&gt;&lt;/P&gt;&lt;P&gt;It gives me back this response...&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;
&amp;lt;authenticateTestResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"&amp;gt;
  &amp;lt;messages&amp;gt;
    &amp;lt;resultCode&amp;gt;Ok&amp;lt;/resultCode&amp;gt;
    &amp;lt;message&amp;gt;
      &amp;lt;code&amp;gt;I00001&amp;lt;/code&amp;gt;
      &amp;lt;text&amp;gt;Successful.&amp;lt;/text&amp;gt;
    &amp;lt;/message&amp;gt;
  &amp;lt;/messages&amp;gt;
&amp;lt;/authenticateTestResponse&amp;gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I copied the C# demo code found here:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/AuthorizeNet/sample-code-csharp/blob/master/PaymentTransactions/ChargeCreditCard.cs" target="_self"&gt;https://github.com/AuthorizeNet/sample-code-csharp/blob/master/PaymentTransactions/ChargeCreditCard.cs&lt;/A&gt;&lt;/P&gt;&lt;P&gt;and changed it as necessary (filling in values from our forms/databases).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my actual code:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;        public static Result Run(long clientid, decimal chargeAmount, customerAddressType billingAddress, creditCardType creditCard, List&amp;lt;lineItemType&amp;gt; lineItems) {
            Models.ClientAuthorizeNetInfo authInfo = Data.GetClientAuthorizeNetInfo(clientid);

            ApiOperationBase&amp;lt;ANetApiRequest, ANetApiResponse&amp;gt;.RunEnvironment =
                authInfo.UseSandbox ?
                    AuthorizeNet.Environment.SANDBOX :
                    AuthorizeNet.Environment.PRODUCTION;

            //standard api call to retrieve response
            var paymentType = new paymentType { Item = creditCard };

            var transactionRequest = new transactionRequestType {
                transactionType = transactionTypeEnum.authCaptureTransaction.ToString(),    // charge the card
                amount = chargeAmount,
                amountSpecified = true,
                currencyCode = "USD",
                payment = paymentType,
                billTo = billingAddress,
                lineItems = lineItems.ToArray()
            };

            var request = new createTransactionRequest { transactionRequest = transactionRequest };
            request.merchantAuthentication = new merchantAuthenticationType() {
                name = authInfo.ApiLogin,
                ItemElementName = ItemChoiceType.transactionKey,
                Item = authInfo.TransactionKey,
            };
            Library.Log("AuthorizeNetTransaction.Run", JsonConvert.SerializeObject(request));
            Library.Log("AuthorizeNetTransaction.Run", (authInfo.UseSandbox ?
                    AuthorizeNet.Environment.SANDBOX.getBaseUrl() :
                    AuthorizeNet.Environment.PRODUCTION.getBaseUrl()));

            // instantiate the controller that will call the service
            var controller = new createTransactionController(request);
            controller.Execute((authInfo.UseSandbox ?
                    AuthorizeNet.Environment.SANDBOX :
                    AuthorizeNet.Environment.PRODUCTION));

            // get the response from the service (errors contained if any)
            var response = controller.GetApiResponse();
            Library.Log("AuthorizeNetTransaction.Run", JsonConvert.SerializeObject(response));

            Result rv = new Result();

            // validate response
            if (response != null) {
                if (response.messages.resultCode == messageTypeEnum.Ok) {
                    if (response.transactionResponse.messages != null) {
                        rv.success = true;
                        rv.data = $"Transaction ID: {response.transactionResponse.transId}; Authorization Code: {response.transactionResponse.authCode}";
                    } else {
                        if (response.transactionResponse.errors != null) {
                            rv.data = $"({response.transactionResponse.errors[0].errorCode}) {response.transactionResponse.errors[0].errorText}";
                        } else {
                            rv.data = "Failure information unavailable.";
                        }
                    }
                } else {
                    if (response.transactionResponse != null &amp;amp;&amp;amp; response.transactionResponse.errors != null) {
                        rv.data = $"({response.transactionResponse.errors[0].errorCode}) {response.transactionResponse.errors[0].errorText}";
                    } else {
                        rv.data = $"({response.messages.message[0].code}) {response.messages.message[0].text}";
                    }
                }
            } else {
                rv.data = "Null response from merchant account.";
            }

            return rv;
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now right off, I'll state there are a few changes to the code I had to make.&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. I had to set "amountSpecified" on the transactionRequest to true, otherwise my amount never showed up in the request.&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. I had to set the merchantAuthentication directly on the request object, otherwise it never showed up in the request.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I'm kinda suspect on trusting the rest of the code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I call GetApiResponse, it always comes back with the following...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;{
    "transactionResponse": {
        "responseCode": null,
        "rawResponseCode": null,
        "authCode": null,
        "avsResultCode": null,
        "cvvResultCode": null,
        "cavvResultCode": null,
        "transId": null,
        "refTransID": null,
        "transHash": null,
        "testRequest": null,
        "accountNumber": null,
        "entryMode": null,
        "accountType": null,
        "splitTenderId": null,
        "prePaidCard": null,
        "messages": null,
        "errors": null,
        "splitTenderPayments": null,
        "userFields": null,
        "shipTo": null,
        "secureAcceptance": null,
        "emvResponse": null,
        "transHashSha2": null,
        "profile": null
    },
    "profileResponse": null,
    "refId": null,
    "messages": {
        "resultCode": 1,
        "message": [
            {
                "code": "E00007",
                "text": "User authentication failed due to invalid authentication values."
            }
        ]
    },
    "sessionToken": null
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have verified (after changing how I add them) that the correct API login and Transaction Key are being sent in the request. For example, here is one of my requests (actual login values changes)...&lt;/P&gt;&lt;PRE&gt;{
    "transactionRequest": {
        "transactionType": "authCaptureTransaction",
        "amount": 600,
        "amountSpecified": true,
        "currencyCode": "USD",
        "payment": {
            "Item": {
                "cardCode": "987",
                "isPaymentTokenSpecified": false,
                "cryptogram": null,
                "cardNumber": "5424000000000015",
                "expirationDate": "0821"
            }
        },
        "profile": null,
        "solution": null,
        "callId": null,
        "terminalNumber": null,
        "authCode": null,
        "refTransId": null,
        "splitTenderId": null,
        "order": null,
        "lineItems": [
            {
                "itemId": "14",
                "name": " adminsitration",
                "description": " adminsitration",
                "quantity": 1,
                "unitPrice": 600,
                "taxableSpecified": false
            }
        ],
        "tax": null,
        "duty": null,
        "shipping": null,
        "taxExemptSpecified": false,
        "poNumber": null,
        "customer": null,
        "billTo": {
            "phoneNumber": null,
            "faxNumber": null,
            "email": null,
            "firstName": "Joe",
            "lastName": "Schmoe",
            "company": null,
            "address": "123 Sesame Street",
            "city": "New York",
            "state": "NY",
            "zip": "10012",
            "country": null
        },
        "shipTo": null,
        "customerIP": null,
        "cardholderAuthentication": null,
        "retail": null,
        "employeeId": null,
        "transactionSettings": null,
        "userFields": null,
        "surcharge": null,
        "merchantDescriptor": null,
        "subMerchant": null,
        "tip": null
    },
    "merchantAuthentication": {
        "name": "myApiLoginHere",
        "Item": "myTransactionKeyHere",
        "ItemElementName": 6,
        "mobileDeviceId": null
    },
    "clientId": null,
    "refId": null
}&lt;/PRE&gt;&lt;P&gt;I'm using one of the test credit cards shown&amp;nbsp;in the Testing Guide and have verified that I am setting the RunEnvironment to SANDBOX (assuming the code to set it is working, given that the code to set the merchantAuthentication in the original sample code wasn't working).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I'm at a loss for why our credentials DO work when tested online, but through code, they are rejected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Mar 2018 21:36:15 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/Error-E0007-via-C-code/m-p/62342#M36689</guid>
      <dc:creator>Xiacon140</dc:creator>
      <dc:date>2018-03-27T21:36:15Z</dc:date>
    </item>
    <item>
      <title>Re: Error E0007 via C# code</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/Error-E0007-via-C-code/m-p/62403#M36733</link>
      <description>&lt;P&gt;Apparently it just didn't like my transaction key for whatever reason.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I generated a new one, and now it works.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Who knows.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Mar 2018 19:18:22 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/Error-E0007-via-C-code/m-p/62403#M36733</guid>
      <dc:creator>Xiacon140</dc:creator>
      <dc:date>2018-03-29T19:18:22Z</dc:date>
    </item>
  </channel>
</rss>

