PayPal sandbox Buy Now Problem - java

I have paypal sandbox test account. I want to create a 'buy Now' button. I am trying it with GWT.
But its even not working with simple HTML form. It displays a 'Buy Now' button on HTML page and after clicking on it redirects to PayPal site. Where it ask to login to buy product but after that it goes on displaying message: The email address or password you have entered does not match our records. Please try again. I am using buyer user to purchase product. I am pretty sure about the username and password.
Providing here the simple HTML form which I am trying:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" id="payPalForm">
<input type="hidden" name="item_number" value="1">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="no_note" value="1"><br>
<input type="hidden" name="business" value="sellr1_1252495907_biz#gmail.com">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="cn" value="Add special instructions to the seller">
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="rm" value="1">
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_paynow_SM.gif:NonHosted">
<input type="hidden" name="variables" value="http://google.com">
<input type="hidden" name="cancel_return" value="http://google.com">
<input type="hidden" name="notify_url" value="http://google.com">
<input type="hidden" name="return" value="http://freelanceswitch.com/payment-complete /">
<input type="hidden" name="currency_code" value="USD">
<input name="item_name" type="hidden" value="Deal Name">
<input name="amount" type="hidden" value="500">
<input type="submit" name="Submit" value="Submit">
</form>
Please advice. Thank you.

As Lazarus has pointed out you are using the wrong address for your form action. You are posting to the live PayPal service - The sandbox is what it is, its a dev version of the live Paypal... why shouldn't the Sandbox environment ask you Credit Card details, how else would you test your check out process?
Obviously the sandbox environment uses dummy credit card numbers.
Anyway, I believe the address you need for your form action method is:
https://www.sandbox.paypal.com/cgi-bin/webscr
Your hidden fields look ok :)
Also please consider marking answers once you feel your questions have been answered - just click on the outline 'tick' for whichever answer you feel is best.

Related

JSP FORM POST : empty attributes

I can't find one attribute sent from a JSP form.
<form name="shuntingForm" action="/TCS_FUND/ShuntAction.aen" method="POST">
<div class="field-item clearfix">
<input type="hidden" name="csrfPreventionSalt" value="<%=CsrfPreventionSalt%>" />
<input type="hidden" name="idSession" value="<%=idSession%>">
Funds Trading<br>
</div>
</form>
request.getAttribute("idSession") & request.getParameter("idSession") show NULL.
Any ideas ? thanks
I would simplify this to return a fixed value.
Change:
<input type="hidden" name="idSession" value="<%=idSession%>">
To:
<input type="hidden" name="idSession" value="123456789">
Once that works, figure out the difference.
You also may want to view the source of the web page. If your idSession does not have the value you expect, your input tag will show the wrong value field.

How to get value from html input radio and put it in input hidden field in jsp java [duplicate]

This question already has answers here:
How to transfer data from JSP to servlet when submitting HTML form
(4 answers)
Closed 2 years ago.
I have the code for radio buttons
<input type="radio" name="opt" id="1" value="1"/><label for="1">${dto.quesOpt1}</label>
<br/>
<input type="radio" name="opt" id="2" value="2"/><label for="2">${dto.quesOpt2}</label>
<br/>
<input type="radio" name="opt" id="3" value="3"/><label for="3">${dto.quesOpt3}</label>
<br/>
<input type="radio" name="opt" id="4" value="4"/><label for="4">${dto.quesOpt4}</label>
And I want to put the value here so I can pass it to my Servlet
<form action="MainController" method="POST">
<input type="hidden" name="quesNum" value="${requestScope.QUESNUM}"/>
<input type="hidden" name="quesId" value="${dto.quesId}"/>
<input type="hidden" name="quesChoice" value="${param.opt}"/> <--------- here
<input type="hidden" name="amount" value="${requestScope.AMOUNT}"/>
<input type="hidden" name="action" value="Previous Question"/>
<input type="submit" value="Previous" <c:if test="${requestScope.QUESNUM == 0}">disabled</c:if>/>
</form>
I always get null value in Servlet
request.getParameter("quesChoice")
I don't know how to pass the value. Please guide me. Thank you.
What you're trying to do is execute server side code (like ${dto.quesId}) inside the browser. You cannot do that.
What you're trying to do is super nasty and is probably not the right way to go. You probably don't need to copy the values from the radio to the form as you can put the radios directly inside the form.
JSPs are a super old technology that most companies have already abandoned years ago and those that still use it, plan to abandon it.
If you really have to use JSPs, your life would be much easier if you used JSTL libraries and MKYoung has some awesome tutorial on how to handle a lot of old java issues, including the one you're struggling with right now: https://mkyong.com/spring-mvc/spring-mvc-radiobutton-and-radiobuttons-example/
If you say "fuck it, I want to code it the way I was planning to do that all along anyway", you still need JavaScript to copy your values as this is the JavaScript that handles the browser-side actions.
Having said all that, this is how you can do it with pure JS:
<html>
<script>
function copyValue() {
let allOptions = Array.prototype.slice.call(document.getElementsByName('opt'));
let selectedOption = allOptions.filter(opt => opt.checked)[0];
let selectedOptionValue = selectedOption ? selectedOption.value : undefined;
document.getElementById('quesNum').value = selectedOptionValue;
}
</script>
<body>
<input type="radio" name="opt" id="1" value="1"/><label for="1">${dto.quesOpt1}</label>
<br/>
<input type="radio" name="opt" id="2" value="2"/><label for="2">${dto.quesOpt2}</label>
<br/>
<input type="radio" name="opt" id="3" value="3"/><label for="3">${dto.quesOpt3}</label>
<br/>
<input type="radio" name="opt" id="4" value="4"/><label for="4">${dto.quesOpt4}</label>
<input type="hidden" name="quesNum" id="quesNum" value="${requestScope.QUESNUM}"/>
<input type="button" value="Copy Value" onClick="copyValue()"/>
</body>
</html>
Note how I had to add the id="quesNum" and then the onClick="copyValue()" to trigger an action.
Here's the example in JSFiddle if you want to play with it: https://jsfiddle.net/kgjanowski/5ymubn6v/22/

Why missing <fieldset> tag will cause controller cannot get form value?

I am developing a WebApp which uses Spring-MVC & Thymeleaf as template engine.
In my HTML,I got a form like this
<form action="/submit" method="POST">
First name: <input type="text" name="fname"/>
Last name: <input type="text" name="lname"/>
<input type="text" id="taskId" name="taskId" th:value="${taskId}" />
<input type="submit" value="Submit"/>
</form>
And I have a controller
#RequestMapping("/submit")
public void addUser(String taskId, String fname, String lname, ModelMap map) {
//save to db...
}
At first I expect taskId, fname, lname will contains the value from the form, but they are all null
Finally I try to wrap all the input field by <fieldset>tag, and it suddenly works. i.e:
<form action="/submit" method="POST">
<fieldset>
First name: <input type="text" name="fname"/>
Last name: <input type="text" name="lname"/>
<input type="text" id="taskId" name="taskId" th:value="${taskId}" />
<input type="submit" value="Submit"/>
</fieldset>
</form>
I would like to know:
Why adding <fieldset> will make everything works?
The HTML - <fieldset> tag is used to group related elements in a form.
Basically the <fieldset> tag draws a box around the related elements in a form.
Most online forms are poorly designed, disorganized, and hard to use. One thing you can do to make your forms better is to organize them into logical sections. The <fieldset> element provides an easy way to break forms down into logical sections.
For more information you can always got to - https://html.com/tags/fieldset/

Form gets submitted on ENTER button

I have form as given below. Now, when I enter something in the #search_string and press ENTER button it automatically takes it to the action=Paid... I'm not sure why the form gets submitted on the ENTER button..
<!--<div id="startsearchbox">-->
<form id="bigsearchform_new" method="post" action="Paid">
<!--<label style="display:none" for="search_string">SEARCH</label>-->
<input id="search_string" name="search_string" type="text" class="startnewsearch rounded" placeholder="Search..." maxlength="500" >
<input id="searchButton1" type="button" class="searchButton" title="Click here to search the database">
<input type="hidden" name="antiCSRF" value="{{acsrf}}" />
<input type="hidden" name="session_id" value="{{session_id}}" />
<input type="hidden" name="commodity_id" id="commodity_id" />
</form>
It's default behavior of the browser to submit the form on ENTER button. If you want to prevent form submitssion use onSubmit event handler.
That is the default behavior for an HTML form, see http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#implicit-submission

How to access the html form data in java program

i have created a java project in eclipse,in this project i have an html form customer.html as shown below
<form>
Name :<input type="text" id="name"/>
Address: <input type="text" id="add"/>
Age:<input type="int" id="age"/>
<input type="submit" onclick="what should i call here in my program"/>
</form>
once the user fills the form and submits it i want to access the form field in java code is it possible.if so how or else is there anyother solution to create an xml file for this form
<input type="submit" onclick="only Javascript function can be called here"/>
if you want to access html form elements at java code you need to submit your form at some controller or another jsp. Like..
<form name="new_employee" method="post" action="../admin/newEmployee.do">
Name :<input type="text" name="employeeName"/>
Address: <input type="text" name="add"/>
Age:<input type="text" name="age"/>
<input type="submit" value="Submit"/>
</form>
form elements can be accessed from generated request by their names like..
request.getParameter("employeeName");

Categories