Paypal IPN for canceling recurring payment

1

I obtained the following code from PayPal's git hub. I am making recurring payments and would like to receive notification on the system when canceling. This could block the provision of my services if the user cancels. I have the servlet code, but I do not know how to get it to respond on my system in JSF. I already mapped in web.xml.

package br.com.spacnet.util;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.paypal.core.LoggingManager;
import com.paypal.ipn.IPNMessage;
import br.com.spacnet.util.Configuration;

public class IPNListenerServlet extends HttpServlet {

/**
 * 
 */
private static final long serialVersionUID = 1L;
 /* 
 * receiver for PayPal ipn call back.
 */
protected void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {

        // For a full list of configuration parameters refer in wiki page. 
        // (https://github.com/paypal/sdk-core-java/wiki/SDK-Configuration-Parameters)
        Map<String,String> configurationMap =  Configuration.getConfig();
        IPNMessage  ipnlistener = new IPNMessage(request,configurationMap);
        boolean isIpnVerified = ipnlistener.validate();
        String transactionType = ipnlistener.getTransactionType();
        Map<String,String> map = ipnlistener.getIpnMap();

        LoggingManager.info(IPNListenerServlet.class, "******* IPN (name:value) pair : "+ map + "  " +
                "######### TransactionType : "+transactionType+"  ======== IPN verified : "+ isIpnVerified);
    }
}

My web.xml looks like this:

 <servlet>
    <description></description>
    <display-name>IPNListenerServlet</display-name>
    <servlet-name>IPNListenerServlet</servlet-name>
    <servlet-class>com.sample.ipn.IPNListenerServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>IPNListenerServlet</servlet-name>
    <url-pattern>/IPNListener</url-pattern>
</servlet-mapping>
    
asked by anonymous 29.09.2014 / 16:53

1 answer

2

I think there are two things wrong:

  • The mapping of Servlet is wrong. The <servlet-class> must be <servlet-class>br.com.spacnet.util.IPNListenerServlet</servlet-class> , since the Servlet class package is this way.

  • Access is wrong. If you are using Browser to access IPNListenerServlet , you are making a request GET to a Servlet that only attends requests POST ( doPost method has been implemented), and the url is wrong. p>

    If context-root of your application is meusite (can be / ), I believe you should make a request POST , or using curl or HttpClient , to address: / p>

      

    localhost:8080/_seu_context-root_/IPNListener

    Because your mapping of Servlet to web.xml is with:

    <url-pattern>/IPNListener</url-pattern>
    

    Alternatively, you could use the @WebServlet annotation to set your Servlet , but for this you need to run in a Servlet Container that implements version 3.0. If this is the case, your Servlet would be:

    @WebServlet("/IPNListener")
    public class IPNListenerServlet extends HttpServlet
    

    No need to set it to web.xml .

  • For more details on the Servlets API, take a look at Java Servlet Technology of Java 7 or Java 6 Servlet Technology

    I do not quite understand why you use the page:

      

    localhost: 8080 / mysite / admin / IPN / ipnMessage.jsp

    Because in general the registered endpoint for IPN of Paypal just needs to respond with a status code. And this can be done directly by Servlet using HttpServletResponse.setStatus , you do not need to give forward to a new page.

    Regarding status:

  • Use status 200 to report that the request has been processed correctly.
  • Any other value is considered an error and the IPN notification is made again at a later time.
  • 29.09.2014 / 19:17