public List<ResponseDetails> ProcessECKTransaction(
                        TransactionType _TT //Required
                        , ElectronicCheckingTransaction _ECKtransaction
                        , List<String> _BatchIds //Conditional : A list of one or more batch Ids to capture.
                        , List<Capture> _CaptureDifferenceData
                        , Undo _UDifferenceData //Conditional : Only used for an Undo. Otherwise null
                        , bool _SendAcknowledge)
        {
            List<Response> _Response = new List<Response>();
            try
            {
                CheckTokenExpire();//Make sure the current token is valid

                //if (_TT == TransactionType.AuthorizeAndCapture)
                if (_TT == TransactionType.Authorize)
                {
                    if (CredentialRequired())
                        _ECKtransaction.Addendum = CredentialsRequired(_serviceId, _credUserName, _credPassword);
                    _Response.Add(Cwsbc.Authorize(_sessionToken, _ECKtransaction, _applicationProfileId, _merchantProfileId, _serviceId));
                    //Always Verify that the requested amount and approved amount are the same.

                    ElectronicCheckingTransactionResponse ECKR = new ElectronicCheckingTransactionResponse();
                    ECKR = (ElectronicCheckingTransactionResponse)_Response[0];
                    if (_ECKtransaction.TransactionData.Amount != ECKR.Amount)
                        MessageBox.Show("The transaction was approved for " + ECKR.Amount
                            + " which is an amount not equal to than the requested amount of " + _ECKtransaction.TransactionData.Amount
                            + ". Please provide alternate payment to complete transaction");
                }
                //if (_TT == TransactionType.Capture)
                if (_TT == TransactionType.CaptureAll)
                {
                    _CaptureDifferenceData = new List<Capture>();
                    Capture cap = new Capture();
                    if (CredentialRequired())
                        cap.Addendum = CredentialsRequired(_serviceId, _credUserName, _credPassword);
                    cap.TransactionId = "-1";
                    _CaptureDifferenceData.Add(cap);
                    _Response = Cwsbc.CaptureAll(_sessionToken, _CaptureDifferenceData, _BatchIds, _applicationProfileId,
                                                 _merchantProfileId, _serviceId);
                }
                if (_TT == TransactionType.CaptureAllAsync)
                {
                    _CaptureDifferenceData = new List<Capture>();
                    Capture cap = new Capture();
                    if (CredentialRequired())
                        cap.Addendum = CredentialsRequired(_serviceId, _credUserName, _credPassword);
                    cap.TransactionId = "-1";
                    _CaptureDifferenceData.Add(cap);
                    _Response.Add(Cwsbc.CaptureAllAsync(_sessionToken, _CaptureDifferenceData, _BatchIds, _applicationProfileId, _merchantProfileId, _serviceId));
                }

                //if (_TT == TransactionType.CaptureSelective)
                //if (_TT == TransactionType.CaptureSelectiveAsync)
                //if (_TT == TransactionType.ReturnById)
                //if (_TT == TransactionType.Return)
                //if (_TT == TransactionType.Adjust)
                if (_TT == TransactionType.Undo)
                {
                    if (CredentialRequired())
                        _UDifferenceData.Addendum = CredentialsRequired(_serviceId, _credUserName, _credPassword);
                    _Response.Add(Cwsbc.Undo(_sessionToken, _UDifferenceData, _applicationProfileId, _serviceId));
                }
                if (_TT == TransactionType.QueryAccount)
                {
                    if (CredentialRequired())
                        _ECKtransaction.Addendum = CredentialsRequired(_serviceId, _credUserName, _credPassword);
                    _Response.Add(Cwsbc.QueryAccount(_sessionToken, _ECKtransaction, _applicationProfileId, _merchantProfileId, _serviceId));
                }

                //if (_TT == TransactionType.Verify)

                List<ResponseDetails> RD = new List<ResponseDetails>();//Convert the response to response details so that we can report on the UI
                if (_Response != null)
                {
                    foreach (Response r in _Response)
                    {
                        if (_SendAcknowledge && r.TransactionId.Length > 0)
                            Cwsbc.Acknowledge(_sessionToken, r.TransactionId, _applicationProfileId, _serviceId);

                        ResponseDetails RDN = new ResponseDetails(0.00M, r, _TT.ToString(), _serviceId, _merchantProfileId, true, TypeCardType.NotSet, "");
                        MessageBox.Show(ProcessResponse(ref RDN));//Pass as reference so we can extract more values from the response
                        RD.Add(RDN);
                    }
                }

                return RD;
            }
            catch (EndpointNotFoundException)
            {
                //In this case the SvcEndpoint was not available. Try the same logic again with the alternate Endpoint
                try
                {
                    SetTxnEndpoint();//Change the endpoint to use the backup.

                    //TODO : Add a copy of the code above once fully tested out.

                    return null;

                }
                catch (EndpointNotFoundException)
                {
                    MessageBox.Show("Neither the primary or secondary endpoints are available. Unable to process.");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Unable to AuthorizeAndCapture\r\nError Message : " + ex.Message, "AuthorizeAndCapture Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (System.TimeoutException te)
            {
                //A timeout has occured. Prompt the user if they'd like to query for the last transaction submitted
                if (_ECKtransaction != null)
                {
                    DialogResult Result;
                    Result = MessageBox.Show("A timeout has occured. Would you like to query 'RequestTransaction' to obtain transactions with the exact same TenderData? To avoid duplicate charges your code will need to reconcile transactions.",
                                "Request Transaction", MessageBoxButtons.YesNo);
                    if (Result == DialogResult.Yes)
                    {
                        RequestTransaction(_ECKtransaction.TenderData);
                    }
                    else { throw te; }
                }
                else { throw te; }
            }
            catch (Exception ex)
            {
                string strErrorId;
                string strErrorMessage;
                if (_FaultHandler.handleTxnFault(ex, out strErrorId, out strErrorMessage))
                { MessageBox.Show(strErrorId + " : " + strErrorMessage); }
                else { MessageBox.Show(ex.Message); }
            }

            return null;
        }
        private string ProcessElectronicCheckingTransactionResponse(ref ResponseDetails _Response)
        {
            ElectronicCheckingTransactionResponse _ECKResponse = new ElectronicCheckingTransactionResponse();
            _ECKResponse = (ElectronicCheckingTransactionResponse)_Response.Response;

            //Set the amount reference
            _Response.TxnAmount = _ECKResponse.Amount;

            string strResponseMessage = "";

            if (_ECKResponse.Status == Status.Successful)//The transaction was approved
            {//NOTE : Please reference the developers guide for a more complete explination of the return fields
                //Note Highly recommended to save
                if (_ECKResponse.TransactionId != null) strResponseMessage = strResponseMessage + "\r\nTransactionId : " + _ECKResponse.TransactionId;
                strResponseMessage = strResponseMessage + "\r\nMerchant Profile Id : " + _Response.MerchantProfileId;
                //Note Optional but recommended to save
                if (_ECKResponse.StatusCode != null) strResponseMessage = strResponseMessage + "\r\nStatus Code : " + _ECKResponse.StatusCode;
                if (_ECKResponse.StatusMessage != null) strResponseMessage = strResponseMessage + "\r\nStatus Message : " + _ECKResponse.StatusMessage;
                //Note Optional data about the batch
                if (_ECKResponse.ACHCapable != null) strResponseMessage = strResponseMessage + "\r\nACHCapable : " + _ECKResponse.ACHCapable;//Indicates if the customer's account will accept ACH transactions. Returned only on QueryAccount() transactions.
                if (_ECKResponse.Amount != null) strResponseMessage = strResponseMessage + "\r\nAmount : " + _ECKResponse.Amount;
                if (_ECKResponse.ApprovalCode != null) strResponseMessage = strResponseMessage + "\r\nApprovalCode : " + _ECKResponse.ApprovalCode; //A code provided when a transaction is approved.
                if (_ECKResponse.ModifiedAccountNumber != null) strResponseMessage = strResponseMessage + "\r\nModifiedAccountNumber : " + _ECKResponse.ModifiedAccountNumber; //Indicates the corrected account number that should be used for electronic check processing
                if (_ECKResponse.ModifiedRoutingNumber != null) strResponseMessage = strResponseMessage + "\r\nModifiedRoutingNumber : " + _ECKResponse.ModifiedRoutingNumber; //Indicates the corrected 9-digit bank routing number that should be used for electronic check processing.
                if (_ECKResponse.ReturnInformation != null)
                {
                    if (_ECKResponse.ReturnInformation.ReturnCode != null) strResponseMessage = strResponseMessage + "\r\nReturnCode : " + _ECKResponse.ReturnInformation.ReturnCode;//Code that indicates why the transaction was returned.
                    if (_ECKResponse.ReturnInformation.ReturnDate != null) strResponseMessage = strResponseMessage + "\r\nReturnDate : " + _ECKResponse.ReturnInformation.ReturnDate; //The date the transaction was returned by the bank.
                    if (_ECKResponse.ReturnInformation.ReturnReason != null) strResponseMessage = strResponseMessage + "\r\nReturnReason : " + _ECKResponse.ReturnInformation.ReturnReason; //Reason that indicates why the transaction was returned.
                }
                if (_ECKResponse.SubmitDate != null) strResponseMessage = strResponseMessage + "\r\nSubmitDate : " + _ECKResponse.SubmitDate; //The date the transaction was submitted to the bank.

                strResponseMessage = "Your transaction was APPROVED\r\n" + strResponseMessage;
            }
            if (_ECKResponse.Status == Status.Failure)//The transaction was declined
            {//NOTE : Please reference the developers guide for a more complete explination of the return fields
                //Note Highly recommended to save
                if (_ECKResponse.TransactionId != null) strResponseMessage = strResponseMessage + "\r\nTransactionId : " + _ECKResponse.TransactionId;
                strResponseMessage = strResponseMessage + "\r\nMerchant Profile Id : " + _Response.MerchantProfileId;
                //Note Optional but recommended to save
                if (_ECKResponse.StatusCode != null) strResponseMessage = strResponseMessage + "\r\nStatus Code : " + _ECKResponse.StatusCode;
                if (_ECKResponse.StatusMessage != null) strResponseMessage = strResponseMessage + "\r\nStatus Message : " + _ECKResponse.StatusMessage;
                //Note Optional
                if (_ECKResponse.ACHCapable != null) strResponseMessage = strResponseMessage + "\r\nACHCapable : " + _ECKResponse.ACHCapable;//Indicates if the customer's account will accept ACH transactions. Returned only on QueryAccount() transactions.
                if (_ECKResponse.Amount != null) strResponseMessage = strResponseMessage + "\r\nAmount : " + _ECKResponse.Amount;
                if (_ECKResponse.ApprovalCode != null) strResponseMessage = strResponseMessage + "\r\nApprovalCode : " + _ECKResponse.ApprovalCode; //A code provided when a transaction is approved.
                if (_ECKResponse.ModifiedAccountNumber != null) strResponseMessage = strResponseMessage + "\r\nModifiedAccountNumber : " + _ECKResponse.ModifiedAccountNumber; //Indicates the corrected account number that should be used for electronic check processing
                if (_ECKResponse.ModifiedRoutingNumber != null) strResponseMessage = strResponseMessage + "\r\nModifiedRoutingNumber : " + _ECKResponse.ModifiedRoutingNumber; //Indicates the corrected 9-digit bank routing number that should be used for electronic check processing.
                if (_ECKResponse.ReturnInformation != null)
                {
                    if (_ECKResponse.ReturnInformation.ReturnCode != null) strResponseMessage = strResponseMessage + "\r\nReturnCode : " + _ECKResponse.ReturnInformation.ReturnCode;//Code that indicates why the transaction was returned.
                    if (_ECKResponse.ReturnInformation.ReturnDate != null) strResponseMessage = strResponseMessage + "\r\nReturnDate : " + _ECKResponse.ReturnInformation.ReturnDate; //The date the transaction was returned by the bank.
                    if (_ECKResponse.ReturnInformation.ReturnReason != null) strResponseMessage = strResponseMessage + "\r\nReturnReason : " + _ECKResponse.ReturnInformation.ReturnReason; //Reason that indicates why the transaction was returned.
                }
                if (_ECKResponse.SubmitDate != null) strResponseMessage = strResponseMessage + "\r\nSubmitDate : " + _ECKResponse.SubmitDate; //The date the transaction was submitted to the bank.

                strResponseMessage = "Your transaction was DECLINED\r\n" + strResponseMessage;
            }
            if (_ECKResponse.Status == Status.NotSet)//The transaction was declined
            {
                strResponseMessage = "No Transactions found for settlement";
            }
            return strResponseMessage;
        }
        private string ProcessStoredValueTransactionResponse(ref ResponseDetails _Response)
        {
            StoredValueTransactionResponse _SVAResponse = new StoredValueTransactionResponse();
            _SVAResponse = (StoredValueTransactionResponse)_Response.Response;

            //Set the amount reference
            _Response.TxnAmount = _SVAResponse.Amount;

            string strMessage = "";

            //Note : IMPORTANT Always verify the approved amount was the same as the requested approval amount for "AuthorizeAndCapture" as well as "Authorize"
            if (_Response.TransactionType == "AuthorizeAndCapture" | _Response.TransactionType == "Authorize")

                if (!_Response.Verbose)
                {// In this case don't present to the user all of the data.
                    if (_SVAResponse.Status == Status.Successful)//The transaction was approved
                    {
                        //NOTE : Please reference the developers guide for a more complete explination of the return fields
                        strMessage = "Your '" + _Response.TransactionType + "' transaction was APPROVED"
                            //Note Highly recommended to save
                        + "\r\nTransactionId : " + _SVAResponse.TransactionId //The unique id of the transaction. TransactionId is required for all subsequent transactions such as Return, Undo, etc.
                        + "\r\nWorkflowId : " + _Response.WorkflowId
                        + "\r\nMerchantProfileId : " + _Response.MerchantProfileId //Must be stored with the TransactionId in order to identify which merchant sent which transaction. Required to support multi-merchant.
                            //Note Optional but recommended to save
                        + "\r\nStatus Code : " + _SVAResponse.StatusCode //Status code generated by the Service Provider. This code should be displayed to the user as verification of the transaction.
                        + "\r\nStatus Message : " + _SVAResponse.StatusMessage //Explains the StatusCode which is generated by the Service Provider. This message should be displayed to the user as verification of the transaction.
                        + "\r\nApprovalCode : " + _SVAResponse.ApprovalCode //A value returned when a transaction is approved. This value should be printed on the receipt, and also recorded for every off-line transaction, such as a voice authorization. This same data element and value must be provided during settlement. Required.
                        + "\r\nAmount : " + _SVAResponse.Amount //Specifies the authorization amount of the transaction. This is the actual amount authorized.
                        ;
                    }
                    if (_SVAResponse.Status == Status.Failure)//The transaction was declined
                    {
                        //NOTE : Please reference the developers guide for a more complete explination of the return fields
                        strMessage = "Your '" + _Response.TransactionType + "' transaction was DECLINED"
                            //Note Highly recommended to save
                        + "\r\nTransactionId : " + _SVAResponse.TransactionId //The unique id of the transaction. TransactionId is required for all subsequent transactions such as Return, Undo, etc.
                        + "\r\nWorkflowId : " + _Response.WorkflowId
                        + "\r\nMerchantProfileId : " + _Response.MerchantProfileId //Must be stored with the TransactionId in order to identify which merchant sent which transaction. Required to support multi-merchant.
                            //Note Optional but recommended to save
                        + "\r\nStatus Code : " + _SVAResponse.StatusCode //Status code generated by the Service Provider. This code should be displayed to the user as verification of the transaction.
                        + "\r\nStatus Message : " + _SVAResponse.StatusMessage //Explains the StatusCode which is generated by the Service Provider. This message should be displayed to the user as verification of the transaction.
                        ;
                    }
                    return strMessage;
                }
            if (_SVAResponse.Status == Status.Successful)//The transaction was approved
            {
                //NOTE : Please reference the developers guide for a more complete explination of the return fields
                strMessage = "Your '" + _Response.TransactionType + "' transaction was APPROVED"
                    //Note Highly recommended to save
                + "\r\nTransactionId : " + _SVAResponse.TransactionId //The unique id of the transaction. TransactionId is required for all subsequent transactions such as Return, Undo, etc.
                + "\r\nWorkflowId : " + _Response.WorkflowId
                + "\r\nMerchantProfileId : " + _Response.MerchantProfileId //Must be stored with the TransactionId in order to identify which merchant sent which transaction. Required to support multi-merchant.
                    //Note Highly recommended to save if Tokenization will be used
                    //+ "\r\nPaymentAccountDataToken : " + _BCResponse.PaymentAccountDataToken //If tokenization purchased this field represents the actual token returned in the transaction for future use.
                    //Note Optional but recommended to save
                + "\r\nStatus Code : " + _SVAResponse.StatusCode //Status code generated by the Service Provider. This code should be displayed to the user as verification of the transaction.
                + "\r\nStatus Message : " + _SVAResponse.StatusMessage //Explains the StatusCode which is generated by the Service Provider. This message should be displayed to the user as verification of the transaction.
                + "\r\nApprovalCode : " + _SVAResponse.ApprovalCode //A value returned when a transaction is approved. This value should be printed on the receipt, and also recorded for every off-line transaction, such as a voice authorization. This same data element and value must be provided during settlement. Required.
                + "\r\nAmount : " + _SVAResponse.Amount //Specifies the authorization amount of the transaction. This is the actual amount authorized.
                    //Note Optional but recommended if AVS is supported
                    //+ "\r\nAVSResult ActualResult : " + _BCResponse.AVSResult.ActualResult //Specifies the actual result of AVS from the Service Provider.
                    //+ "\r\nAVSResult AddressResult : " + _BCResponse.AVSResult.AddressResult //Specifies the result of AVS as it pertains to Address matching
                    //+ "\r\nAVSResult PostalCodeResult : " + _BCResponse.AVSResult.PostalCodeResult //Specifies the result of AVS as it pertains to Postal Code matching
                    //Note Optional but recommended if CV data is supported
                + "\r\nCVResult : " + _SVAResponse.CVResult //Response code returned by the card issuer indicating the result of Card Verification (CVV2/CVC2/CID).
                    //Note Optional
                + "\r\nServiceTransactionId : " + _SVAResponse.ServiceTransactionId
                    //+ "\r\nSettlementDate : " + _BCResponse.SettlementDate //Settlement date. Conditional, if present in the authorization response, this same data element and value must be provided during settlement
                ;
            }
            if (_SVAResponse.Status == Status.Failure)//The transaction was declined
            {
                //NOTE : Please reference the developers guide for a more complete explination of the return fields
                strMessage = "Your '" + _Response.TransactionType + "' transaction was DECLINED"
                    //Note Highly recommended to save
                + "\r\nTransactionId : " + _SVAResponse.TransactionId //The unique id of the transaction. TransactionId is required for all subsequent transactions such as Return, Undo, etc.
                + "\r\nWorkflowId : " + _Response.WorkflowId
                + "\r\nMerchantProfileId : " + _Response.MerchantProfileId //Must be stored with the TransactionId in order to identify which merchant sent which transaction. Required to support multi-merchant.
                    //Note Optional but recommended to save
                + "\r\nStatus Code : " + _SVAResponse.StatusCode //Status code generated by the Service Provider. This code should be displayed to the user as verification of the transaction.
                + "\r\nStatus Message : " + _SVAResponse.StatusMessage //Explains the StatusCode which is generated by the Service Provider. This message should be displayed to the user as verification of the transaction.
                    //Note Optional but recommended if CV data is supported
                + "\r\nCVResult : " + _SVAResponse.CVResult //Response code returned by the card issuer indicating the result of Card Verification (CVV2/CVC2/CID).
                    //Note Optional
                + "\r\nServiceTransactionId : " + _SVAResponse.ServiceTransactionId
                ;
            }
            return strMessage;
        }
        private string ProcessElectronicCheckingCaptureResponse(ref ResponseDetails _Response)
        {
            ElectronicCheckingCaptureResponse _ECKResponse = new ElectronicCheckingCaptureResponse();
            _ECKResponse = (ElectronicCheckingCaptureResponse)_Response.Response;

            //Set the amount reference
            _Response.TxnAmount = _ECKResponse.SummaryData.NetTotals.NetAmount;

            string strResponseMessage = "";

            if (_ECKResponse.Status == Status.Successful)//The transaction was approved
            {//NOTE : Please reference the developers guide for a more complete explination of the return fields
                //Note Highly recommended to save
                if (_ECKResponse.TransactionId != null) strResponseMessage = strResponseMessage + "\r\nTransactionId : " + _ECKResponse.TransactionId;
                strResponseMessage = strResponseMessage + "\r\nMerchant Profile Id : " + _Response.MerchantProfileId;
                //Note Optional but recommended to save
                if (_ECKResponse.StatusCode != null) strResponseMessage = strResponseMessage + "\r\nStatus Code : " + _ECKResponse.StatusCode;
                if (_ECKResponse.StatusMessage != null) strResponseMessage = strResponseMessage + "\r\nStatus Message : " + _ECKResponse.StatusMessage;
                //Note Optional data about the batch
                if (_ECKResponse.SummaryData != null)
                {
                    if (_ECKResponse.SummaryData.CreditTotals != null) strResponseMessage = strResponseMessage + "\r\nCredit Totals \r\n  Count : " + _ECKResponse.SummaryData.CreditTotals.Count + "\r\n  Net Amount : " + _ECKResponse.SummaryData.CreditTotals.NetAmount;
                    if (_ECKResponse.SummaryData.DebitTotals != null) strResponseMessage = strResponseMessage + "\r\nDebit Totals \r\n  Count : " + _ECKResponse.SummaryData.DebitTotals.Count + "\r\n  Net Amount : " + _ECKResponse.SummaryData.DebitTotals.NetAmount;
                    if (_ECKResponse.SummaryData.NetTotals != null) strResponseMessage = strResponseMessage + "\r\nNet Totals \r\n  Count : " + _ECKResponse.SummaryData.NetTotals.Count + "\r\n  Net Amount : " + _ECKResponse.SummaryData.NetTotals.NetAmount;
                    if (_ECKResponse.SummaryData.VoidTotals != null) strResponseMessage = strResponseMessage + "\r\nVoid Totals \r\n  Count : " + _ECKResponse.SummaryData.VoidTotals.Count + "\r\n  Net Amount : " + _ECKResponse.SummaryData.VoidTotals.NetAmount;
                }
                strResponseMessage = "Your transaction was APPROVED\r\n" + strResponseMessage;
            }
            if (_ECKResponse.Status == Status.Failure)//The transaction was declined
            {//NOTE : Please reference the developers guide for a more complete explination of the return fields
                //Note Highly recommended to save
                if (_ECKResponse.TransactionId != null) strResponseMessage = strResponseMessage + "\r\nTransactionId : " + _ECKResponse.TransactionId;
                strResponseMessage = strResponseMessage + "\r\nMerchant Profile Id : " + _Response.MerchantProfileId;
                //Note Optional but recommended to save
                if (_ECKResponse.StatusCode != null) strResponseMessage = strResponseMessage + "\r\nStatus Code : " + _ECKResponse.StatusCode;
                if (_ECKResponse.StatusMessage != null) strResponseMessage = strResponseMessage + "\r\nStatus Message : " + _ECKResponse.StatusMessage;
                //Note Optional

                strResponseMessage = "Your transaction was DECLINED\r\n" + strResponseMessage;
            }
            if (_ECKResponse.Status == Status.NotSet)//The transaction was declined
            {
                strResponseMessage = "No Transactions found for settlement";
            }
            return strResponseMessage;
        }
        private string ProcessBankcardCaptureResponse(ref ResponseDetails _Response)
        {
            BankcardCaptureResponse _BCResponse = new BankcardCaptureResponse();
            _BCResponse = (BankcardCaptureResponse)_Response.Response;

            string strResponseMessage = "";

            if (!_Response.Verbose)
            {// In this case don't present to the user all of the data.
                if (_BCResponse.Status == Status.Successful)//The transaction was approved
                {//NOTE : Please reference the developers guide for a more complete explination of the return fields
                    //Note Highly recommended to save
                    if (_BCResponse.TransactionId != null) strResponseMessage = strResponseMessage + "\r\nTransactionId : " + _BCResponse.TransactionId;
                    strResponseMessage = strResponseMessage + "\r\nMerchant Profile Id : " + _Response.MerchantProfileId;
                    //Note Optional but recommended to save
                    if (_BCResponse.StatusCode != null) strResponseMessage = strResponseMessage + "\r\nStatus Code : " + _BCResponse.StatusCode;
                    if (_BCResponse.StatusMessage != null) strResponseMessage = strResponseMessage + "\r\nStatus Message : " + _BCResponse.StatusMessage;

                    strResponseMessage = "Your transaction was APPROVED\r\n" + strResponseMessage;
                }
                if (_BCResponse.Status == Status.Failure)//The transaction was declined
                {//NOTE : Please reference the developers guide for a more complete explination of the return fields
                    //Note Highly recommended to save
                    if (_BCResponse.TransactionId != null) strResponseMessage = strResponseMessage + "\r\nTransactionId : " + _BCResponse.TransactionId;
                    strResponseMessage = strResponseMessage + "\r\nMerchant Profile Id : " + _Response.MerchantProfileId;
                    //Note Optional but recommended to save
                    if (_BCResponse.StatusCode != null) strResponseMessage = strResponseMessage + "\r\nStatus Code : " + _BCResponse.StatusCode;
                    if (_BCResponse.StatusMessage != null) strResponseMessage = strResponseMessage + "\r\nStatus Message : " + _BCResponse.StatusMessage;

                    strResponseMessage = "Your transaction was DECLINED\r\n" + strResponseMessage;
                }
                return strResponseMessage;
            }
            if (_BCResponse.Status == Status.Successful)//The transaction was approved
            {//NOTE : Please reference the developers guide for a more complete explination of the return fields
                //Note Highly recommended to save
                if (_BCResponse.TransactionId != null) strResponseMessage = strResponseMessage + "\r\nTransactionId : " + _BCResponse.TransactionId;
                strResponseMessage = strResponseMessage + "\r\nMerchant Profile Id : " + _Response.MerchantProfileId;
                //Note Optional but recommended to save
                if (_BCResponse.StatusCode != null) strResponseMessage = strResponseMessage + "\r\nStatus Code : " + _BCResponse.StatusCode;
                if (_BCResponse.StatusMessage != null) strResponseMessage = strResponseMessage + "\r\nStatus Message : " + _BCResponse.StatusMessage;
                //Note Optional data about the batch
                if (_BCResponse.BatchId != null) strResponseMessage = strResponseMessage + "\r\nBatch Id : " + _BCResponse.BatchId;
                if (_BCResponse.PrepaidCard != PrepaidCard.NotSet) strResponseMessage = strResponseMessage + "\r\nPrepaidCard : " + _BCResponse.PrepaidCard; // Enumeration of NotSet, Yes, No.  Indicates if this is a pre-paid card
                if (_BCResponse.TransactionSummaryData != null)
                {
                    if (_BCResponse.TransactionSummaryData.CashBackTotals != null) strResponseMessage = strResponseMessage + "\r\nCash Back Totals \r\n  Count : " + _BCResponse.TransactionSummaryData.CashBackTotals.Count + "\r\n  Net Amount : " + _BCResponse.TransactionSummaryData.CashBackTotals.NetAmount;
                    if (_BCResponse.TransactionSummaryData.NetTotals != null)
                    {
                        strResponseMessage = strResponseMessage + "\r\nNet Totals \r\n  Count : " + _BCResponse.TransactionSummaryData.NetTotals.Count + "\r\n  Net Amount : " + _BCResponse.TransactionSummaryData.NetTotals.NetAmount;
                        //Set the amount reference
                        _Response.TxnAmount = _BCResponse.TransactionSummaryData.NetTotals.NetAmount;
                    }
                    if (_BCResponse.TransactionSummaryData.PINDebitReturnTotals != null) strResponseMessage = strResponseMessage + "\r\nPINDebit Return Totals \r\n  Count : " + _BCResponse.TransactionSummaryData.PINDebitReturnTotals.Count + "\r\n  Net Amount : " + _BCResponse.TransactionSummaryData.PINDebitReturnTotals.NetAmount;
                    if (_BCResponse.TransactionSummaryData.PINDebitSaleTotals != null) strResponseMessage = strResponseMessage + "\r\nPINDebit Sale Totals \r\n  Count : " + _BCResponse.TransactionSummaryData.PINDebitSaleTotals.Count + "\r\n  Net Amount : " + _BCResponse.TransactionSummaryData.PINDebitSaleTotals.NetAmount;
                    if (_BCResponse.TransactionSummaryData.ReturnTotals != null) strResponseMessage = strResponseMessage + "\r\nReturn Totals \r\n  Count : " + _BCResponse.TransactionSummaryData.ReturnTotals.Count + "\r\n  Net Amount : " + _BCResponse.TransactionSummaryData.ReturnTotals.NetAmount;
                    if (_BCResponse.TransactionSummaryData.SaleTotals != null) strResponseMessage = strResponseMessage + "\r\nSale Totals \r\n  Count : " + _BCResponse.TransactionSummaryData.SaleTotals.Count + "\r\n  Net Amount : " + _BCResponse.TransactionSummaryData.SaleTotals.NetAmount;
                    if (_BCResponse.TransactionSummaryData.VoidTotals != null) strResponseMessage = strResponseMessage + "\r\nVoid Totals \r\n  Count : " + _BCResponse.TransactionSummaryData.VoidTotals.Count + "\r\n  Net Amount : " + _BCResponse.TransactionSummaryData.VoidTotals.NetAmount;
                }
                strResponseMessage = "Your transaction was APPROVED\r\n" + strResponseMessage;
            }
            if (_BCResponse.Status == Status.Failure)//The transaction was declined
            {//NOTE : Please reference the developers guide for a more complete explination of the return fields
                //Note Highly recommended to save
                if (_BCResponse.TransactionId != null) strResponseMessage = strResponseMessage + "\r\nTransactionId : " + _BCResponse.TransactionId;
                strResponseMessage = strResponseMessage + "\r\nMerchant Profile Id : " + _Response.MerchantProfileId;
                //Note Optional but recommended to save
                if (_BCResponse.StatusCode != null) strResponseMessage = strResponseMessage + "\r\nStatus Code : " + _BCResponse.StatusCode;
                if (_BCResponse.StatusMessage != null) strResponseMessage = strResponseMessage + "\r\nStatus Message : " + _BCResponse.StatusMessage;
                //Note Optional

                strResponseMessage = "Your transaction was DECLINED\r\n" + strResponseMessage;
            }
            if (_BCResponse.Status == Status.NotSet)//The transaction was declined
            {
                strResponseMessage = "No Transactions found for settlement";
            }
            return strResponseMessage;
        }
        public void RequestTransaction(schemas.ipcommerce.com.Ipc.General.WCF.Contracts.Common.External.Txn.TransactionTenderData _transactionTenderData)
        {
            //The RequestTransaction() operation allows for the retrieval of any transaction matching the supplied tender data. This is useful in situations
             //when the application does not receive a response from CWS indicating the TransactionState.

            List<Response> _Response = new List<Response>();
            CheckTokenExpire();//Make sure the current token is valid
            _Response = Cwsbc.RequestTransaction(_sessionToken, _merchantProfileId, _transactionTenderData);

            if (_Response != null)
            {
                foreach (Response r in _Response)
                {
                    ResponseDetails RDN = new ResponseDetails(0.00M, r, "", "", _merchantProfileId, true, TypeCardType.NotSet, "");
                    MessageBox.Show(ProcessResponse(ref RDN));//Pass as reference so we can extract more values from the response
                }
            }
        }
        public List<ResponseDetails> ProcessSVATransaction(
                         TransactionType _TT //Required
            , StoredValueTransaction _SVAtransaction //Conditional : Only used for an AuthorizeAndCapture, Authorize and ReturnUnlinked. Otherwise null
            , StoredValueManage _SVManage // Conditional : Only used to manage. Otherwise null
            , StoredValueCapture _SVDifferenceData //Conditional : Only used for a Capture. Otherwise null
            , StoredValueReturn _SVRDifferenceData //Conditional : Only used for a ReturnById. Otherwise null
            , Undo _UDifferenceData //Conditional : Only used for an Undo. Otherwise null
            , bool _SendAcknowledge)
        {
            List<Response> _Response = new List<Response>();
            try
            {
                CheckTokenExpire();//Make sure the current token is valid

                //if (_TT == TransactionType.AuthorizeAndCapture)
                if (_TT == TransactionType.Authorize)
                {
                    _Response.Add(Cwsbc.Authorize(_sessionToken, _SVAtransaction, _applicationProfileId, _merchantProfileId, _serviceId));
                    //Always Verify that the requested amount and approved amount are the same.
                    StoredValueTransactionResponse SVR = new StoredValueTransactionResponse();
                    SVR = (StoredValueTransactionResponse)_Response[0];
                    if (_SVAtransaction.TransactionData.Amount != SVR.Amount)
                        MessageBox.Show("The transaction was approved for " + SVR.Amount
                            + " which is an amount not equal to than the requested amount of " + _SVAtransaction.TransactionData.Amount
                            + ". Please provide alternate payment to complete transaction");
                }
                if (_TT == TransactionType.ManageAccountById)
                    _Response.Add(Cwsbc.ManageAccountById(_sessionToken, _SVManage, _applicationProfileId, _serviceId));
                if (_TT == TransactionType.ManageAccount)
                    _Response.Add(Cwsbc.ManageAccount(_sessionToken, _SVAtransaction, _applicationProfileId, _merchantProfileId, _serviceId));
                if (_TT == TransactionType.Capture)
                    _Response.Add(Cwsbc.Capture(_sessionToken, _SVDifferenceData, _applicationProfileId, _serviceId));
                if (_TT == TransactionType.ReturnById)
                    _Response.Add(Cwsbc.ReturnById(_sessionToken, _SVRDifferenceData, _applicationProfileId, _serviceId));
                if (_TT == TransactionType.Return)
                    _Response.Add(Cwsbc.ReturnUnlinked(_sessionToken, _SVAtransaction, _applicationProfileId, _merchantProfileId, _serviceId));
                if (_TT == TransactionType.Undo)
                    _Response.Add(Cwsbc.Undo(_sessionToken, _UDifferenceData, _applicationProfileId, _serviceId));
                if (_TT == TransactionType.QueryAccount)
                    _Response.Add(Cwsbc.QueryAccount(_sessionToken, _SVAtransaction, _applicationProfileId, _merchantProfileId, _serviceId));

                List<ResponseDetails> RD = new List<ResponseDetails>();//Convert the response to response details so that we can report on the UI
                if (_Response != null)
                {
                    foreach (Response r in _Response)
                    {
                        if (_SendAcknowledge && r.TransactionId.Length > 0)
                            Cwsbc.Acknowledge(_sessionToken, r.TransactionId, _applicationProfileId, _serviceId);

                        ResponseDetails RDN = new ResponseDetails(0.00M, r, _TT.ToString(), _serviceId, _merchantProfileId, true, TypeCardType.NotSet, "");
                        MessageBox.Show(ProcessResponse(ref RDN));//Pass as reference so we can extract more values from the response
                        RD.Add(RDN);
                    }
                }

                return RD;
            }
            catch (EndpointNotFoundException)
            {
                //In this case the SvcEndpoint was not available. Try the same logic again with the alternate Endpoint
                try
                {
                    SetTxnEndpoint();//Change the endpoint to use the backup.

                    //TODO : Add a copy of the code above once fully tested out.

                    return null;

                }
                catch (EndpointNotFoundException)
                {
                    MessageBox.Show("Neither the primary or secondary endpoints are available. Unable to process.");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Unable to AuthorizeAndCapture\r\nError Message : " + ex.Message, "AuthorizeAndCapture Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (System.TimeoutException te)
            {
                //A timeout has occured. Prompt the user if they'd like to query for the last transaction submitted
                if (_SVAtransaction != null)
                {
                    DialogResult Result;
                    Result = MessageBox.Show("A timeout has occured. Would you like to query 'RequestTransaction' to obtain transactions with the exact same TenderData? To avoid duplicate charges your code will need to reconcile transactions.",
                                "Request Transaction", MessageBoxButtons.YesNo);
                    if (Result == DialogResult.Yes)
                    {
                        RequestTransaction(_SVAtransaction.TenderData);
                    }
                    else { throw te; }
                }
                else { throw te; }
            }
            catch (Exception ex)
            {
                string strErrorId;
                string strErrorMessage;
                if (_FaultHandler.handleTxnFault(ex, out strErrorId, out strErrorMessage))
                { MessageBox.Show(strErrorId + " : " + strErrorMessage); }
                else { MessageBox.Show(ex.Message); }
            }

            return null;
        }
        public string ProcessResponse(ref ResponseDetails _Response)
        {
            if (_Response.Response is BankcardTransactionResponsePro)
            {//In the 1.17.11 release all response objects are BankcardTransactionResponsePro
                return ProcessBankcardTransactionResponsePro(ref _Response);
            }
            if (_Response.Response is BankcardTransactionResponse)
            {//Future functionality as a BankcardTransactionResponse is presently not returned
            }
            if (_Response.Response is BankcardCaptureResponse)
            {//BankcardCaptureResponse
                return ProcessBankcardCaptureResponse(ref _Response);
            }
            if (_Response.Response is ElectronicCheckingTransactionResponse)
            {
                return ProcessElectronicCheckingTransactionResponse(ref _Response);
            }
            if (_Response.Response is ElectronicCheckingCaptureResponse)
            {
                return ProcessElectronicCheckingCaptureResponse(ref _Response);
            }
            if (_Response.Response is StoredValueTransactionResponse)
            {
                return ProcessStoredValueTransactionResponse(ref _Response);
            }

            return "";
        }