Now I don't have to guess. I can see what you're doing and that takes a lot of mystery out of the question. Your code is setup to only handle a very simple case of a person buying 1 specific item at 1 specific price.
Your code does
not (but should):
*Process Multiple items (could be ok, if you only are selling one item, one at a time and never support shopping carts)
*Check whether the payment_status is = "XXXX" (see table below) and modify the database as needed
*Check that txn_id has not been previously processed as payment_status="Completed"
*Check that receiver_email is your sellers correct email
*Process payment and mark item as paid, notify seller.
*Filter the incoming user data
For starters you need to process the
payment_status values. Here's a list of their possible conditions from IPN variables found at
paypal docs.
[text]*Canceled_Reversal: A reversal has been canceled. For example, you won a dispute with the customer, and the funds for the transaction that was reversed have been returned to you.
*Completed: The payment has been completed, and the funds have been added successfully to the account balance.
*Created: A German ELV payment is made using Express Checkout.
*Denied: The payment was denied. This happens only if the payment was previously pending because of one of the reasons listed for the pending_reason variable or the Fraud_Management_Filters_x variable.
*Expired: This authorization has expired and cannot be captured.
*Failed: The payment has failed. This happens only if the payment was made from your customer's bank account.
*Pending: The payment is pending. See pending_reason for more information.
*Refunded: You refunded the payment.
*Reversed: A payment was reversed due to a chargeback or other type of reversal. The funds have been removed from your account balance and returned to the buyer. The reason for the reversal is specified in the ReasonCode element.
*Processed: A payment has been accepted.
*Voided: This authorization has been voided.[/text]
From this list you can see that your db query (shown below) should not just put 'Valid' all the time in for payment_status. And in the case of "Pending" there is also a pending_reason value you might want to capture.
Code: Select all
mysql_query("INSERT INTO db_listener (datepayment, firstname, lastname, buyerid, emailpaypal, emailreceiver, price, itemname, productid, txnid, status) VALUES ('$todaydate', '$first_name', '$last_name', '$custom', '$payer_email', '$receiver_email', '$payment_amount', '$item_name', '$item_number', '$txn_id', 'Valid')");
To specifically answer your question, you use the payment_status to process your payment_status="Refunded" case. But there are more payment_status conditions you need to process. The basics: "Denied", "Pending", "Reversed", "Canceled_Reversal", "Refunded" and the most important "Completed" should all be checked and processed accordingly.
FWIW you can do all this testing in the sandbox using the IPN simulator, you don't need to do live transactions.