As an example of integration, please use the sample app provided in our GitHub repository as a reference

 

Installation


Add the repository to your gradle dependencies:

allprojects {
    repositories {
        mavenCentral()
  }
}

Add the dependency to a module:

implementation 'com.mypos:slavesdk:2.1.6'

 

Initialization


Initialize the MyPos components in your app:

public class SampleApplication extends Application {

private POSHandler  mPOSHandler;

@Override
public void onCreate() {
	super.onCreate();
	POSHandler.setCurrency(Currency.EUR);
 	mPOSHandler = POSHandler.getInstance();
}

Optional settting for default receipt configuration is avaibale:

POSHandler.setDefaultReceiptConfig(POSHandler.RECEIPT_PRINT_ONLY_MERCHANT_COPY);

If set the default receipt configuration can be removed:

POSHandler.clearDefaultReceiptConfig();

Optional setting for the language of the receipts is avaibale(default is Language.ENGLISH):

POSHandler.setLanguage(Language.GERMAN);

isTerminalBusy() returns boolean to check if an operation is being performed at the moment:

POSHandler.getInstance().isTerminalBusy();

 

Connect to terminal


Choose connection type:

POSHandler.setConnectionType(ConnectionType.BLUETOOTH);
POSHandler.getInstance().connectDevice(context);

If the connection type is set to BLUETOOTH, ensure that the needed permissions are given in order to discover available Bluetooth devices.

if (POSHandler.getInstance().checkPermissions(context)) {
    // continue...
} else {
    // permissions request is sent...
}

 

Handle permissions result:

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
   if (requestCode == POSHandler.PERMISSIONS_REQUEST_CODE) {
       // check permissions result...
   }
}

 

To connect to a Go 2 terminal using Bluetooth Low Energy you can add the following broadcast receiver. This will eliminate the need to enter a pair code.

 

Register a broadcast receiver

IntentFilter intentFilter = new IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST);
intentFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
registerReceiver(broadCastReceiver, intentFilter);

You need to write the broadcastReceiver and handle it as below.

private BroadcastReceiver broadCastReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if(BluetoothDevice.ACTION_PAIRING_REQUEST.equals(action))
        {
            BluetoothDevice bluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            int blPin = intent.getIntExtra("android.bluetooth.device.extra.PAIRING_KEY", 123456);
            bluetoothDevice.setPin(blPin);
            bluetoothDevice.createBond();
        }
    }
};

Attach connection listener


mPOSHandler.setConnectionListener(new ConnectionListener() {
    @Override
    public void onConnected(final BluetoothDevice device) {
        // handle connected event here
    }
});

 

 

Attach pos ready listener

mPOSHandler.setPOSReadyListener(new POSReadyListener() {
    @Override
    public void onPOSReady() {
        // now you can start a transaction
    }
});

 

Send E-Receipt

In case you want to use email/phone receipt you have to choose POSHandler.RECEIPT_E_RECEIPT receipt configuration.

The following listener will be fired immediately after a transaction is approved:

POSHandler.getInstance().setPOSCredentialsListener(new POSCredentialsListener() {
    @Override
    public void askForCredentials(final CredentialsListener listener) {
	listener.onCredentialsSet("email@example.com"); // instead of email you can pass a phone number
    }
});