1

I am trying to develop a salesforce IPN handler to receive Paypal payments notifications.

Paypal requires replying back with same received HTTP request body. I am not able to achieve this as Salesforce HTTP parameters are getting from Map with the alphabetic order. Accordingly, I receive always unverified request from Paypal.

Any Ideas or suggestions?

This is the controller class code that I have used:

        Map<String, String> parameterMap = ApexPages.currentPage().getParameters();
        String queryString = 'cmd=_notify-validate';

        for (String parameterName : parameterMap.KeySet()) {
                queryString += '&' + parameterName + '=' + EncodingUtil.urlEncode(parameterMap.get(parameterName), 'UTF-8');
        }

        Http http = new Http();
        HttpRequest req = new HttpRequest();

        req.setEndpoint(getPaypalBaseURL());
        req.setMethod('POST');
        req.setBody(queryString);
        req.setHeader('Content-Type'  , 'application/x-www-form-urlencoded');
        req.setHeader('Content-Length', req.getBody().length().format());
        req.setTimeout(60000);

        system.debug('req body: ' + req.getBody());

        HttpResponse res = new HttpResponse();
        String verificationResponse;

       // If this method is being called through a test method, create a sample response
        if(Test.isRunningTest()) {
            // The sample response is based on a page parameter populated in the test method, called 'verification response'
            verificationResponse = ApexPages.currentPage().getParameters().get('verifcationResponse');
        } else {
            res = http.send(req);
            verificationResponse = res.getBody(); 
        }

        return verificationResponse.equalsIgnoreCase('VERIFIED');
  • Is there any reason your can't use getURL() instead of getParameters() and just parse the query string yourself? – dsharrison Aug 23 '17 at 0:40
0

@dsharrison, the getURL() returns the encoded url, as that won't work.

@ahmed kishk, I think the issue is your may not be posting the request on correct URL, There is separate endpoints for sandbox and Production IPN. I had similar issue since couple of weeks and was able to solve it by using appropriate endpoint as below :

Send response messages back to PayPal:

Check here for more details

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.