public ANetApiResponse GetTransactionDetails(string transactionId) { ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.SANDBOX; // define the merchant information (authentication / transaction id) ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType() { name = "35WkY7AsU", ItemElementName = ItemChoiceType.transactionKey, Item = "85T8Hsv4JMu76P5b" }; var request = new getTransactionDetailsRequest(); request.transId = transactionId; // instantiate the controller that will call the service var controller = new getTransactionDetailsController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); return(response); }
public override string GetCartNumber(HttpRequest request, IDictionary <string, string> settings) { string cartNumber = ""; try { request.MustNotBeNull("request"); settings.MustNotBeNull("settings"); settings.MustContainKey("mode", "settings"); settings.MustContainKey(settings["mode"] + "_api_login_id", "settings"); settings.MustContainKey(settings["mode"] + "_transaction_key", "settings"); settings.MustContainKey(settings["mode"] + "_signature_key", "settings"); // Write data when testing if (settings.ContainsKey("mode") && settings["mode"] == "sandbox") { LogRequest <AuthorizeNet>(request, logPostData: true); } var authorizeNetEvent = GetValidatedWebhookEvent(settings[settings["mode"] + "_signature_key"]); if (authorizeNetEvent != null && authorizeNetEvent.eventType.StartsWith("net.authorize.payment.")) { var paymentPayload = authorizeNetEvent.payload.ToObject <AuthorizeNetWebhookPaymentPayload>(); if (paymentPayload != null && paymentPayload.entityName == "transaction") { var transactionId = paymentPayload.id; // Configure AuthorizeNet ConfigureAuthorizeNet(settings); // Fetch the transaction var transactionRequest = new getTransactionDetailsRequest { transId = transactionId }; var controller = new getTransactionDetailsController(transactionRequest); controller.Execute(); var transactionResponse = controller.GetApiResponse(); if (transactionResponse != null && transactionResponse.messages.resultCode == messageTypeEnum.Ok && transactionResponse.transaction != null && transactionResponse.transaction.order != null) { // Stash the transaction authorizeNetEvent.transaction = transactionResponse.transaction; // Get the cart number cartNumber = transactionResponse.transaction.order.invoiceNumber; } } } } catch (Exception exp) { LoggingService.Instance.Error <AuthorizeNet>("Authorize.net - GetCartNumber", exp); } return(cartNumber); }
public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, string transactionId) { Console.WriteLine("Get transaction details sample"); ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.SANDBOX; // define the merchant information (authentication / transaction id) ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType() { name = ApiLoginID, ItemElementName = ItemChoiceType.transactionKey, Item = ApiTransactionKey, }; var request = new getTransactionDetailsRequest(); request.transId = transactionId; request.refId = "123123"; // instantiate the controller that will call the service var controller = new getTransactionDetailsController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); if (response != null && response.messages.resultCode == messageTypeEnum.Ok) { if (response.transaction == null) { return(response); } Console.WriteLine("Transaction Id: {0}", response.transaction.transId); Console.WriteLine("Transaction type: {0}", response.transaction.transactionType); Console.WriteLine("Transaction status: {0}", response.transaction.transactionStatus); Console.WriteLine("Transaction auth amount: {0}", response.transaction.authAmount); Console.WriteLine("Transaction settle amount: {0}", response.transaction.settleAmount); Console.WriteLine("Transaction order invoice#: {0}", response.transaction.order.invoiceNumber); Console.WriteLine("Transaction Status {0}", response.transaction.transactionStatus); } else if (response != null) { Console.WriteLine("Error: " + response.messages.message[0].code + " " + response.messages.message[0].text); } return(response); }
public static String Run(String AccessToken, string transactionId) { Console.WriteLine("Get transaction details sample"); ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.SANDBOX; // define the merchant information (authentication / transaction id) ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType() { ItemElementName = ItemChoiceType.accessToken, Item = AccessToken }; var request = new getTransactionDetailsRequest(); request.transId = transactionId; // instantiate the controller that will call the service var controller = new getTransactionDetailsController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); StringBuilder toReturn = new StringBuilder(); if (response != null && response.messages.resultCode == messageTypeEnum.Ok) { if (response.transaction == null) { return("response transaction was null"); } toReturn.AppendLine("Transaction Id: " + response.transaction.transId); toReturn.AppendLine("Transaction type: " + response.transaction.transactionType); toReturn.AppendLine("Transaction status: " + response.transaction.transactionStatus); toReturn.AppendLine("Transaction auth amount: " + response.transaction.authAmount); toReturn.AppendLine("Transaction settle amount: " + response.transaction.settleAmount); } else if (response != null) { toReturn.AppendLine("Error: " + response.messages.message[0].code + " " + response.messages.message[0].text); } return(toReturn.ToString()); }
protected virtual TransactionDetails GetTransactionDetails(string transactionId) { PrepareAuthorizeNet(); var request = new getTransactionDetailsRequest { transId = transactionId }; // instantiate the controller that will call the service var controller = new getTransactionDetailsController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); if (response?.messages == null) { _logger.Error($"Authorize.NET unknown error (transactionId: {transactionId})"); return(new TransactionDetails { IsOk = false }); } var transactionDetails = new TransactionDetails { IsOk = response.messages.resultCode == messageTypeEnum.Ok, Message = response.messages.message.FirstOrDefault() }; if (response.transaction == null) { _logger.Error($"Authorize.NET: Transaction data is missing (transactionId: {transactionId})"); } else { transactionDetails.TransactionStatus = response.transaction.transactionStatus; transactionDetails.OrderDescriptions = response.transaction.order.description.Split('#'); transactionDetails.TransactionType = response.transaction.transactionType; } return(transactionDetails); }
public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, string transactionId) { Console.WriteLine("Get transaction details sample"); ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNet.Environment.SANDBOX; // define the merchant information (authentication / transaction id) ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType() { name = ApiLoginID, ItemElementName = ItemChoiceType.transactionKey, Item = ApiTransactionKey, }; var request = new getTransactionDetailsRequest(); request.transId = transactionId; // instantiate the controller that will call the service var controller = new getTransactionDetailsController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); if (response != null && response.messages.resultCode == messageTypeEnum.Ok) { if (response.transaction == null) return response; Console.WriteLine("Transaction Id: {0}", response.transaction.transId); Console.WriteLine("Transaction type: {0}", response.transaction.transactionType); Console.WriteLine("Transaction status: {0}", response.transaction.transactionStatus); Console.WriteLine("Transaction auth amount: {0}", response.transaction.authAmount); Console.WriteLine("Transaction settle amount: {0}", response.transaction.settleAmount); } else if (response != null) { Console.WriteLine("Error: " + response.messages.message[0].code + " " + response.messages.message[0].text); } return response; }
public override ApiInfo GetStatus(Order order, IDictionary <string, string> settings) { ApiInfo apiInfo = null; try { order.MustNotBeNull("order"); settings.MustNotBeNull("settings"); settings.MustContainKey("mode", "settings"); settings.MustContainKey(settings["mode"] + "_api_login_id", "settings"); settings.MustContainKey(settings["mode"] + "_transaction_key", "settings"); // Configure AuthorizeNet ConfigureAuthorizeNet(settings); // Fetch the transaction var transactionRequest = new getTransactionDetailsRequest { transId = order.TransactionInformation.TransactionId }; var controller = new getTransactionDetailsController(transactionRequest); controller.Execute(); var transactionResponse = controller.GetApiResponse(); if (transactionResponse != null && transactionResponse.messages.resultCode == messageTypeEnum.Ok && transactionResponse.transaction != null) { var paymentState = GetPaymentStateFromTransaction(transactionResponse.transaction); apiInfo = new ApiInfo(transactionResponse.transaction.transId, paymentState); } } catch (Exception exp) { LoggingService.Instance.Error <AuthorizeNet>("Authorize.net(" + order.OrderNumber + ") - GetStatus", exp); } return(apiInfo); }
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 CreateCreditRequestForSettledECheckTransaction() { 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 eCheck 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(); 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); }
/// <summary> /// Process recurring payment /// </summary> /// <param name="transactionId">AuthorizeNet transaction ID</param> public void ProcessRecurringPayment(string transactionId) { PrepareAuthorizeNet(); var request = new getTransactionDetailsRequest { transId = transactionId }; // instantiate the controller that will call the service var controller = new getTransactionDetailsController(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) { var transaction = response.transaction; if (transaction == null) { _logger.Error(String.Format("Authorize.NET: Transaction data is missing (transactionId: {0})", transactionId)); return; } if (transaction.transactionStatus == "refundTransaction") { return; } var orderDescriptions = transaction.order.description.Split('#'); if (orderDescriptions.Length < 2) { _logger.Error(String.Format("Authorize.NET: Missing order GUID (transactionId: {0})", transactionId)); return; } var order = _orderService.GetOrderByGuid(new Guid(orderDescriptions[1])); if (order == null) { _logger.Error(String.Format("Authorize.NET: Order cannot be loaded (order GUID: {0})", orderDescriptions[1])); return; } var recurringPayments = _orderService.SearchRecurringPayments(initialOrderId: order.Id); foreach (var rp in recurringPayments) { var recurringPaymentHistory = rp.RecurringPaymentHistory; var orders = _orderService.GetOrdersByIds(recurringPaymentHistory.Select(rph => rph.OrderId).ToArray()).ToList(); var transactionsIds = new List <string>(); transactionsIds.AddRange(orders.Select(o => o.AuthorizationTransactionId).Where(tId => !string.IsNullOrEmpty(tId))); transactionsIds.AddRange(orders.Select(o => o.CaptureTransactionId).Where(tId => !string.IsNullOrEmpty(tId))); //skip the re-processing of transactions if (transactionsIds.Contains(transactionId)) { continue; } var newPaymentStatus = transaction.transactionType == "authOnlyTransaction" ? PaymentStatus.Authorized : PaymentStatus.Paid; if (recurringPaymentHistory.Count == 0) { //first payment var rph = new RecurringPaymentHistory { RecurringPaymentId = rp.Id, OrderId = order.Id, CreatedOnUtc = DateTime.UtcNow }; rp.RecurringPaymentHistory.Add(rph); if (newPaymentStatus == PaymentStatus.Authorized) { rp.InitialOrder.AuthorizationTransactionId = transactionId; } else { rp.InitialOrder.CaptureTransactionId = transactionId; } _orderService.UpdateRecurringPayment(rp); } else { //next payments var processPaymentResult = new ProcessPaymentResult(); processPaymentResult.NewPaymentStatus = newPaymentStatus; if (newPaymentStatus == PaymentStatus.Authorized) { processPaymentResult.AuthorizationTransactionId = transactionId; } else { processPaymentResult.CaptureTransactionId = transactionId; } _orderProcessingService.ProcessNextRecurringPayment(rp, processPaymentResult); } } } else if (response != null) { _logger.Error(String.Format("Authorize.Net Error: {0} - {1} (transactionId: {2})", response.messages.message[0].code, response.messages.message[0].text, transactionId)); } else { _logger.Error(String.Format("Authorize.NET unknown error (transactionId: {0})", transactionId)); } }
// public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, string transactionId) //{ // Console.WriteLine("Get transaction details sample"); // ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNET.Environment.SANDBOX; // // define the merchant information (authentication / transaction id) // ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType() // { // name = ApiLoginID, // ItemElementName = ItemChoiceType.transactionKey, // Item = ApiTransactionKey, // }; // var request = new getTransactionDetailsRequest(); // request.transId = transactionId; // // instantiate the controller that will call the service // var controller = new getTransactionDetailsController(request); // controller.Execute(); // // get the response from the service (errors contained if any) // var response = controller.GetApiResponse(); // if (response != null && response.messages.resultCode == messageTypeEnum.Ok) // { // if (response.transaction == null) // return response; // Console.WriteLine("Transaction Id: {0}", response.transaction.transId); // Console.WriteLine("Transaction type: {0}", response.transaction.transactionType); // Console.WriteLine("Transaction status: {0}", response.transaction.transactionStatus); // Console.WriteLine("Transaction auth amount: {0}", response.transaction.authAmount); // Console.WriteLine("Transaction settle amount: {0}", response.transaction.settleAmount); // } // else if (response != null) // { // Console.WriteLine("Error: " + response.messages.message[0].code + " " + // response.messages.message[0].text); // } // return response; //} public static void GetTransactionDetailsExec(String ApiLoginID, String ApiTransactionKey) { using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/GetTransactionDetails.csv", FileMode.Open)), true)) { Console.WriteLine("Get transaction details sample"); int flag = 0; int fieldCount = csv.FieldCount; string[] headers = csv.GetFieldHeaders(); //Append Data var item1 = DataAppend.ReadPrevData(); using (CsvFileWriter writer = new CsvFileWriter(new FileStream(@"../../../CSV_DATA/Outputfile.csv", FileMode.Open))) { while (csv.ReadNextRecord()) { ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNET.Environment.SANDBOX; // define the merchant information (authentication / transaction id) string apiLogin = null; string transactionKey = null; string TestcaseID = null; string transactionId = null; //int count = 0; for (int i = 0; i < fieldCount; i++) { // Read the headers with values from the test data input file switch (headers[i]) { case "apiLogin": apiLogin = csv[i]; break; case "transactionKey": transactionKey = csv[i]; break; case "transactionId": transactionId = csv[i]; break; case "TestcaseID": TestcaseID = csv[i]; //count++; break; default: break; } } ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType() { name = apiLogin, ItemElementName = ItemChoiceType.transactionKey, Item = transactionKey, }; CsvRow row = new CsvRow(); try { if (flag == 0) { row.Add("TestCaseId"); row.Add("APIName"); row.Add("Status"); row.Add("TimeStamp"); writer.WriteRow(row); flag = flag + 1; //Append Data foreach (var item in item1) { writer.WriteRow(item); } } var request = new getTransactionDetailsRequest(); request.transId = transactionId; // instantiate the controller that will call the service var controller = new getTransactionDetailsController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); if (response != null && response.messages.resultCode == messageTypeEnum.Ok) { /*****************************/ try { //Assert.AreEqual(response.transaction.transId, transactionId); //Console.WriteLine("Assertion Succeed! Valid TransactionDetails fetched."); CsvRow row1 = new CsvRow(); row1.Add("GTD_00" + flag.ToString()); row1.Add("GetTransactionDetails"); row1.Add("Pass"); row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff")); writer.WriteRow(row1); // Console.WriteLine("Success " + TestcaseID + " CustomerID : " + response.Id); flag = flag + 1; Console.WriteLine("Transaction Id: {0}", response.transaction.transId); Console.WriteLine("Transaction type: {0}", response.transaction.transactionType); Console.WriteLine("Transaction status: {0}", response.transaction.transactionStatus); Console.WriteLine("Transaction auth amount: {0}", response.transaction.authAmount); Console.WriteLine("Transaction settle amount: {0}", response.transaction.settleAmount); } catch { CsvRow row1 = new CsvRow(); row1.Add("GTD_00" + flag.ToString()); row1.Add("GetTransactionDetails"); 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.transaction == null) //return response; } else { Console.WriteLine("Null response"); CsvRow row2 = new CsvRow(); row2.Add("GTD_00" + flag.ToString()); row2.Add("GetTransactionDetails"); row2.Add("Fail"); row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff")); writer.WriteRow(row2); flag = flag + 1; } //else if (response != null) //{ // Console.WriteLine("Error: " + response.messages.message[0].code + " " + // response.messages.message[0].text); //} } //return response; catch (Exception e) { Console.WriteLine(e); CsvRow row2 = new CsvRow(); row2.Add("GTD_00" + flag.ToString()); row2.Add("GetTransactionDetails"); 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 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 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 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); }
/// <summary> /// Process recurring payment /// </summary> /// <param name="transactionId">AuthorizeNet transaction ID</param> public void ProcessRecurringPayment(string transactionId) { PrepareAuthorizeNet(); var request = new getTransactionDetailsRequest { transId = transactionId }; // instantiate the controller that will call the service var controller = new getTransactionDetailsController(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) { var transaction = response.transaction; if (transaction == null) { _logger.Error(String.Format("Authorize.NET: Transaction data is missing (transactionId: {0})", transactionId)); return; } if (transaction.transactionStatus != "settledSuccessfully") { return; } var orderDescriptions = transaction.order.description.Split('#'); if (orderDescriptions.Length < 2) { _logger.Error(String.Format("Authorize.NET: Missing order GUID (transactionId: {0})", transactionId)); return; } var order = _orderService.GetOrderByGuid(new Guid(orderDescriptions[1])); if (order == null) { _logger.Error(String.Format("Authorize.NET: Order cannot be loaded (order GUID: {0})", orderDescriptions[1])); return; } var recurringPayments = _orderService.SearchRecurringPayments(initialOrderId: order.Id); foreach (var rp in recurringPayments) { var recurringPaymentHistory = rp.RecurringPaymentHistory; if (recurringPaymentHistory.Count == 0) { //first payment var rph = new RecurringPaymentHistory { RecurringPaymentId = rp.Id, OrderId = order.Id, CreatedOnUtc = DateTime.UtcNow }; rp.RecurringPaymentHistory.Add(rph); _orderService.UpdateRecurringPayment(rp); } else { //next payments _orderProcessingService.ProcessNextRecurringPayment(rp); } } } else if (response != null) { _logger.Error(String.Format("Authorize.Net Error: {0} - {1} (transactionId: {2})", response.messages.message[0].code, response.messages.message[0].text, transactionId)); } else { _logger.Error(String.Format("Authorize.NET unknown error (transactionId: {0})", transactionId)); } }
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); }