Web Hosting Talk







View Full Version : Trouble with PHP and PayPal IPN


latheesan
03-22-2009, 10:55 PM
Hello,

I am working on a simple paypal ipn processor and i am running into some troubles.

PayPal_IPN_Process.php - http://pastebin.ca/1368384

Code That Is Not Being Executed - http://pastebin.ca/1368387

In my test run, when someone donates, the donation is logged in the table but it was in pending status because of the reason "multi_currency".

So, i logged in and clicked "Accept" payment.

What should've happened is my donation log updated to completed status and the user should have recieved the item he/she paid for.

So, any idea why it isn't working? I've looked at the code/sql-quries in detail. Everything seems to be right but it's not working like it should. Any idea?

foobic
03-23-2009, 01:22 AM
it was in pending status because of the reason "multi_currency".So the payment was in a different currency to your account? If so, it's a setting in your Paypal account under Profile -> Payment Receiving Preferences. You can choose to only accept it manually or accept and automatically convert to your own currency.

latheesan
03-23-2009, 02:26 AM
I accept donation in Euro only, but my player was from usa, so he paid in USD. So, paypal ipn said the payment is pending with the reason "multi_currency".

When this happens, i have to login to my paypal business account and click "Accept" payment. When i do this, paypal should send another ipn with same txn_id and this time with the payment status "Completed".

When this happens, my script should automatically detect a donation log in db already for this, so it just carries out the payment verification check and if it passes, i update the "payment_status" and "pending_reason" field and give the cash points to the donor.

Cash Points are what the player's get for donating. Cash points are non existing items, a simple point system.

latheesan
03-23-2009, 03:24 AM
What i am trying to achieve is create a paypal ipn processor that can handle multiple payment_status. The reason for this is, on the control panel, i want to show a list of donation log when the player logins to the donation panel.

So, if a donation was in pending status, it'd show on the site. It's status will be updated when ever paypal notifies my ipn script.

To work with multiple payment_status, i tweaked the code like so - http://pastebin.ca/1368868

After a trial run, this too did not work. Any idea?

foobic
03-23-2009, 06:15 AM
In my PayPal account under Profile -> Selling Preferences -> Payment Receiving Preferences, I have:
Block payments sent to me in a currency I do not hold:

Yes
No, accept them and convert them to US Dollars
Ask Me
Default is "Ask Me". What's yours set to?

latheesan
03-23-2009, 01:17 PM
Mine is set to "Ask Me".

I know you can set it to automatically accept and convert.

What i am trying to do on my IPN Processor is handle all kind of payment status.

For example, if a player donated to me via eCheque, The payment will take 3~5 days to clear. So, the first ipn response will have the payment_status "Pending" (because paypal is waiting for the eCheque to clear).

So, if my IPN processor can handle multiple payment_status, i'd be able to show the player that we have recieved the donation and currently waiting for the eCheque to clear.

So far my IPN processor can do this much. Log the donation and and only give the product to player, if the payment_status = "Completed".

When the eCheque clears, paypal should send me another ipn with the "Completed" payment_status. This is where my script is failing. It's failing to reliase that there is a log for this donation already and all it has to do is update that record and give the player his product he/she donated for.

My trouble is rather with the code i have, not the way my paypal account is operating for me.

foobic
03-23-2009, 05:21 PM
Ok, sorry - I misunderstood what your problem actually was. In that case I'd suggest you need to debug the code yourself. Start by printing out exactly what you're sending to PayPal and what you're getting back.

As a general suggestion I'd use cURL instead of opening socket connections yourself, but either way should work.

latheesan
03-24-2009, 05:17 PM
After anylysing the code line by line, found 1 tiny typo. I've fixed it :)