01-05-2008, 12:34 PM
|
#6 (permalink)
|
|
The Reckoner
Join Date: Sep 2007
Posts: 437
Thanks: 22
|
You need to compare your details against the details sent back from paypal. It's actually straight forward, although they make it seem difficult. You could add the following validation function and then call that in replace of the comments:
PHP Code:
function validatePaypal() { // Ewwww global, I feel dirty :) global $payment_status, $payment_currency, $payment_amount, $receiver_email; // Check that the payment is actually complete if ($payment_status != 'Completed') { error_log('IPN failed, expected payment status Completed, received ' . $payment_status); return false; } // Check receiver email against your email. elseif ($receiver_email != PAYPAL_EMAIL) { error_log('IPN failed, expected reciever email ' . PAYPAL_EMAIL . ' received ' . $receiver_email); return false; } // Check the payment amount against your products amount elseif ($payment_amount != PRODUCT_AMOUNT) { error_log('IPN failed, expected payment amount of ' . PRODUCT_AMOUNT . ' received ' . $payment_amount); return false; }
// Check the payent currency against your requested currency elseif ($payment_currency != PRODUCT_CURRENCY) { error_log('IPN failed, expected ' . PRODUCT_CURRENCY . ' currency, but received ' . $payment_currency); return false; }
// Todo: Check for duplicate txn_id return true; }
Then, replace all the comments:
PHP Code:
// check the payment_status is Completed // check that txn_id has not been previously processed // check that receiver_email is your Primary PayPal email // check that payment_amount/payment_currency are correct // process payment
With a call to the function:
PHP Code:
if (validatePaypal()) { // Payment is complete and is OK! Make sure you log this payment, // especially the txn_id } else { // Payment failed, we have the error logs but you should // also log this for manual inspection }
I've missed out one validation check from the validatePaypal function and it's an important one. You need to check previous payments txn_id and ensure that you're not receiving a duplicate.
Hope that helps.
__________________
Any fool can write code that a computer can understand. Good programmers write code that humans can understand.
|
|
|
|