public List<ResponseDetails> ProcessBCPTransactionPro(
            TransactionType _TT //Required
            , BankcardTransactionPro _BCtransaction //Conditional : Only used for an AuthorizeAndCapture, Authorize and ReturnUnlinked. Otherwise null
            , BankcardCapturePro _BCDifferenceData //Conditional : Only used for a Capture. Otherwise null
            , List<String> _BatchIds //Conditional : A list of one or more batch Ids to capture.
            , BankcardReturn _RDifferenceData //Conditional : Only used for a ReturnById. Otherwise null
            , Adjust _ADifferenceData //Conditional : Only used for an Adjust. Otherwise null
            , BankcardUndo _UDifferenceData //Conditional : Only used for an Undo. Otherwise null
            , List<string> _TransactionIds //Conditional : Only used for a CaptureSelective. Otherwise null
            , List<Capture> _CaptureDifferenceData //Conditional : Only used for CaptureAll and CaptureSelective. Otherwise null
            , bool _SendAcknowledge
            , bool _UseWorkflowId)
        {
            List<Response> _Response = new List<Response>();
            try
            {
                CheckTokenExpire();//Make sure the current token is valid

                string _serviceIdOrWorkflowId = _serviceId;
                if (_UseWorkflowId)
                    _serviceIdOrWorkflowId = _workflowId;

                if (_TT == TransactionType.AuthorizeAndCapture)
                {
                    if (CredentialRequired())
                        _BCtransaction.Addendum = CredentialsRequired(_serviceId, _credUserName, _credPassword);
                    _Response.Add(Cwsbc.AuthorizeAndCapture(_sessionToken, _BCtransaction, _applicationProfileId, _merchantProfileId, _serviceIdOrWorkflowId));
                    //Always Verify that the requested amount and approved amount are the same.
                    BankcardTransactionResponsePro BCR = new BankcardTransactionResponsePro();
                    BCR = (BankcardTransactionResponsePro)_Response[0];
                    if (_BCtransaction.TransactionData.Amount != BCR.Amount)
                        MessageBox.Show("The transaction was approved for " + BCR.Amount
                            + " which is an amount not equal to the requested amount of " + _BCtransaction.TransactionData.Amount
                            + ". Please provide alternate payment to complete transaction");
                }

                if (_TT == TransactionType.Authorize)
                {
                    if (CredentialRequired())
                        _BCtransaction.Addendum = CredentialsRequired(_serviceId, _credUserName, _credPassword);
                    _Response.Add(Cwsbc.Authorize(_sessionToken, _BCtransaction, _applicationProfileId, _merchantProfileId, _serviceIdOrWorkflowId));
                    //Always Verify that the requested amount and approved amount are the same.
                    BankcardTransactionResponsePro BCR = new BankcardTransactionResponsePro();
                    BCR = (BankcardTransactionResponsePro)_Response[0];
                    if (_BCtransaction.TransactionData.Amount != BCR.Amount)
                        MessageBox.Show("The transaction was approved for " + BCR.Amount
                            + " which is an amount not equal to than the requested amount of " + _BCtransaction.TransactionData.Amount
                            + ". Please provide alternate payment to complete transaction");
                }
                if (_TT == TransactionType.Capture)
                {
                    if (CredentialRequired())
                        _BCDifferenceData.Addendum = CredentialsRequired(_serviceId, _credUserName, _credPassword);
                    _Response.Add(Cwsbc.Capture(_sessionToken, _BCDifferenceData, _applicationProfileId, _serviceId));
                }
                if (_TT == TransactionType.CaptureAll)
                {
                    if (CredentialRequired())
                        _BCDifferenceData.Addendum = CredentialsRequired(_serviceId, _credUserName, _credPassword);
                    _Response = Cwsbc.CaptureAll(_sessionToken, _CaptureDifferenceData, _BatchIds, _applicationProfileId,
                                                 _merchantProfileId, _serviceId);
                }
                if (_TT == TransactionType.CaptureAllAsync)
                {
                    if (CredentialRequired())
                        _BCDifferenceData.Addendum = CredentialsRequired(_serviceId, _credUserName, _credPassword);
                    _Response.Add(Cwsbc.CaptureAllAsync(_sessionToken, _CaptureDifferenceData, _BatchIds,
                                                        _applicationProfileId, _merchantProfileId, _serviceId));
                }
                if (_TT == TransactionType.CaptureSelective)
                {
                    if (CredentialRequired())
                        _BCDifferenceData.Addendum = CredentialsRequired(_serviceId, _credUserName, _credPassword);
                    _Response = Cwsbc.CaptureSelective(_sessionToken, _TransactionIds, _CaptureDifferenceData,
                                                       _applicationProfileId, _serviceId);
                }
                if (_TT == TransactionType.CaptureSelectiveAsync)
                {
                    if (CredentialRequired())
                        _BCDifferenceData.Addendum = CredentialsRequired(_serviceId, _credUserName, _credPassword);
                    _Response.Add(Cwsbc.CaptureSelectiveAsync(_sessionToken, _TransactionIds, _CaptureDifferenceData,
                                                              _applicationProfileId, _serviceId));
                }
                if (_TT == TransactionType.ReturnById)
                {
                    if (CredentialRequired())
                        _RDifferenceData.Addendum = CredentialsRequired(_serviceId, _credUserName, _credPassword);
                    _Response.Add(Cwsbc.ReturnById(_sessionToken, _RDifferenceData, _applicationProfileId, _serviceId));
                }
                if (_TT == TransactionType.Return)
                {
                    if (CredentialRequired())
                        _BCtransaction.Addendum = CredentialsRequired(_serviceId, _credUserName, _credPassword);
                    _Response.Add(Cwsbc.ReturnUnlinked(_sessionToken, _BCtransaction, _applicationProfileId, _merchantProfileId, _serviceId));
                }
                if (_TT == TransactionType.Adjust)
                {
                    if (CredentialRequired())
                        _ADifferenceData.Addendum = CredentialsRequired(_serviceId, _credUserName, _credPassword);
                    _Response.Add(Cwsbc.Adjust(_sessionToken, _ADifferenceData, _applicationProfileId, _serviceId));
                }
                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())
                        _BCtransaction.Addendum = CredentialsRequired(_serviceId, _credUserName, _credPassword);
                    _Response.Add(Cwsbc.QueryAccount(_sessionToken, _BCtransaction, _applicationProfileId,
                                                     _merchantProfileId, _serviceId));
                }
                if (_TT == TransactionType.Verify)
                    _Response.Add(Cwsbc.Verify(_sessionToken, _BCtransaction, _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(), _serviceIdOrWorkflowId, _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(_BCtransaction != 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(_BCtransaction.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;
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            #region Preparing the Application to Transact

            #region Setup Clients

            // setup service information client from service reference generated code
            var svcClient = new CWSServiceInformationClient();

            // setup transaction client from service reference generated code
            var txnClient = new CwsTransactionProcessingClient(new BasicHttpsBinding(),
                                                               new EndpointAddress("https://api.cert.nabcommerce.com/2.0.18/Txn"));

            #endregion

            #region SignOnWithToken

            // test identity token for global host capture
            string identityToken = "PHNhbWw6QXNzZXJ0aW9uIE1ham9yVmVyc2lvbj0iMSIgTWlub3JWZXJzaW9uPSIxIiB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odW1icHJpbnRTSEExIj5ZREJlRFNGM0Z4R2dmd3pSLzBwck11OTZoQ2M9PC9vOktleUlkZW50aWZpZXI+PC9vOlNlY3VyaXR5VG9rZW5SZWZlcmVuY2U+PC9LZXlJbmZvPjwvU2lnbmF0dXJlPjwvc2FtbDpBc3NlcnRpb24+";

            string sessionToken = svcClient.SignOnWithToken(identityToken);

            #endregion

            #region SaveApplicationData

            var applicationData = new ApplicationData()
            {
                ApplicationAttended = false,
                ApplicationLocation = NabVelocity.Svc.ApplicationLocation.OffPremises,
                ApplicationName     = "MyTestApp",
                EncryptionType      = NabVelocity.Svc.EncryptionType.NotSet,
                HardwareType        = NabVelocity.Svc.HardwareType.PC,
                PINCapability       = NabVelocity.Svc.PINCapability.PINNotSupported,
                PTLSSocketId        = "MIIFCzCCA/OgAwIBAgICAoEwDQYJKoZIhvcNAQEFBQAwgbExNDAyBgNVBAMTK0lQIFBheW1lbnRzIEZyYW1ld29yayBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkxCzAJBgNVBAYTAlVTMREwDwYDVQQIEwhDb2xvcmFkbzEPMA0GA1UEBxMGRGVudmVyMRowGAYDVQQKExFJUCBDb21tZXJjZSwgSW5jLjEsMCoGCSqGSIb3DQEJARYdYWRtaW5AaXBwYXltZW50c2ZyYW1ld29yay5jb20wHhcNMTMwODI2MTcxMDI3WhcNMjMwODI0MTcxMDI3WjCBjDELMAkGA1UEBhMCVVMxETAPBgNVBAgTCENvbG9yYWRvMQ8wDQYDVQQHEwZEZW52ZXIxGjAYBgNVBAoTEUlQIENvbW1lcmNlLCBJbmMuMT0wOwYDVQQDEzR0ZHNwM25TZ0FJQUFBUDhBSCtDWUFBQUVBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUE9MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtn6ILI78EaOLcWrmI9RZf8Vj+3P/WcrDLimSyJJH/8LnIBbXNkiKcZSMg/KHqNLAtq/ncYqZcicgAfa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ik0UQ+YQNM=",
                ReadCapability      = NabVelocity.Svc.ReadCapability.KeyOnly,
                SerialNumber        = "208093707",
                SoftwareVersion     = "1.0",
                SoftwareVersionDate = new DateTime(2014, 12, 4),
            };

            string applicationProfileId = "";

            try
            {
                // an application identified is returned and passed in on every transaction
                applicationProfileId = svcClient.SaveApplicationData(sessionToken, applicationData);
            }
            catch (FaultException <NabVelocity.Svc.CWSValidationResultFault> ex)
            {
                foreach (var validationError in ex.Detail.Errors)
                {
                    Console.WriteLine(string.Format("Validatior error: {0} - {1}",
                                                    validationError.RuleLocationKey, validationError.RuleMessage));
                }
            }

            #endregion

            #region GetApplicationData

            ApplicationData appData = svcClient.GetApplicationData(sessionToken, applicationProfileId);

            #endregion

            #region GetServiceInformation

            ServiceInformation serviceInfo = svcClient.GetServiceInformation(sessionToken);
            string             serviceId   = "";

            bool imageTransactions = true;
            if (serviceInfo.ElectronicCheckingServices.Count() > 0)
            {
                if (serviceInfo.ElectronicCheckingServices.First().ServiceName.Contains("GETI"))
                {
                    imageTransactions = true;
                }

                serviceId = serviceInfo.ElectronicCheckingServices.First().ServiceId;
            }

            bool serviceIsHostCapture = false;
            bool serviceIsTermCapture = false;

            if (serviceInfo.BankcardServices.Count() > 0)
            {
                BankcardService service = serviceInfo.BankcardServices.First();
                //// the serviceId represents the payment processor (global, firstdata, chase, etc.)
                serviceId = service.ServiceId;
                // if Capture is supported, the service is host capture
                serviceIsHostCapture = service.Operations.Capture;
                // if CaptureAll is supprted, the service is terminal capture
                serviceIsTermCapture = service.Operations.CaptureAll;
            }
            #endregion

            #region SaveMerchantProfiles

            string merchantProfileId = "Joe's Online Crab Shack";
            var    merchantProfile   = new MerchantProfile()
            {
                ProfileId    = merchantProfileId,
                ServiceId    = serviceId,
                MerchantData = new MerchantProfileMerchantData()
                {
                    MerchantId           = "689035621266620",
                    Name                 = "Joe's Online Crab Shack",
                    Phone                = "(555) 555-5555",
                    CustomerServicePhone = "(555) 555-5555",
                    Address              = new NabVelocity.Svc.AddressInfo()
                    {
                        Street1    = "100 Rampart Lane",
                        City       = "Denver",
                        PostalCode = "80220",
                    },
                    BankcardMerchantData = new BankcardMerchantData()
                    {
                        IndustryType = NabVelocity.Svc.IndustryType.Ecommerce,
                        AgentBank    = "000000",
                    },
                },
            };

            try
            {
                // merchant profiles follow the processor, so always use the serviceId (not the workflowId)
                svcClient.SaveMerchantProfiles(sessionToken, serviceId, TenderType.Credit,
                                               new MerchantProfile[] { merchantProfile });
            }
            catch (FaultException <NabVelocity.Svc.CWSValidationResultFault> ex)
            {
                foreach (var validationError in ex.Detail.Errors)
                {
                    Console.WriteLine(string.Format("Validatior error: {0} - {1}",
                                                    validationError.RuleLocationKey, validationError.RuleMessage));
                }
            }

            #endregion

            #region GetMerchantProfiles

            MerchantProfile[] merchantProfiles = svcClient.GetMerchantProfiles(sessionToken, serviceId, TenderType.Credit);

            #endregion

            #endregion

            #region Transacting

            if (serviceInfo.ElectronicCheckingServices.Count() > 0)
            {
                string filePathName   = @"..\..\..\tifBackSample.tif";
                byte[] rawImgData     = File.ReadAllBytes(filePathName);
                char[] base64CharData = new char[getB64Length(rawImgData.Length)];
                Convert.ToBase64CharArray(rawImgData, 0, rawImgData.Length, base64CharData, 0);
                byte[] backImageData = Encoding.ASCII.GetBytes(base64CharData);

                filePathName   = @"..\..\..\tifFrontSample.tif";
                rawImgData     = File.ReadAllBytes(filePathName);
                base64CharData = new char[getB64Length(rawImgData.Length)];
                Convert.ToBase64CharArray(rawImgData, 0, rawImgData.Length, base64CharData, 0);
                byte[] frontImageData = Encoding.ASCII.GetBytes(base64CharData);

                var debitRequest = new ElectronicCheckingTransaction
                {
                    CustomerData = new ElectronicCheckingCustomerData()
                    {
                        BillingData = new CustomerInfo()
                        {
                            Address = new NabVelocity.Txn.AddressInfo()
                            {
                                Street1       = "123 N Central",
                                City          = "Thornton",
                                PostalCode    = "12345",
                                StateProvince = "CO",
                                CountryCode   = NabVelocity.Txn.TypeISOCountryCodeA3.USA
                            },
                            Name = new NameInfo
                            {
                                First = "Bob",
                                Last  = "Dillan",
                            },
                            Phone = "3213211234"
                        },
                    },
                    TenderData = new ElectronicCheckingTenderData
                    {
                        CheckData = new CheckData
                        {
                            AccountNumber    = "12345678",
                            RoutingNumber    = "490000018",
                            CheckCountryCode = CheckCountryCode.US,
                            CheckNumber      = "1234",
                            OwnerType        = OwnerType.Personal,
                            UseType          = UseType.Checking,
                            RawMICRLine      = "toad"
                        },
                        SocketLocation = new SocketLocation
                        {
                            SocketCity  = "Denver",
                            SocketState = "CO"
                        },
                        BackCheckImage = new CheckImage
                        {
                            CompressionType = ImgCompressionType.Group_4,
                            DocType         = DocType.Check,
                            FormatType      = ImgFormatType.TIFF_6,
                            ImgData         = backImageData,
                            ImgSize         = backImageData.Length,
                        },
                        FrontCheckImage = new CheckImage
                        {
                            CompressionType = ImgCompressionType.Group_4,
                            DocType         = DocType.Check,
                            FormatType      = ImgFormatType.TIFF_6,
                            ImgData         = frontImageData,
                            ImgSize         = frontImageData.Length,
                        }
                    },
                    TransactionData = new ElectronicCheckingTransactionData
                    {
                        Amount          = 25.00m,
                        SECCode         = SECCode.POP,
                        TransactionType = TransactionType.Debit,
                        CurrencyCode    = NabVelocity.Txn.TypeISOCurrencyCodeA3.USD,
                        EffectiveDate   = DateTime.Now,
                        IsRecurring     = false,
                        PayeeId         = "Some Data",
                        ServiceType     = ServiceType.ACH,
                        TxnCodeType     = TxnCodeType.Conversion,
                    }
                };

                try
                {
                    var debitResponse =
                        (ElectronicCheckingTransactionResponse)
                        txnClient.Authorize(sessionToken, debitRequest, applicationProfileId, merchantProfileId, serviceId);

                    Console.WriteLine("(Debit) Status: " + debitResponse.Status + "\r\n");
                }
                catch (FaultException <NabVelocity.Txn.CWSValidationResultFault> ex)
                {
                    foreach (var validationError in ex.Detail.Errors)
                    {
                        Console.WriteLine(string.Format("Validatior error: {0} - {1}", validationError.RuleLocationKey,
                                                        validationError.RuleMessage));
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            if (serviceIsHostCapture)
            {
                #region Host Capture workflow

                try
                {
                    #region Verify

                    var verifyRequest = new BankcardTransaction()
                    {
                        TenderData = new BankcardTenderData()
                        {
                            CardData = new CardData()
                            {
                                CardType = TypeCardType.Visa,
                                PAN      = "5100000000000016",
                                Expire   = "1215",
                            },
                            CardSecurityData = new CardSecurityData()
                            {
                                AVSData = new AVSData()
                                {
                                    Street        = "123 Rain Road",
                                    City          = "Aurora",
                                    StateProvince = "CO",
                                    PostalCode    = "80080",
                                },
                                CVData         = "383",
                                CVDataProvided = CVDataProvided.Provided,
                            },
                        },
                        TransactionData = new BankcardTransactionData()
                        {
                            Amount       = 0.00M,
                            EntryMode    = NabVelocity.Txn.EntryMode.Keyed,
                            IndustryType = NabVelocity.Txn.IndustryType.Ecommerce,
                        },
                        CustomerData = new TransactionCustomerData()
                        {
                        }
                    };

                    var verifyResponse = (BankcardTransactionResponse)txnClient.Verify(sessionToken, verifyRequest,
                                                                                       applicationProfileId, merchantProfileId, serviceId);

                    Console.WriteLine("(Verify) Status: " + verifyResponse.Status + "\r\n"
                                      + "CV Result: " + verifyResponse.CVResult + "\r\n"
                                      + "AVS Postal Result: " + verifyResponse.AVSResult.PostalCodeResult + "\r\n");

                    #endregion

                    #region Authorize

                    var authRequest = new BankcardTransaction()
                    {
                        TenderData = new BankcardTenderData()
                        {
                            CardData = new CardData()
                            {
                                CardType = TypeCardType.Visa,
                                PAN      = "5100000000000016",
                                Expire   = "1215",
                            },
                            CardSecurityData = new CardSecurityData()
                            {
                                AVSData = new AVSData()
                                {
                                    Street        = "123 Rain Road",
                                    City          = "Aurora",
                                    StateProvince = "CO",
                                    PostalCode    = "80080",
                                },
                                CVData         = "383",
                                CVDataProvided = CVDataProvided.Provided,
                            },
                        },
                        TransactionData = new BankcardTransactionData()
                        {
                            CurrencyCode = NabVelocity.Txn.TypeISOCurrencyCodeA3.USD,
                            OrderNumber  = "123456",
                            Amount       = 15.00M,
                            EntryMode    = NabVelocity.Txn.EntryMode.Keyed,
                            IndustryType = NabVelocity.Txn.IndustryType.Ecommerce,
                        },
                    };

                    var authResponse = (BankcardTransactionResponse)txnClient.Authorize(sessionToken, authRequest,
                                                                                        applicationProfileId, merchantProfileId, serviceId);

                    Console.WriteLine("(Authorize) Status: " + authResponse.Status + "\r\n"
                                      + "Amount: " + authResponse.Amount + "\r\n"
                                      + "ApprovalCode: " + authResponse.ApprovalCode + "\r\n"
                                      + "TransactionId: " + authResponse.TransactionId + "\r\n");

                    #endregion

                    #region Capture

                    var captureDifferenceData = new BankcardCapture()
                    {
                        TransactionId = authResponse.TransactionId,
                        Amount        = authResponse.Amount + 1.00M,
                    };

                    var captureResponse = (BankcardCaptureResponse)txnClient.Capture(sessionToken, captureDifferenceData,
                                                                                     applicationProfileId, serviceId);

                    Console.WriteLine("(Capture) Status: " + captureResponse.Status + "\r\n"
                                      + "Amount: " + captureResponse.TransactionSummaryData.NetTotals.NetAmount + "\r\n"
                                      + "TransactionId: " + captureResponse.TransactionId + "\r\n");

                    #endregion

                    #region AuthAndCapture

                    var authAndCaptureRequest = new BankcardTransaction()
                    {
                        TenderData = new BankcardTenderData()
                        {
                            CardData = new CardData()
                            {
                                CardType = TypeCardType.Visa,
                                PAN      = "5100000000000016",
                                Expire   = "1215",
                            },
                            CardSecurityData = new CardSecurityData()
                            {
                                AVSData = new AVSData()
                                {
                                    Street        = "123 Rain Road",
                                    City          = "Aurora",
                                    StateProvince = "CO",
                                    PostalCode    = "80080",
                                },
                                CVData         = "383",
                                CVDataProvided = CVDataProvided.Provided,
                            },
                        },
                        TransactionData = new BankcardTransactionData()
                        {
                            CurrencyCode = NabVelocity.Txn.TypeISOCurrencyCodeA3.USD,
                            OrderNumber  = "123456",
                            Amount       = 15.00M,
                            EntryMode    = NabVelocity.Txn.EntryMode.Keyed,
                            IndustryType = NabVelocity.Txn.IndustryType.Ecommerce,
                        },
                    };

                    var authAndCapResponse = (BankcardTransactionResponse)txnClient.AuthorizeAndCapture(sessionToken, authAndCaptureRequest,
                                                                                                        applicationProfileId, merchantProfileId, serviceId);

                    Console.WriteLine("(AuthAndCapture) Status: " + authAndCapResponse.Status + "\r\n"
                                      + "Amount: " + authAndCapResponse.Amount + "\r\n"
                                      + "ApprovalCode: " + authAndCapResponse.ApprovalCode + "\r\n"
                                      + "TransactionId: " + authAndCapResponse.TransactionId + "\r\n");

                    #endregion

                    #region ReturnById

                    var returnByIdRequest = new BankcardReturn()
                    {
                        TransactionId       = authAndCapResponse.TransactionId,
                        TransactionDateTime = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fffzzz"),
                    };

                    var returnByIdResponse = (BankcardTransactionResponse)txnClient.ReturnById(sessionToken, returnByIdRequest,
                                                                                               applicationProfileId, serviceId);

                    Console.WriteLine("(ReturnById) Status: " + returnByIdResponse.Status + "\r\n"
                                      + "Amount: " + returnByIdResponse.Amount + "\r\n"
                                      + "ApprovalCode: " + returnByIdResponse.ApprovalCode + "\r\n"
                                      + "TransactionId: " + returnByIdResponse.TransactionId + "\r\n");

                    #endregion

                    #region ReturnUnlinked

                    var returnRequest = new BankcardTransaction()
                    {
                        TenderData = new BankcardTenderData()
                        {
                            CardData = new CardData()
                            {
                                CardType = TypeCardType.Visa,
                                PAN      = "5100000000000016",
                                Expire   = "1215",
                            },
                        },
                        TransactionData = new BankcardTransactionData()
                        {
                            CurrencyCode = NabVelocity.Txn.TypeISOCurrencyCodeA3.USD,
                            OrderNumber  = "123456",
                            Amount       = 15.00M,
                            EntryMode    = NabVelocity.Txn.EntryMode.Keyed,
                            IndustryType = NabVelocity.Txn.IndustryType.Ecommerce,
                        },
                    };

                    var returnUnlinkedResponse = (BankcardTransactionResponse)txnClient.ReturnUnlinked(sessionToken, returnRequest,
                                                                                                       applicationProfileId, merchantProfileId, serviceId);

                    Console.WriteLine("(ReturnUnlinked) Status: " + returnUnlinkedResponse.Status + "\r\n"
                                      + "Amount: " + returnUnlinkedResponse.Amount + "\r\n"
                                      + "ApprovalCode: " + returnUnlinkedResponse.ApprovalCode + "\r\n"
                                      + "TransactionId: " + returnUnlinkedResponse.TransactionId + "\r\n");

                    #endregion

                    #region Tokenized Transactions

                    // build a transaction
                    var tokenizedRequest = new BankcardTransaction()
                    {
                        TenderData = new BankcardTenderData()
                        {
                            // we only need to use a token in the tender data now
                            PaymentAccountDataToken = verifyResponse.PaymentAccountDataToken
                        },
                        TransactionData = new BankcardTransactionData()
                        {
                            CurrencyCode = NabVelocity.Txn.TypeISOCurrencyCodeA3.USD,
                            OrderNumber  = "123456",
                            Amount       = 15.00M,
                            EntryMode    = NabVelocity.Txn.EntryMode.Keyed,
                            IndustryType = NabVelocity.Txn.IndustryType.Ecommerce,
                        },
                    };

                    authResponse = (BankcardTransactionResponse)txnClient.Authorize(sessionToken, tokenizedRequest,
                                                                                    applicationProfileId, merchantProfileId, serviceId);
                    authAndCapResponse = (BankcardTransactionResponse)txnClient.AuthorizeAndCapture(sessionToken, tokenizedRequest,
                                                                                                    applicationProfileId, merchantProfileId, serviceId);
                    returnUnlinkedResponse = (BankcardTransactionResponse)txnClient.ReturnUnlinked(sessionToken, tokenizedRequest,
                                                                                                   applicationProfileId, merchantProfileId, serviceId);

                    #endregion

                    #region Adjust

                    var adjustReq = new Adjust()
                    {
                        Amount        = 1.00M,
                        TransactionId = authAndCapResponse.TransactionId,
                    };

                    Response adjustResponse = txnClient.Adjust(sessionToken, adjustReq, applicationProfileId, serviceId);

                    Console.WriteLine("(Adjust) Status: " + adjustResponse.Status + "\r\n"
                                      + "StatusMessage: " + adjustResponse.StatusMessage + "\r\n"
                                      + "TransactionId: " + adjustResponse.TransactionId + "\r\n");

                    #endregion

                    #region Undo

                    var undoRequest = new BankcardUndo()
                    {
                        TransactionId = authResponse.TransactionId,
                    };

                    Response undoResponse = txnClient.Undo(sessionToken, undoRequest, applicationProfileId, serviceId);

                    Console.WriteLine("(Undo) Status: " + undoResponse.Status + "\r\n"
                                      + "StatusMessage: " + undoResponse.StatusMessage + "\r\n"
                                      + "TransactionId: " + undoResponse.TransactionId + "\r\n");

                    #endregion
                }
                catch (FaultException <NabVelocity.Txn.CWSValidationResultFault> ex)
                {
                    foreach (var validationError in ex.Detail.Errors)
                    {
                        Console.WriteLine(string.Format("Validatior error: {0} - {1}",
                                                        validationError.RuleLocationKey, validationError.RuleMessage));
                    }
                }

                #endregion
            }

            if (serviceIsTermCapture)
            {
                #region Term Capture Workflow

                try
                {
                    #region Verify

                    var verifyRequest = new BankcardTransaction()
                    {
                        TenderData = new BankcardTenderData()
                        {
                            CardData = new CardData()
                            {
                                CardType = TypeCardType.Visa,
                                PAN      = "4111111111111111",
                                Expire   = "1215",
                            },
                            CardSecurityData = new CardSecurityData()
                            {
                                AVSData = new AVSData()
                                {
                                    Street        = "123 Rain Road",
                                    City          = "Aurora",
                                    StateProvince = "CO",
                                    PostalCode    = "80080",
                                },
                                CVData         = "123",
                                CVDataProvided = CVDataProvided.Provided,
                            },
                        },
                        TransactionData = new BankcardTransactionData()
                        {
                            Amount       = 0.00M,
                            EntryMode    = NabVelocity.Txn.EntryMode.Keyed,
                            IndustryType = NabVelocity.Txn.IndustryType.Ecommerce,
                        },
                        CustomerData = new TransactionCustomerData()
                        {
                        }
                    };

                    var verifyResponse = (BankcardTransactionResponse)txnClient.Verify(sessionToken, verifyRequest,
                                                                                       applicationProfileId, merchantProfileId, serviceId);

                    Console.WriteLine("(Verify) Status: " + verifyResponse.Status + "\r\n"
                                      + "CV Result: " + verifyResponse.CVResult + "\r\n"
                                      + "AVS Postal Result: " + verifyResponse.AVSResult.PostalCodeResult + "\r\n");

                    #endregion

                    #region Authorize

                    var authRequest = new BankcardTransaction()
                    {
                        TenderData = new BankcardTenderData()
                        {
                            CardData = new CardData()
                            {
                                CardType = TypeCardType.Visa,
                                PAN      = "4111111111111111",
                                Expire   = "1215",
                            },
                            CardSecurityData = new CardSecurityData()
                            {
                                AVSData = new AVSData()
                                {
                                    Street        = "123 Rain Road",
                                    City          = "Aurora",
                                    StateProvince = "CO",
                                    PostalCode    = "80080",
                                },
                                CVData         = "123",
                                CVDataProvided = CVDataProvided.Provided,
                            },
                        },
                        TransactionData = new BankcardTransactionData()
                        {
                            CurrencyCode = NabVelocity.Txn.TypeISOCurrencyCodeA3.USD,
                            OrderNumber  = "123456",
                            Amount       = 15.00M,
                            EntryMode    = NabVelocity.Txn.EntryMode.Keyed,
                            IndustryType = NabVelocity.Txn.IndustryType.Ecommerce,
                        },
                    };

                    var authResponse = (BankcardTransactionResponse)txnClient.Authorize(sessionToken, authRequest,
                                                                                        applicationProfileId, merchantProfileId, serviceId);

                    Console.WriteLine("(Authorize) Status: " + authResponse.Status + "\r\n"
                                      + "Amount: " + authResponse.Amount + "\r\n"
                                      + "ApprovalCode: " + authResponse.ApprovalCode + "\r\n"
                                      + "TransactionId: " + authResponse.TransactionId + "\r\n");

                    #endregion

                    #region Capture Selective

                    var captureSelectiveDifferenceData = new BankcardCapture()
                    {
                        TransactionId = authResponse.TransactionId,
                        Amount        = authResponse.Amount + 1.00M,
                    };

                    Response[] captureSelectiveResponses = txnClient.CaptureSelective(sessionToken, new[] { authResponse.TransactionId },
                                                                                      new[] { captureSelectiveDifferenceData }, applicationProfileId, serviceId);

                    foreach (var response in captureSelectiveResponses)
                    {
                        if (response.Status == Status.Failure)
                        {
                            Console.WriteLine("(Capture Selective) Status: " + response.Status + "\r\n"
                                              + "StatusMessage: " + response.StatusMessage + "\r\n"
                                              + "TransactionId: " + response.TransactionId + "\r\n");
                        }
                        else
                        {
                            var captureResponse = (BankcardCaptureResponse)response;

                            Console.WriteLine("(Capture Selective) Status: " + captureResponse.Status + "\r\n"
                                              + "Industry: " + captureResponse.IndustryType + "\r\n"
                                              + "Sales Count: " + captureResponse.TransactionSummaryData.SaleTotals.Count + "\r\n"
                                              + "Sales Amount: " + captureResponse.TransactionSummaryData.SaleTotals.NetAmount + "\r\n"
                                              + "Return Count: " + captureResponse.TransactionSummaryData.ReturnTotals.Count + "\r\n"
                                              + "Return Amount: " + captureResponse.TransactionSummaryData.ReturnTotals.NetAmount + "\r\n"
                                              + "TransactionId: " + captureResponse.TransactionId + "\r\n");
                        }
                    }

                    #endregion

                    #region ReturnById

                    var returnByIdRequest = new BankcardReturn()
                    {
                        TransactionId       = authResponse.TransactionId,
                        TransactionDateTime = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fffzzz"),
                    };

                    var returnByIdResponse = (BankcardTransactionResponse)txnClient.ReturnById(sessionToken, returnByIdRequest,
                                                                                               applicationProfileId, serviceId);

                    Console.WriteLine("(ReturnById) Status: " + returnByIdResponse.Status + "\r\n"
                                      + "Amount: " + returnByIdResponse.Amount + "\r\n"
                                      + "ApprovalCode: " + returnByIdResponse.ApprovalCode + "\r\n"
                                      + "TransactionId: " + returnByIdResponse.TransactionId + "\r\n");

                    #endregion

                    #region ReturnUnlinked

                    var returnRequest = new BankcardTransaction()
                    {
                        TenderData = new BankcardTenderData()
                        {
                            CardData = new CardData()
                            {
                                CardType = TypeCardType.Visa,
                                PAN      = "4111111111111111",
                                Expire   = "1215",
                            },
                        },
                        TransactionData = new BankcardTransactionData()
                        {
                            CurrencyCode = NabVelocity.Txn.TypeISOCurrencyCodeA3.USD,
                            OrderNumber  = "123456",
                            Amount       = 15.00M,
                            EntryMode    = NabVelocity.Txn.EntryMode.Keyed,
                            IndustryType = NabVelocity.Txn.IndustryType.Ecommerce,
                        },
                    };

                    var returnUnlinkedResponse = (BankcardTransactionResponse)txnClient.ReturnUnlinked(sessionToken, returnRequest,
                                                                                                       applicationProfileId, merchantProfileId, serviceId);

                    Console.WriteLine("(ReturnUnlinked) Status: " + returnUnlinkedResponse.Status + "\r\n"
                                      + "Amount: " + returnUnlinkedResponse.Amount + "\r\n"
                                      + "ApprovalCode: " + returnUnlinkedResponse.ApprovalCode + "\r\n"
                                      + "TransactionId: " + returnUnlinkedResponse.TransactionId + "\r\n");

                    #endregion

                    #region Tokenized Transactions

                    // build a transaction
                    var tokenizedRequest = new BankcardTransaction()
                    {
                        TenderData = new BankcardTenderData()
                        {
                            // we only need to use a token in the tender data now
                            PaymentAccountDataToken = verifyResponse.PaymentAccountDataToken
                        },
                        TransactionData = new BankcardTransactionData()
                        {
                            CurrencyCode = NabVelocity.Txn.TypeISOCurrencyCodeA3.USD,
                            OrderNumber  = "123456",
                            Amount       = 15.00M,
                            EntryMode    = NabVelocity.Txn.EntryMode.Keyed,
                            IndustryType = NabVelocity.Txn.IndustryType.Ecommerce,
                        },
                    };

                    authResponse = (BankcardTransactionResponse)txnClient.Authorize(sessionToken, tokenizedRequest,
                                                                                    applicationProfileId, merchantProfileId, serviceId);
                    returnUnlinkedResponse = (BankcardTransactionResponse)txnClient.ReturnUnlinked(sessionToken, tokenizedRequest,
                                                                                                   applicationProfileId, merchantProfileId, serviceId);

                    #endregion

                    #region Adjust

                    var adjustReq = new Adjust()
                    {
                        Amount        = 1.00M,
                        TransactionId = authResponse.TransactionId,
                    };

                    Response adjustResponse = txnClient.Adjust(sessionToken, adjustReq, applicationProfileId, serviceId);

                    Console.WriteLine("(Adjust) Status: " + adjustResponse.Status + "\r\n"
                                      + "StatusMessage: " + adjustResponse.StatusMessage + "\r\n"
                                      + "TransactionId: " + adjustResponse.TransactionId + "\r\n");

                    #endregion

                    #region Undo

                    var undoRequest = new BankcardUndo()
                    {
                        TransactionId = adjustResponse.TransactionId,
                    };

                    Response undoResponse = txnClient.Undo(sessionToken, undoRequest, applicationProfileId, serviceId);

                    Console.WriteLine("(Undo) Status: " + undoResponse.Status + "\r\n"
                                      + "StatusMessage: " + undoResponse.StatusMessage + "\r\n"
                                      + "TransactionId: " + undoResponse.TransactionId + "\r\n");

                    #endregion

                    #region Capture All

                    Response[] captureAllResponses = txnClient.CaptureAll(sessionToken, null,
                                                                          null, applicationProfileId, merchantProfileId, serviceId);

                    foreach (var response in captureAllResponses)
                    {
                        if (response.Status == Status.Failure)
                        {
                            Console.WriteLine("(Capture All) Status: " + response.Status + "\r\n"
                                              + "StatusMessage: " + response.StatusMessage + "\r\n"
                                              + "TransactionId: " + response.TransactionId + "\r\n");
                        }
                        else
                        {
                            var captureResponse = (BankcardCaptureResponse)response;

                            Console.WriteLine("(Capture All) Status: " + captureResponse.Status + "\r\n"
                                              + "Industry: " + captureResponse.IndustryType + "\r\n"
                                              + "Sales Count: " + captureResponse.TransactionSummaryData.SaleTotals.Count + "\r\n"
                                              + "Sales Amount: " + captureResponse.TransactionSummaryData.SaleTotals.NetAmount + "\r\n"
                                              + "Return Count: " + captureResponse.TransactionSummaryData.ReturnTotals.Count + "\r\n"
                                              + "Return Amount: " + captureResponse.TransactionSummaryData.ReturnTotals.NetAmount + "\r\n"
                                              + "TransactionId: " + captureResponse.TransactionId + "\r\n");
                        }
                    }

                    #endregion
                }
                catch (FaultException <NabVelocity.Txn.CWSValidationResultFault> ex)
                {
                    foreach (var validationError in ex.Detail.Errors)
                    {
                        Console.WriteLine(string.Format("Validatior error: {0} - {1}",
                                                        validationError.RuleLocationKey, validationError.RuleMessage));
                    }
                }

                #endregion
            }

            #endregion

            #region Querying for Transactions

            var tmsClient = new NabVelocity.Tms.TMSOperationsClient();

            var queryParams = new NabVelocity.Tms.QueryTransactionsParameters()
            {
                Amounts              = new[] { 16.00M },
                CardTypes            = new[] { NabVelocity.Tms.TypeCardType.Visa },
                CaptureStates        = new[] { NabVelocity.Tms.CaptureState.Captured },
                MerchantProfileIds   = new[] { "My Test App" },
                TransactionDateRange = new NabVelocity.Tms.DateRange()
                {
                    StartDateTime = DateTime.Now.AddDays(-2), EndDateTime = DateTime.Now
                },
                TransactionClassTypePairs = new[] {
                    new NabVelocity.Tms.TransactionClassTypePair()
                    {
                        TransactionClass = "BCP", TransactionType = "AUTH"
                    }
                },
            };

            var pagingParams = new NabVelocity.Tms.PagingParameters()
            {
                Page = 0, PageSize = 10
            };

            var txnsSummary = tmsClient.QueryTransactionsSummary(sessionToken, queryParams, false, pagingParams);

            var txnsDetail = tmsClient.QueryTransactionsDetail(sessionToken, queryParams, NabVelocity.Tms.TransactionDetailFormat.CWSTransaction, false, pagingParams);

            var txnsFamilies = tmsClient.QueryTransactionFamilies(sessionToken, queryParams, pagingParams);

            #endregion
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            #region Preparing the Application to Transact

            #region Setup Clients

            bool certification = bool.Parse(ConfigurationManager.AppSettings["certification"]);

            // setup service information client from service reference generated code
            var svcClient = new CWSServiceInformationClient(new BasicHttpsBinding()
            {
                MaxReceivedMessageSize = 20000000
            },
                                                            new EndpointAddress("https://api" + (certification ? ".cert." : ".") + "nabcommerce.com/2.0.18/SvcInfo"));

            // setup transaction client from service reference generated code
            var txnClient = new CwsTransactionProcessingClient(new BasicHttpsBinding(),
                                                               new EndpointAddress("https://api" + (certification ? ".cert." : ".") + "nabcommerce.com/2.0.18/Txn"));

            string applicationProfileId = ConfigurationManager.AppSettings["applicationProfileId"];
            string merchantProfileId    = ConfigurationManager.AppSettings["merchantProfileId"];;

            #endregion

            #region SignOnWithToken

            string identityToken = ConfigurationManager.AppSettings["identityToken"];

            string sessionToken = svcClient.SignOnWithToken(identityToken);

            #endregion

            #region GetServiceInformation

            ServiceInformation serviceInfo = svcClient.GetServiceInformation(sessionToken);

            BankcardService service = serviceInfo.BankcardServices.First();
            //// the serviceId represents the payment processor (global, firstdata, chase, etc.)
            string serviceId = service.ServiceId;
            // if Capture is supported, the service is host capture
            bool serviceIsHostCapture = service.Operations.Capture;
            // if CaptureAll is supprted, the service is terminal capture
            bool serviceIsTermCapture = service.Operations.CaptureAll;

            #endregion

            #endregion

            #region Transacting

            if (serviceIsHostCapture)
            {
                #region Host Capture workflow

                try
                {
                    #region Verify

                    var verifyRequest = new BankcardTransaction()
                    {
                        TenderData = new BankcardTenderData()
                        {
                            CardData = new CardData1()
                            {
                                CardType = TypeCardType.Visa,
                                PAN      = "5100000000000016",
                                Expire   = "1224",
                            },
                            CardSecurityData = new CardSecurityData1()
                            {
                                AVSData = new AVSData()
                                {
                                    Street        = "123 Rain Road",
                                    City          = "Aurora",
                                    StateProvince = "CO",
                                    PostalCode    = "80080",
                                },
                                CVData         = "383",
                                CVDataProvided = CVDataProvided.Provided,
                            },
                        },
                        TransactionData = new BankcardTransactionData()
                        {
                            Amount       = 0.00M,
                            EntryMode    = NabVelocity.Txn.EntryMode.Keyed,
                            IndustryType = NabVelocity.Txn.IndustryType.Ecommerce,
                        },
                        CustomerData = new TransactionCustomerData()
                        {
                        }
                    };

                    var verifyResponse = (BankcardTransactionResponse)txnClient.Verify(sessionToken, verifyRequest,
                                                                                       applicationProfileId, merchantProfileId, serviceId);

                    Console.WriteLine("(Verify) Status: " + verifyResponse.Status + "\r\n"
                                      + "CV Result: " + verifyResponse.CVResult + "\r\n"
                                      + "AVS Postal Result: " + verifyResponse.AVSResult.PostalCodeResult + "\r\n");

                    #endregion

                    #region Authorize

                    var authRequest = new BankcardTransaction()
                    {
                        TenderData = new BankcardTenderData()
                        {
                            CardData = new CardData1()
                            {
                                CardType = TypeCardType.Visa,
                                PAN      = "5100000000000016",
                                Expire   = "1224",
                            },
                            CardSecurityData = new CardSecurityData1()
                            {
                                AVSData = new AVSData()
                                {
                                    Street        = "123 Rain Road",
                                    City          = "Aurora",
                                    StateProvince = "CO",
                                    PostalCode    = "80080",
                                },
                                CVData         = "383",
                                CVDataProvided = CVDataProvided.Provided,
                            },
                        },
                        TransactionData = new BankcardTransactionData()
                        {
                            CurrencyCode = NabVelocity.Txn.TypeISOCurrencyCodeA3.USD,
                            OrderNumber  = "123456",
                            Amount       = 15.00M,
                            EntryMode    = NabVelocity.Txn.EntryMode.Keyed,
                            IndustryType = NabVelocity.Txn.IndustryType.Ecommerce,
                        },
                    };

                    var authResponse = (BankcardTransactionResponse)txnClient.Authorize(sessionToken, authRequest,
                                                                                        applicationProfileId, merchantProfileId, serviceId);

                    Console.WriteLine("(Authorize) Status: " + authResponse.Status + "\r\n"
                                      + "Amount: " + authResponse.Amount + "\r\n"
                                      + "ApprovalCode: " + authResponse.ApprovalCode + "\r\n"
                                      + "TransactionId: " + authResponse.TransactionId + "\r\n");

                    #endregion

                    #region Capture

                    var captureDifferenceData = new BankcardCapture()
                    {
                        TransactionId = authResponse.TransactionId,
                        Amount        = authResponse.Amount + 1.00M,
                    };

                    var captureResponse = (BankcardCaptureResponse)txnClient.Capture(sessionToken, captureDifferenceData,
                                                                                     applicationProfileId, serviceId);

                    Console.WriteLine("(Capture) Status: " + captureResponse.Status + "\r\n"
                                      + "Amount: " + captureResponse.TransactionSummaryData.NetTotals.NetAmount + "\r\n"
                                      + "TransactionId: " + captureResponse.TransactionId + "\r\n");

                    #endregion

                    #region AuthAndCapture

                    var authAndCaptureRequest = new BankcardTransaction()
                    {
                        TenderData = new BankcardTenderData()
                        {
                            CardData = new CardData1()
                            {
                                CardType = TypeCardType.Visa,
                                PAN      = "5100000000000016",
                                Expire   = "1224",
                            },
                            CardSecurityData = new CardSecurityData1()
                            {
                                AVSData = new AVSData()
                                {
                                    Street        = "123 Rain Road",
                                    City          = "Aurora",
                                    StateProvince = "CO",
                                    PostalCode    = "80080",
                                },
                                CVData         = "383",
                                CVDataProvided = CVDataProvided.Provided,
                            },
                        },
                        TransactionData = new BankcardTransactionData()
                        {
                            CurrencyCode = NabVelocity.Txn.TypeISOCurrencyCodeA3.USD,
                            OrderNumber  = "123456",
                            Amount       = 15.00M,
                            EntryMode    = NabVelocity.Txn.EntryMode.Keyed,
                            IndustryType = NabVelocity.Txn.IndustryType.Ecommerce,
                        },
                    };

                    var authAndCapResponse = (BankcardTransactionResponse)txnClient.AuthorizeAndCapture(sessionToken, authAndCaptureRequest,
                                                                                                        applicationProfileId, merchantProfileId, serviceId);

                    Console.WriteLine("(AuthAndCapture) Status: " + authAndCapResponse.Status + "\r\n"
                                      + "Amount: " + authAndCapResponse.Amount + "\r\n"
                                      + "ApprovalCode: " + authAndCapResponse.ApprovalCode + "\r\n"
                                      + "TransactionId: " + authAndCapResponse.TransactionId + "\r\n");

                    #endregion

                    #region ReturnById

                    var returnByIdRequest = new BankcardReturn()
                    {
                        TransactionId       = authAndCapResponse.TransactionId,
                        TransactionDateTime = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fffzzz"),
                    };

                    var returnByIdResponse = (BankcardTransactionResponse)txnClient.ReturnById(sessionToken, returnByIdRequest,
                                                                                               applicationProfileId, serviceId);

                    Console.WriteLine("(ReturnById) Status: " + returnByIdResponse.Status + "\r\n"
                                      + "Amount: " + returnByIdResponse.Amount + "\r\n"
                                      + "ApprovalCode: " + returnByIdResponse.ApprovalCode + "\r\n"
                                      + "TransactionId: " + returnByIdResponse.TransactionId + "\r\n");

                    #endregion

                    #region ReturnUnlinked

                    var returnRequest = new BankcardTransaction()
                    {
                        TenderData = new BankcardTenderData()
                        {
                            CardData = new CardData1()
                            {
                                CardType = TypeCardType.Visa,
                                PAN      = "5100000000000016",
                                Expire   = "1224",
                            },
                        },
                        TransactionData = new BankcardTransactionData()
                        {
                            CurrencyCode = NabVelocity.Txn.TypeISOCurrencyCodeA3.USD,
                            OrderNumber  = "123456",
                            Amount       = 15.00M,
                            EntryMode    = NabVelocity.Txn.EntryMode.Keyed,
                            IndustryType = NabVelocity.Txn.IndustryType.Ecommerce,
                        },
                    };

                    var returnUnlinkedResponse = (BankcardTransactionResponse)txnClient.ReturnUnlinked(sessionToken, returnRequest,
                                                                                                       applicationProfileId, merchantProfileId, serviceId);

                    Console.WriteLine("(ReturnUnlinked) Status: " + returnUnlinkedResponse.Status + "\r\n"
                                      + "Amount: " + returnUnlinkedResponse.Amount + "\r\n"
                                      + "ApprovalCode: " + returnUnlinkedResponse.ApprovalCode + "\r\n"
                                      + "TransactionId: " + returnUnlinkedResponse.TransactionId + "\r\n");

                    #endregion

                    #region Tokenized Transactions

                    // build a transaction
                    var tokenizedRequest = new BankcardTransaction()
                    {
                        TenderData = new BankcardTenderData()
                        {
                            // we only need to use a token in the tender data now
                            PaymentAccountDataToken = verifyResponse.PaymentAccountDataToken
                        },
                        TransactionData = new BankcardTransactionData()
                        {
                            CurrencyCode = NabVelocity.Txn.TypeISOCurrencyCodeA3.USD,
                            OrderNumber  = "123456",
                            Amount       = 15.00M,
                            EntryMode    = NabVelocity.Txn.EntryMode.Keyed,
                            IndustryType = NabVelocity.Txn.IndustryType.Ecommerce,
                        },
                    };

                    authResponse = (BankcardTransactionResponse)txnClient.Authorize(sessionToken, tokenizedRequest,
                                                                                    applicationProfileId, merchantProfileId, serviceId);
                    authAndCapResponse = (BankcardTransactionResponse)txnClient.AuthorizeAndCapture(sessionToken, tokenizedRequest,
                                                                                                    applicationProfileId, merchantProfileId, serviceId);
                    returnUnlinkedResponse = (BankcardTransactionResponse)txnClient.ReturnUnlinked(sessionToken, tokenizedRequest,
                                                                                                   applicationProfileId, merchantProfileId, serviceId);

                    #endregion

                    #region Adjust

                    var adjustReq = new Adjust()
                    {
                        Amount        = 1.00M,
                        TransactionId = authAndCapResponse.TransactionId,
                    };

                    Response adjustResponse = txnClient.Adjust(sessionToken, adjustReq, applicationProfileId, serviceId);

                    Console.WriteLine("(Adjust) Status: " + adjustResponse.Status + "\r\n"
                                      + "StatusMessage: " + adjustResponse.StatusMessage + "\r\n"
                                      + "TransactionId: " + adjustResponse.TransactionId + "\r\n");

                    #endregion

                    #region Undo

                    var undoRequest = new BankcardUndo()
                    {
                        TransactionId = authResponse.TransactionId,
                    };

                    Response undoResponse = txnClient.Undo(sessionToken, undoRequest, applicationProfileId, serviceId);

                    Console.WriteLine("(Undo) Status: " + undoResponse.Status + "\r\n"
                                      + "StatusMessage: " + undoResponse.StatusMessage + "\r\n"
                                      + "TransactionId: " + undoResponse.TransactionId + "\r\n");

                    #endregion
                }
                catch (FaultException <NabVelocity.Txn.CWSValidationResultFault> ex)
                {
                    foreach (var validationError in ex.Detail.Errors)
                    {
                        Console.WriteLine(string.Format("Validatior error: {0} - {1}",
                                                        validationError.RuleLocationKey, validationError.RuleMessage));
                    }
                }

                #endregion
            }

            if (serviceIsTermCapture)
            {
                #region Term Capture Workflow

                try
                {
                    #region Verify

                    var verifyRequest = new BankcardTransaction()
                    {
                        TenderData = new BankcardTenderData()
                        {
                            CardData = new CardData1()
                            {
                                CardType = TypeCardType.Visa,
                                PAN      = "4111111111111111",
                                Expire   = "1224",
                            },
                            CardSecurityData = new CardSecurityData1()
                            {
                                AVSData = new AVSData()
                                {
                                    Street        = "123 Rain Road",
                                    City          = "Aurora",
                                    StateProvince = "CO",
                                    PostalCode    = "80080",
                                },
                                CVData         = "123",
                                CVDataProvided = CVDataProvided.Provided,
                            },
                        },
                        TransactionData = new BankcardTransactionData()
                        {
                            Amount       = 0.00M,
                            EntryMode    = NabVelocity.Txn.EntryMode.Keyed,
                            IndustryType = NabVelocity.Txn.IndustryType.Ecommerce,
                        },
                        CustomerData = new TransactionCustomerData()
                        {
                        }
                    };

                    var verifyResponse = (BankcardTransactionResponse)txnClient.Verify(sessionToken, verifyRequest,
                                                                                       applicationProfileId, merchantProfileId, serviceId);

                    Console.WriteLine("(Verify) Status: " + verifyResponse.Status + "\r\n"
                                      + "CV Result: " + verifyResponse.CVResult + "\r\n"
                                      + "AVS Postal Result: " + verifyResponse.AVSResult.PostalCodeResult + "\r\n");

                    #endregion

                    #region Authorize

                    var authRequest = new BankcardTransaction()
                    {
                        TenderData = new BankcardTenderData()
                        {
                            CardData = new CardData1()
                            {
                                CardType = TypeCardType.Visa,
                                PAN      = "4111111111111111",
                                Expire   = "1224",
                            },
                            CardSecurityData = new CardSecurityData1()
                            {
                                AVSData = new AVSData()
                                {
                                    Street        = "123 Rain Road",
                                    City          = "Aurora",
                                    StateProvince = "CO",
                                    PostalCode    = "80080",
                                },
                                CVData         = "123",
                                CVDataProvided = CVDataProvided.Provided,
                            },
                        },
                        TransactionData = new BankcardTransactionData()
                        {
                            CurrencyCode = NabVelocity.Txn.TypeISOCurrencyCodeA3.USD,
                            OrderNumber  = "123456",
                            Amount       = 15.00M,
                            EntryMode    = NabVelocity.Txn.EntryMode.Keyed,
                            IndustryType = NabVelocity.Txn.IndustryType.Ecommerce,
                        },
                    };

                    var authResponse = (BankcardTransactionResponse)txnClient.Authorize(sessionToken, authRequest,
                                                                                        applicationProfileId, merchantProfileId, serviceId);

                    Console.WriteLine("(Authorize) Status: " + authResponse.Status + "\r\n"
                                      + "Amount: " + authResponse.Amount + "\r\n"
                                      + "ApprovalCode: " + authResponse.ApprovalCode + "\r\n"
                                      + "TransactionId: " + authResponse.TransactionId + "\r\n");

                    #endregion

                    #region Capture Selective

                    var captureSelectiveDifferenceData = new BankcardCapture()
                    {
                        TransactionId = authResponse.TransactionId,
                        Amount        = authResponse.Amount + 1.00M,
                    };

                    Response[] captureSelectiveResponses = txnClient.CaptureSelective(sessionToken, new[] { authResponse.TransactionId },
                                                                                      new[] { captureSelectiveDifferenceData }, applicationProfileId, serviceId);

                    foreach (var response in captureSelectiveResponses)
                    {
                        if (response.Status == Status.Failure)
                        {
                            Console.WriteLine("(Capture Selective) Status: " + response.Status + "\r\n"
                                              + "StatusMessage: " + response.StatusMessage + "\r\n"
                                              + "TransactionId: " + response.TransactionId + "\r\n");
                        }
                        else
                        {
                            var captureResponse = (BankcardCaptureResponse)response;

                            Console.WriteLine("(Capture Selective) Status: " + captureResponse.Status + "\r\n"
                                              + "Industry: " + captureResponse.IndustryType + "\r\n"
                                              + "Sales Count: " + captureResponse.TransactionSummaryData.SaleTotals.Count + "\r\n"
                                              + "Sales Amount: " + captureResponse.TransactionSummaryData.SaleTotals.NetAmount + "\r\n"
                                              + "Return Count: " + captureResponse.TransactionSummaryData.ReturnTotals.Count + "\r\n"
                                              + "Return Amount: " + captureResponse.TransactionSummaryData.ReturnTotals.NetAmount + "\r\n"
                                              + "TransactionId: " + captureResponse.TransactionId + "\r\n");
                        }
                    }

                    #endregion

                    #region ReturnById

                    var returnByIdRequest = new BankcardReturn()
                    {
                        TransactionId       = authResponse.TransactionId,
                        TransactionDateTime = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fffzzz"),
                    };

                    var returnByIdResponse = (BankcardTransactionResponse)txnClient.ReturnById(sessionToken, returnByIdRequest,
                                                                                               applicationProfileId, serviceId);

                    Console.WriteLine("(ReturnById) Status: " + returnByIdResponse.Status + "\r\n"
                                      + "Amount: " + returnByIdResponse.Amount + "\r\n"
                                      + "ApprovalCode: " + returnByIdResponse.ApprovalCode + "\r\n"
                                      + "TransactionId: " + returnByIdResponse.TransactionId + "\r\n");

                    #endregion

                    #region ReturnUnlinked

                    var returnRequest = new BankcardTransaction()
                    {
                        TenderData = new BankcardTenderData()
                        {
                            CardData = new CardData1()
                            {
                                CardType = TypeCardType.Visa,
                                PAN      = "4111111111111111",
                                Expire   = "1224",
                            },
                        },
                        TransactionData = new BankcardTransactionData()
                        {
                            CurrencyCode = NabVelocity.Txn.TypeISOCurrencyCodeA3.USD,
                            OrderNumber  = "123456",
                            Amount       = 15.00M,
                            EntryMode    = NabVelocity.Txn.EntryMode.Keyed,
                            IndustryType = NabVelocity.Txn.IndustryType.Ecommerce,
                        },
                    };

                    var returnUnlinkedResponse = (BankcardTransactionResponse)txnClient.ReturnUnlinked(sessionToken, returnRequest,
                                                                                                       applicationProfileId, merchantProfileId, serviceId);

                    Console.WriteLine("(ReturnUnlinked) Status: " + returnUnlinkedResponse.Status + "\r\n"
                                      + "Amount: " + returnUnlinkedResponse.Amount + "\r\n"
                                      + "ApprovalCode: " + returnUnlinkedResponse.ApprovalCode + "\r\n"
                                      + "TransactionId: " + returnUnlinkedResponse.TransactionId + "\r\n");

                    #endregion

                    #region Tokenized Transactions

                    // build a transaction
                    var tokenizedRequest = new BankcardTransaction()
                    {
                        TenderData = new BankcardTenderData()
                        {
                            // we only need to use a token in the tender data now
                            PaymentAccountDataToken = verifyResponse.PaymentAccountDataToken
                        },
                        TransactionData = new BankcardTransactionData()
                        {
                            CurrencyCode = NabVelocity.Txn.TypeISOCurrencyCodeA3.USD,
                            OrderNumber  = "123456",
                            Amount       = 15.00M,
                            EntryMode    = NabVelocity.Txn.EntryMode.Keyed,
                            IndustryType = NabVelocity.Txn.IndustryType.Ecommerce,
                        },
                    };

                    authResponse = (BankcardTransactionResponse)txnClient.Authorize(sessionToken, tokenizedRequest,
                                                                                    applicationProfileId, merchantProfileId, serviceId);
                    returnUnlinkedResponse = (BankcardTransactionResponse)txnClient.ReturnUnlinked(sessionToken, tokenizedRequest,
                                                                                                   applicationProfileId, merchantProfileId, serviceId);

                    #endregion

                    #region Adjust

                    var adjustReq = new Adjust()
                    {
                        Amount        = 1.00M,
                        TransactionId = authResponse.TransactionId,
                    };

                    Response adjustResponse = txnClient.Adjust(sessionToken, adjustReq, applicationProfileId, serviceId);

                    Console.WriteLine("(Adjust) Status: " + adjustResponse.Status + "\r\n"
                                      + "StatusMessage: " + adjustResponse.StatusMessage + "\r\n"
                                      + "TransactionId: " + adjustResponse.TransactionId + "\r\n");

                    #endregion

                    #region Undo

                    var undoRequest = new BankcardUndo()
                    {
                        TransactionId = adjustResponse.TransactionId,
                    };

                    Response undoResponse = txnClient.Undo(sessionToken, undoRequest, applicationProfileId, serviceId);

                    Console.WriteLine("(Undo) Status: " + undoResponse.Status + "\r\n"
                                      + "StatusMessage: " + undoResponse.StatusMessage + "\r\n"
                                      + "TransactionId: " + undoResponse.TransactionId + "\r\n");

                    #endregion

                    #region Capture All

                    Response[] captureAllResponses = txnClient.CaptureAll(sessionToken, null,
                                                                          null, applicationProfileId, merchantProfileId, serviceId);

                    foreach (var response in captureAllResponses)
                    {
                        if (response.Status == Status.Failure)
                        {
                            Console.WriteLine("(Capture All) Status: " + response.Status + "\r\n"
                                              + "StatusMessage: " + response.StatusMessage + "\r\n"
                                              + "TransactionId: " + response.TransactionId + "\r\n");
                        }
                        else
                        {
                            var captureResponse = (BankcardCaptureResponse)response;

                            Console.WriteLine("(Capture All) Status: " + captureResponse.Status + "\r\n"
                                              + "Industry: " + captureResponse.IndustryType + "\r\n"
                                              + "Sales Count: " + captureResponse.TransactionSummaryData.SaleTotals.Count + "\r\n"
                                              + "Sales Amount: " + captureResponse.TransactionSummaryData.SaleTotals.NetAmount + "\r\n"
                                              + "Return Count: " + captureResponse.TransactionSummaryData.ReturnTotals.Count + "\r\n"
                                              + "Return Amount: " + captureResponse.TransactionSummaryData.ReturnTotals.NetAmount + "\r\n"
                                              + "TransactionId: " + captureResponse.TransactionId + "\r\n");
                        }
                    }

                    #endregion
                }
                catch (FaultException <NabVelocity.Txn.CWSValidationResultFault> ex)
                {
                    foreach (var validationError in ex.Detail.Errors)
                    {
                        Console.WriteLine(string.Format("Validatior error: {0} - {1}",
                                                        validationError.RuleLocationKey, validationError.RuleMessage));
                    }
                }

                #endregion
            }

            #endregion
        }
        private void cmdReturnById_Click(object sender, EventArgs e)
        {//The ReturnById() operation is used to return a transaction that has been previously captured.
            if (ChkLstTransactionsProcessed.CheckedItems.Count == 0) { MessageBox.Show("Please Select (Check) transactions for ReturnById"); return; }
            //Check to see if this transaction type is supported
            if (!SupportedTxnTypes.ReturnById) { MessageBox.Show("ReturnById Not Supported");return; }

            Cursor = Cursors.WaitCursor;

            if (_bcs != null) //Process a BankCard Transaction
            {
                try
                {
                    BankcardReturn BCRDifferenceData = new BankcardReturn();

                    List<ResponseDetails> txnsToProcess = new List<ResponseDetails>();
                    if (_bcs.Tenders.CreditAuthorizeSupport == CreditAuthorizeSupportType.AuthorizeOnly)
                    {//NOTE : Please note that in the case of some Service Providers AuthorizeAndCapture is not supported for ReturnById. Use Authorize Instead
                        //In this case it's a terminal capture service that supports PINDebit

                        //First verify if all transactions selected are "Authorize" transactions
                        foreach (object itemChecked in ChkLstTransactionsProcessed.CheckedItems)
                        {
                            if (((ResponseDetails)(itemChecked)).TransactionType != TransactionType.Authorize.ToString())
                            {
                                MessageBox.Show("All selected messages must be of type Authorize");
                                Cursor = Cursors.Default;
                                return;
                            }
                            txnsToProcess.Add(((ResponseDetails)(itemChecked)));
                        }
                       
                        //Now in ordert to process a ReturnById we must first Capture the transaction. This can be done with CaptureAll or CaptureSelective.
                        MessageBox.Show("All transctions must be processed via a CaptureAll or CaptureSelective first. Running CaptureAll");
                        processResponse(Helper.ProcessBCPTransaction(TransactionType.CaptureAll, null, null, null, null, null, null, null, null, ChkAcknowledge.Checked, false));

                        //Now process each message selected
                        foreach (ResponseDetails _RD in txnsToProcess)
                        {
                            BCRDifferenceData.TransactionId = _RD.Response.TransactionId;
                            BCRDifferenceData.Amount = 8.00M;
                            processResponse(Helper.ProcessBCPTransaction(TransactionType.ReturnById, null, null, null, BCRDifferenceData, null, null, null, null, ChkAcknowledge.Checked, false));
                        }
                    }
                    else
                    {
                        //In this case it's a host capture solution. So only AuthorizeAndCapture and Capture transactions are permitted. 

                        //First verify if all transactions selected are "AuthorizeAndCapture" or "Capture" transactions
                        foreach (object itemChecked in ChkLstTransactionsProcessed.CheckedItems)
                        {
                            if (((ResponseDetails)(itemChecked)).TransactionType != TransactionType.AuthorizeAndCapture.ToString()
                                && ((ResponseDetails)(itemChecked)).TransactionType != TransactionType.Capture.ToString())
                            {
                                MessageBox.Show("All selected messages must be of type AuthorizeAndCapture or Capture");
                                Cursor = Cursors.Default;
                                return;
                            }
                            txnsToProcess.Add(((ResponseDetails)(itemChecked)));
                        }
                        //Now process each  message selected
                        foreach (ResponseDetails _RD in txnsToProcess)
                        {
                            //Let's return the transaction
                            BCRDifferenceData.TransactionId = _RD.Response.TransactionId;
                            BCRDifferenceData.Amount = 8.00M;
                            processResponse(Helper.ProcessBCPTransaction(TransactionType.ReturnById, null, null, null, BCRDifferenceData, null, null, null, null, ChkAcknowledge.Checked, false));
                        }
                    }
                }
                catch (Exception ex) { MessageBox.Show(ex.Message); }
                finally { Cursor = Cursors.Default; }

            }
            else if (_svas != null) //Process a Stored Value Transaction
            {
                //Check to see if this transaction type is supported
                if (!SupportedTxnTypes.ReturnById) { MessageBox.Show("ReturnById Not Supported"); Cursor = Cursors.Default; return; }

                try
                {
                    StoredValueTransaction SVtransaction = SetStoredValueTxnData();
                    List<ResponseDetails> response = new List<ResponseDetails>();
                    StoredValueReturn SVRDifferenceData = new StoredValueReturn();
                    string strTransactionId = "";
                    SVtransaction.TransactionData.Amount = 84.00M;

                    if (_svas.Tenders.CreditAuthorizeSupport == CreditAuthorizeSupportType.AuthorizeAndCaptureOnly)
                    {
                        response = Helper.ProcessSVATransaction(TransactionType.AuthorizeAndCapture, SVtransaction, null, null, null, null, ChkAcknowledge.Checked);
                        if (response.Count < 1) { return; }
                        ChkLstTransactionsProcessed.Items.Add(response[0]); 
                        StoredValueTransactionResponse SVR = (StoredValueTransactionResponse)response[0].Response;
                        strTransactionId = SVR.TransactionId;
                        //Now in ordert to process a ReturnById we must first Capture the transaction. This can be done with CaptureAll or CaptureSelective.
                        response = Helper.ProcessBCPTransaction(TransactionType.CaptureAll, null, null, null, null, null, null, null, null, ChkAcknowledge.Checked, false);
                        if (response.Count < 1) { return; }
                        ChkLstTransactionsProcessed.Items.Add(response[0]);

                        //Now Let's return the transaction
                        SVRDifferenceData.TransactionId = strTransactionId;
                        SVRDifferenceData.Amount = 36.00M;
                        response = Helper.ProcessSVATransaction(TransactionType.ReturnById, null, null, null, SVRDifferenceData, null, ChkAcknowledge.Checked);
                        if (response.Count < 1) { return; }
                        ChkLstTransactionsProcessed.Items.Add(response[0]);
                    }
                }
                catch (Exception ex) { MessageBox.Show(ex.Message); }
                finally { Cursor = Cursors.Default; }

            }
            else if (_ecks != null) //Process as a Check transaction
            {
                try
                {
                    MessageBox.Show(@"Placeholder for ECK code. Please ask your solution consultant for an example");
                }
                catch (Exception ex) { MessageBox.Show(ex.Message); }
                finally { Cursor = Cursors.Default; }
            }
        }
        static void Main(string[] args)
        {
            Console.BufferWidth = 150;
            //Console.BufferHeight = Console.LargestWindowHeight;
            Console.BufferHeight = 60;
            Console.SetWindowSize(Console.BufferWidth, Console.BufferHeight);

            #region Step 1: SignOn Authentication
            Console.WriteLine("Attempting to sign in...");
            _sessionToken = _svcClient.SignOn(_identityToken);
            Console.WriteLine(!string.IsNullOrEmpty(_sessionToken) ? "Successfully signed in!\n" : "ERROR Signing in!\n");
            #endregion

            #region Step 2: Managing Application Configuration Data
            Console.WriteLine("Attempting to save application data...");
            var applicationData = DataGenerator.CreateApplicationData();
            _applicationProfileId = _svcClient.SaveApplicationData(_sessionToken, applicationData);
            if(!string.IsNullOrEmpty(_applicationProfileId))
                Console.WriteLine("Application saved successfully! Application Profile ID: " + _applicationProfileId + "\n");
            else Console.WriteLine("ERROR Saving Application!\n");
            #endregion

            #region Step 3: Retrieving Service Information
            Console.WriteLine("Getting service information...");
            var serviceInfo = _svcClient.GetServiceInformation(_sessionToken);
            #endregion

            #region Step 4: Managing Merchant Profiles
            if (serviceInfo.BankcardServices.Any())
            {
                // If there are multiple services you'll want to use them as desired. The sample will only focus on the first one.
                var bankcardService = serviceInfo.BankcardServices.First();
                _bcpServiceId = bankcardService.ServiceId;
                Console.WriteLine("There are " + serviceInfo.BankcardServices.Count() + " bankcard services available. Using serviceId " + _bcpServiceId + "\n");

                if (!_svcClient.IsMerchantProfileInitialized(_sessionToken, _bcpServiceId, _merchantProfileId, TenderType.Credit))
                {
                    Console.WriteLine("Merchant Profile " + _merchantProfileId + " does not exist. Attempting to save...");
                    _svcClient.SaveMerchantProfiles(_sessionToken, _bcpServiceId, TenderType.Credit, DataGenerator.CreateMerchantProfiles());
                    if (_svcClient.IsMerchantProfileInitialized(_sessionToken, _bcpServiceId, _merchantProfileId, TenderType.Credit))
                        Console.WriteLine("Merchant Profile " + _merchantProfileId + " saved successfully!\n");

                } else Console.WriteLine("Merchant Profile " + _merchantProfileId + " exists. Skipping SaveMerchantProfiles.");
            }
            if(serviceInfo.ElectronicCheckingServices.Any())
            {
                // If there are multiple services you'll want to use them as desired. The sample will only focus on the first one.
                var eckServce = serviceInfo.ElectronicCheckingServices.First();
                _eckServiceId = eckServce.ServiceId;
                Console.WriteLine("There are " + serviceInfo.BankcardServices.Count() + " electronic checking services available. Using serviceId " + _eckServiceId + "\n");

                if (!_svcClient.IsMerchantProfileInitialized(_sessionToken, _eckServiceId, _merchantProfileId, TenderType.PINDebit))
                {
                    Console.WriteLine("Merchant Profile " + _merchantProfileId + " does not exist. Attempting to save...");
                    _svcClient.SaveMerchantProfiles(_sessionToken, _eckServiceId, TenderType.PINDebit, DataGenerator.CreateMerchantProfiles());
                    if (_svcClient.IsMerchantProfileInitialized(_sessionToken, _eckServiceId, _merchantProfileId, TenderType.PINDebit))
                        Console.WriteLine("Merchant Profile " + _merchantProfileId + " saved successfully!\n");

                }
                else Console.WriteLine("Merchant Profile " + _merchantProfileId + " exists. Skipping SaveMerchantProfiles.");
            }
            if(serviceInfo.StoredValueServices.Any())
            {
                // If there are multiple services you'll want to use them as desired. The sample will only focus on the first one.
                var svaService = serviceInfo.ElectronicCheckingServices.First();
                _svaServiceId = svaService.ServiceId;
                Console.WriteLine("There are " + serviceInfo.BankcardServices.Count() + " stroed value services available. Using serviceId " + _svaServiceId + "\n");

                if (!_svcClient.IsMerchantProfileInitialized(_sessionToken, _svaServiceId, _merchantProfileId, TenderType.NotSet))
                {
                    Console.WriteLine("Merchant Profile " + _merchantProfileId + " does not exist. Attempting to save...");
                    _svcClient.SaveMerchantProfiles(_sessionToken, _svaServiceId, TenderType.NotSet, DataGenerator.CreateMerchantProfiles());
                    if (_svcClient.IsMerchantProfileInitialized(_sessionToken, _svaServiceId, _merchantProfileId, TenderType.NotSet))
                        Console.WriteLine("Merchant Profile " + _merchantProfileId + " saved successfully!\n");

                }
                else Console.WriteLine("Merchant Profile " + _merchantProfileId + " exists. Skipping SaveMerchantProfiles.");
            }

            // GetMerchantProfiles
            var merchantProfiles = new List<MerchantProfile>();
            if(!string.IsNullOrEmpty(_bcpServiceId))
            {
                Console.WriteLine("Getting Merchant Profiles with service ID: " + _bcpServiceId);
                merchantProfiles = _svcClient.GetMerchantProfiles(_sessionToken, _bcpServiceId, TenderType.Credit);
            }
            else if (!string.IsNullOrEmpty(_eckServiceId))
            {
                Console.WriteLine("Getting Merchant Profiles with service ID: " + _eckServiceId);
                merchantProfiles = _svcClient.GetMerchantProfiles(_sessionToken, _eckServiceId, TenderType.PINDebit);
            }
            else if (!string.IsNullOrEmpty(_svaServiceId))
            {
                Console.WriteLine("Getting Merchant Profiles with service ID: " + _svaServiceId);
                merchantProfiles = _svcClient.GetMerchantProfiles(_sessionToken, _svaServiceId, TenderType.NotSet);
            }
            Console.WriteLine("There are " + merchantProfiles.Count + " merchant profiles related to this serviceId.");
            foreach (var merchantProfile in merchantProfiles)
            {
                Console.WriteLine("    Merchant Profile Id: " + merchantProfile.ProfileId);
                Console.WriteLine("        Service Name: " + merchantProfile.ServiceName);
            }
            #endregion

            #region Step 5: Authorizing Transactions
            var bankcardTransaction = DataGenerator.CreateBankcardTransaction();
            var eckTransaction = new ElectronicCheckingTransaction(); // TODO create ECK Transaction
            var svaTransaction = new StoredValueTransaction(); // TODO Create SVA Transaction

            var txnIdForAdjustAndCapture = "";
            var txnIdForUndo = "";
            var txnIdsForCaptureAll = new List<string>();
            var txnIdsForCaptureSelective = new List<string>();
            var txnIdForReturnById = "";
            // Bankcard Services - Authorize
            if(!string.IsNullOrEmpty(_bcpServiceId) && serviceInfo.BankcardServices.First().Operations.Authorize)
            {
                Console.WriteLine("\nBankcard Processing: Creating transaction to adjust and then capture...");
                var response = _txnClient.Authorize(_sessionToken, bankcardTransaction, _applicationProfileId, _merchantProfileId,_bcpServiceId);
                ScreenPrinter.PrintTransactionResponse(response, "AUTHORIZE");
                if(response != null)
                    txnIdForAdjustAndCapture = !string.IsNullOrEmpty(response.TransactionId) ? response.TransactionId : null;

                Console.WriteLine("\nBankcard Processing: Creating transaction to undo...");
                var response2 = _txnClient.Authorize(_sessionToken, bankcardTransaction, _applicationProfileId, _merchantProfileId, _bcpServiceId);
                ScreenPrinter.PrintTransactionResponse(response2, "AUTHORIZE");
                if (response2 != null)
                    txnIdForUndo = !string.IsNullOrEmpty(response2.TransactionId) ? response2.TransactionId : null;

                Console.WriteLine("\nBankcard Processing: Creating 3 transactions to be used to Capture All...");
                for (int i = 0; i < 3; i++)
                {
                    var response3 = _txnClient.Authorize(_sessionToken, bankcardTransaction, _applicationProfileId, _merchantProfileId, _bcpServiceId);
                    ScreenPrinter.PrintTransactionResponse(response3, "AUTHORIZE");
                    if (response3 != null && !string.IsNullOrEmpty(response3.TransactionId))
                        txnIdsForCaptureAll.Add(response3.TransactionId);
                }

                Console.WriteLine("\nBankcard Processing: Creating 3 transactions to be used to Capture Selective...");
                for (int i = 0; i < 3; i++)
                {
                    var response4 = _txnClient.Authorize(_sessionToken, bankcardTransaction, _applicationProfileId, _merchantProfileId, _bcpServiceId);
                    ScreenPrinter.PrintTransactionResponse(response4, "AUTHORIZE");
                    if (response4 != null && !string.IsNullOrEmpty(response4.TransactionId))
                        txnIdsForCaptureSelective.Add(response4.TransactionId);
                }
            }
            // Bankcard Services - Authorize and Capture
            if (!string.IsNullOrEmpty(_bcpServiceId) && serviceInfo.BankcardServices.First().Operations.AuthAndCapture)
            {
                Console.WriteLine("\nBankcard Processing: Creating authorize and capture transaction to return by id...");
                var response = _txnClient.AuthorizeAndCapture(_sessionToken, bankcardTransaction, _applicationProfileId, _merchantProfileId, _bcpServiceId);
                ScreenPrinter.PrintTransactionResponse(response, "AUTHORIZE AND CAPTURE");
                if (response != null)
                    txnIdForReturnById = !string.IsNullOrEmpty(response.TransactionId) ? response.TransactionId : null;
            }
            // Electronic Checking Services - Authorize
            if (!string.IsNullOrEmpty(_eckServiceId) && serviceInfo.ElectronicCheckingServices.First().Operations.Authorize)
            {
                Console.WriteLine("\nElectronic Checking Service: Creating 3 transactions to be used to Capture All...");
                for (int i = 0; i < 3; i++)
                {
                    var response = _txnClient.Authorize(_sessionToken, eckTransaction, _applicationProfileId, _merchantProfileId, _eckServiceId);
                    ScreenPrinter.PrintTransactionResponse(response, "AUTHORIZE");
                    if (response != null && !string.IsNullOrEmpty(response.TransactionId))
                        txnIdsForCaptureAll.Add(response.TransactionId);
                }
            }
            // Stored Value Services - Authorize
            if (!string.IsNullOrEmpty(_svaServiceId) && serviceInfo.StoredValueServices.First().Operations.Authorize)
            {
                Console.WriteLine("\nStored Value Service: Creating transaction to adjust and then capture...");
                var response = _txnClient.Authorize(_sessionToken, svaTransaction, _applicationProfileId, _merchantProfileId, _svaServiceId);
                ScreenPrinter.PrintTransactionResponse(response, "AUTHORIZE");
                if (response != null)
                    txnIdForAdjustAndCapture = !string.IsNullOrEmpty(response.TransactionId) ? response.TransactionId : null;

                Console.WriteLine("\nStored Value Service: Creating transaction to undo...");
                var response2 = _txnClient.Authorize(_sessionToken, svaTransaction, _applicationProfileId, _merchantProfileId, _svaServiceId);
                ScreenPrinter.PrintTransactionResponse(response2, "AUTHORIZE");
                if (response2 != null)
                    txnIdForUndo = !string.IsNullOrEmpty(response2.TransactionId) ? response2.TransactionId : null;
            }
            // Stored Value Services - Authorize and Capture
            if(!string.IsNullOrEmpty(_svaServiceId) && serviceInfo.StoredValueServices.First().Operations.AuthAndCapture)
            {
                Console.WriteLine("\nStored Value Service: Creating authorize and capture transaction to return by id...");
                var response = _txnClient.AuthorizeAndCapture(_sessionToken, svaTransaction, _applicationProfileId, _merchantProfileId, _svaServiceId);
                ScreenPrinter.PrintTransactionResponse(response, "AUTHORIZE AND CAPTURE");
                if (response != null)
                    txnIdForReturnById = !string.IsNullOrEmpty(response.TransactionId) ? response.TransactionId : null;
            }
            #endregion

            //_txnClient.Capture(_sessionToken, )

            #region Step 6: Adjusting and Voiding Transactions

            // Bankcard Services - Adjust
            if (!string.IsNullOrEmpty(_bcpServiceId) && serviceInfo.BankcardServices.First().Operations.Adjust)
            {
                Console.WriteLine("\nBankcard Services: Adjust on transaction " + txnIdForAdjustAndCapture + "...");
                var adjust = new Adjust { Amount = 5.00m, TransactionId = txnIdForAdjustAndCapture };
                var response = _txnClient.Adjust(_sessionToken, adjust, _applicationProfileId, _bcpServiceId);
                ScreenPrinter.PrintTransactionResponse(response, "ADJUST AUTH(" + txnIdForAdjustAndCapture + ")");
                if(response != null) // Save the new txn guid, you'll use the most recent txn guid associated with the transaction for capture later.
                    txnIdForAdjustAndCapture = !string.IsNullOrEmpty(response.TransactionId) ? response.TransactionId : null;
            }
            // Bankcard Services - Undo
            if (!string.IsNullOrEmpty(_bcpServiceId) && serviceInfo.BankcardServices.First().Operations.Undo && !string.IsNullOrEmpty(txnIdForUndo))
            {
                Console.WriteLine("\nBankcard Services: Undo on transaction " + txnIdForUndo + "...");
                var bankcardUndo = new BankcardUndo(){TransactionId = txnIdForUndo, PINDebitReason = PINDebitUndoReason.NotSet, ForceVoid = false};
                var response = _txnClient.Undo(_sessionToken, bankcardUndo, _applicationProfileId, _bcpServiceId);
                ScreenPrinter.PrintTransactionResponse(response, "UNDO (" + txnIdForUndo + ")");
            }
            // Electronic Checking Services - Undo
            if (!string.IsNullOrEmpty(_eckServiceId) && serviceInfo.ElectronicCheckingServices.First().Operations.Undo && !string.IsNullOrEmpty(txnIdForUndo))
            {
                Console.WriteLine("\nElectronic Checking Services: Undo on transaction " + txnIdForUndo + "...");
                var response = _txnClient.Undo(_sessionToken, new Undo() { TransactionId = txnIdForUndo }, _applicationProfileId, _eckServiceId);
                ScreenPrinter.PrintTransactionResponse(response, "UNDO AUTH(" + txnIdForUndo + ")");
            }
            // Stored Value Services - Undo
            if (!string.IsNullOrEmpty(_svaServiceId) && serviceInfo.StoredValueServices.First().Operations.Undo && !string.IsNullOrEmpty(txnIdForUndo))
            {
                Console.WriteLine("Stored Value Services: Undo on transaction " + txnIdForUndo + "...");
                var response = _txnClient.Undo(_sessionToken, new Undo() { TransactionId = txnIdForUndo }, _applicationProfileId, _svaServiceId);
                ScreenPrinter.PrintTransactionResponse(response, "UNDO AUTH(" + txnIdForUndo + ")");
            }
            #endregion

            #region Step 7: Capturing Transaction for Settlement

            // Bankcard Services - Capture
            if (!string.IsNullOrEmpty(_bcpServiceId) && serviceInfo.BankcardServices.First().Operations.Capture && !string.IsNullOrEmpty(txnIdForAdjustAndCapture))
            {
                Console.WriteLine("\nBankcard Services: Capture on transaction " + txnIdForAdjustAndCapture + "...");
                var chargeType = ConfigurationManager.AppSettings["IndustryType"] == "Retail" ? ChargeType.RetailOther : ChargeType.NotSet;
                var capture = new BankcardCapture() { TransactionId = txnIdForAdjustAndCapture, ChargeType = chargeType};
                if (ConfigurationManager.AppSettings["IndustryType"] == "MOTO")
                    capture.ShipDate = DateTime.Now;
                var response = _txnClient.Capture(_sessionToken, capture, _applicationProfileId, _bcpServiceId);
                if(response != null)
                    ScreenPrinter.PrintCaptureResponse(response, "CAPTURE (" + txnIdForAdjustAndCapture + ")");
                // Incase the returnById txnId was not set earlier, we will use this Id to return later.
                if (string.IsNullOrEmpty(txnIdForReturnById))
                    txnIdForReturnById = txnIdForAdjustAndCapture;
            }
            // Bankcard Services - CaptureSelective
            if (!string.IsNullOrEmpty(_bcpServiceId) && serviceInfo.BankcardServices.First().Operations.CaptureSelective && txnIdsForCaptureSelective.Count > 0)
            {
                Console.WriteLine("\nBankcard Services: CaptureSelective on transactions" + "...");
                var chargeType = ConfigurationManager.AppSettings["IndustryType"] == "Retail" ? ChargeType.RetailOther : ChargeType.NotSet;
                var captures = new List<BankcardCapture>();
                foreach (var txnId in txnIdsForCaptureSelective)
                {
                    var capture = new BankcardCapture() { TransactionId = txnId, ChargeType = chargeType };
                    if (ConfigurationManager.AppSettings["IndustryType"] == "MOTO")
                        capture.ShipDate = DateTime.Now;
                    captures.Add(capture);
                }
                var response = _txnClient.CaptureSelective<BankcardCapture>(_sessionToken, txnIdsForCaptureSelective, captures, _applicationProfileId, _bcpServiceId);
                if (response != null)
                    foreach (var r in response)
                        ScreenPrinter.PrintCaptureResponse(r, "CAPTURE (" + r.TransactionId + ")");
            }
            // Bankcard Services - CaptureAll
            if (!string.IsNullOrEmpty(_bcpServiceId) && serviceInfo.BankcardServices.First().Operations.CaptureAll && txnIdsForCaptureAll.Count > 0)
            {
                Console.WriteLine("\nBankcard Services: CaptureAll on transactions" + "...");
                var chargeType = ConfigurationManager.AppSettings["IndustryType"] == "Retail" ? ChargeType.RetailOther : ChargeType.NotSet;
                var captures = new List<BankcardCapture>();
                foreach (var txnId in txnIdsForCaptureAll)
                {
                    var capture = new BankcardCapture() { TransactionId = txnId, ChargeType = chargeType };
                    if (ConfigurationManager.AppSettings["IndustryType"] == "MOTO")
                        capture.ShipDate = DateTime.Now;
                    captures.Add(capture);
                }
                var response = _txnClient.CaptureAll<BankcardCapture>(_sessionToken, captures, _applicationProfileId, _merchantProfileId, _bcpServiceId);
                if (response != null)
                    foreach (var r in response)
                        ScreenPrinter.PrintCaptureResponse(r, "CAPTURE (" + r.TransactionId + ")");
            }
            // Electronic Checking Services - Capture All
            if (!string.IsNullOrEmpty(_eckServiceId) && serviceInfo.ElectronicCheckingServices.First().Operations.CaptureAll && txnIdsForCaptureAll.Count > 0)
            {
                Console.WriteLine("\nElectronic Checking Services: CaptureAll on transactions" + "...");
                var captures = txnIdsForCaptureAll.Select(txnId => new Capture() {TransactionId = txnId}).ToList();
                var response = _txnClient.CaptureAll<Capture>(_sessionToken, captures, _applicationProfileId, _merchantProfileId, _eckServiceId);
                if (response != null)
                    foreach (var r in response)
                        ScreenPrinter.PrintCaptureResponse(r, "CAPTURE (" + r.TransactionId + ")");
            }
            // Stored Value Services - Capture
            if (!string.IsNullOrEmpty(_svaServiceId) && serviceInfo.StoredValueServices.First().Operations.Capture && !string.IsNullOrEmpty(txnIdForAdjustAndCapture))
            {
                Console.WriteLine("\nStored Value Services: Capture on transaction " + txnIdForAdjustAndCapture + "...");
                var capture = new Capture() { TransactionId = txnIdForAdjustAndCapture};
                var response = _txnClient.Capture(_sessionToken, capture, _applicationProfileId, _svaServiceId);
                if (response != null)
                    ScreenPrinter.PrintCaptureResponse(response, "CAPTURE (" + txnIdForAdjustAndCapture + ")");
            }

            #endregion

            #region Step 8: Refunding Transactions
            // If the txnIdForReturnById was not set by this point, attempt to authorize and capture a new transaction.
            if(!string.IsNullOrEmpty(_bcpServiceId) && string.IsNullOrEmpty(txnIdForReturnById))
            {
                var authResponse = _txnClient.Authorize(_sessionToken, bankcardTransaction, _applicationProfileId, _merchantProfileId, _bcpServiceId);
                if (authResponse != null)
                {
                    var chargeType = ConfigurationManager.AppSettings["IndustryType"] == "Retail"? ChargeType.RetailOther : ChargeType.NotSet;
                    var capture = new BankcardCapture() {TransactionId = authResponse.TransactionId, ChargeType = chargeType};
                    if (ConfigurationManager.AppSettings["IndustryType"] == "MOTO")
                        capture.ShipDate = DateTime.Now;
                    var cList = new List<BankcardCapture>();
                    cList.Add(capture);
                    var capResponse = _txnClient.CaptureAll<BankcardCapture>(_sessionToken, cList, _applicationProfileId, _merchantProfileId, _bcpServiceId);
                    if (capResponse != null)
                        txnIdForReturnById = authResponse.TransactionId;
                }
            }

            if(!string.IsNullOrEmpty(_bcpServiceId) && serviceInfo.BankcardServices.First().Operations.ReturnById && !string.IsNullOrEmpty(txnIdForReturnById))
            {
                Console.WriteLine("\nBankcard Services: Return by id on " + txnIdForReturnById+ "...");
                // Specify an amount in the BankcardReturn if performing a partial return.
                // BankcardTenderData is required for PIN Debit transactions.
                var returnById = new BankcardReturn() {TransactionId = txnIdForReturnById};
                var response = _txnClient.ReturnById(_sessionToken, returnById, _applicationProfileId, _bcpServiceId);
                if (response != null)
                    ScreenPrinter.PrintTransactionResponse(response, "RETURN BY ID (" + txnIdForReturnById+ ")");
            }
            if (!string.IsNullOrEmpty(_bcpServiceId) && serviceInfo.BankcardServices.First().Operations.ReturnUnlinked)
            {
                Console.WriteLine("\nBankcard Services: Return Unlinked Transaction" + "...");
                var response = _txnClient.ReturnUnlinked(_sessionToken, bankcardTransaction, _applicationProfileId,_merchantProfileId, _bcpServiceId);
                if (response != null)
                    ScreenPrinter.PrintTransactionResponse(response, "RETURN UNLINKED");
            }
            if (!string.IsNullOrEmpty(_svaServiceId) && serviceInfo.StoredValueServices.First().Operations.ReturnById && !string.IsNullOrEmpty(txnIdForReturnById))
            {
                Console.WriteLine("\nStored Value Services: Return by id on " + txnIdForReturnById + "...");
                var returnById = new Return() { TransactionId = txnIdForReturnById};
                var response = _txnClient.ReturnById(_sessionToken, returnById, _applicationProfileId, _svaServiceId);
                if (response != null)
                    ScreenPrinter.PrintTransactionResponse(response, "RETURN BY ID (" + txnIdForReturnById + ")");
            }
            if (!string.IsNullOrEmpty(_svaServiceId) && serviceInfo.StoredValueServices.First().Operations.ReturnUnlinked)
            {
                Console.WriteLine("\nStored Value Services: Return Unlinked Transaction" + "...");
                var response = _txnClient.ReturnUnlinked(_sessionToken, svaTransaction, _applicationProfileId, _merchantProfileId, _bcpServiceId);
                if (response != null)
                    ScreenPrinter.PrintTransactionResponse(response, "RETURN UNLINKED");
            }
            #endregion

            #region Step 9: Optional Operations
            // TODO Add Content for optional operations. They can include:
            // Bankcard Processing (BCP): Acknowledge, Disburse, QueryAccount, Verify, RequestTransaction (Leave out Acknowledge and Dispurse in sample)
            // Electronic Checking (ECK): QueryAccount
            // Stored Value Account (SVA): QueryAccount, ManageAccount, ManageAccountById
            #endregion

            #region Transaction Management Services

            Console.WriteLine("\n***Begin Transaction Managment Services***\n");

            var queryTransactionParameters = DataGenerator.CreateQueryTransactionParameters(QueryType.AND);
            var pagingParameters = DataGenerator.CreatePagingParameters();

            // QueryTransactionFamilies
            Console.WriteLine("Querying transaction Families...");
            var queryTransactionFamilies = _mgmtClient.QueryTransactionFamilies(_sessionToken, queryTransactionParameters, pagingParameters);
            ScreenPrinter.PrintTransactionFamilies(queryTransactionFamilies);

            //QueryTransactionsDetails
            var txnIds = new List<string>();
            if (queryTransactionFamilies[0] != null)
                txnIds.Add(queryTransactionFamilies[0].TransactionIds.First());
            if (queryTransactionFamilies[1] != null)
                txnIds.Add(queryTransactionFamilies[1].TransactionIds.First());
            if (queryTransactionFamilies[2] != null)
                txnIds.Add(queryTransactionFamilies[2].TransactionIds.First());

            queryTransactionParameters = DataGenerator.CreateQueryTransactionParameters(QueryType.OR, txnIds);
            queryTransactionParameters.TransactionDateRange = null;
            Console.WriteLine("\nQuery Transaction Details on the first " + txnIds.Count + " transaction ids returned from Query Transaciton Families...");
            var queryTransactionsDetail = _mgmtClient.QueryTransactionsDetail(_sessionToken, queryTransactionParameters, TransactionDetailFormat.CWSTransaction, pagingParameters, includeRelated: false);
            ScreenPrinter.PrintTransactionDetail(queryTransactionsDetail);

            Console.WriteLine("\nQuery Transaction Summaries on the first " + txnIds.Count + " transaction ids returned from Query Transaction Families...");
            var queryTransactionsSummary = _mgmtClient.QueryTransactionsSummary(_sessionToken, queryTransactionParameters, pagingParameters, true);
            ScreenPrinter.PrintTransactionSummary(queryTransactionsSummary);

            Console.WriteLine("\n***End Transaction Managment Services***\n");

            #endregion

            // Cleaning up after the sample code by deleting the merchant profile and the application data.
            Console.WriteLine("\n****CLEAN UP****\n");
            Console.WriteLine("Deleting Merchant Profile " + _merchantProfileId + ".");
            _svcClient.DeleteMerchantProfile(_sessionToken, _bcpServiceId, _merchantProfileId, TenderType.Credit);
            if (!_svcClient.IsMerchantProfileInitialized(_sessionToken, _bcpServiceId, _merchantProfileId, TenderType.Credit))
                Console.WriteLine("Merchant Profile " + _merchantProfileId + " deleted successfully!");

            Console.WriteLine("\nDeleting Application Data for Application Profile Id " + _applicationProfileId + "...");
            _svcClient.DeleteApplicationData(_sessionToken, _applicationProfileId);
            if (_svcClient.GetApplicationData(_sessionToken, _applicationProfileId) == null)
                Console.WriteLine("Application Data deleted successfully!");

            Console.WriteLine("\nPress any key to exit...");
            Console.ReadKey();
        }