public void TestWebCheckout() { PayuEntity payuEntity = new PayuEntity() { actionUrld = actionUrl, merchantId = "508029", accountId = "512323", description = "Starbucks", referenceCode = "coffee-" + new Random().Next(100000).ToString(), amount = "100", tax = "18", taxReturnBase = "0", currency = "PEN", signature = "", test = "0", buyerEmail = "*****@*****.**", responseUrl = "https://chaosmonkey.la", confirmationUrl = "https://www.google.com/", APIKey = "4Vj8eK4rloUd272L48hsrarnUA" }; try { CreateHTMLFile(payuEntity); VISAPayment(payuEntity); Assert.Pass(); } catch (System.Exception e) { Console.WriteLine("Error Message: " + e.Message); //Assert.Fail(); //throw; } }
public void CreateHTMLFile(PayuEntity payuEntity) { using (FileStream fs = new FileStream(testHtml, FileMode.Create)) { using (StreamWriter w = new StreamWriter(fs, Encoding.UTF8)) { string form = "<form method='post' action='" + payuEntity.actionUrld + "/'>" + "<input name='merchantId' type='hidden' value='" + payuEntity.merchantId + "' > " + "<input name='accountId' type='hidden' value='" + payuEntity.accountId + "' >" + "<input name='description' type='hidden' value='" + payuEntity.description + "' >" + "<input name='referenceCode' type='hidden' value='" + payuEntity.referenceCode + "' >" + "<input name='amount' type='hidden' value='" + payuEntity.amount + "' >" + "<input name='tax' type='hidden' value='" + payuEntity.tax + "' >" + "<input name='taxReturnBase' type='hidden' value='" + payuEntity.taxReturnBase + "' >" + "<input name='currency' type='hidden' value='" + payuEntity.currency + "' >" + "<input name='signature' type='hidden' value='" + GetSignature(payuEntity) + "' >" + "<input name='test' type='hidden' value='" + payuEntity.test + "' >" + "<input name='buyerEmail' type='hidden' value='" + payuEntity.buyerEmail + "' >" + "<input name='responseUrl' type='hidden' value='" + payuEntity.responseUrl + "' >" + "<input name='confirmationUrl' type='hidden' value='" + payuEntity.confirmationUrl + "' >" + "<input name='Submit' type='submit' value='Procesar con PAY U' > " + "</form>"; w.WriteLine(form); } } }
public void VISAPayment(PayuEntity payuEntity) { using (IWebDriver driver = new ChromeDriver()) { WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); driver.Navigate().GoToUrl(testUrl); var btnSummit = driver.FindElement(By.Name("Submit")); btnSummit.Click(); Thread.Sleep(5000); var visa = driver.FindElement(By.Id("pm-VISA")); visa.Click(); var fullName = driver.FindElement(By.Name("fullName")); fullName.SendKeys("Carlos Hidalgo"); var documentType = driver.FindElement(By.Name("documentType")); documentType.SendKeys("DNI"); var dniNumber = driver.FindElement(By.Name("dniNumber")); dniNumber.SendKeys("42172764"); var addCreditCardNumber = driver.FindElement(By.Name("addCreditCardNumber")); addCreditCardNumber.SendKeys("4213550085154432"); var securityCode = driver.FindElement(By.Name("securityCode")); securityCode.SendKeys("621"); var expirationMonth = driver.FindElement(By.Name("expirationMonth")); expirationMonth.SendKeys("2"); var expirationYear = driver.FindElement(By.Name("expirationYear")); expirationYear.SendKeys("25"); var installments = driver.FindElement(By.Name("installments")); installments.SendKeys("1"); var contactPhone = driver.FindElement(By.Name("contactPhone")); contactPhone.SendKeys("940375749"); /*var tandc = driver.FindElement(By.Name("tandc")); * contactPhone.Click();*/ Thread.Sleep(3000); var buyer_data_button_pay = driver.FindElement(By.Id("buyer_data_button_pay")); buyer_data_button_pay.Click(); Thread.Sleep(10000); } }
public string GetSignature(PayuEntity payuEntity) { string url = "http://developers.payulatam.com/es/web_checkout/integration.html"; using (IWebDriver driver = new ChromeDriver()) { WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); driver.Navigate().GoToUrl(url); //Remove ReadOnly Properties IJavaScriptExecutor js = (IJavaScriptExecutor)driver; js.ExecuteScript("document.querySelector('#signature_generated').removeAttribute('readonly')"); var signature_apikey = driver.FindElement(By.Id("signature_apikey")); signature_apikey.SendKeys("4Vj8eK4rloUd272L48hsrarnUA"); var signature_merchanId = driver.FindElement(By.Id("signature_merchanId")); signature_merchanId.SendKeys(payuEntity.merchantId); var signature_referenceCode = driver.FindElement(By.Id("signature_referenceCode")); signature_referenceCode.SendKeys(payuEntity.referenceCode); var signature_amount = driver.FindElement(By.Id("signature_amount")); signature_amount.SendKeys(payuEntity.amount); var signature_currency = driver.FindElement(By.Id("signature_currency")); signature_currency.SendKeys(payuEntity.currency); //Generate Signature var signature_generate = driver.FindElement(By.Id("signature_generate")); signature_generate.Click(); js.ExecuteScript("document.querySelector('#signature_generated').value"); var signature = driver.FindElement(By.CssSelector("#signature_generated")).GetAttribute("value"); return(signature); } }