2016-08-04 4 views
0

Ich weiß, es gibt viele Fragen zu dieser Anfrage, aber ich kann nicht die richtige Antwort auf meine Bedürfnisse zu beurteilen. Hier ist mein aktueller Code für mein Projekt. und ich bekomme immer eine ungültige Antwort von Paypal mit Paypal Sandbox IPN Simulator.Neueste 2016 Paypal IPN Code immer UNGÜLTIGE Antwort

Kann mir jemand zeigen, was mit meinem Code falsch ist, schätze ich Ihre Hilfe. Vielen Dank im Voraus.

<?php 

$post_data = file_get_contents('php://input'); 
$post_array = explode('&', $post_data); 
$dataFromPayPal = array(); 
foreach ($post_array as $keyval) { 
    $keyval = explode ('=', $keyval); 
    if (count($keyval) == 2) 
     $dataFromPayPal[$keyval[0]] = urldecode($keyval[1]); 
} 

$req = 'cmd=_notify-validate'; 
if(function_exists('get_magic_quotes_gpc')) { 
    $get_magic_quotes_exists = true; 
} 
foreach ($dataFromPayPal as $key => $value) { 
    if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) { 
     $value = urlencode(stripslashes($value)); 
    } else { 
     $value = urlencode($value); 
    } 
    $req .= "&$key=$value"; 
} 

$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); 


$tokens = explode("\r\n\r\n", trim($res)); 
$res = trim(end($tokens)); 

if (strcmp ($res, "INVALID") == 0) { 
    echo "INVALID"; 
} 
else if (strcmp ($res, "VERIFIED") == 0) { 


$item_name = $_POST['item_name']; 
$item_number = $_POST['item_number']; 
$payment_status = $_POST['payment_status']; 
$payment_amount = $_POST['mc_gross']; 
$payment_currency = $_POST['mc_currency']; 
$txn_id = $_POST['txn_id']; 
$receiver_email = $_POST['receiver_email']; 
$payer_email = $_POST['payer_email']; 


    //STORE temporary info to table 
    //================ 
    require 'config.php'; 

    $query = "INSERT INTO Payments (ItemName,ItemNumber,PayStatus,PayAmount,PayCurrency,PayTransID,PayEmail,RecEmail) 
      VALUES('$item_name', '$item_number', '$payment_status', '$payment_amount', '$payment_currency', '$txn_id', '$payer_email', '$receiver_email')"; 
    $result = mysqli_query($con, $query); 

    mysqli_close($con); 


} 


?> 

Antwort

0

Ich habe endlich die Antwort für meine Anfrage gefunden. Sie können diesen Code als endgültiges IPN für Sandbox oder Live verwenden. Mit der folgenden Überlegung:

  1. Achten Sie darauf, Ihren IPN-Listener zu platzieren -> Mein Verkaufstools -> Instant Payment Notifications Abschnitt.
  2. Verwenden Sie nicht IPN Simulator in Sandbox, es wird immer UNGÜLTIG zurückgegeben.
  3. Erstellen Sie eine tatsächliche Sandbox-Schaltfläche und verwenden Sie sie, aber setzen Sie Ihren IPN-Listener NICHT auf RETURN PAGE, die besagt "Nehmen Sie Kunden zu dieser URL, wenn sie die Kasse beenden".

Das ist alles. Ich hoffe, das wird helfen.

Und hier ist der Arbeitscode:

<?php 
$post_data = file_get_contents('php://input'); 
$post_array = explode('&', $post_data); 
$dataFromPayPal = array(); 
foreach ($post_array as $keyval) { 
    $keyval = explode ('=', $keyval); 
    if (count($keyval) == 2) 
     $dataFromPayPal[$keyval[0]] = urldecode($keyval[1]); 
} 

$req = 'cmd=_notify-validate'; 
if(function_exists('get_magic_quotes_gpc')) { 
    $get_magic_quotes_exists = true; 
} 
foreach ($dataFromPayPal as $key => $value) { 
    if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) { 
     $value = urlencode(stripslashes($value)); 
    } else { 
     $value = urlencode($value); 
    } 
    $req .= "&$key=$value"; 
} 

$ch = curl_init('https://www.sandbox.paypal.com/cgi-bin/webscr'); 
//use https://www.sandbox.paypal.com/cgi-bin/webscr in case you are testing this on a PayPal Sanbox environment 
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) { 
     echo "INVALID"; 
} 
else if (strcmp ($res, "VERIFIED") == 0) { 
     echo "VALID"; 
} 

?>