/ Development

Working with PayPal's API: The two most frustrating weeks of my life.

Notice
This was originally posted under my Minds.com account. However, now that I have a website, I've decided to move it over and clean it up.


PayPal is one of the largest and most trusted online payment solutions available. It's a top choice for anyone looking to start their business or commerce online.

I recently had the pleasure of working with their API for a commission. I've used them in the past, for simple one-time transactions, very simple stuff. However this commission warranted functionality that I'd never really used with PayPal before. So it was an egg hunt, I searched long and far (not really, their documentation is actually pretty thorough) to find the parts necessary to integrate the payment flow into my application.

Here's where the problems start though. My application was supposed to implement subscription based functionality, users would subscribe to the service and receive rewards instantly, if they canceled or refunded their purchase, their rewards were removed. Simple enough, right? That's what I thought too. I looked at some examples and countless StackOverflow posts and was able to grasp what logic I needed to program to be able to handle the IPN system's notifications.

After programming the logic in, I went to test... assuming that the IPN simulator available on their website allowed you to test subscriptions as well. Nope. You've gotta test live in the sandbox. Okay... that's not necessarily an issue, plus it'll be better because I'm getting actual values. I tested it a couple of times and all went well. Then out of the blue, errors. Errors everywhere. My mind was at a loss, I had no idea what the hell could've happened in the span of 2 or 3 hours of idling. I looked over the code maybe 5-6 times wondering just what the hell could possibly be causing this. Truth is there wasn't really anything wrong with it. I just didn't account for something that I never saw in their documentation. Perhaps it was there, or not. Who knows? It's over now. Regardless, their IPN system does not send requests in sequential order.

Here's how the subscriptions work for their IPN system: when a new recurring payment profile has been established, they send a notification that lets you know that a new profile was created, it includes some basic metadata about the subscription. Generally you log or save this somehow, because you will need this later on to relate the actual subscription payments to it. Next, a subscription payment notification is sent. This is when PayPal has actually withdrawn the money from the account and transferred it to yours, and thus you should active the service or do what ever active logic your application does. All should go well, right? Wrong. PayPal doesn't guarantee that these will come in sequential order, instead sometimes the payment may come first and sometimes subscription profile creation notification might be sent first.

Well shit. Time to rework like have my IPN handler. Although a small problem, I thought it absurd for this to happen. It would only, and I mean only, make sense for the profile notification to be sent and then later the payment notification. That's unfortunately not how it works, but as I said it's a relatively small issue.

You might be thinking: Great! You've solved your problem, all is well right? or perhaps maybe you're thinking: Oh dear, you're dumb. If you read more carefully you would see that they might not come in order.

Well yeah, the latter is probably true, the former... very wrong. That whole testing and integrating logic part sounded like everything went super amazing but it actually didn't. During that time I don't know what in the hell PayPal was doing but the entire sandbox environment was practically broken. Random 500 errors spewing everywhere, you'd have to manually clear your cookies to get one page to work, login, and then you'd have to clear them again. That went on for a few days but was eventually fixed (I think?). Next, PayPal's checkout suddenly doesn't work. I mean there is literally no response at all. Just a blank page, and a 200 HTTP Status code. "anmaosdnINDAISNDANSDI waght HADSDAIDSANDAINSD" are pretty close to what my fingers may have smashed on the keyboard at the time. I didn't know what to do and I just wanted to be done with the commission. That was a breaking point for me, I ended up taking a long hiatus from working on it and came back to it hoping for everything to work again.

For the most part, it did. There were still a few quirks here and there but it seems like PayPal had fixed a lot of their issues. Funnily enough, prior to the whole keyboard smashing, I submitted several angry feedback forms to them explaining in clear and explicit detail how much I hated the broken sandbox environment and wished with all my heart that it be fixed. Maybe they heeded my words. Regardless, it worked again.

This was the end of my journey with PayPal. From there on things were okay and I was happy. Needless to say, the next time I need to integrate ANY sort of payment solution into my application I'm sticking with Stripe or another alternative. I like PayPal, I use them for practically all of my online transactions, but I don't plan on using them for any application related work any time soon. It seems like they're in a transitional phase from legacy systems to new modern systems. I commend them for that and recognize that their infrastructure probably has a lot of issues they need to work out right now, so I'm not going to completely abandon them.

Anyway, I hope you enjoyed this small story about my journey with PayPal. I definitely enjoyed it.