This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

CloudwaysCDN — a powerful solution that offers superior performance and satisfied global audience for your business. Read More

How to Build a WooCommerce Payment Gateway Plugin

Updated on  9th May

10 Min Read
Reading Time: 10 minutes

The good thing about creating a WooCommerce payment extension is that the process is very simple. The most important challenge is the interaction with a merchant’s API for submission of payment requests.

 WooCommerce Payment Gateway Plugin

For the purpose of this article, I will use If you do not have one, signup for a sandbox account to test the plugin.

Sandbox Account

The sandbox is a functional payment gateway with two important differences – No actual credit cards are processed and specific errors and responses could be triggered on demand to test various situations.

API Credentials

Structure of the WooCommerce Payment Extension Plugin

To make things easy to handle during the development and testing process, I will split the plugin in two files. These two files will be located in the cloudways-authorize-woocommerce-gateway directory (in the Plugin directory).  The first file registers the payment gateway and custom action link (cloudways-authorize-woocommerce-gateway.php) . The second file will have the class that will create administration fields (cloudways-authorize-woocommerce.php).

Development Of Plugin

Open up the file cloudways-authorize-woocommerce-gateway.php and add the following code to it:

Class Constructor

  • id — This is the global ID for the Payment method.
  • method_title — This is the title that appears on the top of the payment gateways Page.
  • method_description — This is the description for the payment gateway.
  • title — This is the title to be used for the vertical tabs.
  • icon — This is the optional image that appears with the gateway’s name on the front-end.
  • has_fields — This is a boolean option that could be set to ‘true’ if you want payment fields to show on the checkout .
  • supports — This indicates that the method supports the default credit card form.

Insert the above code in cloudways-authorize-woocommerce.php

Activate the Plugin

Now that the plugin has been created, activate the plugin.

Make sure that there are no errors. Go to WooCommerce >> Settings. This will take you to the Checkout Administration options:

WooCommerce setting

At this point, it is a good practice to include an option to set the test mode of the gateway.

  • enabled — Enable/Disable this payment gateway.
  • title — Payment title that the customer will see during the checkout process.
  • description — Payment description that the customer will see during the checkout process.
  • api_login — API Login provided by when you signed up for an account.
  • trans_key — Transaction Key provided by when you signed up for an account.
  • environment — Place the payment gateway in test mode or production.

Save changes

Payment Processing Method

The payment processing is handled by the method process_payment($order_id ).The form will create the following default form fields ( obtained from $_POST):

  • GATEWAYID-card-number
  • GATEWAYID-card-cvc
  • GATEWAYID-card-expiry

Payment Processing Method

Next, I will build the function process_payment(). This function handles all the transactions:

Now test the value of response_code. If the transaction goes through, you will receive a message that signifies success. Here is how the order notes change throughout the process:


Creating the WooCommerce payment extension is not a huge project or a difficult project to tackle. It usually takes just a few hours to create the extension. however, testing  is the key to success. this is where you should thoroughly test the code so that the WooCommerce store remains operational.

If you need more help, do leave a comment and I will get back to you.

Share your opinion in the comment section. COMMENT NOW

Owais Alam

is the WordPress Community Manager at Cloudways - A Managed WooCommerce Hosting Platform and a seasoned PHP developer. He loves to develop all sorts of websites on WordPress and is in love with WooCommerce in particular. You can email him at

Start Growing with Cloudways Today.

Our Clients Love us because we never compromise on these

Get Our Newsletter
Be the first to get the latest updates and tutorials.