Skip to main content

Initialization

To initialize the SDK, you simply have to create an instance of LuneSDKManager that would be used across your app.

Provided that you will need to initialize LuneSDK with credentials, you may want to do all the prep work within a view-model. That includes things like:

  • Getting the credentials
  • Setting up a refresh callback (optional, based on the TTL of your credentials)
  • Setting up logging (also optional)

You can find specific implementation details for your project setup below:

Jetpack Compose​

Follow the steps below to initialize LuneSDK in your Jetpack Compose Project.

  1. Initialize SDK: In your MainActivity, initialize the LuneSDKManager in the onCreate() method:

    MainActivity.kt
    class MainActivity : ComponentActivity() {
    private lateinit var luneSDK: LuneSDKManager
    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    // Initialize the SDK manager
    luneSDK = LuneSDKManager(
    baseUrl = "", // Base URL
    token = "", // User access token
    customerId = id, // Customer ID
    refreshTokenCallback = TokenRefresher() // Callback for token refresh
    )
    // Set up the UI using Jetpack Compose
    setContent {
    LuneBankTheme {
    Surface(modifier = Modifier.fillMaxSize()) {
    RootComposable(luneSDK)
    }
    }
    }
    }
    }
  2. Using SDK in Composable: Pass the LuneSDKManager instance to any composable in your app:

    @Composable
    fun TransactionView(luneSDK: LuneSDKManager) {
    // Use the SDK
    luneSDK.TransactionListComponent()
    }
tip

While you could create multiple instances of LuneSDKManager, we recommend creating just one instance per app. You could share that single instance with other views by passing it around.

Activities and Fragments​

Follow the steps below to initialize LuneSDK in your Activities and Fragments Project.

  1. Add Lune View to Layout: In your layout file, include the Lune view by specifying its fully qualified class name:

    YourLayoutFile.xml
    <io.lunedata.lunesdk.library.classes.LuneCompatManager
    android:id="@+id/luneLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    />
  2. Initialize SDK in Code: In your Activity or Fragment, create and initialize an instance of LuneSDKManager with the required credentials:

    YourActivity.kt
    private lateinit var luneSDK: LuneSDKManager
    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    // Initialize the SDK manager
    luneSDK = LuneSDKManager(
    baseUrl = "", // Base URL
    token = "", // User access token
    customerId = id, // Customer ID
    refreshTokenCallback = TokenRefresher() // Callback for token refresh
    )
    // Optionally set up the callback later
    luneSDK.setupRefreshCallback(TokenRefresher())
    // Configure the Lune view
    val luneView = findViewById<LuneCompatManager>(R.id.luneLayout)
    luneView.manager = luneSDK
    luneView.component = LuneView.ActivityComponent
    }

Refresh Token Callback​

The refresh token callback is a critical component for managing user authentication tokens. It handles the situation where the user's access token expires and needs to be refreshed.

Implementation:​

The callback function is implemented in the TokenRefresher class, which you can customize based on your app's needs:

class TokenRefresher: RefreshTokenCallback {
override fun refreshToken(): String? {
// Implement logic to refresh the token and obtain a new access token
return "" // make sure to return the token here
}
}

ProGuard / R8 Rules​

If your app uses ProGuard or R8, add the following rule to avoid obfuscation issues:

-keep class io.lunedata.lunesdk.** { *; }