How to create your own VPS hosting from scratch and start making money on it? Simple billing with Virtuemart


    Hello, dear readers of Habr. This material is a continuation of a series of articles on how to build a VPS hosting from scratch based on the RUVDS White Label API. And today we will look at the popular Joomla CMS and one of the most popular ecommerce solutions for it - VirtueMart .

    Virtuemart


    Generally speaking, the extension has been around for quite some time (the first version came out already in 2005).
    The product grew and developed with CMS Joomla and currently has a fairly wide functionality.

    Let's look at the pros and cons of the Virtuemart 3 plugin together.

    pros


    • free
    • custom fields
    • one click order form
    • multicurrency
    • simple checkout process
    • flexible and powerful access control system
    • many payment methods are available out of the box


    Minuses


    • bulky code and performance issues
    • there is no simple API for integration with external services
    • default supported payment systems are oriented to the west (paypal, skill, 2checkout)
    • relatively small community (~ 317127 people registered on the official forum , the repository is not working very actively and the number of developers involved is small (for comparison, there are 470 developers in the woocommerce repository, which is 10 times more)
    • low speed of adding new functionality (consequence of including the previous paragraph)
    • security issues caused by the popularity of both the Joomla CMS and the virtuemart extension itself


    Features of adaptation for vps hosting


    Accept payments


    The procedure is the same as when using other bundles, for example wordpress and woocommerce . In order to integrate with the paymaster aggregator we already know , download the free extension . Setting up the paymaster extension is described in detail at the same link.

    Disabling guest shopping


    Go to Virtuemart> Configuration> Checkout and set the flag “Only registered users can checkout”.

    Page Setup


    After installing the Virtuemart plugin, we have the opportunity to use specialized pages in the menu. In order to make a showcase from the main page, go to Menus> Manage and edit the menu with the alias home. We need to change the Menu Item Type to one of the types provided by Virtuemart:
    • Account maintenance
    • Category Layout
    • Displays vendor contact
    • Displays vendor details
    • Displays vendors
    • Front page
    • List orders
    • Manufacturer Default Layout
    • Manufacturer Details Layout
    • Product Details Layout
    • Shopping cart
    • User Edit Address
    • View vendor TOS

    We chose Category Layout and the standard Joomla layout (version 3.5) and, after adding the basic VPS configurations , the main page looks like this:



    Processing paid orders


    So, we have the same tasks:
    • initiate server creation using the RuVDS Whitelabel API and provide the client with all the necessary data about the creation process (server identifier, creation stage, creation progress, server configuration)
    • after creating the server, provide the necessary data for the connection, as well as server management capabilities and information about the end date of the billing period


    What is available to us for integration

    • automatically generated documentation for the Virtuemart 2 API (in the article we consider the 3rd version)
    • api2cart service - a unified API for online stores (from $ 500 per month)
    • free component of SOAP services for Virtuemart 3 (a somewhat truncated version, but its functionality is quite enough for our tasks)


    Let us dwell on the last option. After installing this plugin, the following SOAP services are available:
    • VM_Categories
    • VM_Order
    • VM_Product
    • VM_SQLQueries
    • VM_Users
    • VM_Upload


    Their wsdl are accessible by url (example for a service managing a product category):
    http: // host / administrator / components / com_vm_soa / services /VM_CategoriesWSDL.php

    We need 3 - VM_Order, VM_Product and VM_SQLQueries.

    Unfortunately, when using this integration method, the hook mechanism is not available to us. Therefore, we will periodically select orders with the appropriate status and initiate the creation of servers of the desired configuration.

    We will write a simple script in the PHP language that will create the server after paying for the order:
    'admin',
    		'password'=>'admin',
    		'orderServiceWsdl'=>'http://localhost/administrator/components/com_vm_soa/services/VM_OrderWSDL.php',
    		'productServiceWsdl' =>'http://localhost/administrator/components/com_vm_soa/services/VM_ProductWSDL.php'
    	];
    }
    function getCompleteOrders($limitStart = 0, $limitEnd=1000)
    {
    	$applicationSettings = getApplicationSettings();	
    	$loginInfo = new stdClass;
    	$loginInfo->login=$applicationSettings['login'];
    	$loginInfo->password=$applicationSettings['password'];
    	$loginInfo->isEncrypted="Y";
    	$loginInfo->lang=null;	
    	$orderServiceClient = new SoapClient($applicationSettings['orderServiceWsdl']);
    	$getOrderFromStatusRequest = new stdClass;
    	$getOrderFromStatusRequest->limite_start = $limitStart;
    	$getOrderFromStatusRequest->limite_end = $limitEnd;
    	$getOrderFromStatusRequest->status = 'F'; 					//завершенные заказы
    	$getOrderFromStatusRequest->loginInfo = $loginInfo;
    	try {		
    		// выбираем все заказы со статусом "завершенный"
    		return [$orderServiceClient->GetOrdersFromStatus($getOrderFromStatusRequest)];		
    	}catch(\SoapFault $e){
    		echo $e->getMessage();		
    		return false;
    	}
    }
    function processPayedOrder($orderId)
    {
    	$applicationSettings = getApplicationSettings();	
    	$loginInfo = new stdClass;
    	$loginInfo->login=$applicationSettings['login'];
    	$loginInfo->password=$applicationSettings['password'];
    	$loginInfo->isEncrypted="Y";
    	$loginInfo->lang=null;
    	$productServiceClient = new SoapClient($applicationSettings['productServiceWsdl']);
    	$getProductsFromOrderIdRequest = new stdClass;
    	$getProductsFromOrderIdRequest->order_id = $orderId;
    	$getProductsFromOrderIdRequest->include_prices = true;
    	$getProductsFromOrderIdRequest->loginInfo = $loginInfo;
    	try {
    		// выбираем заказанные конфигурации
    		$products = [$productServiceClient->GetProductsFromOrderId($getProductsFromOrderIdRequest)];	
    	} catch(\SoapFault $e){
    		echo $e->getMessage();
    		return false;
    	}
    	// создаём сервер в зависимости от конфигурации
    	foreach($products as $product) createRuvdsServer($product);
    	return true;
    }
    function createRuvdsServer($product)
    {	
    	// код создания сервера через RUVDS White-Label Api и ожидания завершения процесса
    }
    $orders = getCompleteOrders();
    if (!$orders || count($orders)==0) return 1;
    foreach ($orders as $order)
    {
    	$orderId=$order->Order->id;	
    	$res = processPayedOrder($orderId);	
    	if(!$res) echo 'Processing order with id '.$orderId.' failed!';
    }
    


    Next, using any task scheduler, for example cron, we configure the launch of this script with the necessary frequency.

    Summary


    In general, the Joomla 3 + Virtuemart 3 bundle looks like a fairly functional and powerful tool as the basis for organizing your VPS hosting. Immediately out of the box, there are many settings for everything you can imagine. But is this required when reselling, say, 3-10 popular virtual server configurations ?

    In the next article, we will look at CMS Drupal and one of its most popular eCommerce extensions, and perhaps the new CMS will be more suitable for this task. See you soon!

    Also popular now: