public static void DeleteCustomerPaymentProfileExec(String ApiLoginID, String ApiTransactionKey)
        {
            using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/DeleteCustomerPaymentProfile.csv", FileMode.Open)), true))
            {
                Console.WriteLine("DeleteCustomerPaymentProfile 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;
                        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);
                                }
                            }



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

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

                            //Send Request to EndPoint
                            deleteCustomerPaymentProfileResponse response = controller.GetApiResponse();
                            if (response != null && response.messages.resultCode == messageTypeEnum.Ok)
                            {
                                /*****************************/
                                try
                                {
                                    //Assert.AreEqual(response.Id, customerProfileId);
                                    Console.WriteLine("Assertion Succeed! Valid CustomerPaymentProfile deleted.");
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("DCPP_00" + flag.ToString());
                                    row1.Add("DeleteCustomerPaymentProfile");
                                    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;
                                }
                                catch
                                {
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("DCPP_00" + flag.ToString());
                                    row1.Add("DeleteCustomerPaymentProfile");
                                    row1.Add("Fail");
                                    row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                    writer.WriteRow(row1);
                                    Console.WriteLine("Assertion Failed! Invalid CustomerPaymentProfile deleted.");
                                    flag = flag + 1;
                                }
                                /*******************/
                                //if (response != null && response.messages.message != null)
                                //{
                                //    Console.WriteLine("Success, ResultCode : " + response.messages.resultCode.ToString());
                                //}
                            }
                            else
                            {
                                CsvRow row1 = new CsvRow();
                                row1.Add("DCPP_00" + flag.ToString());
                                row1.Add("DeleteCustomerPaymentProfile");
                                row1.Add("Fail");
                                row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                writer.WriteRow(row1);
                            }
                        }
                        //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("DCPP_00" + flag.ToString());
                            row2.Add("DeleteCustomerPaymentProfile");
                            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;
                    }
                }
            }
        }
        //public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey)
        //{
        //    Console.WriteLine("Get settled batch 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,
        //    };

        //    //Get a date 1 week in the past
        //    var firstSettlementDate = DateTime.Today.Subtract(TimeSpan.FromDays(31));
        //    //Get today's date
        //    var lastSettlementDate = DateTime.Today;
        //    Console.WriteLine("First settlement date: {0} Last settlement date:{1}", firstSettlementDate,
        //        lastSettlementDate);

        //    var request = new getSettledBatchListRequest();
        //    request.firstSettlementDate = firstSettlementDate;
        //    request.lastSettlementDate = lastSettlementDate;
        //    request.includeStatistics = true;

        //    // instantiate the controller that will call the service
        //    var controller = new getSettledBatchListController(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.batchList == null)
        //            return response;

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

        //    return response;
        //}

        public static void GetSettledBatchListExec(String ApiLoginID, String ApiTransactionKey)
        {
            using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/GetSettledBatchList.csv", FileMode.Open)), true))
            {
                Console.WriteLine("Get settled batch 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;


                        //Get a date 1 week in the past
                        var firstSettlementDate = DateTime.Today.Subtract(TimeSpan.FromDays(31));
                        //Get today's date
                        var lastSettlementDate = DateTime.Today;
                        Console.WriteLine("First settlement date: {0} Last settlement date:{1}", firstSettlementDate,
                                          lastSettlementDate);
                        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;
                            }
                        }
                        // 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 Result
                                foreach (var item in item1)
                                {
                                    writer.WriteRow(item);
                                }
                            }
                            var request = new getSettledBatchListRequest();
                            request.firstSettlementDate = firstSettlementDate;
                            request.lastSettlementDate  = lastSettlementDate;
                            request.includeStatistics   = true;

                            // instantiate the controller that will call the service
                            var controller = new getSettledBatchListController(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 customerProfileId fetched.");
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("GSBL_00" + flag.ToString());
                                    row1.Add("GetSettledBatchList");
                                    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 batch in response.batchList)
                                    {
                                        Console.WriteLine("Batch Id: {0}", batch.batchId);
                                        Console.WriteLine("Batch settled on (UTC): {0}", batch.settlementTimeUTC);
                                        Console.WriteLine("Batch settled on (Local): {0}", batch.settlementTimeLocal);
                                        Console.WriteLine("Batch settlement state: {0}", batch.settlementState);
                                        Console.WriteLine("Batch market type: {0}", batch.marketType);
                                        Console.WriteLine("Batch product: {0}", batch.product);
                                        foreach (var statistics in batch.statistics)
                                        {
                                            Console.WriteLine(
                                                "Account type: {0} Total charge amount: {1} Charge count: {2} Refund amount: {3} Refund count: {4} Void count: {5} Decline count: {6} Error amount: {7}",
                                                statistics.accountType, statistics.chargeAmount, statistics.chargeCount,
                                                statistics.refundAmount, statistics.refundCount,
                                                statistics.voidCount, statistics.declineCount, statistics.errorCount);
                                        }
                                    }
                                }
                                catch
                                {
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("GSBL_00" + flag.ToString());
                                    row1.Add("GetSettledBatchList");
                                    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.batchList == null)
                                //return response;
                            }
                            else
                            {
                                //Console.WriteLine("Null response");
                                CsvRow row2 = new CsvRow();
                                row2.Add("GSBL_00" + flag.ToString());
                                row2.Add("GetSettledBatchList");
                                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("GSBL_00" + flag.ToString());
                            row2.Add("GetSettledBatchList");
                            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 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);
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        //  public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, decimal amount)
        //  {
        //      Console.WriteLine("Charge Track Data 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,
        //      };

        //      // You can pass either track 1 or track 2 but not both
        //      var trackData = new creditCardTrackType { ItemElementName = ItemChoiceType1.track2, Item = "4111111111111111=170310199999888" };

        //      //standard api call, simply use cardData in place of creditcard type
        //      var paymentType = new paymentType { Item = trackData };

        //      // 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,
        //          lineItems = lineItems,
        //          // Retail data required for POS transactions
        //          retail = new transRetailInfoType { deviceType = "1", marketType = "2" }
        //      };

        //      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 ChargeTrackDataExec(String ApiLoginID, String ApiTransactionKey, decimal amount)
        public static void ChargeTrackDataExec(String ApiLoginID, String ApiTransactionKey)
        {
            using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/ChargeTrackData.csv", FileMode.Open)), true))
            {
                Console.WriteLine("Charge Track Data 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,
                        };

                        // You can pass either track 1 or track 2 but not both
                        var trackData = new creditCardTrackType {
                            ItemElementName = ItemChoiceType1.track2, Item = "4111111111111111=170310199999888"
                        };

                        //standard api call, simply use cardData in place of creditcard type
                        var paymentType = new paymentType {
                            Item = trackData
                        };

                        // 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)
                        };



                        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;
                            }
                        }
                        try
                        {
                            var transactionRequest = new transactionRequestType
                            {
                                transactionType = transactionTypeEnum.authCaptureTransaction.ToString(), // charge the card

                                amount    = Convert.ToDecimal(amount),
                                payment   = paymentType,
                                lineItems = lineItems,
                                // Retail data required for POS transactions
                                retail = new transRetailInfoType {
                                    deviceType = "1", marketType = "2"
                                }
                            };

                            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);
                                            //Console.WriteLine("Assertion Succeed! Valid customerProfileId fetched.");
                                            CsvRow row1 = new CsvRow();
                                            row1.Add("CTD_00" + flag.ToString());
                                            row1.Add("ChargeTrackData");
                                            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("CTD_00" + flag.ToString());
                                            row1.Add("ChargeTrackData");
                                            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("CTD_00" + flag.ToString());
                                        row2.Add("ChargeTrackData");
                                        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("CTD_00" + flag.ToString());
                                    row2.Add("ChargeTrackData");
                                    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("CTD_00" + flag.ToString());
                                row2.Add("ChargeTrackData");
                                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("CTD_00" + flag.ToString());
                            row2.Add("ChargeTrackData");
                            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);
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        //  public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, decimal amount)
        //  {
        //      Console.WriteLine("Authorize 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"
        //      };

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

        //      var transactionRequest = new transactionRequestType
        //      {
        //          transactionType = transactionTypeEnum.authOnlyTransaction.ToString(),    // authorize only
        //          amount = amount,
        //          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 AuthorizeCreditCardExec(String ApiLoginID, String ApiTransactionKey)
        {
            using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/AuthorizeCreditCard.csv", FileMode.Open)), true))
            {
                Console.WriteLine("Authorize 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,
                        };
                        //CustomersApi instance = new CustomersApi(EnvironmentSet.Sandbox);
                        // Customer Response Object
                        // Customer response = null;
                        //initialization



                        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"
                            };

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

                            var transactionRequest = new transactionRequestType
                            {
                                transactionType = transactionTypeEnum.authOnlyTransaction.ToString(),    // authorize only
                                amount          = Convert.ToDecimal(amount),
                                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();

                            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("ACC_00" + flag.ToString());
                                    row1.Add("AuthorizeCreditCard");
                                    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("ACC_00" + flag.ToString());
                                    row1.Add("AuthorizeCreditCard");
                                    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("ACC_00" + flag.ToString());
                                row1.Add("AuthorizeCreditCard");
                                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("ACC_00" + flag.ToString());
                            row2.Add("AuthorizeCreditCard");
                            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);
                        }
                    }
                }
            }
        }
Esempio n. 6
0
        //public CsvFileReader(string filename)
        //    : base(filename)
        //{
        //}

        /// <summary>
        /// Reads a row of data from a CSV file
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public bool ReadRow(CsvRow row)
        {
            row.LineText = ReadLine();
            if (String.IsNullOrEmpty(row.LineText))
            {
                return(false);
            }

            int pos  = 0;
            int rows = 0;

            while (pos < row.LineText.Length)
            {
                string value;

                // Special handling for quoted field
                if (row.LineText[pos] == '"')
                {
                    // Skip initial quote
                    pos++;

                    // Parse quoted value
                    int start = pos;
                    while (pos < row.LineText.Length)
                    {
                        // Test for quote character
                        if (row.LineText[pos] == '"')
                        {
                            // Found one
                            pos++;

                            // If two quotes together, keep one
                            // Otherwise, indicates end of value
                            if (pos >= row.LineText.Length || row.LineText[pos] != '"')
                            {
                                pos--;
                                break;
                            }
                        }
                        pos++;
                    }
                    value = row.LineText.Substring(start, pos - start);
                    value = value.Replace("\"\"", "\"");
                }
                else
                {
                    // Parse unquoted value
                    int start = pos;
                    while (pos < row.LineText.Length && row.LineText[pos] != ',')
                    {
                        pos++;
                    }
                    value = row.LineText.Substring(start, pos - start);
                }

                // Add field to list
                if (rows < row.Count)
                {
                    row[rows] = value;
                }
                else
                {
                    row.Add(value);
                }
                rows++;

                // Eat up to and including next comma
                while (pos < row.LineText.Length && row.LineText[pos] != ',')
                {
                    pos++;
                }
                if (pos < row.LineText.Length)
                {
                    pos++;
                }
            }
            // Delete any unused items
            while (row.Count > rows)
            {
                row.RemoveAt(rows);
            }

            // Return true if any columns read
            return(row.Count > 0);
        }
Esempio n. 7
0
        //public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey)
        //{
        //    Console.WriteLine("Running VisaCheckoutDecrypt Sample ...");

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

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

        //    //create a transaction
        //    var opaqueDataType = new opaqueDataType
        //    {
        //        dataDescriptor = "COMMON.VCO.ONLINE.PAYMENT",
        //        dataKey = "foFBEbhXljevQQasx5Q87hzj57xvUl4iBmXDdB1vs/Lm/M1uKJiF9V5QxI0A6NvAtIckMvutSl0Chz2SNoSeBuTRzK0y4IlfnfWKnJF7a1LV/bjZokTtFKINdZ+Ks9RB",
        //        dataValue = "AjHRw1gU/pQqLQLIElFPBV00dQkzQvZnhAd6XrpVI8MRzhatkmv5MVtggr7XkIfWtiVk8JJQDvuwYAQ6Hl/MNxFIgn7ygGbZm17yAoQpR9l0z0d93I92Oed5sxueqG46CaDCJm1W8zhm9ce8ARn6JyQtDokhHt3psxbfut8q/+cjl8jsIGKKLR+IgA3zPxO3vaL9JEum4bkE3oDJvQhlYJPTjtV3zJRe5n6prvDkMJ9deP0tyiRHaR8OB6BUrCMkyhDLS3ghn2Do7Dv+uN+7bRtj9SuTyUEvDhTx/o3PJ0ELdwBkdKvRh0sLcrK3LkBoto3ppq/a0WT+ckOEz5u+1pUvXAJtCRPHyILvyScFB39OUoxVSvvaBrBGgUaztGqRvVJNhqQmAYU2NQ5DgoWM8TcBzdQwdzqkczbs7egVQa/44+p78zWjzJxoG5cP7EQUNnUL7eaIj3ezbwBtz0ciwNsuCm2bs6vT0hB6GVXwkro5fcvV52Vd32wrpmRJYd20CjfuR7Nit4xKF8VTtmQ0c7A3zgvaUBXH/gOn4KMNXDl8BOKlJaP+hjHy5EhFCW4zO1G1Oz6kOCNY9bQiRhfSw3sSK1gpEiwX8bbjIPpvxiQ1zSaPk5EV+llKF4nMY90qHsE6bS1qp6hqEPLgsQasfdQJ/qQEAZfvuufApEu35ddFYycBz2D8jL/QDEzUIU4/DDOciWAGhlRKfo58H+KcdmcqTAbWOtfNPS1fR33phC0ETUiT3HyQu2rYeY2AdUQZOG5/NULs3nlN2F5TpK3Uhy9hNcuC20PBljcrL0yK6e4C53Md3VHGq31RsTs2lQvcbiURP43peYPeCk+gffN1TUKWfeKuNHcz1Xxc0b4IybMn8uxcaGAraxjdJ1J01I+PuwLgy5Xcsi9SB84CDfxlCNlJvUMgWgyG6iWisjmfzHjEyW+mvI6NFBlqeuRCoOLIpByIRCienHShSGRNRvfyIoHag65QXhR7oTFK93GnilitBNjxBjM+sihiNd+r1XgE8XcuftQObt3c81HL9FIAtrmyAsMEjFl4e1xBdxpGZ3Ft0QMTX12/K0ragGkm5dYmaKigiz3NSOPkT+VieoD0ZpoulXd+8rceocpKhlM0aARbZxKYGaApeyfALlvVH2ilOxn2YPRP7a1Umnr+OtE/yOvvCQfFF0EfEfXmAKoiNbgif7jBjXLWyu7zBLKFmiGI8VboyARpPAFcoOpywqxN6DRCO20A/yHKE5YvR+PPsX0ggrPOts7hEKpp9Z8kd33UC0D3JsxVTsc+L5rwZt1Pk9C4jUOhfWZaINqohS3OVASwfSSmL6JiFivEACvf8FX2D8yz3pz40x79R8nNUy0mQNjrsUzqnNeQjKbKojKvdZvrgcMGYUfyQe3wDIqpqUo8beBkszDrX4Speppb5Qeeu/uYKswus7MhFnhHxQ/eFT9f9K84fXvoP5Zcd+jyWBHen8XwgfNui6XcsEo5IL6X40Zsao+f7LbilFpA+34cldTQybb4SxbqUKhJLmAaL/po8axvJLQenP3vJpfQY5Fbq7oVOXYLJwqm71wf0r1bVTpcgg6pZeD64QCJND3q2DvCWe66uQBcFOQVp9BggUTkKW5hefIUIP3TD1G8HOH508PBCLemVm7Q3TZSG3g+aw25URKTEg+KPpLEQykXYv32FIjM8B3Bq1Z+7t6kRc9u6xtMliAy/kz5UcxaTNlDfrsuw1AISX+3NZ0gIVsKbsZ+nCpnXuv9DeuI55Ccz1A99B2lG2d1zSa9Y+M0wX/KFIkN2wrv2Af7zSVt2ovxoGdbK1wkpErzkqmqupr5Bh16CpccHIsI+DV3yfwgmbaIg0YGaxLjKCoeLTF/RogEsw+2wJjqxgbIXJVtpS5sQqcUrUHpQGl5iee0V1BiGL6Z9qcoARMJ3JwY6FDw6Be7Le38LgONm5FRa7/CQFd8Gh0oyvPgyUKoxlLO1OvlXN8PJ4qMJGRKn6X7KwDrUpjv2pXIzO+t11WHUMprVYq3br0MPjnF6I8bi4CqpKUoYp6jUm4Prx4qCiY7UIWAYsPvjE4Vlp+o0ny0P3wiNGAHmD1bVeoFhsgXI0MIPTlsnYCCy6YkFBI/piXAo0ooxXKvIg6LR3zF0Hopaj85gL3fgIHo/Jo5HlH+z3C/C/5PGEapgDNnlB4jEfNQMOVeBlZZBVmJXIz8eQDMzsDApxp0NE+00HdsrLUbD5H/HbwUHoKK7ipypQltvF1ZQx6N69zllqeI5pwr0F4a+QPfKiPANbcT6qEaUm24K4iXMWQ/5kccHX2t"
        //    };

        //    var decryptPaymentDataRequest = new decryptPaymentDataRequest()
        //    {
        //        opaqueData = opaqueDataType,
        //        callId = "1166739390571781401"
        //    };
        //    //create controller, execute and get response
        //    var decryptPaymentDataController = new decryptPaymentDataController(decryptPaymentDataRequest);
        //    decryptPaymentDataController.Execute();
        //    var decryptPaymentDataResponse = decryptPaymentDataController.GetApiResponse();

        //    if (decryptPaymentDataResponse != null)
        //    {
        //        //validate response
        //        Console.WriteLine("Result : "+decryptPaymentDataResponse.messages.message);
        //        Console.WriteLine("       : "+decryptPaymentDataResponse.messages.resultCode);
        //        Console.WriteLine("First Name : "+decryptPaymentDataResponse.billingInfo.firstName);
        //        Console.WriteLine("Last name  : "+decryptPaymentDataResponse.billingInfo.lastName);
        //        Console.WriteLine("Card Number : "+decryptPaymentDataResponse.cardInfo.cardNumber);
        //        Console.WriteLine("Amount : "+decryptPaymentDataResponse.paymentDetails.amount);
        //    }

        //    return decryptPaymentDataResponse;

        //}

        public static void DecryptVisaCheckoutDataExec(String ApiLoginID, String ApiTransactionKey)
        {
            using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/DecryptVisaCheckoutData.csv", FileMode.Open)), true))
            {
                Console.WriteLine("Running VisaCheckoutDecrypt 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;

                        //create a transaction
                        var opaqueDataType = new opaqueDataType
                        {
                            dataDescriptor = "COMMON.VCO.ONLINE.PAYMENT",
                            dataKey        = "foFBEbhXljevQQasx5Q87hzj57xvUl4iBmXDdB1vs/Lm/M1uKJiF9V5QxI0A6NvAtIckMvutSl0Chz2SNoSeBuTRzK0y4IlfnfWKnJF7a1LV/bjZokTtFKINdZ+Ks9RB",
                            dataValue      = "AjHRw1gU/pQqLQLIElFPBV00dQkzQvZnhAd6XrpVI8MRzhatkmv5MVtggr7XkIfWtiVk8JJQDvuwYAQ6Hl/MNxFIgn7ygGbZm17yAoQpR9l0z0d93I92Oed5sxueqG46CaDCJm1W8zhm9ce8ARn6JyQtDokhHt3psxbfut8q/+cjl8jsIGKKLR+IgA3zPxO3vaL9JEum4bkE3oDJvQhlYJPTjtV3zJRe5n6prvDkMJ9deP0tyiRHaR8OB6BUrCMkyhDLS3ghn2Do7Dv+uN+7bRtj9SuTyUEvDhTx/o3PJ0ELdwBkdKvRh0sLcrK3LkBoto3ppq/a0WT+ckOEz5u+1pUvXAJtCRPHyILvyScFB39OUoxVSvvaBrBGgUaztGqRvVJNhqQmAYU2NQ5DgoWM8TcBzdQwdzqkczbs7egVQa/44+p78zWjzJxoG5cP7EQUNnUL7eaIj3ezbwBtz0ciwNsuCm2bs6vT0hB6GVXwkro5fcvV52Vd32wrpmRJYd20CjfuR7Nit4xKF8VTtmQ0c7A3zgvaUBXH/gOn4KMNXDl8BOKlJaP+hjHy5EhFCW4zO1G1Oz6kOCNY9bQiRhfSw3sSK1gpEiwX8bbjIPpvxiQ1zSaPk5EV+llKF4nMY90qHsE6bS1qp6hqEPLgsQasfdQJ/qQEAZfvuufApEu35ddFYycBz2D8jL/QDEzUIU4/DDOciWAGhlRKfo58H+KcdmcqTAbWOtfNPS1fR33phC0ETUiT3HyQu2rYeY2AdUQZOG5/NULs3nlN2F5TpK3Uhy9hNcuC20PBljcrL0yK6e4C53Md3VHGq31RsTs2lQvcbiURP43peYPeCk+gffN1TUKWfeKuNHcz1Xxc0b4IybMn8uxcaGAraxjdJ1J01I+PuwLgy5Xcsi9SB84CDfxlCNlJvUMgWgyG6iWisjmfzHjEyW+mvI6NFBlqeuRCoOLIpByIRCienHShSGRNRvfyIoHag65QXhR7oTFK93GnilitBNjxBjM+sihiNd+r1XgE8XcuftQObt3c81HL9FIAtrmyAsMEjFl4e1xBdxpGZ3Ft0QMTX12/K0ragGkm5dYmaKigiz3NSOPkT+VieoD0ZpoulXd+8rceocpKhlM0aARbZxKYGaApeyfALlvVH2ilOxn2YPRP7a1Umnr+OtE/yOvvCQfFF0EfEfXmAKoiNbgif7jBjXLWyu7zBLKFmiGI8VboyARpPAFcoOpywqxN6DRCO20A/yHKE5YvR+PPsX0ggrPOts7hEKpp9Z8kd33UC0D3JsxVTsc+L5rwZt1Pk9C4jUOhfWZaINqohS3OVASwfSSmL6JiFivEACvf8FX2D8yz3pz40x79R8nNUy0mQNjrsUzqnNeQjKbKojKvdZvrgcMGYUfyQe3wDIqpqUo8beBkszDrX4Speppb5Qeeu/uYKswus7MhFnhHxQ/eFT9f9K84fXvoP5Zcd+jyWBHen8XwgfNui6XcsEo5IL6X40Zsao+f7LbilFpA+34cldTQybb4SxbqUKhJLmAaL/po8axvJLQenP3vJpfQY5Fbq7oVOXYLJwqm71wf0r1bVTpcgg6pZeD64QCJND3q2DvCWe66uQBcFOQVp9BggUTkKW5hefIUIP3TD1G8HOH508PBCLemVm7Q3TZSG3g+aw25URKTEg+KPpLEQykXYv32FIjM8B3Bq1Z+7t6kRc9u6xtMliAy/kz5UcxaTNlDfrsuw1AISX+3NZ0gIVsKbsZ+nCpnXuv9DeuI55Ccz1A99B2lG2d1zSa9Y+M0wX/KFIkN2wrv2Af7zSVt2ovxoGdbK1wkpErzkqmqupr5Bh16CpccHIsI+DV3yfwgmbaIg0YGaxLjKCoeLTF/RogEsw+2wJjqxgbIXJVtpS5sQqcUrUHpQGl5iee0V1BiGL6Z9qcoARMJ3JwY6FDw6Be7Le38LgONm5FRa7/CQFd8Gh0oyvPgyUKoxlLO1OvlXN8PJ4qMJGRKn6X7KwDrUpjv2pXIzO+t11WHUMprVYq3br0MPjnF6I8bi4CqpKUoYp6jUm4Prx4qCiY7UIWAYsPvjE4Vlp+o0ny0P3wiNGAHmD1bVeoFhsgXI0MIPTlsnYCCy6YkFBI/piXAo0ooxXKvIg6LR3zF0Hopaj85gL3fgIHo/Jo5HlH+z3C/C/5PGEapgDNnlB4jEfNQMOVeBlZZBVmJXIz8eQDMzsDApxp0NE+00HdsrLUbD5H/HbwUHoKK7ipypQltvF1ZQx6N69zllqeI5pwr0F4a+QPfKiPANbcT6qEaUm24K4iXMWQ/5kccHX2t"
                        };

                        var decryptPaymentDataRequest = new decryptPaymentDataRequest()
                        {
                            opaqueData = opaqueDataType,
                            callId     = "1166739390571781401"
                        };
                        //create controller, execute and get response
                        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 decryptPaymentDataController = new decryptPaymentDataController(decryptPaymentDataRequest);
                            decryptPaymentDataController.Execute();
                            var decryptPaymentDataResponse = decryptPaymentDataController.GetApiResponse();

                            if (decryptPaymentDataResponse != null)
                            {
                                /*****************************/
                                try
                                {
                                    //Assert.AreEqual(response.Id, customerProfileId);
                                    //Console.WriteLine("Assertion Succeed! Valid customerProfileId fetched.");
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("DVCD_00" + flag.ToString());
                                    row1.Add("DecryptVisaCheckoutData");
                                    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;

                                    //validate response
                                    Console.WriteLine("Result : " + decryptPaymentDataResponse.messages.message);
                                    Console.WriteLine("       : " + decryptPaymentDataResponse.messages.resultCode);
                                    Console.WriteLine("First Name : " + decryptPaymentDataResponse.billingInfo.firstName);
                                    Console.WriteLine("Last name  : " + decryptPaymentDataResponse.billingInfo.lastName);
                                    Console.WriteLine("Card Number : " + decryptPaymentDataResponse.cardInfo.cardNumber);
                                    Console.WriteLine("Amount : " + decryptPaymentDataResponse.paymentDetails.amount);
                                }
                                catch
                                {
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("DVCD_00" + flag.ToString());
                                    row1.Add("DecryptVisaCheckoutData");
                                    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
                            {
                                CsvRow row1 = new CsvRow();
                                row1.Add("DVCD_00" + flag.ToString());
                                row1.Add("DecryptVisaCheckoutData");
                                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;
                            }

                            //return decryptPaymentDataResponse;
                        }
                        catch (Exception e)
                        {
                            CsvRow row2 = new CsvRow();
                            row2.Add("DVCD_00" + flag.ToString());
                            row2.Add("DecryptVisaCheckoutData");
                            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);
                        }
                    }
                }
            }
        }
Esempio n. 8
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;
                    }
                }
            }
        }
Esempio n. 9
0
        //public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, string customerProfileId)
        //{
        //    Console.WriteLine("CreateCustomerShippingAddress Sample");
        //    ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNET.Environment.SANDBOX;
        //    ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
        //    {
        //        name            = ApiLoginID,
        //        ItemElementName = ItemChoiceType.transactionKey,
        //        Item            = ApiTransactionKey,
        //    };

        //    customerAddressType officeAddress = new customerAddressType();
        //    officeAddress.firstName = "Chris";
        //    officeAddress.lastName = "brown";
        //    officeAddress.address = "1200 148th AVE NE";
        //    officeAddress.city = "NorthBend";
        //    officeAddress.zip = "92101";


        //    var request = new createCustomerShippingAddressRequest
        //    {
        //        customerProfileId = customerProfileId,
        //        address = officeAddress,
        //    };

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

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

        //    return response;
        //}
        public static void CreateCustomerShippingAddressExec(String ApiLoginID, String ApiTransactionKey)
        {
            using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/CreateCustomerAddress.csv", FileMode.Open)), true))
            {
                Console.WriteLine("CreateCustomerShippingAddress Sample");
                int      flag       = 0;
                int      fieldCount = csv.FieldCount;
                string[] headers    = csv.GetFieldHeaders();
                // Writing to output CSV file
                //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 customerId = null;
                        string firstName  = null;
                        string lastName   = null;
                        string address    = null;
                        string city       = null;
                        string zip        = null;
                        string TestcaseID = null;

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

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

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

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

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

                            case "zip":
                                zip = 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);
                                }
                            }
                            //response = instance.GetCustomer(customerId, authorization);
                            customerAddressType officeAddress = new customerAddressType();
                            officeAddress.firstName = firstName;
                            officeAddress.lastName  = lastName;
                            officeAddress.address   = address;
                            officeAddress.city      = city;
                            officeAddress.zip       = zip;

                            var request = new createCustomerShippingAddressRequest();
                            request.customerProfileId = customerId;
                            request.address           = officeAddress;


                            // instantiate the controller that will call the service
                            var controller = new createCustomerShippingAddressController(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("CCSA_00" + flag.ToString());
                                    row1.Add("CreateCustomerShippingAddress");
                                    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, customerAddressId : " + response.customerAddressId);
                                }
                                catch
                                {
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("CCSA_00" + flag.ToString());
                                    row1.Add("CreateCustomerShippingAddress");
                                    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("CCSA_00" + flag.ToString());
                                row1.Add("CreateCustomerShippingAddress");
                                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("CCSA_00" + flag.ToString());
                            row2.Add("createCustomerShippingAddress");
                            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 customerProfileId)
        //{
        //    Console.WriteLine("Update customer 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 profile = new customerProfileExType
        //    {
        //        merchantCustomerId = "custId123",
        //        description = "some description",
        //        email = "*****@*****.**",
        //        customerProfileId = customerProfileId
        //    };

        //    var request = new updateCustomerProfileRequest();
        //    request.profile = profile;

        //    // instantiate the controller that will call the service
        //    var controller = new updateCustomerProfileController(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);
        //    }
        //    else if(response != null)
        //    {
        //        Console.WriteLine("Error: " + response.messages.message[0].code + "  " +
        //                          response.messages.message[0].text);
        //    }

        //    return response;
        //}

        public static void UpdateCustomerProfileExec(String ApiLoginID, String ApiTransactionKey)
        {
            using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/UpdateCustomerProfile.csv", FileMode.Open)), true))
            {
                Console.WriteLine("Update customer profile sample");
                int      flag       = 0;
                int      fieldCount = csv.FieldCount;
                string[] headers    = csv.GetFieldHeaders();
                // Writing to output CSV file
                //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;
                        string description       = null;
                        string email             = null;


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

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

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

                            case "email":
                                email = 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 profile = new customerProfileExType
                            {
                                merchantCustomerId = "custId123",
                                description        = description,
                                email             = email,
                                customerProfileId = customerProfileId
                            };

                            var request = new updateCustomerProfileRequest();
                            request.profile = profile;


                            // instantiate the controller that will call the service
                            var controller = new updateCustomerProfileController(request);
                            controller.Execute();
                            updateCustomerProfileResponse 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("UCP_00" + flag.ToString());
                                    row1.Add("UpdateCustomerProfile");
                                    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);
                                }
                                catch
                                {
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("UCP_00" + flag.ToString());
                                    row1.Add("UpdateCustomerProfile");
                                    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("UCP_00" + flag.ToString());
                                row1.Add("UpdateCustomerProfile");
                                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("UCP_00" + flag.ToString());
                            row2.Add("UpdateCustomerProfile");
                            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);
                        }
                    }
                }
            }
        }
Esempio n. 11
0
        //public static ANetApiResponse Run(string ApiLoginId, string ApiTransactionKey, string customerProfileId)
        //{
        //    Console.WriteLine("Get Accept Customer Profile Page 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,
        //    };

        //    settingType[] settings = new settingType[]{
        //                                        new settingType()
        //                                        // More settings can be added here as and when required
        //                            };
        //    settings[0] = new settingType();
        //    settings[0].settingName = settingNameEnum.hostedProfileReturnUrl.ToString();
        //    settings[0].settingValue = "https://returnurl.com/return/";


        //    var request = new getHostedProfilePageRequest();
        //    request.customerProfileId = customerProfileId;
        //    request.hostedProfileSettings = settings;

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

        //    var response = controller.GetApiResponse();

        //    if (response != null && response.messages.resultCode == messageTypeEnum.Ok)
        //    {
        //        Console.WriteLine(response.messages.message[0].code);
        //        Console.WriteLine(response.messages.message[0].text);
        //        Console.WriteLine("Token: " + response.token.ToString());
        //    }
        //    else if(response != null)
        //    {
        //        Console.WriteLine("Error: " + response.messages.message[0].code + "  " +
        //                                      response.messages.message[0].text);
        //    }

        //    return response;
        //}
        public static void GetAcceptCustomerProfilePageExec(String ApiLoginID, String ApiTransactionKey)
        {
            Console.WriteLine("Get Accept Customer Profile Page sample");
            using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/GetAcceptCustomerProfilePage.csv", FileMode.Open)), true))
            {
                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 customerProfileId = null;
                        string TestCaseId        = null;

                        for (int i = 0; i < fieldCount; i++)
                        {
                            switch (headers[i])
                            {
                            case "customerProfileId":
                                customerProfileId = 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);
                                }
                            }
                            //response = instance.GetCustomer(customerId, authorization);
                            settingType[] settings = new settingType[] {
                                new settingType()
                                // More settings can be added here as and when required
                            };
                            settings[0]              = new settingType();
                            settings[0].settingName  = settingNameEnum.hostedProfileReturnUrl.ToString();
                            settings[0].settingValue = "https://returnurl.com/return/";


                            var request = new getHostedProfilePageRequest();
                            request.customerProfileId     = customerProfileId;
                            request.hostedProfileSettings = settings;

                            var controller = new getHostedProfilePageController(request);
                            controller.Execute();

                            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("GACPP_00" + flag.ToString());
                                    row1.Add("GetAcceptCustomerProfilePage");
                                    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].code);
                                    Console.WriteLine(response.messages.message[0].text);
                                    Console.WriteLine("Token: " + response.token.ToString());
                                }
                                catch
                                {
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("GACPP_00" + flag.ToString());
                                    row1.Add("GetAcceptCustomerProfilePage");
                                    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("GACPP_00" + flag.ToString());
                                row1.Add("GetAcceptCustomerProfilePage");
                                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("GACPP_00" + flag.ToString());
                            row2.Add("GetAcceptCustomerProfilePage");
                            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);
                        }
                    }
                }
            }
        }
Esempio n. 12
0
        //  public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, string TransactionID)
        //  {
        //      Console.WriteLine("Credit Bank Account");

        //      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.refundTransaction.ToString(),    // refund type
        //          payment         = paymentType,
        //          amount          = 126.44m,
        //          refTransId      = TransactionID
        //      };

        //      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 CreditBankAccountExec(String ApiLoginID, String ApiTransactionKey)
        {
            using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/CreditBankAccount.csv", FileMode.Open)), true))
            {
                Console.WriteLine("Credit Bank Account");
                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 TransactionID = null;
                        string TestcaseID    = 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;
                            }
                        }
                        try
                        {
                            var transactionRequest = new transactionRequestType
                            {
                                transactionType = transactionTypeEnum.refundTransaction.ToString(),    // refund type
                                payment         = paymentType,
                                amount          = 126.44m,
                                refTransId      = TransactionID
                            };
                            //Write to output file
                            CsvRow row = new CsvRow();

                            if (flag == 0)
                            {
                                row.Add("TestCaseId");
                                row.Add("APIName");
                                row.Add("Status");
                                row.Add("TimeStamp");
                                writer.WriteRow(row);
                                //foreach (var item in records1)
                                //{
                                //    CsvRow row_prev = new CsvRow();
                                //    row_prev.Add(item.TestCaseId.ToString());
                                //    row_prev.Add(item.APIName.ToString());
                                //    row_prev.Add(item.Status.ToString());
                                //    row_prev.Add(item.TimeStamp.ToString());
                                //    writer.WriteRow(row_prev);
                                //}
                                //Append Results
                                foreach (var item in item1)
                                {
                                    writer.WriteRow(item);
                                }
                                flag = flag + 1;
                            }
                            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);
                                            //Console.WriteLine("Assertion Succeed! Valid CustomerId fetched.");
                                            CsvRow row1 = new CsvRow();
                                            row1.Add("CBA_00" + flag.ToString());
                                            row1.Add("CreditBankAccount");
                                            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("CBA_00" + flag.ToString());
                                            row1.Add("CreditBankAccount");
                                            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
                                    {
                                        Console.WriteLine("Failed Transaction.");
                                        CsvRow row2 = new CsvRow();
                                        row2.Add("GCP_00" + flag.ToString());
                                        row2.Add("CreditBankAccount");
                                        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("GCP_00" + flag.ToString());
                                    row2.Add("CreditBankAccount");
                                    row2.Add("Fail");
                                    row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                    writer.WriteRow(row2);
                                    flag = flag + 1;
                                    //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.");
                                CsvRow row2 = new CsvRow();
                                row2.Add("GCP_00" + flag.ToString());
                                row2.Add("CreditBankAccount");
                                row2.Add("Fail");
                                row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                writer.WriteRow(row2);
                                flag = flag + 1;
                            }
                        }
                        catch (Exception e)
                        {
                            CsvRow row2 = new CsvRow();
                            row2.Add("GCP_00" + flag.ToString());
                            row2.Add("CreditBankAccount");
                            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);
                        }
                    }
                }
            }
        }
Esempio n. 13
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);
                        }
                    }
                }
            }
        }
Esempio n. 14
0
        //public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey)
        //{
        //    Console.WriteLine("Get 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,
        //    };

        //    // unique batch id
        //    string batchId = "12345";

        //    var request = new getTransactionListRequest();
        //    request.batchId = batchId;
        //    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 getTransactionListController(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 transaction in response.transactions)
        //        {
        //            Console.WriteLine("Transaction Id: {0}", transaction.transId);
        //            Console.WriteLine("Submitted on (Local): {0}", transaction.submitTimeLocal);
        //            Console.WriteLine("Status: {0}", transaction.transactionStatus);
        //            Console.WriteLine("Settle amount: {0}", transaction.settleAmount);
        //        }
        //    }
        //    else if(response != null)
        //    {
        //        Console.WriteLine("Error: " + response.messages.message[0].code + "  " +
        //                          response.messages.message[0].text);
        //    }

        //    return response;
        //}

        public static void GetTransactionListExec(String ApiLoginID, String ApiTransactionKey)
        {
            using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/GetTransactionList.csv", FileMode.Open)), true))
            {
                Console.WriteLine("Get transaction list sample");
                // var data = csv.GetCurrentRawData();// GetRecords<string[]>().ToList();//sharath
                int      flag       = 0;
                int      fieldCount = csv.FieldCount;
                string[] headers    = csv.GetFieldHeaders();
                //sharath
                //List<CsvRow> lstCsv = new List<CsvRow>();
                //using (CsvReader reader = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/Outputfile.csv", FileMode.Open)), true))
                //{
                //    int fieldCount1 = reader.FieldCount;

                //    string[] headers1 = reader.GetFieldHeaders();
                //    while (reader.ReadNextRecord())
                //    {
                //        CsvRow rowcsv = new CsvRow();
                //        for (int i = 0; i < fieldCount1; i++)
                //        {
                //            try { rowcsv.Add(reader[i]); }
                //            catch (Exception e)
                //            { }
                //        }
                //        lstCsv.Add(rowcsv);
                //        //Console.Write(string.Format("{0} = {1};",
                //        //   headers1[i], reader[i]));
                //        // Console.WriteLine();
                //        //  Console.Read();
                //    }

                //}

                ////sharath


                //Append Data
                var item1 = DataAppend.ReadPrevData();

                using (CsvFileWriter writer = new CsvFileWriter(new FileStream(@"../../../CSV_DATA/Outputfile.csv", FileMode.Open)))
                {
                    while (csv.ReadNextRecord())
                    {
                        try
                        {
                            ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNET.Environment.SANDBOX;
                            // define the merchant information (authentication / transaction id)


                            // unique batch id
                            string batchId = "12345";

                            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];
                                    // ApiLoginID = apiLogin;
                                    break;

                                case "transactionKey":
                                    transactionKey = csv[i];
                                    // ApiTransactionKey = transactionKey;
                                    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;
                                    //sharath
                                    foreach (var item in item1)
                                    {
                                        writer.WriteRow(item);
                                    }
                                    //sharath
                                }
                                var request = new getTransactionListRequest();
                                request.batchId = batchId;
                                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 getTransactionListController(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("GTL_00" + flag.ToString());
                                        row1.Add("GetTransactionList");
                                        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 transaction in response.transactions)
                                        {
                                            Console.WriteLine("Transaction Id: {0}", transaction.transId);
                                            Console.WriteLine("Submitted on (Local): {0}", transaction.submitTimeLocal);
                                            Console.WriteLine("Status: {0}", transaction.transactionStatus);
                                            Console.WriteLine("Settle amount: {0}", transaction.settleAmount);
                                        }
                                    }
                                    catch
                                    {
                                        CsvRow row1 = new CsvRow();
                                        row1.Add("GTL_00" + flag.ToString());
                                        row1.Add("GetTransactionList");
                                        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 transaction in response.transactions)
                                    //    {
                                    //        Console.WriteLine("Transaction Id: {0}", transaction.transId);
                                    //        Console.WriteLine("Submitted on (Local): {0}", transaction.submitTimeLocal);
                                    //        Console.WriteLine("Status: {0}", transaction.transactionStatus);
                                    //        Console.WriteLine("Settle amount: {0}", transaction.settleAmount);
                                    //    }
                                    //}
                                }
                                else
                                {
                                    //Console.WriteLine("Error: " + response.messages.message[0].code + "  " +
                                    //                  response.messages.message[0].text);
                                    CsvRow row2 = new CsvRow();
                                    row2.Add("GTL_00" + flag.ToString());
                                    row2.Add("GetTransactionList");
                                    row2.Add("Fail");
                                    row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                    writer.WriteRow(row2);
                                    flag = flag + 1;
                                }

                                //return response;
                            }

                            //return response;
                            catch (Exception e)
                            {
                                CsvRow row2 = new CsvRow();
                                row2.Add("GTL_00" + flag.ToString());
                                row2.Add("GetTransactionList");
                                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);
                            }
                        }

                        catch (Exception ex)
                        {
                            CsvRow row2 = new CsvRow();
                            row2.Add("GTL_00" + flag.ToString());
                            row2.Add("GetTransactionList");
                            row2.Add("Fail");
                            row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                            writer.WriteRow(row2);
                            flag = flag + 1;
                        }
                    }
                }
            }
        }
Esempio n. 15
0
        //public static ANetApiResponse Run(string ApiLoginID, string ApiTransactionKey, string emailId)
        //{
        //    Console.WriteLine("CreateCustomerProfile Sample");

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


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

        //    var bankAccount = new bankAccountType
        //    {
        //        accountNumber = "231323342",
        //        routingNumber = "000000224",
        //        accountType = bankAccountTypeEnum.checking,
        //        echeckType = echeckTypeEnum.WEB,
        //        nameOnAccount = "test",
        //        bankName = "Bank Of America"
        //    };

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

        //    List<customerPaymentProfileType> paymentProfileList = new List<customerPaymentProfileType>();
        //    customerPaymentProfileType ccPaymentProfile = new customerPaymentProfileType();
        //    ccPaymentProfile.payment = cc;

        //    customerPaymentProfileType echeckPaymentProfile = new customerPaymentProfileType();
        //    echeckPaymentProfile.payment = echeck;

        //    paymentProfileList.Add(ccPaymentProfile);
        //    paymentProfileList.Add(echeckPaymentProfile);

        //    List<customerAddressType> addressInfoList = new List<customerAddressType>();
        //    customerAddressType homeAddress = new customerAddressType();
        //    homeAddress.address = "10900 NE 8th St";
        //    homeAddress.city = "Seattle";
        //    homeAddress.zip = "98006";


        //    customerAddressType officeAddress = new customerAddressType();
        //    officeAddress.address = "1200 148th AVE NE";
        //    officeAddress.city = "NorthBend";
        //    officeAddress.zip = "92101";

        //    addressInfoList.Add(homeAddress);
        //    addressInfoList.Add(officeAddress);


        //    customerProfileType customerProfile = new customerProfileType();
        //    customerProfile.merchantCustomerId = "Test CustomerID";
        //    customerProfile.email = emailId;
        //    customerProfile.paymentProfiles = paymentProfileList.ToArray();
        //    customerProfile.shipToList = addressInfoList.ToArray();

        //    var request = new createCustomerProfileRequest{ profile = customerProfile, validationMode = validationModeEnum.none};

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

        //    createCustomerProfileResponse 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)
        //        {
        //            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 CreateCustomerProfileExec(String ApiLoginID, String ApiTransactionKey)
        {
            using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/CreateCustomerProfile.csv", FileMode.Open)), true))
            {
                Console.WriteLine("CreateCustomerProfile Sample");
                int      fieldCount = csv.FieldCount;
                int      flag       = 0;
                string[] headers    = csv.GetFieldHeaders();
                // Writing to output CSV file
                //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 description = null;
                        string email       = null;



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

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

                            case "email":
                                email = 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"
                            };

                            var bankAccount = new bankAccountType
                            {
                                accountNumber = "231323342",
                                routingNumber = "000000224",
                                accountType   = bankAccountTypeEnum.checking,
                                echeckType    = echeckTypeEnum.WEB,
                                nameOnAccount = "test",
                                bankName      = "Bank Of America"
                            };
                            //standard api call to retrieve response
                            paymentType cc = new paymentType {
                                Item = creditCard
                            };
                            paymentType echeck = new paymentType {
                                Item = bankAccount
                            };

                            List <customerPaymentProfileType> paymentProfileList = new List <customerPaymentProfileType>();
                            customerPaymentProfileType        ccPaymentProfile   = new customerPaymentProfileType();
                            ccPaymentProfile.payment = cc;

                            customerPaymentProfileType echeckPaymentProfile = new customerPaymentProfileType();
                            echeckPaymentProfile.payment = echeck;

                            paymentProfileList.Add(ccPaymentProfile);
                            paymentProfileList.Add(echeckPaymentProfile);

                            List <customerAddressType> addressInfoList = new List <customerAddressType>();
                            customerAddressType        homeAddress     = new customerAddressType();
                            homeAddress.address = "10900 NE 8th St";
                            homeAddress.city    = "Seattle";
                            homeAddress.zip     = "98006";


                            customerAddressType officeAddress = new customerAddressType();
                            officeAddress.address = "1200 148th AVE NE";
                            officeAddress.city    = "NorthBend";
                            officeAddress.zip     = "92101";

                            addressInfoList.Add(homeAddress);
                            addressInfoList.Add(officeAddress);


                            customerProfileType customerProfile = new customerProfileType();
                            customerProfile.merchantCustomerId = "Test CustomerID";
                            customerProfile.email           = email;
                            customerProfile.description     = description;
                            customerProfile.paymentProfiles = paymentProfileList.ToArray();
                            customerProfile.shipToList      = addressInfoList.ToArray();
                            var request = new createCustomerProfileRequest
                            {
                                profile = customerProfile, validationMode = validationModeEnum.none
                            };


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

                            // get the response from the service (errors contained if any)
                            createCustomerProfileResponse 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("CCP_00" + flag.ToString());
                                    row1.Add("CreateCustomerProfile");
                                    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("CCP_00" + flag.ToString());
                                    row1.Add("CreateCustomerProfile");
                                    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("CCP_00" + flag.ToString());
                                row1.Add("CreateCustomerProfile");
                                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("CCP_00" + flag.ToString());
                            row2.Add("CreateCustomerProfile");
                            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);
                        }
                    }
                }
            }
        }
Esempio n. 16
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);
                        }
                    }
                }
            }
        }
Esempio n. 17
0
        //public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey)
        //{
        //    Console.WriteLine("Approve held transaction 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 updateHeldTransactionRequest();
        //    request.heldTransactionRequest = new heldTransactionRequestType
        //    {
        //        action = afdsTransactionEnum.approve,
        //        refTransId = "60012192922"
        //    };

        //    // instantiate the controller that will call the service
        //    var controller = new updateHeldTransactionController(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("Transaction Approved: "+response.transactionResponse.transId);
        //    }
        //    else if (response != null)
        //    {
        //        Console.WriteLine("Error: " + response.messages.message[0].code + "  " +
        //                          response.messages.message[0].text);
        //    }

        //    return response;
        //}

        public static void ApproveOrDeclineHeldTransactionExec(String ApiLoginID, String ApiTransactionKey)
        {
            using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/ApproveOrDeclineHeldTransaction.csv", FileMode.Open)), true))
            {
                Console.WriteLine("Approve held transaction 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;
                            }
                        }
                        // 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 updateHeldTransactionRequest();
                            request.heldTransactionRequest = new heldTransactionRequestType
                            {
                                action     = afdsTransactionEnum.approve,
                                refTransId = "60012192922"
                            };

                            // instantiate the controller that will call the service
                            var controller = new updateHeldTransactionController(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 customerProfileId fetched.");
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("ADHT_00" + flag.ToString());
                                    row1.Add("ApproveOrDeclineHeldTransaction");
                                    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("Transaction Approved: " + response.transactionResponse.transId);
                                }
                                catch
                                {
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("ADHT_00" + flag.ToString());
                                    row1.Add("ApproveOrDeclineHeldTransaction");
                                    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
                            {
                                CsvRow row1 = new CsvRow();
                                row1.Add("ADHT_00" + flag.ToString());
                                row1.Add("ApproveOrDeclineHeldTransaction");
                                row1.Add("Fail");
                                row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                writer.WriteRow(row1);
                                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("ADHT_00" + flag.ToString());
                            row2.Add("ApproveOrDeclineHeldTransaction");
                            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("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);
                        }
                    }
                }
            }
        }
Esempio n. 19
0
        //public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, string customerProfileId, string customerPaymentProfileId)
        //{
        //    Console.WriteLine("Update 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 creditCard = new creditCardType
        //    {
        //        cardNumber = "4111111111111111",
        //        expirationDate = "0718"
        //    };

        //    //===========================================================================
        //    // NOTE:  For updating just the address, not the credit card/payment data
        //    //        you can pass the masked values returned from
        //    //        GetCustomerPaymentProfile or GetCustomerProfile
        //    //        E.g.
        //    //                * literal values shown below
        //    //===========================================================================
        //    /*var creditCard = new creditCardType
        //    {
        //        cardNumber = "XXXX1111",
        //        expirationDate = "XXXX"
        //    };*/

        //    var paymentType = new paymentType { Item = creditCard };

        //    var paymentProfile = new customerPaymentProfileExType
        //    {
        //        billTo = new customerAddressType
        //        {
        //            // change information as required for billing
        //            firstName = "John",
        //            lastName = "Doe",
        //            address = "123 Main St.",
        //            city = "Bellevue",
        //            state = "WA",
        //            zip = "98004",
        //            country = "USA",
        //            phoneNumber = "000-000-000",
        //        },
        //        payment = paymentType,
        //        customerPaymentProfileId = customerPaymentProfileId
        //    };

        //    var request = new updateCustomerPaymentProfileRequest();
        //    request.customerProfileId = customerProfileId;
        //    request.paymentProfile = paymentProfile;
        //    request.validationMode = validationModeEnum.liveMode;


        //    // instantiate the controller that will call the service
        //    var controller = new updateCustomerPaymentProfileController(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);
        //    }
        //    else if (response != null)
        //    {
        //        Console.WriteLine("Error: " + response.messages.message[0].code + "  " +
        //                          response.messages.message[0].text);
        //    }

        //    return response;
        //}

        public static void UpdateCustomerPaymentProfileExec(String ApiLoginID, String ApiTransactionKey)
        {
            using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/UpdateCustomerPaymentProfile.csv", FileMode.Open)), true))
            {
                Console.WriteLine("Update 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,
                        };

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

                        //===========================================================================
                        // NOTE:  For updating just the address, not the credit card/payment data
                        //        you can pass the masked values returned from
                        //        GetCustomerPaymentProfile or GetCustomerProfile
                        //        E.g.
                        //                * literal values shown below
                        //===========================================================================

                        /*var creditCard = new creditCardType
                         * {
                         *  cardNumber = "XXXX1111",
                         *  expirationDate = "XXXX"
                         * };*/
                        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 paymentType = new paymentType {
                                Item = creditCard
                            };

                            var paymentProfile = new customerPaymentProfileExType
                            {
                                billTo = new customerAddressType
                                {
                                    // change information as required for billing
                                    firstName   = "John",
                                    lastName    = "Doe",
                                    address     = "123 Main St.",
                                    city        = "Bellevue",
                                    state       = "WA",
                                    zip         = "98004",
                                    country     = "USA",
                                    phoneNumber = "000-000-000",
                                },
                                payment = paymentType,
                                customerPaymentProfileId = customerPaymentProfileId
                            };

                            var request = new updateCustomerPaymentProfileRequest();
                            request.customerProfileId = customerProfileId;
                            request.paymentProfile    = paymentProfile;
                            request.validationMode    = validationModeEnum.liveMode;


                            // instantiate the controller that will call the service
                            var controller = new updateCustomerPaymentProfileController(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);
                                /*****************************/
                                try
                                {
                                    //Assert.AreEqual(response.Id, customerProfileId);
                                    Console.WriteLine("Assertion Succeed! Valid CustomerPaymentProfile updated.");
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("UCPP_00" + flag.ToString());
                                    row1.Add("UpdateCustomerPaymentProfile");
                                    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;
                                }
                                catch
                                {
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("UCPP_00" + flag.ToString());
                                    row1.Add("UpdateCustomerPaymentProfile");
                                    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 updated.");
                                    flag = flag + 1;
                                }
                                /*******************/
                            }
                            else
                            {
                                CsvRow row1 = new CsvRow();
                                row1.Add("UCPP_00" + flag.ToString());
                                row1.Add("UpdateCustomerPaymentProfile");
                                row1.Add("Fail");
                                row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                writer.WriteRow(row1);
                                Console.WriteLine("Assertion Failed! Invalid CustomerPaymentProfile updated.");
                                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("UCPP_00" + flag.ToString());
                            row2.Add("UpdateCustomerPaymentProfile");
                            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, short intervalLength,
        //    string customerProfileId, string customerPaymentProfileId, string customerAddressId)
        //{
        //    Console.WriteLine("Create Subscription Sample");

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

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

        //    paymentScheduleTypeInterval interval = new paymentScheduleTypeInterval();

        //    interval.length = intervalLength;                        // months can be indicated between 1 and 12
        //    interval.unit   = ARBSubscriptionUnitEnum.days;

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

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

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

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

        //    ARBSubscriptionType subscriptionType = new ARBSubscriptionType()
        //    {
        //        amount = 35.55m,
        //        trialAmount = 0.00m,
        //        paymentSchedule = schedule,
        //        profile = customerProfile
        //    };

        //    var request = new ARBCreateSubscriptionRequest {subscription = subscriptionType };

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

        //    ARBCreateSubscriptionResponse 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)
        //        {
        //            Console.WriteLine("Success, Subscription ID : " + response.subscriptionId.ToString());
        //        }
        //    }
        //    else if(response != null)
        //    {
        //        Console.WriteLine("Error: " + response.messages.message[0].code + "  " + response.messages.message[0].text);
        //    }

        //    return response;
        //}
        public static void CreateSubscriptionFromCustomerProfileExec(String ApiLoginID, String ApiTransactionKey)
        {
            using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/CreateASubscriptionFromCustomerProfile.csv", FileMode.Open)), true))
            {
                Console.WriteLine("Create 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 customerProfileId        = null;
                        string TestCase_Id              = null;
                        string length                   = null;
                        string customerPaymentProfileId = null;
                        string customerAddressId        = null;
                        for (int i = 0; i < fieldCount; i++)
                        {
                            switch (headers[i])
                            {
                            case "customerProfileId":
                                customerProfileId = csv[i];
                                break;

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

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

                            case "length":
                                length = 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);
                                }
                            }
                            paymentScheduleTypeInterval interval = new paymentScheduleTypeInterval();

                            interval.length = Convert.ToInt16(length);                        // months can be indicated between 1 and 12
                            interval.unit   = ARBSubscriptionUnitEnum.days;

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

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

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

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

                            ARBSubscriptionType subscriptionType = new ARBSubscriptionType()
                            {
                                amount          = 35.55m,
                                trialAmount     = 0.00m,
                                paymentSchedule = schedule,
                                profile         = customerProfile
                            };

                            var request = new ARBCreateSubscriptionRequest {
                                subscription = subscriptionType
                            };

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

                            ARBCreateSubscriptionResponse 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("CASFCP_00" + flag.ToString());
                                    row1.Add("CreateSubscriptionFromCustomerProfile");
                                    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, Subscription ID : " + response.subscriptionId.ToString());
                                }
                                catch
                                {
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("CASFCP_00" + flag.ToString());
                                    row1.Add("CreateSubscriptionFromCustomerProfile");
                                    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("CASFCP_00" + flag.ToString());
                                row1.Add("CreateSubscriptionFromCustomerProfile");
                                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("CASFCP_00" + flag.ToString());
                            row2.Add("CreateSubscriptionFromCustomerProfile");
                            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);
                        }
                    }
                }
            }
        }
Esempio n. 22
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);
                        }
                    }
                }
            }
        }
Esempio n. 23
0
        //public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey)
        //{
        //    Console.WriteLine("Get Customer Profile Id 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 getCustomerProfileIdsRequest();

        //    // instantiate the controller that will call the service
        //    var controller = new getCustomerProfileIdsController(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 Profile Ids: ");
        //        foreach (var id in response.ids)
        //        {
        //            Console.WriteLine(id);
        //        }
        //    }
        //    else if (response != null)
        //    {
        //        Console.WriteLine("Error: " + response.messages.message[0].code + "  " +
        //                          response.messages.message[0].text);
        //    }

        //    return response;
        //}
        public static void GetCustomerProfileIdsExec(String ApiLoginID, String ApiTransactionKey)
        {
            using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/GetCustomerProfileIds.csv", FileMode.Open)), true))
            {
                Console.WriteLine("Get Customer Profile Id 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())
                    {
                        ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNET.Environment.SANDBOX;

                        string apiLogin       = null;
                        string transactionKey = null;
                        string TestcaseID     = null;


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

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

                            case "TestcaseID":
                                TestcaseID = 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,
                        };
                        //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 getCustomerProfileIdsRequest();



                            // instantiate the controller that will call the service
                            var controller = new getCustomerProfileIdsController(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("GCPI_00" + flag.ToString());
                                    row1.Add("GetCustomerProfileIds");
                                    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 Profile Ids: ");
                                    foreach (var id in response.ids)
                                    {
                                        Console.WriteLine(id);
                                    }
                                }
                                catch
                                {
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("GCPI_00" + flag.ToString());
                                    row1.Add("GetCustomerProfileIds");
                                    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("GCPI_00" + flag.ToString());
                                row1.Add("GetCustomerProfileIds");
                                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("GCPI_00" + flag.ToString());
                            row2.Add("GetCustomerProfileIds");
                            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);
                        }
                    }
                }
            }
        }
Esempio n. 24
0
        //public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey)
        //{
        //    Console.WriteLine("Get suspicious 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.pendingApproval;
        //    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 GetHeldTransactionListExec(String ApiLoginID, String ApiTransactionKey)
        {
            using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/GetHeldTransactionList.csv", FileMode.Open)), true))
            {
                Console.WriteLine("Get suspicious 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 Results
                                foreach (var item in item1)
                                {
                                    writer.WriteRow(item);
                                }
                            }
                            var request = new getUnsettledTransactionListRequest();
                            request.status          = TransactionGroupStatusEnum.pendingApproval;
                            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)
                            {
                                /*****************************/
                                try
                                {
                                    //Assert.AreEqual(response.Id, customerProfileId);
                                    //Console.WriteLine("Assertion Succeed! Valid customerProfileId fetched.");
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("GHT_00" + flag.ToString());
                                    row1.Add("GetHeldTransactionList");
                                    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;
                                }
                                catch
                                {
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("GHT_00" + flag.ToString());
                                    row1.Add("GetHeldTransactionList");
                                    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
                            {
                                CsvRow row2 = new CsvRow();
                                row2.Add("GHT_00" + flag.ToString());
                                row2.Add("GetHeldTransactionList");
                                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("GHT_00" + flag.ToString());
                            row2.Add("GetHeldTransactionList");
                            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 customerProfileId,
        //      string customerPaymentProfileId, decimal Amount)
        //  {
        //      Console.WriteLine("Charge Customer Profile");

        //      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
        //      };

        //      //create a customer payment profile
        //      customerProfilePaymentType profileToCharge = new customerProfilePaymentType();
        //      profileToCharge.customerProfileId = customerProfileId;
        //      profileToCharge.paymentProfile = new paymentProfile { paymentProfileId = customerPaymentProfileId };

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

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

        //      // instantiate the collector 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 ChargeCustomerProfileExec(String ApiLoginID, String ApiTransactionKey)
        {
            using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/ChargeCustomerProfile.csv", FileMode.Open)), true))
            {
                Console.WriteLine("Charge Customer Profile");

                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 amount     = null;
                        string TestCaseId = null;
                        string customerPaymentProfileId = 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;

                            case "customerPaymentProfileId":
                                customerPaymentProfileId = 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);
                                }
                            }


                            //create a customer payment profile
                            customerProfilePaymentType profileToCharge = new customerProfilePaymentType();
                            profileToCharge.customerProfileId = customerProfileId;
                            profileToCharge.paymentProfile    = new paymentProfile {
                                paymentProfileId = customerPaymentProfileId
                            };

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

                            var request = new createTransactionRequest {
                                transactionRequest = transactionRequest
                            };

                            // instantiate the collector 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) && (response.messages.resultCode == messageTypeEnum.Ok) &&
                                (response.transactionResponse.messages != 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("CCP_00" + flag.ToString());
                                    row1.Add("ChargeCustomerProfile");
                                    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("CCP_00" + flag.ToString());
                                    row1.Add("ChargeCustomerProfile");
                                    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 row1 = new CsvRow();
                                //    row1.Add("CCP_00" + flag.ToString());
                                //    row1.Add("ChargeCustomerProfile");
                                //    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.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("CCP_00" + flag.ToString());
                                //    row2.Add("ChargeCustomerProfile");
                                //    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
                            {
                                CsvRow row2 = new CsvRow();
                                row2.Add("CCP_00" + flag.ToString());
                                row2.Add("ChargeCustomerProfile");
                                row2.Add("Fail");
                                row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                writer.WriteRow(row2);
                                flag = flag + 1;
                                if (response == null)
                                {
                                    Console.WriteLine("Null Response.");
                                }
                                else
                                {
                                    Console.WriteLine("WAP");
                                }
                                ;
                            }
                        }

                        //return response;
                        catch (Exception e)
                        {
                            CsvRow row2 = new CsvRow();
                            row2.Add("CCP_00" + flag.ToString());
                            row2.Add("ChargeCustomerProfile");
                            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, decimal amount)
        //  {
        //      Console.WriteLine("Charge Encrypted Track Data 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,
        //      };


        //      // Track data goes in EncryptedTrack Data Type
        //      var cardData = new encryptedTrackDataType();

        //      // KeyManagementScheme corresponds to the encryption settings and data from the reader
        //      var scheme = new KeyManagementScheme();
        //      scheme.DUKPT = new KeyManagementSchemeDUKPT {
        //          Operation = OperationType.DECRYPT,
        //          DeviceInfo = new KeyManagementSchemeDUKPTDeviceInfo { Description = "4649443D4944544543482E556E694D61672E416E64726F69642E53646B7631" },
        //          EncryptedData = new KeyManagementSchemeDUKPTEncryptedData { Value = "02f300801f342600039b252a343237352a2a2a2a2a2a2a2a353637355e332f54455354205e2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a3f2a3b343237352a2a2a2a2a2a2a2a353637353d2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a3f2a521db2603bfe6169fc371211161c4ad6edd7294a8352af1ba8b388c527d8d6335286413ad67521b8be085da998cef7ae3621b0b72eecd6d61953a4a268e02a8cdff3d365216df73646b326d8dac369c11a2a3a4a9336addc4a15ae5d8843e0163bae895b9b4df3253439b4dd885363ad108604ea04f2e4fac701a5a0e65c54e1301a5ed7706eb88762994901000000400015ac1e03" },
        //          Mode = new KeyManagementSchemeDUKPTMode { Data = null, PIN = "1" }
        //      };

        //      cardData.FormOfPayment = new KeyBlock { Value = new KeyValue { Encoding = EncodingType.Hex, EncryptionAlgorithm = EncryptionAlgorithmType.TDES, Scheme = scheme } };


        //      //standard api call, simply use cardData in place of creditcard type
        //      var paymentType = new paymentType { Item = cardData };

        //      // 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,
        //          lineItems = lineItems,
        //          // Retail data required for POS transactions
        //          retail = new transRetailInfoType { deviceType = "1", marketType = "2" }
        //      };

        //      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 ChargeEncryptedTrackDataExec(String ApiLoginID, String ApiTransactionKey)
        {
            using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/ChargeEncryptedTrackData.csv", FileMode.Open)), true))
            {
                Console.WriteLine("Charge Encrypted Track Data 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,
                        };


                        // Track data goes in EncryptedTrack Data Type
                        var cardData = new encryptedTrackDataType();

                        // KeyManagementScheme corresponds to the encryption settings and data from the reader
                        var scheme = new KeyManagementScheme();
                        scheme.DUKPT = new KeyManagementSchemeDUKPT
                        {
                            Operation  = OperationType.DECRYPT,
                            DeviceInfo = new KeyManagementSchemeDUKPTDeviceInfo {
                                Description = "4649443D4944544543482E556E694D61672E416E64726F69642E53646B7631"
                            },
                            EncryptedData = new KeyManagementSchemeDUKPTEncryptedData {
                                Value = "02f300801f342600039b252a343237352a2a2a2a2a2a2a2a353637355e332f54455354205e2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a3f2a3b343237352a2a2a2a2a2a2a2a353637353d2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a3f2a521db2603bfe6169fc371211161c4ad6edd7294a8352af1ba8b388c527d8d6335286413ad67521b8be085da998cef7ae3621b0b72eecd6d61953a4a268e02a8cdff3d365216df73646b326d8dac369c11a2a3a4a9336addc4a15ae5d8843e0163bae895b9b4df3253439b4dd885363ad108604ea04f2e4fac701a5a0e65c54e1301a5ed7706eb88762994901000000400015ac1e03"
                            },
                            Mode = new KeyManagementSchemeDUKPTMode {
                                Data = null, PIN = "1"
                            }
                        };

                        cardData.FormOfPayment = new KeyBlock {
                            Value = new KeyValue {
                                Encoding = EncodingType.Hex, EncryptionAlgorithm = EncryptionAlgorithmType.TDES, Scheme = scheme
                            }
                        };


                        //standard api call, simply use cardData in place of creditcard type
                        var paymentType = new paymentType {
                            Item = cardData
                        };

                        // 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)
                        };

                        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(), // charge the card

                                amount    = Convert.ToDecimal(amount),
                                payment   = paymentType,
                                lineItems = lineItems,
                                // Retail data required for POS transactions
                                retail = new transRetailInfoType {
                                    deviceType = "1", marketType = "2"
                                }
                            };

                            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);
                                            //Console.WriteLine("Assertion Succeed! Valid customerProfileId fetched.");
                                            CsvRow row1 = new CsvRow();
                                            row1.Add("CETD_00" + flag.ToString());
                                            row1.Add("ChargeEncryptedTrackData");
                                            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("CETD_00" + flag.ToString());
                                            row1.Add("ChargeEncryptedTrackData");
                                            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("CETD_00" + flag.ToString());
                                        row2.Add("ChargeEncryptedTrackData");
                                        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("CETD_00" + flag.ToString());
                                    row2.Add("ChargeEncryptedTrackData");
                                    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("CETD_00" + flag.ToString());
                                row2.Add("ChargeEncryptedTrackData");
                                row2.Add("Fail");
                                row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                writer.WriteRow(row2);
                                flag = flag + 1;
                            }

                            //return response;
                        }

                        //return response;
                        catch (Exception e)
                        {
                            CsvRow row2 = new CsvRow();
                            row2.Add("CETD_00" + flag.ToString());
                            row2.Add("ChargeEncryptedTrackData");
                            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);
                        }
                    }
                }
            }
        }
Esempio n. 27
0
        //public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, string subscriptionId)
        //{
        //    Console.WriteLine("Get Subscription Status 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 ARBGetSubscriptionStatusRequest { subscriptionId = subscriptionId };

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

        //    ARBGetSubscriptionStatusResponse 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)
        //        {
        //            Console.WriteLine("Success, Subscription Retrieved With RefID : " + response.refId);
        //        }
        //    }
        //    else
        //    {
        //        Console.WriteLine("Error: " + response.messages.message[0].code + "  " + response.messages.message[0].text);
        //    }

        //    return response;
        //}
        public static void GetSubscriptionStatusExec(String ApiLoginID, String ApiTransactionKey)
        {
            using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/GetSubscriptionStatus.csv", FileMode.Open)), true))
            {
                Console.WriteLine("Get Subscription Status 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;

                        for (int i = 0; i < fieldCount; i++)
                        {
                            switch (headers[i])
                            {
                            case "subscriptionId":
                                subscriptionId = 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);
                                }
                            }
                            var request = new ARBGetSubscriptionStatusRequest {
                                subscriptionId = subscriptionId
                            };

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

                            ARBGetSubscriptionStatusResponse 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("GSS_00" + flag.ToString());
                                    row1.Add("GetSubscriptionStatus");
                                    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, Subscription Retrieved With RefID : " + response.refId);
                                }
                                catch
                                {
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("GSS_00" + flag.ToString());
                                    row1.Add("GetSubscriptionStatus");
                                    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("GSS_00" + flag.ToString());
                                row1.Add("GetSubscriptionStatus");
                                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("GSS_00" + flag.ToString());
                            row2.Add("GetSubscriptionStatus");
                            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);
                        }
                    }
                }
            }
        }
Esempio n. 28
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);
                        }
                    }
                }
            }
        }