transactional operations with paypal api - paypal

I am adding payments to our website. I would like a way to update my database and capture a payment via paypal api within a transaction. Does anybody know if there is any way to do this? Perhaps a paypal callback?

Do the capture and after that, update the database. Some minutes later you'll receive an IPN message with details about the capture and you can use it to check whether the database is updated. But don't rely on IPN only, from my experience I can say that it's not 100% reliable. Sometimes it happens that I don't receive some of the IPNs, or they are delayed with some hours.

Related

What are all possible scenarios for PayPal's IPN?

Sadly, PayPal's documentation is woefully inadequate.
What are the possible values for payment_status, and when do they occur?
I am aware of:
Completed - pretty self-explanatory
Pending - eCheque payment that hasn't gone through yet
And... that's it. That's all that's mentioned in the documentation.
But I need to know, what other values exist? What do you get if an eCheque is denied? What about when a client (fraudulently, -mutter mutter-) issues a chargeback against a payment (and rips you off for a few hundred quid -more muttering-), what does IPN send in these cases?
Ultimately I want to automate more of the scenarios that come up. For instance, if a Pending transaction arrives then I want to be able to reliably explain to the client that their eCheque is pending and they will be notified when it clears, and then proceed to notify them when it is indeed cleared (or denied).
Since I deal in virtual currency, I want to be able to debit a user's account automatically if they file a chargeback, but then credit them again if the chargeback is resolved and the funds returned to me.
And I really don't like how there might be other scenarios that I can't prepare for, simply because the documentation is shite.
Anyone got some hands-on experience, or are there any actual devs from PayPal who will honour this call?

IPN delay and SAAS application

I have a SAAS web application that works through a subscription fee. If the subscription is valid everything works fine, otherwise the app goes in read-only mode until the customer renew the subscription. I've developed the payment flow with the PayPal API.
The problem is that PayPal Documentation says this:
"Although PayPal usually processes IPN messages immediately, IPN is not synchronized with actions on your website. Internet connectivity is not always 100% reliable and IPN messages can be lost or delayed. The IPN service automatically resends messages until the listener acknowledges them. The service resends messages for up to 4 days.
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."
Unfortunately this is exactly my case: when customers renew the subscription I need to immediately activate the app so I placed all the logic right in the "notify callback" where I have to create the order, send a confirmation email, update some session variables... but I if there's a delay from PayPal IPN this is a problem!
In these days I did some test in Sandbox mode and in several cases I got an answer from IPN even 4 hours after the successful payment! This is unacceptable for my app!
Finally the question: what's the best solution for my case? It makes sense to move the application activation from "notify callback" to "success callback"? There may be problems?
Thanks
Don't use IPN for this; it's a poor fit & not designed to be inserted into synchronous user experience flows. It works fine as a way to initiate offline fulfillment, but can delay your customers if they are actively waiting for access.
You don't specify which PayPal product you are using, but each product should provide a way to immediately give you feedback that the payment has been completed. For example with Express Checkout or any API-based payment you can take action (activate/re-activate a subscription) when you receive the successful API response (the DoEC API in the case of Express Checkout).
With web-only/non-API products you can take action when the customer redirects to your return_url, using PDT to securely get information about the transaction if you need that (it can include an IPN-style key that you post back to PayPal to verify, exactly as you do with an IPN).
If you are concerned about the edge cases of someone closing their browser before it can redirect to you, or some other sort of dropped connection or programming error, you can also check & activate/fulfill upon receipt of an IPN to catch any fallout. So all customers that complete a normal payment flow are activated immediately; if they do something wonky (or your code breaks, or whatever) then the activation still happens, albeit potentially delayed by a few seconds or minutes.

PayPal simple Subscribe and Unsubscribe

I have a page that will have a monthly subscription fee and I was wondering if PayPal's simple subscribe and unsubscribe buttons can do the trick without using the API.
On subscription the user is returned to my page and I handle the subscription, but if the user decides to unsubscribe how can I handle it? Or is it possible at all?
Does the page make a return call to the same address I have given for redirection?
Thank you for the help in advance.
Yes, Standard Subscription buttons can be used without any API calls. I would recommend using Instant Payment Notification (IPN) to handle all transactions associated with subscription profiles.
PayPal's IPN server will POST transaction data to a listener script you have on your server when transactions occur in real-time. This allows you to automate post-transaction procedures like updating your database, sending email notifications, or anything else you might like to do when transactions occur.

How do I deal with PayPal customers who can't direct return

PayPal states:
Note: If you have turned on Auto
Return and have chosen to turn on
PayPal Account Optional for new users,
a new user will not be automatically
directed back to your website, but
will be given the option to return.
But if some of the customers don't get "Auto Returned", how do I handle them programmatically?
Paypal does not guarantee autoreturn especially when Paypal Account - optional setting is on.
The right way to handle the integration is with Instant Payment Notification (IPN) option. Using IPN Paypal will make POSTS to your page notifying you of payment events. The following link explains the IPN process pretty well.
To summarize, you will write code that will trap posts from Paypal and then make sure to update your billing data accordingly.
Also, IPN messages might be slightly delayed.
Create a script (cron or what) that does check for such payments at paypal perodically (e.g. every hour).
Is this what you mean?
https://www.paypal.com/cgi-bin/webscr?cmd=p/mer/express_return_summary-outside
If not, you may need to be a little more specific with your question. Like - are you using paypal pro? How are your customers checking out? etc. And now that I read the answer below mine, I wonder if you are even talking about the payment process and not something else.

PayPal TimeOut - DoExpressCheckoutPayment

We are using PayPal on a faily large website, integration went well with all code helpers from the integration wizard. Now we had processed a number of transactions in the first day of putting this live but a small percentage (5%) essentially had there transaction processed by PayPal but our system recieved a TimeOut. I believe this happens at the point where we submit the "DoExpressCheckoutPayment" Method. and because of this the system cannot tell if the payment has been complete or not.
This is a real tough one, as the website has a live currency that we need to update so paypal taking the money but the system not updating is not acceptable.
I'm interested to know if this is a common problem and how we should go about handeling it. I'm doing my best to re-create the issue but cannot at this time.
This looks like a similar problem - https://www.x.com/thread/45136
Any help would be appriciated!
Add retry logic to your application. This is a common way of handling this problem.
After looking into this in more depth, retry logic is not a good idea as the TimeOut is due to the response (So paypal has most likly credited the account).
Instant Payment Notification (IPN) seems to be the solution.