public async Task <IActionResult> Details(int cardId) { CardDetailsDto card; try { card = await this.cardService.GetCardDetailsByIdAsync(cardId); } catch (ServiceException) { Response.StatusCode = 404; return(View("NotFound")); } var model = new CardInfoViewModel() { Id = card.Id, CardNumber = card.LastFourDigit, CardType = card.Type.GetDisplayName(), Cvv = card.Cvv, Expiry = card.ExpiryDate, Cardholder = card.CardholerName }; return(PartialView("_DetailsCardPartial", model)); }
public async Task <IActionResult> GetTransportCardById([FromQuery] int id) { TransportCard transportCard = await _cardService.GetTransportCardById(id); if (transportCard == null) { return(BadRequest(new { response_message = "Cannot find record with the entered transport card id. Please try again.", isError = true })); } CardInfoViewModel response = new CardInfoViewModel { CardType = _cardTypeService.GetCardTypeById(transportCard.CardTypeId).Result, CardTypeId = transportCard.CardTypeId, CreateDate = formatDateToShow(transportCard.CreateDate), DateRegistered = formatDateToShow(transportCard.DateRegistered), DiscountCardDetails = _discountCardDetailsService.GetDiscountCardDetailsById(id).Result, ExpirationDate = formatDateToShow(transportCard.ExpirationDate), Id = transportCard.Id, LastDateUsed = formatDateToShow(transportCard.LastDateUsed), Load = transportCard.Load, TodayCardUsage = _transportService.GetAllTransportById(id).Result.Count }; //result.CardType = await _cardTypeService.GetCardTypeById(result.CardTypeId); return(Ok(response)); }
public async Task <IActionResult> Create([Bind("Id,Name,CardTypeId,CardSeriesId,SeriesNum,CardPassword,ImagePath")] CardInfoViewModel cardInfoViewModel) { if (ModelState.IsValid) { var cardInfoDTO = _mapper.Map <CardInfoDTO>(cardInfoViewModel); await _cardInfoService.AddData(cardInfoDTO); return(RedirectToAction(nameof(Index))); } return(View(cardInfoViewModel)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,CardTypeId,CardSeriesId,SeriesNum,CardPassword,ImagePath")] CardInfoViewModel cardInfoViewModel) { if (id != cardInfoViewModel.Id) { return(NotFound()); } if (ModelState.IsValid) { var cardInfo = _mapper.Map <CardInfoDTO>(cardInfoViewModel); await _cardInfoService.UpdateData(cardInfo); return(RedirectToAction(nameof(Index))); } var cardSeriesList = await _cardSeriesService.GetList(); var cardTypeList = await _cardTypeService.GetList(); ViewData["CardSeriesId"] = new SelectList(_mapper.Map <IEnumerable <CardSeriesViewModel> >(cardSeriesList), "Id", "SeriesName", cardInfoViewModel.CardSeriesId); ViewData["CardTypeId"] = new SelectList(_mapper.Map <IEnumerable <CardTypeViewModel> >(cardTypeList), "Id", "TypeName", cardInfoViewModel.CardTypeId); return(View(cardInfoViewModel)); }
public ActionResult PaymentProcess(CardInfoViewModel data) { if (string.IsNullOrEmpty(data.customerProfile_Id)) { data.customerProfile_Id = _helper.CreateCust(data); } if (data.addnewcard.isCardSave) { data.addPayment.CCID = true; string message = UpdateCust(data); if (string.IsNullOrEmpty(message)) { var response = new PaymentResponse { aTranId = data.aTranId, cutomerProfileId = data.customerProfile_Id, statusCode = "200", message = "Card Added Successfully!!", transAmount = data.Amount, }; _helper.PostPaymentResponse(response, data.reqId); TempData["Success"] = "Card Added Successfully!!"; } else { TempData["Error"] = message; } return(RedirectToAction("Payment", "Payment", new { aTranId = data.aTranId })); } if (data.PostType == "Pay") { if (data.addnewcard.CCAddCard || data.addnewcard.BankAddCard) { var response = _helper.PaymentMethod(data); _helper.PostPaymentResponse(response, data.reqId); if (response.statusCode == "200") { return(RedirectToAction("ThanKYou", "Payment")); } else { TempData["Error"] = response.message; } } else if (data.addnewcard.SaveCard) { var response = _helper.CustTransection(data, data.addnewcard.custumerCardId); response.aTranId = data.aTranId; _helper.PostPaymentResponse(response, data.reqId); if (response.statusCode == "200") { return(RedirectToAction("ThanKYou", "Payment")); } else { TempData["Error"] = response.message; } return(RedirectToAction("Payment", "Payment", new { aTranId = data.aTranId })); //foreach (var item in data.savecard) //{ // if (item.CCDynamic) // { // var response = _helper.CustTransection(item.customerPaymentProfileId, data.customerProfile_Id, data.Amount, data.ANET_ApiLoginID, data.ANET_ApiTransactionKey); // if (response.statusCode == "200") // { // return RedirectToAction("ThanKYou", "Payment"); // } // else // { // TempData["Error"] = response.message; // } // } //} } if (!data.addnewcard.CCAddCard && !data.addnewcard.BankAddCard) { TempData["Error"] = "No Payment Method is Selected"; } } else if (data.PostType == "CreateCustomer") { string cusProfileId = _helper.CreateCust(data); if (!string.IsNullOrEmpty(cusProfileId)) { TempData["Success"] = "Profile Create Successfully!!"; return(RedirectToAction("Payment", "Payment", new { aTranId = data.aTranId, CusProfilId = cusProfileId })); } else { TempData["Error"] = "Error while saving customer!!"; } } //else if(data.savecard.)s return(RedirectToAction("Payment", "Payment", new { aTranId = data.aTranId })); }
// GET: Payment method fir github public ActionResult Payment(string aTranId, string CusProfilId = "") { CardInfoViewModel cardInfoView = new CardInfoViewModel(); try { //cardInfoView.CustomerId = "A001"; //cardInfoView.email = "*****@*****.**"; //cardInfoView.customerProfile_Id = "1960547788"; //cardInfoView.savecard = GetCardInfo(cardInfoView.customerProfile_Id); var requestUrl = $"{ConfigurationManager.AppSettings["GetPaymentInfoUrl"]}"; var urlParameter = $"?aTranId={aTranId}"; HttpClient client = new HttpClient(); client.BaseAddress = new Uri(requestUrl); // Add an Accept header for JSON format. client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); // List data response. HttpResponseMessage response = client.GetAsync(urlParameter).Result; // Blocking call! Program will wait here until a response is received or a timeout occurs. if (response.IsSuccessStatusCode) { // Parse the response body. var dataObjects = response.Content.ReadAsStringAsync().Result; PaymentInfo obj = JsonConvert.DeserializeObject <PaymentInfo>(dataObjects); cardInfoView.reqId = PaymentInfo.SaveRequest(obj); if (obj.StatusCode == "200") { cardInfoView.email = obj.customeremail; cardInfoView.customerProfile_Id = string.IsNullOrEmpty(obj.CustomerProfileId) ? CusProfilId : obj.CustomerProfileId;//obj.CustomerProfileId == string.Empty? CusProfilId: obj.CustomerProfileId;//"1599538578"; cardInfoView.Amount = Math.Round(Convert.ToDecimal(obj.amount), 2); cardInfoView.InvoiceNumber = obj.docType.ToLower() == "order" ? obj.OrderNumber : obj.InvoiceNumber; cardInfoView.ANET_ApiLoginID = obj.ANET_ApiLoginID; cardInfoView.OderNumber = obj.OrderNumber; cardInfoView.ANET_ApiTransactionKey = obj.ANET_ApiTransactionKey; cardInfoView.Environment = obj.env; cardInfoView.aTranId = obj.tranidkey; cardInfoView.taxAmount = obj.taxAmount; cardInfoView.shipping = obj.shipping; cardInfoView.docType = obj.docType; // billing and shiping info cardInfoView.billingFName = obj.billingFName; cardInfoView.billingLName = obj.billingLName; cardInfoView.billingCompany = obj.billingCompany; cardInfoView.billingAddrLine1 = obj.billingAddrLine1; cardInfoView.billingAddressLine2 = obj.billingAddressLine2; cardInfoView.billingCity = obj.billingCity; cardInfoView.billingState = obj.billingState; cardInfoView.billingCountry = obj.billingCountry; cardInfoView.billingZipCode = obj.billingZipCode; cardInfoView.billingPhno = obj.billingPhno; cardInfoView.billingFax = obj.billingFax; cardInfoView.shippingFName = obj.shippingFName; cardInfoView.shippingLName = obj.shippingLName; cardInfoView.shippingCompany = obj.shippingCompany; cardInfoView.shippingAddrLine1 = obj.shippingAddrLine1; cardInfoView.shippingAddressLine2 = obj.shippingAddressLine2; cardInfoView.shippingCity = obj.shippingCity; cardInfoView.shippingState = obj.shippingState; cardInfoView.shippingCountry = obj.shippingCountry; cardInfoView.shippingZipCode = obj.shippingZipCode; cardInfoView.shippingPhno = obj.shippingPhno; cardInfoView.shippingFax = obj.shippingFax; // billing and shiping info if (!string.IsNullOrEmpty(cardInfoView.customerProfile_Id)) { cardInfoView.savecard = _helper.GetCardInfo(cardInfoView.customerProfile_Id, cardInfoView.ANET_ApiLoginID, cardInfoView.ANET_ApiTransactionKey); } } else { return(Json($"Error Geting Customer information: {obj.Message}", JsonRequestBehavior.AllowGet)); } } else { //Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase); return(Json("Error Geting Customer information", JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { string path = $"{System.Web.HttpContext.Current.Server.MapPath("~/Error")}/{Guid.NewGuid().ToString()}.txt"; FileSave.FileSaveData(path, ex.Message); } return(View(cardInfoView)); }
public string UpdateCust(CardInfoViewModel data) { string message = string.Empty; try { ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.PRODUCTION; // define the merchant information (authentication / transaction id) ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType() { name = data.ANET_ApiLoginID, ItemElementName = ItemChoiceType.transactionKey, Item = data.ANET_ApiTransactionKey, }; if (data.addPayment.CCID) { var creditCard = new creditCardType { cardNumber = data.addnewcard.x_card_num, expirationDate = data.addnewcard.x_exp_code, }; // standard api call to retrieve response paymentType cc = new paymentType { Item = creditCard }; customerPaymentProfileExType ccPaymentProfile = new customerPaymentProfileExType(); ccPaymentProfile.payment = cc; var request = new createCustomerPaymentProfileRequest(); request.paymentProfile = ccPaymentProfile; request.customerProfileId = data.customerProfile_Id; // instantiate the controller that will call the service var controller = new createCustomerPaymentProfileController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); if (response != null && response.messages.resultCode == messageTypeEnum.Ok) { //Console.WriteLine(response.messages.message[0].text); } else if (response != null) { //Console.WriteLine("Error: " + response.messages.message[0].code + " " + // response.messages.message[0].text); message = response.messages.message[0].text; } } else if (data.addPayment.BAccount) { var bankAccount = new bankAccountType { accountNumber = data.addPayment.PayAdd_account_num, routingNumber = data.addPayment.ABA_Routing_num, accountType = bankAccountTypeEnum.checking, echeckType = echeckTypeEnum.WEB, nameOnAccount = data.addPayment.PayAdd_name_on_acc, bankName = data.addPayment.PayAdd_bank_name }; paymentType echeck = new paymentType { Item = bankAccount }; customerPaymentProfileType echeckPaymentProfile = new customerPaymentProfileType(); echeckPaymentProfile.payment = echeck; var request = new createCustomerPaymentProfileRequest(); request.paymentProfile = echeckPaymentProfile; request.customerProfileId = data.customerProfile_Id; // instantiate the controller that will call the service var controller = new createCustomerPaymentProfileController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); if (response != null && response.messages.resultCode == messageTypeEnum.Ok) { //Console.WriteLine(response.messages.message[0].text); } else if (response != null) { //Console.WriteLine("Error: " + response.messages.message[0].code + " " + // response.messages.message[0].text); message = response.messages.message[0].text; } } else { message = "Some Error ouccerd Please try again!!!"; } } catch { } return(message); }
public string CreateCust(CardInfoViewModel data) { //Console.WriteLine("Create Customer Profile Sample"); // set whether to use the sandbox environment, or production enviornment ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.PRODUCTION; // define the merchant information (authentication / transaction id) ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType() { name = data.ANET_ApiLoginID, ItemElementName = ItemChoiceType.transactionKey, Item = data.ANET_ApiTransactionKey, }; customerProfileType customerProfile = new customerProfileType(); customerProfile.merchantCustomerId = data.CustomerId; customerProfile.email = data.email; var request = new createCustomerProfileRequest { profile = customerProfile, validationMode = validationModeEnum.none }; // instantiate the controller that will call the service var controller = new createCustomerProfileController(request); controller.Execute(); // get the response from the service (errors contained if any) createCustomerProfileResponse response = controller.GetApiResponse(); // validate response if (response != null) { if (response.messages.resultCode == messageTypeEnum.Ok) { if (response.messages.message != null) { //Console.WriteLine("Success!"); //Console.WriteLine("Customer Profile ID: " + ); return(response.customerProfileId); } } else { Console.WriteLine("Customer Profile Creation Failed."); Console.WriteLine("Error Code: " + response.messages.message[0].code); Console.WriteLine("Error message: " + response.messages.message[0].text); } } else { if (controller.GetErrorResponse().messages.message.Length > 0) { Console.WriteLine("Customer Profile Creation Failed."); Console.WriteLine("Error Code: " + response.messages.message[0].code); Console.WriteLine("Error message: " + response.messages.message[0].text); } else { Console.WriteLine("Null Response."); } } return(string.Empty); }
public void cardAdd(CardInfoViewModel data) { //Console.WriteLine("Update customer profile sample"); ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.PRODUCTION; // define the merchant information (authentication / transaction id) ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType() { name = data.ANET_ApiLoginID, ItemElementName = ItemChoiceType.transactionKey, Item = data.ANET_ApiTransactionKey, }; if (data.addnewcard.CCAddCard) { var creditCard = new creditCardType { cardNumber = data.addnewcard.x_card_num, expirationDate = data.addnewcard.x_exp_code }; // standard api call to retrieve response paymentType cc = new paymentType { Item = creditCard }; customerPaymentProfileExType ccPaymentProfile = new customerPaymentProfileExType(); ccPaymentProfile.payment = cc; var request = new createCustomerPaymentProfileRequest(); request.paymentProfile = ccPaymentProfile; request.customerProfileId = data.customerProfile_Id; // instantiate the controller that will call the service var controller = new createCustomerPaymentProfileController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); if (response != null && response.messages.resultCode == messageTypeEnum.Ok) { Console.WriteLine(response.messages.message[0].text); } else if (response != null) { Console.WriteLine("Error: " + response.messages.message[0].code + " " + response.messages.message[0].text); } } else if (data.addnewcard.BankAddCard) { var bankAccount = new bankAccountType { accountNumber = data.addnewcard.x_name_account_num, routingNumber = data.addnewcard.x_aba_rout_num, accountType = bankAccountTypeEnum.checking, echeckType = echeckTypeEnum.WEB, nameOnAccount = data.addnewcard.x_name_on_account, bankName = data.addnewcard.x_bank_name }; paymentType echeck = new paymentType { Item = bankAccount }; customerPaymentProfileExType ccPaymentProfile = new customerPaymentProfileExType(); ccPaymentProfile.payment = echeck; var request = new createCustomerPaymentProfileRequest(); request.paymentProfile = ccPaymentProfile; request.customerProfileId = data.customerProfile_Id; // instantiate the controller that will call the service var controller = new createCustomerPaymentProfileController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); if (response != null && response.messages.resultCode == messageTypeEnum.Ok) { Console.WriteLine(response.messages.message[0].text); } else if (response != null) { Console.WriteLine("Error: " + response.messages.message[0].code + " " + response.messages.message[0].text); } } }
public PaymentResponse PaymentMethod(CardInfoViewModel data) { ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.PRODUCTION; PaymentResponse objPaymentRes = new PaymentResponse(); objPaymentRes.transAmount = data.Amount; objPaymentRes.aTranId = data.aTranId; objPaymentRes.cutomerProfileId = data.customerProfile_Id; // define the merchant information (authentication / transaction id) ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType() { name = data.ANET_ApiLoginID, ItemElementName = ItemChoiceType.transactionKey, Item = data.ANET_ApiTransactionKey, }; if (data.addnewcard.CCAddCard) { var creditCard = new creditCardType { cardNumber = data.addnewcard.x_card_num, expirationDate = data.addnewcard.x_exp_code }; //standard api call to retrieve response var paymentType = new paymentType { Item = creditCard }; var transactionRequest = new transactionRequestType { transactionType = transactionTypeEnum.authOnlyTransaction.ToString(), // authorize only amount = data.Amount, payment = paymentType, poNumber = data.InvoiceNumber, shipTo = new nameAndAddressType { firstName = data.shippingFName, lastName = data.shippingLName, address = data.shippingAddrLine1 + ' ' + data.shippingAddressLine2, city = data.shippingCity, company = data.shippingCompany, state = data.shippingState, country = data.shippingCountry, zip = data.shippingZipCode }, billTo = new customerAddressType { firstName = data.billingFName, lastName = data.billingLName, address = $"{data.billingAddrLine1} {data.billingAddressLine2}", city = data.billingCity, company = data.billingCompany, state = data.billingState, country = data.billingCountry, zip = data.billingZipCode, email = data.email, faxNumber = !string.IsNullOrEmpty(data.billingFax) ? data.billingFax : string.Empty, phoneNumber = data.billingPhno }, tax = new extendedAmountType { amount = Convert.ToDecimal(data.taxAmount), name = "", description = "" } , duty = new extendedAmountType { amount = decimal.Parse("0.00"), name = "", description = "" }, shipping = new extendedAmountType { amount = Convert.ToDecimal(data.shipping), name = "", description = "" }, }; var request = new createTransactionRequest { transactionRequest = transactionRequest }; // instantiate the controller that will call the service var controller = new createTransactionController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); // validate response if (response != null) { if (response.messages.resultCode == messageTypeEnum.Ok) { if (data.addnewcard.addPaycheck) { cardAdd(data); } if (response.transactionResponse.messages != null) { //Console.WriteLine("Successfully created transaction with Transaction ID: " + response.transactionResponse.transId); //Console.WriteLine("Response Code: " + response.transactionResponse.responseCode); //Console.WriteLine("Message Code: " + response.transactionResponse.messages[0].code); //Console.WriteLine("Description: " + response.transactionResponse.messages[0].description); //Console.WriteLine("Success, Auth Code : " + response.transactionResponse.authCode); objPaymentRes.statusCode = "200"; objPaymentRes.message = response.transactionResponse.messages[0].description; objPaymentRes.transId = response.transactionResponse.transId; objPaymentRes.transactionResponse = response.transactionResponse; } else { //Console.WriteLine("Failed Transaction."); if (response.transactionResponse.errors != null) { //Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode); //Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText); objPaymentRes.statusCode = "400"; objPaymentRes.message = response.transactionResponse.errors[0].errorText; objPaymentRes.transId = response.transactionResponse.transId; objPaymentRes.transactionResponse = response.transactionResponse; } } } else { // Console.WriteLine("Failed Transaction."); if (response.transactionResponse != null && response.transactionResponse.errors != null) { //Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode); //Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText); objPaymentRes.statusCode = "400"; objPaymentRes.message = response.transactionResponse.errors[0].errorText; objPaymentRes.transId = response.transactionResponse.transId; objPaymentRes.transactionResponse = response.transactionResponse; } else { //Console.WriteLine("Error Code: " + response.messages.message[0].code); //Console.WriteLine("Error message: " + response.messages.message[0].text); objPaymentRes.statusCode = "400"; objPaymentRes.message = response.messages.message[0].text; objPaymentRes.transId = string.Empty; objPaymentRes.cutomerProfileId = data.customerProfile_Id; objPaymentRes.transactionResponse = new transactionResponse(); } } } else { // Console.WriteLine("Null Response."); var responseError = controller.GetErrorResponse(); if (responseError.messages != null) { objPaymentRes.statusCode = "400"; objPaymentRes.message = responseError.messages.message.Select(i => i.text).FirstOrDefault(); objPaymentRes.transId = string.Empty; objPaymentRes.transactionResponse = new transactionResponse(); } else { objPaymentRes.statusCode = "400"; objPaymentRes.message = "Null Response"; objPaymentRes.transId = string.Empty; objPaymentRes.transactionResponse = new transactionResponse(); } } // return View("Payment", data); } else if (data.addnewcard.BankAddCard) { var bankAccount = new bankAccountType { accountNumber = data.addnewcard.x_name_account_num, routingNumber = data.addnewcard.x_aba_rout_num, accountType = bankAccountTypeEnum.savings, echeckType = echeckTypeEnum.WEB, nameOnAccount = data.addnewcard.x_name_on_account, bankName = data.addnewcard.x_bank_name }; paymentType echeck = new paymentType { Item = bankAccount }; var transactionRequest = new transactionRequestType { transactionType = transactionTypeEnum.authOnlyTransaction.ToString(), // authorize only amount = data.Amount, payment = echeck }; var request = new createTransactionRequest { transactionRequest = transactionRequest }; // instantiate the controller that will call the service var controller = new createTransactionController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); // validate response if (response != null) { if (response.messages.resultCode == messageTypeEnum.Ok) { if (response.transactionResponse.messages != null) { if (data.addnewcard.addPaycheck) { cardAdd(data); } //Console.WriteLine("Successfully created transaction with Transaction ID: " + response.transactionResponse.transId); //Console.WriteLine("Response Code: " + response.transactionResponse.responseCode); //Console.WriteLine("Message Code: " + response.transactionResponse.messages[0].code); //Console.WriteLine("Description: " + response.transactionResponse.messages[0].description); //Console.WriteLine("Success, Auth Code : " + response.transactionResponse.authCode); objPaymentRes.aTranId = data.aTranId; objPaymentRes.statusCode = response.transactionResponse.responseCode; objPaymentRes.message = response.transactionResponse.messages[0].description; objPaymentRes.transId = response.transactionResponse.transId; objPaymentRes.cutomerProfileId = data.customerProfile_Id; objPaymentRes.transactionResponse = response.transactionResponse; } else { Console.WriteLine("Failed Transaction."); if (response.transactionResponse.errors != null) { //Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode); //Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText); objPaymentRes.statusCode = "400"; objPaymentRes.message = response.transactionResponse.errors[0].errorText; objPaymentRes.transId = response.transactionResponse.transId; objPaymentRes.transactionResponse = response.transactionResponse; } } } else { Console.WriteLine("Failed Transaction."); if (response.transactionResponse != null && response.transactionResponse.errors != null) { //Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode); //Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText); objPaymentRes.statusCode = "400"; objPaymentRes.message = response.transactionResponse.errors[0].errorText; objPaymentRes.transId = response.transactionResponse.transId; objPaymentRes.transactionResponse = response.transactionResponse; } else { //Console.WriteLine("Error Code: " + response.messages.message[0].code); //Console.WriteLine("Error message: " + response.messages.message[0].text); objPaymentRes.statusCode = "400"; objPaymentRes.message = response.messages.message[0].text; objPaymentRes.transId = string.Empty; objPaymentRes.transactionResponse = new transactionResponse(); } } } else { objPaymentRes.statusCode = "400"; objPaymentRes.message = "Null Response"; objPaymentRes.transId = string.Empty; objPaymentRes.transactionResponse = new transactionResponse(); } //return View("Payment", data); } else { foreach (var item in data.savecard) { if (item.CCDynamic) { CustTransection(data, item.customerPaymentProfileId); } } //return View("Payment", data); } return(objPaymentRes); }
public PaymentResponse CustTransection(CardInfoViewModel data, string customerPaymentProfileId) { PaymentResponse objPaymentRes = new PaymentResponse(); try { //String ApiLoginID = "5z2fSW5G"; String ApiTransactionKey = "66JWg8eyL2Z78Sfs"; ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.PRODUCTION; // define the merchant information (authentication / transaction id) ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType() { name = data.ANET_ApiLoginID, ItemElementName = ItemChoiceType.transactionKey, Item = data.ANET_ApiTransactionKey, }; objPaymentRes.cutomerProfileId = data.customerProfile_Id; objPaymentRes.transAmount = data.Amount; // Use CIM to create the profile we're going to charge var customerProfileId = data.customerProfile_Id; //"1960337182"; var paymentProfileId = customerPaymentProfileId; // "1976458349"; //create a customer payment profile customerProfilePaymentType profileToCharge = new customerProfilePaymentType(); profileToCharge.customerProfileId = customerProfileId; profileToCharge.paymentProfile = new paymentProfile { paymentProfileId = paymentProfileId }; var transactionRequestType = new transactionRequestType { transactionType = transactionTypeEnum.authCaptureTransaction.ToString(), amount = Convert.ToDecimal(data.Amount), profile = profileToCharge, poNumber = data.InvoiceNumber, //transactionSettings = itemArr.ToArray(), shipTo = new nameAndAddressType { firstName = data.shippingFName, lastName = data.shippingLName, address = data.shippingAddrLine1 + ' ' + data.shippingAddressLine2, city = data.shippingCity, company = data.shippingCompany, state = data.shippingState, country = data.shippingCountry, zip = data.shippingZipCode }, //billTo = new customerAddressType //{ // firstName = data.billingFName, // lastName = data.billingLName, // address = $"{data.billingAddrLine1} {data.billingAddressLine2}", // city = data.billingCity, // company = data.billingCompany, // state = data.billingState, // country = data.billingCountry, // zip = data.billingZipCode, // email = data.email, // faxNumber = !string.IsNullOrEmpty(data.billingFax) ? data.billingFax : string.Empty, // phoneNumber = data.billingPhno //}, tax = new extendedAmountType { amount = Convert.ToDecimal(data.taxAmount), name = "", description = "" } , shipping = new extendedAmountType { amount = Convert.ToDecimal(data.shipping), name = "", description = "" }, }; var createRequest = new createTransactionRequest { //refId = RefId, transactionRequest = transactionRequestType, }; //create controller, execute and get response var createController = new createTransactionController(createRequest); createController.Execute(); var response = createController.GetApiResponse(); 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); objPaymentRes.statusCode = "200"; objPaymentRes.message = response.transactionResponse.messages[0].description; objPaymentRes.transId = response.transactionResponse.transId; objPaymentRes.transactionResponse = response.transactionResponse; } else { //Console.WriteLine("Failed Transaction."); if (response.transactionResponse.errors != null) { //Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode); //Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText); objPaymentRes.statusCode = "400"; objPaymentRes.message = response.transactionResponse.errors[0].errorText; objPaymentRes.transId = response.transactionResponse.transId; objPaymentRes.transactionResponse = response.transactionResponse; } } } else { // Console.WriteLine("Failed Transaction."); if (response.transactionResponse != null && response.transactionResponse.errors != null) { //Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode); //Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText); objPaymentRes.statusCode = "400"; objPaymentRes.message = response.transactionResponse.errors[0].errorText; objPaymentRes.transId = response.transactionResponse.transId; objPaymentRes.transactionResponse = response.transactionResponse; } else { //Console.WriteLine("Error Code: " + response.messages.message[0].code); //Console.WriteLine("Error message: " + response.messages.message[0].text); objPaymentRes.statusCode = "400"; objPaymentRes.message = response.messages.message[0].text; objPaymentRes.transId = string.Empty; objPaymentRes.transactionResponse = new transactionResponse(); } } } else { // Console.WriteLine("Null Response."); objPaymentRes.statusCode = "400"; objPaymentRes.message = "Null Response"; objPaymentRes.transId = string.Empty; objPaymentRes.transactionResponse = new transactionResponse(); } } catch { } return(objPaymentRes); }