public override String CaptureOrder(Order o) { String result = "error"; o.CaptureTXCommand = ""; o.CaptureTXResult = ""; string txn_number = o.AuthorizationPNREF; Decimal OrderTotal = o.OrderBalance; bool useLiveTransactions = AppLogic.AppConfigBool("UseLiveTransactions"); string crypt = AppLogic.AppConfig("eSelectPlus.crypt"); if (o.AuthorizationCode.Contains(cryptLabel)) { crypt = o.AuthorizationCode.Substring(o.AuthorizationCode.IndexOf(cryptLabel) + cryptLabel.Length, 1); } StringBuilder transactionCommand = new StringBuilder(4096); String sAmount = Localization.CurrencyStringForGatewayWithoutExchangeRate(OrderTotal); if (sAmount.StartsWith(".")) { sAmount = "0" + sAmount; } transactionCommand.Append("x_type=PRIOR_AUTH_CAPTURE"); transactionCommand.Append("&x_amount=" + sAmount); esp.completion reqCompletion = new esp.completion(); reqCompletion.order_id = o.OrderNumber.ToString(); reqCompletion.comp_amount = sAmount; reqCompletion.txn_number = txn_number; reqCompletion.crypt_type = crypt; try { string sResponse = sendRequest(useLiveTransactions, reqCompletion); esp.response resp = null; if (sResponse != null) { resp = DeserializeResponse(sResponse); } if (resp != null) { esp.receipt respReceipt = (esp.receipt)resp.receipt[0]; o.CaptureTXCommand = transactionCommand.ToString(); o.CaptureTXResult = respReceipt.Complete; if (respReceipt.Complete == "true") { o.AuthorizationPNREF = respReceipt.TransID; result = AppLogic.ro_OK; } else { result = respReceipt.Message; } } } catch { result = "failed"; } return(result); }
public override String RefundOrder(int OriginalOrderNumber, int NewOrderNumber, decimal RefundOrderTotal, String RefundReason, Address UseBillingAddress) { String result = "error"; string crypt = AppLogic.AppConfig("eSelectPlus.crypt"); DB.ExecuteSQL("update orders set RefundTXCommand=NULL, RefundTXResult=NULL where OrderNumber=" + OriginalOrderNumber.ToString()); bool useLiveTransactions = AppLogic.AppConfigBool("UseLiveTransactions"); String TransID = String.Empty; String Last4 = String.Empty; int CustomerID = 0; Decimal OrderTotal = System.Decimal.Zero; string authCode = string.Empty; string theOrderTotal = string.Empty; using (var conn = DB.dbConn()) { conn.Open(); using (var rs = DB.GetRS("select * from orders with (NOLOCK) where OrderNumber=" + OriginalOrderNumber.ToString(), conn)) { if (rs.Read()) { TransID = DB.RSField(rs, "AuthorizationPNREF"); Last4 = DB.RSField(rs, "Last4"); OrderTotal = DB.RSFieldDecimal(rs, "OrderTotal"); CustomerID = DB.RSFieldInt(rs, "CustomerID"); authCode = DB.RSField(rs, "AuthorizationCode"); } } } if (authCode.Contains(cryptLabel)) { crypt = authCode.Substring(authCode.IndexOf(cryptLabel) + cryptLabel.Length, 1); } StringBuilder transactionCommand = new StringBuilder(4096); transactionCommand.Append("x_type=CREDIT"); transactionCommand.Append("&x_trans_id=" + TransID); if (RefundOrderTotal == System.Decimal.Zero) { theOrderTotal = Localization.CurrencyStringForGatewayWithoutExchangeRate(OrderTotal); } else { theOrderTotal = Localization.CurrencyStringForGatewayWithoutExchangeRate(RefundOrderTotal); } if (theOrderTotal.StartsWith(".")) { theOrderTotal = "0" + theOrderTotal; } transactionCommand.Append("&x_amount=" + theOrderTotal); transactionCommand.Append("&x_cust_id=" + CustomerID.ToString()); transactionCommand.Append("&x_invoice_num=" + OriginalOrderNumber.ToString()); transactionCommand.Append("&x_customer_ip=" + CommonLogic.CustomerIpAddress()); transactionCommand.Append("&x_card_num=" + Last4); transactionCommand.Append("&x_description=" + HttpContext.Current.Server.UrlEncode(RefundReason)); esp.refundTxn reqRefund = new esp.refundTxn(); reqRefund.order_id = OriginalOrderNumber.ToString(); reqRefund.amount = theOrderTotal; reqRefund.txn_number = TransID; reqRefund.crypt_type = crypt; try { string sResponse = sendRequest(useLiveTransactions, reqRefund); esp.response resp = null; if (sResponse != null) { resp = DeserializeResponse(sResponse); } if (resp != null) { esp.receipt respReceipt = (esp.receipt)resp.receipt[0]; StringBuilder tps = new StringBuilder(""); tps.Append("update orders set "); tps.Append("RefundTXCommand=" + DB.SQuote(transactionCommand.ToString()) + ","); tps.Append("RefundTXResult=" + DB.SQuote(respReceipt.Complete) + ","); tps.Append("RefundReason=" + DB.SQuote(RefundReason.ToString())); tps.Append(" where ordernumber=" + OriginalOrderNumber.ToString()); DB.ExecuteSQL(tps.ToString()); if (respReceipt.Complete == "true") { result = AppLogic.ro_OK; } else { result = respReceipt.Message; } } } catch { result = "failed"; } return(result); }
public override String ProcessCard(int OrderNumber, int CustomerID, Decimal OrderTotal, bool useLiveTransactions, TransactionModeEnum TransactionMode, Address UseBillingAddress, String CardExtraCode, Address UseShippingAddress, String CAVV, String ECI, String XID, out String AVSResult, out String AuthorizationResult, out String AuthorizationCode, out String AuthorizationTransID, out String TransactionCommandOut, out String TransactionResponse) { String result = "Error"; AuthorizationCode = String.Empty; AuthorizationResult = String.Empty; AuthorizationTransID = String.Empty; AVSResult = String.Empty; TransactionCommandOut = String.Empty; TransactionResponse = String.Empty; String sOrderNumber = OrderNumber.ToString(); if (AppLogic.AppConfigBool("eSelectPlus.randomizeOrderNumberForTesting") && !useLiveTransactions) { Random r = new Random(); sOrderNumber = "r" + r.Next(0, 9999999); } String crypt = AppLogic.AppConfig("eSelectPlus.crypt"); String sAmount = Localization.CurrencyStringForGatewayWithoutExchangeRate(OrderTotal); if (sAmount.StartsWith(".")) { sAmount = "0" + sAmount; } String signedPARes = String.Empty; CustomerSession cSession = new CustomerSession(CustomerID); if (cSession["3Dsecure.PaRes"].Length != 0) { signedPARes = cSession["3Dsecure.PaRes"]; // After grabbing it, clear out the session PaRes so it won't be re-used ever again. cSession["3Dsecure.PaRes"] = String.Empty; } String CardNumber = UseBillingAddress.CardNumber.Trim(); String expire_date = CommonLogic.IIF(UseBillingAddress.CardExpirationYear.PadLeft(2, '0').Length > 2, UseBillingAddress.CardExpirationYear.PadLeft(2, '0').Substring(2, 2), UseBillingAddress.CardExpirationYear.PadLeft(2, '0')) + UseBillingAddress.CardExpirationMonth.PadLeft(2, '0'); int CardTypeID = DB.GetSqlN("select CardTypeID N from CreditCardType where CardType = " + DB.SQuote(UseBillingAddress.CardType)); bool Try3DSecure = CommonLogic.IntegerIsInIntegerList(CardTypeID, AppLogic.AppConfig("3DSECURE.CreditCardTypeIDs")); if (Try3DSecure) { if (signedPARes == String.Empty) { // check for enrollment string reqXID = sOrderNumber.PadLeft(20, '0'); // must be 20 chars esp.txn reqTxn = new esp.txn(); reqTxn.xid = reqXID; reqTxn.amount = sAmount; reqTxn.pan = CardNumber; reqTxn.expdate = expire_date; reqTxn.MD = sOrderNumber; reqTxn.merchantUrl = string.Format("{0}{1}", AppLogic.GetStoreHTTPLocation(useSsl: true, includeScriptLocation: true, noVirtualNoSlash: true), DependencyResolver.Current.GetService <UrlHelper>().Action( actionName: ActionNames.ThreeDSecureReturn, controllerName: ControllerNames.ThreeDSecure)); reqTxn.accept = CommonLogic.ServerVariables("HTTP_ACCEPT"); reqTxn.userAgent = CommonLogic.ServerVariables("HTTP_USER_AGENT"); string resultMPI = sendRequestMPI(useLiveTransactions, reqTxn); esp.MpiResponse respMPI = null; if (resultMPI != null) { respMPI = DeserializeResponseMPI(resultMPI); } if (respMPI != null) { TransactionResponse = XmlCommon.PrettyPrintXml(resultMPI); if (respMPI.message == "Y") { // enrolled, must authenticate cSession["3DSecure.CustomerID"] = CustomerID.ToString(); cSession["3DSecure.OrderNumber"] = sOrderNumber; cSession["3DSecure.MD"] = sOrderNumber; cSession["3DSecure.ACSUrl"] = respMPI.ACSUrl; cSession["3DSecure.paReq"] = respMPI.PaReq; cSession["3DSecure.XID"] = reqXID; cSession.UpdateCustomerSession(null, null); result = AppLogic.ro_3DSecure; // This is what triggers the 3D Secure IFRAME to be used. return(result); } else if (respMPI.message == "N") { // not enrolled crypt = "6"; } else if (respMPI.message == "U") { // non-participating card type crypt = "7"; } } } else { // this is round two for authenticated buyers esp.acs reqACS = new esp.acs(); reqACS.MD = sOrderNumber; reqACS.PaRes = signedPARes; string resultMPI = sendRequestMPI(useLiveTransactions, reqACS); esp.MpiResponse respMPI = null; if (resultMPI != null) { respMPI = DeserializeResponseMPI(resultMPI); } if (respMPI != null) { TransactionResponse = XmlCommon.PrettyPrintXml(resultMPI); if (respMPI.message == "Y") { // fully authenticated CAVV = respMPI.cavv; crypt = "5"; } else if (respMPI.message == "A") { // attempted to verify CAVV = respMPI.cavv; crypt = "6"; } else if (respMPI.message == "N") { // failed to verify return("Authentication failed. Please try again or choose a different payment method."); } if (CAVV.Length != 0) { // encode it to store in the session, it will be decoded before being saved to the database byte[] str = Encoding.UTF8.GetBytes("MPI=" + respMPI.message + ", CAVV=" + CAVV); cSession["3DSecure.LookupResult"] = Convert.ToBase64String(str); } } } } esp.billing bill = new AspDotNetStorefrontGateways.Processors.esp.billing(); bill.first_name = UseBillingAddress.FirstName; bill.last_name = UseBillingAddress.LastName; bill.company_name = UseBillingAddress.Company; bill.address = UseBillingAddress.Address1; bill.city = UseBillingAddress.City; bill.province = UseBillingAddress.State; bill.postal_code = UseBillingAddress.Zip; bill.country = UseBillingAddress.Country; bill.phone_number = UseBillingAddress.Phone; esp.shipping ship = null; if (UseShippingAddress != null) { ship = new esp.shipping(); ship.first_name = UseShippingAddress.FirstName; ship.last_name = UseShippingAddress.LastName; ship.company_name = UseShippingAddress.Company; ship.address = UseShippingAddress.Address1; ship.city = UseShippingAddress.City; ship.province = UseShippingAddress.State; ship.postal_code = UseShippingAddress.Zip; ship.country = UseShippingAddress.Country; ship.phone_number = UseShippingAddress.Phone; } esp.cust_info cst = new esp.cust_info(); cst.billing = bill; cst.shipping = ship; cst.email = UseBillingAddress.EMail; esp.avs_info avs = null; if (AppLogic.AppConfigBool("eSelectPlus.includeAVS")) { avs = new esp.avs_info(); int iSpace = UseBillingAddress.Address1.IndexOf(" "); if (iSpace > 0) { avs.avs_street_number = UseBillingAddress.Address1.Substring(0, iSpace); avs.avs_street_name = UseBillingAddress.Address1.Substring(iSpace + 1); } else { avs.avs_street_name = UseBillingAddress.Address1; } avs.avs_zipcode = UseBillingAddress.Zip; } esp.cvd_info cvd = null; if (CardExtraCode.Trim().Length != 0) { cvd = new esp.cvd_info(); cvd.cvd_indicator = "1"; cvd.cvd_value = CardExtraCode.Trim(); } object oReqItem = null; if (TransactionMode == TransactionModeEnum.auth) { if (CAVV.Length != 0) { esp.cavv_preauth cavvPreAuth = new esp.cavv_preauth(); cavvPreAuth.order_id = sOrderNumber; cavvPreAuth.cust_id = CustomerID.ToString(); cavvPreAuth.amount = sAmount; cavvPreAuth.pan = CardNumber; cavvPreAuth.expdate = expire_date; cavvPreAuth.cavv = CAVV; cavvPreAuth.avs_info = avs; cavvPreAuth.cvd_info = cvd; cavvPreAuth.cust_info = cst; oReqItem = cavvPreAuth; } else { esp.preauth preAuthTxn = new esp.preauth(); preAuthTxn.order_id = sOrderNumber; preAuthTxn.cust_id = CustomerID.ToString(); preAuthTxn.amount = sAmount; preAuthTxn.pan = CardNumber; preAuthTxn.expdate = expire_date; preAuthTxn.avs_info = avs; preAuthTxn.cvd_info = cvd; preAuthTxn.cust_info = cst; preAuthTxn.crypt_type = crypt; oReqItem = preAuthTxn; } } else { if (CAVV.Length != 0) { esp.cavv_purchase cavvPurchase = new esp.cavv_purchase(); cavvPurchase.order_id = sOrderNumber; cavvPurchase.cust_id = CustomerID.ToString(); cavvPurchase.amount = sAmount; cavvPurchase.pan = CardNumber; cavvPurchase.expdate = expire_date; cavvPurchase.cavv = CAVV; cavvPurchase.avs_info = avs; cavvPurchase.cvd_info = cvd; cavvPurchase.cust_info = cst; oReqItem = cavvPurchase; } else { esp.purchaseTxn purchaseTxn = new esp.purchaseTxn(); purchaseTxn.order_id = sOrderNumber; purchaseTxn.cust_id = CustomerID.ToString(); purchaseTxn.amount = sAmount; purchaseTxn.pan = CardNumber; purchaseTxn.expdate = expire_date; purchaseTxn.crypt_type = crypt; purchaseTxn.avs_info = avs; purchaseTxn.cvd_info = cvd; purchaseTxn.cust_info = cst; oReqItem = purchaseTxn; } } try { string sResponse = sendRequest(useLiveTransactions, oReqItem); esp.response resp = null; if (sResponse != null) { resp = DeserializeResponse(sResponse); if (resp != null) { TransactionResponse = XmlCommon.PrettyPrintXml(sResponse); esp.receipt respReceipt = (esp.receipt)resp.receipt[0]; result = respReceipt.Message; AuthorizationCode = respReceipt.AuthCode; if (AuthorizationCode == null) { AuthorizationCode = String.Empty; } try { AuthorizationResult = (System.Int32.Parse(respReceipt.ResponseCode).ToString()); if (AuthorizationResult == null) { AuthorizationResult = String.Empty; } } catch { AuthorizationResult = String.Empty; } AuthorizationTransID = respReceipt.TransID; if (AuthorizationTransID == null || AuthorizationTransID == "null") { AuthorizationTransID = String.Empty; } AVSResult = respReceipt.AvsResultCode; if (AVSResult == null || AVSResult == "null") { AVSResult = String.Empty; } if (respReceipt.CvdResultCode != null && respReceipt.CvdResultCode != "null") { AVSResult += ", CVD Result: " + respReceipt.CvdResultCode; } if (AuthorizationResult != String.Empty && System.Int32.Parse(AuthorizationResult) < 50) { result = AppLogic.ro_OK; if (crypt != AppLogic.AppConfig("eSelectPlus.crypt")) { // we need to store the crypt if it is not the default value // this gets parsed elsewhere so don't modify unless you know what you are doing AuthorizationCode += ", " + cryptLabel + crypt; } } else { result = AppLogic.GetString("gw.moneris.code." + AuthorizationResult, UseBillingAddress.SkinID, UseBillingAddress.LocaleSetting); if (result == "gw.moneris.code." + AuthorizationResult) { result = "Card not accepted. Please try again or choose a different payment method."; } } } else { // failed to Deserialize result = "System error. Unexpected response from payment gateway."; } } else { // failed to communicate result = "System error. Failed to communicate to payment gateway."; return(result); } } catch { result = "System error. Communications to payment gateway aborted unexpectedly."; } if (result != AppLogic.ro_OK && TransactionResponse.Length == 0) { TransactionResponse = result; } return(result); }
public override String VoidOrder(int OrderNumber) { String result = "error"; string crypt = AppLogic.AppConfig("eSelectPlus.crypt"); string txn_number = string.Empty; string authCode = string.Empty; bool useLiveTransactions = AppLogic.AppConfigBool("UseLiveTransactions"); DB.ExecuteSQL("update orders set VoidTXCommand=NULL, VoidTXResult=NULL where OrderNumber=" + OrderNumber.ToString()); using (var connn = DB.dbConn()) { connn.Open(); using (var rsv = DB.GetRS("select AuthorizationPNREF, AuthorizationCode from Orders where OrderNumber=" + OrderNumber.ToString(), connn)) { if (rsv.Read()) { txn_number = DB.RSField(rsv, "AuthorizationPNREF"); authCode = DB.RSField(rsv, "AuthorizationCode"); } } } if (authCode.Contains(cryptLabel)) { crypt = authCode.Substring(authCode.IndexOf(cryptLabel) + cryptLabel.Length, 1); } esp.purchasecorrection reqCorrection = new esp.purchasecorrection(); reqCorrection.order_id = OrderNumber.ToString(); reqCorrection.txn_number = txn_number; reqCorrection.crypt_type = crypt; StringBuilder transactionCommand = new StringBuilder(4096); transactionCommand.Append("x_type=VOID"); transactionCommand.Append("&x_customer_ip=" + CommonLogic.CustomerIpAddress()); transactionCommand.Append("&x_trans_id=" + txn_number); try { string sResponse = sendRequest(useLiveTransactions, reqCorrection); esp.response resp = null; if (sResponse != null) { resp = DeserializeResponse(sResponse); } if (resp != null) { esp.receipt respReceipt = (esp.receipt)resp.receipt[0]; StringBuilder tps = new StringBuilder(""); tps.Append("update orders set "); tps.Append("VoidTXResult=" + DB.SQuote(respReceipt.Complete) + ","); tps.Append("VoidTXCommand=" + DB.SQuote(transactionCommand.ToString())); tps.Append(" where ordernumber=" + OrderNumber.ToString()); DB.ExecuteSQL(tps.ToString()); if (respReceipt.Complete == "true") { result = AppLogic.ro_OK; } else { result = respReceipt.Message; } } } catch { result = "failed"; } return(result); }