Tech Process payment gateway with Woocommerce : PART 2

...and we are back. This Tutorial would guide you throuhg the necessary steps for integrating Tech Process gateway with Woo Commerce. NOTE: the solution provided is more of a work around, but works like a charm. Before you start, make sure you have read the provious tutorial

Tech Process payment gateway with Woocommerce: PART 1

also you need to download and install, wordpress and woocommerce. My current version for wordpress is 3.4.1 and for woocommerce its 1.6.4.

If you have everything setup correctly, with some dummy products, Login to your admin and you would have something like this


Click settings to view default gateways provided from Woocommerce.

WooCommerce_Settings  Proteins_India  WordPress_2012-08-24_20-06-59.png.scaled1000

So to get our new custom gateway in the list above we need to create a new gateway class and then load it. Though you can find a not very nice documentation from woocommerce here. But i would cover it here.

First you need to understand where your new class file would be located. Here is a screenshot to make you undertand My project is saved as "WOOPI" in "/var/www", i you are on windows and using wamp then you would have your project directory under "C:/wamp/www/".


you can see a new folder called "banking" under "/var/www/woopi/wp-content/plugins/woocommerce/classes/gateways/". Also you can see a class file that we have to create under this new folder. So let us begin...

Create a new file with name as "class-wc-banking.php". Remember keeping "class-wc-" in the name is important.

Here are important parts of file that you need to understand.

Constructor : class-wc-banking.php

Next is an important function "payment_fields()", that would contain your fields, If you need you need to show any on check out page. As i stated in the above, you have set

$this->has_fields         = true;// true if u want to show fields at the time of checkout.

So if you want to show the fields, define your function like this.

To make things clear, these are the fields you can use form the original "Request.php" file came in teh bundle from Tech Process.

We will not be using these fields in our tutorial. But still i would be sharing all necessary information.

inportant thing to know is that the fields does not have any SUBMIT button, this is because woocommerce has its its own(ajax based) way to submit form fields.

Next is validating these form fields, the original documentation from woo commerce shows a method that would retrun false or true if the validation is passed or not.

The function goes as follows.

public function validate_fields(){       global $woocommerce;       return true;    }

Since we are not using any fields so we do not need any validations so we simply return true.

Next is the most important function that would get all the necessary value and redirect the user to payment gateway. Here is the function "process_payment($orderId)" as you see it automatically takes the order id.

Another thing to remember os thet the code in this function is made using the original "getcheck.php" and some code from the woocommerce itself.

I know its huge, but its important.

We still have not added our file to woo commerce and has not displyed it in admin. so we need a couple of more functions .

so your class would contain all those functions (as discussed above) .

Next function would be added in the same file but outside tha class code block. the function adds your class to woo commerce.

/**  * Add the gateway to WooCommerce  **/ function add_banking_gateway( $methods ) {     $methods[] = 'WC_banking'; return $methods; } add_filter('woocommerce_payment_gateways', 'add_banking_gateway' );

now your class should look like this(copy paste ode can be found here).

Now one last step to show your gateway in admin. open the file "plugins/woocommerce/woocommerce.php" and at line number 184 add a new line to include your file, look screenshot below


save the file and go to administrator >> woocommerce >> payment gateways (tab)


Simply enable your gateway, press save and "Tadaaaa". your gateway can be seen on the checkout page.

Checkout  Proteins_India_2012-08-25_14-52-28.png.scaled1000

If everything is set corect, clicking "Place order" button would take us to the payment gateway page where we can make payment. No matter if u made a payment or canceled it, response would go to the "Response.php" as I told you in my preivous blog post. Below we would redirect the user to Thank you or transaction failed pages(create them if they are not) depending upon the gateway's response code.

Open your "Response.php" (i expect that its in your root folder). Find for the code


So this is where we set the product status and redirect user

if(trim($return_array[14])=='0300') {     // set status of order as pending     // redirect user } else{ // set status of order as failed     // redirect user }

NOTE: i tried a lot using woocommerce's classes to set the product status, but finally I studied the databse and ran raw sql queries in "Response.php".

See the screenshot to understand how woocommerce relates the necessary data


in database(screenshot above) you have a table called "wp_posts" that has your products, and another table called "wp_terms" that stores related terms needed.

There is table called "term_taxonomy_id" that relates "wp_posts" with "Wp_terms"

you can clearly see order status defined in table "wp_terms"

Now, go to your Response.php file and include "wp_config.php" file, this file has your database details for wordpress.

<?php session_start(); include('wp-config.php'); $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); // connect to HOST mysql_select_db(DB_NAME, $conn); // selecting the DB

now simple put the queries as




i hope you find this helpful. please do comment for any help.

thank you