Implementation guide
Before starting implementation you should have finished Installation of the MCD SDK.
Main Interface
com.meawallet.mtc.MeaTokenControl
is the main interface of MTC SDK.
All methods support both synchronous and asynchronous invocations:
- asynchronous: Network request is executed on a background thread and result is returned on the main UI thread as a callback.
- synchronous: Network request is executed on the same thread, cannot be used from the main UI thread.
Initialization
Before you can use MTC SDK in your application, you must initialize it using MeaTokenControl.initialize(...)
method once during every app lifetime.
We suggest to initialize MTC SDK in Application.onCreate()
method:
- kotlin
- java
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
...
try {
MeaTokenControl.initialize(this)
}
catch (exception: MtcInitializationFailedException) {
val mtcError = exception.mtcError
// Handle error.
}
}
}
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
...
try {
MeaTokenControl.initialize(this);
}
catch (MtcInitializationFailedException exception) {
MtcError mtcError = exception.getMtcError();
// Handle error.
}
}
}
Card Data Parameters
- kotlin
- java
val cardId: String = "<value>"
val cardSecret: String = "<value>"
val cardParams: MtcCardDataParameters = MtcCardDataParameters.withCardSecret(cardId, cardSecret)
String cardId = "<value>";
String cardSecret = "<value>";
MtcCardDataParameters cardParams = MtcCardDataParameters.withCardSecret(cardId, cardSecret);
Get Tokens
- asynchronous
- kotlin
- java
MeaTokenControl.getTokens(cardParams,
object : MtcGetTokensListener {
override fun onSuccess(accounts: List<MtcAccount>) {
// Use retrieved data.
}
override fun onFailure(mtcError: MtcError) {
val errorCode: Int = mtcError.code
val errorMessage: String = mtcError.message
// Handle error.
}
}
)
MeaTokenControl.getTokens(cardParams,
new MtcGetTokensListener() {
@Override
public void onSuccess(@NonNull List<MtcAccount> accounts) {
// Use retrieved data.
}
@Override
public void onFailure(@NonNull MtcError mtcError) {
int errorCode = mtcError.getCode();
String errorMessage = mtcError.getMessage();
// Handle error.
}
}
);
- synchronous
- kotlin
- java
val accounts: List<MtcAccount> = try {
MeaTokenControl.getTokens(cardParams)
} catch (exception: MtcException) {
val mtcError = exception.mtcError
val errorCode = mtcError.code
val errorMessage = mtcError.message
// Handle error.
}
// Use retrieved data.
List<MtcAccount> accounts;
try {
accounts = MeaTokenControl.getTokens(cardParams);
}
catch (MtcException exception) {
MtcError mtcError = exception.getMtcError();
int errorCode = mtcError.getCode();
String errorMessage = mtcError.getMessage();
// Handle error.
}
// Use retrieved data.
Suspend Token
- asynchronous
- kotlin
- java
MeaTokenControl.suspendToken(tokenUniqueReference,
object : MtcTokenControlListener {
override fun onSuccess(tokenUniqueReference: String) {
// Use retrieved data.
}
override fun onFailure(mtcError: MtcError) {
val errorCode: Int = mtcError.code
val errorMessage: String = mtcError.message
// Handle error.
}
}
)
MeaTokenControl.suspendToken(tokenUniqueReference,
new MtcTokenControlListener() {
@Override
public void onSuccess(@NonNull String tokenUniqueReference) {
// Use retrieved data.
}
@Override
public void onFailure(@NonNull MtcError mtcError) {
int errorCode = mtcError.getCode();
String errorMessage = mtcError.getMessage();
// Handle error.
}
}
);
- synchronous
- kotlin
- java
val suspendedTokenUniqueReference: String = try {
MeaTokenControl.suspendToken(tokenUniqueReference)
} catch (exception: MtcException) {
val mtcError = exception.mtcError
val errorCode = mtcError.code
val errorMessage = mtcError.message
// Handle error.
}
// Use retrieved data.
try {
String suspendedTokenUniqueReference = MeaTokenControl.suspendToken(tokenUniqueReference);
}
catch (MtcException exception) {
MtcError mtcError = exception.getMtcError();
int errorCode = mtcError.getCode();
String errorMessage = mtcError.getMessage();
// Handle error.
}
// Use retrieved data.
Unsuspend Token
- asynchronous
- kotlin
- java
MeaTokenControl.unsuspendToken(tokenUniqueReference,
object : MtcTokenControlListener {
override fun onSuccess(tokenUniqueReference: String) {
// Use retrieved data.
}
override fun onFailure(mtcError: MtcError) {
val errorCode: Int = mtcError.code
val errorMessage: String = mtcError.message
// Handle error.
}
}
)
MeaTokenControl.unsuspendToken(tokenUniqueReference,
new MtcTokenControlListener() {
@Override
public void onSuccess(@NonNull String tokenUniqueReference) {
// Use retrieved data.
}
@Override
public void onFailure(@NonNull MtcError mtcError) {
int errorCode = mtcError.getCode();
String errorMessage = mtcError.getMessage();
// Handle error.
}
}
);
- synchronous
- kotlin
- java
val unsuspendedTokenUniqueReference: String = try {
MeaTokenControl.unsuspendToken(tokenUniqueReference)
} catch (exception: MtcException) {
val mtcError = exception.mtcError
val errorCode = mtcError.code
val errorMessage = mtcError.message
// Handle error.
}
// Use retrieved data.
try {
String unsuspendedTokenUniqueReference = MeaTokenControl.unsuspendToken(tokenUniqueReference);
}
catch (MtcException exception) {
MtcError mtcError = exception.getMtcError();
int errorCode = mtcError.getCode();
String errorMessage = mtcError.getMessage();
// Handle error.
}
// Use retrieved data.
Delete Token
- asynchronous
- kotlin
- java
MeaTokenControl.deleteToken(tokenUniqueReference,
object : MtcTokenControlListener {
override fun onSuccess(tokenUniqueReference: String) {
// Use retrieved data.
}
override fun onFailure(mtcError: MtcError) {
val errorCode: Int = mtcError.code
val errorMessage: String = mtcError.message
// Handle error.
}
}
)
MeaTokenControl.deleteToken(tokenUniqueReference,
new MtcTokenControlListener() {
@Override
public void onSuccess(@NonNull String tokenUniqueReference) {
// Use retrieved data.
}
@Override
public void onFailure(@NonNull MtcError mtcError) {
int errorCode = mtcError.getCode();
String errorMessage = mtcError.getMessage();
// Handle error.
}
}
);
- synchronous
- kotlin
- java
val deletedTokenUniqueReference: String = try {
MeaTokenControl.deleteToken(tokenUniqueReference)
} catch (exception: MtcException) {
val mtcError = exception.mtcError
val errorCode = mtcError.code
val errorMessage = mtcError.message
// Handle error.
}
// Use retrieved data.
try {
String deletedTokenUniqueReference = MeaTokenControl.deleteToken(tokenUniqueReference);
}
catch (MtcException exception) {
MtcError mtcError = exception.getMtcError();
int errorCode = mtcError.getCode();
String errorMessage = mtcError.getMessage();
// Handle error.
}
// Use retrieved data.
Get Token Status History
- asynchronous
- kotlin
- java
MeaTokenControl.getTokenStatusHistory(tokenUniqueReference,
object : MtcGetTokenStatusHistoryListener {
override fun onSuccess(tokenStatusInfoList: List<MtcTokenStatusInfo>) {
// Use retrieved data.
}
override fun onFailure(mtcError: MtcError) {
val errorCode: Int = mtcError.code
val errorMessage: String = mtcError.message
// Handle error.
}
}
)
MeaTokenControl.getTokenStatusHistory(tokenUniqueReference,
new MtcGetTokenStatusHistoryListener() {
@Override
public void onSuccess(@NonNull List<MtcTokenStatusInfo> tokenStatusInfoList) {
// Use retrieved data.
}
@Override
public void onFailure(@NonNull MtcError mtcError) {
int errorCode = mtcError.getCode();
String errorMessage = mtcError.getMessage();
// Handle error.
}
}
);
- synchronous
- kotlin
- java
val tokenStatusInfoList: List<MtcTokenStatusInfo> = try {
MeaTokenControl.getTokenStatusHistory(tokenUniqueReference)
} catch (exception: MtcException) {
val mtcError = exception.mtcError
val errorCode = mtcError.code
val errorMessage = mtcError.message
// Handle error.
}
// Use retrieved data.
List<MtcTokenStatusInfo> tokenStatusInfoList;
try {
tokenStatusInfoList = MeaTokenControl.getTokenStatusHistory(tokenUniqueReference);
}
catch (MtcException exception) {
MtcError mtcError = exception.getMtcError();
int errorCode = mtcError.getCode();
String errorMessage = mtcError.getMessage();
// Handle error.
}
// Use retrieved data.
Error Handling
MtcError
is a generic MTC error object containing all error info (error code, error name, error message and request Id). MtcError
can be returned with onFailure
callback or gathered from MtcException
object.