public void MockcreateCustomerPaymentProfileTest()
        {
            //define all mocked objects as final
            var mockController = GetMockController <createCustomerPaymentProfileRequest, createCustomerPaymentProfileResponse>();
            var mockRequest    = new createCustomerPaymentProfileRequest
            {
                merchantAuthentication = new merchantAuthenticationType {
                    name = "mocktest", Item = "mockKey", ItemElementName = ItemChoiceType.transactionKey
                },
            };
            var mockResponse = new createCustomerPaymentProfileResponse
            {
                refId                    = "1234",
                sessionToken             = "sessiontoken",
                customerPaymentProfileId = "1234",
                validationDirectResponse = "mockValidation",
            };

            var errorResponse = new ANetApiResponse();
            var results       = new List <String>();
            const messageTypeEnum messageTypeOk = messageTypeEnum.Ok;

            SetMockControllerExpectations <createCustomerPaymentProfileRequest, createCustomerPaymentProfileResponse, createCustomerPaymentProfileController>(
                mockController.MockObject, mockRequest, mockResponse, errorResponse, results, messageTypeOk);
            mockController.MockObject.Execute(AuthorizeNet.Environment.CUSTOM);
            //mockController.MockObject.Execute();
            // or var controllerResponse = mockController.MockObject.ExecuteWithApiResponse(AuthorizeNet.Environment.CUSTOM);
            var controllerResponse = mockController.MockObject.GetApiResponse();

            Assert.IsNotNull(controllerResponse);

            Assert.IsNotNull(controllerResponse.customerPaymentProfileId);
            LogHelper.info(Logger, "createCustomerPaymentProfile: Details:{0}", controllerResponse.customerPaymentProfileId);
        }
Пример #2
0
        public static void Run(String ApiLoginID, String ApiTransactionKey)
        {
            Console.WriteLine("CreateCustomerPaymentProfile Sample");
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment         = AuthorizeNet.Environment.SANDBOX;
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType()
            {
                name            = ApiLoginID,
                ItemElementName = ItemChoiceType.transactionKey,
                Item            = ApiTransactionKey,
            };

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

            paymentType echeck = new paymentType {
                Item = bankAccount
            };

            customerPaymentProfileType echeckPaymentProfile = new customerPaymentProfileType();

            echeckPaymentProfile.payment = echeck;

            var request = new createCustomerPaymentProfileRequest
            {
                customerProfileId = "35772885",
                paymentProfile    = echeckPaymentProfile,
                validationMode    = validationModeEnum.none
            };

            //Prepare Request
            var controller = new createCustomerPaymentProfileController(request);

            controller.Execute();

            //Send Request to EndPoint
            createCustomerPaymentProfileResponse response = controller.GetApiResponse();

            if (response != null && response.messages.resultCode == messageTypeEnum.Ok)
            {
                if (response != null && response.messages.message != null)
                {
                    Console.WriteLine("Success, createCustomerPaymentProfileID : " + response.customerPaymentProfileId);
                }
            }
            else
            {
                Console.WriteLine("Error: " + response.messages.message[0].code + "  " + response.messages.message[0].text);
                if (response.messages.message[0].code == "E00039")
                {
                    Console.WriteLine("Duplicate ID: " + response.customerPaymentProfileId);
                }
            }
        }
        //public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, string customerProfileId)
        //{
        //    Console.WriteLine("CreateCustomerPaymentProfile Sample");
        //    ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNET.Environment.SANDBOX;
        //    ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
        //    {
        //        name            = ApiLoginID,
        //        ItemElementName = ItemChoiceType.transactionKey,
        //        Item            = ApiTransactionKey,
        //    };

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

        //    paymentType echeck = new paymentType {Item = bankAccount};

        //    var billTo = new customerAddressType
        //    {
        //        firstName = "John",
        //        lastName = "Snow"
        //    };
        //    customerPaymentProfileType echeckPaymentProfile = new customerPaymentProfileType();
        //    echeckPaymentProfile.payment = echeck;
        //    echeckPaymentProfile.billTo = billTo;

        //    var request = new createCustomerPaymentProfileRequest
        //    {
        //        customerProfileId = customerProfileId,
        //        paymentProfile = echeckPaymentProfile,
        //        validationMode = validationModeEnum.none
        //    };

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

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

        //    return response;

        //}

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

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

                        paymentType echeck = new paymentType {
                            Item = bankAccount
                        };

                        var billTo = new customerAddressType
                        {
                            firstName = "John",
                            lastName  = "Snow"
                        };
                        customerPaymentProfileType echeckPaymentProfile = new customerPaymentProfileType();
                        echeckPaymentProfile.payment = echeck;
                        echeckPaymentProfile.billTo  = billTo;


                        string customerProfileId = 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;

                            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 createCustomerPaymentProfileRequest
                            {
                                customerProfileId = customerProfileId,
                                paymentProfile    = echeckPaymentProfile,
                                validationMode    = validationModeEnum.none
                            };
                            //Prepare Request
                            var controller = new createCustomerPaymentProfileController(request);
                            controller.Execute();

                            //Send Request to EndPoint
                            createCustomerPaymentProfileResponse response = controller.GetApiResponse();
                            //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 customerProfileId fetched.");
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("CCPP_00" + flag.ToString());
                                    row1.Add("CreateCustomerPaymentProfile");
                                    row1.Add("Pass");
                                    row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff"));
                                    writer.WriteRow(row1);
                                    //  Console.WriteLine("Success " + TestcaseID + " CustomerID : " + response.Id);
                                    flag = flag + 1;
                                    Console.WriteLine("Success, createCustomerPaymentProfileID : " + response.customerPaymentProfileId);
                                }
                                catch
                                {
                                    CsvRow row1 = new CsvRow();
                                    row1.Add("CCPP_00" + flag.ToString());
                                    row1.Add("CreateCustomerPaymentProfile");
                                    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;
                                }
                                /*******************/
                                //if (response.messages.message != null)
                                //{
                                //    Console.WriteLine("Success, createCustomerPaymentProfileID : " + response.customerPaymentProfileId);
                                //}
                            }
                            else
                            {
                                //Console.WriteLine("Error: " + response.messages.message[0].code + "  " + response.messages.message[0].text);
                                CsvRow row1 = new CsvRow();
                                row1.Add("CCPP_00" + flag.ToString());
                                row1.Add("CreateCustomerPaymentProfile");
                                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;
                                //if (response.messages.message[0].code == "E00039")
                                //{
                                //    Console.WriteLine("Duplicate ID: " + response.customerPaymentProfileId);
                                //}
                            }

                            //return response;
                        }
                        catch (Exception e)
                        {
                            CsvRow row2 = new CsvRow();
                            row2.Add("CCPP_00" + flag.ToString());
                            row2.Add("CreateCustomerPaymentProfile");
                            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);
                        }
                    }
                }
            }
        }
Пример #4
0
        public static ANetApiResponse Run(string ApiLoginID, string ApiTransactionKey, string customerProfileId)
        {
            Console.WriteLine("Create Customer Payment Profile Sample");

            // set whether to use the sandbox environment, or production enviornment
            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 = "01245524321",
                routingNumber = "000000204",
                accountType   = bankAccountTypeEnum.checking,
                echeckType    = echeckTypeEnum.WEB,
                nameOnAccount = "test",
                bankName      = "Bank Of America"
            };

            paymentType echeck = new paymentType {
                Item = bankAccount
            };

            var billTo = new customerAddressType
            {
                firstName = "John",
                lastName  = "Snow"
            };
            customerPaymentProfileType echeckPaymentProfile = new customerPaymentProfileType();

            echeckPaymentProfile.payment = echeck;
            echeckPaymentProfile.billTo  = billTo;

            var request = new createCustomerPaymentProfileRequest
            {
                customerProfileId = customerProfileId,
                paymentProfile    = echeckPaymentProfile,
                validationMode    = validationModeEnum.none
            };

            // instantiate the controller that will call the service
            var controller = new createCustomerPaymentProfileController(request);

            controller.Execute();

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

            // validate response
            if (response != null)
            {
                if (response.messages.resultCode == messageTypeEnum.Ok)
                {
                    if (response.messages.message != null)
                    {
                        Console.WriteLine("Success! Customer Payment Profile ID: " + response.customerPaymentProfileId);
                    }
                }
                else
                {
                    Console.WriteLine("Customer Payment Profile Creation Failed.");
                    Console.WriteLine("Error Code: " + response.messages.message[0].code);
                    Console.WriteLine("Error message: " + response.messages.message[0].text);
                    if (response.messages.message[0].code == "E00039")
                    {
                        Console.WriteLine("Duplicate Payment Profile ID: " + response.customerPaymentProfileId);
                    }
                }
            }
            else
            {
                if (controller.GetErrorResponse().messages.message.Length > 0)
                {
                    Console.WriteLine("Customer Payment Profile Creation Failed.");
                    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);
        }
Пример #5
0
        public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, string customerProfileId)
        {
            //Console.WriteLine("CreateCustomerPaymentProfile Sample");
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment         = AuthorizeNet.Environment.SANDBOX;
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType()
            {
                name            = ApiLoginID,
                ItemElementName = ItemChoiceType.transactionKey,
                Item            = ApiTransactionKey,
            };
            bankAccountType bankAccount;

            bankAccount = LouACH.DataBaseTransactions.DataBase.ReadBankData();
            //var bankAccount = new bankAccountType
            //{
            //    accountNumber = "01245524321",
            //    routingNumber = "000000204",
            //    accountType = bankAccountTypeEnum.checking,
            //    echeckType = echeckTypeEnum.WEB,
            //    nameOnAccount = "test",
            //    bankName = "Bank Of America"
            //};

            paymentType echeck = new paymentType {
                Item = bankAccount
            };

            var billTo = new customerAddressType
            {
                firstName = "John",
                lastName  = "Snow"
            };
            customerPaymentProfileType echeckPaymentProfile = new customerPaymentProfileType();

            echeckPaymentProfile.payment = echeck;
            echeckPaymentProfile.billTo  = billTo;

            var request = new createCustomerPaymentProfileRequest
            {
                customerProfileId = customerProfileId,
                paymentProfile    = echeckPaymentProfile,
                validationMode    = validationModeEnum.none
            };

            //Prepare Request
            var controller = new createCustomerPaymentProfileController(request);

            controller.Execute();

            //Send Request to EndPoint
            createCustomerPaymentProfileResponse response = controller.GetApiResponse();

            if (response != null && response.messages.resultCode == messageTypeEnum.Ok)
            {
                if (response != null && response.messages.message != null)
                {
                    //Console.WriteLine("Success, createCustomerPaymentProfileID : " + response.customerPaymentProfileId);
                    LouACH.Main.theOutput = "Successfully created Profile with Transaction ID: " + response.customerPaymentProfileId;
                }
            }
            else
            {
                // Console.WriteLine("Error: " + response.messages.message[0].code + "  " + response.messages.message[0].text);
                if (response.messages.message[0].code == "E00039")
                {
                    //Console.WriteLine("Duplicate ID: " + response.customerPaymentProfileId);
                    LouACH.Main.theOutput = "Error: " + response.messages.message[0].code + "  " + response.messages.message[0].text;
                }
            }

            return(response);
        }