I'm trying to implement Omnipay with Sagepay Direct but am really struggling with the 3D Secure bit.
When I post the MD, PaReq and TermUrl to https://test.sagepay.com/mpitools/accesscontroler?action=pareq I just get a blank screen.
These previous SO answers suggest removing spaces from the PaReq field solves the issue, but I don't have any spaces in my data.
SagePay Direct 3DSecure checkout part returning blank page when redirecting out to bank
Sage Pay test server won't load 3D Secure page
The data returned from the Omnipay method $response->getRedirectData() is
"PaReq" => "eJxVUk1TwjAQvfsrGO52mza0lVnCoBxERqcqOuMxpqt0pB8mrRZ/vQkUweTy3svO2+xLcNoVm8EXaZNX5WTIPH84FWe4Wmui+SOpVpPAWzJGvtMgzybDwGcjn7OLmEc8CXnAgmQ0FJjOHuhTYG8krI/HEA7UOmi1lmUjUKrPy8Wd4DwKoxFCT7EgvZiLgPn7HfpuIexlLGVBYqZkRsV2RaZ5pjKrNMJOR1W1ZaO3IgkihAPBVm/EumlqMwaQdW08U1bfmur2dZMrT1Ve+wGGNm/nhvQXIbh6hONF09YhY/27PBNyef308zKLuuXdA0u71DC5DrItj2/uJwiuAjPZkLDxxH4SsgGLx2E85hxhp6Ms3MUEc1P1GGvXYnZycCqgzV5TqQ5zHRhSV1cl2YoA4Q9jRkaJR/dKqdwObtOFbewkhOMgV9cuf9XYSJmLfoecX24DYwnbGzqC4Gqhf1XoP4BF/z7GLxIJvBw="
"MD" => "20150419746483421285"
This is the HTML for the form I'm using
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<form action="https://test.sagepay.com/mpitools/accesscontroler?action=pareq" method="post">
<input name="MD" value="20150419746483421285" type="hidden">
<input name="PaReq" value="eJxVUk1TwjAQvfsrGO52mza0lVnCoBxERqcqOuMxpqt0pB8mrRZ/vQkUweTy3svO2+xLcNoVm8EXaZNX5WTIPH84FWe4Wmui+SOpVpPAWzJGvtMgzybDwGcjn7OLmEc8CXnAgmQ0FJjOHuhTYG8krI/HEA7UOmi1lmUjUKrPy8Wd4DwKoxFCT7EgvZiLgPn7HfpuIexlLGVBYqZkRsV2RaZ5pjKrNMJOR1W1ZaO3IgkihAPBVm/EumlqMwaQdW08U1bfmur2dZMrT1Ve+wGGNm/nhvQXIbh6hONF09YhY/27PBNyef308zKLuuXdA0u71DC5DrItj2/uJwiuAjPZkLDxxH4SsgGLx2E85hxhp6Ms3MUEc1P1GGvXYnZycCqgzV5TqQ5zHRhSV1cl2YoA4Q9jRkaJR/dKqdwObtOFbewkhOMgV9cuf9XYSJmLfoecX24DYwnbGzqC4Gqhf1XoP4BF/z7GLxIJvBw=" type="hidden">
<input name="TermUrl" value="https://www.example.com/payment/auth-return" type="hidden">
<center><p>Please click button below to Authenticate your card</p><input value="Go" type="submit"></center>
</form>
</body>
</html>
Do you know why I'm getting a blank page? Do I need to transform the data in some way before sending it to Sagepay?
I've tried everything I can think of but am getting nowhere.
ok, so it's magically working now....may have been a problem at Sagepay's end?
In case it's useful for someone else, here's my iFrame code...
<iframe src="secure-3d.php?acsURL=<?=$responseUrl?>&PaReq=<?=$responseData['PaReq']?>&MD=<?=$responseData['MD']?>&TermUrl=<?=$responseData['TermUrl']?>" name="secure-3d" id="secure-3d" width="100%" height="500" frameborder="0"></iframe>
...where 'secure-3d.php' is my self-submitting form as below....
<form id="cardToken" name="cardToken" action="<?=$_GET['acsURL']?>" method="post">
<input type="hidden" name="MD" value='<?=str_replace(' ','+',$_GET['MD'])?>' />
<input type="hidden" name="PaReq" value='<?=str_replace(' ','+',$_GET['PaReq'])?>' />
<input type="hidden" name="TermUrl" value='<?=str_replace(' ','+',$_GET['TermUrl'])?>' />
<noscript>
<center><p>Please click button below to Authenticate your card</p><input type="submit" value="Go"/></p></center>
</noscript>
</form>
<script language="Javascript">
var form = document.getElementById("cardToken");
form.submit();
</script>
I just pass the PaReq, MD and TermUrl data through to the form in the querystring, then you need to str_replace spaces to pluses when creating the hidden fields.
That should do it!
If anyone has any ideas on how to make this better, please comment
Related
Can anyone give me an example about to change to italian ReCaptcha questions and answers?
I found the following code:
<script type="text/javascript" src="https://www.google.com/recaptcha/api.js?hl=it" />
But no idea where to put it and all attempts to place it on my contact form failed.
It always speaks english only.
Thanks in advance
Script tags usually go in the head section, between the <head> and </head> tags, or just before the body closing tag, </body>.
However, you also need to add a tag in the form for the ReCaptcha to be show.
This code will display the ReCaptcha in Italian:
<html>
<head>
<title>reCAPTCHA demo: Simple page</title>
<script src="https://www.google.com/recaptcha/api.js?hl=it" async defer></script>
</head>
<body>
<form action="?" method="POST">
<div class="g-recaptcha" data-sitekey="your_site_key"></div>
<br/>
<input type="submit" value="Submit">
</form>
</body>
</html>
You need to replace the data-sitekey attribute with your own API sitekey.
Is it possible to create a dynamic replace in Thymeleaf?
I have the following controller:
#Controller
public class LoginController {
#RequestMapping("/login")
public String getLogin(Model model){
model.addAttribute("template","login");
return "index";
}
}
And the following view:
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" >
<head></head>
<body>
<div th:replace="fragments/${template} :: ${template}"></div>
</body>
</html>
And i'm getting the following error:
Error resolving template "fragments/${template}", template might not exist or might not be accessible by any of the configured Template Resolvers
UPDATE
I tried to preprocess my variables like this:
<div th:replace="fragments/${__#{${template}}__} :: ${__#{${template}}__}"></div>
How ever now ${template} is getting replaced with login i have the following error now:
Exception evaluating SpringEL expression: "??login_en_US??"
Although Joe Essey's solution is working as well i solved with following code:
<div th:replace="#{'fragments/' + ${template}} :: ${template}"></div>
I believe the appropriate method to manage this behavior in thymeleaf is to use layout:fragment tags. Please correct me if I'm wrong. Here is a simple example of my layout page, and the login page which is 'dynamically' loaded:
layout.html
<html xmlns:layout="http://www.w3.org/1999/xhtml" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<title layout:title-pattern="$DECORATOR_TITLE - $CONTENT_TITLE">Layout</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
</head>
<body>
<div>
<div class="app-container">
<div th:fragment="content">
</div>
</div>
</div>
<div th:fragment="script"></div>
</body>
</html>
Then, when login gets loaded, it replaces the th:fragment div with the associated div in the html view which matches the string returned by the controller method, in this case login.html:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.w3.org/1999/xhtml"
layout:decorator="layout">
<head>
<title>Login</title>
</head>
<body>
<div th:fragment="content">
<form th:action="#{/login}" method="post">
<div><label> User Name : <input type="text" name="username"/> </label></div>
<div><label> Password: <input type="password" name="password"/> </label></div>
<div><input type="submit" value="Sign In"/></div>
</form>
</div>
</body>
</html>
Now, if you want to load another fragment conditionally, the approach I take is to add replace tags with th:if cases. Here's an example of a Form that displays different questions based on an attribute of the current user:
<div th:if="${foo.type)} == 'type_1'">
<div th:replace="fragments/custom-questions :: type-1-checkboxes"></div>
</div>
<div th:if="${foo.type} == 'type_2'">
<div th:replace="fragments/custom-questions :: type-2-checkboxes"></div>
</div>
Then the associated div gets loaded from the file custom-questions.html:
<div th:fragment="type-1-checkboxes">
//stuff
</div>
<div th:fragment="type-2-checkboxes">
//stuff
</div>
I am just encountering this issue (this is my first time with thymeleaf/spring). This is what solved it for me:
<div class="col-md-12" th:include="__${template}__ :: body" ...
In Thymeleaf 3.0, the following solution has worked for me:
<div th:replace="('fragments/' + ${template}) :: (${template})">
(Note however, that I use it with fixed name of the fragment and dynamic name of the template, so the parantheses around :: (${template}) might be optional.)
The solution is inspired by documentation for Thymeleaf in https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#fragment-specification-syntax
Both templatename and selector in the above examples can be fully-featured expressions (even conditionals!) like:
<div th:insert="footer :: (${user.isAdmin}? #{footer.admin} : #{footer.normaluser})"></div>
Note again how the surrounding ~{...} envelope is optional in th:insert/th:replace
<div th:insert=“${subpage}::fragementName”>
Just change subpage names and you will dynamic behaviour in thymleaf
I have a problem redirecting a page with javascript. I want to redirect the page after clicking a button, but it is redirecting it automatically.
Why is that?
window.onload=initAll;
function initAll(){
if(window.addEventListener) {
document.getElementById('check').addEventListener("click",redirection,false);
} else if (window.attachEvent){
document.getElementById('check').attachEvent("onclick", redirection);
}
function redirection(){
window.location.href='http://www.google.com';
}
}
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="glavna.js"></script>
</head>
<body>
<div id="wrapper">
<form action="glavna.html">City:<input id="city" type="text"/>
Price: From:<input type="text" id="from"/> To:<input type="text" id="to"/>
Refresh in min :<input type="text" id="refresh"/>
<button id="check" >Search</button>
</form>
</div>
</body>
</html>
this can be done with window.location.href what it does
// similar behavior as clicking on a link
window.location.href = "you want to redirect";
window.location is location object. To redirect Use window.location.href instead
This should be an easy fix for the right guru! Everything is working for me except that I can't get this form to submit without clicking the submit button. The data values are all valid. The action page, ...gdform.php, uses $_post to get the "redirect" value from the form and then uses php to do a header Location change. That works fine if I execute the form with the submit button. I just need it to happen without any click...
Take a look, please!
<?php session_start();
require_once('Connect.php') ;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Nitrofill Document</title>
<?php
//error_reporting(E_ALL);
$sn=$_GET['num'];
echo $sn;
mysql_connect($hostname,$username, $password) OR die('Unable to connect to database! Please try again later.');
mysql_select_db($dbname);
$selectSQL = "select * from `Presentations` where `serialnum` ='" . $sn ."'" ;
$result = mysql_query($selectSQL) or die(mysql_error());
$row = mysql_fetch_array($result, MYSQL_BOTH);
$thedoc = urldecode($row['docurl']);
$therecip=urldecode($row['recipient']);
$thetracker=urldecode($row['tracker']);
$lastacc=urldecode($row['last_accessed']);
?>
</head>
<body>
<form id="notice" action="http://m3sglobal.com/gdform.php" method="post">
<input name="subject" value="<?php echo $therecip . " has viewed the document you sent them.";?> " />
<input type="hidden" name="redirect" value="<?php echo $thedoc ; ?>"/>
<label>Email:</label><input type="text" name="email" value="<?php echo $thetracker ; ?>"/>
<label>Comments:</label><textarea name="comments" cols="40" rows="5">
Document Viewed:<?php echo $thedoc ; ?>
When Accessed:<?php echo $lastacc ; ?>
</textarea>
<input type="submit" name="submit"/>
</form>
</body>
</html>
<script type="text/javascript">
$(document).ready(function(){
myfunc
});
function myfunc () {
var frm = document.getElementById("notice");
frm.submit();
}
</script>
I might be wrong but shouldn't it be: (corrected typos)
$(document).ready(function(){
myfunc(); <--// with ();
});
function myfunc() { <--// without space
var frm = document.getElementById("notice");
frm.submit();
}
or better yet:
$(document).ready(function(){
$("form#notice").submit();
});
EDIT:
Prowla is right, you also didn't declare the jQuery library. Good catch Prowla, I missed that, just saw the typos.
EDIT #2:
Your code is pretty messy there, and you have that PHP generated string in the <head>. Also your submit had no value, you used name. I cleaned it up, here is working code (for me at least):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Nitrofill Document</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$("form#notice").submit();
});
</script>
</head>
<body>
<!--// ALL THE PHP SHOULD GO HERE TO MAKE THE URL BELOW //-->
qyO452ZKphttps://docs.google.com/presentation/pub?id=1chxqg-qjrfEvAR9_Jia7lt4ps2_Q7IfTiI41bQE7Q_4&start=true&loop=false&delayms=3000<br/>greg.mcgee#gmail.com<br/>greg.mcgee#advetel.com<br/>Thu, 23 Feb 2012 19:42:11 MST<br/>
<!--// END PHP //-->
<form id="notice" action="http://m3sglobal.com/gdform.php" method="post">
<input name="subject" value="greg.mcgee#gmail.com has viewed the document you sent them. " />
<input type="hidden" name="redirect" value="https://docs.google.com/presentation/pub?id=1chxqg-qjrfEvAR9_Jia7lt4ps2_Q7IfTiI41bQE7Q_4&start=true&loop=false&delayms=3000"/>
<label>Email:</label><input type="text" name="email" value="greg.mcgee#advetel.com"/>
<label>Comments:</label><textarea name="comments" cols="40" rows="5">
Document Viewed:https://docs.google.com/presentation/pub?id=1chxqg-qjrfEvAR9_Jia7lt4ps2_Q7IfTiI41bQE7Q_4&start=true&loop=false&delayms=3000
When Accessed:Thu, 23 Feb 2012 19:42:11 MST
</textarea>
<input type="submit" value="submit"/>
</form>
</body>
</html>
You might want to consider using firebug to help you troubleshoot your pages. Its how I figured this out. Also remember Prowla's advice, and protect your SQL.
Using jQuery: (Remember to put the jquery script in your <head> tags).
<head>
...
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
...
<head>
...
// submit form with id notice
$(document).ready(function(){
$('#notice').submit();
});
Also your SQL is subject to injection. Please look into using prepared statements.
Sample in PHP:
$mysqli = new mysqli('localhost', 'user', 'password', 'db');
$stmt = $mysqli->prepare('select * from `Presentations` where `serialnum` =?');
$stmt->bind_param('i',$sn);
$stmt->execute();
....
I'm new on Grails and I have some troubles with Ajax (so I could have missed something). On my main gsp I want a select box, that, when I click on its options, makes appear another field on the same page to select other things. As the content in the second part is dynamic, I need somme Ajax. Anyway I haven't succeed yet. Here is my code :
main.gsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="layout" content="main" />
<title>Sample title</title>
<g:javascript library="jquery"/>
</head>
<body>
<h1>Selection de l'email</h1>
<div class="dialog">
<g:select name="selectTemplate"
from="${templateCategories}"
value="category"
noSelection="['':'--- choisissez un modèle ---']"
onchange="${remoteFunction(
controller:"email"
action:"printTestTemplate"
update:"listTemplates"
params:'\'category=\'+this.value'
)}"
/>
<div id="listTemplates">RRR</div>
</div>
</body>
</html>
EmailController
def printTestTemplate = {
println params.category //doesn't print anything
println "YEAAAAAAAAAH" //the same
render(view:"formSelectTemplate", model:[templates:EmailTemplate.findByCategory(params.templateCategory)])
}
formSelectTemplate.gsp
<h1>YOUHOUUU !</h1>
I've both tried to call a view or template (by renaming the gsp of course), but nothing worked. Nevertheless I don't understand, I followed the official doc. Notice that the HTML result creates no event on the select box, and that Firebug tells me there is no 404. So I must have missed something in the creation of the box.
select result in HTML :
<select id="selectTemplate" name="selectTemplate">
<option value="Refus">Refus</option>
<option value="Informations complémentaires">Informations complémentaires</option>
</select>
Did you forget comas between the arguments of your remoteFunction call ? like this:
onchange="${remoteFunction(controller:"email",
action:"printTestTemplate",
update:"listTemplates",
params:'\'category=\'+this.value' )}"