cancel
Showing results for 
Search instead for 
Did you mean: 

C# SDK Bug fixes for the Transaction Details API

So I just started using the transaction details api.  I discovered that there several bugs, some relating to getting transactions, and some missing features that were available in xml, but had missing functions in the c# methods.

 

First, the GetSettledBatchList only returns batches that were settled in the last 24 hours, even if one specifies dates.  While the code does set the dates in the xml it generates, the problem stems from the fact that there is another value of 'settlementDateFieldSpecified' that is not set to true when one specifies the dates.  To fix this

 

in the AnetAPISchema.cs file, around line 5690 or so, inside the 'getSettledBatchListRequest' class, one needs to add this

 

this.firstSettlementDateFieldSpecified = true;

 to the firstSettlementDate property. this results in this:

 

/// <remarks/>
        public System.DateTime firstSettlementDate {
            get {
                return this.firstSettlementDateField;
            }
            set {
                this.firstSettlementDateField = value;
                this.firstSettlementDateFieldSpecified = true;
            }
        }

 

 

you also need to do a similar thing to the lastSettlementDate property, so it looks like this:

 

/// <remarks/>
        public System.DateTime lastSettlementDate {
            get {
                return this.lastSettlementDateField;
            }
            set {
                this.lastSettlementDateField = value;
                this.lastSettlementDateFieldSpecified = true;
            }
        }

 

 

After doing this, using dates in GetTransactionList and GetSettledBatchList will both work.

 

----

Another bug that exists is that one cannot get the statistics out of any batch object. This is from a similar bug as the date issue, where one needs to set a boolean in the xml request to get the batch statistics. To fix this, first change IReportingGateway.cs, so that  lines 4 and 5 are changed to this:

 

System.Collections.Generic.List<AuthorizeNet.Batch> GetSettledBatchList(DateTime from, DateTime to, bool includeStatistics = false);
System.Collections.Generic.List<AuthorizeNet.Batch> GetSettledBatchList(bool includeStatistics = false);

 then, in ReportingGateway.cs, change the method GetSettledBatchList with the date fields to this:

 

public List<Batch> GetSettledBatchList(DateTime from, DateTime to, bool includeStatistics = false)

 and the GetSettledBatchList that doesn't specify anything to this:

 

public List<Batch> GetSettledBatchList(bool includeStatistics = false)

 These changes make it so that there is an option boolean you can pass to the GetSettledBatchList functions in order to have the 'Charges' property have values in it.

----

And those are the bug fixes. Now for the missing features.

 

First, we're missing GetUnsettledTransactionList.

 

In the AnetApiSchema.cs, add the following at the end, before the last closing brace.

 

 

/// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "AnetApi/xml/v1/schema/AnetApiSchema.xsd")]
    [System.Xml.Serialization.XmlRootAttribute(Namespace = "AnetApi/xml/v1/schema/AnetApiSchema.xsd", IsNullable = false)]
    public partial class getUnsettledTransactionListRequest : ANetApiRequest
    {
        //there are no fields to pass for unsettled transaction requests
    }

    /// is duplicate to the list from a standard transaction list <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "AnetApi/xml/v1/schema/AnetApiSchema.xsd")]
    [System.Xml.Serialization.XmlRootAttribute(Namespace = "AnetApi/xml/v1/schema/AnetApiSchema.xsd", IsNullable = false)]
    public partial class getUnsettledTransactionListResponse : ANetApiResponse
    {

        private transactionSummaryType[] transactionsField;

        /// <remarks/>
        [System.Xml.Serialization.XmlArrayItemAttribute("transaction", IsNullable = false)]
        public transactionSummaryType[] transactions
        {
            get
            {
                return this.transactionsField;
            }
            set
            {
                this.transactionsField = value;
            }
        }
    }

 Then in ReportingGateway.cs, add the following before the second to last closing brace

 

 

/// <summary>
        /// returns the most recent 1000 transactions that are unsettled
        /// </summary>
        /// <returns></returns>
        public List<Transaction> GetUnsettledTransactionList()
        {
            var response = (getUnsettledTransactionListResponse) _gateway.Send(new getUnsettledTransactionListRequest());
            return Transaction.NewListFromResponse(response.transactions);
        }

 And in HttpXMLUtility.cs, in the large switch that starts around line 126, add this:

 

 

case "getUnsettledTransactionListResponse":
    serializer = new XmlSerializer(typeof(getUnsettledTransactionListResponse));
    apiResponse = (getUnsettledTransactionListResponse)serializer.Deserialize(reader);
    break;

 

 

Now you should be able to get unsettled transactions.

 

Next, we're missing the details for a single transaction, GetTransactionDetails

In ReportingGateway.cs, add the following (probably after the GetTransactionList functions)

 

/// <summary>
/// Returns Transaction details for a given transaction ID (transid)
/// </summary>
/// <param name="transactionID"></param>
public Transaction GetTransactionDetails(string transactionID){
    var req = new getTransactionDetailsRequest();
    req.transId = transactionID;
    var response = (getTransactionDetailsResponse) _gateway.Send(req);
    return Transaction.NewFromResponse(response.transaction);
}

 

 

And in AnetApiSchema, add this (I put it on line 5553)

 

/// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "AnetApi/xml/v1/schema/AnetApiSchema.xsd")]
    [System.Xml.Serialization.XmlRootAttribute(Namespace = "AnetApi/xml/v1/schema/AnetApiSchema.xsd", IsNullable = false)]
    public partial class getTransactionDetailsRequest : ANetApiRequest {

        private string transIdField;

        /// <remarks/>
        public string transId {
            get {
                return this.transIdField;
            }
            set {
                this.transIdField = value;
            }
        }
    }

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "AnetApi/xml/v1/schema/AnetApiSchema.xsd")]
    [System.Xml.Serialization.XmlRootAttribute(Namespace = "AnetApi/xml/v1/schema/AnetApiSchema.xsd", IsNullable = false)]
    public partial class getTransactionDetailsResponse : ANetApiResponse {

        private transactionDetailsType transactionField;

        /// <remarks/>
        public transactionDetailsType transaction {
            get {
                return this.transactionField;
            }
            set {
                this.transactionField = value;
            }
        }
    }

 And in HttpXmlUtility, add this to the switch statement that starts on line 126

 

case "getTransactionDetailsResponse":
    serializer = new XmlSerializer(typeof(getTransactionDetailsResponse));
    apiResponse = (getTransactionDetailsResponse)serializer.Deserialize(reader);
    break;

 

 

 

Finally, the last missing feature, is getting the info/statistics for a single batch id.

 

In ReportingGateway, add the following (I put it right after the second GetSettledbatchList):

 

 

/// <summary>
        /// Returns the statistics for a single batchId
        /// </summary>
        /// <param name="batchId">the batch id</param>
        /// <returns>a batch with statistics</returns>
        public Batch GetBatchStatistics(string batchId)
        {
            var req = new getBatchStatisticsRequest();
            req.batchId = batchId;
            var response = (getBatchStatisticsResponse)_gateway.Send(req);
            return Batch.NewFromResponse(response);
        }

 

Then, add the following to AnetApiSchema

 

/// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "AnetApi/xml/v1/schema/AnetApiSchema.xsd")]
    [System.Xml.Serialization.XmlRootAttribute(Namespace = "AnetApi/xml/v1/schema/AnetApiSchema.xsd", IsNullable = false)]
    public partial class getBatchStatisticsRequest : ANetApiRequest
    {
        private string batchIdField;

        /// <remarks/>
        public string batchId
        {
            get
            {
                return this.batchIdField;
            }
            set
            {
                this.batchIdField = value;
            }
        }
    }

    // <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "AnetApi/xml/v1/schema/AnetApiSchema.xsd")]
    [System.Xml.Serialization.XmlRootAttribute(Namespace = "AnetApi/xml/v1/schema/AnetApiSchema.xsd", IsNullable = false)]
    public partial class getBatchStatisticsResponse : ANetApiResponse
    {
        private batchDetailsType batchField;
        /// <remarks/>
        [System.Xml.Serialization.XmlElement("batch")]
        public batchDetailsType batchDetails
        {
            get
            {
                return this.batchField;
            }
            set{
                this.batchField = value;
            }
        }
    }

 

 

And add this to the switch statement (that starts on 126) in HttpXmlUtility

 

case "getBatchStatisticsResponse":
    serializer = new XmlSerializer(typeof(getBatchStatisticsResponse));
    apiResponse = (getBatchStatisticsResponse)serializer.Deserialize(reader);
    break;

 

And this to Batch.cs, in the class Batch (I added it on line 125)

 

public static Batch NewFromResponse(getBatchStatisticsResponse batch)
        {
            return new Batch
            {
                ID = batch.batchDetails.batchId,
                PaymentMethod = batch.batchDetails.paymentMethod,
                SettledOn = batch.batchDetails.settlementTimeUTC,
                State = batch.batchDetails.settlementState,
                Charges = Charge.NewFromStat(batch.batchDetails.statistics)
            };
        }

 

 

Now you should have everything that is available in XML, and fixed all of the bugs too.

 

 

Or at least I think so. It's possible I'm missing some changes I've made.

 

jbrueni
Member
4 REPLIES 4

Hey jbrueni,

 

Thank you for the fabulous feedback! I'm passing this on to our development teams so they can review it as they make updates to the SDK.

 

Thanks,

 

Michelle

Developer Community Manager

Michelle
All Star

Any update on when the new C# dll will be released? I am running into the same object reference not set to an instance of an object null reference exceptions when calling gate.GetTransactionList() or gate.GetSettledBatchList()

Hey again,

 

The last scheduled release of the updates to the C# SDK got postponed, but we are working on getting the next release out hopefully within the next week or so. Once the SDK has been updated with the bug fixes, we will post an announcement in the News and Announcements board. So keep your eye out for that to come soon.

Thanks,

Michelle
Developer Community Manager

Just to follow up, the C# SDK bug fixes were released last week. Check out the thread here for a list of what was fixed.

 Thanks,

Michelle
Developer Community Manager