-
Place MonetaryMobileToken.aar in the
libsfolder of your app. -
Ensure
libsfolder is included inflatDirrepositories in your app's build.gradle file.repositories { flatDir { dirs 'libs' } } -
Add MonetaryMobileToken.aar to the
dependenciesin your app's build.gradle file.dependencies { compile (name: 'MonetaryMobileToken', ext: 'aar') }
import co.monetary.mobiletoken.*;@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:
token: The one-time-use token for the user-entered account data.brand: The card brand of account represented by the token.expirationMonth: The 2-digit expiration month of the account.expirationYear: The 4-digit expiration year of the account.last4: The last 4 digits of the account number.
For the MonetaryTokenizerActivity.RESULT_ERROR resultCode, the received Intent contains a MonetaryTokenizationError object named "error" that contains 2 members:
errorCode: The MonetaryMobileToken error code.errorMessage: The error description.
The MonetaryTokenizationError object's member errorCode is an enum of 4 possible values:
ErrorCodes.CONNECTION_ERROR: Failed to communicate with Monetary Token API.ErrorCodes.AUTHENTICATION_ERROR: Public key authentication failed.ErrorCodes.VALIDATION_ERROR: Failed to tokenize due to invalid account information.ErrorCodes.UNKNOWN_ERROR: An error has occurred tokenizing the account data at the Monetary Token API.
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);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!