📜 ⬆️ ⬇️

BILLmanager has become more open



We return to Habr after a long absence. And today we want to tell you how quickly and simply to create your own additional module for BILLmanager. This task has been greatly simplified, because the source code for plug-ins already implemented by us is now available.

The possibility of obtaining an additional module for BILLmanager existed before, and in several ways.

The first option is to order the module from us in the ISPsystem. The resulting product will be supported in all subsequent versions of BILLmanager, and will also be available for connection to other users. However, sometimes our dense roadmap can delay the release of the desired plugin for a long time.
')
The second option is to contact our technology partners, but in this case, the issue with product support will need to be addressed with partners additionally.

And finally, the third option is to write the module yourself. Starting from version 5.58, you no longer need an impressive programming experience, since Now the BILLmanager developer kit includes examples of source code for 8 existing plug-ins, namely:

  1. cpanel - provides integration with the same control panel;
  2. epp is a universal processor for interacting with domain name registrars that support the EPP protocol;
  3. webnames - interacts with this domain registrar;
  4. thesslstore - a module for purchasing SSL certificates;
  5. paypal - plugin for receiving payments through this payment system;
  6. privatbank - to interact with the billing of the bank;
  7. remotemail - mail gateway;
  8. smsc - SMS gateway for the company SMS center;

To get a package with examples you need to install BILLmanager (instructions on how to do this are located here ). During the installation process, select the desired version of the product (Standard, Advanced or Corporate), and then install the billmanager- [selected_opart] package -devel (for example, yum install billmanager-corporate-devel).
After installing the devel package, the examples will be here:
/ usr / local / mgr5 / src / examples

Armed with samples and available documentation , you can develop a module for almost any payment system, domain registrar, SMS gateway, etc.
Consider the process of writing an SMS gateway for interacting with the cellular operator Q-telecom; source code - under katami slightly lower.

When modifying the module, a description of the API Q-telecom was used; it lies here .

From the API documentation you can see that the interaction is performed via the http protocol, just like in the SMS gateway from the examples. Take advantage of this.
Create a copy of the / usr / local / mgr5 / src / examples / smsc directory and name it gwqtc.
Inside there are 3 files: xml is responsible for how the plugin looks in BILLmanager; cpp describes the backend; In the makefile there are instructions for the compiler how to collect all this beauty in a binary.

Let's start with the most difficult - with alterations gwsmsc.cpp. Rename it to gwqtc.cpp, then open the file in a text editor. We change in the piece of the code responsible for creating the post-request the names of the variables to the ones described by the guys from Q-telecom. Add the parameter gzip = none, so that in case of failures the error text comes readable. Those lines that QTC does not understand - delete.

Where and what changed


Then in the file we look for and change “smsc” to “qtc” (as a result, the changes will be in two lines). Everything, the gwqtc.cpp file is ready. The most difficult we have done.

Let's do xml: change its name to billmgr_mod_gwqtc; inside “SMS-center” we rewrite to “Q-telecom”, and “smsc” to “qtc”. With the appearance of finished.
In the makefile, everything is quite simple: everywhere we change “smsc” to “qtc”.

Now we compile and install the module with the command make install, not forgetting to install the gcc-c ++ package before it if it is not in the system.
After all these actions in BILLmanager, in the menu “Integration” → “Message Modules” → “Create” you will see a new module, Q-telecom.

How it looks in BILLmanager


It remains to make the settings received when concluding a contract with Q-telecom - and you can use it!

Here are the promised sources in the final form.

gwqtc.cpp
#include <gate/gatemodule.h> #include <defines.h> #include <mgr/mgrlog.h> #include <mgr/mgrrpc.h> #include <sstream> #define BINARY_NAME "gwqtc" MODULE("notify"); namespace gate { class QTC : public Module { public: QTC() : Module(BINARY_NAME) { } virtual mgr_xml::Xml Features() const { mgr_xml::Xml out; mgr_xml::XmlNode features = out.GetRoot().AppendChild("features"); features.AppendChild("feature").SetProp("name", GATE_CMD_OUTGOING); out.GetRoot().AppendChild("notify_module", "ntsms"); return out; } virtual mgr_xml::Xml Ingoing(mgr_xml::Xml& msg) const { mgr_xml::Xml out; return out; } virtual void Outgoing(mgr_xml::Xml& msg) const { string message = msg.GetRoot().FindNode("message"); string project_id = msg.GetRoot().FindNode("project").FindNode("id"); string phone = msg.GetRoot().FindNode("user").FindNode("phone"); str::inpl::RemoveNonDigit(phone); string sender = GateParam("originator_" + project_id); if (sender.empty()) sender = GateParam("originator"); mgr_rpc::HttpQuery http; http.EnableCookie(); http.AcceptAnyResponse(); std::stringstream out; http.Post("http://service.qtelecom.ru/public/http/", "user=" + str::url::Encode(GateParam("login")) + "&pass=" + str::url::Encode(GateParam("psw")) + "&target=" + str::url::Encode(phone) + "&message=" + str::url::Encode(message) + "&gzip=none" "&sender=" + str::url::Encode(sender) + "&action=post_sms", out); Debug("response: %s", out.str().c_str()); mgr_xml::XmlString result(out.str()); string result_str = result.GetNode("//result/error"); if (!result_str.empty()) throw mgr_err::Error(result_str); } }; } // END NAMESPACE GATE RUN_MODULE(gate::QTC) 


billmgr_mod_gwqtc.xml
 <?xml version="1.0" encoding="UTF-8"?> <mgrdata> <plugin name="gwqtc"> <group>gateway</group> <author>BILLmanager team</author> </plugin> <metadata name="gateway.gwqtc"> <form> <field name="login"> <input type="text" name="login" required="yes" identifier="yes"/> </field> <field name="psw"> <input type="password" name="psw" required="yes"/> </field> <field name="originator" project="yes"> <input type="text" name="originator"/> </field> </form> </metadata> <lang name="ru"> <messages name="plugin"> <msg name="desc_short_gwqtc">Q-telecom</msg> <msg name="desc_full_gwqtc"> Q-telecom</msg> <msg name="price_gwqtc"></msg> </messages> <messages name="gateway.gwqtc"> <msg name="login"></msg> <msg name="psw"></msg> <msg name="translit"></msg> <msg name="originator"></msg> <msg name="hint_login">    Q-telecom</msg> <msg name="hint_psw">   </msg> <msg name="hint_translit">    </msg> <msg name="hint_originator">   </msg> </messages> <messages name="gateway_include"> <msg name="module_gwqtc"> Q-telecom</msg> <msg name="gwqtc">Q-telecom</msg> <msg name="desc_gwqtc"> </msg> </messages> </lang> <lang name="en"> <messages name="plugin"> <msg name="desc_short_gwqtc">SMS-center</msg> <msg name="desc_full_gwqtc">Server SMS-center</msg> <msg name="price_gwqtc">Free</msg> </messages> </lang> </mgrdata> 


Makefile
 MGR = billmgr PLUGIN = gwqtc CFLAGS += -I/usr/local/mgr5/include/billmgr CXXFLAGS += -I/usr/local/mgr5/include/billmgr WRAPPER += gwqtc gwqtc_SOURCES = gwqtc.cpp gwqtc_FOLDER = gate gwqtc_LDADD = -lmgr -lmgrdb gwqtc_DLIBS = gatemodule BASE ?= /usr/local/mgr5 include $(BASE)/src/isp.mk 


As we have just found out, only a few lines have been changed for the examples. That is, now a small programming experience is enough for writing plug-ins, and partners will be able to improve the quality of their products based on samples.
By the way, we have planned the launch of a store of modules in which the add-ons you have developed can be placed free of charge or for some money for other companies.

We hope this article will be useful to BILLmanager users. We will be very happy to hear about your progress in the process described.

Source: https://habr.com/ru/post/306888/


All Articles