Sample Application

The Stax Android SDK source is available on GitHub. The sample app is built as a simple, modern Android application. Two key classes highlight the Stax SDK usage:

MainApplication.kt
StaxViewModel.kt

Sample App Demo

The Stax sample application is an Android application that interacts with Stax BBPOS mobile readers and that Stax API to accept payments from cards, Apple Pay, and Google Pay. It is a small, single-screen app that has buttons for the main functions of the Stax SDK, including:

  • Initializing the SDK.
  • Searching & connecting to a card reader.
  • Disconnecting a card reader.
  • Accepting a 1¢ charge.
  • Pre-authorizing and capturing a 1¢ charge.
  • Voiding & refunding a charge.
  • Cancelling an in-progress transaction.

Getting Started
To get started with the sample application, you can run the following code snippet:

git clone <https://github.com/fattmerchantorg/fattmerchant-android-sdk.git> 

Once the SDK repository has been cloned, you can open the project in Android Studio. Before running the project for the first time,

  • Create a local.properties file at the project's root.
  • Add a staxApiKey variable and set its value to your API Key.

This allows you to test the Stax SDK within your merchant environment. Once you’ve set up the local.properties file, you can run the app project on your physical Android device.

MainApplication.kt

The MainApplication class stores the application context and instance statically to access them from the ViewModel class. The StaxSDK requires both the application context and instance to initialize the SDK and properly communicate with the hardware device. In this small example, we store those values as shown below.


class MainApplication : Application() {  
    companion object {  
        lateinit var context: Context  
        lateinit var application: Application  
    }
  override fun onCreate() {
    super.onCreate()
    context = applicationContext
    application = this
}
  }

StaxViewModel.kt

The StaxViewModel class is the main class that interacts with the Stax SDK. It is heavily commented on and easy to read. The functions are named based on the buttons they are associated with. For example, clicking the “Initialize” button on the sample application will call the onInitialize() function in the view model. This naming convention is made for every function in the view model class.