Hi jayeshps,
I have implemented PayPal IPN in the following way:
In the html form you submit, you set the notifyUrl to a path i.e.
www.example.com/payment/ipn
In my Application class I have the following: mountPage("/payment/ipn",
IPNPaymentHandler.class);
Then my IPNPaymentHandler.class is as follows:
public class IPNPaymentHandler extends WebPage {
private static final Log log =
LogFactory.getLog(IPNPaymentHandler.class);
public IPNPaymentHandler() {
super();
log.debug("IPN Payment being received");
Request request = getRequest();
try {
Set<String> paramSet =
request.getRequestParameters().getParameterNames();
Iterator<String> iterator = paramSet.iterator();
StringBuffer sb = new StringBuffer();
sb.append("cmd=_notify-validate");
while(iterator.hasNext()){
String paramName = (String)iterator.next();
String paramValue =
request.getRequestParameters().getParameterValue(paramName).toString();
sb.append("&" + paramName + "=" +
URLEncoder.encode(paramValue,
"UTF-8"));
}
URL u = new
URL(AppUtil.getSettings().getPayPalWebsiteStandardUrl());
URLConnection uc = u.openConnection();
uc.setDoOutput(true);
uc.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
PrintWriter pw = new PrintWriter(uc.getOutputStream());
pw.println(sb.toString());
pw.close();
BufferedReader in = new BufferedReader(new
InputStreamReader(uc.getInputStream()));
String res = in.readLine();
in.close();
// assign posted variables to local variables
String itemName =
request.getRequestParameters().getParameterValue("item_name").toString();
String itemNumber =
request.getRequestParameters().getParameterValue("item_number").toString();
String paymentStatus =
request.getRequestParameters().getParameterValue("payment_status").toString();
String paymentAmount =
request.getRequestParameters().getParameterValue("mc_gross").toString();
String paymentCurrency =
request.getRequestParameters().getParameterValue("mc_currency").toString();
String txnId =
request.getRequestParameters().getParameterValue("txn_id").toString();
String receiverEmail =
request.getRequestParameters().getParameterValue("receiver_email").toString();
String payerEmail =
request.getRequestParameters().getParameterValue("payer_email").toString();
//check notification validation
if(res != null && res.equals("VERIFIED")) {
if(paymentStatus.equals("Completed")) {
//Do business logic
}
else {
log.debug("paymentStatus = " +
paymentStatus);
}
}
else if(res != null && res.equals("INVALID")) {
log.info("result = " + res);
log.info("itemName = " + itemName + "
itemNumber = " + itemNumber + "
paymentStatus = " + paymentStatus + " paymentAmount = " + paymentAmount + "
" + paymentCurrency);
log.info(" txnId = " + txnId + " receiverEmail
= " + receiverEmail + "
payerEmail = " + payerEmail);
}
else {
log.info("result = " + res);
log.info("itemName = " + itemName + "
itemNumber = " + itemNumber + "
paymentStatus = " + paymentStatus + " paymentAmount = " + paymentAmount + "
" + paymentCurrency);
log.info(" txnId = " + txnId + " receiverEmail
= " + receiverEmail + "
payerEmail = " + payerEmail);
}
}
catch(MalformedURLException mue) {
mue.printStackTrace();
}
catch(IOException ioe) {
ioe.printStackTrace();
}
}
}
The above is just the skeleton where you can fine tune to your needs...
Please do let me know if you see any flaws.... payment needs to be done
right especially with security etc.
Regards
Vishal
--
View this message in context:
http://apache-wicket.1842946.n4.nabble.com/Paypal-Integration-in-wicket-tp4670325p4670415.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]