Skip to main content
Version: Android 1.0.8

FID with Native

I. Introduction to SDK#

Is one of the very important mobile products of Ftech. The SDK is the bridge between Ftech's games, applications and platform systems.

Synopsis:

  • Call Ftech's login/register/logout interface
  • Get user's information

Download SDK

II. SDK Setup#

1. Install the SDK#

Copy the files:#

  • FID-Funzy-v1.0.8.arr
  • FPay-Funzy-v1.0.8.arr

to the folder libs

  • Open build.gradle file of app and add .arr file like below
dependencies {    ...    implementation fileTree(dir: 'libs', include: ['.jar', '.aar'])    implementation 'androidx.core:core-ktx:1.6.0'    implementation 'androidx.appcompat:appcompat:1.3.1'    implementation 'com.google.android.material:material:1.4.0'    implementation 'androidx.constraintlayout:constraintlayout:2.1.0'    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1"    implementation 'androidx.fragment:fragment-ktx:1.3.6'    implementation 'androidx.legacy:legacy-support-v4:1.0.0'      implementation 'com.squareup.retrofit2:retrofit:2.9.0'    implementation "com.squareup.retrofit2:converter-gson:2.9.0"    implementation "com.squareup.retrofit2:converter-scalars:2.9.0"    implementation "com.squareup.retrofit2:converter-moshi:2.6.2"    implementation "com.squareup.okhttp3:logging-interceptor:4.7.2"    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.3'    implementation 'org.jetbrains.kotlin:kotlin-reflect:1.5.21'    implementation "com.github.bumptech.glide:glide:4.12.0"    implementation "jp.wasabeef:glide-transformations:4.3.0"    implementation 'com.google.androidbrowserhelper:androidbrowserhelper:2.2.2'    implementation 'com.android.billingclient:billing:4.0.0'    implementation 'com.appsflyer:af-android-sdk:6.3.2'    implementation "androidx.room:room-runtime:2.3.0"    kapt "androidx.room:room-compiler:2.3.0"    implementation "androidx.room:room-ktx:2.3.0"    implementation 'com.google.firebase:firebase-messaging:23.0.3'    implementation 'com.google.firebase:firebase-core:20.1.2'}
  • Initialize file network-security-config.xml in folder resource xml:
<?xml version="1.0" encoding="utf-8"?><network-security-config xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools" tools:ignore="MissingDefaultResource">    <base-config cleartextTrafficPermitted="true">        <trust-anchors>            <certificates src="system" />        </trust-anchors>    </base-config></network-security-config>
  • Mở tệp Manifest.xml của app và gọi file network-security-config.xml và cấu hình sentry với giá trị sẽ được gửi khi dự án được khởi động như hình dưới
<application        android:name="ai.ftech.fid.FApplication"        android:networkSecurityConfig="@xml/network_security_config"        android:roundIcon="@mipmap/ic_launcher_round"        android:supportsRtl="true"        android:theme="@style/Theme.FIDAuthentication">

    <meta-data android:name="io.sentry.dsn" android:value="sentry_link" /></application>
  • Initialize FID in file Application
override fun onCreate() {    super.onCreate()    FID.init(this)    FID.setPlatformTracking(            arrayOf(                PLATFORM_TRACKING.APPSFLYER,                PLATFORM_TRACKING.FIREBASE            )    )    FPay.init(this)}
  • Create file fid_config.json in assets directory

    clientId , merchant, partnerCode, scope and gameCode parameters will be operated provided granted to the project when starting the project

III. SDK Integration#

After importing enough resources, configure we start coding:

1. Calling functions in activity lifecycle#

override fun onResume() {    super.onResume()    FID.notifyActive(this)    FPay.notifyActive(this)}
override fun onPause() {    super.onPause()    FID.notifyInactive(this)    FPay.notifyInactive(this)}

2. Call the login/register function#

2.1 Register callback#

override fun onCreate(savedInstanceState: Bundle?) {    super.onCreate(savedInstanceState)    FID.registerSDK(this)    FPay.register(this)}
override fun onDestroy() {    super.onDestroy()    FID.unregisterSDK(this)    FPay.unregister(this)}

2.2 Call the login/register function with the syntax:#

FID.login(object : FIDCallBack<FIDUser> {    override fun onSuccess(result: FIDUser) {
    }
    override fun onFail() {
    }         override fun onCancel() {                 }})
  • Attributes in the FIDUser class:
KeyData TypeMission
profileFIDProfile
authenticationFIDAuthentication
  • Attributes in the FIDProfile class:
KeyData TypeMission
idLong
subString
pictureString
nameString
emailString
phoneString
preferredUsernameString
additionalInfoString
ekycVerifiedBoolean
hasPasswordBoolean
cardInfoFIDKCardData
  • Attributes in the FIDAuthentication class:
KeyData TypeMission
idTokenString
accessTokenString
refreshTokenString
expiresInString
tokenTypeString
scopeString
  • This function will initialize the default configuration for the SDK and call the login/register form automatically.
  • Upon successful login/registration the SDK returns a model containing the user's data as result in callback onSuccess(). Handling of successful login/registration here
  • When login / registration is not successful, it will be handled at the callback onFail()

3. Call the logout function#

  • Call the logout function with the syntax:
FID.logout(object : FIDCallBack<Boolean> {  override fun onSuccess(result: Boolean) {
  }
  override fun onFail() {
  }     override fun onCancel() {                     }})
  • When successful logout will be processed in callback onSuccess()
  • When the logout fails, it will be handled at the callback onFail()

Demo image of login, registration, forgot password:

4. Get user information#

  • Call the function to get KOL deeplink with the syntax:
FID.handleDeepLink(intent, this)
  • Call the function to get user information with the syntax:
FID.getCurrentAccount(object : FIDCallBack<FIDUser> {    override fun onSuccess(result: FIDUser) {      }      override fun onFail() {      }        override fun onCancel() {                       }})
  • When successful logout will be processed in callback onSuccess()
  • When the logout fails, it will be handled at the callback onFail()

5. In-app purchase processing#

  • Before using payment, dev needs to call setPlayerInfo function. Where: gameServer is the identifier of the game server and nickName is the name of the game character.
FID.setPlayerInfo(PlayerInfo().apply {    this.gameServer = "Server name"    this.nickName = "nick name"})

5.1 Use the built-in UI in the SDK#

  • The payment function uses the interface of the SDK
FPay.purchaseItemWithUI(object : FPay.FPayCallBack<String> {    override fun onSuccess(result: String) {        }
    override fun onFail(error: String) {
    }        override fun onCancel() {                       }})

5.2 The partner side uses the available UI#

  • Function to get list of items:
FPay.getListProduct(object : FPay.FPayCallBack<List<ProductItem>> {    override fun onSuccess(result: List<ProductItem>) {            }
    override fun onFail(error: String) {
    }        override fun onCancel() {                       }})
  • Item purchase handler function, passing in the paymentWithoutUISDK function the productInfo object is taken from the list item list in getListProduct function.
private fun purchaseItemWithoutUI() {    val productItem = ProductItem().apply {        storePackageID = "eclazz.item1"        gameCode = "FSDK"        iapPackageId = 12        inGamePackageID = "152217"        displayAmount = 23000        displayCurrency = "VND"    }    FPay.purchaseItemWithoutUI(        this,        productItem = productItem,        object : FPay.FIDPaymentCallback {            override fun onSuccess(transId: String) {                            }              override fun onFailure() {                            }              override fun onCancel() {              }        }    )}
  • The onSuccess callback returns a list of items as listProductItem. Dev takes this data to self build interface.
  • When the item list cannot be obtained, the dev will process it in the onFail callback.
  • Upon successful item purchase, it will be processed in the onSuccess callback. In this callback return 1 transaction code.
  • In case of unsuccessful item purchase, it will be handled at the onFailure' callback.
  • When purchasing items that the user cancels will be handled in the onCancel callback.

How does the payment flow work?#

All payment methods share the same flow of operations as follows:

Game calls the payment interface from the SDK. The game will get the item list from the SDK or the SDK shows the item list for the game The SDK sends a payment request to the server. The server notifies the game server through an api payment callback, the game server processes the transaction to add money or in-game items and then tells the game to display the results in the game. At the same time, the server also receives information and returns it to the SDK. Sdk send packages to client game. The SDK still reports the results to the game through a delegate. The game that has received the results from the game server (which is the most accurate) does not need to use the information returned from this SDK anymore. It is used in special cases.

6. Q&A#

This part the game will ask the SDK to open a webview form for users to create questions about the game, as well like refer to the issues that the community has answered before,...

  • Call the Q&A function with the syntax:
FID.openQA(this)

7. Connect Account#

  • Call the Connect account function with the syntax:
FID.connectAccount(object : FIDCallBack<FIDUser> {                override fun onSuccess(result: FIDUser) {                                  }
                override fun onFail() {                                    }
                override fun onCancel() {                                  }            })

8. Tracking#

  • Using this code below :
 FID.sendLogSelectServer("server_name") // pass server name into constructor
  • Tracking the select character event :
FID.sendLogSelectCharacter("character_name") // pass character name into constructor
  • Tracking up level :
FID.sendLogLevelUp("1") // pass level into constructor
  • Tracking tutorial completed :
FID.sendLogTutorialCompleted()
  • Custom event :
FID.sendLogTracking("event_1", "extra_data") // pass custom event into constructor

9. Note#

We implement the OIDC Connect (https://auth0.com/docs/authorization/protocols/openid-connect-protocol). After the user login via our SDK, the user can receive an accessToken. If you wanna verify the accessToken, you can use our well-known endpoint to do it.

https://id-dev.ftech.ai/.well-known/openid-configuration

To confirm the access token of the FID provided via the callback, use the following REST API:

curl --location --request POST 'https://id-dev.ftech.ai/connect/introspect'--header 'Content-Type: application/x-www-form-urlencoded'--header 'Authorization: Basic ZnVuenktYXBpOkZGTzVPS3lvZzJHa3NkNXFDRWZKd1pmcUQ4b1o4dWtIMkw1d1BwU1Y='--data-urlencode 'token={access_token}'
  • Authorization: Basic code

  • code = base64(api_resource_name:api_resource_secret)

  • response:

{  "iss": "https://id-dev.ftech.ai",  "nbf": 1634272203,  "iat": 1634272203,  "exp": 1634272383,  "aud": [  "fid-api",  "fpay-api",  "funzy-api",  "https://id-dev.ftech.ai/resources"  ],  "amr": "pwd",  "client_id": "6669642d646576",  "sub": "20699307220992000",  "auth_time": 1634272203,  "idp": "local",  "preferred_username": "fid_1wNMUvvrFK",  "sid": "6bf0945a3bc04e06b5d545b2f5338165",  "active": true,  "scope": "funzy-api:client"}

The active property returns true if validated and vice versa

10. Licenses#

All information is copyright of Ftech.ai