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 {
jcenter()
}
}
Add the dependency to a module:
implementation 'com.mypos:slavesdk:1.0.2'
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 connection type is set to BLUETOOTH, make sure ACCESS_COARSE_LOCATION permission is given in order to discover available bluetooth devices.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, PERMISSION_COARSE_LOCATION);
}
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
}
});