Setup Instructions

Installation Steps

Integrating Triangle with your application is fairly straight-forward. You need to:

  • Download the SDK
  • Generate keys for your application
  • Add the library to your application

Data Flow

Before examining the steps in detail, let's take a moment to think about the architecture of Triangle. We use unique encryption keys for each application in addition to unique keys for each account in the system. Before your application can use any of the methods in the API, a key exchange needs to occur between your application and the Triangle backend. In this process, you have to provide your account's access key and secret key, in addition to the identifier of the application in which you are using the APIs. The system then verifies your identity, ensures that the API is being used in the application it was intended to, and finally exchanges the encryption keys with the application.

The key exchange is a one-time process and is the only time during which data flows through the network. We recommend you do this process during your application's start; alternatively you can postpone this task to the time you first try to scan a credit card. After a successful key exchange, the Triange API won't use the network. Card scans are done completely on the client side and the data is not sent to our servers in any way.

Generating Keys

Your application will have unqiue keys assigned to it that will be used to encrypt the card information your application scans. To generate the keys, simply go to the keys page and add your application. Once your application is added, take note of its Application ID generated by the system. Access Key, Secret Key and the Application ID is the data you need to initialize the Triangle API in your application.

Adding the Library

The sample application in our GitHub repository is a great starting point to do this step. You can exactly see how an application uses the APIs with all the relevant details being present.

1. Add the Library

To add the library to your project, find the***.jar file in the SDK you downloaded and add it to the libs folder of your project.

2. Modify the Android Manifest

The Triangle API requires NFC permissions and also network connectivity during the key exchange. Further, if you intend to use the ScanActivity class of the API, you need to declare it in your manifest. To add these permissions and define the activity, add the following lines to AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
    <uses-permission android:name="android.permission.NFC" />
    <uses-permission android:name="android.permission.INTERNET" />
        <activity android:name="io.triangle.reader.ScanActivity" />

3. Initialize Triangle APIs

Before the API can be used, the key exchange step needs to occur. We recommend you do this in your Application's onCreate as it is done in the sample application.

    public void onCreate()

        // Initialize the Triangle API if it has not been initialized yet
        final Session triangleSession = Session.getInstance();

        if (!triangleSession.isInitialized())
            // Since the initialization performs network IO, we should execute it in a background thread
            AsyncTask<Void, Void, Void> triangleInitializationTask = new AsyncTask<Void, Void, Void>()
                Exception exception;

                protected Void doInBackground(Void... voids)
                    // Please use the keys you obtain from the keys page below
                                "applicationId", // Application ID
                                "accessKey",      // Access Key
                                "secretKey", // Secret Key
                    catch (Exception exception)
                        this.exception = exception;

                    return null;

                protected void onPostExecute(Void aVoid)

                    if (this.exception != null)
                        // Do error handling if initialization was not successful

            // Finally execute the task

Now you're free to leverage any of the classes in the API. The easiest way to get started is to send an Intent to the ScanActivity class that automatically reads the card's information when a payment card comes to close proximity of the device.
You can inspect the scanCard method of the sample class here on GitHub.


  Share on Facebook   Tweet