Ejemplo n.º 1
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 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;
        }
Ejemplo n.º 3
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);
                        }
                    }
                }
            }
        }