cancel
Showing results for 
Search instead for 
Did you mean: 

ECheque Error: There was an error generating the XML document.

Below is my code:

 

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = UseSandbox ? AuthorizeNet.Environment.SANDBOX : AuthorizeNet.Environment.PRODUCTION;
ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
{
name = ApiLoginID,
ItemElementName = ItemChoiceType.transactionKey,
Item = TransactionKey
};

 

ECheckPayment eChequePayment = payment as ECheckPayment;

 

var bankAccount = new bankAccountType
{

accountType = bankAccountTypeEnum.checking,
routingNumber = eChequePayment.CheckRouting,
accountNumber = eChequePayment.CheckAccount,
nameOnAccount = eChequePayment.CardHolderName,
echeckType = echeckTypeEnum.WEB
};

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

var transactionRequest = new transactionRequestType
{
transactionType = transactionTypeEnum.authCaptureTransaction.ToString(),
payment = paymentType,
amount = eChequePayment.Amount
};

var request = new createTransactionRequest { transactionRequest = transactionRequest };

// instantiate the controller 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();

// validate response
if (response != null)
{
if (response.messages.resultCode == messageTypeEnum.Ok)
{
if (response.transactionResponse.messages != null)
{
//Transaction ID and Transaction Code are the same
eChequePayment.TransactionID = response.transactionResponse.transId;
eChequePayment.ProviderTransactionID = response.refId;
eChequePayment.AuthorizationCode = response.transactionResponse.responseCode;
eChequePayment.ValidationCode = response.messages.message[0].code;
result = true;
}
else
{
Logger.GetLogger.Error("Failed Transaction.");
if (response.transactionResponse.errors != null)
{
Logger.GetLogger.Error("Error Code: " + response.transactionResponse.errors[0].errorCode);
Logger.GetLogger.Error("Error message: " + response.transactionResponse.errors[0].errorText);
throw new Exception("Error: " + response.transactionResponse.errors[0].errorCode + " " + response.transactionResponse.errors[0].errorText);
}
}
}
else
{
Logger.GetLogger.Error("Failed Transaction.");
if (response.transactionResponse != null && response.transactionResponse.errors != null)
{
Logger.GetLogger.Error("Error Code: " + response.transactionResponse.errors[0].errorCode);
Logger.GetLogger.Error("Error message: " + response.transactionResponse.errors[0].errorText);
throw new Exception("Error: " + response.transactionResponse.errors[0].errorCode + " " + response.transactionResponse.errors[0].errorText);

}
else
{
Logger.GetLogger.Error("Error Code: " + response.messages.message[0].code);
Logger.GetLogger.Error("Error message: " + response.messages.message[0].text);
throw new Exception("Error: " + response.messages.message[0].code + " " + response.messages.message[0].text);
}
}
}
else
{
Logger.GetLogger.Error("Null Response.");
}
}
catch (Exception ex)
{
message = "Unexpected error encountered in AuthorizeDotNetEChequeGateway.ProcessPayment: " + ex.Message.ToString();
Logger.GetLogger.Error("Unexpected error encountered in AuthorizeDotNetEChequeGateway.ProcessPayment: " + ex.Message.ToString());
throw ex;
}

 

It gives me the below mentioned error: 

There was an error generating the XML document.

 

Below is the stack trace:

 

at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
at AuthorizeNet.Util.HttpUtility.PostData[TQ,TS](Environment env, TQ request)
at AuthorizeNet.Api.Controllers.Bases.ApiOperationBase`2.Execute(Environment environment)
at AuthorizeDotNet.Gateways.Authorize.Net.ECheque.AuthorizeDotNetEChequeGateway.ProcessPayment(Payment payment, String& message)

 

Has anyone got a similar error/issue, any guidance on this will be appreciated.

 

 

 

 

 

 

 

 

sidu1987
Member
2 REPLIES 2

Hi @sidu1987

 

Have you checked out our sample code for it 

 

https://github.com/AuthorizeNet/sample-code-csharp/blob/master/PaymentTransactions/DebitBankAccount....

 

Hope it helps !!! 





Send feedback at developer_feedback@authorize.net
Anurag
Moderator Moderator
Moderator

Hi @Anurag, thank you for looking into my issue. The code above is the same as the sample piece that you provided. Do I need to change any setting for ECheque which I am missing in my case.