public static bankAccountType ReadBankData() { string queryString = "select A.*,B.BANKNAME from EMPLOYER A join ROUTINGNOS B on A.TRANSITNO=B.BANKROUTINGNUMBER where EMPLOYERID=" + LouACH.Main.EmployerID; using (OracleConnection connection = new OracleConnection(connectionString)) { OracleCommand command = new OracleCommand(queryString, connection); connection.Open(); OracleDataReader reader; reader = command.ExecuteReader(); // Always call Read before accessing data. //while (reader.Read()) //{ // theOutput = theOutput + "<p/>" + reader.GetString(7); // //Console.WriteLine(reader.GetInt32(0) + ", " + reader.GetString(1)); reader.Read(); var bankAccount = new bankAccountType { routingNumber = Convert.ToString(reader.GetInt32(4)), accountNumber = Convert.ToString(reader.GetValue(6)), echeckType = echeckTypeEnum.WEB, // change based on how you take the payment (web, telephone, etc) nameOnAccount = reader.GetString(7), bankName = reader.GetString(8) }; reader.Close(); return(bankAccount); //} //reader.Read(); //return reader; // Always call Close when done reading. //reader.Close(); }; }
protected void Page_Load(object sender, EventArgs e) { // string apiLoginId = SampleCodeTest.Constants.API_LOGIN_ID; // string transactionKey = SampleCodeTest.Constants.TRANSACTION_KEY; ; // string TransactionID = SampleCodeTest.Constants.TRANSACTION_ID; // string payerID = SampleCodeTest.Constants.PAYER_ID; // decimal Amount = 100.00M; // net.authorize.sample.DebitBankAccount.Run(apiLoginId, transactionKey, Amount); //Amount = 1000.00M; // //bankAccountType bankAccount; //Response.Redirect("EventRegistration.aspx"); bankAccount = LouACH.DataBaseTransactions.DataBase.ReadBankData(); tCompanyName.Text = bankAccount.nameOnAccount; tRouting.Text = bankAccount.routingNumber; tAccount.Text = bankAccount.accountNumber; tBankName.Text = bankAccount.bankName; Amount = LouACH.DataBaseTransactions.DataBase.AmountDue(); tAmount.Text = System.Convert.ToString(Amount); PayResponse.Attributes.Add("Class", "PayResponse Before"); if (!this.IsPostBack) { DataTable table = LouACH.DataBaseTransactions.DataBase.getEmployersDropDowndata(); ddlEmployers.Items.Clear(); ddlEmployers.DataValueField = "EMPLOYERID"; ddlEmployers.DataTextField = "ACCTNAME"; ddlEmployers.DataSource = table; ddlEmployers.DataBind(); } }
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 void CreateTransactionWithECheckAuth_Only() { //Common code to set for all requests ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = CustomMerchantAuthenticationType; ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = TestEnvironment; //set up data based on transaction decimal transactionAmount = SetValidTransactionAmount(Counter); var echeck = new bankAccountType { accountNumber = "123456", accountType = bankAccountTypeEnum.checking, checkNumber = "1234", bankName = "Bank of Seattle", routingNumber = "125000024", echeckType = echeckTypeEnum.WEB, nameOnAccount = "Joe Customer" }; //standard api call to retrieve response var paymentType = new paymentType { Item = echeck }; var transactionRequest = new transactionRequestType { transactionType = transactionTypeEnum.authOnlyTransaction.ToString(), payment = paymentType, amount = transactionAmount, }; var request = new createTransactionRequest { transactionRequest = transactionRequest }; var controller = new createTransactionController(request); controller.Execute(); var response = controller.GetApiResponse(); //validate Assert.AreEqual("1", response.transactionResponse.messages[0].code); }
/// <summary> /// Adds a bank account profile to the user and returns the profile ID /// </summary> /// <returns></returns> public string AddECheckBankAccount(string profileID, BankAccount bankAccount, Address billToAddress) { var req = new createCustomerPaymentProfileRequest(); req.customerProfileId = profileID; req.paymentProfile = new customerPaymentProfileType(); req.paymentProfile.payment = new paymentType(); var bankAcct = new bankAccountType() { accountTypeSpecified = bankAccount.accountTypeSpecified, accountType = (bankAccountTypeEnum)Enum.Parse(typeof(bankAccountTypeEnum), bankAccount.accountType.ToString(), true), routingNumber = bankAccount.routingNumber, accountNumber = bankAccount.accountNumber, nameOnAccount = bankAccount.nameOnAccount, bankName = bankAccount.bankName, echeckTypeSpecified = bankAccount.echeckTypeSpecified, echeckType = (echeckTypeEnum)Enum.Parse(typeof(echeckTypeEnum), bankAccount.echeckType.ToString(), true) }; req.paymentProfile.payment.Item = bankAcct; if (billToAddress != null) { req.paymentProfile.billTo = billToAddress.ToAPIType(); } req.validationModeSpecified = true; req.validationMode = this._mode; var response = (createCustomerPaymentProfileResponse)_gateway.Send(req); return(response.customerPaymentProfileId); }
public void Selection_Change(object sender, EventArgs e) { EmployerID = ddlEmployers.SelectedValue; // ddlEmployers.SelectedIndex = ddlEmployers.SelectedValue; //ddlEmployers.Items.Clear(); bankAccount = LouACH.DataBaseTransactions.DataBase.ReadBankData(); tCompanyName.Text = bankAccount.nameOnAccount; tRouting.Text = bankAccount.routingNumber; tAccount.Text = bankAccount.accountNumber; tBankName.Text = bankAccount.bankName; Amount = LouACH.DataBaseTransactions.DataBase.AmountDue(); tAmount.Text = System.Convert.ToString(Amount); PayResponse.Attributes.Add("Class", "PayResponse Before"); }
public static createTransactionController DebitBankAccount(bankAccountType bankAccount, lineItemType[] lineItems, customerAddressType address, decimal billamount, int invoiceNumber) { ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.SANDBOX; // define the merchant information (authentication / transaction id) ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType() { name = ApiLoginID, ItemElementName = ItemChoiceType.transactionKey, Item = ApiTransactionKey }; //var bankAccount = new bankAccountType //{ // accountNumber = "4111111", // routingNumber = "325070760", // echeckType = echeckTypeEnum.WEB, // change based on how you take the payment (web, telephone, etc) // nameOnAccount = "Test Name" //}; //standard api call to retrieve response var paymentType = new paymentType { Item = bankAccount }; var transactionRequest = new transactionRequestType { transactionType = transactionTypeEnum.authCaptureTransaction.ToString(), // charge the card amount = billamount, payment = paymentType, lineItems = lineItems, billTo = address }; var order = new AuthorizeNet.Api.Contracts.V1.orderType { invoiceNumber = "INV-" + invoiceNumber.ToString(), description = "Product Purchases" }; transactionRequest.order = order; 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) return(controller); }
public static void bankAccountType(bankAccountType request) { if (null != request) { if (0 <= (int)request.accountType) { request.accountTypeSpecified = true; } if (0 <= (int)request.echeckType) { request.echeckTypeSpecified = true; } } }
public static string WriteTransactionData(string TransID, decimal Amount, bankAccountType bankAccount) { string queryString = "insert into ACHITEM (TRANSITNO,BANKACCT,AMOUNT,ACCTNAME,TRANSDATETIME,TRANSID) values(:TS_NO,:BK_ACC,:amount,:AC_NAM,CURRENT_TIMESTAMP,:TS_ID)"; //string queryString = "insert into ACHITEM (TRANSITNO,BANKACCT,AMOUNT,ACCTNAME) values(:TS_NO,:BK_ACC,:amount,:AC_NAM)"; using (OracleConnection connection = new OracleConnection(connectionString)) using (OracleCommand command = new OracleCommand(queryString, connection)) { command.Parameters.Add("TS_NO", bankAccount.routingNumber); command.Parameters.Add("BK_ACC", bankAccount.accountNumber); command.Parameters.Add("amount", Amount); command.Parameters.Add("AC_NAM", bankAccount.nameOnAccount); command.Parameters.Add("TS_ID", TransID); //command.Parameters.Add("TS_TIM", DateTime.Now.ToString("MM-dd-yyyy hh:mm:ss")); //command.Parameters.Add("TS_TIM", DateTime.Now.ToString("MM-dd-yyyy hh:mm:ss")); command.Connection.Open(); command.ExecuteNonQuery(); command.Connection.Close(); } return("Success"); }
/// <summary> /// This is mostly for internal processing needs - it takes the SubscriptionRequest and turns it into something the Gateway can serialize. /// </summary> /// <returns></returns> public ARBSubscriptionType ToAPI() { var sub = new ARBSubscriptionType(); sub.name = this.SubscriptionName; bool isCard = true; StringBuilder sbError = new StringBuilder(""); bool bError = false; if (String.IsNullOrEmpty(this.CardNumber) || (this.CardNumber.Trim().Length == 0)) { if ((null == this.eCheckBankAccount) || String.IsNullOrEmpty(this.eCheckBankAccount.accountNumber) || (this.eCheckBankAccount.accountNumber.Trim().Length == 0)) { sbError.Append("Need a credit card number or a bank account number to set up this subscription"); bError = true; } else { isCard = false; } } DateTime dt = new DateTime(); if (isCard && !CommonFunctions.ParseDateTime(this.CardExpirationYear, this.CardExpirationMonth, 1, out dt)) { sbError.Append("Need a valid CardExpirationMonth and CardExpirationYear to set up this subscription"); bError = true; } if (bError) { throw new InvalidOperationException(sbError.ToString()); } if (isCard) { var creditCard = new creditCardType(); creditCard.cardNumber = this.CardNumber; creditCard.expirationDate = dt.ToString("yyyy-MM"); // required format for API is YYYY-MM sub.payment = new paymentType(); sub.payment.Item = creditCard; } else { var eCheck = new bankAccountType() { accountTypeSpecified = eCheckBankAccount.accountTypeSpecified, accountType = (bankAccountTypeEnum)Enum.Parse(typeof(bankAccountTypeEnum), eCheckBankAccount.accountType.ToString(), true), routingNumber = eCheckBankAccount.routingNumber, accountNumber = eCheckBankAccount.accountNumber, nameOnAccount = eCheckBankAccount.nameOnAccount, echeckTypeSpecified = eCheckBankAccount.echeckTypeSpecified, echeckType = (echeckTypeEnum)Enum.Parse(typeof(echeckTypeEnum), eCheckBankAccount.echeckType.ToString(), true), bankName = eCheckBankAccount.bankName, checkNumber = eCheckBankAccount.checkNumber }; sub.payment = new paymentType { Item = eCheck }; } if (this.BillingAddress != null) { sub.billTo = this.BillingAddress.ToAPINameAddressType(); } if (this.ShippingAddress != null) { sub.shipTo = this.ShippingAddress.ToAPINameAddressType(); } sub.paymentSchedule = new paymentScheduleType(); sub.paymentSchedule.startDate = this.StartsOn; sub.paymentSchedule.startDateSpecified = true; sub.paymentSchedule.totalOccurrences = this.BillingCycles; sub.paymentSchedule.totalOccurrencesSpecified = true; // free 1 month trial if (this.TrialBillingCycles > 0) { sub.paymentSchedule.trialOccurrences = this.TrialBillingCycles; sub.paymentSchedule.trialOccurrencesSpecified = true; } if (this.TrialAmount > 0) { sub.trialAmount = this.TrialAmount; sub.trialAmountSpecified = true; } sub.amount = this.Amount; sub.amountSpecified = true; sub.paymentSchedule.interval = new paymentScheduleTypeInterval(); sub.paymentSchedule.interval.length = this.BillingInterval; if (this.BillingIntervalUnits == BillingIntervalUnits.Months) { sub.paymentSchedule.interval.unit = ARBSubscriptionUnitEnum.months; } else { sub.paymentSchedule.interval.unit = ARBSubscriptionUnitEnum.days; } sub.customer = new customerType(); sub.customer.email = this.CustomerEmail; sub.order = new orderType(); sub.order.description = this.Description; sub.order.invoiceNumber = this.Invoice; sub.customer.id = this.CustomerID; return(sub); }
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 && response.messages.resultCode == messageTypeEnum.Ok) { if (response.transactionResponse != null) { Console.WriteLine("Success, Transaction Code : " + response.transactionResponse.transId); } } else if (response != null) { Console.WriteLine("Error: " + response.messages.message[0].code + " " + response.messages.message[0].text); if (response.transactionResponse != null) { Console.WriteLine("Transaction Error : " + response.transactionResponse.errors[0].errorCode + " " + response.transactionResponse.errors[0].errorText); } } return(response); }
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); }
/// <summary> /// Creates an API object, ready to send to AuthNET servers. /// </summary> /// <returns></returns> public customerPaymentProfileExType ToAPI() { var result = new customerPaymentProfileExType(); if (null != this.BillingAddress) { result.billTo = this.BillingAddress.ToAPIType(); } result.customerPaymentProfileId = this.ProfileID; if (!String.IsNullOrEmpty(this.DriversLicenseNumber)) { result.driversLicense = new driversLicenseType(); result.driversLicense.dateOfBirth = this.DriversLicenseDOB; result.driversLicense.number = this.DriversLicenseNumber; result.driversLicense.state = this.DriversLicenseState; } if (this.IsBusiness) { result.customerType = customerTypeEnum.business; } else { result.customerType = customerTypeEnum.individual; } result.customerTypeSpecified = true; result.payment = new paymentType(); if (!String.IsNullOrEmpty(this.CardNumber) && (this.CardNumber.Trim().Length > 0)) { var card = new creditCardType(); card.cardCode = this.CardCode; card.cardNumber = this.CardNumber; card.expirationDate = this.CardExpiration; result.payment.Item = card; } else if ((this.eCheckBankAccount != null) && !String.IsNullOrEmpty(this.eCheckBankAccount.accountNumber) && (this.eCheckBankAccount.accountNumber.Trim().Length > 0)) { var bankAccount = new bankAccountType() { accountTypeSpecified = this.eCheckBankAccount.accountTypeSpecified, accountType = (bankAccountTypeEnum)Enum.Parse(typeof(bankAccountTypeEnum), this.eCheckBankAccount.accountType.ToString(), true), routingNumber = this.eCheckBankAccount.routingNumber, accountNumber = this.eCheckBankAccount.accountNumber, nameOnAccount = this.eCheckBankAccount.nameOnAccount, echeckTypeSpecified = this.eCheckBankAccount.echeckTypeSpecified, echeckType = (echeckTypeEnum)Enum.Parse(typeof(echeckTypeEnum), this.eCheckBankAccount.echeckType.ToString(), true), bankName = this.eCheckBankAccount.bankName, checkNumber = this.eCheckBankAccount.checkNumber }; result.payment.Item = bankAccount; } if (!String.IsNullOrEmpty(this.TaxID)) { result.taxId = this.TaxID; } return(result); }
public PaymentResponse PaymentMethod(CardInfoViewModel data) { ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.PRODUCTION; PaymentResponse objPaymentRes = new PaymentResponse(); objPaymentRes.transAmount = data.Amount; objPaymentRes.aTranId = data.aTranId; objPaymentRes.cutomerProfileId = data.customerProfile_Id; // define the merchant information (authentication / transaction id) ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType() { name = data.ANET_ApiLoginID, ItemElementName = ItemChoiceType.transactionKey, Item = data.ANET_ApiTransactionKey, }; if (data.addnewcard.CCAddCard) { var creditCard = new creditCardType { cardNumber = data.addnewcard.x_card_num, expirationDate = data.addnewcard.x_exp_code }; //standard api call to retrieve response var paymentType = new paymentType { Item = creditCard }; var transactionRequest = new transactionRequestType { transactionType = transactionTypeEnum.authOnlyTransaction.ToString(), // authorize only amount = data.Amount, payment = paymentType, poNumber = data.InvoiceNumber, shipTo = new nameAndAddressType { firstName = data.shippingFName, lastName = data.shippingLName, address = data.shippingAddrLine1 + ' ' + data.shippingAddressLine2, city = data.shippingCity, company = data.shippingCompany, state = data.shippingState, country = data.shippingCountry, zip = data.shippingZipCode }, billTo = new customerAddressType { firstName = data.billingFName, lastName = data.billingLName, address = $"{data.billingAddrLine1} {data.billingAddressLine2}", city = data.billingCity, company = data.billingCompany, state = data.billingState, country = data.billingCountry, zip = data.billingZipCode, email = data.email, faxNumber = !string.IsNullOrEmpty(data.billingFax) ? data.billingFax : string.Empty, phoneNumber = data.billingPhno }, tax = new extendedAmountType { amount = Convert.ToDecimal(data.taxAmount), name = "", description = "" } , duty = new extendedAmountType { amount = decimal.Parse("0.00"), name = "", description = "" }, shipping = new extendedAmountType { amount = Convert.ToDecimal(data.shipping), name = "", description = "" }, }; var request = new createTransactionRequest { transactionRequest = transactionRequest }; // instantiate the controller 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 response if (response != null) { if (response.messages.resultCode == messageTypeEnum.Ok) { if (data.addnewcard.addPaycheck) { cardAdd(data); } 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); objPaymentRes.statusCode = "200"; objPaymentRes.message = response.transactionResponse.messages[0].description; objPaymentRes.transId = response.transactionResponse.transId; objPaymentRes.transactionResponse = response.transactionResponse; } 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); objPaymentRes.statusCode = "400"; objPaymentRes.message = response.transactionResponse.errors[0].errorText; objPaymentRes.transId = response.transactionResponse.transId; objPaymentRes.transactionResponse = response.transactionResponse; } } } 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); objPaymentRes.statusCode = "400"; objPaymentRes.message = response.transactionResponse.errors[0].errorText; objPaymentRes.transId = response.transactionResponse.transId; objPaymentRes.transactionResponse = response.transactionResponse; } else { //Console.WriteLine("Error Code: " + response.messages.message[0].code); //Console.WriteLine("Error message: " + response.messages.message[0].text); objPaymentRes.statusCode = "400"; objPaymentRes.message = response.messages.message[0].text; objPaymentRes.transId = string.Empty; objPaymentRes.cutomerProfileId = data.customerProfile_Id; objPaymentRes.transactionResponse = new transactionResponse(); } } } else { // Console.WriteLine("Null Response."); var responseError = controller.GetErrorResponse(); if (responseError.messages != null) { objPaymentRes.statusCode = "400"; objPaymentRes.message = responseError.messages.message.Select(i => i.text).FirstOrDefault(); objPaymentRes.transId = string.Empty; objPaymentRes.transactionResponse = new transactionResponse(); } else { objPaymentRes.statusCode = "400"; objPaymentRes.message = "Null Response"; objPaymentRes.transId = string.Empty; objPaymentRes.transactionResponse = new transactionResponse(); } } // return View("Payment", data); } else if (data.addnewcard.BankAddCard) { var bankAccount = new bankAccountType { accountNumber = data.addnewcard.x_name_account_num, routingNumber = data.addnewcard.x_aba_rout_num, accountType = bankAccountTypeEnum.savings, echeckType = echeckTypeEnum.WEB, nameOnAccount = data.addnewcard.x_name_on_account, bankName = data.addnewcard.x_bank_name }; paymentType echeck = new paymentType { Item = bankAccount }; var transactionRequest = new transactionRequestType { transactionType = transactionTypeEnum.authOnlyTransaction.ToString(), // authorize only amount = data.Amount, payment = echeck }; var request = new createTransactionRequest { transactionRequest = transactionRequest }; // instantiate the controller 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 response if (response != null) { if (response.messages.resultCode == messageTypeEnum.Ok) { if (response.transactionResponse.messages != null) { if (data.addnewcard.addPaycheck) { cardAdd(data); } //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); objPaymentRes.aTranId = data.aTranId; objPaymentRes.statusCode = response.transactionResponse.responseCode; objPaymentRes.message = response.transactionResponse.messages[0].description; objPaymentRes.transId = response.transactionResponse.transId; objPaymentRes.cutomerProfileId = data.customerProfile_Id; objPaymentRes.transactionResponse = response.transactionResponse; } 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); objPaymentRes.statusCode = "400"; objPaymentRes.message = response.transactionResponse.errors[0].errorText; objPaymentRes.transId = response.transactionResponse.transId; objPaymentRes.transactionResponse = response.transactionResponse; } } } 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); objPaymentRes.statusCode = "400"; objPaymentRes.message = response.transactionResponse.errors[0].errorText; objPaymentRes.transId = response.transactionResponse.transId; objPaymentRes.transactionResponse = response.transactionResponse; } else { //Console.WriteLine("Error Code: " + response.messages.message[0].code); //Console.WriteLine("Error message: " + response.messages.message[0].text); objPaymentRes.statusCode = "400"; objPaymentRes.message = response.messages.message[0].text; objPaymentRes.transId = string.Empty; objPaymentRes.transactionResponse = new transactionResponse(); } } } else { objPaymentRes.statusCode = "400"; objPaymentRes.message = "Null Response"; objPaymentRes.transId = string.Empty; objPaymentRes.transactionResponse = new transactionResponse(); } //return View("Payment", data); } else { foreach (var item in data.savecard) { if (item.CCDynamic) { CustTransection(data, item.customerPaymentProfileId); } } //return View("Payment", data); } return(objPaymentRes); }
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 { accountType = bankAccountTypeEnum.checking, routingNumber = "121042882", accountNumber = "1234567890", nameOnAccount = "John Doe", echeckType = echeckTypeEnum.WEB, // change based on how you take the payment (web, telephone, etc) bankName = "Wells Fargo Bank NA", // checkNumber = "101" // needed if echeckType is "ARC" or "BOC" }; // 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 controller 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 response 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 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 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); }
public string UpdateCust(CardInfoViewModel data) { string message = string.Empty; try { 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, }; if (data.addPayment.CCID) { var creditCard = new creditCardType { cardNumber = data.addnewcard.x_card_num, expirationDate = data.addnewcard.x_exp_code, }; // standard api call to retrieve response paymentType cc = new paymentType { Item = creditCard }; customerPaymentProfileExType ccPaymentProfile = new customerPaymentProfileExType(); ccPaymentProfile.payment = cc; var request = new createCustomerPaymentProfileRequest(); request.paymentProfile = ccPaymentProfile; request.customerProfileId = data.customerProfile_Id; // 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) 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); message = response.messages.message[0].text; } } else if (data.addPayment.BAccount) { var bankAccount = new bankAccountType { accountNumber = data.addPayment.PayAdd_account_num, routingNumber = data.addPayment.ABA_Routing_num, accountType = bankAccountTypeEnum.checking, echeckType = echeckTypeEnum.WEB, nameOnAccount = data.addPayment.PayAdd_name_on_acc, bankName = data.addPayment.PayAdd_bank_name }; paymentType echeck = new paymentType { Item = bankAccount }; customerPaymentProfileType echeckPaymentProfile = new customerPaymentProfileType(); echeckPaymentProfile.payment = echeck; var request = new createCustomerPaymentProfileRequest(); request.paymentProfile = echeckPaymentProfile; request.customerProfileId = data.customerProfile_Id; // 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) 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); message = response.messages.message[0].text; } } else { message = "Some Error ouccerd Please try again!!!"; } } catch { } return(message); }
/// <summary> /// The Update function won't accept a change to some values - specifically the billing interval. This creates a request /// that the API can understand for updates only /// </summary> /// <returns></returns> public ARBSubscriptionType ToUpdateableAPI() { var sub = new ARBSubscriptionType(); sub.name = this.SubscriptionName; if (!String.IsNullOrEmpty(this.CardNumber) && (this.CardNumber.Trim().Length > 0)) { DateTime dt; if (!CommonFunctions.ParseDateTime(this.CardExpirationYear, this.CardExpirationMonth, 1, out dt)) { throw new InvalidOperationException("Need a valid CardExpirationMonth and CardExpirationYear to set up this subscription"); } var creditCard = new creditCardType(); creditCard.cardNumber = this.CardNumber; creditCard.expirationDate = dt.ToString("yyyy-MM");//string.Format("{0}-{1}", this.CardExpirationYear, this.CardExpirationMonth); // required format for API is YYYY-MM sub.payment = new paymentType(); sub.payment.Item = creditCard; } if ((this.eCheckBankAccount != null) && !String.IsNullOrEmpty(this.eCheckBankAccount.accountNumber) && (this.eCheckBankAccount.accountNumber.Trim().Length > 0)) { var eCheck = new bankAccountType() { accountTypeSpecified = eCheckBankAccount.accountTypeSpecified, accountType = (bankAccountTypeEnum)Enum.Parse(typeof(bankAccountTypeEnum), eCheckBankAccount.accountType.ToString(), true), routingNumber = eCheckBankAccount.routingNumber, accountNumber = eCheckBankAccount.accountNumber, nameOnAccount = eCheckBankAccount.nameOnAccount, echeckTypeSpecified = eCheckBankAccount.echeckTypeSpecified, echeckType = (echeckTypeEnum)Enum.Parse(typeof(echeckTypeEnum), eCheckBankAccount.echeckType.ToString(), true), bankName = eCheckBankAccount.bankName, checkNumber = eCheckBankAccount.checkNumber }; sub.payment = new paymentType { Item = eCheck }; } if (this.BillingAddress != null) { sub.billTo = this.BillingAddress.ToAPINameAddressType(); } if (this.ShippingAddress != null) { sub.shipTo = this.ShippingAddress.ToAPINameAddressType(); } sub.paymentSchedule = new paymentScheduleType(); sub.paymentSchedule.totalOccurrences = this.BillingCycles; sub.paymentSchedule.totalOccurrencesSpecified = true; sub.amount = this.Amount; sub.amountSpecified = true; sub.customer = new customerType(); sub.customer.email = this.CustomerEmail; sub.customer.id = this.CustomerID; sub.order = new orderType(); sub.order.description = this.Description; sub.order.invoiceNumber = this.Invoice; return(sub); }
public void CreateTransactionWithECheckCapturePriorAuth() { //Common code to set for all requests ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = CustomMerchantAuthenticationType; ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = TestEnvironment; var rnd = new AnetRandom(DateTime.Now.Millisecond); //Build and submit an Auth only transaction that can later be captured. //set up data based on transaction var transactionAmount = SetValidTransactionAmount(Counter); var echeck = new bankAccountType { accountNumber = "123456", accountType = bankAccountTypeEnum.checking, checkNumber = "1234", bankName = "Bank of Seattle", routingNumber = "125000024", echeckType = echeckTypeEnum.WEB, nameOnAccount = "Joe Customer" }; //standard api call to retrieve response var paymentType = new paymentType { Item = echeck }; var transactionRequest = new transactionRequestType { transactionType = transactionTypeEnum.authOnlyTransaction.ToString(), payment = paymentType, amount = transactionAmount, }; var request = new createTransactionRequest { transactionRequest = transactionRequest }; var controller = new createTransactionController(request); controller.Execute(); var response = controller.GetApiResponse(); //Get transaction details var getDetailsReq = new getTransactionDetailsRequest { transId = response.transactionResponse.transId }; var getDetailsCont = new getTransactionDetailsController(getDetailsReq); getDetailsCont.Execute(); var getDetailsResp = getDetailsCont.GetApiResponse(); //Build and execute the capture request. var capECheck = new bankAccountType { accountNumber = ((AuthorizeNet.Api.Contracts.V1.bankAccountMaskedType)(getDetailsResp.transaction.payment.Item)).accountNumber.TrimStart(new char[] { 'X' }), routingNumber = "XXXX", nameOnAccount = ((AuthorizeNet.Api.Contracts.V1.bankAccountMaskedType)(getDetailsResp.transaction.payment.Item)).nameOnAccount, bankName = ((AuthorizeNet.Api.Contracts.V1.bankAccountMaskedType)(getDetailsResp.transaction.payment.Item)).bankName, echeckType = ((AuthorizeNet.Api.Contracts.V1.bankAccountMaskedType)(getDetailsResp.transaction.payment.Item)).echeckType, }; var capPayment = new paymentType { Item = capECheck }; var capTransactionRequest = new transactionRequestType { transactionType = transactionTypeEnum.priorAuthCaptureTransaction.ToString(), refTransId = getDetailsResp.transaction.transId, }; request = new createTransactionRequest { transactionRequest = capTransactionRequest }; controller = new createTransactionController(request); controller.Execute(); var capResponse = controller.GetApiResponse(); //validate Assert.AreEqual("1", capResponse.transactionResponse.messages[0].code); }
public void SetUp() { MockContext = new MockFactory(); //initialize counter Counter = _random.Next(1, (int)(Math.Pow(2, 24))); CounterStr = GetRandomString(""); _now = DateTime.UtcNow; _nowString = _now.ToString(DateFormat); _pastDate = _now.AddMonths(-1); _nowDate = _now; _futureDate = _now.AddMonths(1); CustomMerchantAuthenticationType = new merchantAuthenticationType { name = ApiLoginIdKey, ItemElementName = ItemChoiceType.transactionKey, Item = TransactionKey, }; // merchantAuthenticationType.setSessionToken(GetRandomString("SessionToken")); // merchantAuthenticationType.setPass_word(GetRandomString("Pass_word")); // merchantAuthenticationType.setMobileDeviceId(GetRandomString("MobileDevice")); // ImpersonationAuthenticationType impersonationAuthenticationType = new ImpersonationAuthenticationType(); // impersonationAuthenticationType.setPartnerLoginId(CnpApiLoginIdKey); // impersonationAuthenticationType.setPartnerTransactionKey(CnpTransactionKey); // merchantAuthenticationType.setImpersonationAuthentication(impersonationAuthenticationType); CustomerProfileType = new customerProfileType { merchantCustomerId = GetRandomString("Customer"), description = GetRandomString("CustomerDescription"), email = CounterStr + "*****@*****.**", }; //make sure these elements are initialized by calling get as it uses lazy initialization var paymentProfiles = CustomerProfileType.paymentProfiles; var addresses = CustomerProfileType.shipToList; CreditCardOne = new creditCardType { cardNumber = "4111111111111111", expirationDate = "2038-12", }; // creditCardOne.setCardCode(""); BankAccountOne = new bankAccountType { accountType = bankAccountTypeEnum.savings, routingNumber = "125000000", accountNumber = GetRandomString("A/C#"), nameOnAccount = GetRandomString("A/CName"), echeckType = echeckTypeEnum.WEB, bankName = GetRandomString("Bank"), checkNumber = CounterStr, }; TrackDataOne = new creditCardTrackType { ItemElementName = ItemChoiceType1.track1, Item = GetRandomString("Track1"), //trackDataOne.setTrack2(GetRandomString("Track2")); }; EncryptedTrackDataOne = new encryptedTrackDataType { FormOfPayment = new KeyBlock(), }; //keyBlock.setValue(value); PayPalOne = new payPalType { successUrl = GetRandomString("https://success.anet.net"), cancelUrl = GetRandomString("https://cancel.anet.net"), paypalLc = GetRandomString("Lc"), paypalHdrImg = GetRandomString("Hdr"), paypalPayflowcolor = GetRandomString("flowClr"), payerID = GetRandomString("PayerId"), }; PaymentOne = new paymentType { Item = CreditCardOne }; //paymentOne.setBankAccount(bankAccountOne); //paymentOne.setTrackData(trackDataOne); //paymentOne.setEncryptedTrackData(encryptedTrackDataOne); //paymentOne.setPayPal( payPalOne); // driversLicenseOne = new DriversLicenseType(); // driversLicenseOne.setNumber(GetRandomString("DLNumber")); // driversLicenseOne.setState(GetRandomString("WA")); // driversLicenseOne.setDateOfBirth(nowString); CustomerAddressOne = new customerAddressType { firstName = GetRandomString("FName"), lastName = GetRandomString("LName"), company = GetRandomString("Company"), address = GetRandomString("StreetAdd"), city = "Bellevue", state = "WA", zip = "98000", country = "USA", phoneNumber = FormatToPhone(Counter), faxNumber = FormatToPhone(Counter + 1), }; CustomerPaymentProfileOne = new customerPaymentProfileType { customerType = customerTypeEnum.individual, payment = PaymentOne, }; // customerPaymentProfileOne.setBillTo(customerAddressOne); // customerPaymentProfileOne.setDriversLicense(driversLicenseOne); // customerPaymentProfileOne.setTaxId(GetRandomString("XX")); CustomerOne = new customerType { type = customerTypeEnum.individual, id = GetRandomString("Id"), email = CounterStr + "*****@*****.**", phoneNumber = FormatToPhone(Counter), faxNumber = FormatToPhone(Counter + 1), driversLicense = DriversLicenseOne, taxId = "911011011", }; CustomerTwo = new customerType(); var interval = new paymentScheduleTypeInterval { length = 1, unit = ARBSubscriptionUnitEnum.months, }; OrderType = new orderType() { //TODO ADD VALIDATION ON INVOICE LENGTH invoiceNumber = GetRandomString("Inv:"), description = GetRandomString("Description"), }; NameAndAddressTypeOne = new nameAndAddressType { firstName = GetRandomString("FName"), lastName = GetRandomString("LName"), company = GetRandomString("Company"), address = GetRandomString("Address"), city = GetRandomString("City"), state = GetRandomString("State"), zip = "98004", country = "USA", }; NameAndAddressTypeTwo = new nameAndAddressType { firstName = GetRandomString("FName"), lastName = GetRandomString("LName"), company = GetRandomString("Company"), address = GetRandomString("Address"), city = GetRandomString("City"), state = GetRandomString("State"), zip = "98004", country = "USA", }; PaymentScheduleTypeOne = new paymentScheduleType { interval = interval, startDate = _nowDate, totalOccurrences = 5, trialOccurrences = 0, }; ArbSubscriptionOne = new ARBSubscriptionType { amount = SetValidSubscriptionAmount(Counter), billTo = NameAndAddressTypeOne, customer = CustomerOne, name = GetRandomString("Name"), order = OrderType, payment = PaymentOne, paymentSchedule = PaymentScheduleTypeOne, shipTo = NameAndAddressTypeOne, trialAmount = SetValidSubscriptionAmount(0), }; CustomerDataOne = new customerDataType { driversLicense = CustomerOne.driversLicense, email = CustomerOne.email, id = CustomerOne.id, taxId = CustomerOne.taxId, type = CustomerOne.type, }; RefId = CounterStr; }
// public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, decimal Amount) // { // Console.WriteLine("Debit Bank Account Transaction"); // ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNET.Environment.SANDBOX; // // define the merchant information (authentication / transaction id) // ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType() // { // name = ApiLoginID, // ItemElementName = ItemChoiceType.transactionKey, // Item = ApiTransactionKey // }; // var bankAccount = new bankAccountType // { // accountNumber = "4111111", // routingNumber = "325070760", // echeckType = echeckTypeEnum.WEB, // change based on how you take the payment (web, telephone, etc) // nameOnAccount = "Test Name" // }; // //standard api call to retrieve response // var paymentType = new paymentType { Item = bankAccount }; // var transactionRequest = new transactionRequestType // { // transactionType = transactionTypeEnum.authCaptureTransaction.ToString(), // refund type // payment = paymentType, // amount = Amount // }; // var request = new createTransactionRequest { transactionRequest = transactionRequest }; // // instantiate the contoller that will call the service // var controller = new createTransactionController(request); // controller.Execute(); // // get the response from the service (errors contained if any) // var response = controller.GetApiResponse(); // //validate // if (response != null) // { // if (response.messages.resultCode == messageTypeEnum.Ok) // { // if(response.transactionResponse.messages != null) // { // Console.WriteLine("Successfully created transaction with Transaction ID: " + response.transactionResponse.transId); // Console.WriteLine("Response Code: " + response.transactionResponse.responseCode); // Console.WriteLine("Message Code: " + response.transactionResponse.messages[0].code); // Console.WriteLine("Description: " + response.transactionResponse.messages[0].description); //Console.WriteLine("Success, Transaction Code : " + response.transactionResponse.transId); // } // else // { // Console.WriteLine("Failed Transaction."); // if (response.transactionResponse.errors != null) // { // Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode); // Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText); // } // } // } // else // { // Console.WriteLine("Failed Transaction."); // if (response.transactionResponse != null && response.transactionResponse.errors != null) // { // Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode); // Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText); // } // else // { // Console.WriteLine("Error Code: " + response.messages.message[0].code); // Console.WriteLine("Error message: " + response.messages.message[0].text); // } // } // } // else // { // Console.WriteLine("Null Response."); // } // return response; // } public static void DebitBankAccountExec(String ApiLoginID, String ApiTransactionKey) { using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/DebitBankAccount.csv", FileMode.Open)), true)) { Console.WriteLine("Debit Bank Account Transaction"); int flag = 0; int fieldCount = csv.FieldCount; string[] headers = csv.GetFieldHeaders(); //Append data var item1 = DataAppend.ReadPrevData(); using (CsvFileWriter writer = new CsvFileWriter(new FileStream(@"../../../CSV_DATA/Outputfile.csv", FileMode.Open))) { while (csv.ReadNextRecord()) { ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNET.Environment.SANDBOX; // define the merchant information (authentication / transaction id) ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType() { name = ApiLoginID, ItemElementName = ItemChoiceType.transactionKey, Item = ApiTransactionKey }; var bankAccount = new bankAccountType { accountNumber = "4111111", routingNumber = "325070760", echeckType = echeckTypeEnum.WEB, // change based on how you take the payment (web, telephone, etc) nameOnAccount = "Test Name" }; //standard api call to retrieve response var paymentType = new paymentType { Item = bankAccount }; string amount = null; string TestCaseId = null; for (int i = 0; i < fieldCount; i++) { switch (headers[i]) { case "TestCaseId": TestCaseId = csv[i]; break; case "amount": amount = csv[i]; break; default: break; } } CsvRow row = new CsvRow(); try { if (flag == 0) { row.Add("TestCaseId"); row.Add("APIName"); row.Add("Status"); row.Add("TimeStamp"); writer.WriteRow(row); flag = flag + 1; //Append Results foreach (var item in item1) { writer.WriteRow(item); } } var transactionRequest = new transactionRequestType { transactionType = transactionTypeEnum.authCaptureTransaction.ToString(), // refund type payment = paymentType, amount = Convert.ToDecimal(amount) }; var request = new createTransactionRequest { transactionRequest = transactionRequest }; request.merchantAuthentication = ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication; // instantiate the contoller that will call the service var controller = new createTransactionController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); //validate if (response != null) { if (response.messages.resultCode == messageTypeEnum.Ok) { if (response.transactionResponse.messages != null) { /*****************************/ try { //Assert.AreEqual(response.Id, customerProfileId); Console.WriteLine("Assertion Succeed! Valid customerProfileId fetched."); CsvRow row1 = new CsvRow(); row1.Add("DBA_00" + flag.ToString()); row1.Add("CreateCustomerPaymentProfile"); row1.Add("Pass"); row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff")); writer.WriteRow(row1); // Console.WriteLine("Success " + TestcaseID + " CustomerID : " + response.Id); flag = flag + 1; Console.WriteLine("Successfully created transaction with Transaction ID: " + response.transactionResponse.transId); Console.WriteLine("Response Code: " + response.transactionResponse.responseCode); Console.WriteLine("Message Code: " + response.transactionResponse.messages[0].code); Console.WriteLine("Description: " + response.transactionResponse.messages[0].description); Console.WriteLine("Success, Transaction Code : " + response.transactionResponse.transId); } catch { CsvRow row1 = new CsvRow(); row1.Add("DBA_00" + flag.ToString()); row1.Add("CreateCustomerPaymentProfile"); row1.Add("Assertion Failed!"); row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff")); writer.WriteRow(row1); Console.WriteLine("Assertion Failed! Invalid CustomerPaymentProfile fetched."); flag = flag + 1; } /*******************/ } else { Console.WriteLine("Failed Transaction."); CsvRow row2 = new CsvRow(); row2.Add("DBA_00" + flag.ToString()); row2.Add("DebitBankAccount"); row2.Add("Fail"); row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff")); writer.WriteRow(row2); flag = flag + 1; //if (response.transactionResponse.errors != null) //{ // Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode); // Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText); //} } } else { Console.WriteLine("Failed Transaction."); CsvRow row2 = new CsvRow(); row2.Add("DBA_00" + flag.ToString()); row2.Add("DebitBankAccount"); row2.Add("Fail"); row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff")); writer.WriteRow(row2); flag = flag + 1; //if (response.transactionResponse != null && response.transactionResponse.errors != null) //{ // Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode); // Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText); //} //else //{ // Console.WriteLine("Error Code: " + response.messages.message[0].code); // Console.WriteLine("Error message: " + response.messages.message[0].text); //} } } //} else { Console.WriteLine("Null Response."); CsvRow row2 = new CsvRow(); row2.Add("DBA_00" + flag.ToString()); row2.Add("DebitBankAccount"); row2.Add("Fail"); row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff")); writer.WriteRow(row2); flag = flag + 1; } //return response; } //} catch (Exception e) { CsvRow row2 = new CsvRow(); row2.Add("DBA_00" + flag.ToString()); row2.Add("DebitBankAccount"); row2.Add("Fail"); row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff")); writer.WriteRow(row2); flag = flag + 1; //Console.WriteLine(TestCaseId + " Error Message " + e.Message); } } } } }
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" }; //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) }; //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 void cardAdd(CardInfoViewModel data) { //Console.WriteLine("Update customer profile sample"); 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, }; if (data.addnewcard.CCAddCard) { var creditCard = new creditCardType { cardNumber = data.addnewcard.x_card_num, expirationDate = data.addnewcard.x_exp_code }; // standard api call to retrieve response paymentType cc = new paymentType { Item = creditCard }; customerPaymentProfileExType ccPaymentProfile = new customerPaymentProfileExType(); ccPaymentProfile.payment = cc; var request = new createCustomerPaymentProfileRequest(); request.paymentProfile = ccPaymentProfile; request.customerProfileId = data.customerProfile_Id; // 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) 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); } } else if (data.addnewcard.BankAddCard) { var bankAccount = new bankAccountType { accountNumber = data.addnewcard.x_name_account_num, routingNumber = data.addnewcard.x_aba_rout_num, accountType = bankAccountTypeEnum.checking, echeckType = echeckTypeEnum.WEB, nameOnAccount = data.addnewcard.x_name_on_account, bankName = data.addnewcard.x_bank_name }; paymentType echeck = new paymentType { Item = bankAccount }; customerPaymentProfileExType ccPaymentProfile = new customerPaymentProfileExType(); ccPaymentProfile.payment = echeck; var request = new createCustomerPaymentProfileRequest(); request.paymentProfile = ccPaymentProfile; request.customerProfileId = data.customerProfile_Id; // 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) 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); } } }
//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); } } } } }
public void CreateCustomerProfileFromECheckTransaction() { var rnd = new AnetRandom(DateTime.Now.Millisecond); string customerIndx = rnd.Next(99999).ToString(); ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = CustomMerchantAuthenticationType; ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = TestEnvironment; //set up data based on transaction var transactionAmount = SetValidTransactionAmount(Counter); var echeck = new bankAccountType { accountNumber = "123456", accountType = bankAccountTypeEnum.checking, checkNumber = "1234", bankName = "Bank of Seattle", routingNumber = "125000024", echeckType = echeckTypeEnum.WEB, nameOnAccount = "Joe Customer" }; //Create and submit transaction with customer info to create profile from. var paymentType = new paymentType { Item = echeck }; var transactionRequest = new transactionRequestType { transactionType = transactionTypeEnum.authOnlyTransaction.ToString(), payment = paymentType, amount = (decimal)transactionAmount, customer = new customerDataType { email = string.Format("Customer{0}@visa.com", customerIndx), taxId = string.Format("{0}{1}{2}", rnd.Next(999).ToString("000"), rnd.Next(99).ToString("00"), rnd.Next(9999).ToString("0000")) }, billTo = new customerAddressType { firstName = "New", lastName = string.Format("Customer{0}", customerIndx), company = "New Company", address = "1234 Sample St NE", city = "Bellevue", state = "WA", zip = "98001" }, shipTo = new customerAddressType { firstName = "New", lastName = string.Format("Customer{0}", customerIndx), company = "New Company", address = "1234 Sample St NE", city = "Bellevue", state = "WA", zip = "98001" } }; var request = new createTransactionRequest { transactionRequest = transactionRequest }; var controller = new createTransactionController(request); controller.Execute(); var response = controller.GetApiResponse(); //Verify that transaction was accepted and save the transaction ID Assert.AreEqual(messageTypeEnum.Ok, response.messages.resultCode); string txnID = response.transactionResponse.transId; //Build and submit request to create Customer Profile based on the accepted transaction createCustomerProfileFromTransactionRequest profileFromTransReq = new createCustomerProfileFromTransactionRequest(); profileFromTransReq.transId = txnID; createCustomerProfileFromTransactionController profileFromTrxnController = new createCustomerProfileFromTransactionController(profileFromTransReq); profileFromTrxnController.Execute(); createCustomerProfileResponse createProfResp = profileFromTrxnController.GetApiResponse(); Assert.AreEqual(messageTypeEnum.Ok, createProfResp.messages.resultCode); //Get customer profile and verify that profile data matches the data submitted with the transaction getCustomerProfileRequest profileReq = new getCustomerProfileRequest { customerProfileId = createProfResp.customerProfileId }; getCustomerProfileController getCustContr = new getCustomerProfileController(profileReq); getCustContr.Execute(); var getCustResp = getCustContr.GetApiResponse(); //validate Assert.AreEqual("1", response.transactionResponse.messages[0].code); }