// returns true if no errors, and card is enrolled: static public bool PreChargeLookup(string cardNumber, int cardExpirationYear, int cardExpirationMonth, int orderNumber, decimal orderTotal, string orderDescription, out string acsUrl, out string payload, out string transactionId, out string cardinalLookupResult) { var ccRequest = new CardinalCommerce.CentinelRequest(); var ccResponse = new CardinalCommerce.CentinelResponse(); var numAttempts = AppLogic.AppConfigUSInt("CardinalCommerce.Centinel.NumRetries"); var callSucceeded = false; payload = string.Empty; acsUrl = String.Empty; transactionId = String.Empty; // ================================================================================== // Construct the cmpi_lookup message // ================================================================================== ccRequest.add("MsgType", AppLogic.AppConfig("CardinalCommerce.Centinel.MsgType.Lookup")); ccRequest.add("Version", "1.7"); ccRequest.add("ProcessorId", AppLogic.AppConfig("CardinalCommerce.Centinel.ProcessorID")); ccRequest.add("MerchantId", AppLogic.AppConfig("CardinalCommerce.Centinel.MerchantID")); ccRequest.add("TransactionPwd", AppLogic.AppConfig("CardinalCommerce.Centinel.TransactionPwd")); ccRequest.add("TransactionType", "C"); //C = Credit Card / Debit Card Authentication. ccRequest.add("Amount", Localization.CurrencyStringForGatewayWithoutExchangeRate(orderTotal).Replace(",", "").Replace(".", "")); ccRequest.add("CurrencyCode", Localization.StoreCurrencyNumericCode()); ccRequest.add("CardNumber", cardNumber); ccRequest.add("CardExpMonth", cardExpirationMonth.ToString().PadLeft(2, '0')); ccRequest.add("CardExpYear", cardExpirationYear.ToString().PadLeft(4, '0')); ccRequest.add("OrderNumber", orderNumber.ToString()); // Optional fields ccRequest.add("OrderDescription", orderDescription); ccRequest.add("UserAgent", CommonLogic.ServerVariables("HTTP_USER_AGENT")); ccRequest.add("Recurring", "N"); if (numAttempts == 0) { numAttempts = 1; } for (int i = 1; i <= numAttempts; i++) { callSucceeded = true; try { var URL = AppLogic.AppConfigBool("CardinalCommerce.Centinel.IsLive") ? AppLogic.AppConfig("CardinalCommerce.Centinel.TransactionUrl.Live") : AppLogic.AppConfig("CardinalCommerce.Centinel.TransactionUrl.Test"); ccResponse = ccRequest.sendHTTP(URL, AppLogic.AppConfigUSInt("CardinalCommerce.Centinel.MapsTimeout")); } catch { callSucceeded = false; } if (callSucceeded) { break; } } if (callSucceeded) { var errorNo = ccResponse.getValue("ErrorNo"); var enrolled = ccResponse.getValue("Enrolled"); payload = ccResponse.getValue("Payload"); acsUrl = ccResponse.getValue("ACSUrl"); transactionId = ccResponse.getValue("TransactionId"); cardinalLookupResult = ccResponse.getUnparsedResponse(); ccRequest = null; ccResponse = null; //====================================================================================== // Assert that there was no error code returned and the Cardholder is enrolled in the // Payment Authentication Program prior to starting the Authentication process. //====================================================================================== if (errorNo == "0" && enrolled == "Y") { return(true); } return(false); } ccRequest = null; ccResponse = null; cardinalLookupResult = AppLogic.GetString("cardinal.cs.1", 1, Localization.GetDefaultLocale()); return(false); }
static public string PreChargeAuthenticate(int orderNumber, string paRes, string transactionId, out string paResStatus, out string signatureVerification, out string errorNumber, out string errorDescription, out string cardinalAuthenticateResult) { var ccRequest = new CardinalCommerce.CentinelRequest(); var ccResponse = new CardinalCommerce.CentinelResponse(); var numAttempts = AppLogic.AppConfigUSInt("CardinalCommerce.Centinel.NumRetries"); var callSucceeded = false; errorNumber = string.Empty; errorDescription = string.Empty; paResStatus = string.Empty; signatureVerification = string.Empty; if (paRes.Length == 0 || transactionId.Length == 0) { cardinalAuthenticateResult = AppLogic.GetString("cardinal.cs.3", 1, Localization.GetDefaultLocale()); return(AppLogic.GetString("cardinal.cs.2", 1, Localization.GetDefaultLocale())); } else { // ================================================================================== // Construct the cmpi_authenticate message // ================================================================================== ccRequest.add("MsgType", AppLogic.AppConfig("CardinalCommerce.Centinel.MsgType.Authenticate")); //cmpi_authenticate ccRequest.add("Version", "1.7"); ccRequest.add("ProcessorId", AppLogic.AppConfig("CardinalCommerce.Centinel.ProcessorID")); ccRequest.add("MerchantId", AppLogic.AppConfig("CardinalCommerce.Centinel.MerchantID")); ccRequest.add("TransactionType", "C"); ccRequest.add("TransactionPwd", AppLogic.AppConfig("CardinalCommerce.Centinel.TransactionPwd")); ccRequest.add("TransactionId", transactionId); ccRequest.add("PAResPayload", HttpContext.Current.Server.HtmlEncode(paRes)); if (numAttempts == 0) { numAttempts = 1; } for (int i = 1; i <= numAttempts; i++) { callSucceeded = true; try { var URL = AppLogic.AppConfigBool("CardinalCommerce.Centinel.IsLive") ? AppLogic.AppConfig("CardinalCommerce.Centinel.TransactionUrl.Live") : AppLogic.AppConfig("CardinalCommerce.Centinel.TransactionUrl.Test"); ccResponse = ccRequest.sendHTTP(URL, AppLogic.AppConfigUSInt("CardinalCommerce.Centinel.MapsTimeout")); } catch { callSucceeded = false; } if (callSucceeded) { break; } } if (callSucceeded) { errorNumber = ccResponse.getValue("ErrorNo"); errorDescription = ccResponse.getValue("ErrorDesc"); paResStatus = ccResponse.getValue("PAResStatus"); signatureVerification = ccResponse.getValue("SignatureVerification"); cardinalAuthenticateResult = ccResponse.getUnparsedResponse(); var response = ccResponse.getUnparsedResponse(); return(response); } cardinalAuthenticateResult = AppLogic.GetString("cardinal.cs.4", 1, Localization.GetDefaultLocale()); return(AppLogic.GetString("cardinal.cs.5", 1, Localization.GetDefaultLocale())); } }
/// <summary> /// This is not used for getting a follow up status on check clears, but is only a backup measure if /// the browser does not return to the storefront and complete the order properly. /// </summary> static public String MyECheckStatus(String NotificationID, out String OrderId, out String PAResStatus, out String SignatureVerification, out String ErrorNo, out String ErrorDesc, out String CardinalAuthenticateResult) { CardinalCommerce.CentinelRequest ccRequest = new CardinalCommerce.CentinelRequest(); CardinalCommerce.CentinelResponse ccResponse = new CardinalCommerce.CentinelResponse(); ErrorNo = String.Empty; ErrorDesc = String.Empty; PAResStatus = String.Empty; OrderId = String.Empty; SignatureVerification = String.Empty; CardinalAuthenticateResult = String.Empty; // ================================================================================== // Construct the cmpi_payment_status message // ================================================================================== ccRequest.add("MsgType", "cmpi_payment_status"); ccRequest.add("Version", "1.7"); ccRequest.add("MerchantId", AppLogic.AppConfig("CardinalCommerce.Centinel.MerchantID")); ccRequest.add("ProcessorId", AppLogic.AppConfig("CardinalCommerce.Centinel.ProcessorID")); ccRequest.add("TransactionPwd", AppLogic.AppConfig("CardinalCommerce.Centinel.TransactionPwd")); ccRequest.add("TransactionType", "ME"); ccRequest.add("NotificationId", NotificationID); int NumAttempts = AppLogic.AppConfigUSInt("CardinalCommerce.Centinel.NumRetries"); if (NumAttempts == 0) { NumAttempts = 1; } bool CallWasOK = false; for (int i = 1; i <= NumAttempts; i++) { CallWasOK = true; try { String URL = AppLogic.AppConfig("CardinalCommerce.Centinel.TransactionUrl.Test"); if (AppLogic.AppConfigBool("CardinalCommerce.Centinel.IsLive")) { URL = AppLogic.AppConfig("CardinalCommerce.Centinel.TransactionUrl.Live"); } ccResponse = ccRequest.sendHTTP(URL, AppLogic.AppConfigUSInt("CardinalCommerce.Centinel.MapsTimeout")); } catch { CallWasOK = false; } if (CallWasOK) { break; } } if (CallWasOK) { string OrderNumber = ccResponse.getValue("OrderNumber"); ErrorNo = ccResponse.getValue("ErrorNo"); ErrorDesc = ccResponse.getValue("ErrorDesc"); OrderId = ccResponse.getValue("OrderId"); PAResStatus = ccResponse.getValue("PAResStatus"); SignatureVerification = ccResponse.getValue("SignatureVerification"); CardinalAuthenticateResult = ccResponse.getUnparsedResponse(); String tmpS = ccResponse.getUnparsedResponse(); ccRequest = null; ccResponse = null; String msg = "Failed to complete order."; if (PAResStatus.Trim().Equals("Y", StringComparison.InvariantCultureIgnoreCase)) { msg += " Customer was CHARGED but no order was created."; } String sql = "insert into FailedTransaction(CustomerID,OrderNumber,IPAddress,OrderDate,PaymentGateway,PaymentMethod,TransactionCommand,TransactionResult) values(0," + OrderNumber.ToString() + ",'',getdate(),'Cardinal'," + DB.SQuote(AppLogic.ro_PMCardinalMyECheck) + "," + DB.SQuote(msg) + "," + DB.SQuote(CardinalAuthenticateResult) + ")"; DB.ExecuteSQL(sql); return(tmpS); } else { String msg = "MyECheck notification failed."; String sql = "insert into FailedTransaction(CustomerID,OrderNumber,IPAddress,OrderDate,PaymentGateway,PaymentMethod,TransactionCommand,TransactionResult) values(0,0,'',getdate(),'Cardinal'," + DB.SQuote(AppLogic.ro_PMCardinalMyECheck) + "," + DB.SQuote(msg) + "," + DB.SQuote("NotificationId=" + NotificationID) + ")"; DB.ExecuteSQL(sql); } ccRequest = null; ccResponse = null; return("MyECheck Status Error"); }
static public String MyECheckAuthenticate(int OrderNumber, String PaRes, String TransactionID, out String OrderId, out String PAResStatus, out String SignatureVerification, out String ErrorNo, out String ErrorDesc, out String CardinalAuthenticateResult) { CardinalCommerce.CentinelRequest ccRequest = new CardinalCommerce.CentinelRequest(); CardinalCommerce.CentinelResponse ccResponse = new CardinalCommerce.CentinelResponse(); ErrorNo = String.Empty; ErrorDesc = String.Empty; PAResStatus = String.Empty; OrderId = String.Empty; SignatureVerification = String.Empty; if (PaRes.Length == 0 || TransactionID.Length == 0) { CardinalAuthenticateResult = AppLogic.GetString("cardinal.cs.8", 1, Localization.GetDefaultLocale()); return(AppLogic.GetString("cardinal.cs.7", 1, Localization.GetDefaultLocale())); } else { // ================================================================================== // Construct the cmpi_authenticate message // ================================================================================== ccRequest.add("MsgType", "cmpi_authenticate"); ccRequest.add("Version", "1.7"); ccRequest.add("MerchantId", AppLogic.AppConfig("CardinalCommerce.Centinel.MerchantID")); ccRequest.add("ProcessorId", AppLogic.AppConfig("CardinalCommerce.Centinel.ProcessorID")); ccRequest.add("TransactionPwd", AppLogic.AppConfig("CardinalCommerce.Centinel.TransactionPwd")); ccRequest.add("TransactionType", "ME"); ccRequest.add("TransactionId", TransactionID); ccRequest.add("PAResPayload", HttpContext.Current.Server.HtmlEncode(PaRes)); int NumAttempts = AppLogic.AppConfigUSInt("CardinalCommerce.Centinel.NumRetries"); if (NumAttempts == 0) { NumAttempts = 1; } bool CallWasOK = false; for (int i = 1; i <= NumAttempts; i++) { CallWasOK = true; try { String URL = AppLogic.AppConfig("CardinalCommerce.Centinel.TransactionUrl.Test"); if (AppLogic.AppConfigBool("CardinalCommerce.Centinel.IsLive")) { URL = AppLogic.AppConfig("CardinalCommerce.Centinel.TransactionUrl.Live"); } ccResponse = ccRequest.sendHTTP(URL, AppLogic.AppConfigUSInt("CardinalCommerce.Centinel.MapsTimeout")); } catch { CallWasOK = false; } if (CallWasOK) { break; } } if (CallWasOK) { ErrorNo = ccResponse.getValue("ErrorNo"); ErrorDesc = ccResponse.getValue("ErrorDesc"); OrderId = ccResponse.getValue("OrderId"); PAResStatus = ccResponse.getValue("PAResStatus"); SignatureVerification = ccResponse.getValue("SignatureVerification"); CardinalAuthenticateResult = ccResponse.getUnparsedResponse(); String tmpS = ccResponse.getUnparsedResponse(); ccRequest = null; ccResponse = null; return(tmpS); } ccRequest = null; ccResponse = null; CardinalAuthenticateResult = AppLogic.GetString("cardinal.cs.9", 1, Localization.GetDefaultLocale()); return(AppLogic.GetString("cardinal.cs.10", 1, Localization.GetDefaultLocale())); } }
static public bool MyECheckLookup(ShoppingCart cart, int OrderNumber, decimal OrderTotal, String OrderDescription, out String ACSUrl, out String Payload, out String TransactionID, out String CardinalLookupResult) { String MerchantID = AppLogic.AppConfig("CardinalCommerce.Centinel.MerchantID"); String ProcessorID = AppLogic.AppConfig("CardinalCommerce.Centinel.ProcessorID"); String TransactionPwd = AppLogic.AppConfig("CardinalCommerce.Centinel.TransactionPwd"); if (MerchantID.Length == 0) { throw new ArgumentException("You MUST set AppConfig:CardinalCommerce.Centinel.MerchantID to a valid value."); } if (ProcessorID.Length == 0) { throw new ArgumentException("You MUST set AppConfig:CardinalCommerce.Centinel.ProcessorID to a valid value."); } if (TransactionPwd.Length == 0) { throw new ArgumentException("You MUST set AppConfig:CardinalCommerce.Centinel.TransactionPwd to a valid value."); } CardinalCommerce.CentinelRequest ccRequest = new CardinalCommerce.CentinelRequest(); CardinalCommerce.CentinelResponse ccResponse = new CardinalCommerce.CentinelResponse(); // ================================================================================== // Construct the cmpi_lookup message // ================================================================================== String IPAddress = cart.ThisCustomer.LastIPAddress; ccRequest.add("MsgType", "cmpi_lookup"); ccRequest.add("Version", "1.7"); ccRequest.add("MerchantId", MerchantID); ccRequest.add("ProcessorId", ProcessorID); ccRequest.add("TransactionPwd", TransactionPwd); ccRequest.add("TransactionType", "ME"); ccRequest.add("Amount", Localization.CurrencyStringForGatewayWithoutExchangeRate(OrderTotal).Replace(",", "").Replace(".", "")); ccRequest.add("CurrencyCode", Localization.StoreCurrencyNumericCode()); ccRequest.add("IPAddress", IPAddress); ccRequest.add("EMail", cart.ThisCustomer.EMail); ccRequest.add("OrderNumber", OrderNumber.ToString()); ccRequest.add("OrderDescription", AppLogic.AppConfig("StoreName") + " Purchase"); ccRequest.add("BillingFirstName", cart.ThisCustomer.PrimaryBillingAddress.FirstName); ccRequest.add("BillingLastName", cart.ThisCustomer.PrimaryBillingAddress.LastName); ccRequest.add("BillingAddress1", cart.ThisCustomer.PrimaryBillingAddress.Address1); ccRequest.add("BillingAddress2", cart.ThisCustomer.PrimaryBillingAddress.Address2); ccRequest.add("BillingCity", cart.ThisCustomer.PrimaryBillingAddress.City); ccRequest.add("BillingState", cart.ThisCustomer.PrimaryBillingAddress.State); ccRequest.add("BillingPostalCode", cart.ThisCustomer.PrimaryBillingAddress.Zip); ccRequest.add("BillingCountryCode", AppLogic.GetCountryTwoLetterISOCode(cart.ThisCustomer.PrimaryBillingAddress.Country)); ccRequest.add("BillingPhone", cart.ThisCustomer.PrimaryBillingAddress.Phone.Replace("(", "").Replace(")", "").Replace("-", "").Replace(" ", "")); int NumAttempts = AppLogic.AppConfigUSInt("CardinalCommerce.Centinel.NumRetries"); if (NumAttempts == 0) { NumAttempts = 1; } bool CallWasOK = false; for (int i = 1; i <= NumAttempts; i++) { CallWasOK = true; try { String URL = AppLogic.AppConfig("CardinalCommerce.Centinel.TransactionUrl.Test"); if (AppLogic.AppConfigBool("CardinalCommerce.Centinel.IsLive")) { URL = AppLogic.AppConfig("CardinalCommerce.Centinel.TransactionUrl.Live"); } ccResponse = ccRequest.sendHTTP(URL, AppLogic.AppConfigUSInt("CardinalCommerce.Centinel.MapsTimeout")); } catch { CallWasOK = false; } if (CallWasOK) { break; } } Payload = String.Empty; ACSUrl = String.Empty; TransactionID = String.Empty; if (CallWasOK) { String errorNo = ccResponse.getValue("ErrorNo"); String errorDesc = ccResponse.getValue("ErrorDesc"); String enrolled = ccResponse.getValue("Enrolled"); Payload = ccResponse.getValue("Payload"); ACSUrl = ccResponse.getValue("ACSUrl"); TransactionID = ccResponse.getValue("TransactionId"); CardinalLookupResult = ccResponse.getUnparsedResponse(); //====================================================================================== // Assert that there was no error code returned and the Cardholder is enrolled in the // Payment Authentication Program prior to starting the Authentication process. //====================================================================================== if (enrolled == "Y") { return(true); } // write to Failed Transaction table String sql = "insert into FailedTransaction(CustomerID,OrderNumber,IPAddress,OrderDate,PaymentGateway,PaymentMethod,TransactionCommand,TransactionResult) values(" + cart.ThisCustomer.CustomerID.ToString() + "," + OrderNumber.ToString() + "," + DB.SQuote(IPAddress) + ",getdate(),'Cardinal'," + DB.SQuote(AppLogic.ro_PMCardinalMyECheck) + "," + DB.SQuote(ccRequest.getUnparsedRequest()) + "," + DB.SQuote(CardinalLookupResult) + ")"; DB.ExecuteSQL(sql); ccRequest = null; ccResponse = null; return(false); } CardinalLookupResult = AppLogic.GetString("cardinal.cs.6", 1, Localization.GetDefaultLocale()); String sql2 = "insert into FailedTransaction(CustomerID,OrderNumber,IPAddress,OrderDate,PaymentGateway,PaymentMethod,TransactionCommand,TransactionResult) values(" + cart.ThisCustomer.CustomerID.ToString() + "," + OrderNumber.ToString() + "," + DB.SQuote(IPAddress) + ",getdate(),'Cardinal'," + DB.SQuote(AppLogic.ro_PMCardinalMyECheck) + "," + DB.SQuote(ccRequest.getUnparsedRequest()) + "," + DB.SQuote(CardinalLookupResult) + ")"; DB.ExecuteSQL(sql2); ccRequest = null; ccResponse = null; return(false); }
static public String PreChargeAuthenticate(int OrderNumber, String PaRes, String TransactionID, out String PAResStatus, out String SignatureVerification, out String ErrorNo, out String ErrorDesc, out String CardinalAuthenticateResult) { CardinalCommerce.CentinelRequest ccRequest = new CardinalCommerce.CentinelRequest(); CardinalCommerce.CentinelResponse ccResponse = new CardinalCommerce.CentinelResponse(); ErrorNo = String.Empty; ErrorDesc = String.Empty; PAResStatus = String.Empty; SignatureVerification = String.Empty; if (PaRes.Length == 0 || TransactionID.Length == 0) { CardinalAuthenticateResult = AppLogic.GetString("cardinal.cs.3", 1, Localization.GetDefaultLocale()); return(AppLogic.GetString("cardinal.cs.2", 1, Localization.GetDefaultLocale())); } else { // ================================================================================== // Construct the cmpi_authenticate message // ================================================================================== ccRequest.add("MsgType", AppLogic.AppConfig("CardinalCommerce.Centinel.MsgType.Authenticate")); //cmpi_authenticate ccRequest.add("Version", "1.7"); ccRequest.add("ProcessorId", AppLogic.AppConfig("CardinalCommerce.Centinel.ProcessorID")); ccRequest.add("MerchantId", AppLogic.AppConfig("CardinalCommerce.Centinel.MerchantID")); ccRequest.add("TransactionType", "C"); ccRequest.add("TransactionPwd", AppLogic.AppConfig("CardinalCommerce.Centinel.TransactionPwd")); ccRequest.add("TransactionId", TransactionID); ccRequest.add("PAResPayload", HttpContext.Current.Server.HtmlEncode(PaRes)); int NumAttempts = AppLogic.AppConfigUSInt("CardinalCommerce.Centinel.NumRetries"); if (NumAttempts == 0) { NumAttempts = 1; } bool CallWasOK = false; for (int i = 1; i <= NumAttempts; i++) { CallWasOK = true; try { String URL = AppLogic.AppConfig("CardinalCommerce.Centinel.TransactionUrl.Test"); if (AppLogic.AppConfigBool("CardinalCommerce.Centinel.IsLive")) { URL = AppLogic.AppConfig("CardinalCommerce.Centinel.TransactionUrl.Live"); } ccResponse = ccRequest.sendHTTP(URL, AppLogic.AppConfigUSInt("CardinalCommerce.Centinel.MapsTimeout")); } catch { CallWasOK = false; } if (CallWasOK) { break; } } if (CallWasOK) { ErrorNo = ccResponse.getValue("ErrorNo"); ErrorDesc = ccResponse.getValue("ErrorDesc"); String cavv = ccResponse.getValue("Cavv"); String xid = ccResponse.getValue("Xid"); PAResStatus = ccResponse.getValue("PAResStatus"); SignatureVerification = ccResponse.getValue("SignatureVerification"); String eciflag = ccResponse.getValue("EciFlag"); //===================================================================================== // ************************************************************************************ // ** Important Note ** // ************************************************************************************ // // Here you should persist the authentication results to your commerce system. A production // integration should, at a minimum, write the PAResStatus, Cavv, EciFlag, Xid to a database // for use when sending the authorization message to your gateway provider. // // Be sure not to simply //pass// the authentication results around from page to page, since // the values could be easily spoofed if that technique is used. // //===================================================================================== CardinalAuthenticateResult = ccResponse.getUnparsedResponse(); String tmpS = ccResponse.getUnparsedResponse(); ccRequest = null; ccResponse = null; return(tmpS); } ccRequest = null; ccResponse = null; CardinalAuthenticateResult = AppLogic.GetString("cardinal.cs.4", 1, Localization.GetDefaultLocale()); return(AppLogic.GetString("cardinal.cs.5", 1, Localization.GetDefaultLocale())); } }