Java SDK

PayDock has now released Java SDK, which can be downloaded from JCentre. There are different dependency snippets to be inserted in your code based on your selected build settings (we support Gradle, Maven or Ivy).

The library is opened sourced and can be found here. Specific tests for you to reference in your program are here.

Planning

Writing the Java SDK was interesting and our approach changed over time. There were a few considerations

  1. Which HTTP library to use: I settled on HttpsURLConnection instead of Apache’s client. I found an example which worked early on so I didn’t change it.
  2. Which JSON library to use to map the data models: I settled on the GSON library from Google as it also handled the date format.
  3. How to deal with ever increasing API functionality while keeping the the code base similar: You will find I extend a few base classes to try maintain the peace.

IDE

I used Android Studio to write the PayDock Java SDK. As I was also planning to write an Android SDK, it only felt natural that I use this IDE to create the library. Creating Java libraries in this IDE are quite simple and it allowed me to use the same repository and build scripts that I would for the Android SDK. Having written a few projects in Android Studio in the past made me feel comfortable using it. From the one IDE, I had the ability to write the Java library, include the functionality tests, link into GitHub for source control and then upload the library to JCentre for distribution. In the project file, I had a simple app which referenced the remote Java library on JCentre. This allowed me to verify that the library worked as expected when downloaded from the repository.

Structure of the SDK

The SDK is split into three sections:

  • Models – contained the structure of the data to be sent and received.
  • Services – contained the methods exposed in the SDK, such as add charges.
  • Tools – contained helpful methods that the services used, such as the HTTP connection class and the query string to url class.

Using this format made it easy to add new endpoints and features as they were added to the API.

Publishing

I used some libraries which easily allowed me to upload the SDK to Jcentre via Bintray. Once some of the artifacts were set, all I had to do was change the library version every time I wanted to upload the library. After the initial set up it now only takes a few seconds to upload a new version of the library to JCentre.

You can use the following steps to upload the library to Bintray, assuming you have already set up an account with them:

  1. In local.properties of your project file set your bintray credentials
    bintray.apikey=<your api key here>
    bintray.user=<your user name>
  2. Add the correct scripts and the library artifacts in your build.gradle
    My build.gradle can be found here
  3. Run the following commands in the terminal
    ./gradlew build
    ./gradlew install
    ./gradlew bintrayUpload

Use the SDK

I put a link to the SDK earlier in the piece so you can download the SDK and I look forward to any reviews and comments. Happy coding!

0 comments