public void PreRisQHardErrorExpected() { Inquiry inquiry = TestHelper.CreateInquiry(KHASH_PTOK, out _sid, out _orderNum); inquiry.SetParameter("PTOK", Khash.HashPaymentToken("BADPTOK")); inquiry.SetGender('M'); // set CART with one item var cart = new ArrayList(); cart.Add(new CartItem("cart item 0 type", "cart item 0", "cart item 0 description", 10, 1000)); inquiry.SetCart(cart); Response response = inquiry.GetResponse(); var mode = response.GetMode(); Assert.True("E".Equals(mode), $"Update failed! Wrong response mode {mode}."); // optional getter var errors = response.GetErrors(); Assert.True(errors.Count == 1, "Wrong responce expected error_num: 332, ERROR_COUNT=1"); var err0 = errors[0]; string errCode = err0.Substring(0, 3); Assert.True(err0.Contains("332 BAD_CARD Cause: [PTOK invalid format], Field: [PTOK], Value: [hidden]"), $"Wrong error value: {err0}, expected 332"); }
/// <summary> /// Set the payment token. /// </summary> /// <param name="token">Payment token</param> protected void SetPaymentToken(string token) { string raw = token; if (null != token && !this.Data.Contains("LAST4")) { if (token.Length > 4) { this.Data["LAST4"] = token.Substring(token.Length - 4); } else { this.Data["LAST4"] = token; } } if (this.IsSetKhashPaymentEncoding()) { token = ("GIFT".Equals(this.Data["PTYP"])) ? Khash.HashGiftCard((int)this.Data["MERC"], token) : Khash.HashPaymentToken(token); } this.Data["PTOK"] = token; }
/// <summary> /// Construct a request object. Set the static setting from the /// web.config file. /// </summary> /// <param name="checkConfiguration">By default is true: will check config file if /// `Ris.Url`, /// `Ris.MerchantId`, /// `Ris.Config.Key` are set.</param> /// <param name="configuration">Instance of configuration.</param> /// <exception cref="Kount.Ris.RequestException">Thrown when there is /// static data missing for a RIS request.</exception> protected Request(bool checkConfiguration, Configuration configuration) { var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); IConfigurationRoot cconfiguration = builder.Build(); configuration.ConnectTimeout = "10000"; if (checkConfiguration) { this.CheckConfigurationParameter(configuration.MerchantId, nameof(configuration.MerchantId)); this.CheckConfigurationParameter(configuration.URL, nameof(configuration.URL)); this.CheckConfigurationParameter(configuration.ConfigKey, nameof(configuration.ConfigKey)); } // timeout must be always defined this.CheckConfigurationParameter(configuration.ConnectTimeout, nameof(configuration.ConnectTimeout)); logTimeElapsed = (String.IsNullOrEmpty(cconfiguration.GetConnectionString("LOG.SIMPLE.ELAPSED")) ? false : cconfiguration.GetConnectionString("LOG.SIMPLE.ELAPSED").Trim().ToLower().Equals("on")); this.data = new System.Collections.Hashtable(); this.SetMerchantId(Int32.Parse(configuration.MerchantId)); Khash.ConfigKey = Khash.GetBase85ConfigKey(configuration.ConfigKey); var risVersion = String.IsNullOrEmpty(configuration.Version) ? RisVersion : configuration.Version; this.SetVersion(risVersion); this.SetUrl(configuration.URL); this.connectTimeout = Int32.Parse(configuration.ConnectTimeout); if (!String.IsNullOrEmpty(configuration.ApiKey)) { this.SetApiKey(configuration.ApiKey); } else { this.CheckConfigurationParameter(configuration.CertificateFile, nameof(configuration.CertificateFile)); this.CheckConfigurationParameter(configuration.PrivateKeyPassword, nameof(configuration.PrivateKeyPassword)); this.SetCertificate( configuration.CertificateFile, configuration.PrivateKeyPassword); } // KHASH payment encoding is set by default. this.SetKhashPaymentEncoding(true); }
/// <summary> /// Construct a request object. Set the static setting from the /// web.config file. /// </summary> /// <param name="checkConfiguration">By default is true: will check config file if /// `Ris.Url`, /// `Ris.MerchantId`, /// `Ris.Config.Key` are set.</param> /// <param name="configuration">Instance of configuration.</param> /// <exception cref="Kount.Ris.RequestException">Thrown when there is /// static data missing for a RIS request.</exception> protected Request(bool checkConfiguration, Configuration configuration) { XmlDocument log4netConfig = new XmlDocument(); log4netConfig.Load(System.IO.File.OpenRead("log4net.config")); var repo = log4net.LogManager.CreateRepository( Assembly.GetEntryAssembly(), typeof(log4net.Repository.Hierarchy.Hierarchy)); log4net.Config.XmlConfigurator.Configure(repo, log4netConfig["log4net"]); if (checkConfiguration) { this.CheckConfigurationParameter(configuration.MerchantId, nameof(configuration.MerchantId)); this.CheckConfigurationParameter(configuration.URL, nameof(configuration.URL)); this.CheckConfigurationParameter(configuration.ConfigKey, nameof(configuration.ConfigKey)); } this.CheckConfigurationParameter(configuration.ConnectTimeout, nameof(configuration.ConnectTimeout)); logTimeElapsed = (String.IsNullOrEmpty(configuration.LogSimpleElapsed) ? false : configuration.LogSimpleElapsed.Trim().ToLower().Equals("on")); this.data = new System.Collections.Hashtable(); this.SetMerchantId(Int32.Parse(configuration.MerchantId)); Khash.ConfigKey = Khash.GetBase85ConfigKey(configuration.ConfigKey); var risVersion = String.IsNullOrEmpty(configuration.Version) ? RisVersion : configuration.Version; this.SetVersion(risVersion); this.SetUrl(configuration.URL); this.connectTimeout = Int32.Parse(configuration.ConnectTimeout); if (!String.IsNullOrEmpty(configuration.ApiKey)) { this.SetApiKey(configuration.ApiKey); } else { this.CheckConfigurationParameter(configuration.CertificateFile, nameof(configuration.CertificateFile)); this.CheckConfigurationParameter(configuration.PrivateKeyPassword, nameof(configuration.PrivateKeyPassword)); this.SetCertificate( configuration.CertificateFile, configuration.PrivateKeyPassword); } // KHASH payment encoding is set by default. this.SetKhashPaymentEncoding(true); }
/// <summary> /// Construct a request object. Set the static setting from the /// web.config file. /// </summary> /// <param name="checkConfiguration">By default is true: will check config file if /// `Ris.Url`, /// `Ris.MerchantId`, /// `Ris.Config.Key` are set.</param> /// <param name="configuration">Instance of configuration.</param> /// <exception cref="Kount.Ris.RequestException">Thrown when there is /// static data missing for a RIS request.</exception> protected Request(bool checkConfiguration, Configuration configuration) { ILoggerFactory factory = LogFactory.GetLoggerFactory(); this.logger = factory.GetLogger(typeof(Request).ToString()); if (checkConfiguration) { this.CheckConfigurationParameter(configuration.MerchantId, nameof(configuration.MerchantId)); this.CheckConfigurationParameter(configuration.URL, nameof(configuration.URL)); this.CheckConfigurationParameter(configuration.ConfigKey, nameof(configuration.ConfigKey)); } // timeout must be always defined this.CheckConfigurationParameter(configuration.ConnectTimeout, nameof(configuration.ConnectTimeout)); this.data = new System.Collections.Hashtable(); this.SetMerchantId(Int32.Parse(configuration.MerchantId)); Khash.ConfigKey = Khash.GetBase85ConfigKey(configuration.ConfigKey); var risVersion = String.IsNullOrEmpty(configuration.Version) ? RisVersion : configuration.Version; this.SetVersion(risVersion); this.SetUrl(configuration.URL); this.connectTimeout = Int32.Parse(configuration.ConnectTimeout); if (!String.IsNullOrEmpty(configuration.ApiKey)) { this.SetApiKey(configuration.ApiKey); } else { this.CheckConfigurationParameter(configuration.CertificateFile, nameof(configuration.CertificateFile)); this.CheckConfigurationParameter(configuration.PrivateKeyPassword, nameof(configuration.PrivateKeyPassword)); this.SetCertificate( configuration.CertificateFile, configuration.PrivateKeyPassword); } // KHASH payment encoding is set by default. this.SetKhashPaymentEncoding(true); }
/// <summary> /// Construct a request object. Set the static setting from the /// web.config file. /// </summary> /// <param name="checkConfiguration">By default is true: will check config file if /// `Ris.Url`, /// `Ris.MerchantId`, /// `Ris.Config.Key` are set.</param> /// <param name="configuration">Instance of configuration.</param> /// <exception cref="Kount.Ris.RequestException">Thrown when there is /// static data missing for a RIS request.</exception> protected Request(bool checkConfiguration, Configuration configuration) { if (checkConfiguration) { this.CheckConfigurationParameter(configuration.MerchantId, nameof(configuration.MerchantId)); this.CheckConfigurationParameter(configuration.URL, nameof(configuration.URL)); this.CheckConfigurationParameter(configuration.ConfigKey, nameof(configuration.ConfigKey)); } this.CheckConfigurationParameter(configuration.ConnectTimeout, nameof(configuration.ConnectTimeout)); logTimeElapsed = (String.IsNullOrEmpty(configuration.LogSimpleElapsed) ? false : configuration.LogSimpleElapsed.Trim().ToLower().Equals("on")); this.data = new System.Collections.Hashtable(); this.SetMerchantId(Int32.Parse(configuration.MerchantId)); Khash.ConfigKey = Khash.GetBase85ConfigKey(configuration.ConfigKey); var risVersion = String.IsNullOrEmpty(configuration.Version) ? RisVersion : configuration.Version; this.SetVersion(risVersion); this.SetUrl(configuration.URL); this.connectTimeout = Int32.Parse(configuration.ConnectTimeout); if (!String.IsNullOrEmpty(configuration.ApiKey)) { this.SetApiKey(configuration.ApiKey); } else { this.CheckConfigurationParameter(configuration.CertificateFile, nameof(configuration.CertificateFile)); this.CheckConfigurationParameter(configuration.PrivateKeyPassword, nameof(configuration.PrivateKeyPassword)); this.SetCertificate( configuration.CertificateFile, configuration.PrivateKeyPassword); } // KHASH payment encoding is set by default. this.SetKhashPaymentEncoding(true); }
public void PreRisQHardSoftErrorsExpected() { Inquiry inquiry = TestHelper.CreateInquiry(KHASH_PTOK, out _sid, out _orderNum); //inquiry.SetPayment(PTYP, "BADPTOK"); inquiry.SetParameter("PTOK", Khash.HashPaymentToken("BADPTOK")); inquiry.SetUserDefinedField("UDF_DOESNOTEXIST", "throw a warning please!"); // set CART with one item var cart = new ArrayList(); cart.Add(new CartItem("cart item 0 type", "cart item 0", "cart item 0 description", 10, 1000)); inquiry.SetCart(cart); Response response = inquiry.GetResponse(false); var mode = response.GetMode(); Assert.True("E".Equals(mode), $"Update failed! Wrong response mode {mode}."); // optional getter var errors = response.GetErrors(); Assert.True(errors.Count == 1, "Wrong responce expected error_num: 332, ERROR_COUNT=1"); var err0 = errors[0]; Assert.True(err0.Contains("332 BAD_CARD Cause: [PTOK invalid format], Field: [PTOK], Value: [hidden]"), $"Wrong error content: {err0}, expected 332."); var warnings = response.GetWarnings(); Assert.True(warnings.Count == 2, $"Wrong number of warnings: {warnings.Count}, expected 2."); List <string> listResponce = new List <string>(Regex.Split(response.ToString(), "[\r\n]+")); var filteredList = listResponce.FindAll(i => i.Contains("WARNING_")); var w1 = filteredList.Find(r => r.Contains("[UDF_DOESNOTEXIST=>throw a warning please!]")); var w2 = filteredList.Find(r => r.Contains("[The label [UDF_DOESNOTEXIST] is not defined for merchant ID [999666].]")); Assert.True(w1 != null, $"Inquiry failed! The value {warnings[0]} of warning is wrong!"); Assert.True(w2 != null, $"Inquiry failed! The value {warnings[1]} of warning is wrong!"); }
public void MaskModeUAfterModeQ() { Inquiry inquiry = TestHelper.CreateInquiryMasked(PTOK, out _sid, out _orderNum); // set CART with one item var cart = new ArrayList(); cart.Add(new CartItem("cart item 0 type", "cart item 0", "cart item 0 description", 10, 1234)); inquiry.SetCart(cart); Response response = inquiry.GetResponse(); // optional getter var errors = response.GetErrors(); Assert.IsTrue(errors.Count == 0, String.Join(Environment.NewLine, errors, "There are errors in response!")); var sessID = response.GetSessionId(); var tranID = response.GetTransactionId(); var ordNum = response.GetOrderNumber(); Update update = new Update(false); update.SetMode(UpdateTypes.ModeU); update.SetVersion("0695"); update.SetMerchantId(TestHelper.TEST_MERCHANT_ID); update.SetApiKey(TestHelper.TEST_API_KEY); update.SetSessionId(sessID); update.SetTransactionId(tranID); update.SetOrderNumber(ordNum); update.SetParameter("PTOK", Khash.HashPaymentToken("5386460135176807")); update.SetPaymentTokenLast4("6807"); update.SetMack('Y'); update.SetAuth('A'); update.SetAvst('M'); update.SetAvsz('M'); update.SetCvvr('M'); response = update.GetResponse(); errors = response.GetErrors(); Assert.IsTrue(errors.Count == 0, String.Join(Environment.NewLine, errors, "There are errors in response!")); var mode = response.GetMode(); Assert.IsTrue("U".Equals(mode), $"Update failed! Wrong response mode {mode}."); Assert.IsTrue(sessID.Equals(response.GetSessionId()), $"Update failed! Wrong session ID {sessID}."); Assert.IsTrue(tranID.Equals(response.GetTransactionId()), $"Update failed! Wrong Transaction Id {tranID}."); var ordU = response.GetOrderNumber(); // orderNum is null var auto = response.GetAuto(); Assert.IsTrue(auto == null, $"Inquiry failed! Approval status {auto} is not null"); var scor = response.GetScore(); Assert.IsTrue(scor == null, $"Inquiry failed! Score {scor} is not null"); var geox = response.GetGeox(); Assert.IsTrue(geox == null, $"Inquiry failed! GEOX {geox} is not null"); }
/// <summary> /// Construct a request object. Set the static setting from the /// web.config file. /// </summary> /// <param name="checkConfiguration">By default is true: will check config file if /// `Ris.Url`, /// `Ris.MerchantId`, /// `Ris.Config.Key` are set.</param> /// <param name="configuration">Instance of configuration.</param> /// <exception cref="Kount.Ris.RequestException">Thrown when there is /// static data missing for a RIS request.</exception> protected Request(bool checkConfiguration, Configuration configuration) { XmlDocument log4netConfig = new XmlDocument(); log4netConfig.Load(System.IO.File.OpenRead("log4net.config")); var repo = log4net.LogManager.CreateRepository( Assembly.GetEntryAssembly(), typeof(log4net.Repository.Hierarchy.Hierarchy)); log4net.Config.XmlConfigurator.Configure(repo, log4netConfig["log4net"]); var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); IConfigurationRoot cconfiguration = builder.Build(); configuration.ConnectTimeout = "10000"; //ILoggerFactory factory = LogFactory.GetLoggerFactory(); //logger = factory.GetLogger(typeof(Request).ToString()); if (checkConfiguration) { this.CheckConfigurationParameter(configuration.MerchantId, nameof(configuration.MerchantId)); this.CheckConfigurationParameter(configuration.URL, nameof(configuration.URL)); this.CheckConfigurationParameter(configuration.ConfigKey, nameof(configuration.ConfigKey)); } // timeout must be always defined this.CheckConfigurationParameter(configuration.ConnectTimeout, nameof(configuration.ConnectTimeout)); this.data = new System.Collections.Hashtable(); this.SetMerchantId(Int32.Parse(configuration.MerchantId)); Khash.ConfigKey = Khash.GetBase85ConfigKey(configuration.ConfigKey); var risVersion = String.IsNullOrEmpty(configuration.Version) ? RisVersion : configuration.Version; this.SetVersion(risVersion); this.SetUrl(configuration.URL); this.connectTimeout = Int32.Parse(configuration.ConnectTimeout); if (!String.IsNullOrEmpty(configuration.ApiKey)) { this.SetApiKey(configuration.ApiKey); } else { this.CheckConfigurationParameter(configuration.CertificateFile, nameof(configuration.CertificateFile)); this.CheckConfigurationParameter(configuration.PrivateKeyPassword, nameof(configuration.PrivateKeyPassword)); this.SetCertificate( configuration.CertificateFile, configuration.PrivateKeyPassword); } // KHASH payment encoding is set by default. this.SetKhashPaymentEncoding(true); }