Jump to content


Photo

Ipn Paypal Not Working Code Stops....

php ipn sql

  • Please log in to reply
1 reply to this topic

#1 danielobo

danielobo

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 18 December 2013 - 11:35 PM

I got to check out deeper into my paypal ipn code. I used INSERTS to make sure I know where the code stops working. The code will not pass this section. Here is the code:
 
   $res = fgets ($fp, 1024);
 
Thus, it never reaches 
 
                if (strcmp($res, "VERIFIED") == 0) {
 
Here is most of the code:
 
// Response from Paypal

// read the post from PayPal system and add 'cmd'
$req = 'cmd=_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";
}

// assign posted variables to local variables
$data['item_name'] = $_POST['item_name'];
$data['item_number'] = $_POST['item_number'];
$data['payment_status'] = $_POST['payment_status'];
$data['payment_amount'] = $_POST['mc_gross'];
$data['payment_currency'] = $_POST['mc_currency'];
$data['txn_id'] = $_POST['txn_id'];
$data['receiver_email'] = $_POST['receiver_email'];
$data['payer_email'] = $_POST['payer_email'];
$data['custom'] = $_POST['custom'];

// post back to PayPal system to validate
$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

$fp = fsockopen ('ssl: // www. sandbox.paypal. com', 443, $errno, $errstr, 30); 

if (!$fp) {
// HTTP ERROR
} else {

fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp($res, "VERIFIED") == 0) {
 
Does anybody know why it does not pass this section of the paypal ipn code?
 


#2 viveknanda

viveknanda

    Member

  • Members
  • PipPip
  • 12 posts

Posted 03 June 2014 - 01:43 PM

why not use curl? its much neater and easier to manage!

<?php
$ch = curl_init('https://www.sandbox.paypal.com/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
 
if( !($res = curl_exec($ch)) ) {
    curl_close($ch);
    exit;
}
curl_close($ch);

if (strcmp ($res, "INVALID") == 0) {
//invalid access to the IPN Script or something wrong with the transaction parameters
}
else if (strcmp ($res, "VERIFIED") == 0) {
//do your stuff
}
?>






Also tagged with one or more of these keywords: php, ipn, sql

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users