Basic 2checkout processing script

We do not have a rant today, nor we do have a review. Today I am going to go over something that a lot of people ask me – how to create a very basic 2checkout processing script. I am going to say now that this guide is simply how to do the processing side of it, it will not cover anything like the database side of things so you can create something like automatic downloads – we may do that as another tutorial.

2checkout HTML Form.

The first thing we need to do is the HTML form for 2checkout. We are going to be using the single page checkout for 2checkout as I prefer that one. Replace sid value with your own and setup the bits below to what you want it to be called. If you want to add a second product to the checkout form, add things like c_name_2, c_price_2 etc. As stated either, I am not going into the database side of things in this tutorial but you can always use a programming language to prefill all in this and use cart_order_id as a method to know what order someone is ordering.

The return URL you want to set up as the same as the URL for the second file which is listed after the HTML form.” method=”post”>
<input type=”hidden” name=”sid” value=”123456″/>
<input type=”hidden” name=”cart_order_id” value=”XXX”/>
<input type=”hidden” name=”total” value=”XXX”/>
<input type=”hidden” name=”c_name_1″ value=”XXX”/>
<input type=”hidden” name=”c_description_1″ value=”XXX”/>
<input type=”hidden” name=”c_price_1″ value=”XXX”/>
<input type=”hidden” name=”fixed” value=”Y”/>
<input type=”hidden” name=”return_url” value=”XXX” />
<input type=”hidden” name=”merchant_order_id” value=”XXX” />
<input type=”hidden” name=”x_receipt_link_url” value=”XXX”/>
<input type=”hidden” name=”id_type” value=”1″/>
<input type=”hidden” name=”c_tangible_1″ value=”N”/>
<input type=”hidden” name=”lang” value=”en”/>
<input type=”hidden” name=”pay_method” value=”CC”/>
<input type=”submit” value=”Purchase”/>
If you want PayPal to be the preferred selection, change pay_method to PPI. So now we need to do the page where they go after they have completed the payment.
2checkout PHP Form
Now this bit is very simple, eveyrthing is passed on directly to us via GET or POST (depending on your 2checkout settings). The only part we actually need to do is make sure you check the hash value given from 2checkout return so that you can confirm the person actually ordered and not just sent a GET request via their own browser.
So how we do make the hash. Well the hash is simply – md5 (secret word + vendor number + order number + total). So such as, we have.
//Lets check the hash!
$OurKey = “snatty”;
$MOrderID = $_GET[‘merchant_order_id’];
$VendorID = $_GET[‘sid’];
$OrderID = $_GET[‘cart_order_id’];
$Total = $_GET[‘total’];
$CheckoutHash = $_GET[‘hash’];
$OurHash = md5($OurKey . $VendorID . $MOrderID . $Total);
if($CheckoutHash == “1”)
//This was a demo order – do what you want for a demo order.
if($OurHash == $CheckoutHash)
//Do all your PHP stuff here such as updating a database etc.
//This is highly like a unlegit order, or fraud or something. Deal with it accordingly.

And there you have it, just a very basic 2checkout ordering system. It isn’t the best but what do you expect for me spending just a few minutes writing this. 2checkout also though does have a setting to send everything by POST so may need to take that into account, While the above should work, II ain’t making promises anything that you can just drop this into your code and it will work. I have also not tested the PHP side of it, but it should work but regardless this tutorial serves as a nice guide to get you started.

Thanks for reading! You may be interested in this …

Join Honeygain - Start earning money by doing nothing.

Need to quote me?

Ellis, M (2012) Basic 2checkout processing script. [online] Tweaked for your Pleasure. Available at: [Accessed 04 Jul 2022]

Get more spam to your inbox!

Enter your email address to subscribe to Tweaked for your Pleasure and receive notifications of new posts by email.

Join 166 other subscribers.

0 0 votes
Article Rating
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments