Pos API 2.1 User Guide - en
Pos API 2.1 User Guide - en
Table of Contents
1. Introduction ............................................................................................................................................. 3
1.1 Basic principles of Pos API 2.1 .......................................................................................................... 3
1.2 Scope ................................................................................................................................................ 3
1.3 Client based ...................................................................................................................................... 3
1.4 Server based ..................................................................................................................................... 4
1.5 System Requirements....................................................................................................................... 5
1.6 Electron Receipt ............................................................................................................................... 5
1.7 E-receipt requirements..................................................................................................................... 6
2. PosAPI integration instructions ................................................................................................................ 7
2.1 Integration methodology.................................................................................................................. 7
2.2 Installation and configuration........................................................................................................... 7
2.3 Windows installation ........................................................................................................................ 8
2.4 Linux installation............................................................................................................................... 9
3. PosAPI methods ..................................................................................................................................... 10
3.1 UString datatype............................................................................................................................. 10
3.2 UString PosAPI::checkAPI() ............................................................................................................. 10
3.3 UString PosAPI::getInformation() ................................................................................................... 11
3.4 UString PosAPI::callFunction(UString, UString)............................................................................... 12
3.5 Static Ustring PosAPI::put(UString param) method ........................................................................ 12
3.6 UString PosAPI::returnBill(UString)................................................................................................... 3
3.7 Ustring PosAPI::sendData() method ................................................................................................. 3
4. Error message description ........................................................................................................................ 5
5. Integrating with Java ................................................................................................................................ 7
6. Integrating with C# ................................................................................................................................. 18
In regards to the revision of VAT law which is adopted on July 9 th of 2015, Pos API 2.1 library has been
developed by General Department of Taxation for the purpose of collecting sales receipts of goods and
services.
Pos API 2.1 is a software module that is meant to work alongside Cashier Pos system, which collects sales
information on goods and services that are being sold to consumers by business entities and individuals.
1.2 Scope
Business entities could use one Pos API 2.1 library to send data to multiple client systems via their central
server. Depending on their business characteristics (number of branches, type of services they offer etc.),
business entities could choose between the “server side” model (graph 3) and the “client side” model (graph
2).
Required fields
Locations Field For consumer For business
Return BarCode No No
Even though the return BarCode is not required it would be helpful to have in case of e-receipt
cancellation process which would require the Irreplicable number (33 digits long) to be typed by
hand.
Even though C++ is a platform independent language, the compilation output requires a bridge library to
be used to integrate depending on the platform. Integration examples on how to integrate with Java and C#
programming languages are included at the end of this manual.
C++ programs can work with other languages provided there is a bridge library created. Bridge library is
unnecessary when it comes to Windows OS environment programming languages like .NET framework or
Delphi.
Necessary libraries:
icudt53.dll
icuin53.dll
icuuc53.dll
Qt5Core.dll
Qt5Network.dll
Qt5Script.dll
Qt5Sql.dll
libeay32.dll
ssleay32.dll
sqldrivers/qsqlite.dll
DLL files above has to be copied to the “Working Directory” of your Cashier Pos system. If your system
was written in Java, the files can be copied to “C:\Windows\Sun\Java\Bin”. The directory
(“C:\Windows\Sun\Java\ Bin\platforms”) can be created manually if it does not exist as shown.
Installing “Visual C++ Redistributable Packager for Visual Studio 2013” is required in order to run Pos
API 2.1 module on Windows OS because PosAPI dll and other necessary libraries are written using Visual
Studio 2013 C++ language.
If you Cashier Pos software is written in Java language, OpenSSL v1.0.2d Light must be installed for
your system to work on Windows environment. If your operating system is Windows XP, it has to be upgraded
to Windows XP SP3.
Necessary libraries:
libicudata.so.53
libicuuc.so.53
libicui18n.so.53
libQt5Core.so.5.4.1
libQt5Network.so.5.4.1
libQt5Script.so.5.4.1
libQt5Sql.so.5.4.1
libcrypto.so.1.0.0
libssl.so.1.0.0
As for Linux OS, above mentioned libraries should be copied to “/usr/lib” directory along with the PosAPI
(libPosAPI.so). OpenSSL library comes installed already on most Linux distributions so it is not required to
install.
Windows and Linux operating systems each have their own ways of working with Unicode string
therefore strings are received differently depending on the OS.
“UString” type converts into std::wstring on Windows but it converts into std::string on Linux.
To ensure the stability of the Cashier Pos system, this method performs an operation check on PosAPI.
There must be a home directory in the OS that running the Cashier Pos system, otherwise the method will
return error.
Input
None
Output
Output format
{
"success":boolean,
"database":{
"success":boolean,
"message":String
},
"config":{
"success":boolean,
"message":String
},
"network":{
"success":boolean,
"message":String
}
}
There is a need to check the PosAPI information in case there are multiple APIs in use by the Cashier
Pos system. This method is used to obtain the PosAPI information.
Input
None
Output
Output format
{
"registerNo":String,
"branchNo":String,
"posId":String,
"dbDirPath":String,
"extraInfo":{
"countBill”: String
}
}
There will be additional methods added to PosAPI in the future and it is not necessary to download the
PosAPI again each time. Those additional methods can be called using this function.
Whenever a function is added to the library, it will be announced via our website and will be included in
future iterations of this manual.
Input
1st input:
Name of the function to be called
Input format
String /Name of the function/
2nd input:
A parameter to be passed
Input format
JSON String /Different depending on the function to be called/
Output
Output format
JSON String / Different depending on the function to be called /
Some of the fields from above table are not required to be filled and should be filled only when the
system environment or sales type demands it.
Non-compulsory fields
Name Description
billIdSuffix Has to be filled when there are multiple sales data incoming to
PosAPI simultaneously. Because there is a chance that same
irreplicable number being generated when there are more than one
sales data incoming.
customerNo Has to be filled when registering a B2B transaction. Not required in
case of B2C.
billType Has to be filled in case of a B2B transaction.
billIdSuffix field contains an irreplicable number within the business entity or within a branch depending on if
the PosAPI had a branch number or not.
Along with these fields, the fields from earlier transmission will be incoming as well. Only billid and date
fields can be saved as they are used for cancelling the receipt.
Receipt editing:
When editing a receipt or executing a partial return, irreplicable number of the receipt to be
edited should be entered into returnBillId field. If a receipt is edited, lottery associated with the receipt
would be cancelled and there would be no lottery or qrCode printed out for that particular edited receipt.
2
3.6 UString PosAPI::returnBill(UString)
“ReturnBill” method is used to register sales receipts of goods and services as “cancelled”. When
returned using this method, lottery and irreplicable number of the receipt will be deemed “cancelled” as
well.
Input
Input format
{
"returnBillId":String,
"date":String
}
Output
Output format
{
"success":boolean,
"errorCode":Integer,
"message":String
}
Output
Name Description
success Indicates if the cancellation was successful or not
true – cancelled
false – not cancelled
errorCode Error code if there is one
message Error message
According to the revised VAT Law, receipt data must be sent within 72 hours after the sale. “sendData”
method is used to send the sales receipts of goods and services to VATPS. In order to execute the method
successfully, the Cashier Pos system must be connected to internet.
3
Also if PosAPI is installed for the first time, this method is called to download lottery package and
configurations.
If you install PosAPI 2.0 database on a Cashier Pos for the first time, you must execute sendData
method without any actual data. By doing so, you register the PosAPI on your machine in VATPS and
download required setup /configuration/ information.
Input
None
Output
Output format
{
"success":boolean,
"errorCode":Integer,
"message":String
}
4
4. Error message description
5
316 Error occurred while working with database!!!\n
317 Error occurred while working with database!!!\n
318 Error occurred while working with database!!!\n
320 Error occurred while working with database!!!\n
Success conditions not met while
trying to register a payment receipt.
210 Incorrect data filled into field /{0}/. Validation: {1}
{0} is JSON field name, {1} RegEX
validation.
Cash amount and non-cash amount does not equal to nonCashAmount + cashAmount ==
220
total amount. amount condition not met.
Error shown when the PosAPI is
banned from Tax system, or faulty
600 Access unsuccessful!!! \n
network connection when attempt
was made.
Error shown when trying to send
601 Error: [{0}]
payment receipt data.
2 Configuration file corrupt. Configuration data not downloaded or
1 Configuration file corrupt. changed manually.
200 Error while converting JSON
JSON data structure error
201 Error while converting JSON
6
5. Integrating with Java
In order to integrate Java and C++, JNI (Java Native Interface) is used. In below example, Intellij IDEA
and Visual Studio 2013 are used.
7
Step 2: Native method creation
package mn.mta.pos.exam;
In order to create a C header file, BridgePosAPI class has to be compiled first. To do that you have to
press “CTRL+F9” or choose “Build -> Make Project” from the main menu. If the compilation is
successful, below screen will be shown:
If the above is shown, open the console (CMD) and execute following commands.
8
cmd> javah mn.mta.pos.exam.BridgePosAPI
Purpose of javah command is to create C header file from a java native class.
mn_mta_pos_exam_BridgePosAPI.h:
#ifndef _Included_mn_mta_pos_exam_BridgePosAPI
#define _Included_mn_mta_pos_exam_BridgePosAPI
#ifdef cplusplus
extern “C” {
#endif
/*
* Class: mn_mta_pos_exam_BridgePosAPI
* Method: put * Signature: (Ljava/lang/String;)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_mn_mta_pos_exam_BridgePosAPI_put
(JNIEnv *, jclass, jstring);
/*
* Class: mn_mta_pos_exam_BridgePosAPI
* Method: returnBill
* Signature: (Ljava/lang/String;)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_mn_mta_pos_exam_BridgePosAPI_returnBill
(JNIEnv *, jclass, jstring);
/*
* Class: mn_mta_pos_exam_BridgePosAPI
* Method: sendData * Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_mn_mta_pos_exam_BridgePosAPI_sendData
(JNIEnv *, jclass);
/*
* Class: mn_mta_pos_exam_BridgePosAPI
* Method: checkAPI * Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_mn_mta_pos_exam_BridgePosAPI_checkAPI
9
(JNIEnv *, jclass);
/*
* Class: mn_mta_pos_exam_BridgePosAPI
* Method: getInformation * Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_mn_mta_pos_exam_BridgePosAPI_getInformation
(JNIEnv *, jclass);
/*
* Class: mn_mta_pos_exam_BridgePosAPI
* Method: callInformation * Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_mn_mta_pos_exam_BridgePosAPI_callInformation
(JNIEnv *, jclass, jstring, jstring);
#ifdef cplusplus
}
#endif
#endif
Step 3: Creating Visual Studio 2013 C++ project
Open Visual Studio 2013 and create the integration library. To create a project, choose “New Project
-> Win32 Console Application” and press Next.
10
Next, select “Application Type -> DLL” and press Finish.
11
Step 4: Add mn_mta_pos_exam_BridgePosAPI.h
Copy “mn_mta_pos_exam_BridgePosAPI.h” file that was created earlier to Visual Studio Project
directory.
Next, right click on “Solution Explorer -> Header Files” and choose “Add -> Existing Item” to add
“mn_mta_pos_exam_BridgePosAPI.h” file.
12
Configuring the integration of JDK header file and PosAPI
Jni.h header file is used when integrating with Java. To add this header file, following steps should be
followed.
Select “PROJECT -> Property” from the top menu. Next, “Configuration Properties -> C/C++ -> General
-> Additional Include Directories” and add following paths.
“[JDK PATH]\include” and “[JDK PATH]\include\win32” paths should be added. Also the download
“[PosAPI PATH]\include directory” should be included as well.
13
After above header files are added, PosAPI.lib file should now be imported.
Select “PROJECT -> Property” from the top menu. Select “Configuration Properties -> Linker -> Input -
> Additional Dependencies” and add “[PosAPI PATH]\[Cpu Architecture]\PosAPI.lib” path.
14
Step 5: Coding the integration in “BridgePosAPI.cpp” file
#include “stdafx.h”
#include “mn_mta_pos_exam_BridgePosAPI.h”
#include <PosAPI.h>
#include <codecvt>
#include <locale>
#include <vector>
/*
* std::string-ийг std::wstring төрөлрүү хөрвүүлэх method
*/
wstring s2ws(const string& str)
{
typedef codecvt_utf8<wchar_t> convert_typeX;
wstring_convert<convert_typeX, wchar_t>
converterX; return converterX.from_bytes(str);
}
/*
* std::wstring-ийг std::string төрөлрүү хөрвүүлэх method
*/
string ws2s(const wstring& wstr)
{
typedef codecvt_utf8<wchar_t> convert_typeX;
wstring_convert<convert_typeX, wchar_t>
converterX; return converterX.to_bytes(wstr);
}
15
JNIEXPORT jstring JNICALL
Java_mn_mta_pos_exam_BridgePosAPI_returnBill
(JNIEnv *env, jclass c, jstring param){
const char* strParam = env->GetStringUTFChars(param, 0);
UString data = s2ws(string(strParam));
UString result =
PosAPI::returnBill(data);
return env->NewStringUTF(ws2s(result).c_str());
}
return env->NewStringUTF(ws2s(result).c_str());
16
1> BridgePosAPI.vcxproj -> D:\My Project\BridgePosAPI\BridgePosAPI\x64\Debug\
BridgePosAPI.dll
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
Colored text indicates the location of the newly created dll.
Step 7: Load the library from within Java project
Copy “BridgePosAPI.dll”, “PosAPI.dll” libraries along with other secondary libraries to
“C:/Windows/Sun/Java/Bin” directory. If the directory does not exist, it should be created manually.
After the above steps, libraries should be loaded from within the Java code.
package mn.mta.pos.exam;
public class BridgePosAPI {
static{
String os = System.getProperty(“os.name”); if
(os.toUpperCase().contains(“WINDOWS”)) {
System.loadLibrary(“icudt53”);
System.loadLibrary(“icuuc53”);
System.loadLibrary(“icuin53”);
System.loadLibrary(“Qt5Core”);
System.loadLibrary(“Qt5SQL”);
System.loadLibrary(“Qt5Network”);
System.loadLibrary(“Qt5Gui”);
System.loadLibrary(“Qt5Widgets”);
System.loadLibrary(“PosAPI”);
}
System.loadLibrary(“BridgePosAPI”);
}
Дээрх кодыг бичсэний дараа main method-ийг дуудахад доорх үр дүн харагдаж байвал
таны код амжилттай ажилласан гэж ойлгож болно.
Гаралт:
result = {
“succcess”: true
}
17
6. Integrating with C#
C++ library can be used using C# once Unmanaged C++ library is integrated with C# code. Following
example was done in Visual Studio 2013.
Step 1: Project creation
18
Step 2: Creating Native method
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
namespace PosApiExam
{
class Program
{
[DllImport(
“PosAPI.dll”,
CharSet = CharSet.Unicode, CallingConvention
= CallingConvention.Cdecl
)]
[return: MarshalAs(UnmanagedType.BStr)]
public static extern string put(String message);
[DllImport(
“PosAPI.dll”,
CharSet = CharSet.Unicode, CallingConvention
= CallingConvention.Cdecl
)]
[return: MarshalAs(UnmanagedType.BStr)]
public static extern string returnBill(String message);
[DllImport(“PosAPI.dll”)]
[return: MarshalAs(UnmanagedType.BStr)]
public static extern string sendData();
[STAThread]
static void Main(string[] args)
{
var result = sendData();
Console.WriteLine(“result = ”+ result);
}
}
}
Above methods each call C++ mehods: PosAPI::put, PosAPI::returnBill, PosAPI::sendData respectively.
If the following result is returned after writing the above code and invoking the main method, your code
has worked successfully.
19
Output:
result = {
“succcess”: true
}
20