Integrate Bitcoin Payment Gateway Into OpenCart: Part 1

In this series, we are going to look at building a Bitcoin payment system into our installation of OpenCart. Before we get started, I recommend that you practice the basic OpenCart module development if you are not familiar with how to build your own modules.

Once done, you should have enough knowledge to continue with developing more advanced modules. In this series, that's exactly what we aim to do.

Getting Started

Before we begin building the extension, set up OpenCart on your local machine. Next, download the BitPay API Library from the article attachment and place it in your store root as shown in the following screenshot:

BitPay API Library

To configure and set up up our Bitcoin Payment Module, we need an admin interface. To do this, we'll follow the MVC pattern for implementing our admin panel.

1. Create the Admin Controller

  1. Navigate to admin/controller/payment
  2. Create a PHP file and name it bitpay.php
  3. Open the file in your favorite IDE and create a class following the OpenCart class naming convention, for example: class ControllerPaymentBitpay extends Controller {}
  4. Inside the controller class, define the default index function. 
  5. Then, inside this function, start writing the code as featured below.

1.1 Loading Language & Models

1.2 Setting Up Page Title

To set the Page Title of the document we use the following code:

1.3. Parsing Controllers Elements to View

1.4. Routing Save & Cancel Buttons

The following code is used to assign Action / Save & Cancel URLs triggers:

1.5. Getting Available Order Statuses

The following code gets all the order statuses from the Localisation-Model (which is pre-coded into OpenCart) and parses it for the view:

1.6. Fetching Data From the Database

Our saving process will come in the model section. However the following code is responsible for fetching this module data (if any) and parsing it for view.

1.6 Rendering the View Template

The following code adds children to our view template and renders it for the user view.

2. Creating Admin View

  1. Navigate to admin/view/template/payment
  2. Create a file and name it bitpay.tpl
  3. You can place your own HTML. In my case, I've done that using the following steps.

2.1. Adding Header Child

To load the header that we passed as a child at 1.6:

2.2 Warning Block

Warning Block is a div section which will display user warnings if any:

2.3 The Complete Template

The complete HTML will look something like below:

At this point, we are done with the layout of the module. Now its time to save the Module Data into the database. So we will be putting a little code inside the controller for this purpose.

Saving the Data

Inside your controller's default function, place some serialization code as shown below:

Introduction Validation

The following is the validation function that validates the required data:

We are done creating the payment module layout for the dashboard, and you should be able to test-drive the admin panel. Remember to grant permission to the administration user before testing.


In this article, we introduced the administrative portion of the payment module. Note that it's a good idea to give the site administrator more control via an interface than, say, to require that they write in code.

In the next article, we'll implement the payment module with respect to the front-end. In the meantime, feel free to shoot any questions or comments via the form below.



Related Articles