Clickbank is an payment processor that doesnt seem to have any documentation or working complex examples. However, and this is a big however, they take payments on their site from a single url (ie no form need be posted to their site) and even better it handles the entire affiliate click through arrangements for your products. They seem to have a monopoly on this particular area so have no need to upgrade their systems to fall more inline with other processors (like Paypal for example).
I shall start from the beginning with the initial steps. Let us assume that we have a clickbank account for the time being…
The first step is to log into your clickbank admin account and set up your products with the price, name and, something else they require, a thankyou page.
Note that for the first product you sell with clickbank there is a $50 fee for the priviledge of having it activated. I have no idea whether you get this back or not.
So set up your product, get it activated and keep note of the Product ID…
As previously mentionned, Clickbank takes money for you when you send your clients to a specific payment page on a url which is formed in the following way:
Where the parts in square brackets must be replaced with the appropriate information.
That is essentially it…. you create the product, generate the url, put it on your site and start collecting money.
But what if you want to do something useful with the payment like provide a service of some sort or systematically keep a record of transactions on your own server?
For this you need to enable the IPN (Instant Payment Notification) service which requires ticking a couple of boxes to prove you aren’t an idiot (which, if doing this type of integration, you most likely won’t be). You also need to give it the url to ‘Call Back’ to (The url of the script that will be dealing with the data collected during the transaction).
Once IPN has been enabled you can write a script to receive the data sent by Clickbank on each payment. This basically needs to do three things:
- Verify that the request is valid
- Send back a 200 OK response code
- Do anything you like with the data
The first part is fully documented on their site, carefully hidden but fully documented with examples in various languages. It basically consists of taking the first 8 characters from a sha1 encoded string built up of the concatenated variables sent via POST with your ‘Secret Key’ on the end. When compared to the verify code they send you in the same POST request you can see whether the request is genuine or not.
See the ‘You might also be interested in’ section at the bottom of this post for a code example and links to official documentation
This is the first time that I have mentioned the secret key but it is just that, a key which you set up in the Clickbank admin system that you also put in your script but NOT tell anyone else.
Once you have verified the request is a genuine one then you can move onto the part that does something to your site/database.
The data that it sends you says:
- Type of transaction it is (SALE, BILL, REFUND, TEST…)
- Product sold
- Time and date of sale (in a useful unix timestamp)
- Who purchased it (name and email)
- Product ID
This is useful for basic systems that simply log a sale so with this data you should be able to email yourself to send a book or get it to activate an account etc..
I needed a bit more information than this though so needed to use another variable it sends through called ‘cvendthru’. What cvendthru does is gives you a list of the extra arguments which were given against the sell url (example above but with ‘/?myvariable=test’ or something useful at the end).
This makes life alot easier when updating records and storing more information because it can contain anything at all in a string which looks like ‘var1=1&var2=2&var3=3&var4=…’. You can use your script to ‘explode’ this into an array and use the variables contained within. It did take me a few attempts to work out how to do this as Google seems to have few results with cvendthru in the name.
You might also be interested in:
If you have done any clickbank integration and feel I have missed anything or given the wrong information then please contact me by leaving a comment on this post, the forum or sending an email to email@example.com