public string GetCustomerProfile()
        {
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment         = AuthorizeNet.Environment.SANDBOX;
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType()
            {
                name            = "35WkY7AsU",
                ItemElementName = ItemChoiceType.transactionKey,
                Item            = "85T8Hsv4JMu76P5b"
            };

            customerProfileType customerProfile = new customerProfileType();

            //customerProfile.merchantCustomerId = "Test CustomerID";
            customerProfile.email       = "*****@*****.**";
            customerProfile.description = "abc";


            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();

            // validate response
            if (response != null)
            {
                if (response.messages.resultCode == messageTypeEnum.Ok)
                {
                    return(response.customerProfileId);
                }
                else
                {
                    return($"{response.messages.message[0].code}+ and {response.messages.message[0].text}");
                }
            }
            else
            {
                if (controller.GetErrorResponse().messages.message.Length > 0)
                {
                    return($"{response.messages.message[0].code}+ and {response.messages.message[0].text}");
                }
                else
                {
                    return($"Profile created failed");
                }
            }
        }
Example #2
0
        //Create Customer Profile and Customer Payment Profile, returning their IDs.
        private Boolean createProfile(out String customerProfileId, out String paymentProfileId)
        {
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = CustomMerchantAuthenticationType;
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment         = TestEnvironment;

            var    rnd      = new AnetRandom(DateTime.Now.Millisecond);
            string custIndx = rnd.Next(99999).ToString();

            var creditCard = new creditCardType {
                cardNumber = "4111111111111111", expirationDate = "0622"
            };
            var paymentType = new paymentType {
                Item = creditCard
            };

            var paymentProfile = new customerPaymentProfileType {
                payment = paymentType
            };

            var createRequest = new createCustomerProfileRequest
            {
                profile = new customerProfileType {
                    merchantCustomerId = "TSTCSTER" + custIndx,
                    paymentProfiles    = new customerPaymentProfileType[] { paymentProfile }
                }
            };

            //create profiles and get response
            var createController = new createCustomerProfileController(createRequest);
            var createResponse   = createController.ExecuteWithApiResponse();

            //validate response
            if (messageTypeEnum.Ok != createResponse.messages.resultCode)
            {
                customerProfileId = "0";
                paymentProfileId  = "0";
                return(false);
            }
            else
            {
                Assert.NotNull(createResponse.customerProfileId);
                Assert.NotNull(createResponse.customerPaymentProfileIdList);
                Assert.AreNotEqual(0, createResponse.customerPaymentProfileIdList.Length);

                customerProfileId = createResponse.customerProfileId;
                paymentProfileId  = createResponse.customerPaymentProfileIdList[0];

                return(true);
            }
        }
        public static AuthorizeNetResponse CreateCustomerProfile(string customerId, string desc, bool simulation = false)
        {
            AuthorizeNetResponse finalResponse = new AuthorizeNetResponse();

            try
            {
                InitEnvironmentAndAccount(simulation);


                customerProfileType customerProfile = new customerProfileType();
                customerProfile.merchantCustomerId = customerId;
                customerProfile.description        = desc;


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

                System.Net.ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; // .net3.5沒有Tls12

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

                //createCustomerProfileTransactionRequest request2 = new createCustomerProfileTransactionRequest();
                controller.Execute();

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

                // validate response
                finalResponse = ParseResponse(response);
            }
            catch (Exception ex)
            {
                finalResponse = GenerateExceptionResponse(ex.Message);
            }
            return(finalResponse);
        }
        public void CreateTransactionFromProfile()
        {
            //Creates a customer profile and customer payment profile
            //Then uses those profiles to create a transaction request

            //Common code to set for all requests
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = CustomMerchantAuthenticationType;
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment         = TestEnvironment;

            Random rnd = new Random(DateTime.Now.Millisecond);

            string profileRandom = rnd.Next(9999).ToString();

            //Create profile to use in transaction creation
            var profileShipTo = new customerAddressType
            {
                address     = profileRandom + " First St NE",
                city        = "Bellevue",
                state       = "WA",
                zip         = "98007",
                company     = "Sample Co " + profileRandom,
                country     = "USA",
                firstName   = "Sample" + profileRandom,
                lastName    = "Name" + profileRandom,
                phoneNumber = "425 123 4567",
            };

            var paymentProfile = new customerPaymentProfileType
            {
                billTo       = profileShipTo,
                customerType = customerTypeEnum.individual,
                payment      = new paymentType {
                    Item = new creditCardType {
                        cardNumber = "4111111111111111", expirationDate = "0622"
                    }
                },
            };

            var createProfileReq = new createCustomerProfileRequest
            {
                profile = new customerProfileType
                {
                    description     = "SampleProfile " + profileRandom,
                    email           = "SampleEmail" + profileRandom + "@Visa.com",
                    shipToList      = new customerAddressType[] { profileShipTo },
                    paymentProfiles = new customerPaymentProfileType[] { paymentProfile }
                }
            };

            var createProfileCont = new createCustomerProfileController(createProfileReq);

            createProfileCont.Execute();
            var createProfileResp = createProfileCont.GetApiResponse();

            //Get profile using getCustomerProfileRequest
            var getCustReq = new getCustomerProfileRequest {
                customerProfileId = createProfileResp.customerProfileId
            };
            var getCustCont = new getCustomerProfileController(getCustReq);

            getCustCont.Execute();
            var getCustResp = getCustCont.GetApiResponse();


            //Create Transaction
            //Create instance of customer payment profile using the profile IDs from the profile we loaded above.
            var custPaymentProfile = new AuthorizeNet.Api.Contracts.V1.customerProfilePaymentType {
                customerProfileId = getCustResp.profile.customerProfileId, paymentProfile = new paymentProfile {
                    paymentProfileId = getCustResp.profile.paymentProfiles[0].customerPaymentProfileId
                }
            };

            var testTxn = new transactionRequestType
            {
                profile         = custPaymentProfile,
                amount          = (decimal)rnd.Next(9999) / 100,
                transactionType = transactionTypeEnum.authCaptureTransaction.ToString()
            };

            var txnControler = new createTransactionController(new createTransactionRequest {
                transactionRequest = testTxn
            });

            txnControler.Execute();
            var txnControlerResp = txnControler.GetApiResponse();

            //verify transaction succeeded.
            Assert.AreEqual("1", txnControlerResp.transactionResponse.messages[0].code);
        }
Example #5
0
        public void GetCustomerPaymentProfileListSampleTest()
        {
            LogHelper.info(Logger, "Sample getCustomerPaymentProfileList");

            ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = CustomMerchantAuthenticationType;
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment         = TestEnvironment;

            CustomerProfileType.paymentProfiles = new customerPaymentProfileType[] { getCustomerPaymentProfileObject() };
            var createRequest = new createCustomerProfileRequest
            {
                refId   = RefId,
                profile = CustomerProfileType
            };

            //create a customer profile
            var createController = new createCustomerProfileController(createRequest);
            var createResponse   = createController.ExecuteWithApiResponse();

            Assert.NotNull(createResponse);
            LogHelper.info(Logger, "Created Customer profile : {0}", createResponse.customerProfileId);

            var getProfileListRequest = new getCustomerPaymentProfileListRequest
            {
                refId      = RefId,
                searchType = CustomerPaymentProfileSearchTypeEnum.cardsExpiringInMonth,
                month      = "2032-10"
            };

            bool found = false;

            //setup retry loop to allow for delays in replication
            for (int counter = 0; counter < 5; counter++)
            {
                //get customer profile list
                var getProfileController   = new getCustomerPaymentProfileListController(getProfileListRequest);
                var getProfileListResponse = getProfileController.ExecuteWithApiResponse();

                for (int profile = 0; profile < getProfileListResponse.paymentProfiles.Length; profile++)
                {
                    var profileId = Convert.ToString(getProfileListResponse.paymentProfiles[profile].customerPaymentProfileId);
                    if (profileId.Equals(createResponse.customerPaymentProfileIdList[0]))
                    {
                        found = true;
                        break;
                    }
                }

                if (found)
                {
                    break;
                }

                System.Threading.Thread.Sleep(10000);
            }

            Assert.IsTrue(found);

            //delete the created customer profile
            var deleteRequest = new deleteCustomerProfileRequest
            {
                refId             = RefId,
                customerProfileId = createResponse.customerProfileId
            };
            var deleteController = new deleteCustomerProfileController(deleteRequest);
            var deleteResponse   = deleteController.ExecuteWithApiResponse();

            Assert.IsNotNull(deleteResponse);
        }
        public static void Run(string apiLoginId, string apiTransactionKey)
        {
            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 = "0123454321",
                routingNumber = "000000204",
                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           = "*****@*****.**";
            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.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);
                }
            }
        }
        public static ANetApiResponse Run(string ApiLoginID, string ApiTransactionKey, string emailId)
        {
            Console.WriteLine("Create Customer 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 creditCard = new creditCardType
            {
                cardNumber     = "4111111111111111",
                expirationDate = "1018"
            };

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

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

            // validate response
            if (response != null)
            {
                if (response.messages.resultCode == messageTypeEnum.Ok)
                {
                    if (response.messages.message != null)
                    {
                        Console.WriteLine("Success!");
                        Console.WriteLine("Customer Profile ID: " + response.customerProfileId);
                        Console.WriteLine("Payment Profile ID: " + response.customerPaymentProfileIdList[0]);
                        Console.WriteLine("Shipping Profile ID: " + response.customerShippingAddressIdList[0]);
                    }
                }
                else
                {
                    Console.WriteLine("Customer Profile Creation Failed.");
                    Console.WriteLine("Error Code: " + response.messages.message[0].code);
                    Console.WriteLine("Error message: " + response.messages.message[0].text);
                }
            }
            else
            {
                if (controller.GetErrorResponse().messages.message.Length > 0)
                {
                    Console.WriteLine("Customer 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);
        }
Example #8
0
        public ActionResult CreateCustProfile(Card c)
        {
            string cardnumber = c.cardnumber;
            string expirydate = c.expirydate;
            string cvv        = c.cvv;


            Console.WriteLine("Create Customer 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 creditCard = new creditCardType
            {
                cardNumber     = "4111111111111111",
                expirationDate = "0725"
            };

            //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;
            //ccPaymentProfile.defaultPaymentProfile = true;

            //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 parthlathiya";
            customerProfile.email           = Session["Email"].ToString();
            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();

            DAL dal = new DAL();

            // validate response
            if (response != null)
            {
                if (response.messages.resultCode == messageTypeEnum.Ok)
                {
                    if (response.messages.message != null)
                    {
                        ViewBag.Message = "We have stored your card details. Now you can subscribe to any channel/pack with single click.";
                        ViewBag.Type    = "success";

                        dal.UpdateCustProfileId(Session["Email"].ToString(), response.customerProfileId, response.customerPaymentProfileIdList[0]);

                        //Console.WriteLine("Success!");
                        //Console.WriteLine("Customer Profile ID: " + response.customerProfileId);
                        Console.WriteLine("Payment Profile ID: " + response.customerPaymentProfileIdList[0]);
                        Console.WriteLine("Shipping Profile ID: " + response.customerShippingAddressIdList[0]);
                    }
                }
                else
                {
                    ViewBag.Message = "Customer Profile Creation Failed.";
                    ViewBag.Type    = "danger";
                    Console.WriteLine("Error Code: " + response.messages.message[0].code);
                    Console.WriteLine("Error message: " + response.messages.message[0].text);
                }
            }
            else
            {
                if (controller.GetErrorResponse().messages.message.Length > 0)
                {
                    ViewBag.Message = "Customer Profile Creation Failed.";
                    ViewBag.Type    = "danger";
                    Console.WriteLine("Error Code: " + response.messages.message[0].code);
                    Console.WriteLine("Error message: " + response.messages.message[0].text);
                }
                else
                {
                    Console.WriteLine("Null Response.");
                }
            }

            List <Channel> channelsList = dal.AllChannels();
            List <Pack>    packsList    = dal.AllPacks();

            ViewData["AllChannels"] = channelsList;
            ViewData["AllPacks"]    = packsList;
            List <int> chids = new List <int>();

            foreach (var ch1 in channelsList)
            {
                chids.Add(ch1.ChannelId);
            }
            List <bool> subornot = dal.issubornot(chids, Session["Email"].ToString());

            ViewData["SuborNot"] = subornot;
            Customer c1 = dal.FetchCustomer(Session["email"].ToString());

            List <int> packids = new List <int>();

            foreach (var pack in packsList)
            {
                packids.Add(pack.PackId);
            }
            List <bool> subornot1 = dal.issubornot1(packids, Session["Email"].ToString());

            ViewData["SuborNot1"] = subornot1;

            List <bool> subornot2 = dal.issubornotinanypack(chids, packids, Session["Email"].ToString());

            ViewData["SuborNot2"] = subornot2;

            ViewData["ProfileId"] = c1.ProfileId;

            return(View("../Home/Welcome"));
        }
        public static void Run(string apiLoginId, string apiTransactionKey)
        {
            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 = "0123454321",
                routingNumber = "000000204",
                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 = "*****@*****.**";
            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.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);
            }
        }
Example #10
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);
                        }
                    }
                }
            }
        }
        public void CreateTransactionFromProfile()
        {
            //Creates a customer profile and customer payment profile
            //Then uses those profiles to create a transaction request

            //Common code to set for all requests
            ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = CustomMerchantAuthenticationType;
            ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = TestEnvironment;

            Random rnd = new Random(DateTime.Now.Millisecond);

            string profileRandom = rnd.Next(9999).ToString();

            //Create profile to use in transaction creation
            var profileShipTo = new customerAddressType
            {
                address = profileRandom + " First St NE",
                city = "Bellevue",
                state = "WA",
                zip = "98007",
                company = "Sample Co " + profileRandom,
                country = "USA",
                firstName = "Sample" + profileRandom,
                lastName = "Name" + profileRandom,
                phoneNumber = "425 123 4567",
            };

            var paymentProfile = new customerPaymentProfileType
            {
                billTo = profileShipTo,
                customerType = customerTypeEnum.individual,
                payment = new paymentType { Item = new creditCardType { cardNumber = "4111111111111111", expirationDate = "0622" } },
            };

            var createProfileReq = new createCustomerProfileRequest
            {
                profile = new customerProfileType
                {
                    description = "SampleProfile " + profileRandom,
                    email = "SampleEmail" + profileRandom + "@Visa.com",
                    shipToList = new customerAddressType[] { profileShipTo },
                    paymentProfiles = new customerPaymentProfileType[] { paymentProfile }
                }
            };

            var createProfileCont = new createCustomerProfileController(createProfileReq);
            createProfileCont.Execute();
            var createProfileResp = createProfileCont.GetApiResponse();

            //Get profile using getCustomerProfileRequest
            var getCustReq = new getCustomerProfileRequest { customerProfileId = createProfileResp.customerProfileId };
            var getCustCont = new getCustomerProfileController(getCustReq);
            getCustCont.Execute();
            var getCustResp = getCustCont.GetApiResponse();


            //Create Transaction
            //Create instance of customer payment profile using the profile IDs from the profile we loaded above.
            var custPaymentProfile = new AuthorizeNet.Api.Contracts.V1.customerProfilePaymentType { customerProfileId = getCustResp.profile.customerProfileId, paymentProfile = new paymentProfile { paymentProfileId = getCustResp.profile.paymentProfiles[0].customerPaymentProfileId } };

            var testTxn = new transactionRequestType
            {
                profile = custPaymentProfile,
                amount = (decimal)rnd.Next(9999) / 100,
                transactionType = transactionTypeEnum.authCaptureTransaction.ToString()
            };

            var txnControler = new createTransactionController(new createTransactionRequest { transactionRequest = testTxn });
            txnControler.Execute();
            var txnControlerResp = txnControler.GetApiResponse();

            //verify transaction succeeded.
            Assert.AreEqual("1", txnControlerResp.transactionResponse.messages[0].code);

        }
Example #12
0
        public string CreateCust(CardInfoViewModel data)
        {
            //Console.WriteLine("Create Customer Profile Sample");

            // set whether to use the sandbox environment, or production enviornment
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.PRODUCTION;

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

            customerProfileType customerProfile = new customerProfileType();

            customerProfile.merchantCustomerId = data.CustomerId;
            customerProfile.email = data.email;

            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();

            // validate response
            if (response != null)
            {
                if (response.messages.resultCode == messageTypeEnum.Ok)
                {
                    if (response.messages.message != null)
                    {
                        //Console.WriteLine("Success!");
                        //Console.WriteLine("Customer Profile ID: " + );
                        return(response.customerProfileId);
                    }
                }
                else
                {
                    Console.WriteLine("Customer Profile Creation Failed.");
                    Console.WriteLine("Error Code: " + response.messages.message[0].code);
                    Console.WriteLine("Error message: " + response.messages.message[0].text);
                }
            }
            else
            {
                if (controller.GetErrorResponse().messages.message.Length > 0)
                {
                    Console.WriteLine("Customer 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(string.Empty);
        }
        //Create Customer Profile and Customer Payment Profile, returning their IDs.
        private Boolean createProfile(out String customerProfileId, out String paymentProfileId)
        {

            ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = CustomMerchantAuthenticationType;
            ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = TestEnvironment;

            var rnd = new AnetRandom(DateTime.Now.Millisecond);
            string custIndx = rnd.Next(99999).ToString();

            var creditCard = new creditCardType { cardNumber = "4111111111111111", expirationDate = "0622" };
            var paymentType = new paymentType {Item = creditCard};

            var paymentProfile = new customerPaymentProfileType{ payment = paymentType };

            var createRequest = new createCustomerProfileRequest
            {
                profile = new customerProfileType{
                                    merchantCustomerId = "TSTCSTER"+custIndx,
                                    paymentProfiles = new customerPaymentProfileType[]{ paymentProfile }
                                    }   
            };

            //create profiles and get response
            var createController = new createCustomerProfileController(createRequest);
            var createResponse = createController.ExecuteWithApiResponse();

            //validate response
            if (messageTypeEnum.Ok != createResponse.messages.resultCode)
            {
                customerProfileId = "0";
                paymentProfileId = "0";
                return false;
            }
            else
            {
                Assert.NotNull(createResponse.customerProfileId);
                Assert.NotNull(createResponse.customerPaymentProfileIdList);
                Assert.AreNotEqual(0, createResponse.customerPaymentProfileIdList.Length);

                customerProfileId = createResponse.customerProfileId;
                paymentProfileId = createResponse.customerPaymentProfileIdList[0];

                return true;
            }
        }
        public void GetCustomerPaymentProfileListSampleTest()
        {
            LogHelper.info(Logger, "Sample getCustomerPaymentProfileList");

            ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = CustomMerchantAuthenticationType;
            ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = TestEnvironment;

            CustomerProfileType.paymentProfiles = new customerPaymentProfileType[] { getCustomerPaymentProfileObject() };
            var createRequest = new createCustomerProfileRequest
            {
                refId = RefId,
                profile = CustomerProfileType
            };

            //create a customer profile
            var createController = new createCustomerProfileController(createRequest);
            var createResponse = createController.ExecuteWithApiResponse();
            Assert.NotNull(createResponse);
            LogHelper.info(Logger, "Created Customer profile : {0}", createResponse.customerProfileId);

            var getProfileListRequest = new getCustomerPaymentProfileListRequest
            {
                refId = RefId,
                searchType = CustomerPaymentProfileSearchTypeEnum.cardsExpiringInMonth,
                month = "2032-10"
            };

            bool found = false;
            //setup retry loop to allow for delays in replication
            for (int counter = 0; counter < 5; counter++)
            {
				//get customer profile list
                var getProfileController = new getCustomerPaymentProfileListController(getProfileListRequest);
                var getProfileListResponse = getProfileController.ExecuteWithApiResponse();

                for (int profile = 0; profile < getProfileListResponse.paymentProfiles.Length; profile++)
                {
                    var profileId = Convert.ToString(getProfileListResponse.paymentProfiles[profile].customerPaymentProfileId);
                    if (profileId.Equals(createResponse.customerPaymentProfileIdList[0]))
                    {
                        found = true;
                        break;
                    }
                }

                if (found)
                    break;

                System.Threading.Thread.Sleep(10000);
            }

            Assert.IsTrue(found);
            
			//delete the created customer profile
			var deleteRequest = new deleteCustomerProfileRequest
            {
                refId = RefId,
                customerProfileId = createResponse.customerProfileId
            };
            var deleteController = new deleteCustomerProfileController(deleteRequest);
            var deleteResponse = deleteController.ExecuteWithApiResponse();
            Assert.IsNotNull(deleteResponse);
        }