SuperFaktura C/C++ API
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
thirdparty
.gitignore
LICENSE
README.md
api_test.vcxproj
api_test.vcxproj.filters
cacert.pem
super_faktura_api.sln
super_faktura_api.vcxproj
super_faktura_api.vcxproj.filters

README.md

SuperFaktura C/C++ API for Windows

##About SuperFaktura C/C++ API allows you to create invoices or import invoices from SuperFaktura. SuperFaktura is small invoicing cloud application, frequently used by Slovak users to manage their invoices. More info: superfaktura.sk.

##With this API you can

  • Import single or all document from user account to your application
  • Create new invoices from your application

##Why to use

  • Simplify process of communication Application <-> SuperFaktura
  • Single DLL with optional C++ helpers
  • Very easy to implement in C++, see examples
  • Async queue request processing, so you do not wait for requests to complete
  • Works from Windows XP SP3 to Windows 10, 32 and 64 bit version
  • Fast and low on resources

##How to use (C++ example) api_helper.h Contains all requied functionality, so you do not need to know how to communicate with api dll. It will automatically safe load/unload api dll when required or explicitly requested, provides simple and intuitive classes and interfaces. Note: For complete example see src/api_test.cpp. ###Implement class to receive notifications about API events (invoice created, ...) Note: Your class must derive from sf_api::ClientApi

#include <iostream>
#include "my_class.h"
#include "api_helper.h"

//
// UPDATE TO VALID SUPERFAKTURA API LOGIN CREDENTIALS
//
const char* API_EMAIL = "sslhtest@sslhtest.sk";
const char* API_TOKEN = "97f2a43024f1330551ce4a4e82e31910";

HANDLE g_invoiceEvent = NULL;	// sync api calls

/**
 * Catch requests from API
 */
class MyApi : public sf_api::ClientApi
{
	/**
	* Called when invoice by id request is completed with success
	*/
	virtual void
	InvoiceByIdSuccess(const sf_api::Invoice& inv) override
	{
		std::cout << "Get invoice by id success." << std::endl;
		SetEvent(g_invoiceEvent);
	};

	/**
	* Called on invoce by id failure
	*/
	virtual void
	InvoiceByIdFailure(uint32_t id) override
	{
		std::cout << "Get invoice by id failed." << std::endl;
		SetEvent(g_invoiceEvent);
	}

	/**
	* Called on invoices get success
	*/
	virtual void
	InvoicesSuccess(
		const std::vector<sf_api::Invoice>& invs, 
		size_t currentPage, 
		size_t totalPages
	) override
	{
		std::cout << "Page of invoices request completed success." << std::endl;
		SetEvent(g_invoiceEvent);
	}

	/**
	* Called on invoices get failure
	*/
	virtual void
	InvoicesFailure(const GetInvoicesReqS* req) override
	{
		std::cout << "Page of invoices request failed." << std::endl;
		SetEvent(g_invoiceEvent);
	}

	/**
	* Invoice was created successfuly
	*/
	virtual void
	InvoiceCreatedSuccess(uint32_t id) override
	{
		std::cout << "Invoice with ID: " << id << " was created." << std::endl;
		SetEvent(g_invoiceEvent);
	}

	/**
	* Invoice created failed
	*/
	virtual void
	InvoiceCreatedFailure(
		const sf_api::Invoice& inv, 
		int code, 
		const char* data
	) override
	{
		std::cout << "Invoice was not created. This is bad. Maybe try to create invoice later." << std::endl;
		SetEvent(g_invoiceEvent);
	}
};

###Start using

int main(int argc, char** argv)
{
  // create API instance
  sf_api::Api<MyApi> api(
		API_EMAIL,
		API_TOKEN
	);
	
	if (api.IsLoaded())
	{
		// 
		// Create invoice/s example
		// Will demonstrate how to create invoices with this API
		// 

		sf_api::Invoice invoice;

		invoice.SetName("Some Very Long Invoice Name");
		invoice.SetHeaderComment(
			"This is my header comment"
			". This is only informative value."
		);
		
		//
		// Invoice item
		//
		
		sf_api::InvoiceItem item;
		item.SetUnitPrice(25);
		item.SetQuantity(8);
		item.SetTax(20);
		
		invoice.AddInvoiceItem(item);
		
		//
		// Create client for invoice
		//
		sf_api::Client client;
		client.SetName("Farba s.r.o.");
		client.SetAddress("Prhlava 32");
		client.SetCity("Bratislava");
		client.SetZip("11000");
		client.SetDelName("Farba2 s.r.o.");
		client.SetDelAddress("Methodova 64");
		client.SetDelCity("Nitra");
		
		invoice.SetClient(client);
		
		//
		// Try to create invoice
		//
		
		api << invoice;
		if (api.GetError() != RES_OK)
		{
			std::cout << "Create invoice failed." << std::endl;
		}
		
		return 0;
	}
}

##Compiled DLL libraries You can find latest compiled libraries in releases page, see Releases page

How to compile

Use Visual Studio to compile. Will create custom MSVC14 build scripts soon. Do not forget to add sfapi.dll and cacert.pem to your application root directory. Otherwise application will not work properly.

##Notes about security Never use SuperFaktura API credentials directly with no extra layer of encryption as in "api_test.cpp". These credentials are visible to everyone who can analyze your executable file. Note that everybody who knows your API credentials can modify (delete, create, modify, ...) documents in your SuperFaktura account. This is poor authentication concept, so you must design your app as secure as possible.

##Need more info, want to participate, report bugs? Contact me directly at jandoczy@jandoczy.com