Paypal IPN Message - paypal

i have included the payment system in my site using paypal.
in paypal, i have choose the payment message service as IPN.
Now i have some question about the flow my site, i don't how to handle it.
1) Now If the user name called "A" had paid for some service and at the same time user name called "B" is also making payment, How about I came to know that which user had paid for the service? [ means what should i include in my payment flow to know about the user? should i add the user id with my item name and then get that id from that item name in IPN message url]
2) What time is taken by IPN message, bcz last time when i was checking my payment module then i don't know when my message was sent by paypal, but it was certainly taken time say more 3 - 5 min, now what should i do to get the payment status immediately bcz in my site i want that, as soon as user had paid then that service should start immediately.
EDIT: Can i include any custom data with my payment. Bcz in IPN message sent by paypal, their is one filed called "custom" sent by the paypal so to add that if i have to include that file in my payment form.

1.)
there are custom HTML transaction variables that can be set for things like this and you will have to name the input tag accordingly. There would be two input elements for each custom field that you want to save. One for the field name and one for the field value.
These tags are on0, on1, or on2 for the custom field names and os0, os1, and os2 for the custom field values.
I would send on0 with a value of "UserID" and os0 the actual ID.
These values will be represented in the IPN as follows:
os0 is represented as option_selection1
on0 is represented as option_name1
Here's the info on PayPal's Parameters
2.) They are almost always within 5 minutes, but I have heard that from time to time there can be periods where this might be significantly more. You can always create a PDT success page that digests the same info that would be in the IPN message. This would be your return page from the paypal site and all your data would be included in the request. Just make sure you keep track of you still use the IPN in case the transaction succeeds but the user never makes it back to your site. I like using both methods so you can customize the welcome back to your site for the user based on their transaction. And if you doing that and have all the info you need, might as well process the order as well.

Related

How to check the initial message sent to paypal?

I need to match the user who triggered the initial Http message sent to paypal, to the IPN i'm receiving on my backend when the transaction is completed. Since Paypal is unaware of my user database I'm looking for some kind of transaction ID.
the thing is, when a user clicks on a paypal hosted button, Paypal opens another window and processes the buyer login and every other payment steps there.
I've had a look at the URL of that new Paypal window and there is nothing there that will also be stated on the IPN.
Is there a way to check the initial http message sent to paypal from my frontend?
You can use the custom parameter to pass your own unique ID into the payment request. This would then be returned in the same custom parameter included in IPN.
The field is literally called custom and you can pass anything you want in it up to 256 characters.
You should be able to add it as an additional hidden field in your HTML form for the hosted button. If it doesn't pass as expected that way, though, you'll need to use a non-hosted button.

Paypal IPN getting delayed by hours

I'm using paypal adaptive payments to make transaction via paypal. Although few of transactions are taking more than 6 hours too receive IPN.
I've gone through forum posts and their documentation, I came through - https://developer.paypal.com/webapps/developer/docs/classic/products/instant-payment-notification/
"Because IPN is not a real-time service, your checkout flow should not wait for the IPN message before it is allowed to complete. If the checkout flow is dependent on receiving an IPN message, processing can be delayed by system load or other reasons. You should configure your checkout flow to handle a possible delay."
The callback is taking more than 6 hours is way too much. any suggestions ?
I've built several custom carts. On average, I see the PayPal IPN come back within 2 minutes at the longest, and usually recurring payments take longer than single payments because they send two IPN messages, not just one, on the initial setup. I usually take the 'custom' property and put a unique identifier that I have permanently cookied. So, even though I may see an initial IPN come in on a recurring payment, I wait for the one that says that txn_type is subscr_payment and also that payment_status is Completed. You can't really trust a subscription payment as being paid unless you see that second message. And if it's a single payment, then I look for txn_type to be web_accept and payment_status to Completed.
The way I handle things is to redirect the customer to PayPal to purchase using the form button technique. The customer pays and then gets redirected (thanks to the form hidden vars I created initially) back to my own custom cart URL that I specify. I call that URL the payment-confirmation script. I display a message with a progress bar to please wait while their payment is being confirmed with PayPal. I hold them there 10 seconds and then redirect to the receipt. It is on the receipt where I check the database to see if my IPN script has already processed this order. If not, then I redirect them back to the payment-confirmation script again for another 10 second progress bar delay. My receipt uses a session cookie to ensure I never send them into a loop more than one time to the payment-confirmation script. So, the customer waits another 10 seconds and then comes back to the receipt page, where I test again, reading my permanent cookie on the 'custom' property that I saved, versus the 'custom' property that comes in from the IPN that I use as the order key in the database. Usually within the first or second 10 second delay, the IPN has come in and I can proceed. However, if the IPN has still not come in, then I redirect to a friendly error message saying that their payment cannot be confirmed and to call our call center to remedy the issue. Our call center techs then see the delay problem in PayPal, back the other transaction out, and sell to the customer over the phone manually, instead.

PayPal notify url return variables - customer phone number

Is there a way to return the buyers phone number in the notify url variables? I do not see it being returned at all. I am getting the address and all other profile information but not the phone number? Is there something I need to set prior or a hidden field I need to setup in the form prior to checkout?
While the IPN reference does list contact_phone as an IPN field, my experience is that it is not frequently returned. Many people do not have it in their PayPal account profile (a similar problem exists for Ebay customers). There is nothing you need to do on your end, except make sure you code can process that field. It will be included if it is present.

Refreshing browser after PayPal PDT payment causes item to be bought twice

I have implemented PayPal payments using PDT. I realize a combination of PDT and IPN is recommended, however for my purposes PDT is sufficient.
I am able to direct user to PayPal, collect payment and then conduct an action (updating account credits for the user in the database) when the user returns to my site. The URL shows an address like:
http://www.domain.com/process_pdt?tx=45138128VH922173V&st=Completed&amt=1.99&cc=USD&cm=&item_number=
So far so good. The problem I have is refreshing the browser with this URL causes the user's account to get credited again without redirecting the user to PayPal to collect payment a second time.
I have read that I should add the transaction id (tx in URL above) to the user table and check to ensure this tx id has not already been used. If it has, I should display an error message. Is this the only way to go about this, i.e. by storing each tx id in the user table and then checking for the id's existence each time the process_pdt URL above is called by the user (legitimately or fraudulently)?
Ah, yes: this is indeed the only way to go. As a simple sanity check you may want to do a redirect from the process page to a URL that does not include the txn_id (that way a casual refresh won't cause the problem, but if they use their back button it will still happen) but you must verify that the txn_id is only used once yourself.

Which PAYPAL method to use?

I am working an e-commerce site which will allow pdfs to be downloaded once payment is done.
So, user will put them in a cart, click buy using paypal and from there will come back to see download link on a success page.
I have implemented PDT.
Not sure which is the best option ?
Please help. I want to take care of any connection lost scenario too, like user completes payment at PAYPAL and while returning back to our site's success page, connection is lost and for some n days, user couldnt access internet as well.
I would just use the IPN.
Keep a record in your database that has all of the order items.
e.g. Order and Order Items (in 2 tables)
Then send that primary key across as the "custom" variable.
Then your ipn handler page will validate the payment and then email the customer their digital goods.