DEV Community

Doug Sillars for Fidel API

Posted on • Originally published at blog.fidel.uk

Adding the Fidel Android SDK to Your Kotlin Android Application

Fidel's real-time transaction monitoring allows you to monitor your customers' purchasing patterns. The first step, is of course, for customers to opt-in their credit cards for tracking at your locations. Dealing with card numbers opens up a requirement of "PCI Compliance." This is the Payment Card Industry Security Standard and requires regular security checks to ensure your systems are adequately protected.

If your systems are not PCI compliant, or you'd rather not worry about handling card numbers for real-time transactions, you can use Fidel's PCI compliant SDKs to link the cards. Thus absolving you of any security requirements for the process. Our documentation walks through the steps to add our SDK to a Java-based Android app, so in this post, we'll use Kotlin to accomplish the same.

Kotlin Android App

To add the SDK to an application, we'll build a basic "Hello World" Android app.

In Android Studio, start a new project:

Create an empty Activity from the templates:
Screenshot of Android Studio Activity creation

Finally, name your application, choose Kotlin as your language, and use API 19 or higher (or use legacy support libraries to support older versions of Android).
Screenshot of Android Studio Project configuration

Android Studio will chug for a bit but will create the working "Hello World" application for you.

Running the 'Hello World' app on your phone.

If you are new to Android development, you'll need to setup ADB debugging on your phone, and connect your phone to your computer. You can then click the "run" button in Android Studio to start the Hello World app:
start app

The app will soon start up on your phone:
screenshot of app running on phone

Adding in the Fidel SDK

Adding the Fidel SDK is easy: while the instructions in the documentation are for Java - Android Studio converts the code into Kotlin for you.

Let's walk through all of the steps we need to walk through to add the Fidel Card linking SDK to our sample app. Following the documentation, we need to:

  1. Add maven { url 'https://jitpack.io' } to our repositories section of our build.grade file.
  2. Add implementation 'com.github.FidelLimited:android-sdk:1.3.1' to the App build.gradle dependencies.
  3. Since you've updated your dependencies - sync your project. Sync Project
  4. Now we can begin adding in our code to the MainActivity (and update the apiKey with your public key and the appropriate programId). You can find all this information in your Fidel Dashboard.
Fidel.apiKey = "pk_test_6e94da6f-145a-47db-b56b-f1314e74aa2e"
Fidel.programId = "f8d6890e-145d-46ea-b66f-afacfd954580"
Enter fullscreen mode Exit fullscreen mode
  1. Now we add the Company name, privacy policy and deletion instructions. I also added the country parameter in this step:
Fidel.companyName = "Star Wars Quotes" // default: "Company Name".
Fidel.privacyURL = "https://media.giphy.com/media/4560Nv2656Gv0Lvp9F/giphy.gif"
// Maximum 60 characters, default: "going to your account settings."
Fidel.deleteInstructions = "https://media.giphy.com/media/DrDePYcSohIFG/giphy.gif" 
Fidel.country = Fidel.Country.UNITED_KINGDOM;
Enter fullscreen mode Exit fullscreen mode
  1. Paste in the result card response:
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)
    if (requestCode == Fidel.FIDEL_LINK_CARD_REQUEST_CODE) {
        if (data != null && data.hasExtra(Fidel.FIDEL_LINK_CARD_RESULT_CARD)) {
            val card = data.getParcelableExtra<Parcelable>(Fidel.FIDEL_LINK_CARD_RESULT_CARD) as LinkResult?
            Log.d("d", "CARD ID = " + card!!.id)
        }
    }
}
Enter fullscreen mode Exit fullscreen mode
  1. Finally, make sure to present the Fidel activity:
Fidel.present(this@MainActivity)
Enter fullscreen mode Exit fullscreen mode

That is all there is to it - your app is now ready to run!

Screenshot of Fidel SDK running on an Android

Card Linking on Android

There are 2 techniques to link your card with the Android SDK:

  1. The traditional way of entering the long card number/expiration date/CCV. Note also that if you have cards stored in Google Pay - your phone will attempt to autofill this for you. This is convenient for your customers, but real cards will fail in the Fidel test environment: Screenshot of Fidel SDK running on an Android with Google Pay autofill

Entering a test number will sync with the Fidel backend:
Manually entering a card number
immediately synced in Fidel

  1. The Android SDK also has an optical card reader. By giving the application permission to use the camera: card scanning with the camera

The library in use does not appear to work for test cards found in a Google image search, but it does work with real cards.

Conclusion

With just a few lines of code, you can add the Fidel Android SDK to your application to allow your customers fast and easy sign up into your card linking service. Because the card numbers never touch your system, and the Fidel SDK is entirely PCI compliant, there are no security risks to you or your customers.

Let us know how you are using the Android SDK in your app over in the community forum.

Top comments (0)