public IActionResult PaymentMethodDelete(int profileId) { IWorkContext _workContext = EngineContext.Current.Resolve <IWorkContext>(); var customer = _workContext.CurrentCustomer; GBSPaymentServiceClient gateway = new GBSPaymentServiceClient(); var response = gateway.DeleteProfile(int.Parse(profileId.ToString()), _gbsPaymentSettings.GBSPaymentWebServiceAddress, _gbsPaymentSettings.LoginId, _gbsPaymentSettings.Password, _gbsPaymentSettings.UseSandbox); if (response.procStatus == "0" || response.procStatus == "9581") { DBManager dbmanager = new DBManager(); Dictionary <string, string> paramDic = new Dictionary <string, string>(); paramDic.Add("@CustomerID", customer.Id.ToString()); paramDic.Add("@ProfileID", profileId.ToString()); string select = "DELETE FROM Profiles WHERE CustomerID = " + customer.Id + " AND ProfileID = " + profileId + ""; DataView dView = dbmanager.GetParameterizedDataView(select, paramDic); //dbmanager.GetDataView(select); } else { //ADD ERROR CODE HERE } //redirect to the payment methods list page return(Json(new { redirect = Url.RouteUrl("CustomerPaymentMethods"), })); }
public IActionResult PaymentMethodEdit(int profileId) { IWorkContext _workContext = EngineContext.Current.Resolve <IWorkContext>(); var customer = _workContext.CurrentCustomer; var model = new CustomerPaymentProfilesModel(); GBSPaymentServiceClient gateway = new GBSPaymentServiceClient(); var response = gateway.ReadProfile(int.Parse(profileId.ToString()), _gbsPaymentSettings.GBSPaymentWebServiceAddress, _gbsPaymentSettings.LoginId, _gbsPaymentSettings.Password, _gbsPaymentSettings.UseSandbox); if (response.procStatus == "0") { DBManager dbmanager = new DBManager(); Dictionary <string, string> paramDic = new Dictionary <string, string>(); paramDic.Add("@CustomerID", customer.Id.ToString()); paramDic.Add("@ProfileID", profileId.ToString()); string select = "SELECT * FROM Profiles WHERE CustomerID = " + customer.Id + " AND ProfileID = " + profileId + ""; DataView dView = dbmanager.GetParameterizedDataView(select, paramDic); //dbmanager.GetDataView(select); DataRow firstRow = dView.Table.Rows[0]; PaymentMethodModel getProfile = new PaymentMethodModel(); getProfile.profileID = Convert.ToInt32(response.profileID); getProfile.NickName = firstRow["NickName"].ToString(); getProfile.Last4Digits = response.cardNumber.ToString(); getProfile.CardType = firstRow["CardType"].ToString(); getProfile.ExpMonth = (int)firstRow["ExpMonth"]; getProfile.ExpYear = (int)firstRow["ExpYear"]; model.SavedProfiles.Add(getProfile); } else { //ADD ERROR CODE HERE ViewBag.warnings = response.profileMessage; } return(View(model)); }
public ProcessPaymentRequest GetPaymentInfo(IFormCollection form) { var paymentInfo = new ProcessPaymentRequest(); GBSPaymentServiceClient gateway = new GBSPaymentServiceClient(); if (form.Keys.Contains("ProfileID") && !String.IsNullOrEmpty(form["ProfileID"].ToString())) { WebServices.Models.Payment.PaymentProfileModel paymentProfile = gateway.ReadProfile(int.Parse(form["ProfileID"]), _gbsPaymentSettings.GBSPaymentWebServiceAddress, _gbsPaymentSettings.LoginId, _gbsPaymentSettings.Password, _gbsPaymentSettings.UseSandbox); paymentInfo = new ProcessPaymentRequest(); paymentInfo.CreditCardName = paymentProfile.customerName; paymentInfo.CreditCardNumber = paymentProfile.cardNumber; paymentInfo.CreditCardExpireMonth = int.Parse(paymentProfile.cardExpireMonth); paymentInfo.CreditCardExpireYear = int.Parse(paymentProfile.cardExpireYear); paymentInfo.CustomValues["ProfileID"] = form["ProfileID"].ToString(); paymentInfo.CustomValues["SavedProfile"] = true; paymentInfo.CustomValues["StoreProfile"] = form["StoreProfile"]; } else { paymentInfo = new ProcessPaymentRequest(); //paymentInfo.CreditCardType is not used by Authorize.NET paymentInfo.CreditCardName = form["CardholderName"]; paymentInfo.CreditCardNumber = form["CardNumber"]; paymentInfo.CreditCardExpireMonth = int.Parse(form["ExpireMonth"]); paymentInfo.CreditCardExpireYear = int.Parse(form["ExpireYear"]); paymentInfo.CreditCardCvv2 = form["CardCode"]; paymentInfo.CustomValues["SavedProfile"] = false; paymentInfo.CustomValues["NickName"] = form["NickName"]; paymentInfo.CustomValues["StoreProfile"] = form["StoreProfile"]; } return(paymentInfo); }
/// <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); try { PrepareGBS(); //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) //NOP WEB SERVICE CALL START HERE -------------------------------------------------------------------------------------------------------------------- //create nop payment object from user data PaymentTransactionModel payment = new PaymentTransactionModel(); payment.firstName = customer.BillingAddress.FirstName; payment.lastName = customer.BillingAddress.LastName; payment.streetAddress = customer.BillingAddress.Address1; payment.billingCity = customer.BillingAddress.City; payment.postalCode = customer.BillingAddress.ZipPostalCode; payment.countryCode = customer.BillingAddress.Country.Name; if (payment.countryCode == "United States") { payment.countryCode = "US"; } else { payment.countryCode = "US"; } payment.cardExpireMonth = processPaymentRequest.CreditCardExpireMonth.ToString().Length == 1 ? "0" + processPaymentRequest.CreditCardExpireMonth.ToString() : processPaymentRequest.CreditCardExpireMonth.ToString(); //prepend 0 for single digit months payment.cardExpireYear = processPaymentRequest.CreditCardExpireYear.ToString(); payment.cardNum = processPaymentRequest.CreditCardNumber; payment.orderAmount = processPaymentRequest.OrderTotal.ToString(); payment.pcDestZip = (customer.ShippingAddress != null && customer.ShippingAddress.ZipPostalCode != null) ? customer.ShippingAddress.ZipPostalCode : String.Empty; Object value = null; NopResourceDisplayNameAttribute orderNumberKeyGBS = new NopResourceDisplayNameAttribute(("Account.CustomerOrders.OrderNumber")); if (processPaymentRequest.CustomValues.TryGetValue(orderNumberKeyGBS.DisplayName, out value)) { payment.orderID = processPaymentRequest.CustomValues[orderNumberKeyGBS.DisplayName].ToString(); payment.pcOrderID = processPaymentRequest.CustomValues[orderNumberKeyGBS.DisplayName].ToString(); } else { payment.orderID = "NA"; payment.pcOrderID = "NA"; } payment.state = customer.BillingAddress.StateProvince.Abbreviation; payment.tax = _orderTotalCalculationService.GetTaxTotal((IList <ShoppingCartItem>)customer.ShoppingCartItems, false).ToString(); payment.sandBox = _gbsPaymentSettings.UseSandbox; if (Convert.ToBoolean(processPaymentRequest.CustomValues["SavedProfile"]) == true) { payment.createProfile = false; payment.useProfile = true; payment.profileID = processPaymentRequest.CustomValues["ProfileID"].ToString(); } else { payment.createProfile = true; payment.useProfile = false; payment.profileID = ""; } //will need to be able to switch between sand and production version string address = _gbsPaymentSettings.GBSPaymentWebServiceAddress; GBSPaymentServiceClient gateway = new GBSPaymentServiceClient(); //calls to GBSPaymentGateway function var response = gateway.AuthorizeAndCapture(payment, address, _gbsPaymentSettings.LoginId, _gbsPaymentSettings.Password); //use returned GBSTransactionResponse to tell nop what occured in submit switch (response.responseCode) { case GBSTransactionResponse.ResponseCodeType.Approved: result.NewPaymentStatus = PaymentStatus.Authorized; break; case GBSTransactionResponse.ResponseCodeType.Declined: case GBSTransactionResponse.ResponseCodeType.Error: result.NewPaymentStatus = PaymentStatus.Voided; break; default: result.NewPaymentStatus = PaymentStatus.Voided; break; } //validate if (GetErrors(response, result.Errors)) { return(result); } if (_gbsPaymentSettings.TransactMode == TransactMode.Authorize) { result.AuthorizationTransactionCode = string.Format("{0},{1}", response.transactId, response.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.responseCode, response.authCode); //result.AvsResult = response.transactionResponse.avsResultCode; //result.NewPaymentStatus = _authorizeNetPaymentSettings.TransactMode == TransactMode.Authorize ? PaymentStatus.Authorized : PaymentStatus.Paid; //var congrats = "Congrats the payment was successful, now insert profile id into DB"; bool storeProfile = Convert.ToBoolean(processPaymentRequest.CustomValues["StoreProfile"]); if (payment.createProfile == true && storeProfile == true) { string nickName = String.IsNullOrEmpty(processPaymentRequest.CustomValues["NickName"].ToString()) ? "" : processPaymentRequest.CustomValues["NickName"].ToString(); nickName = nickName.Replace("'", "''"); string last4Digits = response.accountNum.ToString(); last4Digits = last4Digits.Substring(last4Digits.Length - 4); DBManager manager = new DBManager(); Dictionary <string, string> paramDic = new Dictionary <string, string>(); paramDic.Add("@CustomerID", customer.Id.ToString()); paramDic.Add("@ProfileID", response.customerRefNum.ToString()); paramDic.Add("@NickName", nickName); paramDic.Add("@Last4Digits", last4Digits); paramDic.Add("@CardType", response.cardBrand.ToString()); paramDic.Add("@ExpMonth", payment.cardExpireMonth); paramDic.Add("@ExpYear", payment.cardExpireYear); string insert = "INSERT INTO Profiles (CustomerID, ProfileID, NickName, Last4Digits, CardType, ExpMonth, ExpYear) "; insert += "VALUES ('" + customer.Id + "', '" + response.customerRefNum + "', '" + nickName + "', '" + last4Digits + "', '" + response.cardBrand + "', '" + payment.cardExpireMonth + "', '" + payment.cardExpireYear + "')"; try { manager.SetParameterizedQueryNoData(insert, paramDic); } catch (Exception ex) { try { _logger.Error("Payment Plugin Error inserting profile on auth : " + ex.Message + ": query = " + insert, ex, null); } catch (Exception ex1) { _logger.Error("Payment Plugin Error inserting profile on auth with additional failure to log the sql statement : " + ex.Message, ex, null); } } } } catch (Exception ex) { _logger.Error("Payment Plugin Error : " + ex.Message, ex, null); throw new Exception("Payment Plugin Exception: " + ex.Message, ex); } return(result); }
public IActionResult PaymentMethodEdit(CustomerPaymentProfilesModel model, int profileId, IFormCollection form) { IWorkContext _workContext = EngineContext.Current.Resolve <IWorkContext>(); var customer = _workContext.CurrentCustomer; var result = new List <string>(); //form.Add("CardholderName", "Default"); //form.Add("ProfileID", ""); GBSPaymentGateway paymentController = new GBSPaymentGateway(_settingService, _currencyService, _customerService, _webHelper, _orderTotalCalculationService, _encryptionService, _currencySettings, _gbsPaymentSettings, _localizationService, _logger); result = (List <string>)paymentController.ValidatePaymentForm(form); ViewBag.warnings = result; PaymentProfileModel profile = new PaymentProfileModel(); profile.profileID = profileId.ToString(); profile.cardNumber = form["CardNumber"].ToString(); profile.cardExpireMonth = form["ExpireMonth"].ToString().Length == 1 ? "0" + form["ExpireMonth"].ToString() : form["ExpireMonth"].ToString(); //prepend 0 for single digit months profile.cardExpireYear = form["ExpireYear"].ToString(); profile.profileAction = "U"; profile.accountType = "CC"; profile.status = "A"; profile.autoGenerate = true; GBSPaymentServiceClient gateway = new GBSPaymentServiceClient(); var response = gateway.UpdateProfile(profile, _gbsPaymentSettings.GBSPaymentWebServiceAddress, _gbsPaymentSettings.LoginId, _gbsPaymentSettings.Password, _gbsPaymentSettings.UseSandbox); if (response.procStatus == "0") { string cardType; string firstDigit = response.cardNumber.ToString(); firstDigit = firstDigit.Substring(0, firstDigit.Length - (firstDigit.Length - 1)); switch (firstDigit) { case "4": cardType = "VI"; break; case "5": cardType = "MC"; break; case "3": cardType = "AX"; break; case "6": cardType = "DI"; break; default: cardType = "VI"; break; } string profileID = response.profileID.ToString(); string nickName = form["NickName"].ToString(); string last4Digits = response.cardNumber.ToString(); last4Digits = last4Digits.Substring(last4Digits.Length - 4); string expireMonth = profile.cardExpireMonth; string expireYear = profile.cardExpireYear; DBManager manager = new DBManager(); Dictionary <string, string> paramDic = new Dictionary <string, string>(); paramDic.Add("@CustomerID", customer.Id.ToString()); paramDic.Add("@ProfileID", profileID.ToString()); paramDic.Add("@NickName", nickName.ToString()); paramDic.Add("@Last4Digits", last4Digits.ToString()); paramDic.Add("@CardType", cardType.ToString()); paramDic.Add("@ExpMonth", expireMonth.ToString()); paramDic.Add("@ExpYear", expireYear.ToString()); string update = "UPDATE Profiles SET NickName='" + nickName.ToString() + "', Last4Digits='" + last4Digits.ToString() + "', CardType='" + cardType.ToString() + "', ExpMonth='" + expireMonth.ToString() + "', ExpYear='" + expireYear.ToString() + "'"; update += "WHERE CustomerID = " + customer.Id + " AND ProfileID = " + profileID + ""; manager.SetParameterizedQueryNoData(update, paramDic); } else { //ADD ERROR CODE HERE ViewBag.warnings.Add(response.profileMessage); } if (ViewBag.warnings.Count > 0) { return(PaymentMethodEdit(profileId)); } else { return(RedirectToRoute("CustomerPaymentMethods")); } }