Getting Started with Android

πŸ‘

To get a copy of our SDK, please contact our partner team at [email protected]

🚧

Minimum Supported Android Version

Android 8.0 API 26

Import Libraries

  • Create folder named libs in base project directory.
  • Copy and paste both provided aar's in libs folder.
  • In your app level gradle file (Module: project.yourappname) add dependencies.

Gradle example

apply plugin: 'com.android.application'
apply plugin: 'realm-android'

buildscript {
    repositories {
        jcenter()
        google()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.4'
        classpath "io.realm:realm-gradle-plugin:4.2.0"
    }
}

android {
    compileSdk 31

    defaultConfig {
        applicationId "com.paysimple.TestApp"
        minSdk 26
        targetSdk 31
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }
    buildToolsVersion '31.0.0'
}

dependencies {
    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    implementation 'com.android.volley:volley:1.2.1'
    implementation 'com.google.code.gson:gson:2.8.9'


    //tripos dependencies
    implementation 'com.google.dagger:dagger:2.11'
    implementation 'org.apache.commons:commons-lang3:3.5'
    implementation 'commons-io:commons-io:2.5'
    implementation files('../libs/paysimpleandroidsdk-release.aar')
    implementation files('../libs/triposmobilesdk-release.aar')
}

Processing a Sale Example

Here's a simplified version of completing a sale within a single Android activity. Use your device's name, copy and paste client token, and create a TextView named "textView" and a button with onClick set to payment.

package com.paysimpleandroid.sdktest;

import android.Manifest;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;

import com.google.gson.Gson;
import com.paysimpleandroid.paysimpleandroidsdk.IPaysimpleBBPOS;
import com.paysimpleandroid.paysimpleandroidsdk.PsDeviceType;
import com.paysimpleandroid.paysimpleandroidsdk.PsEnvironment;
import com.paysimpleandroid.paysimpleandroidsdk.bbpos.DeviceState;
import com.paysimpleandroid.paysimpleandroidsdk.bbpos.PaysimpleBBPOS;
import com.paysimpleandroid.paysimpleandroidsdk.bbpos.PaysimpleSDKError;
import com.paysimpleandroid.paysimpleandroidsdk.bbpos.PaysimpleSDKResponse;
import com.paysimpleandroid.paysimpleandroidsdk.bbpos.PaysimpleSaleRequest;
import com.paysimpleandroid.paysimpleandroidsdk.bbpos.PaysimpleSaleResponse;
import com.paysimpleandroid.paysimpleandroidsdk.bbpos.PsEnums.PsAmountConfirmationType;
import com.paysimpleandroid.paysimpleandroidsdk.bbpos.PsListeners.PsDeviceInteractionListener;
import com.paysimpleandroid.paysimpleandroidsdk.bbpos.PsListeners.PsListener;

import java.math.BigDecimal;

public class MainActivity extends AppCompatActivity implements PsListener, PsDeviceInteractionListener {

    IPaysimpleBBPOS paysimpleBBPOS;
    private TextView responseView;
    String clientToken = "";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        responseView = findViewById(R.id.textView);

        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION,
                Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.WRITE_EXTERNAL_STORAGE,
                Manifest.permission.BLUETOOTH_CONNECT, Manifest.permission.BLUETOOTH_SCAN}, 1);
        paysimpleBBPOS = PaysimpleBBPOS.getInstance(this, PsEnvironment.QA1, PsDeviceType.BbposEmv);
        paysimpleBBPOS.subscribeToListener(this);
        paysimpleBBPOS.subscribeToDeviceInteractionListener(this);
        new Thread(() -> {
            PaysimpleSDKResponse res = paysimpleBBPOS.initializeAndConnect(clientToken, "CHB202044007347");
        }).start();
    }

    public void payment(View view) {
        if (paysimpleBBPOS.isDeviceConnected()) {
            new Thread(() -> {
                try {
                    //Include all fees here
                    BigDecimal amount = BigDecimal.valueOf(Math.random() * 100).setScale(2,
                            BigDecimal.ROUND_DOWN);

                    PaysimpleSaleRequest saleRequest = new PaysimpleSaleRequest(amount);
                    paysimpleBBPOS.processSale(clientToken, saleRequest);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }).start();
        }
    }

    @Override
    public void updateResponse(Double aDouble, String... strings) {
        runOnUiThread(() -> responseView.setText(strings[0]));
    }

    @Override
    public void onError(PaysimpleSDKError paysimpleSDKError) {
        runOnUiThread(() -> responseView.setText(new Gson().toJson(paysimpleSDKError)));
    }

    @Override
    public void onDeviceEvent(DeviceState deviceState, String s) {
        runOnUiThread(() -> responseView.setText(s + " " + deviceState.name()));
    }

    @Override
    public void onPaymentResponse(PaysimpleSaleResponse paysimpleSaleResponse) {
        runOnUiThread(() -> responseView.setText(new Gson().toJson(paysimpleSaleResponse)));
    }

    @Override
    public void onAmountConfirmation(PsAmountConfirmationType psAmountConfirmationType, BigDecimal bigDecimal, PsConfirmAmountListener psConfirmAmountListener) {
        psConfirmAmountListener.psConfirmAmount(true);
    }

    @Override
    public void onPromptUserForCard(String s) {
        runOnUiThread(() -> responseView.setText(s));
    }

    @Override
    public void onDisplayText(String s) {
        runOnUiThread(() -> responseView.setText(s));
    }

    @Override
    public void onRemoveCard() {
        runOnUiThread(() -> responseView.setText("Remove Card"));
    }

    @Override
    public void onCardRemoved() {
        runOnUiThread(() -> responseView.setText("Card Removed"));
    }
}

What’s Next