Exemplo n.º 1
0
        //public static ANetApiResponse Run(string ApiLoginID, string ApiTransactionKey, string subscriptionId)
        //{
        //    Console.WriteLine("Update Subscription Sample");

        //    ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNET.Environment.SANDBOX;
        //    ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
        //    {
        //        name = ApiLoginID,
        //        ItemElementName = ItemChoiceType.transactionKey,
        //        Item = ApiTransactionKey,
        //    };

        //    paymentScheduleType schedule = new paymentScheduleType
        //    {
        //        startDate = DateTime.Now.AddDays(1),      // start date should be tomorrow
        //        totalOccurrences = 9999                          // 999 indicates no end date
        //    };

        //    #region Payment Information
        //    var creditCard = new creditCardType
        //    {
        //        cardNumber = "4111111111111111",
        //        expirationDate = "0718"
        //    };

        //    //standard api call to retrieve response
        //    paymentType cc = new paymentType { Item = creditCard };
        //    #endregion

        //    nameAndAddressType addressInfo = new nameAndAddressType()
        //    {
        //        firstName = "Calvin",
        //        lastName = "Brown"
        //    };

        //    customerProfileIdType customerProfile = new customerProfileIdType()
        //    {
        //        customerProfileId = "1232312",
        //        customerPaymentProfileId = "2132132",
        //        customerAddressId = "1233432"
        //    };

        //    ARBSubscriptionType subscriptionType = new ARBSubscriptionType()
        //    {
        //        amount = 35.55m,
        //        paymentSchedule = schedule,
        //        billTo = addressInfo,
        //        payment = cc
        //        //You can pass a profile to update subscription
        //        //,profile = customerProfile
        //    };

        //    //Please change the subscriptionId according to your request
        //    var request = new ARBUpdateSubscriptionRequest { subscription = subscriptionType, subscriptionId = subscriptionId };
        //    var controller = new ARBUpdateSubscriptionController(request);
        //    controller.Execute();

        //    ARBUpdateSubscriptionResponse response = controller.GetApiResponse();

        //    //validate
        //    if (response != null && response.messages.resultCode == messageTypeEnum.Ok)
        //    {
        //        if (response != null && response.messages.message != null)
        //        {
        //            Console.WriteLine("Success, RefID Code : " + response.refId);
        //        }
        //    }
        //    else if(response != null)
        //    {
        //        Console.WriteLine("Error: " + response.messages.message[0].code + "  " + response.messages.message[0].text);
        //    }

        //    return response;
        //}
        public static void UpdateSubscriptionExec(String ApiLoginID, String ApiTransactionKey)
        {
            using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/CancleASubscription.csv", FileMode.Open)), true))
            {
                Console.WriteLine("Update Subscription Sample");
                int      flag       = 0;
                int      fieldCount = csv.FieldCount;
                string[] headers    = csv.GetFieldHeaders();
                //Append Data
                var item1 = DataAppend.ReadPrevData();
                using (CsvFileWriter writer = new CsvFileWriter(new FileStream(@"../../../CSV_DATA/Outputfile.csv", FileMode.Open)))
                {
                    while (csv.ReadNextRecord())
                    {
                        // Create Instance of Customer Api
                        ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNET.Environment.SANDBOX;
                        // define the merchant information (authentication / transaction id)
                        ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType()
                        {
                            name            = ApiLoginID,
                            ItemElementName = ItemChoiceType.transactionKey,
                            Item            = ApiTransactionKey,
                        };
                        string subscriptionId           = null;
                        string TestCase_Id              = null;
                        string firstName                = null;
                        string lastName                 = null;
                        string customerProfileId        = null;
                        string customerPaymentProfileId = null;
                        string customerAddressId        = null;
                        string amount = null;
                        for (int i = 0; i < fieldCount; i++)
                        {
                            switch (headers[i])
                            {
                            case "subscriptionId":
                                subscriptionId = csv[i];
                                break;

                            case "firstName":
                                firstName = csv[i];
                                break;

                            case "lastName":
                                lastName = csv[i];
                                break;

                            case "customerProfileId":
                                customerProfileId = csv[i];
                                break;

                            case "customerPaymentProfileId":
                                customerPaymentProfileId = csv[i];
                                break;

                            case "customerAddressId":
                                customerAddressId = csv[i];
                                break;

                            case "amount":
                                amount = csv[i];
                                break;

                            case "TestCase_Id":
                                TestCase_Id = csv[i];
                                break;

                            default:
                                break;
                            }
                        }
                        //Write to output file
                        CsvRow row = new CsvRow();
                        try
                        {
                            if (flag == 0)
                            {
                                row.Add("TestCaseId");
                                row.Add("APIName");
                                row.Add("Status");
                                row.Add("TimeStamp");
                                writer.WriteRow(row);
                                flag = flag + 1;
                                //Append Data
                                foreach (var item in item1)
                                {
                                    writer.WriteRow(item);
                                }
                            }

                            //response = instance.GetCustomer(customerId, authorization);
                            paymentScheduleType schedule = new paymentScheduleType
                            {
                                startDate        = DateTime.Now.AddDays(1), // start date should be tomorrow
                                totalOccurrences = 9999                     // 999 indicates no end date
                            };

                            #region Payment Information
                            var creditCard = new creditCardType
                            {
                                cardNumber     = "4111111111111111",
                                expirationDate = "0718"
                            };

                            //standard api call to retrieve response
                            paymentType cc = new paymentType {
                                Item = creditCard
                            };
                            #endregion

                            nameAndAddressType addressInfo = new nameAndAddressType()
                            {
                                firstName = firstName,
                                lastName  = lastName
                            };

                            customerProfileIdType customerProfile = new customerProfileIdType()
                            {
                                customerProfileId        = customerProfileId,
                                customerPaymentProfileId = customerPaymentProfileId,
                                customerAddressId        = customerAddressId
                            };

                            ARBSubscriptionType subscriptionType = new ARBSubscriptionType()
                            {
                                amount          = Convert.ToDecimal(amount),
                                paymentSchedule = schedule,
                                billTo          = addressInfo,
                                payment         = cc
                                                  //You can pass a profile to update subscription
                                                  //,profile = customerProfile
                            };

                            //Please change the subscriptionId according to your request
                            var request = new ARBUpdateSubscriptionRequest {
                                subscription = subscriptionType, subscriptionId = subscriptionId
                            };
                            var controller = new ARBUpdateSubscriptionController(request);
                            controller.Execute();

                            ARBUpdateSubscriptionResponse response = controller.GetApiResponse();
                            if (response != null && response.messages.resultCode == messageTypeEnum.Ok &&
                                response.messages.message != null)
                            {
                                try
                                {
                                    //Assert.AreEqual(response.Id, customerProfileId);
                                    Console.WriteLine("Assertion Succeed! Valid CustomerId fetched.");
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("UAS_00" + flag.ToString());
                                    row1.Add("UpdateASubscription");
                                    row1.Add("Pass");
                                    row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                    writer.WriteRow(row1);
                                    //  Console.WriteLine("Success " + TestcaseID + " CustomerID : " + response.Id);
                                    flag = flag + 1;
                                    Console.WriteLine("Success, RefID Code : " + response.refId);
                                }
                                catch
                                {
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("UAS_00" + flag.ToString());
                                    row1.Add("UpdateASubscription");
                                    row1.Add("Assertion Failed!");
                                    row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                    writer.WriteRow(row1);
                                    Console.WriteLine("Assertion Failed! Invalid CustomerId fetched.");
                                    flag = flag + 1;
                                }
                            }
                            else
                            {
                                CsvRow row1 = new CsvRow();
                                row1.Add("UAS_00" + flag.ToString());
                                row1.Add("UpdateASubscription");
                                row1.Add("Fail");
                                row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                writer.WriteRow(row1);
                                //Console.WriteLine("Assertion Failed! Invalid CustomerId fetched.");
                                flag = flag + 1;
                            }
                        }
                        catch (Exception e)
                        {
                            CsvRow row2 = new CsvRow();
                            row2.Add("UAS_00" + flag.ToString());
                            row2.Add("UpdateASubscription");
                            row2.Add("Fail");
                            row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                            writer.WriteRow(row2);
                            flag = flag + 1;
                            Console.WriteLine(TestCase_Id + " Error Message " + e.Message);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        //public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, string customerProfileId)
        ////{
        ////    Console.WriteLine("DeleteCustomerProfile Sample");
        ////    ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNET.Environment.SANDBOX;
        ////    ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
        ////    {
        ////        name = ApiLoginID,
        ////        ItemElementName = ItemChoiceType.transactionKey,
        ////        Item = ApiTransactionKey,
        ////    };

        ////    please update the subscriptionId according to your sandbox credentials
        ////    var request = new deleteCustomerProfileRequest
        ////    {
        ////        customerProfileId = customerProfileId
        ////    };

        ////    Prepare Request
        ////    var controller = new deleteCustomerProfileController(request);
        ////    controller.Execute();

        ////    Send Request to EndPoint
        ////    deleteCustomerProfileResponse response = controller.GetApiResponse();
        ////    if (response != null && response.messages.resultCode == messageTypeEnum.Ok)
        ////    {
        ////        if (response != null && response.messages.message != null)
        ////        {
        ////            Console.WriteLine("Success, ResultCode : " + response.messages.resultCode.ToString());
        ////        }
        ////    }
        ////    else if (response != null && response.messages.message != null)
        ////    {
        ////        Console.WriteLine("Error: " + response.messages.message[0].code + "  " + response.messages.message[0].text);
        ////    }

        ////    return response;
        ////}


        public static void DeleteCustomerProfileExec(String ApiLoginID, String ApiTransactionKey)
        {
            using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/DeleteCustomerProfile.csv", FileMode.Open)), true))
            {
                Console.WriteLine("DeleteCustomerProfile Sample");
                int      flag       = 0;
                int      fieldCount = csv.FieldCount;
                string[] headers    = csv.GetFieldHeaders();
                //Append Data
                var item1 = DataAppend.ReadPrevData();
                using (CsvFileWriter writer = new CsvFileWriter(new FileStream(@"../../../CSV_DATA/Outputfile.csv", FileMode.Open)))
                {
                    while (csv.ReadNextRecord())
                    {
                        // Create Instance of Customer Api

                        ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNET.Environment.SANDBOX;
                        // define the merchant information (authentication / transaction id)

                        ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType()
                        {
                            name            = ApiLoginID,
                            ItemElementName = ItemChoiceType.transactionKey,
                            Item            = ApiTransactionKey,
                        };
                        //CustomersApi instance = new CustomersApi(EnvironmentSet.Sandbox);
                        // Customer Response Object
                        // Customer response = null;
                        //initialization



                        string TestcaseID        = null;
                        string customerProfileId = null;


                        for (int i = 0; i < fieldCount; i++)
                        {
                            switch (headers[i])
                            {
                            case "TestcaseID":
                                TestcaseID = csv[i];
                                break;

                            case "customerProfileId":
                                customerProfileId = csv[i];

                                break;

                            default:
                                break;
                            }
                        }

                        //Write to output file
                        CsvRow row = new CsvRow();
                        try
                        {
                            if (flag == 0)
                            {
                                row.Add("TestCaseId");
                                row.Add("APIName");
                                row.Add("Status");
                                row.Add("TimeStamp");
                                writer.WriteRow(row);
                                flag = flag + 1;
                                //Append Data
                                foreach (var item in item1)
                                {
                                    writer.WriteRow(item);
                                }
                            }
                            //response = instance.GetCustomer(customerId, authorization);



                            var request = new deleteCustomerProfileRequest();
                            request.customerProfileId = customerProfileId;

                            // instantiate the controller that will call the service
                            var controller = new deleteCustomerProfileController(request);
                            controller.Execute();
                            deleteCustomerProfileResponse response = controller.GetApiResponse();

                            if (response != null && response.messages.resultCode == messageTypeEnum.Ok &&
                                response.messages.message != null)
                            {
                                try
                                {
                                    //Assert.AreEqual(response.Id, customerProfileId);
                                    //Console.WriteLine("Assertion Succeed! Valid CustomerId fetched.");
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("DCP_00" + flag.ToString());
                                    row1.Add("DeleteCustomerProfile");
                                    row1.Add("Pass");
                                    row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                    writer.WriteRow(row1);
                                    //  Console.WriteLine("Success " + TestcaseID + " CustomerID : " + response.Id);
                                    flag = flag + 1;
                                    Console.WriteLine("Success, ResultCode : " + response.messages.resultCode.ToString());
                                }
                                catch
                                {
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("DCP_00" + flag.ToString());
                                    row1.Add("DeleteCustomerProfile");
                                    row1.Add("Assertion Failed!");
                                    row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                    writer.WriteRow(row1);
                                    //Console.WriteLine("Assertion Failed! Invalid CustomerId fetched.");
                                    flag = flag + 1;
                                }
                            }
                            else
                            {
                                CsvRow row1 = new CsvRow();
                                row1.Add("DCP_00" + flag.ToString());
                                row1.Add("DeleteCustomerProfile");
                                row1.Add("Assertion Failed!");
                                row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                writer.WriteRow(row1);
                                //Console.WriteLine("Assertion Failed! Invalid CustomerId fetched.");
                                flag = flag + 1;
                            }
                        }
                        catch (Exception e)
                        {
                            CsvRow row2 = new CsvRow();
                            row2.Add("DCP_00" + flag.ToString());
                            row2.Add("DeleteCustomerProfile");
                            row2.Add("Fail");
                            row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                            writer.WriteRow(row2);
                            flag = flag + 1;
                            Console.WriteLine(TestcaseID + " Error Message " + e.Message);
                        }
                    }
                }
            }
        }
        //public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, string TransactionID)
        //{
        //    Console.WriteLine("PayPal Prior Authorization Transaction");

        //    ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNET.Environment.SANDBOX;

        //    // define the merchant information (authentication / transaction id)
        //    ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
        //    {
        //        name = ApiLoginID,
        //        ItemElementName = ItemChoiceType.transactionKey,
        //        Item = ApiTransactionKey
        //    };

        //    var payPalType = new payPalType
        //    {
        //        cancelUrl = "http://www.merchanteCommerceSite.com/Success/TC25262",
        //        successUrl = "http://www.merchanteCommerceSite.com/Success/TC25262",     // the url where the user will be returned to
        //    };

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

        //    var transactionRequest = new transactionRequestType
        //    {
        //        transactionType = transactionTypeEnum.priorAuthCaptureTransaction.ToString(),    // capture a prior authorization
        //        payment     = paymentType,
        //        amount      = 19.45m,
        //        refTransId  = TransactionID                                                     // the TransID value that was returned from the first AuthOnlyTransaction call
        //    };

        //    var request = new createTransactionRequest { transactionRequest = transactionRequest };

        //    // instantiate the contoller that will call the service
        //    var controller = new createTransactionController(request);
        //    controller.Execute();

        //    // get the response from the service (errors contained if any)
        //    var response = controller.GetApiResponse();

        //    //validate
        //    if (response != null)
        //    {
        //        if (response.messages.resultCode == messageTypeEnum.Ok)
        //        {
        //            if(response.transactionResponse.messages != null)
        //            {
        //                Console.WriteLine("Successfully created transaction with Transaction ID: " + response.transactionResponse.transId);
        //                Console.WriteLine("Response Code: " + response.transactionResponse.responseCode);
        //                Console.WriteLine("Message Code: " + response.transactionResponse.messages[0].code);
        //                Console.WriteLine("Description: " + response.transactionResponse.messages[0].description);
        //            }
        //            else
        //            {
        //                Console.WriteLine("Failed Transaction.");
        //                if (response.transactionResponse.errors != null)
        //                {
        //                    Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode);
        //                    Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText);
        //                }
        //            }
        //        }
        //        else
        //        {
        //            Console.WriteLine("Failed Transaction.");
        //            if (response.transactionResponse != null && response.transactionResponse.errors != null)
        //            {
        //                Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode);
        //                Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText);
        //            }
        //            else
        //            {
        //                Console.WriteLine("Error Code: " + response.messages.message[0].code);
        //                Console.WriteLine("Error message: " + response.messages.message[0].text);
        //            }
        //        }
        //    }
        //    else
        //    {
        //        Console.WriteLine("Null Response.");
        //    }

        //    return response;
        //}
        public static void PayPalPriorAuthorizationCaptureExec(String ApiLoginID, String ApiTransactionKey)
        {
            using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/PriorAuthorizationCapture.csv", FileMode.Open)), true))
            {
                Console.WriteLine("PayPal Prior Authorization Transaction");
                int      flag       = 0;
                int      fieldCount = csv.FieldCount;
                string[] headers    = csv.GetFieldHeaders();
                //Append Data
                var item1 = DataAppend.ReadPrevData();
                using (CsvFileWriter writer = new CsvFileWriter(new FileStream(@"../../../CSV_DATA/Outputfile.csv", FileMode.Open)))
                {
                    while (csv.ReadNextRecord())
                    {
                        // Create Instance of Customer Api
                        ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNET.Environment.SANDBOX;
                        // define the merchant information (authentication / transaction id)
                        ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType()
                        {
                            name            = ApiLoginID,
                            ItemElementName = ItemChoiceType.transactionKey,
                            Item            = ApiTransactionKey,
                        };
                        string TestCaseId = null;

                        string TransactionID = null;

                        for (int i = 0; i < fieldCount; i++)
                        {
                            switch (headers[i])
                            {
                            case "TransactionID":
                                TransactionID = csv[i];
                                break;


                            case "TestCaseId":
                                TestCaseId = csv[i];
                                break;

                            default:
                                break;
                            }
                        }
                        //Write to output file
                        CsvRow row = new CsvRow();
                        try
                        {
                            if (flag == 0)
                            {
                                row.Add("TestCaseId");
                                row.Add("APIName");
                                row.Add("Status");
                                row.Add("TimeStamp");
                                writer.WriteRow(row);
                                flag = flag + 1;
                                //Append Data
                                foreach (var item in item1)
                                {
                                    writer.WriteRow(item);
                                }
                            }


                            var payPalType = new payPalType
                            {
                                cancelUrl  = "http://www.merchanteCommerceSite.com/Success/TC25262",
                                successUrl = "http://www.merchanteCommerceSite.com/Success/TC25262",     // the url where the user will be returned to
                            };

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

                            var transactionRequest = new transactionRequestType
                            {
                                transactionType = transactionTypeEnum.priorAuthCaptureTransaction.ToString(),    // capture a prior authorization
                                payment         = paymentType,
                                amount          = 19.45m,
                                refTransId      = TransactionID                                                // the TransID value that was returned from the first AuthOnlyTransaction call
                            };

                            var request = new createTransactionRequest {
                                transactionRequest = transactionRequest
                            };

                            // instantiate the contoller that will call the service
                            var controller = new createTransactionController(request);
                            controller.Execute();

                            // get the response from the service (errors contained if any)
                            var response = controller.GetApiResponse();
                            if (response != null && response.messages.resultCode == messageTypeEnum.Ok &&
                                response.transactionResponse.messages != null)
                            {
                                try
                                {
                                    //Assert.AreEqual(response.Id, customerProfileId);
                                    Console.WriteLine("Assertion Succeed! Valid CustomerId fetched.");
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("PAC_00" + flag.ToString());
                                    row1.Add("PriorAuthorizeCapture");
                                    row1.Add("Pass");
                                    row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                    writer.WriteRow(row1);
                                    //  Console.WriteLine("Success " + TestcaseID + " CustomerID : " + response.Id);
                                    flag = flag + 1;
                                    Console.WriteLine("Successfully created transaction with Transaction ID: " + response.transactionResponse.transId);
                                    Console.WriteLine("Response Code: " + response.transactionResponse.responseCode);
                                    Console.WriteLine("Message Code: " + response.transactionResponse.messages[0].code);
                                    Console.WriteLine("Description: " + response.transactionResponse.messages[0].description);
                                }
                                catch
                                {
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("PAC_00" + flag.ToString());
                                    row1.Add("PriorAuthorizeCapture");
                                    row1.Add("Assertion Failed!");
                                    row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                    writer.WriteRow(row1);
                                    Console.WriteLine("Assertion Failed! Invalid CustomerId fetched.");
                                    flag = flag + 1;
                                }
                            }
                            else
                            {
                                CsvRow row1 = new CsvRow();
                                row1.Add("PAC_00" + flag.ToString());
                                row1.Add("PriorAuthorizeCapture");
                                row1.Add("Fail");
                                row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                writer.WriteRow(row1);
                                // Console.WriteLine("Assertion Failed! Invalid CustomerId fetched.");
                                flag = flag + 1;
                            }
                        }
                        catch (Exception e)
                        {
                            CsvRow row2 = new CsvRow();
                            row2.Add("PAC_00" + flag.ToString());
                            row2.Add("PriorAuthorizeCapture");
                            row2.Add("Fail");
                            row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                            writer.WriteRow(row2);
                            flag = flag + 1;
                            Console.WriteLine(TransactionID + " Error Message " + e.Message);
                        }
                    }
                }
            }
        }
        //  public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey)
        //  {
        //      Console.WriteLine("Running VisaCheckoutTransaction Sample ...");
        //      // The test setup.
        //      ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
        //      {
        //          name = ApiLoginID,
        //          ItemElementName = ItemChoiceType.transactionKey,
        //          Item = ApiTransactionKey,
        //      };

        //      ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNET.Environment.SANDBOX;


        //      //set up data based on transaction
        //      var transactionAmount = Convert.ToDecimal(25.60);
        //      var opaqueDataType = new opaqueDataType
        //      {
        //          dataDescriptor = "COMMON.VCO.ONLINE.PAYMENT",
        //          dataKey = "NQzcMISSxLX789w+CGX+tXi3lKntO1dpZbZaREOUprVRByJkg1xnpc2Wx9aT5/BLOxQmHqmIsjjy+tF6HqKKGwovvXjIS3fE3y3tBRNbz8D7y6vYMup+AWbEvZqDEBSi",
        //          dataValue = "+6hn53rUcggeZZti2IdBp3qNLa9ohAH87cFSc1BggZFNEpsrfdJbRViWwv/JbCNkHkOD6CpFlRO3gCDH2VEQTd8laqWR1ccHiZpdYDnOxfhUQpU9E18ZByW7j17puVWogh7HaItbDUL0YvIxxfClX9bohurOo1JHyUgBO9YxTj3CLY2RdRkjmipAQqOyxiGX9enFQjAHdPgKj2RxnVMYe8on5ei94zbtYUbI3fXrp3I+DJcZCGZ4SzrlnPAPpcn20qaIoaOTX/xuD+voRAUKb/KE5oy+CuSNBtyMBgrvWU0Lf3SLjGfE/FJx3Bh9/LABCwWBYQvtpo3DQkDItp8P5/3EOz7JwBFbFd9UQs8wm/J8YvJMd3Kf4MkQ1+KYyg17RH6OAcoNaqQxT3MjOSvVv3KAlKV82ZDco+IRTVPcjyVd/Vff0qDIqes08fPCQDhttefl/bh18urrmCnM9PcP7xJ0A8Ek7LRMLF19c81O7IIaEn0FXxq+UuV5oZArY+mE4GD08xizyd0hoW9pvsdZ7RkuPu4yK1yXPTAKbc3vTxrj0kamFWd4kRHapwLxcvawIQzrlQGQj5AUFkpEg1o1UGWz0vtGgqE08hplJehsTZwPw9KSaA+u5M79gXM3uLR8g2RlE5cEDRLy3aEv0ufeag+lt8zME9wzrfTK8zhjTdBGIAJqSUYto1JbiW9IEMJgjLaqEJhwO49pNlUgOJVp7BXO9JoHPM8PyS+vZlOCX6b0bip/+mCEok09L9B0IhnLjs95Q4kDZfCcQNfDIdLEPe5tLp8eGaSkK3HDoQFbZKCFyGmUTEEF19PScZURbYuGrwpxHqqAAhU87ZmdhRRdJbMTrWPhIvk9/kRzRIP2ciKu8ClNZIJ9azafIUBo7WdlYs+6QbLCn8UCNvYczrLXo3tGhVvHPheWWgmuxDYbHDyJu7SIPKgVvi6LrPYgg8g+I0pMWPojWmBdp85tMt+sQrWk2x325/pOrYXj8fc2W8PHtOAka1EltTdZiNsRKzA8orzLQrtvqtxhzgXMSTOEmosEAxA7DuQdKscL2BWWmiYsAOCNYQxtm/nR6PBAKZ5PDS6Wjk73hKTOeB6kA5E/H1ij15iJqNK6O1+4b4gpJHnHm7tccVQIK5w1EeLR1waqO2G4FMM5FoyA1WsSEQURQncDek0bK1ohcu73l5FLiq8he/H6gF3dEsKL6Z367ki59HKwnnJXfWj/WOUZxTbIho4H5i/lIcc0vSgFH84ReTjjiANEm+ccl5PcFV9wEVlbGXiOiJfeZ0mEzo9ghDyKEAGEDzZtHDwZzKEYyT92oFXkeewGQ6DJX7GSQPZ1MW17jAQODAqmzJcmwMunc7PwGvJcscRbxkXpGe7/asq2H4POz3ByBrBQHCl/+oUVtw8hEbavCpuEgXfWl09Sc3Dfg69UP8XBR80vWsP1YL8YtBxOmL2hinZc5SJZ4boulAOHiMQyKBwwkg2D1gJDEY9JzUJtbg3p06swB0UthNmVuo/1mV8047sB5QrjGCugEo87+vh9eV1EVvyLZLRFS+RIZoIpLR3UkO6Pe1s7MnO7ZvCsbz9sKNb0GtQPoFtU9b7KaCHgQ20vL7xjqTEmR2QwkHEriuGJ8a7oMdSd88w/e2InL1SfHCnS2JeWY9vY6RSTvmjkEf3BFGhHjFP5QRR3Bd8AVH/1YrFcxtSSJP5GeY3CVnJgjZToK+ngxsRzpDcEm6pz3RPUEIBNkk3c9plpdlMbyvuVVKXLSFdTdtAALRfiD9qhdpgGMqboZ0kXi+qn3irYXT19q8oQktoZ4ILkbzewloftLbfUTqQprA8cddy7/ikUKKhBoBVs/DAupRe9aRP3TLgIEz6eNNilZszXoFfUv9EgqOZ0EBb83KNV3HvbE2xGJcTArjRpmzszQQkNOpJnyRDtvPj7FU7K16UYQ9zQBrxnx5vnoWSaqNhzOxikd+hWZ6i5G7EPpCO+utdoMdyOTOoDAjBmiy5JsDHSVv4zvkT9ySYPH2PmS47mMEpZICKTAxuDrm3zTpT064P+7ivcGmaIyaBCkc4udIHaWSbi5XJ/ciXUxSqAtqaVcd5HD++6vjBzKhbAPU4shSBav6qCSp/XqFurEAJbkLB3VmXe7bghcM+VNPJHHiYlIdzndDaFENyaZCukypggK0Gf4cH+8CKI9YnQx9s4JMs4lX57i4IkkoJE7fjWaOHyxYM/AiKvWlMQtRO8Y5Yta454JfHVq7Mg11Wqu2Ex4q5QLNqKudVt3wveu3G1zoNFanW6i+d0Aa3hTdxerl9BacX/"
        //      };

        //      //standard api call to retrieve response
        //      var paymentType = new paymentType { Item = opaqueDataType };
        //      var transactionRequest = new transactionRequestType
        //      {
        //          transactionType = transactionTypeEnum.authCaptureTransaction.ToString(),
        //          payment = paymentType,
        //          amount = transactionAmount,
        //          callId = "1482912778237697701"
        //      };
        //      var request = new createTransactionRequest { transactionRequest = transactionRequest };
        //      var controller = new createTransactionController(request);
        //      controller.Execute();
        //      var response = controller.GetApiResponse();

        //      //validate
        //      if (response != null)
        //      {
        //          if (response.messages.resultCode == messageTypeEnum.Ok)
        //          {
        //              if(response.transactionResponse.messages != null)
        //              {
        //                  Console.WriteLine("Successfully created transaction with Transaction ID: " + response.transactionResponse.transId);
        //                  Console.WriteLine("Response Code: " + response.transactionResponse.responseCode);
        //                  Console.WriteLine("Message Code: " + response.transactionResponse.messages[0].code);
        //                  Console.WriteLine("Description: " + response.transactionResponse.messages[0].description);
        //Console.WriteLine("Success, Auth Code : " + response.transactionResponse.authCode);
        //              }
        //              else
        //              {
        //                  Console.WriteLine("Failed Transaction.");
        //                  if (response.transactionResponse.errors != null)
        //                  {
        //                      Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode);
        //                      Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText);
        //                  }
        //              }
        //          }
        //          else
        //          {
        //              Console.WriteLine("Failed Transaction.");
        //              if (response.transactionResponse != null && response.transactionResponse.errors != null)
        //              {
        //                  Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode);
        //                  Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText);
        //              }
        //              else
        //              {
        //                  Console.WriteLine("Error Code: " + response.messages.message[0].code);
        //                  Console.WriteLine("Error message: " + response.messages.message[0].text);
        //              }
        //          }
        //      }
        //      else
        //      {
        //          Console.WriteLine("Null Response.");
        //      }

        //      return response;

        //  }
        public static void CreateVisaCheckoutTransactionExec(String ApiLoginID, String ApiTransactionKey)
        {
            using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/CreateVisaCheckoutTransaction.csv", FileMode.Open)), true))
            {
                Console.WriteLine("Running VisaCheckoutTransaction Sample ...");
                int      flag       = 0;
                int      fieldCount = csv.FieldCount;
                string[] headers    = csv.GetFieldHeaders();
                //Append data
                var item1 = DataAppend.ReadPrevData();
                using (CsvFileWriter writer = new CsvFileWriter(new FileStream(@"../../../CSV_DATA/Outputfile.csv", FileMode.Open)))
                {
                    while (csv.ReadNextRecord())
                    {
                        // The test setup.


                        ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNET.Environment.SANDBOX;


                        //set up data based on transaction
                        var transactionAmount = Convert.ToDecimal(25.60);
                        var opaqueDataType    = new opaqueDataType
                        {
                            dataDescriptor = "COMMON.VCO.ONLINE.PAYMENT",
                            dataKey        = "NQzcMISSxLX789w+CGX+tXi3lKntO1dpZbZaREOUprVRByJkg1xnpc2Wx9aT5/BLOxQmHqmIsjjy+tF6HqKKGwovvXjIS3fE3y3tBRNbz8D7y6vYMup+AWbEvZqDEBSi",
                            dataValue      = "+6hn53rUcggeZZti2IdBp3qNLa9ohAH87cFSc1BggZFNEpsrfdJbRViWwv/JbCNkHkOD6CpFlRO3gCDH2VEQTd8laqWR1ccHiZpdYDnOxfhUQpU9E18ZByW7j17puVWogh7HaItbDUL0YvIxxfClX9bohurOo1JHyUgBO9YxTj3CLY2RdRkjmipAQqOyxiGX9enFQjAHdPgKj2RxnVMYe8on5ei94zbtYUbI3fXrp3I+DJcZCGZ4SzrlnPAPpcn20qaIoaOTX/xuD+voRAUKb/KE5oy+CuSNBtyMBgrvWU0Lf3SLjGfE/FJx3Bh9/LABCwWBYQvtpo3DQkDItp8P5/3EOz7JwBFbFd9UQs8wm/J8YvJMd3Kf4MkQ1+KYyg17RH6OAcoNaqQxT3MjOSvVv3KAlKV82ZDco+IRTVPcjyVd/Vff0qDIqes08fPCQDhttefl/bh18urrmCnM9PcP7xJ0A8Ek7LRMLF19c81O7IIaEn0FXxq+UuV5oZArY+mE4GD08xizyd0hoW9pvsdZ7RkuPu4yK1yXPTAKbc3vTxrj0kamFWd4kRHapwLxcvawIQzrlQGQj5AUFkpEg1o1UGWz0vtGgqE08hplJehsTZwPw9KSaA+u5M79gXM3uLR8g2RlE5cEDRLy3aEv0ufeag+lt8zME9wzrfTK8zhjTdBGIAJqSUYto1JbiW9IEMJgjLaqEJhwO49pNlUgOJVp7BXO9JoHPM8PyS+vZlOCX6b0bip/+mCEok09L9B0IhnLjs95Q4kDZfCcQNfDIdLEPe5tLp8eGaSkK3HDoQFbZKCFyGmUTEEF19PScZURbYuGrwpxHqqAAhU87ZmdhRRdJbMTrWPhIvk9/kRzRIP2ciKu8ClNZIJ9azafIUBo7WdlYs+6QbLCn8UCNvYczrLXo3tGhVvHPheWWgmuxDYbHDyJu7SIPKgVvi6LrPYgg8g+I0pMWPojWmBdp85tMt+sQrWk2x325/pOrYXj8fc2W8PHtOAka1EltTdZiNsRKzA8orzLQrtvqtxhzgXMSTOEmosEAxA7DuQdKscL2BWWmiYsAOCNYQxtm/nR6PBAKZ5PDS6Wjk73hKTOeB6kA5E/H1ij15iJqNK6O1+4b4gpJHnHm7tccVQIK5w1EeLR1waqO2G4FMM5FoyA1WsSEQURQncDek0bK1ohcu73l5FLiq8he/H6gF3dEsKL6Z367ki59HKwnnJXfWj/WOUZxTbIho4H5i/lIcc0vSgFH84ReTjjiANEm+ccl5PcFV9wEVlbGXiOiJfeZ0mEzo9ghDyKEAGEDzZtHDwZzKEYyT92oFXkeewGQ6DJX7GSQPZ1MW17jAQODAqmzJcmwMunc7PwGvJcscRbxkXpGe7/asq2H4POz3ByBrBQHCl/+oUVtw8hEbavCpuEgXfWl09Sc3Dfg69UP8XBR80vWsP1YL8YtBxOmL2hinZc5SJZ4boulAOHiMQyKBwwkg2D1gJDEY9JzUJtbg3p06swB0UthNmVuo/1mV8047sB5QrjGCugEo87+vh9eV1EVvyLZLRFS+RIZoIpLR3UkO6Pe1s7MnO7ZvCsbz9sKNb0GtQPoFtU9b7KaCHgQ20vL7xjqTEmR2QwkHEriuGJ8a7oMdSd88w/e2InL1SfHCnS2JeWY9vY6RSTvmjkEf3BFGhHjFP5QRR3Bd8AVH/1YrFcxtSSJP5GeY3CVnJgjZToK+ngxsRzpDcEm6pz3RPUEIBNkk3c9plpdlMbyvuVVKXLSFdTdtAALRfiD9qhdpgGMqboZ0kXi+qn3irYXT19q8oQktoZ4ILkbzewloftLbfUTqQprA8cddy7/ikUKKhBoBVs/DAupRe9aRP3TLgIEz6eNNilZszXoFfUv9EgqOZ0EBb83KNV3HvbE2xGJcTArjRpmzszQQkNOpJnyRDtvPj7FU7K16UYQ9zQBrxnx5vnoWSaqNhzOxikd+hWZ6i5G7EPpCO+utdoMdyOTOoDAjBmiy5JsDHSVv4zvkT9ySYPH2PmS47mMEpZICKTAxuDrm3zTpT064P+7ivcGmaIyaBCkc4udIHaWSbi5XJ/ciXUxSqAtqaVcd5HD++6vjBzKhbAPU4shSBav6qCSp/XqFurEAJbkLB3VmXe7bghcM+VNPJHHiYlIdzndDaFENyaZCukypggK0Gf4cH+8CKI9YnQx9s4JMs4lX57i4IkkoJE7fjWaOHyxYM/AiKvWlMQtRO8Y5Yta454JfHVq7Mg11Wqu2Ex4q5QLNqKudVt3wveu3G1zoNFanW6i+d0Aa3hTdxerl9BacX/"
                        };

                        //standard api call to retrieve response
                        var paymentType = new paymentType {
                            Item = opaqueDataType
                        };
                        var transactionRequest = new transactionRequestType
                        {
                            transactionType = transactionTypeEnum.authCaptureTransaction.ToString(),
                            payment         = paymentType,
                            amount          = transactionAmount,
                            callId          = "1482912778237697701"
                        };
                        string apiLogin       = null;
                        string transactionKey = null;
                        string TestcaseID     = null;
                        //int count = 0;
                        for (int i = 0; i < fieldCount; i++)
                        {
                            // Read the headers with values from the test data input file
                            switch (headers[i])
                            {
                            case "apiLogin":
                                apiLogin = csv[i];
                                break;

                            case "transactionKey":
                                transactionKey = csv[i];
                                break;

                            case "TestcaseID":
                                TestcaseID = csv[i];
                                //count++;
                                break;

                            default:
                                break;
                            }
                        }
                        ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType()
                        {
                            name            = apiLogin,
                            ItemElementName = ItemChoiceType.transactionKey,
                            Item            = transactionKey,
                        };
                        CsvRow row = new CsvRow();
                        try
                        {
                            if (flag == 0)
                            {
                                row.Add("TestCaseId");
                                row.Add("APIName");
                                row.Add("Status");
                                row.Add("TimeStamp");
                                writer.WriteRow(row);
                                flag = flag + 1;
                                //Append Result
                                foreach (var item in item1)
                                {
                                    writer.WriteRow(item);
                                }
                            }

                            var request = new createTransactionRequest {
                                transactionRequest = transactionRequest
                            };
                            var controller = new createTransactionController(request);
                            controller.Execute();
                            var response = controller.GetApiResponse();

                            //validate
                            //if (response != null)
                            //{
                            if (response != null && response.messages.resultCode == messageTypeEnum.Ok &&
                                response.transactionResponse.messages != null)
                            {
                                /*****************************/
                                try
                                {
                                    //Assert.AreEqual(response.Id, customerProfileId);
                                    //Console.WriteLine("Assertion Succeed! Valid customerProfileId fetched.");
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("CVCT_00" + flag.ToString());
                                    row1.Add("CreateVisaCheckoutTransaction");
                                    row1.Add("Pass");
                                    row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                    writer.WriteRow(row1);
                                    //  Console.WriteLine("Success " + TestcaseID + " CustomerID : " + response.Id);
                                    flag = flag + 1;

                                    Console.WriteLine("Successfully created transaction with Transaction ID: " + response.transactionResponse.transId);
                                    Console.WriteLine("Response Code: " + response.transactionResponse.responseCode);
                                    Console.WriteLine("Message Code: " + response.transactionResponse.messages[0].code);
                                    Console.WriteLine("Description: " + response.transactionResponse.messages[0].description);
                                    Console.WriteLine("Success, Auth Code : " + response.transactionResponse.authCode);
                                }
                                catch
                                {
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("CVCT_00" + flag.ToString());
                                    row1.Add("CreateVisaCheckoutTransaction");
                                    row1.Add("Fail");
                                    row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                    writer.WriteRow(row1);
                                    //Console.WriteLine("Assertion Failed! Invalid CustomerPaymentProfile fetched.");
                                    flag = flag + 1;
                                }
                            }
                            /*******************/
                            else
                            {
                                Console.WriteLine("Failed Transaction.");
                                CsvRow row2 = new CsvRow();
                                row2.Add("CVCT_00" + flag.ToString());
                                row2.Add("CreateVisaCheckoutTransaction");
                                row2.Add("Fail");
                                row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                writer.WriteRow(row2);
                                flag = flag + 1;
                                //if (response.transactionResponse.errors != null)
                                //{
                                //    Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode);
                                //    Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText);
                                //}
                            }
                            //}
                            //else
                            //{
                            //    Console.WriteLine("Failed Transaction.");
                            //    if (response.transactionResponse != null && response.transactionResponse.errors != null)
                            //    {
                            //        Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode);
                            //        Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText);
                            //    }
                            //    else
                            //    {
                            //        Console.WriteLine("Error Code: " + response.messages.message[0].code);
                            //        Console.WriteLine("Error message: " + response.messages.message[0].text);
                            //    }
                            //}
                            //}
                            //else
                            //{
                            //    Console.WriteLine("Null Response.");
                            //}

                            //return response;
                        }

                        //return response;
                        catch (Exception e)
                        {
                            CsvRow row2 = new CsvRow();
                            row2.Add("CVCT_00" + flag.ToString());
                            row2.Add("CreateVisaCheckoutTransaction");
                            row2.Add("Fail");
                            row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                            writer.WriteRow(row2);
                            flag = flag + 1;
                            //Console.WriteLine(TestCaseId + " Error Message " + e.Message);
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        //  public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, decimal amount)
        //  {
        //      Console.WriteLine("Charge Credit Card Sample");

        //      ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNET.Environment.SANDBOX;

        //      // define the merchant information (authentication / transaction id)
        //      ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
        //      {
        //          name = ApiLoginID,
        //          ItemElementName = ItemChoiceType.transactionKey,
        //          Item = ApiTransactionKey,
        //      };

        //      var creditCard = new creditCardType
        //      {
        //          cardNumber = "4111111111111111",
        //          expirationDate = "0718",
        //          cardCode = "123"
        //      };

        //      var billingAddress = new customerAddressType
        //      {
        //          firstName = "John",
        //          lastName = "Doe",
        //          address = "123 My St",
        //          city = "OurTown",
        //          zip = "98004"
        //      };

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

        //      // Add line Items
        //      var lineItems = new lineItemType[2];
        //      lineItems[0] = new lineItemType { itemId = "1", name = "t-shirt", quantity = 2, unitPrice = new Decimal(15.00) };
        //      lineItems[1] = new lineItemType { itemId = "2", name = "snowboard", quantity = 1, unitPrice = new Decimal(450.00) };

        //      var transactionRequest = new transactionRequestType
        //      {
        //          transactionType = transactionTypeEnum.authCaptureTransaction.ToString(),    // charge the card

        //          amount = amount,
        //          payment = paymentType,
        //          billTo = billingAddress,
        //          lineItems = lineItems
        //      };

        //      var request = new createTransactionRequest { transactionRequest = transactionRequest };

        //      // instantiate the contoller that will call the service
        //      var controller = new createTransactionController(request);
        //      controller.Execute();

        //      // get the response from the service (errors contained if any)
        //      var response = controller.GetApiResponse();

        //      //validate
        //      if (response != null)
        //      {
        //          if (response.messages.resultCode == messageTypeEnum.Ok)
        //          {
        //              if(response.transactionResponse.messages != null)
        //              {
        //                  Console.WriteLine("Successfully created transaction with Transaction ID: " + response.transactionResponse.transId);
        //                  Console.WriteLine("Response Code: " + response.transactionResponse.responseCode);
        //                  Console.WriteLine("Message Code: " + response.transactionResponse.messages[0].code);
        //                  Console.WriteLine("Description: " + response.transactionResponse.messages[0].description);
        //Console.WriteLine("Success, Auth Code : " + response.transactionResponse.authCode);
        //              }
        //              else
        //              {
        //                  Console.WriteLine("Failed Transaction.");
        //                  if (response.transactionResponse.errors != null)
        //                  {
        //                      Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode);
        //                      Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText);
        //                  }
        //              }
        //          }
        //          else
        //          {
        //              Console.WriteLine("Failed Transaction.");
        //              if (response.transactionResponse != null && response.transactionResponse.errors != null)
        //              {
        //                  Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode);
        //                  Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText);
        //              }
        //              else
        //              {
        //                  Console.WriteLine("Error Code: " + response.messages.message[0].code);
        //                  Console.WriteLine("Error message: " + response.messages.message[0].text);
        //              }
        //          }
        //      }
        //      else
        //      {
        //          Console.WriteLine("Null Response.");
        //      }

        //      return response;
        //  }

        public static void ChargeCreditCardExec(String ApiLoginID, String ApiTransactionKey)
        {
            using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/ChargeCreditCard.csv", FileMode.Open)), true))
            {
                Console.WriteLine("Charge Credit Card Sample");
                int      flag       = 0;
                int      fieldCount = csv.FieldCount;
                string[] headers    = csv.GetFieldHeaders();
                //Append Data
                var item1 = DataAppend.ReadPrevData();
                using (CsvFileWriter writer = new CsvFileWriter(new FileStream(@"../../../CSV_DATA/Outputfile.csv", FileMode.Open)))
                {
                    while (csv.ReadNextRecord())
                    {
                        // Create Instance of Customer Api

                        ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNET.Environment.SANDBOX;
                        // define the merchant information (authentication / transaction id)

                        ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType()
                        {
                            name            = ApiLoginID,
                            ItemElementName = ItemChoiceType.transactionKey,
                            Item            = ApiTransactionKey,
                        };
                        string TestcaseID = null;
                        string amount     = null;
                        for (int i = 0; i < fieldCount; i++)
                        {
                            switch (headers[i])
                            {
                            case "TestcaseID":
                                TestcaseID = csv[i];
                                break;

                            case "amount":
                                amount = csv[i];
                                break;

                            default:
                                break;
                            }
                        }

                        //Write to output file
                        CsvRow row = new CsvRow();
                        try
                        {
                            if (flag == 0)
                            {
                                row.Add("TestCaseId");
                                row.Add("APIName");
                                row.Add("Status");
                                row.Add("TimeStamp");
                                writer.WriteRow(row);
                                flag = flag + 1;
                                //Append Data
                                foreach (var item in item1)
                                {
                                    writer.WriteRow(item);
                                }
                            }
                            //response = instance.GetCustomer(customerId, authorization);

                            var creditCard = new creditCardType
                            {
                                cardNumber     = "4111111111111111",
                                expirationDate = "0718",
                                cardCode       = "123"
                            };

                            var billingAddress = new customerAddressType
                            {
                                firstName = "John",
                                lastName  = "Doe",
                                address   = "123 My St",
                                city      = "OurTown",
                                zip       = "98004"
                            };

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

                            // Add line Items
                            var lineItems = new lineItemType[2];
                            lineItems[0] = new lineItemType {
                                itemId = "1", name = "t-shirt", quantity = 2, unitPrice = new Decimal(15.00)
                            };
                            lineItems[1] = new lineItemType {
                                itemId = "2", name = "snowboard", quantity = 1, unitPrice = new Decimal(450.00)
                            };

                            var transactionRequest = new transactionRequestType
                            {
                                transactionType = transactionTypeEnum.authCaptureTransaction.ToString(),    // charge the card

                                amount    = Convert.ToDecimal(amount),
                                payment   = paymentType,
                                billTo    = billingAddress,
                                lineItems = lineItems
                            };

                            var request = new createTransactionRequest {
                                transactionRequest = transactionRequest
                            };

                            // instantiate the contoller that will call the service
                            var controller = new createTransactionController(request);
                            controller.Execute();

                            // get the response from the service (errors contained if any)
                            var response = controller.GetApiResponse();



                            if (response != null && response.messages.resultCode == messageTypeEnum.Ok &&
                                response.transactionResponse.messages != null)
                            {
                                try
                                {
                                    //Assert.AreEqual(response.Id, customerProfileId);
                                    Console.WriteLine("Assertion Succeed! Valid CustomerId fetched.");
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("CCC_00" + flag.ToString());
                                    row1.Add("ChargeCreditCard");
                                    row1.Add("Pass");
                                    row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                    writer.WriteRow(row1);
                                    //  Console.WriteLine("Success " + TestcaseID + " CustomerID : " + response.Id);
                                    flag = flag + 1;
                                    Console.WriteLine("Successfully created transaction with Transaction ID: " + response.transactionResponse.transId);
                                    Console.WriteLine("Response Code: " + response.transactionResponse.responseCode);
                                    Console.WriteLine("Message Code: " + response.transactionResponse.messages[0].code);
                                    Console.WriteLine("Description: " + response.transactionResponse.messages[0].description);
                                    Console.WriteLine("Success, Auth Code : " + response.transactionResponse.authCode);
                                }
                                catch
                                {
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("CCC_00" + flag.ToString());
                                    row1.Add("ChargeCreditCard");
                                    row1.Add("Assertion Failed!");
                                    row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                    writer.WriteRow(row1);
                                    Console.WriteLine("Assertion Failed! Invalid CustomerId fetched.");
                                    flag = flag + 1;
                                }
                            }
                            else
                            {
                                CsvRow row1 = new CsvRow();
                                row1.Add("CCC_00" + flag.ToString());
                                row1.Add("ChargeCreditCard");
                                row1.Add("Assertion Failed!");
                                row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                writer.WriteRow(row1);
                                Console.WriteLine("Assertion Failed! Invalid CustomerId fetched.");
                                flag = flag + 1;
                            }
                        }
                        catch (Exception e)
                        {
                            CsvRow row2 = new CsvRow();
                            row2.Add("CCC_00" + flag.ToString());
                            row2.Add("ChargeCreditCard");
                            row2.Add("Fail");
                            row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                            writer.WriteRow(row2);
                            flag = flag + 1;
                            Console.WriteLine(TestcaseID + " Error Message " + e.Message);
                        }
                    }
                }
            }
        }
        //public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey)
        //{
        //    Console.WriteLine("Get unsettled transaction list sample");

        //    ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNET.Environment.SANDBOX;
        //    // define the merchant information (authentication / transaction id)
        //    ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
        //    {
        //        name = ApiLoginID,
        //        ItemElementName = ItemChoiceType.transactionKey,
        //        Item = ApiTransactionKey,
        //    };

        //    var request = new getUnsettledTransactionListRequest();
        //    request.status  = TransactionGroupStatusEnum.any;
        //    request.statusSpecified = true;
        //    request.paging = new Paging
        //    {
        //        limit = 10,
        //        offset = 1
        //    };
        //    request.sorting = new TransactionListSorting
        //    {
        //        orderBy = TransactionListOrderFieldEnum.id,
        //        orderDescending = true
        //    };
        //    // instantiate the controller that will call the service
        //    var controller = new getUnsettledTransactionListController(request);
        //    controller.Execute();

        //    // get the response from the service (errors contained if any)
        //    var response = controller.GetApiResponse();
        //    if (response != null && response.messages.resultCode == messageTypeEnum.Ok)
        //    {
        //        if (response.transactions == null)
        //            return response;

        //        foreach (var item in response.transactions)
        //        {
        //            Console.WriteLine("Transaction Id: {0} was submitted on {1}", item.transId,
        //                item.submitTimeLocal);
        //        }
        //    }
        //    else if(response != null)
        //    {
        //        Console.WriteLine("Error: " + response.messages.message[0].code + "  " +
        //                          response.messages.message[0].text);
        //    }

        //    return response;
        //}

        public static void GetUnsettledTransactionListExec(String ApiLoginID, String ApiTransactionKey)
        {
            using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/GetUnsettledTransactionList.csv", FileMode.Open)), true))
            {
                Console.WriteLine("Get unsettled transaction list sample");

                int      flag       = 0;
                int      fieldCount = csv.FieldCount;
                string[] headers    = csv.GetFieldHeaders();
                //Append data
                var item1 = DataAppend.ReadPrevData();
                using (CsvFileWriter writer = new CsvFileWriter(new FileStream(@"../../../CSV_DATA/Outputfile.csv", FileMode.Open)))
                {
                    while (csv.ReadNextRecord())
                    {
                        ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNET.Environment.SANDBOX;
                        // define the merchant information (authentication / transaction id)


                        string apiLogin       = null;
                        string transactionKey = null;
                        string TestcaseID     = null;
                        //int count = 0;
                        for (int i = 0; i < fieldCount; i++)
                        {
                            // Read the headers with values from the test data input file
                            switch (headers[i])
                            {
                            case "apiLogin":
                                apiLogin = csv[i];
                                break;

                            case "transactionKey":
                                transactionKey = csv[i];
                                break;

                            case "TestcaseID":
                                TestcaseID = csv[i];
                                //count++;
                                break;

                            default:
                                break;
                            }
                        }
                        ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType()
                        {
                            name            = apiLogin,
                            ItemElementName = ItemChoiceType.transactionKey,
                            Item            = transactionKey,
                        };
                        CsvRow row = new CsvRow();
                        try
                        {
                            if (flag == 0)
                            {
                                row.Add("TestCaseId");
                                row.Add("APIName");
                                row.Add("Status");
                                row.Add("TimeStamp");
                                writer.WriteRow(row);
                                flag = flag + 1;
                                //Append Result
                                foreach (var item in item1)
                                {
                                    writer.WriteRow(item);
                                }
                            }
                            var request = new getUnsettledTransactionListRequest();
                            request.status          = TransactionGroupStatusEnum.any;
                            request.statusSpecified = true;
                            request.paging          = new Paging
                            {
                                limit  = 10,
                                offset = 1
                            };
                            request.sorting = new TransactionListSorting
                            {
                                orderBy         = TransactionListOrderFieldEnum.id,
                                orderDescending = true
                            };
                            // instantiate the controller that will call the service
                            var controller = new getUnsettledTransactionListController(request);
                            controller.Execute();

                            // get the response from the service (errors contained if any)
                            var response = controller.GetApiResponse();
                            if (response != null && response.messages.resultCode == messageTypeEnum.Ok &&
                                response.transactions != null)
                            {
                                /*****************************/
                                try
                                {
                                    //Assert.AreEqual(response.Id, customerProfileId);
                                    //Console.WriteLine("Assertion Succeed! Valid customerProfileId fetched.");
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("GUTL_00" + flag.ToString());
                                    row1.Add("GetUnsettledTransactionList");
                                    row1.Add("Pass");
                                    row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                    writer.WriteRow(row1);
                                    //  Console.WriteLine("Success " + TestcaseID + " CustomerID : " + response.Id);
                                    flag = flag + 1;

                                    foreach (var item in response.transactions)
                                    {
                                        Console.WriteLine("Transaction Id: {0} was submitted on {1}", item.transId,
                                                          item.submitTimeLocal);
                                    }
                                }
                                catch
                                {
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("GUTL_00" + flag.ToString());
                                    row1.Add("GetUnsettledTransactionList");
                                    row1.Add("Assertion Failed!");
                                    row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                    writer.WriteRow(row1);
                                    //Console.WriteLine("Assertion Failed! Invalid CustomerPaymentProfile fetched.");
                                    flag = flag + 1;
                                }
                                /*******************/
                                //if (response.transactions != null)
                                //    //return response;

                                //foreach (var item in response.transactions)
                                //{
                                //    Console.WriteLine("Transaction Id: {0} was submitted on {1}", item.transId,
                                //        item.submitTimeLocal);
                                //}
                            }
                            else
                            {
                                Console.WriteLine("Null response");
                                CsvRow row2 = new CsvRow();
                                row2.Add("GUTL_00" + flag.ToString());
                                row2.Add("GetUnsettledTransactionList");
                                row2.Add("Fail");
                                row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                writer.WriteRow(row2);
                                flag = flag + 1;
                            }
                            //else if (response != null)
                            //{
                            //    Console.WriteLine("Error: " + response.messages.message[0].code + "  " +
                            //                      response.messages.message[0].text);
                            //}
                        }
                        //return response;
                        catch (Exception e)
                        {
                            CsvRow row2 = new CsvRow();
                            row2.Add("GUTL_00" + flag.ToString());
                            row2.Add("GetUnsettledTransactionList");
                            row2.Add("Fail");
                            row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                            writer.WriteRow(row2);
                            flag = flag + 1;
                            //Console.WriteLine(TestCaseId + " Error Message " + e.Message);
                        }
                    }
                }
            }
        }
Exemplo n.º 7
0
        //public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey)
        //{
        //    Console.WriteLine("Get Merchant Details Sample");

        //    ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNET.Environment.SANDBOX;

        //    var request = new getMerchantDetailsRequest
        //    {
        //        merchantAuthentication = new merchantAuthenticationType() { name = ApiLoginID, Item = ApiTransactionKey, ItemElementName = ItemChoiceType.transactionKey }
        //    };

        //    // instantiate the controller that will call the service
        //    var controller = new getMerchantDetailsController(request);
        //    controller.Execute();

        //    // get the response from the service (errors contained if any)
        //    var response = controller.GetApiResponse();

        //    // validate
        //    if (response != null)
        //    {
        //        if (response.messages.resultCode == messageTypeEnum.Ok)
        //        {
        //            Console.WriteLine("Merchant Name: " + response.merchantName);
        //            Console.WriteLine("Gateway ID: " + response.gatewayId);
        //            Console.Write("Processors: ");
        //            foreach (processorType processor in response.processors)
        //            {
        //                Console.Write(processor.name + "; ");
        //            }
        //        }
        //        else
        //        {
        //            Console.WriteLine("Failed to get merchant details.");
        //        }
        //    }
        //    else
        //    {
        //        Console.WriteLine("Null Response.");
        //    }

        //    return response;
        //}

        public static void GetMerchantDetailsExec(String ApiLoginID, String ApiTransactionKey)
        {
            using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/GetMerchantDetails.csv", FileMode.Open)), true))
            {
                Console.WriteLine("Get Merchant Details Sample");

                int      flag       = 0;
                int      fieldCount = csv.FieldCount;
                string[] headers    = csv.GetFieldHeaders();

                //Append data
                var item1 = DataAppend.ReadPrevData();
                using (CsvFileWriter writer = new CsvFileWriter(new FileStream(@"../../../CSV_DATA/Outputfile.csv", FileMode.Open)))
                {
                    while (csv.ReadNextRecord())
                    {
                        ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNET.Environment.SANDBOX;

                        string apiLogin       = null;
                        string transactionKey = null;
                        string TestcaseID     = null;
                        int    count          = 0;
                        for (int i = 0; i < fieldCount; i++)
                        {
                            // Read the headers with values from the test data input file
                            switch (headers[i])
                            {
                            case "apiLogin":
                                apiLogin = csv[i];
                                break;

                            case "transactionKey":
                                transactionKey = csv[i];
                                break;

                            case "TestcaseID":
                                TestcaseID = csv[i];
                                count++;
                                break;

                            default:
                                break;
                            }
                        }
                        var request = new getMerchantDetailsRequest
                        {
                            merchantAuthentication = new merchantAuthenticationType()
                            {
                                name            = apiLogin,
                                Item            = transactionKey,
                                ItemElementName = ItemChoiceType.transactionKey
                            }
                        };
                        CsvRow row = new CsvRow();
                        try
                        {
                            if (flag == 0)
                            {
                                row.Add("TestCaseId");
                                row.Add("APIName");
                                row.Add("Status");
                                row.Add("TimeStamp");
                                writer.WriteRow(row);
                                //Append Result
                                foreach (var item in item1)
                                {
                                    writer.WriteRow(item);
                                }
                                flag = flag + 1;
                            }
                            // instantiate the controller that will call the service
                            var controller = new getMerchantDetailsController(request);
                            controller.Execute();

                            // get the response from the service (errors contained if any)
                            var response = controller.GetApiResponse();

                            // validate
                            if (response != null && response.messages.resultCode == messageTypeEnum.Ok)
                            {
                                //if (response.messages.resultCode == messageTypeEnum.Ok)
                                //{
                                /*****************************/
                                try
                                {
                                    //Assert.AreEqual(response.Id, customerProfileId);
                                    //Console.WriteLine("Assertion Succeed! Valid customerProfileId fetched.");
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("GMD_00" + flag.ToString());
                                    row1.Add("GetMerchantDetails");
                                    row1.Add("Pass");
                                    row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                    writer.WriteRow(row1);
                                    //  Console.WriteLine("Success " + TestcaseID + " CustomerID : " + response.Id);
                                    flag = flag + 1;

                                    //Console.WriteLine("Merchant Name: " + response.merchantName);
                                    //Console.WriteLine("Gateway ID: " + response.gatewayId);
                                    //Console.Write("Processors: ");
                                    //foreach (processorType processor in response.processors)
                                    //{
                                    //    Console.Write(processor.name + "; ");
                                    //}
                                }
                                catch
                                {
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("GMD_00" + flag.ToString());
                                    row1.Add("GetMerchantDetails");
                                    row1.Add("Assertion Failed!");
                                    row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                    writer.WriteRow(row1);
                                    //Console.WriteLine("Assertion Failed! Invalid CustomerPaymentProfile fetched.");
                                    flag = flag + 1;
                                }
                                /*******************/

                                //}
                                //else
                                //{
                                //    Console.WriteLine("Failed to get merchant details.");
                                //}
                            }
                            else
                            {
                                Console.WriteLine("Null Response.");
                                CsvRow row2 = new CsvRow();
                                row2.Add("GMD_00" + flag.ToString());
                                row2.Add("GetMerchantDetails");
                                row2.Add("Fail");
                                row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                writer.WriteRow(row2);
                                flag = flag + 1;
                            }
                        }

                        //return response;
                        catch (Exception e)
                        {
                            CsvRow row2 = new CsvRow();
                            row2.Add("GMD_00" + flag.ToString());
                            row2.Add("GetMerchantDetails");
                            row2.Add("Fail");
                            row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                            writer.WriteRow(row2);
                            flag = flag + 1;
                            //Console.WriteLine(TestCaseId + " Error Message " + e.Message);
                        }
                    }
                }
            }
        }
Exemplo n.º 8
0
        //  public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, decimal Amount)
        //  {
        //      Console.WriteLine("Debit Bank Account Transaction");

        //      ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNET.Environment.SANDBOX;

        //      // define the merchant information (authentication / transaction id)
        //      ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
        //      {
        //          name = ApiLoginID,
        //          ItemElementName = ItemChoiceType.transactionKey,
        //          Item = ApiTransactionKey
        //      };

        //      var bankAccount = new bankAccountType
        //      {
        //          accountNumber   = "4111111",
        //          routingNumber   = "325070760",
        //          echeckType      = echeckTypeEnum.WEB,   // change based on how you take the payment (web, telephone, etc)
        //          nameOnAccount   = "Test Name"
        //      };

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

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

        //      var request = new createTransactionRequest { transactionRequest = transactionRequest };

        //      // instantiate the contoller that will call the service
        //      var controller = new createTransactionController(request);
        //      controller.Execute();

        //      // get the response from the service (errors contained if any)
        //      var response = controller.GetApiResponse();

        //      //validate
        //      if (response != null)
        //      {
        //          if (response.messages.resultCode == messageTypeEnum.Ok)
        //          {
        //              if(response.transactionResponse.messages != null)
        //              {
        //                  Console.WriteLine("Successfully created transaction with Transaction ID: " + response.transactionResponse.transId);
        //                  Console.WriteLine("Response Code: " + response.transactionResponse.responseCode);
        //                  Console.WriteLine("Message Code: " + response.transactionResponse.messages[0].code);
        //                  Console.WriteLine("Description: " + response.transactionResponse.messages[0].description);
        //Console.WriteLine("Success, Transaction Code : " + response.transactionResponse.transId);
        //              }
        //              else
        //              {
        //                  Console.WriteLine("Failed Transaction.");
        //                  if (response.transactionResponse.errors != null)
        //                  {
        //                      Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode);
        //                      Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText);
        //                  }
        //              }
        //          }
        //          else
        //          {
        //              Console.WriteLine("Failed Transaction.");
        //              if (response.transactionResponse != null && response.transactionResponse.errors != null)
        //              {
        //                  Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode);
        //                  Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText);
        //              }
        //              else
        //              {
        //                  Console.WriteLine("Error Code: " + response.messages.message[0].code);
        //                  Console.WriteLine("Error message: " + response.messages.message[0].text);
        //              }
        //          }
        //      }
        //      else
        //      {
        //          Console.WriteLine("Null Response.");
        //      }

        //      return response;
        //  }

        public static void DebitBankAccountExec(String ApiLoginID, String ApiTransactionKey)
        {
            using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/DebitBankAccount.csv", FileMode.Open)), true))
            {
                Console.WriteLine("Debit Bank Account Transaction");
                int      flag       = 0;
                int      fieldCount = csv.FieldCount;
                string[] headers    = csv.GetFieldHeaders();
                //Append data
                var item1 = DataAppend.ReadPrevData();
                using (CsvFileWriter writer = new CsvFileWriter(new FileStream(@"../../../CSV_DATA/Outputfile.csv", FileMode.Open)))
                {
                    while (csv.ReadNextRecord())
                    {
                        ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNET.Environment.SANDBOX;

                        // define the merchant information (authentication / transaction id)
                        ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType()
                        {
                            name            = ApiLoginID,
                            ItemElementName = ItemChoiceType.transactionKey,
                            Item            = ApiTransactionKey
                        };

                        var bankAccount = new bankAccountType
                        {
                            accountNumber = "4111111",
                            routingNumber = "325070760",
                            echeckType    = echeckTypeEnum.WEB, // change based on how you take the payment (web, telephone, etc)
                            nameOnAccount = "Test Name"
                        };

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

                        string amount     = null;
                        string TestCaseId = null;
                        for (int i = 0; i < fieldCount; i++)
                        {
                            switch (headers[i])
                            {
                            case "TestCaseId":
                                TestCaseId = csv[i];
                                break;

                            case "amount":
                                amount = csv[i];
                                break;

                            default:
                                break;
                            }
                        }
                        CsvRow row = new CsvRow();
                        try
                        {
                            if (flag == 0)
                            {
                                row.Add("TestCaseId");
                                row.Add("APIName");
                                row.Add("Status");
                                row.Add("TimeStamp");
                                writer.WriteRow(row);
                                flag = flag + 1;
                                //Append Results
                                foreach (var item in item1)
                                {
                                    writer.WriteRow(item);
                                }
                            }

                            var transactionRequest = new transactionRequestType
                            {
                                transactionType = transactionTypeEnum.authCaptureTransaction.ToString(),    // refund type
                                payment         = paymentType,
                                amount          = Convert.ToDecimal(amount)
                            };

                            var request = new createTransactionRequest {
                                transactionRequest = transactionRequest
                            };
                            request.merchantAuthentication = ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication;

                            // instantiate the contoller that will call the service
                            var controller = new createTransactionController(request);
                            controller.Execute();

                            // get the response from the service (errors contained if any)
                            var response = controller.GetApiResponse();

                            //validate
                            if (response != null)
                            {
                                if (response.messages.resultCode == messageTypeEnum.Ok)
                                {
                                    if (response.transactionResponse.messages != null)
                                    {
                                        /*****************************/
                                        try
                                        {
                                            //Assert.AreEqual(response.Id, customerProfileId);
                                            Console.WriteLine("Assertion Succeed! Valid customerProfileId fetched.");
                                            CsvRow row1 = new CsvRow();
                                            row1.Add("DBA_00" + flag.ToString());
                                            row1.Add("CreateCustomerPaymentProfile");
                                            row1.Add("Pass");
                                            row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                            writer.WriteRow(row1);
                                            //  Console.WriteLine("Success " + TestcaseID + " CustomerID : " + response.Id);
                                            flag = flag + 1;
                                            Console.WriteLine("Successfully created transaction with Transaction ID: " + response.transactionResponse.transId);
                                            Console.WriteLine("Response Code: " + response.transactionResponse.responseCode);
                                            Console.WriteLine("Message Code: " + response.transactionResponse.messages[0].code);
                                            Console.WriteLine("Description: " + response.transactionResponse.messages[0].description);
                                            Console.WriteLine("Success, Transaction Code : " + response.transactionResponse.transId);
                                        }
                                        catch
                                        {
                                            CsvRow row1 = new CsvRow();
                                            row1.Add("DBA_00" + flag.ToString());
                                            row1.Add("CreateCustomerPaymentProfile");
                                            row1.Add("Assertion Failed!");
                                            row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                            writer.WriteRow(row1);
                                            Console.WriteLine("Assertion Failed! Invalid CustomerPaymentProfile fetched.");
                                            flag = flag + 1;
                                        }
                                        /*******************/
                                    }
                                    else
                                    {
                                        Console.WriteLine("Failed Transaction.");
                                        CsvRow row2 = new CsvRow();
                                        row2.Add("DBA_00" + flag.ToString());
                                        row2.Add("DebitBankAccount");
                                        row2.Add("Fail");
                                        row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                        writer.WriteRow(row2);
                                        flag = flag + 1;

                                        //if (response.transactionResponse.errors != null)
                                        //{
                                        //    Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode);
                                        //    Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText);
                                        //}
                                    }
                                }
                                else
                                {
                                    Console.WriteLine("Failed Transaction.");
                                    CsvRow row2 = new CsvRow();
                                    row2.Add("DBA_00" + flag.ToString());
                                    row2.Add("DebitBankAccount");
                                    row2.Add("Fail");
                                    row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                    writer.WriteRow(row2);
                                    flag = flag + 1;
                                    //if (response.transactionResponse != null && response.transactionResponse.errors != null)
                                    //{
                                    //    Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode);
                                    //    Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText);
                                    //}
                                    //else
                                    //{
                                    //    Console.WriteLine("Error Code: " + response.messages.message[0].code);
                                    //    Console.WriteLine("Error message: " + response.messages.message[0].text);
                                    //}
                                }
                            }
                            //}
                            else
                            {
                                Console.WriteLine("Null Response.");
                                CsvRow row2 = new CsvRow();
                                row2.Add("DBA_00" + flag.ToString());
                                row2.Add("DebitBankAccount");
                                row2.Add("Fail");
                                row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                writer.WriteRow(row2);
                                flag = flag + 1;
                            }

                            //return response;
                        }

                        //}
                        catch (Exception e)
                        {
                            CsvRow row2 = new CsvRow();
                            row2.Add("DBA_00" + flag.ToString());
                            row2.Add("DebitBankAccount");
                            row2.Add("Fail");
                            row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                            writer.WriteRow(row2);
                            flag = flag + 1;
                            //Console.WriteLine(TestCaseId + " Error Message " + e.Message);
                        }
                    }
                }
            }
        }
Exemplo n.º 9
0
        //public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, string customerProfileId,
        //    string customerPaymentProfileId)
        //{
        //    Console.WriteLine("Get Customer Payment Profile sample");

        //    ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNET.Environment.SANDBOX;
        //    // define the merchant information (authentication / transaction id)
        //    ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
        //    {
        //        name = ApiLoginID,
        //        ItemElementName = ItemChoiceType.transactionKey,
        //        Item = ApiTransactionKey,
        //    };

        //    var request = new getCustomerPaymentProfileRequest();
        //    request.customerProfileId = customerProfileId;
        //    request.customerPaymentProfileId = customerPaymentProfileId;

        //    // Set this optional property to true to return an unmasked expiration date
        //    //request.unmaskExpirationDateSpecified = true;
        //    //request.unmaskExpirationDate = true;


        //    // instantiate the controller that will call the service
        //    var controller = new getCustomerPaymentProfileController(request);
        //    controller.Execute();

        //    // get the response from the service (errors contained if any)
        //    var response = controller.GetApiResponse();

        //    if (response != null && response.messages.resultCode == messageTypeEnum.Ok)
        //    {
        //        Console.WriteLine(response.messages.message[0].text);
        //        Console.WriteLine("Customer Payment Profile Id: " + response.paymentProfile.customerPaymentProfileId);
        //        if (response.paymentProfile.payment.Item is creditCardMaskedType)
        //        {
        //            Console.WriteLine("Customer Payment Profile Last 4: " + (response.paymentProfile.payment.Item as creditCardMaskedType).cardNumber);
        //            Console.WriteLine("Customer Payment Profile Expiration Date: " + (response.paymentProfile.payment.Item as creditCardMaskedType).expirationDate);

        //            if (response.paymentProfile.subscriptionIds != null && response.paymentProfile.subscriptionIds.Length > 0)
        //            {
        //                Console.WriteLine("List of subscriptions : ");
        //                for (int i = 0; i < response.paymentProfile.subscriptionIds.Length; i++)
        //                    Console.WriteLine(response.paymentProfile.subscriptionIds[i]);
        //            }
        //        }
        //    }
        //    else if(response != null)
        //    {
        //        Console.WriteLine("Error: " + response.messages.message[0].code + "  " +
        //                          response.messages.message[0].text);
        //    }

        //    return response;
        //}

        public static void GetCustomerPaymentProfileExec(String ApiLoginID, String ApiTransactionKey)
        {
            using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/GetCustomerPaymentProfile.csv", FileMode.Open)), true))
            {
                Console.WriteLine("Get Customer Payment Profile sample");
                int      flag       = 0;
                int      fieldCount = csv.FieldCount;
                string[] headers    = csv.GetFieldHeaders();
                //Append Data
                var item1 = DataAppend.ReadPrevData();
                using (CsvFileWriter writer = new CsvFileWriter(new FileStream(@"../../../CSV_DATA/Outputfile.csv", FileMode.Open)))
                {
                    while (csv.ReadNextRecord())
                    {
                        ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNET.Environment.SANDBOX;
                        // define the merchant information (authentication / transaction id)
                        ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType()
                        {
                            name            = ApiLoginID,
                            ItemElementName = ItemChoiceType.transactionKey,
                            Item            = ApiTransactionKey,
                        };

                        string customerProfileId        = null;
                        string customerPaymentProfileId = null;
                        string TestCaseId = null;

                        for (int i = 0; i < fieldCount; i++)
                        {
                            switch (headers[i])
                            {
                            case "TestCaseId":
                                TestCaseId = csv[i];
                                break;

                            case "customerProfileId":
                                customerProfileId = csv[i];
                                break;

                            case "customerPaymentProfileId":
                                customerPaymentProfileId = csv[i];
                                break;

                            default:
                                break;
                            }
                        }
                        CsvRow row = new CsvRow();
                        try
                        {
                            if (flag == 0)
                            {
                                row.Add("TestCaseId");
                                row.Add("APIName");
                                row.Add("Status");
                                row.Add("TimeStamp");
                                writer.WriteRow(row);
                                flag = flag + 1;
                                //Append Data
                                foreach (var item in item1)
                                {
                                    writer.WriteRow(item);
                                }
                            }


                            var request = new getCustomerPaymentProfileRequest();
                            request.customerProfileId        = customerProfileId;
                            request.customerPaymentProfileId = customerPaymentProfileId;
                            // Set this optional property to true to return an unmasked expiration date
                            //request.unmaskExpirationDateSpecified = true;
                            //request.unmaskExpirationDate = true;


                            // instantiate the controller that will call the service
                            var controller = new getCustomerPaymentProfileController(request);
                            controller.Execute();

                            // get the response from the service (errors contained if any)
                            var response = controller.GetApiResponse();
                            if (response != null && response.messages.resultCode == messageTypeEnum.Ok)
                            {
                                /*****************************/
                                try
                                {
                                    //Assert.AreEqual(response.Id, customerProfileId);
                                    Console.WriteLine("Assertion Succeed! Valid CustomerPaymentProfile fetched.");
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("GCPP_00" + flag.ToString());
                                    row1.Add("GetCustomerPaymentProfile");
                                    row1.Add("Pass");
                                    row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                    writer.WriteRow(row1);
                                    //  Console.WriteLine("Success " + TestcaseID + " CustomerID : " + response.Id);
                                    flag = flag + 1;

                                    Console.WriteLine(response.messages.message[0].text);
                                    Console.WriteLine("Customer Payment Profile Id: " + response.paymentProfile.customerPaymentProfileId);
                                }
                                catch
                                {
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("GCPP_00" + flag.ToString());
                                    row1.Add("GetCustomerPaymentProfile");
                                    row1.Add("Assertion Failed!");
                                    row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                    writer.WriteRow(row1);
                                    Console.WriteLine("Assertion Failed! Invalid CustomerPaymentProfile fetched.");
                                    flag = flag + 1;
                                }
                                /*******************/

                                //if (response.paymentProfile.payment.Item is creditCardMaskedType)
                                //{
                                //    Console.WriteLine("Customer Payment Profile Last 4: " + (response.paymentProfile.payment.Item as creditCardMaskedType).cardNumber);
                                //    Console.WriteLine("Customer Payment Profile Expiration Date: " + (response.paymentProfile.payment.Item as creditCardMaskedType).expirationDate);

                                //    if (response.paymentProfile.subscriptionIds != null && response.paymentProfile.subscriptionIds.Length > 0)
                                //    {
                                //        Console.WriteLine("List of subscriptions : ");
                                //        for (int i = 0; i < response.paymentProfile.subscriptionIds.Length; i++)
                                //            Console.WriteLine(response.paymentProfile.subscriptionIds[i]);
                                //    }
                                //}
                            }
                            else
                            {
                                CsvRow row2 = new CsvRow();
                                row2.Add("GCPP_00" + flag.ToString());
                                row2.Add("GetCustomerPaymentProfile");
                                row2.Add("Fail");
                                row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                writer.WriteRow(row2);
                                flag = flag + 1;
                            }
                        }
                        //else if (response != null)
                        //{
                        //    Console.WriteLine("Error: " + response.messages.message[0].code + "  " +
                        //                      response.messages.message[0].text);
                        //}
                        catch (Exception e)
                        {
                            CsvRow row2 = new CsvRow();
                            row2.Add("GCPP_00" + flag.ToString());
                            row2.Add("GetCustomerPaymentProfile");
                            row2.Add("Fail");
                            row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                            writer.WriteRow(row2);
                            flag = flag + 1;
                            Console.WriteLine(TestCaseId + " Error Message " + e.Message);
                        }
                        //return response;
                    }
                }
            }
        }
Exemplo n.º 10
0
        //public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey)
        //{
        //    Console.WriteLine("Get batch statistics sample");

        //    ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNET.Environment.SANDBOX;
        //    // define the merchant information (authentication / transaction id)
        //    ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
        //    {
        //        name = ApiLoginID,
        //        ItemElementName = ItemChoiceType.transactionKey,
        //        Item = ApiTransactionKey,
        //    };


        //    // unique batch id
        //    string batchId = "12345";
        //    var request = new getBatchStatisticsRequest();
        //    request.batchId = batchId;

        //    // instantiate the controller that will call the service
        //    var controller = new getBatchStatisticsController(request);
        //    controller.Execute();

        //    // get the response from the service (errors contained if any)
        //    var response = controller.GetApiResponse();

        //    if (response != null && response.messages.resultCode == messageTypeEnum.Ok)
        //    {
        //        if (response.batch == null)
        //            return response;

        //        Console.WriteLine("Batch Id: {0}", response.batch.batchId);
        //        Console.WriteLine("Batch settled on (UTC): {0}", response.batch.settlementTimeUTC);
        //        Console.WriteLine("Batch settled on (Local): {0}", response.batch.settlementTimeLocal);
        //        Console.WriteLine("Batch settlement state: {0}", response.batch.settlementState);
        //        Console.WriteLine("Batch payment method: {0}", response.batch.paymentMethod);
        //        foreach (var item in response.batch.statistics)
        //        {
        //            Console.WriteLine(
        //                "Account type: {0} Charge amount: {1} Charge count: {2} Refund amount: {3} Refund count: {4} Void count: {5} Decline count: {6} Error amount: {7}",
        //                item.accountType, item.chargeAmount, item.chargeCount, item.refundAmount, item.refundCount,
        //                item.voidCount, item.declineCount, item.errorCount);
        //        }
        //    }
        //    else if (response != null)
        //    {
        //        Console.WriteLine("Error: " + response.messages.message[0].code + "  " +
        //                          response.messages.message[0].text);
        //    }
        //    else
        //    {
        //        Console.WriteLine("Null response");
        //    }

        //    return response;
        //}

        public static void GetBatchStatisticsExec(String ApiLoginID, String ApiTransactionKey)
        {
            using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/GetBatchStatistics.csv", FileMode.Open)), true))
            {
                Console.WriteLine("Get batch statistics sample");

                int      flag       = 0;
                int      fieldCount = csv.FieldCount;
                string[] headers    = csv.GetFieldHeaders();

                //Append data
                var item1 = DataAppend.ReadPrevData();
                using (CsvFileWriter writer = new CsvFileWriter(new FileStream(@"../../../CSV_DATA/Outputfile.csv", FileMode.Open)))
                {
                    while (csv.ReadNextRecord())
                    {
                        ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNET.Environment.SANDBOX;

                        // unique batch id
                        string batchId = "12345";
                        var    request = new getBatchStatisticsRequest();
                        request.batchId = batchId;

                        string apiLogin       = null;
                        string transactionKey = null;
                        string TestcaseID     = null;
                        //int count = 0;
                        for (int i = 0; i < fieldCount; i++)
                        {
                            // Read the headers with values from the test data input file
                            switch (headers[i])
                            {
                            case "apiLogin":
                                apiLogin = csv[i];
                                break;

                            case "transactionKey":
                                transactionKey = csv[i];
                                break;

                            case "TestcaseID":
                                TestcaseID = csv[i];
                                //count++;
                                break;

                            default:
                                break;
                            }
                        }


                        CsvRow row = new CsvRow();
                        try
                        {
                            if (flag == 0)
                            {
                                row.Add("TestCaseId");
                                row.Add("APIName");
                                row.Add("Status");
                                row.Add("TimeStamp");
                                writer.WriteRow(row);
                                flag = flag + 1;

                                //Append Results
                                foreach (var item in item1)
                                {
                                    writer.WriteRow(item);
                                }
                            }
                            // define the merchant information (authentication / transaction id)
                            ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType()
                            {
                                name            = apiLogin,
                                ItemElementName = ItemChoiceType.transactionKey,
                                Item            = transactionKey,
                            };
                            // instantiate the controller that will call the service
                            var controller = new getBatchStatisticsController(request);
                            controller.Execute();

                            // get the response from the service (errors contained if any)
                            var response = controller.GetApiResponse();

                            if (response != null && response.messages.resultCode == messageTypeEnum.Ok && response.batch != null)
                            {
                                /*****************************/
                                try
                                {
                                    //Assert.AreEqual(response.Id, customerProfileId);
                                    //Console.WriteLine("Assertion Succeed! Valid customerProfileId fetched.");
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("GBS_00" + flag.ToString());
                                    row1.Add("GetBatchStatistics");
                                    row1.Add("Pass");
                                    row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                    writer.WriteRow(row1);
                                    //  Console.WriteLine("Success " + TestcaseID + " CustomerID : " + response.Id);
                                    flag = flag + 1;

                                    Console.WriteLine("Batch Id: {0}", response.batch.batchId);
                                    Console.WriteLine("Batch settled on (UTC): {0}", response.batch.settlementTimeUTC);
                                    Console.WriteLine("Batch settled on (Local): {0}", response.batch.settlementTimeLocal);
                                    Console.WriteLine("Batch settlement state: {0}", response.batch.settlementState);
                                    Console.WriteLine("Batch payment method: {0}", response.batch.paymentMethod);
                                    foreach (var item in response.batch.statistics)
                                    {
                                        Console.WriteLine(
                                            "Account type: {0} Charge amount: {1} Charge count: {2} Refund amount: {3} Refund count: {4} Void count: {5} Decline count: {6} Error amount: {7}",
                                            item.accountType, item.chargeAmount, item.chargeCount, item.refundAmount, item.refundCount,
                                            item.voidCount, item.declineCount, item.errorCount);
                                    }
                                }
                                catch
                                {
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("GBS_00" + flag.ToString());
                                    row1.Add("GetBatchStatistics");
                                    row1.Add("Assertion Failed!");
                                    row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                    writer.WriteRow(row1);
                                    //Console.WriteLine("Assertion Failed! Invalid CustomerPaymentProfile fetched.");
                                    flag = flag + 1;
                                }
                                /*******************/
                            }

                            //else if (response != null)
                            //{
                            //    Console.WriteLine("Error: " + response.messages.message[0].code + "  " +
                            //                      response.messages.message[0].text);
                            //}
                            else
                            {
                                //Console.WriteLine("Null response");
                                CsvRow row2 = new CsvRow();
                                row2.Add("GBS_00" + flag.ToString());
                                row2.Add("GetBatchStatistics");
                                row2.Add("Fail");
                                row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                writer.WriteRow(row2);
                                flag = flag + 1;
                            }
                        }

                        //return response;
                        catch (Exception e)
                        {
                            CsvRow row2 = new CsvRow();
                            row2.Add("GBS_00" + flag.ToString());
                            row2.Add("GetBatchStatistics");
                            row2.Add("Fail");
                            row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                            writer.WriteRow(row2);
                            flag = flag + 1;
                            //Console.WriteLine(TestCaseId + " Error Message " + e.Message);
                        }
                    }
                }
            }
        }
Exemplo n.º 11
0
        //public static ANetApiResponse Run(string ApiLoginID, string ApiTransactionKey, string transactionId)
        //{
        //    Console.WriteLine("CreateCustomerProfileFromTransaction Sample");

        //    ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNET.Environment.SANDBOX;
        //    ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
        //    {
        //        name            = ApiLoginID,
        //        ItemElementName = ItemChoiceType.transactionKey,
        //        Item            = ApiTransactionKey,
        //    };

        //    var customerProfile = new customerProfileBaseType
        //    {
        //        merchantCustomerId = "123212",
        //        email = "*****@*****.**",
        //        description = "This is a sample customer profile"
        //    };

        //    var request = new createCustomerProfileFromTransactionRequest
        //    {
        //        transId = transactionId,
        //        // You can either specify the customer information in form of customerProfileBaseType object
        //        customer = customerProfile
        //        //  OR
        //        // You can just provide the customer Profile ID
        //        // customerProfileId = "123343"
        //    };

        //    var controller = new createCustomerProfileFromTransactionController(request);
        //    controller.Execute();

        //    createCustomerProfileResponse response = controller.GetApiResponse();

        //    //validate
        //    if (response != null && response.messages.resultCode == messageTypeEnum.Ok)
        //    {
        //        if (response != null && response.messages.message != null)
        //        {
        //            Console.WriteLine("Success, CustomerProfileID : " + response.customerProfileId);
        //            Console.WriteLine("Success, CustomerPaymentProfileID : " + response.customerPaymentProfileIdList[0]);
        //            Console.WriteLine("Success, CustomerShippingProfileID : " + response.customerShippingAddressIdList[0]);
        //        }
        //    }
        //    else if(response != null)
        //    {
        //        Console.WriteLine("Error: " + response.messages.message[0].code + "  " + response.messages.message[0].text);
        //    }

        //    return response;
        //}
        public static void CreateCustomerProfileFromTransactionExec(String ApiLoginID, String ApiTransactionKey)
        {
            using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/CreateACustomerProfileFromATransaction.csv", FileMode.Open)), true))
            {
                Console.WriteLine("CreateCustomerProfileFromTransaction Sample");
                int fieldCount = csv.FieldCount;
                //Append Data
                var item1 = DataAppend.ReadPrevData();
                using (CsvFileWriter writer = new CsvFileWriter(new FileStream(@"../../../CSV_DATA/Outputfile.csv", FileMode.Open)))
                {
                    int      flag    = 0;
                    string[] headers = csv.GetFieldHeaders();
                    while (csv.ReadNextRecord())
                    {
                        // Create Instance of Customer Api
                        ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNET.Environment.SANDBOX;
                        // define the merchant information (authentication / transaction id)
                        ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType()
                        {
                            name            = ApiLoginID,
                            ItemElementName = ItemChoiceType.transactionKey,
                            Item            = ApiTransactionKey,
                        };
                        //CustomersApi instance = new CustomersApi(EnvironmentSet.Sandbox);
                        // Customer Response Object
                        // Customer response = null;
                        //initialization


                        string TestCaseId        = null;
                        string CustomerProfileId = null;
                        string TransactionId     = null;


                        for (int i = 0; i < fieldCount; i++)
                        {
                            switch (headers[i])
                            {
                            case "CustomerProfileId":
                                CustomerProfileId = csv[i];
                                break;

                            case "TransactionId":
                                TransactionId = csv[i];
                                break;

                            case "TestCaseId":
                                TestCaseId = csv[i];
                                break;

                            default:
                                break;
                            }
                        }
                        //Write to output file
                        CsvRow row = new CsvRow();
                        try
                        {
                            if (flag == 0)
                            {
                                row.Add("TestCaseId");
                                row.Add("APIName");
                                row.Add("Status");
                                row.Add("TimeStamp");
                                writer.WriteRow(row);
                                flag = flag + 1;
                                //Append Data
                                foreach (var item in item1)
                                {
                                    writer.WriteRow(item);
                                }
                            }
                            var customerProfile = new customerProfileBaseType
                            {
                                merchantCustomerId = "123212",
                                email       = "*****@*****.**",
                                description = "This is a sample customer profile"
                            };

                            var request = new createCustomerProfileFromTransactionRequest();
                            request.customerProfileId = CustomerProfileId;
                            request.customer          = customerProfile;

                            request.transId = TransactionId;


                            // instantiate the controller that will call the service
                            var controller = new createCustomerProfileFromTransactionController(request);
                            controller.Execute();

                            // get the response from the service (errors contained if any)
                            var response = controller.GetApiResponse();
                            if (response != null && response.messages.resultCode == messageTypeEnum.Ok &&
                                response.messages.message != null)
                            {
                                try
                                {
                                    //Assert.AreEqual(response.Id, customerProfileId);
                                    Console.WriteLine("Assertion Succeed! Valid CustomerId fetched.");
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("CACFPT_00" + flag.ToString());
                                    row1.Add("createCustomerFromPaymentTransaction");
                                    row1.Add("Pass");
                                    row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                    writer.WriteRow(row1);
                                    //  Console.WriteLine("Success " + TestcaseID + " CustomerID : " + response.Id);
                                    flag = flag + 1;
                                    Console.WriteLine("Success, CustomerProfileID : " + response.customerProfileId);
                                    Console.WriteLine("Success, CustomerPaymentProfileID : " + response.customerPaymentProfileIdList[0]);
                                    Console.WriteLine("Success, CustomerShippingProfileID : " + response.customerShippingAddressIdList[0]);
                                }
                                catch
                                {
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("CACFPT_00" + flag.ToString());
                                    row1.Add("createCustomerFromPaymentTransaction");
                                    row1.Add("Fail");
                                    row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                    writer.WriteRow(row1);
                                    Console.WriteLine("Assertion Failed! Invalid CustomerId fetched.");
                                    flag = flag + 1;
                                }
                            }
                            else
                            {
                                CsvRow row1 = new CsvRow();
                                row1.Add("CACFPT_00" + flag.ToString());
                                row1.Add("createCustomerFromPaymentTransaction");
                                row1.Add("Fail");
                                row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                writer.WriteRow(row1);
                                //Console.WriteLine("Assertion Failed! Invalid CustomerId fetched.");
                                flag = flag + 1;
                            }
                        }
                        catch (Exception e)
                        {
                            CsvRow row2 = new CsvRow();
                            row2.Add("CACFPT_00" + flag.ToString());
                            row2.Add("createCustomerFromPaymentTransaction");
                            row2.Add("Fail");
                            row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                            writer.WriteRow(row2);
                            flag = flag + 1;
                            Console.WriteLine(TestCaseId + " Error Message " + e.Message);
                        }
                    }
                }
            }
        }
Exemplo n.º 12
0
        //public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey)
        //{
        //    Console.WriteLine("Get A List of Subscriptions Sample");

        //    ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNET.Environment.SANDBOX;

        //    ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
        //    {
        //        name = ApiLoginID,
        //        ItemElementName = ItemChoiceType.transactionKey,
        //        Item = ApiTransactionKey,
        //    };

        //    var request = new ARBGetSubscriptionListRequest {searchType = ARBGetSubscriptionListSearchTypeEnum.subscriptionActive };    // only gets active subscriptions

        //    var controller = new ARBGetSubscriptionListController(request);          // instantiate the contoller that will call the service
        //    controller.Execute();

        //    ARBGetSubscriptionListResponse response = controller.GetApiResponse();   // get the response from the service (errors contained if any)

        //    //validate
        //    if (response != null && response.messages.resultCode == messageTypeEnum.Ok)
        //    {
        //        if (response != null && response.messages.message != null && response.subscriptionDetails != null)
        //        {
        //            Console.WriteLine("Success, " + response.totalNumInResultSet + " Results Returned ");
        //        }
        //    }
        //    else if(response != null)
        //    {
        //        Console.WriteLine("Error: " + response.messages.message[0].code + "  " + response.messages.message[0].text);
        //    }

        //    return response;
        //}
        public static void GetListOfSubscriptionsExec(String ApiLoginID, String ApiTransactionKey)
        {
            using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/CreateASubscriptionFromCustomerProfile.csv", FileMode.Open)), true))
            {
                Console.WriteLine("Get A List of Subscriptions Sample");
                int      flag       = 0;
                int      fieldCount = csv.FieldCount;
                string[] headers    = csv.GetFieldHeaders();
                //Append Data
                var item1 = DataAppend.ReadPrevData();
                using (CsvFileWriter writer = new CsvFileWriter(new FileStream(@"../../../CSV_DATA/Outputfile.csv", FileMode.Open)))
                {
                    while (csv.ReadNextRecord())
                    {
                        // Create Instance of Customer Api
                        ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNET.Environment.SANDBOX;

                        string TestCase_Id = null;

                        string apiLoginID        = null;
                        string apiTransactionKey = null;
                        for (int i = 0; i < fieldCount; i++)
                        {
                            switch (headers[i])
                            {
                            case "apiLoginID":
                                apiLoginID = csv[i];
                                break;

                            case "apiTransactionKey":
                                apiTransactionKey = csv[i];
                                break;

                            case "TestCase_Id":
                                TestCase_Id = csv[i];
                                break;

                            default:
                                break;
                            }
                        }
                        // define the merchant information (authentication / transaction id)
                        ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType()
                        {
                            name            = apiLoginID,
                            ItemElementName = ItemChoiceType.transactionKey,
                            Item            = apiTransactionKey,
                        };
                        //Write to output file
                        CsvRow row = new CsvRow();
                        try
                        {
                            if (flag == 0)
                            {
                                row.Add("TestCaseId");
                                row.Add("APIName");
                                row.Add("Status");
                                row.Add("TimeStamp");
                                writer.WriteRow(row);
                                flag = flag + 1;
                                //Append Data
                                foreach (var item in item1)
                                {
                                    writer.WriteRow(item);
                                }
                            }
                            var request = new ARBGetSubscriptionListRequest {
                                searchType = ARBGetSubscriptionListSearchTypeEnum.subscriptionActive
                            };                                                                       // only gets active subscriptions

                            var controller = new ARBGetSubscriptionListController(request);          // instantiate the contoller that will call the service
                            controller.Execute();

                            ARBGetSubscriptionListResponse response = controller.GetApiResponse();



                            if (response != null && response.messages.resultCode == messageTypeEnum.Ok &&
                                response.messages.message != null && response.subscriptionDetails != null)
                            {
                                try
                                {
                                    //Assert.AreEqual(response.Id, customerProfileId);
                                    Console.WriteLine("Assertion Succeed! Valid CustomerId fetched.");
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("GLOS_00" + flag.ToString());
                                    row1.Add("GetListOfSubscription");
                                    row1.Add("Pass");
                                    row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                    writer.WriteRow(row1);
                                    //  Console.WriteLine("Success " + TestcaseID + " CustomerID : " + response.Id);
                                    flag = flag + 1;
                                    Console.WriteLine("Success, " + response.totalNumInResultSet + " Results Returned ");
                                }
                                catch
                                {
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("GLOS_00" + flag.ToString());
                                    row1.Add("GetListOfSubscription");
                                    row1.Add("Assertion Failed!");
                                    row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                    writer.WriteRow(row1);
                                    Console.WriteLine("Assertion Failed! Invalid CustomerId fetched.");
                                    flag = flag + 1;
                                }
                            }
                            else
                            {
                                CsvRow row1 = new CsvRow();
                                row1.Add("GLOS_00" + flag.ToString());
                                row1.Add("GetListOfSubscription");
                                row1.Add("Fail");
                                row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                writer.WriteRow(row1);
                                //Console.WriteLine("Assertion Failed! Invalid CustomerId fetched.");
                                flag = flag + 1;
                            }
                        }
                        catch (Exception e)
                        {
                            CsvRow row2 = new CsvRow();
                            row2.Add("GLOS_00" + flag.ToString());
                            row2.Add("GetListOfSubscription");
                            row2.Add("Fail");
                            row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                            writer.WriteRow(row2);
                            flag = flag + 1;
                            Console.WriteLine(TestCase_Id + " Error Message " + e.Message);
                        }
                    }
                }
            }
        }
        //public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey)
        //{
        //    Console.WriteLine("Get Account Updater job details sample");

        //    ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNET.Environment.SANDBOX;
        //    // define the merchant information (authentication / transaction id)
        //    ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
        //    {
        //        name = ApiLoginID,
        //        ItemElementName = ItemChoiceType.transactionKey,
        //        Item = ApiTransactionKey,
        //    };

        //    // parameters for request
        //    string month = "2018-05";
        //    //AUJobTypeEnum.all = "all";

        //    var request = new getAUJobDetailsRequest();
        //    request.month = month;
        //    request.modifiedTypeFilter = AUJobTypeEnum.all;
        //    request.paging = new Paging
        //    {
        //        limit = 1000,
        //        offset = 1
        //    };

        //    // instantiate the controller that will call the service
        //    var controller = new getAUJobDetailsController(request);
        //    controller.Execute();

        //    // get the response from the service (errors contained if any)
        //    var response = controller.GetApiResponse();

        //    if (response != null && response.messages.resultCode == messageTypeEnum.Ok)
        //    {
        //        if (response.auDetails == null)
        //            return response;

        //        foreach (var update in response.auDetails)
        //        {
        //            Console.WriteLine("Profile ID / Payment Profile ID: {0} / {1}", update.customerProfileID, update.customerPaymentProfileID);
        //            Console.WriteLine("Update Time (UTC): {0}", update.updateTimeUTC);
        //            Console.WriteLine("Reason Code: {0}", update.auReasonCode);
        //            Console.WriteLine("Reason Description: {0}", update.reasonDescription);

        //            ////Fetching Subscription ID for AU Update
        //            //if (update.subscriptionIds != null && update.subscriptionIds.Length > 0)
        //            //{
        //            //    Console.WriteLine("List of subscriptions : ");
        //            //    for (int i = 0; i < update.subscriptionIds.Length; i++)
        //            //        Console.WriteLine(update.subscriptionIds[i]);
        //            //}
        //        }

        //        foreach (var delete in response.auDetails)
        //        {
        //            Console.WriteLine("Profile ID / Payment Profile ID: {0} / {1}", delete.customerProfileID, delete.customerPaymentProfileID);
        //            Console.WriteLine("Update Time (UTC): {0}", delete.updateTimeUTC);
        //            Console.WriteLine("Reason Code: {0}", delete.auReasonCode);
        //            Console.WriteLine("Reason Description: {0}", delete.reasonDescription);

        //            ////Fetching Subscription ID for AU Delete
        //            //if (delete.subscriptionIds != null && delete.subscriptionIds.Length > 0)
        //            //{
        //            //    Console.WriteLine("List of subscriptions : ");
        //            //    for (int i = 0; i < delete.subscriptionIds.Length; i++)
        //            //        Console.WriteLine(delete.subscriptionIds[i]);
        //            //}
        //        }
        //    }
        //    else if (response != null)
        //    {
        //        Console.WriteLine("Error: " + response.messages.message[0].code + "  " +
        //                            response.messages.message[0].text);
        //    }

        //    return response;
        //}
        public static void GetAccountUpdaterJobDetailsExec(String ApiLoginID, String ApiTransactionKey)
        {
            using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/GetAccountUpdateJobDetails.csv", FileMode.Open)), true))
            {
                Console.WriteLine("Get Account Updater job details sample");
                int      flag       = 0;
                int      fieldCount = csv.FieldCount;
                string[] headers    = csv.GetFieldHeaders();
                //Append Data
                var item1 = DataAppend.ReadPrevData();
                using (CsvFileWriter writer = new CsvFileWriter(new FileStream(@"../../../CSV_DATA/Outputfile.csv", FileMode.Open)))
                {
                    while (csv.ReadNextRecord())
                    {
                        string TestCase_Id    = null;
                        string apiLogin       = null;
                        string transactionKey = null;
                        for (int i = 0; i < fieldCount; i++)
                        {
                            switch (headers[i])
                            {
                            case "apiLogin":
                                apiLogin = csv[i];
                                break;

                            case "transactionKey":
                                transactionKey = csv[i];
                                break;

                            case "TestCase_Id":
                                TestCase_Id = csv[i];
                                break;

                            default:
                                break;
                            }
                        }
                        //Write to output file
                        CsvRow row = new CsvRow();
                        try
                        {
                            if (flag == 0)
                            {
                                row.Add("TestCaseId");
                                row.Add("APIName");
                                row.Add("Status");
                                row.Add("TimeStamp");
                                writer.WriteRow(row);
                                flag = flag + 1;
                                //Append Data
                                foreach (var item in item1)
                                {
                                    writer.WriteRow(item);
                                }
                            }

                            ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNET.Environment.SANDBOX;
                            // define the merchant information (authentication / transaction id)
                            ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType()
                            {
                                name            = apiLogin,
                                ItemElementName = ItemChoiceType.transactionKey,
                                Item            = ApiTransactionKey,
                            };

                            // parameters for request
                            string month = "2018-05";
                            //AUJobTypeEnum.all = "all";

                            var request = new getAUJobDetailsRequest();
                            request.month = month;
                            request.modifiedTypeFilter = AUJobTypeEnum.all;
                            request.paging             = new Paging
                            {
                                limit  = 1000,
                                offset = 1
                            };

                            // instantiate the controller that will call the service
                            var controller = new getAUJobDetailsController(request);
                            controller.Execute();

                            // get the response from the service (errors contained if any)
                            var response = controller.GetApiResponse();



                            if (response != null && response.messages.resultCode == messageTypeEnum.Ok)
                            {
                                try
                                {
                                    //Assert.AreEqual(response.Id, customerProfileId);
                                    Console.WriteLine("Assertion Succeed! Valid CustomerId fetched.");
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("GAUJD_00" + flag.ToString());
                                    row1.Add("GetAccountUpdaterJobDetails");
                                    row1.Add("Pass");
                                    row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                    writer.WriteRow(row1);
                                    //  Console.WriteLine("Success " + TestcaseID + " CustomerID : " + response.Id);
                                    flag = flag + 1;

                                    foreach (var update in response.auDetails)
                                    {
                                        Console.WriteLine("Profile ID / Payment Profile ID: {0} / {1}", update.customerProfileID, update.customerPaymentProfileID);
                                        Console.WriteLine("Update Time (UTC): {0}", update.updateTimeUTC);
                                        Console.WriteLine("Reason Code: {0}", update.auReasonCode);
                                        Console.WriteLine("Reason Description: {0}", update.reasonDescription);
                                    }
                                    foreach (var delete in response.auDetails)
                                    {
                                        Console.WriteLine("Profile ID / Payment Profile ID: {0} / {1}", delete.customerProfileID, delete.customerPaymentProfileID);
                                        Console.WriteLine("Update Time (UTC): {0}", delete.updateTimeUTC);
                                        Console.WriteLine("Reason Code: {0}", delete.auReasonCode);
                                        Console.WriteLine("Reason Description: {0}", delete.reasonDescription);
                                    }
                                }
                                catch
                                {
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("GAUJD_00" + flag.ToString());
                                    row1.Add("GetAccountUpdaterJobDetails");
                                    row1.Add("Assertion Failed!");
                                    row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                    writer.WriteRow(row1);
                                    Console.WriteLine("Assertion Failed! Invalid CustomerId fetched.");
                                    flag = flag + 1;
                                }
                            }
                            else
                            {
                                CsvRow row1 = new CsvRow();
                                row1.Add("GAUJD_00" + flag.ToString());
                                row1.Add("GetAccountUpdaterJobDetails");
                                row1.Add("Fail");
                                row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                writer.WriteRow(row1);
                                Console.WriteLine("Assertion Failed! Invalid CustomerId fetched.");
                                flag = flag + 1;
                            }
                        }
                        catch (Exception e)
                        {
                            CsvRow row2 = new CsvRow();
                            row2.Add("GAUJD_00" + flag.ToString());
                            row2.Add("GetAccountUpdaterJobDetails");
                            row2.Add("Fail");
                            row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                            writer.WriteRow(row2);
                            flag = flag + 1;
                            Console.WriteLine(TestCase_Id + " Error Message " + e.Message);
                        }
                    }
                }
            }
        }
Exemplo n.º 14
0
        //  public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey)
        //  {
        //      Console.WriteLine("Charge Tokenized Credit Card Sample");

        //      ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNET.Environment.SANDBOX;

        //      // define the merchant information (authentication / transaction id)
        //      ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
        //      {
        //          name = ApiLoginID,
        //          ItemElementName = ItemChoiceType.transactionKey,
        //          Item = ApiTransactionKey,
        //      };

        //      var creditCard = new creditCardType
        //      {
        //          cardNumber = "4111111111111111",
        //          expirationDate = "0718",
        //          cryptogram = Guid.NewGuid().ToString()             // Set this to the value of the cryptogram received from the token provide
        //      };

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

        //      var transactionRequest = new transactionRequestType
        //      {
        //          transactionType = transactionTypeEnum.authCaptureTransaction.ToString(),    // charge the card
        //          amount = 133.45m,
        //          payment = paymentType
        //      };

        //      var request = new createTransactionRequest { transactionRequest = transactionRequest };

        //      // instantiate the contoller that will call the service
        //      var controller = new createTransactionController(request);
        //      controller.Execute();

        //      // get the response from the service (errors contained if any)
        //      var response = controller.GetApiResponse();

        //      //validate
        //      if (response != null)
        //      {
        //          if (response.messages.resultCode == messageTypeEnum.Ok)
        //          {
        //              if(response.transactionResponse.messages != null)
        //              {
        //                  Console.WriteLine("Successfully created transaction with Transaction ID: " + response.transactionResponse.transId);
        //                  Console.WriteLine("Response Code: " + response.transactionResponse.responseCode);
        //                  Console.WriteLine("Message Code: " + response.transactionResponse.messages[0].code);
        //                  Console.WriteLine("Description: " + response.transactionResponse.messages[0].description);
        //Console.WriteLine("Success, Auth Code : " + response.transactionResponse.authCode);
        //              }
        //              else
        //              {
        //                  Console.WriteLine("Failed Transaction.");
        //                  if (response.transactionResponse.errors != null)
        //                  {
        //                      Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode);
        //                      Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText);
        //                  }
        //              }
        //          }
        //          else
        //          {
        //              Console.WriteLine("Failed Transaction.");
        //              if (response.transactionResponse != null && response.transactionResponse.errors != null)
        //              {
        //                  Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode);
        //                  Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText);
        //              }
        //              else
        //              {
        //                  Console.WriteLine("Error Code: " + response.messages.message[0].code);
        //                  Console.WriteLine("Error message: " + response.messages.message[0].text);
        //              }
        //          }
        //      }
        //      else
        //      {
        //          Console.WriteLine("Null Response.");
        //      }

        //      return response;
        //  }

        public static void ChargeTokenizedCreditCardExec(String ApiLoginID, String ApiTransactionKey)
        {
            using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/ChargeTokenizedCreditCard.csv", FileMode.Open)), true))
            {
                Console.WriteLine("Charge Tokenized Credit Card Sample");
                int      flag       = 0;
                int      fieldCount = csv.FieldCount;
                string[] headers    = csv.GetFieldHeaders();
                //Append data
                var item1 = DataAppend.ReadPrevData();
                using (CsvFileWriter writer = new CsvFileWriter(new FileStream(@"../../../CSV_DATA/Outputfile.csv", FileMode.Open)))
                {
                    while (csv.ReadNextRecord())
                    {
                        ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNET.Environment.SANDBOX;



                        var creditCard = new creditCardType
                        {
                            cardNumber     = "4111111111111111",
                            expirationDate = "0718",
                            cryptogram     = Guid.NewGuid().ToString()         // Set this to the value of the cryptogram received from the token provide
                        };

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

                        var transactionRequest = new transactionRequestType
                        {
                            transactionType = transactionTypeEnum.authCaptureTransaction.ToString(),    // charge the card
                            amount          = 133.45m,
                            payment         = paymentType
                        };

                        string apiLogin       = null;
                        string transactionKey = null;
                        string TestCaseId     = null;
                        for (int i = 0; i < fieldCount; i++)
                        {
                            switch (headers[i])
                            {
                            case "TestCaseId":
                                TestCaseId = csv[i];
                                break;

                            case "apiLogin":
                                apiLogin = csv[i];
                                break;

                            case "transactionKey":
                                transactionKey = csv[i];
                                break;

                            default:
                                break;
                            }
                        }
                        // define the merchant information (authentication / transaction id)
                        ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType()
                        {
                            name            = apiLogin,
                            ItemElementName = ItemChoiceType.transactionKey,
                            Item            = transactionKey,
                        };
                        CsvRow row = new CsvRow();
                        try
                        {
                            if (flag == 0)
                            {
                                row.Add("TestCaseId");
                                row.Add("APIName");
                                row.Add("Status");
                                row.Add("TimeStamp");
                                writer.WriteRow(row);
                                flag = flag + 1;
                                //Append Results
                                foreach (var item in item1)
                                {
                                    writer.WriteRow(item);
                                }
                            }
                            var request = new createTransactionRequest {
                                transactionRequest = transactionRequest
                            };

                            // instantiate the contoller that will call the service
                            var controller = new createTransactionController(request);
                            controller.Execute();

                            // get the response from the service (errors contained if any)
                            var response = controller.GetApiResponse();

                            //validate
                            if (response != null)
                            {
                                if (response.messages.resultCode == messageTypeEnum.Ok)
                                {
                                    if (response.transactionResponse.messages != null)
                                    {
                                        /*****************************/
                                        try
                                        {
                                            //Assert.AreEqual(response.Id, customerProfileId);
                                            CsvRow row1 = new CsvRow();
                                            row1.Add("CTCC_00" + flag.ToString());
                                            row1.Add("ChargeTokenizedCreditCard");
                                            row1.Add("Pass");
                                            row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                            writer.WriteRow(row1);
                                            //  Console.WriteLine("Success " + TestcaseID + " CustomerID : " + response.Id);
                                            flag = flag + 1;
                                            Console.WriteLine("Successfully created transaction with Transaction ID: " + response.transactionResponse.transId);
                                            Console.WriteLine("Response Code: " + response.transactionResponse.responseCode);
                                            Console.WriteLine("Message Code: " + response.transactionResponse.messages[0].code);
                                            Console.WriteLine("Description: " + response.transactionResponse.messages[0].description);
                                            Console.WriteLine("Success, Auth Code : " + response.transactionResponse.authCode);
                                        }
                                        catch
                                        {
                                            CsvRow row1 = new CsvRow();
                                            row1.Add("CTCC_00" + flag.ToString());
                                            row1.Add("ChargeTokenizedCreditCard");
                                            row1.Add("Assertion Failed!");
                                            row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                            writer.WriteRow(row1);
                                            flag = flag + 1;
                                        }
                                        /*******************/
                                    }
                                    else
                                    {
                                        Console.WriteLine("Failed Transaction.");
                                        if (response.transactionResponse.errors != null)
                                        {
                                            Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode);
                                            Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText);
                                        }
                                    }
                                }
                                else
                                {
                                    Console.WriteLine("Failed Transaction.");
                                    CsvRow row2 = new CsvRow();
                                    row2.Add("CTCC_00" + flag.ToString());
                                    row2.Add("ChargeTokenizedCreditCard");
                                    row2.Add("Fail");
                                    row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                    writer.WriteRow(row2);
                                    flag = flag + 1;
                                    //if (response.transactionResponse != null && response.transactionResponse.errors != null)
                                    //{
                                    //    Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode);
                                    //    Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText);
                                    //}
                                    //else
                                    //{
                                    //    Console.WriteLine("Error Code: " + response.messages.message[0].code);
                                    //    Console.WriteLine("Error message: " + response.messages.message[0].text);
                                    //}
                                }
                            }
                            else
                            {
                                Console.WriteLine("Null Response.");
                                CsvRow row2 = new CsvRow();
                                row2.Add("CTCC_00" + flag.ToString());
                                row2.Add("ChargeTokenizedCreditCard");
                                row2.Add("Fail");
                                row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                writer.WriteRow(row2);
                                flag = flag + 1;
                            }
                        }



                        //return response;
                        catch (Exception e)
                        {
                            CsvRow row2 = new CsvRow();
                            row2.Add("CTCC_00" + flag.ToString());
                            row2.Add("ChargeTokenizedCreditCard");
                            row2.Add("Fail");
                            row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                            writer.WriteRow(row2);
                            flag = flag + 1;
                            Console.WriteLine(TestCaseId + " Error Message " + e.Message);
                        }
                    }
                }
            }
        }