Reputation: 7463
I am currently testing an IPN script in PHP, using Paypal's sandbox.
It seems to work fine, except that it seems to get hit twice every time. I put in some code right at the top to just send me an email alert so I know the script has been executed. I get that alert twice with every transaction.
I can even comment out everything in my script except that line, and I still get it twice, so I think I can be reasonably certain the problem is not in my IPN script but something on the Paypal end.
I don't know if this means I've got some setting in my account on Paypal wrong, or if there's a normal part of Paypal workings that I'm not understanding or what's going on. I'm pretty sure my IPN script shouldn't be running twice for every transaction, though.
Is there a reason my IPN script would get hit twice? Is there something I can or should be doing about that?
Updates:
I have confirmed that the double hit happens every single time.
There actually is a difference in the two emails I get back. In one there is a payment_date
variable, and in the second one there is a subscr_date
variable. The subscr_date
variable is set to a time just a few seconds after the payment_date
.
While it would seem that all that is happening is that I am getting two notifications, one for the payment, and one for the subscription starting, this still strikes me as odd. My understanding of the IPN script is that its purpose is so that I can execute changes in my database (or whatever else) based on a successful payment. If they intend to hit me twice each time, then whatever changes I intend to execute will be done twice, which I think is clearly not the ideal approach.
Also, since what a customer is purchasing is a subscription, it seems they are giving me two notifications about the same thing with a different names each time. Also rather strange.
So I'm still wondering... is this normal, and what should I be doing to prevent my code from being executed twice?
Upvotes: 3
Views: 1552
Reputation: 568
You are getting 2 different IPN events - 1 to confirm the payment and 1 to confirm the start of the subscription.
See the IPN subscription events here http://www.paypalobjects.com/en_US/ebook/subscriptions/notifications.html#1032718 and the IPN subscription variables here http://www.paypalobjects.com/en_US/ebook/subscriptions/Appx-ipn_subscription_variables.html (scroll down to Table A.2) for what you can expect to see in each type.
There are also IPN events, for example to mark the end of a subscription, which are not directly related to a payment.
Upvotes: 3