Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet redirect to another server

 
Ramkumar Subburaj
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am creating a shopping cart application and using paypal as payment gateway integration.

The usual way to checkout is put all the paypal variables in the form as hidden variables and post it to payapl.

For safety reasons, i was trying to post the checkout process to a servlet, intercepted by a filter where i create a custom request object inserting all the paypal values and pass the new request object to the servlet.

Now the servlet has the request object which contains all required paypal parameters.

Is there any way to forward the request to paypal from servlet or a filter.
 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are thinking about a forward like we do using request dispatcher, then that's not possible. You'll have to connect to Paypal using HttpsURLConnection or a API like Apache HttpClient to make a request to paypal...
 
Ramkumar Subburaj
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if i connect using Apache HttpClient, will the user be redirected to paypal site?

And the method which i am try to implement, is it fine or does it have some disadvantage
 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ramkumar Subburaj wrote:if i connect using Apache HttpClient, will the user be redirected to paypal site?

And the method which i am try to implement, is it fine or does it have some disadvantage


Do you want to redirect the client ot paypal or just make a request to paypal on client's behalf??
 
Ramkumar Subburaj
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to redirect the user to paypal site
 
Rukmal Dias
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

For this you need Apache HttpClient (http://hc.apache.org/downloads.cgi) libs. This makes tasks lot easier.

This is for HttpClient 4.1 library..



The POST method didn't work..
Hope this helps..

Rukmal Dias
 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Rukmal - Welcome to JavaRanch

 
Dinesh Arora
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it is possible. I have just implemented a code my application where my customer leaves my application site and goes to paypal page. Customer logs in and clicks "I agree" and gets back to my application/site.

I am using Spring framework. The first call that I mentioned above is where Paypal send me a token which I can use to actually charge the customer account. When customers reviews the final order on my site and decides to submit, I use this token and give a call to Paypal to charge the account.

How I am doing this:


Customer chooses option: I want to pay via Paypal. The call comes to my servlet.
Step 1. Get the paypal token. You will need to call the PayPal Api to get the token. Check Paypal developer guide.

Step 2. "Forward" customer to Paypal site by appending the token(REMEBER NEVER SEND PAYMENT INFORMATION IN THE URL.)

I fill in Paypal business value object (customer name, email, price, currecny etc.). Then I am forwarding the customer to this URL
String forwardUrl = https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=" + paypalResponseVO.getPayPalResponseVO().getApiToken();

Step3: After customer clicks agree on Paypal URL. Paypal automatically redirects the customer to my site. How is that possible. When you requested token number in step one, you pass information such as CancelUrl, SuccessUrl. Paypal uses this url to forward customer back to your site.

So now in my forward URL I have provided logic that if everything was fine then take the customer to the next page.

Step 4. Customer reviews the order and asks to charge the Paypal account. Use the same token number and send a another request to Paypal API to charge the account.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic