
Hello, dear readers of Habr. This article is a continuation of the cycle of materials on how to build a VPS hosting from scratch based on the
RUVDS White Label API .
In the introductory article of the cycle, we talked about the fact that first of all we would need a website and offered 3 options how to create it. We will dwell in detail on the version with the use of popular CMS and plug-ins to them, which are designed to quickly provide the necessary functionality for us to receive payments and pay for servers.
In a series of publications, we will look at such popular CMS as Wordpress, Joomla and Drupal.
Why we chose them:
- Supported by almost all popular shared hosting
- Written in PHP (low entry threshold, extensive community, lots of reference materials and freelance programmers)
- Free (to start with minimal investment is important)
- Common on the internet
')
Disclaimer: We do not claim that these CMS are the most popular or the best. Also, we are not saying that PHP is the number one language and you just have to use it only. You can use any technologies that are suitable for solving the problem of creating your own VPS hosting. This material has been supplemented with many references to third-party sources, the contents of which we did not include in its text, otherwise it would have been less readable and consistent. We hope you find them useful. So let's get started.In this article we will look at Wordpress (how to deploy Wordpress on our hosting, we described in detail in our previous article) and its WooCommerce plugin, and also find out how to adapt it for VPS hosting.
This plugin is considered to be one of the most powerful and functional free eCommerce solutions for Wordpress. Together with him comes the specialized
Storefront theme, which fully supports the latest functionality of the plug-in called “out of the box”. You can either use this theme with minor design modifications, or purchase a paid one for $ 50-70, for example here. What immediately catches the eye is the presence of many extensions, including for integration with various payment aggregators, such as
robokassa or
paymaster (both are free).
pros
- Ease of installation. In the step-by-step installation process, everything is intuitive. We load a plug-in and a subject, we activate. Then you can immediately add products and move to more fine-tuning.
- The presence of a huge number of paid and free templates
- Easy and convenient addition of products
- Extensibility In addition to the boxed functionality, there are many plug-in extensions that allow you to get the desired functionality.
- Free Without many words
- Constant improvements and updates. The plugin is being actively developed, the last commit to the repository on github was a few days ago (at the time of this writing).
- Functionality for building various reports
- Coupons, promotions out of the box
- SEO. For goods, setting up the cnc, site maps, meta tags is available (as well as for simple pages)
- The presence of a multilingual extension
Minuses
- Orientation to the west. Payment methods are by default oriented to the western market. In fact, not too much and minus, given that you can add all popular payment systems for free by connecting the robokassa extension mentioned above
- There may be conflicts when installing some extensions together.
- There is no free technical support.
- Security. Considering the popularity of CMS wordpress in the world and the popularity of the expansion itself, shops on this engine often become the target of a hacker attack.
Features adaptation for vps-hosting
What needs to be done first? To begin, install and activate the theme and the plugin (the installation is intuitive and is no different from the installation of the usual themes and plugins). We will not consider the design of your future VPS hosting pages in this material. We are interested in how to set up this WooCommerce so that customers can order servers on your VPS hosting.
Accept payments
Here everything is absolutely the same as in the organization of receiving payments for any other goods. There are a lot of plug-ins that implement integration with aggregators for woocommerce. If you choose from free extensions woocommerce to accept payments in Russia and the CIS, you can connect robokassa or paymaster. In the case of robokassa, immediately after registering on the site, you can immediately accept payments as an individual on the basis
of an offer agreement , but in this case we have a
high commission . In general, even with this in mind, the final price of your server will still be quite attractive in relation to competitors, so you can safely begin to work right away with robokassa. Detailed information on the settings of the robokassa extension
can be obtained here.If you plan to use another aggregator and very prudently approach this question, here is a detailed comparison of aggregators . Choose the appropriate one, see if there is a corresponding extension for WooCommerce , find its repository and see how active the development is and whether it is alive. If everything is fine, feel free to set and customize.Disabling guest purchase and delivery mechanism
WooCommerce has the ability to make purchases without registration. We also need the client to make purchases only from his account, in which, by the way, we will display to the client all the necessary information, including about his servers. To do this, go to Wordpress Settings> WooCommerce> Settings> Payments and uncheck "Allow guests to place orders."
Delivery must also be disabled. To do this, go to
Wordpress Settings> WooCommerce> Settings> General and select "Disable delivery and delivery calculation"
Setting pages
After installing the plugin, in the section of the page 3 additional ones appeared: a shop window, a basket, an order. We will place the storefront on the main order page so that the user has the opportunity to immediately select the desired configuration and proceed with the order. This is done like this:
Go to the
Wordpress Settings> Settings> Reading and specify the page with the WooCommerce product window as the main page and the page of records.
Adding products
In our case, the product will be the VPS configuration. For simplicity, we take 3 configurations and add them as a product to the site:
- Minimum: 1 × 2.6GHz CPU, 1GB RAM, 20GB HDD, 1 IP
- Medium: 4 × 2.6GHz CPU, 4GB RAM, 40GB HDD, 1 IP
- Powerful: 10 × 2.6GHz CPU, 10GB RAM, 80GB HDD, 1 IP
In the product adding menu, we recommend immediately replacing the content of the Label field with a more understandable option, for example medium-configuration. Also, it is desirable to describe in the contents of the goods for what purposes this configuration is suitable, for example, to place your site on with attendance of up to 100 people per day. Do not forget to specify the price and discount, if required. Also, be sure to specify the image of the goods.
The result should be like this:

This is a standard design showcase page from the
Storefront . Next, we refine the design of the main page, using the services of freelancers and fill it with
necessary contentProcessing paid orders
Here we come to one of the most important points in the question of adapting WooCommerce for the sale of VPS rental services. After paying for the VPS server on your service, you must provide this server to the client.
For simplicity in this section, we will not consider how to arrange a server renewal, a test period, etc., but limit ourselves to creating a server after its first payment. So, the task is to ensure that as soon as the service is paid for:
- initiate server creation using the RuVDS Whitelabel API and provide the client with all the necessary information about the creation process (server ID, creation phase, creation progress, server configuration)
- after creating the server, provide the necessary data for the connection, as well as the server management capabilities and information about the end date of the calculation period
To solve this problem, there are many ways. One of the simplest is to periodically receive data on paid orders for which VPS were not created directly from the corresponding wordpress and woocommerce tables (a detailed description of the woocommerce scheme can
be found here ) and if such exist, mark them as “in progress” and run server creation process. Not the best solution, but one of the easiest ... You can also use woocommerce web hooks for this task. What are web hooks? In simple terms, this is a subscription to an event in the online store. We show how to work with this mechanism on the REST API.
What is good woocommerce? Not least because it has a documented
REST API (and examples of its use in 4 languages, Javascript, PHP, Python, Ruby and curl, the output of which can then be disassembled as you like). Also, to use the features of the plugin, there is
wp cli and
detailed documentation on its code.In order to use the REST API, you must first generate a special key. This is done as follows: go to
WooCommerce> Settings> API and click add key. When generating a key, you need to select a user and specify the type of rights (read, write, read / write). We generate a key for the current user and specify the level of read / write rights. Next, go to
Settings> permalinks and select the second type. Now REST API is available at url:
yourdomain.com/wc-api/v3To work with the API, we will use a
special library for PHP . Install it using
composer by running the console:
composer require automattic/woocommerce
You can log in to the API and get a list of products using the following PHP code:
<?php require __DIR__ . '/vendor/autoload.php'; use Automattic\WooCommerce\Client; use Automattic\WooCommerce\HttpClient\HttpClientException; $woocommerce = new Client( 'https://yourdomain.com/', 'ck_0000000000000000000000000000000000000000', 'cs_0000000000000000000000000000000000000000' ); try { print_r($woocommerce->get('products')); } catch (HttpClientException $e) { echo $e->getMessage(); }
The client can already buy a server using the available storefront functionality on the main page. Accordingly, in order to start the creation of the server when paying for the order, we can add the appropriate web hook to the event of changing the order status:
... ... $webHookData = [ 'webhook' => [ 'name' => 'Order updated', 'topic' => 'order.updated', 'delivery_url' => 'https://yourdomain.com/deliver/secret' ] ]; try { print_r($woocommerce->post('webhooks', $data)); } catch (HttpClientException $e) { echo $e->getMessage(); }
Now, when this event comes, the load of the web hook will be delivered to the address 'https://yourdomain.com/deliver/secret'.
Anything that has been delivered by the web hook can also be displayed as follows:
print_r($woocommerce->get('webhooks/webhook_id/deliveries'))
When processing a request for delivery_url, you need to check whether the order status has changed to completed. If yes, from the order you get an array of server configuration id (array of product identifiers in the line_items property) and start the process of creating a VPS.
In the next articles of the cycle we will examine in detail how to do this.