Mdumanoj Mdumanoj -4 years ago 152
Java Question

PayPal IPN Configuration using Java Web Service

I am working on PayPal IPN Listener Configuration using Spring Web Service. I searched in the Google, I can't get much useful resource for Java Implementation there is lot of Examples for PHP only.

I am trying to create a recurring payment option for my web application using PayPal Recurring Payment APIs. I have some premium membership for my website user have to pay some money to subscribe membership. I created a Billing Plan, Billing Agreement and I used Approval URL from Billing Agreement response to get Authorize from user. I got stuck in the IPN Listener. I have no idea how to configure IPN Listener in Spring Web Service. I need to have auto renewal feature in my Web Application. Here is my listener

@RequestMapping(value = "ipn", method = RequestMethod.POST)
public @ResponseBody
Map<String,Object> IPNListener(HttpServletRequest request, HttpServletResponse response) throws IllegalStateException, IOException {
try {
HttpClient client = HttpClientBuilder.create().build();
HttpPost post = new HttpPost("");
List<NameValuePair> params = new ArrayList<NameValuePair>();

params.add(new BasicNameValuePair("cmd", "_notify-validate")); //You need to add this parameter to tell PayPal to verify
for (Enumeration<String> e = request.getParameterNames(); e.hasMoreElements();) {
String name = e.nextElement();
String value = request.getParameter(name);
params.add(new BasicNameValuePair(name, value));
post.setEntity(new UrlEncodedFormEntity(params));

HttpResponse resp = client.execute(post);
InputStream is = resp.getEntity().getContent();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String result = "";
String line = null;
while ((line = br.readLine()) != null) {
result += line;
String rc = result.trim();"IPN Listener Result :: " + rc);
if ("VERIFIED".equals(rc)) {"IPN Listener Verified");
// Add Premium Membership for User
} catch (Exception e) {
logger.error("IPN Listener Exception ");
return null;

I have so many users in my Web Application. Here I don't have idea

how to identify which user's payment is done?

which user I need to activate the premium membership?

Is there any way to configure membership_Id and User_Id to get back in IPN Listener while creating Billing Plan or Billing Agreement?

Answer Source

I got solution for this problem. I used the created Agreement_Id to track user_id and membership_id. After I executed the Agreement, I stored Agreement_Id with membership_id and user_id in my database. I will get Agreement_Id in name of Recurring_Payment_Id in IPN Listener. I will query my database to get user_id and membership_id using Agreement_id. Hope this may help someone.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download