This application component let's you easily integrate with the Xero API.
It mainly leverages the official Xero Java SDK. The configuration of the SDK is done via CUBA's application properties.
xero
is available in the CUBA marketplace- Select a version of the add-on which is compatible with the platform version used in your project:
Platform Version | Add-on Version |
---|---|
6.9.x | 0.1.x |
Add custom application component to your project:
- Artifact group:
de.diedavids.cuba.xero
- Artifact name:
xero-global
- Version: add-on version
dependencies {
appComponent("de.diedavids.cuba.xero:xero-global:*addon-version*")
}
In order to download all dependencies it is required to additionally add the following maven repositories to your build.gradle
:
buildscript {
//...
repositories {
maven { url "https://raw.github.com/XeroAPI/Xero-Java/mvn-repo" }
maven { url "https://raw.github.com/XeroAPI/XeroAPI-Schemas/mvn-repo" }
//...
}
}
In order to interact with the Xero API it is reqiured to setup an account and create the corresponding credentials accordingly. After that the configuation settings can be setup in the CUBA application.
In order to configure the connection to Xero correctly, this youtube video shows how to setup the integration: CUBA Xero Java SDK Integration - configuration
In order to interact with the Xero API, the following steps are required:
- create an account at Xero
- enable the Xero demo company
- create a application
Once all those steps are done, you will get credentials from Xero (Consumer Key, Consumer Secret etc.)
Additionally a public / private key pair has to be created. See details here: https://developer.xero.com/documentation/api-guides/create-publicprivate-key
Using OpenSSL it looks like this:
openssl genrsa -out privatekey.pem 1024
openssl req -new -x509 -key privatekey.pem -out publickey.cer -days 1825
openssl pkcs12 -export -out public_privatekey.pfx -inkey privatekey.pem -in publickey.cer
Now you should have a file called public_privatekey.pfx
and a password defined for it.
In the CUBA application it is possible to configure all required and optional attributes through Administration > Application Properties > Xero
.
The required file public_privatekey.pfx
can be used in two ways:
The first option is to put the public_privatekey.pfx
file into the conf directory of the CUBA application.
In the configuration it has to be referenced via the application property xero.pathToPrivateKey
where the filename
should be inserted as a value.
The second option uses the external files feature of the CUBA application. You can just upload the file via Administration > External Files
.
Then in the configuration xero.privateKeyFileDescriptor
has to point the FileDescriptor. This can be done
via the following String sys$FileDescriptor-f0edbbb8-24c8-a179-a052-0e73f5eb88d1
where f0edbbb8-24c8-a179-a052-0e73f5eb88d1
is the UUID of the uploaded file.
The ID of the file can be retrieved via the external files screen, when right click on the file and select System information
.
In order to use the Xero API, you can use the default XeroClient
from the official SDK.
To get a reference to a XeroClient
instance, you can use the following snippet:
@Inject
XeroClientFactory xeroClientFactory;
public List<Invoice> getInvoicesFromXero() {
XeroClient client = xeroClientFactory.createClient();
List<Invoice> xeroInvoiceList = client.getInvoices();
return xeroInvoiceList;
}
An example usage of this application component can be found here: cuba-example-using-xero
More information on how to use Xero as well as using additional configurations, the following resources should be looked at: