Hi All,I am new to java ,And the project which has given to me is to integrate the payapal at our site.I have integrated that.
Now the problem is once my customer is done with his payment,he should me returned back to my site and also he should be able to see his transaction details at my sitPage.
I Have written a Servlet which will be called on the click of Pay at paypal site.but I guess the servlet is not working
The code that i have wrriten is :
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
import java.util.Properties;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class PdtServlet extends AbstractTeleTrakController {
protected void processRequest(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException,
TeleTrakDatabaseException, TeleTrakGeneralException {
DirectCallDeligate directCallDeligate = new DirectCallDeligate(request);
String action = request.getParameter("userAction");
String page="";
String paypalTransactionId=null;
Map paramterMap=request.getParameterMap();
int noOfParameters=paramterMap.size();
System.out.println("noOfParameters==>"+noOfParameters);
//Returned From paypal
String firstName=null;
String lastName=null;
String paymentStatusFromPaypal=null;
String paymentAmount=null;
String currency=null;
String customValueWeHaveSend=null;
int dealerId=0;
int noOfTollFreeNos;
int totalCharges;
String paymentMethod="";
if(noOfParameters==1){
//Paypal is pinging our servlet with tx code
paypalTransactionId=request.getParameter("tx");
PayPalHelper payPalHelper = new PayPalHelper();
String identityToken= payPalHelper.getPdTIdentity();
OutputStreamWriter streamWriter=null;
HttpURLConnection urlConnection=null;
BufferedReader reader=null;
String urlToBePosted =payPalHelper.getPayPalSiteURL();
StringBuffer dataToPostBuffer = new StringBuffer();
try{
dataToPostBuffer.append("cmd=");
dataToPostBuffer.append("_notify-synch");
dataToPostBuffer.append("&tx=");
dataToPostBuffer.append(paypalTransactionId);
dataToPostBuffer.append("at=");
dataToPostBuffer.append(identityToken);
URL url = new URL(urlToBePosted);
urlConnection = (HttpURLConnection)url.openConnection();
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
urlConnection.setUseCaches(false);
urlConnection.setRequestMethod("POST");
streamWriter = new OutputStreamWriter(urlConnection.getOutputStream());
streamWriter.write(dataToPostBuffer.toString());
streamWriter.flush();
Properties paypalProperties = new Properties();
paypalProperties.load(urlConnection.getInputStream());
reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
StringBuffer returnBuffer = new StringBuffer();
String lineToRead;
while((lineToRead=reader.readLine())!=null){
returnBuffer.append(lineToRead);
}//end of while
firstName = paypalProperties.getProperty("first_name");
lastName=paypalProperties.getProperty("last_name");
paymentAmount=paypalProperties.getProperty("payment_gross");
currency= paypalProperties.getProperty("mc_currency");
customValueWeHaveSend= paypalProperties.getProperty("custom");
//if("SUCCESS".equalsIgnoreCase(returnBuffer.toString().substring(0,7))==true){
paymentStatusFromPaypal= paypalProperties.getProperty(payPalHelper.getPayPalPdtPaymentStatusField());
if(paymentStatusFromPaypal.equalsIgnoreCase("Completed")){
//Payment is sucess
}
if(paymentStatusFromPaypal.equalsIgnoreCase("Failed")){
System.out.println("Failed=========>");
}
if(paymentStatusFromPaypal.equalsIgnoreCase("Processed")){
System.out.println("payment has been accepted and processed===>");
}
if(paymentStatusFromPaypal.equalsIgnoreCase("Denied")){
System.out.println("Payment has been denied===>");
}
if(paymentStatusFromPaypal.equalsIgnoreCase("Expired")){
System.out.println("Payment has been Expired===>");
}
if(paymentStatusFromPaypal.equalsIgnoreCase("Pending")){
System.out.println("Payment has been Pending===>");
}
//}
}catch(Exception ex){
System.out.println("Exception Occured While taking value from paypal pdt");
ex.printStackTrace();
}
page="/Creditcard.jsp";
}else{
}//end of if
}//end of method
}//end of serlvet
Can anyone plz me help me out.
And if possible plz do reply at
gourav@logixworld.comRegards
Gourav