0
votes

My problem

I set up an IPN listener in CodeIgniter framework, but it always returns INVALID Response.

What I tried Till now:

  • Ensured that my server is sending the request to www.sandbox.paypal.com and not www.paypal.com.
  • Ensured that my response is equal to PayPal's request, prefixed with cmd=_notify-validate&
  • I used PayPal IPN code sample

My Code:

Paypal Buy button code...

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr"     method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="My sandbox facilitator email id">
<input type="hidden" name="item_name" value="My Business">
<input type="hidden" name="item_number" value="10101">
<input type="hidden" name="amount" value="10">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="bn" value="PP-BuyNowBF">
<input type="image" src="" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
<img alt="" border="0"  src="https://www.paypal.com/en_GB/i/scr/pixel.gif" width="1" height="1">
<input type="hidden" name="return" value="<?php echo base_url(); ?>homepage/success">
 <input type="hidden" name="cancel_return" value="<?php echo base_url();homepage/cancel">
<input type="hidden" name="rm" value="2"> 
<input type="hidden" name="notify_url" value="<?php echo base_url(); ?>/homepage/ipn" /> 
</form>

Paypal IPN codes sample from this link https://github.com/paypal/ipn-code-samples/blob/master/paypal_ipn.php#L125

1
Thanks to all. I resolved this issue with my own.Sachin Jaiswal

1 Answers

1
votes

I had a similar problem where I was getting INVALID response from paypal, but it was due to some characters in the passing values.

Make sure that the values you are passing to paypal are correct. My data were correct but caused issue due to a character that was not accepting by paypal.

I fixed it like below code:

$req = 'cmd=' . urlencode('_notify-validate');
        foreach ($_POST as $key => $value) 
        {
            $value = urlencode(stripslashes($value));
            $value = preg_replace('/(.*[^%^0^D])(%0A)(.*)/i','${1}%0D%0A${3}',$value);// IPN fix
            $req .= "&$key=$value";
        }

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, 'https://www.sandbox.paypal.com/cgi-bin/webscr');
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: www.sandbox.paypal.com'));
        $res = curl_exec($ch);
        curl_close($ch);