'Paypal IPN: three steps validation to ensure data correctness
- step 1: return an empty HTTP 200 response -> will be done at the end
by returning \'\'
- step 2: POST the complete, unaltered message back to Paypal (preceded
by cmd=_notify-validate or _notify-synch for PDT), with same encoding
- step 3: paypal send either VERIFIED or INVALID (single word) for IPN
or SUCCESS or FAIL (+ data) for PDT
Once data is validated, process it.'

def paypal_validate_data(self, **post):

    res = False
    new_post = dict(post, cmd='_notify-validate')
    reference = post.get('item_number')
    tx = None
    if reference:
        tx = request.env['payment.transaction'].search([('reference', '=', reference)])
    paypal_urls = request.env['payment.acquirer']._get_paypal_urls(((tx and tx.acquirer_id.environment) or 'prod'))
    pdt_request = bool(new_post.get('amt'))
    if pdt_request:
        new_post['at'] = request.env['ir.config_parameter'].sudo().get_param('payment_paypal.pdt_token')
        new_post['cmd'] = '_notify-synch'
    validate_url = paypal_urls['paypal_form_url']
    urequest = urllib2.Request(validate_url, werkzeug.url_encode(new_post))
    uopen = urllib2.urlopen(urequest)
    resp = uopen.read()
    if pdt_request:
        (resp, post) = self._parse_pdt_response(resp)
    if ((resp == 'VERIFIED') or (pdt_request and (resp == 'SUCCESS'))):
        _logger.info('Paypal:    validated    data')
        res = request.env['payment.transaction'].sudo().form_feedback(post, 'paypal')
    elif ((resp == 'INVALID') or (pdt_request and (resp == 'FAIL'))):
        _logger.warning('Paypal:    answered    INVALID/FAIL    on    data    verification')
    else:
        _logger.warning(('Paypal:    unrecognized    paypal    answer,    received    %s    instead    of    VERIFIED/SUCCESS    or    INVALID/FAIL    (validation:    %s)' % (resp, ('PDT' if pdt_request else 'IPN/DPN'))))
    return res
