static void Main(string[] args) { //Call Rent calculation SP log4net.ILog log = log4net.LogManager.GetLogger(typeof(BGBC.Schedule.Program)); try { BGBC.Model.BGBCFunctions.RentCalcSchedule(DateTime.Today.Date); log.Info("Executed for " + DateTime.Today.Date); } catch (Exception ex) { log.Error(ex.Message); } IRepository <RentAutoPay, int> rentAutoRepo = new RentAutoPayRepository(); IRepository <RentDue, int?> rentDueRepo = new RentDueRepository(); try { IEnumerable <RentAutoPay> listRentPay = listRentPay = rentAutoRepo.Get(); foreach (var rentPayitem in listRentPay) { RentDue rentDue = rentDueRepo.Get().Where(x => x.UserID == rentPayitem.UserID && x.DueStatus == true).FirstOrDefault(); if (rentDue != null) { try { User user = rentDue.User; Profile profile = rentDue.User.Profiles.FirstOrDefault(); var lineItems = new AuthorizeNet.Api.Contracts.V1.lineItemType[2]; int[] rentidsarry = new int[2]; string fee = "Service Fee(10.75%)"; lineItems[0] = new AuthorizeNet.Api.Contracts.V1.lineItemType { itemId = "1", name = (rentDue.Description.Length < 30) ? rentDue.Description : rentDue.Description.Substring(0, 30), quantity = 1, unitPrice = rentDue.DueAmount }; lineItems[1] = new AuthorizeNet.Api.Contracts.V1.lineItemType { itemId = "1", name = (fee.Length < 30) ? fee : fee.Substring(0, 30), quantity = 1, unitPrice = rentPayitem.Charges }; int invoiceNumber = BGBCFunctions.GetInoiveNo(); AuthorizeNet.Api.Controllers.createTransactionController controller; var billAddress = new AuthorizeNet.Api.Contracts.V1.customerAddressType { firstName = user.FirstName, lastName = user.LastName, address = profile.BillingAddress + ", " + (string.IsNullOrEmpty(profile.BillingAddress_2) ? "" : profile.BillingAddress_2), city = profile.BillingCty, state = profile.BillingState, zip = profile.BillingZip, email = user.Email, phoneNumber = profile.MobilePhone, country = "USA" }; string address = string.Format("{0}<br/>{1}<br/>{2}, {3} {4}", profile.BillingAddress, profile.BillingAddress_2, profile.BillingCty, profile.BillingState, profile.BillingZip); if (rentPayitem.PaymentType == 2) { var bankAccount = new AuthorizeNet.Api.Contracts.V1.bankAccountType { accountNumber = rentPayitem.AccountNo, routingNumber = rentPayitem.RoutingNo, echeckType = AuthorizeNet.Api.Contracts.V1.echeckTypeEnum.WEB, // change based on how you take the payment (web, telephone, etc) nameOnAccount = user.FirstName + " " + user.LastName }; controller = PaymentGateway.DebitBankAccount(bankAccount, lineItems, billAddress, rentPayitem.TotalAmt, invoiceNumber); } else { var creditCard = new AuthorizeNet.Api.Contracts.V1.creditCardType { cardNumber = rentPayitem.CCNO, expirationDate = rentPayitem.ExpMon + rentPayitem.ExpYear.ToString(), cardCode = rentPayitem.CVV }; controller = PaymentGateway.ChargeCreditCard(creditCard, lineItems, billAddress, rentPayitem.TotalAmt, invoiceNumber); } AuthorizeNet.Api.Contracts.V1.createTransactionResponse response = controller.GetApiResponse(); if (response != null) { if (response.messages.resultCode == AuthorizeNet.Api.Contracts.V1.messageTypeEnum.Ok) { if (response.transactionResponse != null) { if (response.transactionResponse.errors == null) { try { string rentid = string.Join(",", rentidsarry); Payment pay = BGBCFunctions.RentPayment(user.UserID, invoiceNumber, response.transactionResponse.accountNumber, response.transactionResponse.accountType, response.transactionResponse.transId, response.transactionResponse.messages[0].code, response.transactionResponse.messages[0].description, "", rentPayitem.TotalAmt, address, "Auto rent pay", rentDue.RentDueID.ToString()); IRepository <RentPayment, int> rentPay = new RentPaymentRepository(); rentPay.Add(new RentPayment { PropertyID = rentDue.PropertyID, Description = fee, Amount = rentPayitem.Charges, PaymentID = pay.PaymentID }); } catch (Exception ex) { Console.WriteLine("Transaction Error : " + ex.Message); } System.Diagnostics.Trace.TraceInformation("Success, Auth Code : " + response.transactionResponse.authCode); } else { Console.WriteLine("Transaction Error : " + response.transactionResponse.errors[0].errorCode + " " + response.transactionResponse.errors[0].errorText); } } } else { System.Diagnostics.Trace.TraceInformation("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); } } } else { Console.WriteLine("Transaction Error, unable to complete the transaction."); } } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine("Transaction Error, unable to complete the transaction."); } } } } catch (Exception ex) { throw; } }
public ActionResult Transaction() { Models.Checkout checkout = new Models.Checkout(); try { checkout = (Models.Checkout)TempData["cartdata"]; var lineItems = new AuthorizeNet.Api.Contracts.V1.lineItemType[checkout.OrderList.Count]; for (int i = 0; i < checkout.OrderList.Count; i++) { lineItems[i] = new AuthorizeNet.Api.Contracts.V1.lineItemType { itemId = i.ToString(), name = (checkout.OrderList[i].Item.Length < 10) ? checkout.OrderList[i].Item : checkout.OrderList[i].Item.Substring(0, 10), quantity = checkout.OrderList[i].Quantity, unitPrice = checkout.OrderList[i].Subtotal }; } int invoiceNumber = BGBCFunctions.GetInoiveNo(); AuthorizeNet.Api.Controllers.createTransactionController controller; var billAddress = new AuthorizeNet.Api.Contracts.V1.customerAddressType { firstName = checkout.FirstName, lastName = checkout.LastName, address = checkout.BillingAddress + ", " + (string.IsNullOrEmpty(checkout.BillingAddress_2) ? "" : checkout.BillingAddress_2), city = checkout.BillingCty, state = checkout.BillingState, zip = checkout.BillingZip, email = checkout.Email, phoneNumber = checkout.Phone, country = "USA" }; string address = string.Format("{0}<br/>{1}<br/>{2}, {3} {4}", checkout.BillingAddress, checkout.BillingAddress_2, checkout.BillingCty, checkout.BillingState, checkout.BillingZip); if (checkout.PaymentMethod == "eCheck") { var bankAccount = new AuthorizeNet.Api.Contracts.V1.bankAccountType { accountNumber = checkout.BankAccountNumber, routingNumber = checkout.BankRoutingNumber, echeckType = AuthorizeNet.Api.Contracts.V1.echeckTypeEnum.WEB, // change based on how you take the payment (web, telephone, etc) nameOnAccount = checkout.FirstName + " " + checkout.LastName }; controller = PaymentGateway.DebitBankAccount(bankAccount, lineItems, billAddress, checkout.OrderTotal, invoiceNumber); } else { var creditCard = new AuthorizeNet.Api.Contracts.V1.creditCardType { cardNumber = checkout.CardNo, expirationDate = checkout.CardExpMon + checkout.CardExpYear.ToString(), cardCode = checkout.CVV }; controller = PaymentGateway.ChargeCreditCard(creditCard, lineItems, billAddress, checkout.OrderTotal, invoiceNumber); } AuthorizeNet.Api.Contracts.V1.createTransactionResponse response = controller.GetApiResponse(); if (response != null) { if (response.messages.resultCode == AuthorizeNet.Api.Contracts.V1.messageTypeEnum.Ok) { if (response.transactionResponse != null) { if (response.transactionResponse.errors == null) { try { int userid = 0; if (!Request.IsAuthenticated) { User selUser = new User { FirstName = checkout.FirstName, LastName = checkout.LastName, Password = BGBC.Core.Security.Cryptography.Encrypt(checkout.ChoosePassword), UserType = 3, Email = checkout.Email }; selUser.Profiles.Add(new Profile { BillingAddress = checkout.BillingAddress, BillingAddress_2 = checkout.BillingAddress_2, BillingCty = checkout.BillingCty, BillingState = checkout.BillingState, MobilePhone = checkout.Phone }); selUser = _userRepository.Add(selUser); CustomPrincipalSerializeModel serializeModel = new CustomPrincipalSerializeModel(); serializeModel.UserId = selUser.UserID; serializeModel.FirstName = selUser.FirstName; serializeModel.LastName = selUser.LastName; serializeModel.roles = new string[] { "Customer" }; string userData = Newtonsoft.Json.JsonConvert.SerializeObject(serializeModel); System.Web.Security.FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, selUser.FirstName, DateTime.Now, DateTime.Now.AddMinutes(15), false, userData); string encTicket = FormsAuthentication.Encrypt(authTicket); HttpCookie faCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket); Response.Cookies.Add(faCookie); userid = selUser.UserID; } else { userid = ((BGBC.Core.CustomPrincipal)(User)).UserId; } Order order = BGBCFunctions.ProductTrans(userid, checkout.Email, checkout.ChoosePassword, invoiceNumber, response.transactionResponse.accountNumber, response.transactionResponse.accountType, response.transactionResponse.transId, response.transactionResponse.messages[0].code, response.transactionResponse.messages[0].description, Request.UserHostAddress, address, checkout.Comments, checkout.ProductIds); IRepository <ProductOrder, int> productOrder = new ProductOrderRepository(); foreach (var item in checkout.OrderList.Where(x => x.ProductID == 0)) { productOrder.Add(new ProductOrder { OrderID = order.OrderID, Name = item.Item, Price = item.Price }); } //Save Payment details if (checkout.SaveCard) { UserCC ccinfo = _userCCRep.Get(userid); if (ccinfo == null) //There is no details in database { if (checkout.PaymentMethod == "eCheck") { _userCCRep.Add(new UserCC { UserID = userid, PaymentType = 2, AccountType = checkout.BankAccountType, RoutingNo = Cryptography.Encrypt(checkout.BankRoutingNumber), AccountNo = Cryptography.Encrypt(checkout.BankAccountNumber) }); } else { _userCCRep.Add(new UserCC { UserID = userid, PaymentType = 1, CCNO = Cryptography.Encrypt(checkout.CardNo), ExpMon = Cryptography.Encrypt(checkout.CardExpMon), ExpYear = Cryptography.Encrypt(checkout.CardExpYear) }); } } else { if (checkout.PaymentMethod == "eCheck") { ccinfo.CCNO = string.Empty; ccinfo.ExpMon = string.Empty; ccinfo.ExpYear = string.Empty; ccinfo.PaymentType = 2; ccinfo.AccountType = checkout.BankAccountType; ccinfo.RoutingNo = Cryptography.Encrypt(checkout.BankRoutingNumber); ccinfo.AccountNo = Cryptography.Encrypt(checkout.BankAccountNumber); } else { ccinfo.CCNO = Cryptography.Encrypt(checkout.CardNo); ccinfo.ExpMon = Cryptography.Encrypt(checkout.CardExpMon); ccinfo.ExpYear = Cryptography.Encrypt(checkout.CardExpYear); ccinfo.PaymentType = 1; ccinfo.AccountType = string.Empty; ccinfo.RoutingNo = string.Empty; ccinfo.AccountNo = string.Empty; } } } else { UserCC ccinfo = _userCCRep.Get(userid); if (ccinfo != null) { _userCCRep.Remove(ccinfo); } } HttpCookie authCookie = Request.Cookies[".BGBCProducts"]; authCookie.Value = string.Empty; Response.SetCookie(authCookie); TempData.Remove("cartdata"); return(RedirectToAction("OrderHistory", "Report")); } catch (Exception ex) { log.Error(ex.Message); ModelState.AddModelError("", "Transaction Error : " + ex.Message); } System.Diagnostics.Trace.TraceInformation("Success, Auth Code : " + response.transactionResponse.authCode); } else { ModelState.AddModelError("", "Transaction Error : " + response.transactionResponse.errors[0].errorCode + " " + response.transactionResponse.errors[0].errorText); } } } else { System.Diagnostics.Trace.TraceInformation("Error: " + response.messages.message[0].code + " " + response.messages.message[0].text); if (response.transactionResponse != null) { ModelState.AddModelError("", "Transaction Error : " + response.transactionResponse.errors[0].errorCode + " " + response.transactionResponse.errors[0].errorText); } TempData["cartdata"] = checkout; } } else { TempData["cartdata"] = checkout; ModelState.AddModelError("", "Transaction Error, unable to complete the transaction."); } } catch (Exception ex) { log.Error(ex.Message); ModelState.AddModelError("", "Transaction Error, unable to complete the transaction."); } Tuple <List <Models.OrderSummary>, decimal, string> ordersummary = getCartProducts(); checkout.OrderList = ordersummary.Item1; checkout.OrderTotal = ordersummary.Item2; checkout.ProductIds = ordersummary.Item3; checkoutDropDown(); return(View("Checkout", checkout)); }