PayPal Adaptive Payment IPN with Custom Variables

I've already published two articles regarding PayPal Adaptive Payments. The first dealt with generating a valid IPN response, where the second covered decoding the strangely-encoded variables PayPal gives us to work with.

Today I will cover one of the last issues that seems common among PayPal's IPN and Adaptive Payments: custom variables.

Why do we need custom variables?

PayPal's IPN is an important tool in automating payments from users. We can make our servers act accordingly once our PayPal account receives funds. The previous article covered utilizing the variables passed to us from an IPN message such as payment amounts, account emails, and payment status, but what about variables we need to use to identify payments beyond amounts and email addresses?

We can use custom variables

Traditionally, we would just use the custom payment variable, but this restricts us to only one variable with a length of 255 characters. This is a caveat we must overcome for systems that require more than one variable of an arbitrary length. The secret lies within the notify_url payment variable.

Okay, what now?

It's easy- just pass your data through URL parameters. Use your standard notify_url and append your urlencode'd variables.

When your server receives the IPN message, use your IPN handler to strip the data from the URL using php's $_GET variable. This simple trick effectively extends the functionality of PayPal's IPN messaging.

This should conclude the series of articles regarding PayPal's IPN and Adaptive Payments. Know any other tricks that should be shared? Let me know!