FID with Native
#
I. Introduction to SDKIs 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
#
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 ofapp
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 resourcexml
:
<?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ìnhsentry
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
- Kotlin
- Java
override fun onCreate() { super.onCreate() FID.init(this) FID.setPlatformTracking( arrayOf( PLATFORM_TRACKING.APPSFLYER, PLATFORM_TRACKING.FIREBASE ) ) FPay.init(this)}
@Overridepublic void onCreate() { super.onCreate(); FID.INSTANCE.init(this); FID.INSTANCE.setPlatformTracking(new FTechTracking.PLATFORM[]{ FTechTracking.PLATFORM.APPSFLYER, FTechTracking.PLATFORM.FIREBASE }); FPay.INSTANCE.init(this);}
Create file
fid_config.json
inassets
directoryclientId
,merchant
,partnerCode
,scope
andgameCode
parameters will be operated provided granted to the project when starting the project
#
III. SDK IntegrationAfter importing enough resources, configure we start coding:
#
1. Calling functions in activity lifecycle- Kotlin
- Java
override fun onResume() { super.onResume() FID.notifyActive(this) FPay.notifyActive(this)}
override fun onPause() { super.onPause() FID.notifyInactive(this) FPay.notifyInactive(this)}
@Overrideprotected void onResume() { super.onResume(); FID.INSTANCE.notifyActive(this); FPay.INSTANCE.notifyActive(this);}
@Overrideprotected void onPause() { super.onPause(); FID.INSTANCE.notifyInactive(this); FPay.INSTANCE.notifyInactive(this);}
#
2. Call the login/register function#
2.1 Register callback- Kotlin
- Java
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)}
@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); FID.INSTANCE.registerSDK(this); FPay.INSTANCE.register(this); }
@Overrideprotected void onDestroy() { super.onDestroy(); FID.INSTANCE.unregisterSDK(this); FPay.INSTANCE.unregister(this);}
#
2.2 Call the login/register function with the syntax:- Kotlin
- Java
FID.login(object : FIDCallBack<FIDUser> { override fun onSuccess(result: FIDUser) {
}
override fun onFail() {
} override fun onCancel() { }})
FID.INSTANCE.login(new FIDCallBack<FIDUser>() { @Override public void onCancel() {
}
@Override public void onSuccess(FIDUser result) {
}
@Override public void onFail() {
}});
- Attributes in the FIDUser class:
Key | Data Type | Mission |
---|---|---|
profile | FIDProfile | |
authentication | FIDAuthentication |
- Attributes in the FIDProfile class:
Key | Data Type | Mission |
---|---|---|
id | Long | |
sub | String | |
picture | String | |
name | String | |
String | ||
phone | String | |
preferredUsername | String | |
additionalInfo | String | |
ekycVerified | Boolean | |
hasPassword | Boolean | |
cardInfo | FIDKCardData |
- Attributes in the FIDAuthentication class:
Key | Data Type | Mission |
---|---|---|
idToken | String | |
accessToken | String | |
refreshToken | String | |
expiresIn | String | |
tokenType | String | |
scope | String |
- 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 callbackonSuccess()
. 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:
- Kotlin
- Java
FID.logout(object : FIDCallBack<Boolean> { override fun onSuccess(result: Boolean) {
}
override fun onFail() {
} override fun onCancel() { }})
FID.INSTANCE.logout(new FIDCallBack<Boolean>() { @Override public void onCancel() { } @Override public void onFail() { } @Override public void onSuccess(Boolean result) { }});
- 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:
- Kotlin
- Java
FID.handleDeepLink(intent, this)
FID.INSTANCE.handleDeepLink(intent, this);
- Call the function to get user information with the syntax:
- Kotlin
- Java
FID.getCurrentAccount(object : FIDCallBack<FIDUser> { override fun onSuccess(result: FIDUser) { } override fun onFail() { } override fun onCancel() { }})
FID.INSTANCE.getCurrentAccount(new FIDCallBack<FIDUser>() { @Override public void onCancel() { } @Override public void onSuccess(FIDUser result) { } @Override public void onFail() { }});
- 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 andnickName
is the name of the game character.
- Kotlin
- Java
FID.setPlayerInfo(PlayerInfo().apply { this.gameServer = "Server name" this.nickName = "nick name"})
PlayerInfo playerInfo = new PlayerInfo();playerInfo.setGameServer("Server name");playerInfo.setNickName("nick name");
FID.INSTANCE.setPlayerInfo(playerInfo);
#
5.1 Use the built-in UI in the SDK- The payment function uses the interface of the SDK
- Kotlin
- Java
FPay.purchaseItemWithUI(object : FPay.FPayCallBack<String> { override fun onSuccess(result: String) { }
override fun onFail(error: String) {
} override fun onCancel() { }})
FPay.INSTANCE.purchaseItemWithUI(new FPay.FPayCallBack<String>() { @Override public void onCancel() { } @Override public void onSuccess(String result) { } @Override public void onFail(@NonNull String error) { }});
#
5.2 The partner side uses the available UI- Function to get list of items:
- Kotlin
- Java
FPay.getListProduct(object : FPay.FPayCallBack<List<ProductItem>> { override fun onSuccess(result: List<ProductItem>) { }
override fun onFail(error: String) {
} override fun onCancel() { }})
FPay.INSTANCE.getListProduct(new FPay.FPayCallBack<List<ProductItem>>() { @Override public void onCancel() { } @Override public void onSuccess(List<ProductItem> result) { } @Override public void onFail(@NonNull String error) { }});
- Item purchase handler function, passing in the paymentWithoutUISDK function the productInfo object is taken from the list item list in getListProduct function.
- Kotlin
- Java
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() { } } )}
private void purchaseItemWithoutUI(){ ProductItem productItem=new ProductItem(); productItem.setStorePackageID("eclazz.item1"); productItem.setGameCode("FSDK"); productItem.setIapPackageId(12); productItem.setInGamePackageID("152217"); productItem.setDisplayAmount(23000); productItem.setDisplayCurrency("VND");
FPay.INSTANCE.purchaseItemWithoutUI(this,productItem,new FPay.FIDPaymentCallback() { @Override public void onSuccess(@NonNull String transactionId){
}
@Override public void onFailure(){
}
@Override public void 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&AThis 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:
- Kotlin
- Java
FID.openQA(this)
FID.INSTANCE.openQA(this);
#
7. Connect Account- Call the Connect account function with the syntax:
- Kotlin
- Java
FID.connectAccount(object : FIDCallBack<FIDUser> { override fun onSuccess(result: FIDUser) { }
override fun onFail() { }
override fun onCancel() { } })
FID.INSTANCE.connectAccount(new FIDCallBack<FIDUser>() { @Override public void onCancel() { FIDCallBack.super.onCancel(); }
@Override public void onSuccess(FIDUser result) { }
@Override public void onFail() {
} });
#
8. Tracking- Using this code below :
- Kotlin
- Java
FID.sendLogSelectServer("server_name") // pass server name into constructor
FID.INSTANCE.sendLogSelectServer("server_name"); // pass server name into constructor
- Tracking the select character event :
- Kotlin
- Java
FID.sendLogSelectCharacter("character_name") // pass character name into constructor
FID.INSTANCE.sendLogSelectCharacter("character_name"); // pass character name into constructor
- Tracking up level :
- Kotlin
- Java
FID.sendLogLevelUp("1") // pass level into constructor
FID.INSTANCE.sendLogLevelUp("1"); // pass level into constructor
- Tracking tutorial completed :
- Kotlin
- Java
FID.sendLogTutorialCompleted()
FID.INSTANCE.sendLogTutorialCompleted();
- Custom event :
- Kotlin
- Java
FID.sendLogTracking("event_1", "extra_data") // pass custom event into constructor
FID.INSTANCE.sendLogTracking("event_1", "extra_data); // pass custom event into constructor
#
9. NoteWe 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. LicensesAll information is copyright of Ftech.ai