Skip to main content

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:

class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
...

try {
MeaTokenControl.initialize(this)
}
catch (exception: MtcInitializationFailedException) {
val mtcError = exception.mtcError
// Handle error.
}
}
}

Card Data Parameters

val cardId: String = "<value>"
val cardSecret: String = "<value>"

val cardParams: MtcCardDataParameters = MtcCardDataParameters.withCardSecret(cardId, cardSecret)

Get Tokens

  • asynchronous
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.
}
}
)
  • synchronous
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.

Suspend Token

  • asynchronous
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.
}
}
)
  • synchronous
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.

Unsuspend Token

  • asynchronous
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.
}
}
)
  • synchronous
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.

Delete Token

  • asynchronous
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.
}
}
)
  • synchronous
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.

Get Token Status History

  • asynchronous
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.
}
}
)
  • synchronous
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.

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.