Monetary

Monetary MobileToken Android Library

Getting started with MobileToken for Android

Add MonetaryMobileToken.aar to your Android (Gradle) project

  1. Place MonetaryMobileToken.aar in the libs folder of your app.
  2. Ensure libs folder is included in flatDir repositories in your app's build.gradle file.

    repositories {
      flatDir {
        dirs 'libs'
      }
    }
    
  3. Add MonetaryMobileToken.aar to the dependencies in your app's build.gradle file.

    dependencies {
      compile (name: 'MonetaryMobileToken', ext: 'aar')
    }
    

Include the library in your code

import co.monetary.mobiletoken.*;

Implement tokenization result handler

Implement onActivityResult for MonetaryTokenizerActivity.MONETARY_TOKENIZER_REQUEST requestCode
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    if (requestCode == MonetaryTokenizerActivity.MONETARY_TOKENIZER_REQUEST)
    {
        if (resultCode == MonetaryTokenizerActivity.RESULT_SUCCESS)
        {
            // A token has been received!
            MonetaryToken token = (MonetaryToken)data.getSerializableExtra("token");
        }
        else if (resultCode == MonetaryTokenizerActivity.RESULT_ERROR)
        {
            // A tokenization error has occurred!
            MonetaryTokenizationError error = (MonetaryTokenizationError)data.getSerializableExtra("error");
        }
        else if (resultCode == MonetaryTokenizerActivity.RESULT_CANCELED)
        {
            // The user has cancelled tokenization!
        }
    }
}

For the MonetaryTokenizerActivity.RESULT_SUCCESS resultCode, the received Intent contains a MonetaryToken object named "token" that contains 5 String members:

For the MonetaryTokenizerActivity.RESULT_ERROR resultCode, the received Intent contains a MonetaryTokenizationError object named "error" that contains 2 members:

The MonetaryTokenizationError object's member errorCode is an enum of 4 possible values:

Request a token for keyed account

Create an Intent for MonetaryTokenizerActivity and provide a Monetary public key as an extra named "publicKey" then start activity for result with the Intent
Intent tokenIntent = new Intent(this, MonetaryTokenizerActivity.class);
tokenIntent.putExtra("publicKey", "[Public Key Goes Here]");
startActivityForResult(tokenIntent, MonetaryTokenizerActivity.MONETARY_TOKENIZER_REQUEST);

Report bugs

If you encounter any bugs or issues with the latest version of MobileToken for Android, please report them to us by opening a GitHub Issue!