问题
When an IPN is verified as completed my code puts the txn_id in a database but it is not being set. All other PayPal variables that I am using are set but this one is not. I need a way to uniquely identity the transaction so that's why I am using that variable, here is my code that I use to grab the id:
$txn_id = $_POST['txn_id'];
I checked PayPal's list of variables and txn_id is listed on there but I'm not receiving anything/it's not set.
The payment is not a subscription payment, it's just a normal one time buy payment.
回答1:
How / where are you receiving the data? Shows us your HTML.
I recently had trouble receiving POST data from PayPal. However, the IPN.php still works. You can do some debugging on your IPN/return page.
Add this to your PayPal file to see exactly what you are receiving. If the POST section is empty, that will be your issue and you might need to work with GET data instead.
Option 1) Dump everything received into a file
function test_file_dump2( $msg ) {
$filename = dirname(__FILE__).'-IPN-dump.log';
$f = fopen( $filename, 'a' );
fwrite( $f, var_export( $msg, true ) . "\n" );
fclose( $f );
}
test_file_dump2($_POST);
test_file_dump2($_GET);
Option 2) Log all errors to in this directory
ini_set('error_reporting', E_ALL); // everything. Change to E_ALL & ~E_NOTICE); to remove notices
error_reporting(E_ALL );
ini_set('html_errors',TRUE);
ini_set('log_errors', TRUE);
ini_set('display_errors',TRUE);
ini_set('error_log', dirname(__FILE__) . '/-errors-ipn.log');
Option 3) if in success.php or a page you can see
echo "<pre> GET contents<br><br>"; print_r($_GET); echo "</pre>";
echo "<pre> POST contents<br><br>"; print_r($_POST); echo "</pre>";
来源:https://stackoverflow.com/questions/46015077/paypal-ipn-post-variable-txn-id-not-being-set