Transaction Integration for AffiliateWP and OptimizePress

by Brandon
Transaction Integration for AffiliateWP and OptimizePress

I was recently working on a project that used OptimizePress and subsequently the OptimizeMember plugin. The client I was working with had already purchased AffiliateWP and wanted to use this as the solution to their affiliate tracking needs. So nearing the end of the project, they requested that I add affiliate tracking capability using AffiliateWP. Integration of these two systems ended up being much more work than I had anticipated.

I knew early on that OptimizeMember does not integrate directly with AffiliateWP, however I found an AffiliateWP support page that stated AffiliateWP just needed a page visit after a purchase to record the affiliate commission. While the purchase redirect seemed like an easy solution, the problem I ran into is that there was no way to link a transaction with its affiliate. Furthermore, my client did not want such a redirection to occur so I had to come up with a different approach. Within the OptimizeMember plugin settings you can set up URL notifications for various events. With this in mind, I created a URL notification that would fire upon a purchase and pass enough information to make the connection between a transaction and an affiliate. After testing the URL notification page and found it worked well, I was onto the last step: visit the page using an affiliate link, make a purchase, and ensure the transaction is tied to the affiliate. To my frustration, no matter how many purchases I made I could not get the notification to fire and decided to contact OptimizePress support for help.

Unsure if this was a server or an application issue, I asked OptimizePress support if there was anything that would keep the notification from being fired. They responded that with a valid email address the notifications would work and requested login access to the site. Eager to wrap up this issue, I provided OptimizePress support with user credentials for them to further investigate. A few days later, they responded that the OptimizePress theme was out of date and instructed me to update it. Confused by the suggestion that an outdated theme would cause issues with the plugin notifications, I updated it anyway but the notifications still did not work. After some back and forth with OptimizePress support, they told me that they had reviewed my notification configuration and that since I was attempting to integrate with AffiliateWP I should instead contact AffiliateWP for help. At this point I was very frustrated because the issue was not with the AffiliateWP integration-the issue was with the OptimizePress notification system. I replied to OptimizePress support expressing this sentiment and they completely stopped responding. Very professional…

Since OptimizePress support had stopped responding, I was on my own. I dug into the code and started looking for where the notifications were being fired. What I found should have been a simple answer from OptimizePress support: payment notifications will not fire until after the purchase is made and the user completes registration. This created a problem for me because the user registration did not retain affiliate referral information and I had no way of knowing if an affiliate referred the user. This payment notification setup was not going to work for my needs and if I was going to get a link between these systems, I would have to abandon my current strategy and start over.

I found OptimizeMember had hooks in place for PayPal purchases. Since I was using PayPal, I concluded that this was the next logical place to attempt an integration. I created an empty plugin project and added a hook to the PayPal hook that OptimizeMemberprovided. After numerous logging and debug sessions to find the purchase data I needed, I was able to obtain a user’sinformation at the time of purchase, but I was still unable to link an affiliate. Since I was having a hard time getting the required affiliatedata, I contacted AffiliateWP support and they were very helpful. With their framework and provided code examples, I was able to obtain the affiliate id, referral id, and process a paid referral. I then created a custom plugin that integrated OptimizeMember with AffiliateWP seamlessly.

I vowed that in my spare time I would make the plugin open source and publish it on WordPress in hopes of saving someone else the time and frustration I encountered. You can find the plugin in the WordPress plugins page here and access the code at this GitHub repository. My hope is that this plugin can be a starting point for a tighter integration between OptimizeMember and AffiliateWP. If you find yourself using this plugin or modifying it to meet your needs, I’d love to hear from you.