public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, string customerProfileID, string customerAddressId) { Console.WriteLine("Update customer shipping address sample"); ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.SANDBOX; // define the merchant information (authentication / transaction id) ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType() { name = ApiLoginID, ItemElementName = ItemChoiceType.transactionKey, Item = ApiTransactionKey, }; var creditCard = new creditCardType { cardNumber = "4111111111111111", expirationDate = "1018" }; var paymentType = new paymentType { Item = creditCard }; var address = new customerAddressExType { firstName = "Newfirstname", lastName = "Doe", address = "123 Main St.", city = "Bellevue", state = "WA", zip = "98004", country = "USA", phoneNumber = "000-000-000", customerAddressId = customerAddressId }; var request = new updateCustomerShippingAddressRequest(); request.customerProfileId = customerProfileID; request.address = address; // instantiate the controller that will call the service var controller = new updateCustomerShippingAddressController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); if (response != null && response.messages.resultCode == messageTypeEnum.Ok) { Console.WriteLine(response.messages.message[0].text); } else if (response != null) { Console.WriteLine("Error: " + response.messages.message[0].code + " " + response.messages.message[0].text); } return(response); }
public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, decimal amount) { Console.WriteLine("Authorize Credit Card Sample"); ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.SANDBOX; // define the merchant information (authentication / transaction id) ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType() { name = ApiLoginID, ItemElementName = ItemChoiceType.transactionKey, Item = ApiTransactionKey, }; var creditCard = new creditCardType { cardNumber = "4111111111111111", expirationDate = "1028" }; //standard api call to retrieve response var paymentType = new paymentType { Item = creditCard }; var transactionRequest = new transactionRequestType { transactionType = transactionTypeEnum.authOnlyTransaction.ToString(), // authorize only amount = amount, payment = paymentType }; var request = new createTransactionRequest { transactionRequest = transactionRequest }; // instantiate the 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, Auth Code : " + response.transactionResponse.authCode); } else { Console.WriteLine("Failed Transaction."); if (response.transactionResponse.errors != null) { Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode); Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText); } } } else { Console.WriteLine("Failed Transaction."); if (response.transactionResponse != null && response.transactionResponse.errors != null) { Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode); Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText); } else { Console.WriteLine("Error Code: " + response.messages.message[0].code); Console.WriteLine("Error message: " + response.messages.message[0].text); } } } else { Console.WriteLine("Null Response."); } return(response); }
public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey) { Console.WriteLine("PayPal Authorize Only Transaction"); ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.SANDBOX; // define the merchant information (authentication / transaction id) ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType() { name = ApiLoginID, ItemElementName = ItemChoiceType.transactionKey, Item = ApiTransactionKey }; var payPalType = new payPalType { cancelUrl = "http://www.merchanteCommerceSite.com/Success/TC25262", successUrl = "http://www.merchanteCommerceSite.com/Success/TC25262", // the url where the user will be returned to }; //standard api call to retrieve response var paymentType = new paymentType { Item = payPalType }; var transactionRequest = new transactionRequestType { transactionType = transactionTypeEnum.authOnlyTransaction.ToString(), // capture the card only payment = paymentType, amount = 19.45m }; 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, Auth Code : " + response.transactionResponse.authCode); } } 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); }
/// <summary> /// Process a payment /// </summary> /// <param name="processPaymentRequest">Payment info required for an order processing</param> /// <returns>Process payment result</returns> public ProcessPaymentResult ProcessPayment(ProcessPaymentRequest processPaymentRequest) { var result = new ProcessPaymentResult(); var customer = _customerService.GetCustomerById(processPaymentRequest.CustomerId); PrepareAuthorizeNet(); var creditCard = new creditCardType { cardNumber = processPaymentRequest.CreditCardNumber, expirationDate = processPaymentRequest.CreditCardExpireMonth.ToString("D2") + processPaymentRequest.CreditCardExpireYear, cardCode = processPaymentRequest.CreditCardCvv2 }; //standard api call to retrieve response var paymentType = new paymentType { Item = creditCard }; transactionTypeEnum transactionType; switch (_authorizeNetPaymentSettings.TransactMode) { case TransactMode.Authorize: transactionType = transactionTypeEnum.authOnlyTransaction; break; case TransactMode.AuthorizeAndCapture: transactionType = transactionTypeEnum.authCaptureTransaction; break; default: throw new NopException("Not supported transaction mode"); } var billTo = new customerAddressType { firstName = customer.BillingAddress.FirstName, lastName = customer.BillingAddress.LastName, email = customer.BillingAddress.Email, address = customer.BillingAddress.Address1, city = customer.BillingAddress.City, zip = customer.BillingAddress.ZipPostalCode }; if (!string.IsNullOrEmpty(customer.BillingAddress.Company)) { billTo.company = customer.BillingAddress.Company; } if (customer.BillingAddress.StateProvince != null) { billTo.state = customer.BillingAddress.StateProvince.Abbreviation; } if (customer.BillingAddress.Country != null) { billTo.country = customer.BillingAddress.Country.TwoLetterIsoCode; } var transactionRequest = new transactionRequestType { transactionType = transactionType.ToString(), amount = Math.Round(processPaymentRequest.OrderTotal, 2), payment = paymentType, currencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode, billTo = billTo, customerIP = _webHelper.GetCurrentIpAddress(), order = new orderType { //x_invoice_num is 20 chars maximum. hece we also pass x_description invoiceNumber = processPaymentRequest.OrderGuid.ToString().Substring(0, 20), description = string.Format("Full order #{0}", processPaymentRequest.OrderGuid) } }; 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 = GetApiResponse(controller, result.Errors); //validate if (response == null) { return(result); } if (_authorizeNetPaymentSettings.TransactMode == TransactMode.Authorize) { result.AuthorizationTransactionId = response.transactionResponse.transId; result.AuthorizationTransactionCode = string.Format("{0},{1}", response.transactionResponse.transId, response.transactionResponse.authCode); } if (_authorizeNetPaymentSettings.TransactMode == TransactMode.AuthorizeAndCapture) { result.CaptureTransactionId = string.Format("{0},{1}", response.transactionResponse.transId, response.transactionResponse.authCode); } result.AuthorizationTransactionResult = string.Format("Approved ({0}: {1})", response.transactionResponse.responseCode, response.transactionResponse.messages[0].description); result.AvsResult = response.transactionResponse.avsResultCode; result.NewPaymentStatus = _authorizeNetPaymentSettings.TransactMode == TransactMode.Authorize ? PaymentStatus.Authorized : PaymentStatus.Paid; return(result); }
/// <summary> /// gets address and amount to charge and runs through the trasaction process /// </summary> /// <param name="cardNumber"></param> /// <param name="User"></param> /// <param name="cart"></param> /// <returns>String</returns> public string Run(string cardNumber, ApplicationUser user, Cart cart) { //sets the enviornment to sanbox ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.SANDBOX; //Gets access requirment from user secrets ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType() { name = _configuration["AuthNetAPILogin"], ItemElementName = ItemChoiceType.transactionKey, Item = _configuration["AuthNetTransactionKey"] }; //gets credit card info var creditCard = new creditCardType { cardNumber = cardNumber, expirationDate = "1022" }; //gets the address customerAddressType billingAddress = GetAddress(user); //sets the payment type to credit card var paymentType = new paymentType { Item = creditCard }; var transactionRequest = new transactionRequestType { transactionType = transactionTypeEnum.authCaptureTransaction.ToString(), amount = cart.GrandTotal, payment = paymentType, billTo = billingAddress, }; //creates the request for the transaction createTransactionRequest request = new createTransactionRequest { transactionRequest = transactionRequest }; //creates the transaction controller var controller = new createTransactionController(request); controller.Execute(); var response = controller.GetApiResponse(); if (response != null) { if (response.messages.resultCode == messageTypeEnum.Ok) { if (response.transactionResponse.messages != null) { return("Okay"); } } else { return("Something Went Wrong"); } } return("Something Went Wrong"); }
public TransactionResponse ChargeCredit(PaymentModel payment) { // determine run Environment to SANDBOX for developemnt level 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 = transactionKey, }; var creditCard = new creditCardType { cardNumber = payment.CardNumber, //"Ex: x111111111111111", expirationDate = payment.Month + payment.Year, //"Ex: 0522" cardCode = payment.CardCode, //"Ex: 111" }; var billingAddress = new customerAddressType { firstName = payment.FirstName, lastName = payment.LastName, city = payment.Address1, address = payment.Address2, zip = payment.Postcode, phoneNumber = payment.Phone }; //standard api call to retrieve response var paymentType = new paymentType { Item = creditCard }; // Add line Items you pay to obtain these var lineItems = new lineItemType[2]; lineItems[0] = new lineItemType { itemId = "1", name = "t-shirt", quantity = 2, unitPrice = new Decimal(1.00) }; lineItems[1] = new lineItemType { itemId = "2", name = "snowboard", quantity = 1, unitPrice = new Decimal(1.00) }; var transactionRequest = new transactionRequestType { transactionType = transactionTypeEnum.authCaptureTransaction.ToString(), // charge the card amount = 2, payment = paymentType, billTo = billingAddress, lineItems = lineItems }; var request = new createTransactionRequest { transactionRequest = transactionRequest }; // instantiate the contoller that will call the service var controller = new createTransactionController(request); controller.Execute(); var resCode = controller.GetResultCode(); var resAll = controller.GetResults(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); //validate TransactionResponse result = new TransactionResponse(); if (response != null) { result.resultCode = response.messages.resultCode; if (response.messages.resultCode == messageTypeEnum.Ok) { if (response.transactionResponse.messages != null) { result.transId = response.transactionResponse.transId; result.responseCode = response.transactionResponse.responseCode; result.messageCode = response.transactionResponse.messages[0].code; result.description = response.transactionResponse.messages[0].description; result.authCode = response.transactionResponse.authCode; } else { if (response.transactionResponse.errors != null) { result.errorCode = response.transactionResponse.errors[0].errorCode; result.errorText = response.transactionResponse.errors[0].errorText; } } } else { if (response.transactionResponse != null && response.transactionResponse.errors != null) { result.errorCode = response.transactionResponse.errors[0].errorCode; result.errorText = response.transactionResponse.errors[0].errorText; } else { result.errorCode = response.messages.message[0].code; result.errorText = response.messages.message[0].text; } } } else { result.errorCode = "NONE"; result.errorText = "Failed Transaction,, Unkown Error"; } return(result); }
public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, short intervalLength, string customerProfileId, string customerPaymentProfileId, string customerAddressId) { Console.WriteLine("Create Subscription Sample"); ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.SANDBOX; ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType() { name = ApiLoginID, ItemElementName = ItemChoiceType.transactionKey, Item = ApiTransactionKey }; paymentScheduleTypeInterval interval = new paymentScheduleTypeInterval(); interval.length = intervalLength; // months can be indicated between 1 and 12 interval.unit = ARBSubscriptionUnitEnum.days; paymentScheduleType schedule = new paymentScheduleType { interval = interval, startDate = DateTime.Now.AddDays(1), // start date should be tomorrow totalOccurrences = 9999, // 999 indicates no end date trialOccurrences = 3 }; #region Payment Information var creditCard = new creditCardType { cardNumber = "4111111111111111", expirationDate = "1028" }; //standard api call to retrieve response paymentType cc = new paymentType { Item = creditCard }; #endregion customerProfileIdType customerProfile = new customerProfileIdType() { customerProfileId = customerProfileId, customerPaymentProfileId = customerPaymentProfileId, customerAddressId = customerAddressId }; ARBSubscriptionType subscriptionType = new ARBSubscriptionType() { amount = 35.55m, trialAmount = 0.00m, paymentSchedule = schedule, profile = customerProfile }; var request = new ARBCreateSubscriptionRequest { subscription = subscriptionType }; var controller = new ARBCreateSubscriptionController(request); // instantiate the controller that will call the service controller.Execute(); ARBCreateSubscriptionResponse response = controller.GetApiResponse(); // get the response from the service (errors contained if any) // validate response if (response != null && response.messages.resultCode == messageTypeEnum.Ok) { if (response != null && response.messages.message != null) { Console.WriteLine("Success, Subscription ID : " + response.subscriptionId.ToString()); } } else if (response != null) { Console.WriteLine("Error: " + response.messages.message[0].code + " " + response.messages.message[0].text); } return(response); }
/// <summary> /// Permet d'éditer une nouvelle opération. /// </summary> /// <param name="operation">Opération concernée.</param> /// <param name="Name">Nom de l'opération.</param> /// <param name="Amount">Montant de l'opération.</param> /// <param name="PaymentType">Type de paiement.</param> /// <param name="OperationType">Type d'opération.</param> /// <param name="Date">Date de l'opération.</param> /// <param name="category">Catégorie de l'opération.</param> public static void EditOperation(Model.Operation operation, string Name, float Amount, paymentType PaymentType, operationType OperationType, DateTime Date, Category category) { operation.Name = Name; operation.Amount = Amount; operation.PaymentType = PaymentType; operation.OperationType = OperationType; operation.Date = Date; operation.category = category; Program.ctx.Save(); }
public void SampleCodeCreateCreditRequestForSettledTransaction() { var rnd = new AnetRandom(DateTime.Now.Millisecond); ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = CustomMerchantAuthenticationType; ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = TestEnvironment; // Find a settled credit card transaction and set txnToCredit to its transaction ID string txnToCredit = "Not Set"; if (txnToCredit == "Not Set") { Assert.Fail("This test requires that you set txnToCredit to the transaction ID of a settled credit card transaction"); } //get details of the specified transaction decimal txnAmount = 0m; string txnCardNo = string.Empty; var gtdReq = new getTransactionDetailsRequest { transId = txnToCredit }; var gtdCont = new getTransactionDetailsController(gtdReq); gtdCont.Execute(); var gtdResp = gtdCont.GetApiResponse(); //Test the transaction before continuing Assert.AreEqual(messageTypeEnum.Ok, gtdResp.messages.resultCode); txnAmount = gtdResp.transaction.settleAmount; txnCardNo = ((AuthorizeNet.Api.Contracts.V1.creditCardMaskedType)(gtdResp.transaction.payment.Item)).cardNumber; //Create payment type that matches transaction to credit var creditCard = new creditCardType { cardNumber = txnCardNo.TrimStart(new char[] { 'X' }), expirationDate = "XXXX" }; var paymentType = new paymentType { Item = creditCard }; //Create credit request transactionRequestType txnType = new transactionRequestType { amount = txnAmount, refTransId = txnToCredit, transactionType = transactionTypeEnum.refundTransaction.ToString(), payment = paymentType, }; createTransactionRequest creditReq = new createTransactionRequest { transactionRequest = txnType }; createTransactionController creditCont = new createTransactionController(creditReq); creditCont.Execute(); createTransactionResponse creditResp = creditCont.GetApiResponse(); //validate Assert.AreEqual("1", creditResp.transactionResponse.messages[0].code); }
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> /// Permet d'ajouter une nouvelle opération. /// </summary> /// <param name="Account">Compte concerné par l'operation.</param> /// <param name="Name">Nom de l'opération.</param> /// <param name="opT">Type d'opération.</param> /// <param name="date">Date de l'opération.</param> /// <param name="paT">Type de paiement.</param> /// <param name="Amount">Montant de l'opération.</param> /// <param name="cat">Catégorie de l'opération.</param> public static void AddOperation(Model.Account Account, string Name, operationType opT, DateTime date, paymentType paT, float Amount, Category cat) { Account.Operations.Add(new Operation(Name, opT, date, paT, Amount, cat)); Program.ctx.Save(); }
public string Run(string cardtype, customerAddressType details) { ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.SANDBOX; ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType() { name = _config["AN-ApiLoginID"], ItemElementName = ItemChoiceType.transactionKey, Item = _config["AN-TransactionKey"] }; var creditCard = new creditCardType(); switch (cardtype) { case "visa": creditCard = new creditCardType { cardNumber = "4007000000027", expirationDate = "1021", cardCode = "900" }; break; case "master": creditCard = new creditCardType { cardNumber = "5424000000000015", expirationDate = "1021", cardCode = "901" }; break; case "amex": creditCard = new creditCardType { cardNumber = "370000000000002", expirationDate = "1021", cardCode = "900" }; break; case "discover": creditCard = new creditCardType { cardNumber = "6011000000000012", expirationDate = "1021", cardCode = "900" }; break; } customerAddressType billingAddress = details; var paymentType = new paymentType { Item = creditCard }; var requestType = new transactionRequestType { transactionType = transactionTypeEnum.authCaptureTransaction.ToString(), amount = 130.5m, payment = paymentType, billTo = billingAddress }; var request = new createTransactionRequest { transactionRequest = requestType }; var controller = new createTransactionController(request); controller.Execute(); var response = controller.GetApiResponse(); if (response != null) { if (response.messages.resultCode == messageTypeEnum.Ok) { return("success"); } } return("fail"); }
/// <summary> /// Runs the credit card transaction request /// </summary> /// <returns>Empty string</returns> public bool Run(Order input) { // type of environment ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.SANDBOX; string authNetId = WebHostEnvironment.IsDevelopment() ? _config["AUTHORIZELOGINID"] : Environment.GetEnvironmentVariable("AUTHORIZELOGINID"); string authNetKey = WebHostEnvironment.IsDevelopment() ? _config["AUTHORIZETRANSACTIONKEY"] : Environment.GetEnvironmentVariable("AUTHORIZETRANSACTIONKEY"); // setup merchant account credentials ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType() { name = authNetId, ItemElementName = ItemChoiceType.transactionKey, Item = authNetKey }; string cardExpDate = WebHostEnvironment.IsDevelopment() ? _config["TESTEXPIRATIONDATE"] : Environment.GetEnvironmentVariable("TESTEXPIRATIONDATE"); string cardSecCode = WebHostEnvironment.IsDevelopment() ? _config["TESTCVV"] : Environment.GetEnvironmentVariable("TESTCVV"); // create card we want on file // visa var creditCard = new creditCardType { cardNumber = _config[input.CardType], expirationDate = cardExpDate, cardCode = cardSecCode }; customerAddressType billingAddress = GetBillingAddress(input); var paymentType = new paymentType { Item = creditCard }; var transRequest = new transactionRequestType { transactionType = transactionTypeEnum.authCaptureTransaction.ToString(), amount = input.Cart.Total, payment = paymentType, billTo = billingAddress }; var request = new createTransactionRequest { transactionRequest = transRequest }; var controller = new createTransactionController(request); controller.Execute(); var response = controller.GetApiResponse(); if (response != null) { if (response.messages.resultCode == messageTypeEnum.Ok) { return(true); } } else { return(false); } return(false); }
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 string Run(long creditCardPassInside, int experationCardIniside) { ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.SANDBOX; //define merchant information (authentication & transaction ID) ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType() { name = _configuration["AuthNetAPILogin"], ItemElementName = ItemChoiceType.transactionKey, Item = _configuration["AuthNetTransactionKey"] }; //CREATE A CREDIT CARD we need a cc //bring in a parameter var creditCard = new creditCardType { //Drop down or have user put in their own CC and check that it's for the future cardNumber = creditCardPassInside.ToString(), expirationDate = experationCardIniside.ToString() }; customerAddressType billingAddress = new customerAddressType(); var paymentType = new paymentType { Item = creditCard }; //transaction request type consolidate all the info before sending to autho.net //1. amount of order transactionRequestType transactionRequest = new transactionRequestType { transactionType = transactionTypeEnum.authCaptureTransaction.ToString(), amount = 2.34m, payment = paymentType, billTo = billingAddress, //lineItems = lineItems, }; createTransactionRequest request = new createTransactionRequest { transactionRequest = transactionRequest }; //Make a call out to Autho.Net var controller = new createTransactionController(request); //execcute the callll controller.Execute(); //Response from call above var response = controller.GetApiResponse(); if (response != null) { if (response.messages.resultCode == messageTypeEnum.Ok) { if (response.transactionResponse != null) { //Console.WriteLine("Success, Auth Code : " + response.transactionResponse.authCode); return("OK"); } } else { Console.WriteLine("Transaction Error : " + response.transactionResponse.errors[0].errorCode + " " + response.transactionResponse.errors[0].errorText); return("This is NOT ok!"); } } return("Does not works"); /* * // 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, Auth Code : " + response.transactionResponse.authCode); * } * else * { * Console.WriteLine("Failed Transaction."); * if (response.transactionResponse.errors != null) * { * Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode); * Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText); * } * } * } * else * { * Console.WriteLine("Failed Transaction."); * if (response.transactionResponse != null && response.transactionResponse.errors != null) * { * Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode); * Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText); * } * else * { * Console.WriteLine("Error Code: " + response.messages.message[0].code); * Console.WriteLine("Error message: " + response.messages.message[0].text); * } * } * } * else * { * Console.WriteLine("Null Response."); * } * * return "It was submitted. That's all I can say";*/ }
public void SampleCodeCreateTransactionPriorAuthCapture() { //Common code to set for all requests ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = CustomMerchantAuthenticationType; ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = TestEnvironment; //set up data based on transaction var transactionAmount = SetValidTransactionAmount(Counter); var creditCard = new creditCardType { cardNumber = "4111111111111111", expirationDate = "0622" }; //Build auth only transaction request. var paymentType = new paymentType { Item = creditCard }; 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 capCC = new creditCardType { cardNumber = ((creditCardMaskedType)(getDetailsResp.transaction.payment.Item)).cardNumber.TrimStart(new char[] { 'X' }), expirationDate = "XXXX", }; var capPayment = new paymentType { Item = capCC }; var capTransactionRequest = new transactionRequestType { transactionType = transactionTypeEnum.priorAuthCaptureTransaction.ToString(), refTransId = getDetailsResp.transaction.transId, authCode = getDetailsResp.transaction.authCode, }; 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 static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, string TransactionID) { Console.WriteLine("PayPal Void Transaction"); ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.SANDBOX; // define the merchant information (authentication / transaction id) ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType() { name = ApiLoginID, ItemElementName = ItemChoiceType.transactionKey, Item = ApiTransactionKey }; var payPalType = new payPalType { cancelUrl = "", successUrl = "", // the url where the user will be returned to }; //standard api call to retrieve response var paymentType = new paymentType { Item = payPalType }; var transactionRequest = new transactionRequestType { transactionType = transactionTypeEnum.voidTransaction.ToString(), // refund type payment = paymentType, 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); } 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, 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 }; Random rand = new Random(); int randomAccountNumber = rand.Next(10000, int.MaxValue); var bankAccount = new bankAccountType { accountType = bankAccountTypeEnum.checking, routingNumber = "125008547", accountNumber = randomAccountNumber.ToString(), 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.authCaptureTransaction.ToString(), // refund type payment = paymentType, amount = Amount }; 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 TransactionVM Test(String ApiLoginId, String ApiTransactionKey, TransactionVM model) { Console.WriteLine("Charge Credit Card Sample"); ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.SANDBOX; // define the merchant information (authentication / transaction id) ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType() { name = ApiLoginId, ItemElementName = ItemChoiceType.transactionKey, Item = ApiTransactionKey, }; var creditCard = new creditCardType { cardNumber = "4111111111111111", expirationDate = "0721" }; //standard api call to retrieve response var paymentType = new paymentType { Item = creditCard }; var transactionRequest = new transactionRequestType { transactionType = transactionTypeEnum.authCaptureTransaction.ToString(), // charge the card amount = 133.45m, payment = paymentType }; var request = new createTransactionRequest { transactionRequest = transactionRequest }; // instantiate the contoller that will call the service var controller = new createTransactionController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); if (response.messages.resultCode == messageTypeEnum.Ok) { if (response.transactionResponse != null) { model.Response = "Success, Auth Code : " + response.transactionResponse.authCode; } } else { model.Response = "Error: " + response.messages.message[0].code + " " + response.messages.message[0].text; if (response.transactionResponse != null) { model.Response = "Transaction Error : " + response.transactionResponse.errors[0].errorCode + " " + response.transactionResponse.errors[0].errorText; } } return(model); }
public string Run() { // controllers.Base for authoriseNet ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.SANDBOX; ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType() { name = _config["AN-ApiLoginID"], ItemElementName = ItemChoiceType.transactionKey, Item = _config["AN-TransactionKey"] }; // set a credit card. // can be hard coded. or brought in through secrets // DO NOT ask the user for their credit number var creditCard = new creditCardType { cardNumber = "4111111111111111", expirationDate = "1020", cardCode = "102" }; customerAddressType billingAddress = GetAddress("someUserId"); var paymentType = new paymentType { Item = creditCard }; // this class takes everything we've defined, and puts it all in one object. var potato = new transactionRequestType { transactionType = transactionTypeEnum.authCaptureTransaction.ToString(), amount = 122.5m, payment = paymentType, billTo = billingAddress }; var request = new createTransactionRequest { transactionRequest = potato }; var controller = new createTransactionController(request); // This is going to produce an error! // to fix this error........ // PM> install-package System.Configuration.ConfigurationManager controller.Execute(); var response = controller.GetApiResponse(); if (response != null) { if (response.messages.resultCode == messageTypeEnum.Ok) { return("success!"); } } return("fail"); }
public static ANetApiResponse Run(string ApiLoginID, string ApiTransactionKey, string subscriptionId) { Console.WriteLine("Update Subscription Sample"); ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.SANDBOX; ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType() { name = ApiLoginID, ItemElementName = ItemChoiceType.transactionKey, Item = ApiTransactionKey, }; paymentScheduleType schedule = new paymentScheduleType { startDate = DateTime.Now.AddDays(1), // start date should be tomorrow totalOccurrences = 9999 // 999 indicates no end date }; #region Payment Information var creditCard = new creditCardType { cardNumber = "4111111111111111", expirationDate = "0718" }; //standard api call to retrieve response paymentType cc = new paymentType { Item = creditCard }; #endregion nameAndAddressType addressInfo = new nameAndAddressType() { firstName = "Calvin", lastName = "Brown" }; customerProfileIdType customerProfile = new customerProfileIdType() { customerProfileId = "1232312", customerPaymentProfileId = "2132132", customerAddressId = "1233432" }; ARBSubscriptionType subscriptionType = new ARBSubscriptionType() { amount = 35.55m, paymentSchedule = schedule, billTo = addressInfo, payment = cc //You can pass a profile to update subscription //,profile = customerProfile }; //Please change the subscriptionId according to your request var request = new ARBUpdateSubscriptionRequest { subscription = subscriptionType, subscriptionId = subscriptionId }; var controller = new ARBUpdateSubscriptionController(request); controller.Execute(); ARBUpdateSubscriptionResponse response = controller.GetApiResponse(); //validate if (response != null && response.messages.resultCode == messageTypeEnum.Ok) { if (response != null && response.messages.message != null) { Console.WriteLine("Success, RefID Code : " + response.refId); } } else if (response != null) { Console.WriteLine("Error: " + response.messages.message[0].code + " " + response.messages.message[0].text); } return(response); }
public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, decimal amount) { Console.WriteLine("Charge Encrypted Track Data Sample"); ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.SANDBOX; // define the merchant information (authentication / transaction id) ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType() { name = ApiLoginID, ItemElementName = ItemChoiceType.transactionKey, Item = ApiTransactionKey, }; // Track data goes in EncryptedTrack Data Type var cardData = new encryptedTrackDataType(); // KeyManagementScheme corresponds to the encryption settings and data from the reader var scheme = new KeyManagementScheme(); scheme.DUKPT = new KeyManagementSchemeDUKPT { Operation = OperationType.DECRYPT, DeviceInfo = new KeyManagementSchemeDUKPTDeviceInfo { Description = "4649443D4944544543482E556E694D61672E416E64726F69642E53646B7631" }, EncryptedData = new KeyManagementSchemeDUKPTEncryptedData { Value = "02f300801f342600039b252a343237352a2a2a2a2a2a2a2a353637355e332f54455354205e2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a3f2a3b343237352a2a2a2a2a2a2a2a353637353d2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a3f2a521db2603bfe6169fc371211161c4ad6edd7294a8352af1ba8b388c527d8d6335286413ad67521b8be085da998cef7ae3621b0b72eecd6d61953a4a268e02a8cdff3d365216df73646b326d8dac369c11a2a3a4a9336addc4a15ae5d8843e0163bae895b9b4df3253439b4dd885363ad108604ea04f2e4fac701a5a0e65c54e1301a5ed7706eb88762994901000000400015ac1e03" }, Mode = new KeyManagementSchemeDUKPTMode { Data = null, PIN = "1" } }; cardData.FormOfPayment = new KeyBlock { Value = new KeyValue { Encoding = EncodingType.Hex, EncryptionAlgorithm = EncryptionAlgorithmType.TDES, Scheme = scheme } }; //standard api call, simply use cardData in place of creditcard type var paymentType = new paymentType { Item = cardData }; // Add line Items var lineItems = new lineItemType[2]; lineItems[0] = new lineItemType { itemId = "1", name = "t-shirt", quantity = 2, unitPrice = new Decimal(15.00) }; lineItems[1] = new lineItemType { itemId = "2", name = "snowboard", quantity = 1, unitPrice = new Decimal(450.00) }; var transactionRequest = new transactionRequestType { transactionType = transactionTypeEnum.authCaptureTransaction.ToString(), // charge the card amount = amount, payment = paymentType, lineItems = lineItems, // Retail data required for POS transactions retail = new transRetailInfoType { deviceType = "1", marketType = "2" } }; var request = new createTransactionRequest { transactionRequest = transactionRequest }; // instantiate the 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, Auth Code : " + response.transactionResponse.authCode); } else { Console.WriteLine("Failed Transaction."); if (response.transactionResponse.errors != null) { Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode); Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText); } } } else { Console.WriteLine("Failed Transaction."); if (response.transactionResponse != null && response.transactionResponse.errors != null) { Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode); Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText); } else { Console.WriteLine("Error Code: " + response.messages.message[0].code); Console.WriteLine("Error message: " + response.messages.message[0].text); } } } else { Console.WriteLine("Null Response."); } return(response); }
/// <summary> /// Process recurring payment /// </summary> /// <param name="processPaymentRequest">Payment info required for an order processing</param> /// <returns>Process payment result</returns> public ProcessPaymentResult ProcessRecurringPayment(ProcessPaymentRequest processPaymentRequest) { var result = new ProcessPaymentResult(); var customer = _customerService.GetCustomerById(processPaymentRequest.CustomerId); PrepareAuthorizeNet(); var creditCard = new creditCardType { cardNumber = processPaymentRequest.CreditCardNumber, expirationDate = processPaymentRequest.CreditCardExpireMonth.ToString("D2") + processPaymentRequest.CreditCardExpireYear, cardCode = processPaymentRequest.CreditCardCvv2 }; //standard api call to retrieve response var paymentType = new paymentType { Item = creditCard }; var billTo = new nameAndAddressType { firstName = customer.BillingAddress.FirstName, lastName = customer.BillingAddress.LastName, //email = customer.BillingAddress.Email, address = customer.BillingAddress.Address1, //address = customer.BillingAddress.Address1 + " " + customer.BillingAddress.Address2; city = customer.BillingAddress.City, zip = customer.BillingAddress.ZipPostalCode }; if (!string.IsNullOrEmpty(customer.BillingAddress.Company)) { billTo.company = customer.BillingAddress.Company; } if (customer.BillingAddress.StateProvince != null) { billTo.state = customer.BillingAddress.StateProvince.Abbreviation; } if (customer.BillingAddress.Country != null) { billTo.country = customer.BillingAddress.Country.TwoLetterIsoCode; } var dtNow = DateTime.UtcNow; // Interval can't be updated once a subscription is created. var paymentScheduleInterval = new paymentScheduleTypeInterval(); switch (processPaymentRequest.RecurringCyclePeriod) { case RecurringProductCyclePeriod.Days: paymentScheduleInterval.length = Convert.ToInt16(processPaymentRequest.RecurringCycleLength); paymentScheduleInterval.unit = ARBSubscriptionUnitEnum.days; break; case RecurringProductCyclePeriod.Weeks: paymentScheduleInterval.length = Convert.ToInt16(processPaymentRequest.RecurringCycleLength * 7); paymentScheduleInterval.unit = ARBSubscriptionUnitEnum.days; break; case RecurringProductCyclePeriod.Months: paymentScheduleInterval.length = Convert.ToInt16(processPaymentRequest.RecurringCycleLength); paymentScheduleInterval.unit = ARBSubscriptionUnitEnum.months; break; case RecurringProductCyclePeriod.Years: paymentScheduleInterval.length = Convert.ToInt16(processPaymentRequest.RecurringCycleLength * 12); paymentScheduleInterval.unit = ARBSubscriptionUnitEnum.months; break; default: throw new NopException("Not supported cycle period"); } var paymentSchedule = new paymentScheduleType { startDate = new DateTime(dtNow.Year, dtNow.Month, dtNow.Day), totalOccurrences = Convert.ToInt16(processPaymentRequest.RecurringTotalCycles), interval = paymentScheduleInterval }; var subscriptionType = new ARBSubscriptionType { name = processPaymentRequest.OrderGuid.ToString(), amount = Math.Round(processPaymentRequest.OrderTotal, 2), payment = paymentType, billTo = billTo, paymentSchedule = paymentSchedule, customer = new customerType { email = customer.BillingAddress.Email //phone number should be in one of following formats: 111- 111-1111 or (111) 111-1111. //phoneNumber = customer.BillingAddress.PhoneNumber }, order = new orderType { //x_invoice_num is 20 chars maximum. hece we also pass x_description invoiceNumber = processPaymentRequest.OrderGuid.ToString().Substring(0, 20), description = String.Format("Recurring payment #{0}", processPaymentRequest.OrderGuid) } }; if (customer.ShippingAddress != null) { var shipTo = new nameAndAddressType { firstName = customer.ShippingAddress.FirstName, lastName = customer.ShippingAddress.LastName, address = customer.ShippingAddress.Address1, city = customer.ShippingAddress.City, zip = customer.ShippingAddress.ZipPostalCode }; if (customer.ShippingAddress.StateProvince != null) { shipTo.state = customer.ShippingAddress.StateProvince.Abbreviation; } subscriptionType.shipTo = shipTo; } var request = new ARBCreateSubscriptionRequest { subscription = subscriptionType }; // instantiate the contoller that will call the service var controller = new ARBCreateSubscriptionController(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) { result.SubscriptionTransactionId = response.subscriptionId; result.AuthorizationTransactionCode = response.refId; result.AuthorizationTransactionResult = string.Format("Approved ({0}: {1})", response.refId, response.subscriptionId); } else if (response != null) { foreach (var responseMessage in response.messages.message) { result.AddError(string.Format("Error processing recurring payment #{0}: {1}", responseMessage.code, responseMessage.text)); } } else { result.AddError("Authorize.NET unknown error"); } return(result); }
public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, decimal amount) { ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.SANDBOX; //ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNet.Environment.PRODUCTION; // define the merchant information (authentication / transaction id) ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType() { name = ApiLoginID, ItemElementName = ItemChoiceType.transactionKey, Item = ApiTransactionKey, }; ; creditCardType creditCard; creditCard = LouACH.EventReceipt.creditCard; customerAddressType billingAddress; billingAddress = LouACH.EventReceipt.customerAddress; //standard api call to retrieve response var paymentType = new paymentType { Item = creditCard }; var lineItems = new lineItemType[1]; lineItems[0] = LouACH.EventReceipt.lineItems; var transactionRequest = new transactionRequestType { transactionType = transactionTypeEnum.authCaptureTransaction.ToString(), // charge the card amount = amount, payment = paymentType, billTo = billingAddress, lineItems = lineItems }; var request = new createTransactionRequest { transactionRequest = transactionRequest }; // instantiate the contoller that will call the service System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12; 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) { LouACH.EventReceipt.TransactionMessage = response.transactionResponse.messages[0].description + "(Transaction ID: " + response.transactionResponse.transId + ")"; // if (Account=="1") // {LouACH.EventReceipt.TransactionCode1 = response.transactionResponse.transId; // LouACH.EventReceipt.TransactionMessage1 = "Guest Reservation: $200" + response.transactionResponse.messages[0].description + "(Transaction ID: " + response.transactionResponse.transId + ")"; // } // else if (Account == "2") // { // LouACH.EventReceipt.TransactionCode2 = response.transactionResponse.transId; // LouACH.EventReceipt.TransactionMessage2 = "PIASC Donation: " + amount.ToString("C") + response.transactionResponse.messages[0].description + "(Transaction ID: " + response.transactionResponse.transId + ")"; // } // else if (Account == "3") // { // LouACH.EventReceipt.TransactionCode3 = response.transactionResponse.transId; // LouACH.EventReceipt.TransactionMessage3 = "IPM Donation: " + amount.ToString("C") + response.transactionResponse.messages[0].description + "(Transaction ID: " + response.transactionResponse.transId + ")"; // } // else if (Account == "4") // { // LouACH.EventReceipt.TransactionCode4 = response.transactionResponse.transId; // LouACH.EventReceipt.TransactionMessage4 = "PPAC Donation: " + amount.ToString("C") + response.transactionResponse.messages[0].description + "(Transaction ID: " + response.transactionResponse.transId + ")"; // } //} //else //{ //LouACH.EventMakePayment.sOutput = "Failed Transaction."; if (response.transactionResponse.errors != null) { LouACH.EventReceipt.TransactionMessage = "Failed Transaction"; } } } else { 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); LouACH.EventReceipt.TransactionMessage = "Transaction Error: " + response.transactionResponse.errors[0].errorText; } else { //Console.WriteLine("Error Code: " + response.messages.message[0].code); //Console.WriteLine("Error message: " + "Error Code: " + response.messages.message[0].Text); LouACH.EventReceipt.TransactionMessage = "Transaction Error: " + response.transactionResponse.errors[0].errorText; } } } else { //Console.WriteLine("Null Response."); LouACH.EventReceipt.TransactionMessage = "Transaction Error: No Response"; } return(response); }
public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, decimal amount) { Console.WriteLine("Charge Credit Card Sample"); ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.SANDBOX; // define the merchant information (authentication / transaction id) ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType() { name = ApiLoginID, ItemElementName = ItemChoiceType.transactionKey, Item = ApiTransactionKey, }; var creditCard = new creditCardType { cardNumber = "4111111111111111", expirationDate = "0718", cardCode = "123" }; var billingAddress = new customerAddressType { firstName = "John", lastName = "Doe", address = "123 My St", city = "OurTown", zip = "98004" }; //standard api call to retrieve response var paymentType = new paymentType { Item = creditCard }; // Add line Items var lineItems = new lineItemType[2]; lineItems[0] = new lineItemType { itemId = "1", name = "t-shirt", quantity = 2, unitPrice = new Decimal(15.00) }; lineItems[1] = new lineItemType { itemId = "2", name = "snowboard", quantity = 1, unitPrice = new Decimal(450.00) }; var transactionRequest = new transactionRequestType { transactionType = transactionTypeEnum.authCaptureTransaction.ToString(), // charge the card amount = amount, payment = paymentType, billTo = billingAddress, lineItems = lineItems }; 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, Auth Code : " + response.transactionResponse.authCode); } else { Console.WriteLine("Failed Transaction."); if (response.transactionResponse.errors != null) { Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode); Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText); } } } else { Console.WriteLine("Failed Transaction."); if (response.transactionResponse != null && response.transactionResponse.errors != null) { Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode); Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText); } else { Console.WriteLine("Error Code: " + response.messages.message[0].code); Console.WriteLine("Error message: " + response.messages.message[0].text); } } } else { Console.WriteLine("Null Response."); } return(response); }
public static void 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 TransactionID, string PayerID) //{ // Console.WriteLine("PayPal Authorize Capture-Continue Transaction"); // ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNET.Environment.SANDBOX; // // define the merchant information (authentication / transaction id) // ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType() // { // name = ApiLoginID, // ItemElementName = ItemChoiceType.transactionKey, // Item = ApiTransactionKey // }; // var payPalType = new payPalType // { // cancelUrl = "http://www.merchanteCommerceSite.com/Success/TC25262", // successUrl = "http://www.merchanteCommerceSite.com/Success/TC25262", // the url where the user will be returned to // payerID = PayerID // }; // //standard api call to retrieve response // var paymentType = new paymentType { Item = payPalType }; // var transactionRequest = new transactionRequestType // { // transactionType = transactionTypeEnum.authCaptureContinueTransaction.ToString(), // capture the card only // payment = paymentType, // amount = 19.45m, // 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); // } // 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 PayPalAuthorizeCaptureContinueExec(String ApiLoginID, String ApiTransactionKey) { using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/AuthorizationAndCaptureContinue.csv", FileMode.Open)), true)) { Console.WriteLine("PayPal Authorize Capture-Continue Transaction"); int flag = 0; int fieldCount = csv.FieldCount; string[] headers = csv.GetFieldHeaders(); //Append Data var item1 = DataAppend.ReadPrevData(); using (CsvFileWriter writer = new CsvFileWriter(new FileStream(@"../../../CSV_DATA/Outputfile.csv", FileMode.Open))) { while (csv.ReadNextRecord()) { // Create Instance of Customer Api ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNET.Environment.SANDBOX; // define the merchant information (authentication / transaction id) ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType() { name = ApiLoginID, ItemElementName = ItemChoiceType.transactionKey, Item = ApiTransactionKey, }; string TestCaseId = null; string TransactionID = null; string PayerID = null; for (int i = 0; i < fieldCount; i++) { switch (headers[i]) { case "TransactionID": TransactionID = csv[i]; break; case "PayerID": PayerID = csv[i]; break; case "TestCaseId": TestCaseId = csv[i]; break; default: break; } } //Write to output file CsvRow row = new CsvRow(); try { if (flag == 0) { row.Add("TestCaseId"); row.Add("APIName"); row.Add("Status"); row.Add("TimeStamp"); writer.WriteRow(row); flag = flag + 1; //Append Data foreach (var item in item1) { writer.WriteRow(item); } } var payPalType = new payPalType { cancelUrl = "http://www.merchanteCommerceSite.com/Success/TC25262", successUrl = "http://www.merchanteCommerceSite.com/Success/TC25262", // the url where the user will be returned to payerID = PayerID }; //standard api call to retrieve response var paymentType = new paymentType { Item = payPalType }; var transactionRequest = new transactionRequestType { transactionType = transactionTypeEnum.authCaptureContinueTransaction.ToString(), // capture the card only payment = paymentType, amount = 19.45m, 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(); if (response != null && response.messages.resultCode == messageTypeEnum.Ok && response.transactionResponse.messages != null) { try { //Assert.AreEqual(response.Id, customerProfileId); Console.WriteLine("Assertion Succeed! Valid CustomerId fetched."); CsvRow row1 = new CsvRow(); row1.Add("AACC_00" + flag.ToString()); row1.Add("AuthorizationAndCaptureContinue"); row1.Add("Pass"); row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff")); writer.WriteRow(row1); // Console.WriteLine("Success " + TestcaseID + " CustomerID : " + response.Id); flag = flag + 1; Console.WriteLine("Successfully created transaction with Transaction ID: " + response.transactionResponse.transId); Console.WriteLine("Response Code: " + response.transactionResponse.responseCode); Console.WriteLine("Message Code: " + response.transactionResponse.messages[0].code); Console.WriteLine("Description: " + response.transactionResponse.messages[0].description); } catch { CsvRow row1 = new CsvRow(); row1.Add("AACC_00" + flag.ToString()); row1.Add("AuthorizationAndCaptureContinue"); 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("AACC_00" + flag.ToString()); row1.Add("AuthorizationAndCaptureContinue"); row1.Add("Fail"); row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff")); writer.WriteRow(row1); //Console.WriteLine("Assertion Failed! Invalid CustomerId fetched."); flag = flag + 1; } } catch (Exception e) { CsvRow row2 = new CsvRow(); row2.Add("AACC_00" + flag.ToString()); row2.Add("AuthorizationAndCaptureContinue"); 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 refund() { 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 = ChargeCreditCard.iDcode }; 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.messages.resultCode == messageTypeEnum.Ok) { if (response.transactionResponse != null) { Debug.WriteLine("Success, Got refund : " + response.transactionResponse.transId); } } else { Console.WriteLine("Error: " + response.messages.message[0].code + " " + response.messages.message[0].text); if (response.transactionResponse != null) { Debug.WriteLine("Transaction did not get refund : " + response.transactionResponse.errors[0].errorCode + " " + response.transactionResponse.errors[0].errorText); } } }
public static ANetApiResponse Run( creditCardType creditCard, customerAddressType billingAddress, List <lineItemType> lineItems, decimal amount) { ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.SANDBOX; ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType() { name = "4r3yN5eZ7F", ItemElementName = ItemChoiceType.transactionKey, Item = "5Q226P5BjUw97nSN", }; /* * * var creditCard = new creditCardType * { * cardNumber = "4111111111111115", * expirationDate = "1028", * cardCode = "123" * }; * * var billingAddress = new customerAddressType * { * firstName = "John", * lastName = "Doe", * address = "123 My St", * city = "OurTown", * zip = "98004" * }; */ //standard api call to retrieve response var paymentType = new paymentType { Item = creditCard }; // Add line Items //var lineItems = new lineItemType[2]; //lineItems[0] = new lineItemType { itemId = "1", name = "t-shirt", quantity = 2, unitPrice = new Decimal(15.00) }; //lineItems[1] = new lineItemType { itemId = "2", name = "snowboard", quantity = 1, unitPrice = new Decimal(450.00) }; var transactionRequest = new transactionRequestType { transactionType = transactionTypeEnum.authCaptureTransaction.ToString(), amount = amount, payment = paymentType, billTo = billingAddress, lineItems = lineItems.ToArray() }; var request = new createTransactionRequest { transactionRequest = transactionRequest }; var controller = new createTransactionController(request); controller.Execute(); var response = controller.GetApiResponse(); return(response); }
public string Run(CheckoutViewModel cvm) { ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.SANDBOX; ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType() { name = _configuration["AuthNetAPILogin"], ItemElementName = ItemChoiceType.transactionKey, Item = _configuration["AuthNetTransactionKey"] }; var creditCard = new creditCardType { cardNumber = cvm.CC, expirationDate = cvm.ExpirationDateMonth + cvm.ExpirationDateYear }; paymentType paymentType = new paymentType { Item = creditCard }; customerAddressType billingAddress = new customerAddressType { address = cvm.Address, city = cvm.City, state = cvm.State, zip = cvm.ZipCode.ToString() }; transactionRequestType transactionRequest = new transactionRequestType { transactionType = transactionTypeEnum.authCaptureTransaction.ToString(), amount = cvm.Total, payment = paymentType, billTo = billingAddress }; createTransactionRequest request = new createTransactionRequest { transactionRequest = transactionRequest }; var controller = new createTransactionController(request); controller.Execute(); var response = controller.GetApiResponse(); if (response.messages.resultCode == messageTypeEnum.Ok) { if (response.transactionResponse != null) { return("Payment Successful"); } } else { Console.WriteLine("Error: " + response.messages.message[0].code + " " + response.messages.message[0].text); if (response.transactionResponse.errors != null) { Console.WriteLine("Transaction Error : " + response.transactionResponse.errors[0].errorCode + " " + response.transactionResponse.errors[0].errorText); } } return("Payment error!"); }