Dani 4,084 The Queen of DaniWeb Administrator Featured Poster Premium Member

I'm trying to debug my PayPal IPN code. Here is my PHP code:

if ($this->input->post('payment_status') == 'Completed' AND in_array($this->input->post('txn_type'), array('web_accept', 'subscr_payment')))
{
    $query = 'cmd=_notify-validate&' . http_build_query($this->input->post());

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://www.paypal.com/cgi-bin/webscr');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $result = curl_exec($ch);
    curl_close($ch);

    if ($result == 'VERIFIED')
    {   
        $donation = new Donation;
        $donation->insert(array(
            'userid' => $userid,
            'amount' => $this->input->post('mc_gross'),
            'timestamp' => now(),
            'paypal' => $this->input->post('payer_email'),
        ));
    }
}

The official documentation is here: https://www.x.com/developers/PayPal/documentation-tools/code-sample/216623

It only seems to be working about 75% of the time. I think that for the remaining 25%, the payment_status isn't 'Completed' or an invalid value is spcified for txn_type. I don't want it to work on refunds, etc. From what I can tell, there is no distinction between one that worked and one that didn't (i.e. it's not like one was an eCheck and one wasn't, etc). Anything I can look into?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.