AptoideBillingSDKManager Unity Documentation
Overview
The AptoideBillingSDKManager
is a Unity MonoBehaviour class that acts as a bridge between the Unity application and the Aptoide Billing Native SDK. It provides methods to initialize the SDK, manage billing operations, and handle callbacks from the native SDK. This manager is designed to simplify the integration of in-app purchases and billing-related features in Unity applications.
Features
Initialization
- Initializes the Aptoide Billing SDK with the required parameters.
- Establishes a connection to the billing service.
Billing Operations
- Query SKU details asynchronously.
- Launch the billing flow for in-app purchases.
- Consume purchased items.
- Query purchases made by the user.
- Check if specific features are supported by the SDK.
App Update Management
- Check if an app update is available.
- Launch dialogs or redirect users to the store for updates.
Callback Handling
- Handles callbacks from the native SDK for billing setup, purchase updates, SKU details, and consumption responses.
Methods
Initialization
InitializePlugin
InitializePlugin
Initializes the SDK with listeners, a public key, and the game object name.
Parameters:
IAppCoinsBillingStateListener _appCoinsBillingStateListener
IConsumeResponseListener _consumeResponseListener
IPurchasesUpdatedListener _purchasesUpdatedListener
ISkuDetailsResponseListener _skuDetailsResponseListener
string publicKey
string gameObjectName
Initialize
Initialize
Calls the native SDK to initialize with the provided public key and game object name.
StartConnection
StartConnection
Starts the connection to the billing service.
EndConnection
EndConnection
Ends the connection to the billing service.
Billing Operations
IsReady
IsReady
Checks if the billing service is ready.
Returns: bool
QuerySkuDetailsAsync
QuerySkuDetailsAsync
Queries SKU details asynchronously.
Parameters:
string[] skus
string skuType
LaunchBillingFlow
LaunchBillingFlow
Launches the billing flow for a specific SKU.
Parameters:
string sku
string skuType
string developerPayload
Returns:int
(response code)
ConsumeAsync
ConsumeAsync
Consumes a purchased item.
Parameters:
string purchaseToken
IsFeatureSupported
IsFeatureSupported
Checks if a specific feature is supported by the SDK.
Parameters:
string feature
Returns:int
(response code)
QueryPurchases
QueryPurchases
Queries purchases made by the user.
Parameters:
string skuType
Returns:PurchasesResult
App Update Management
IsAppUpdateAvailable
IsAppUpdateAvailable
Checks if an app update is available.
Returns: bool
LaunchAppUpdateDialog
LaunchAppUpdateDialog
Launches a dialog to prompt the user for an app update.
LaunchAppUpdateStore
LaunchAppUpdateStore
Redirects the user to the store for an app update.
Callback Handlers
OnBillingSetupFinished
OnBillingSetupFinished
Handles the callback when the billing setup is finished.
Parameters:
string responseCode
OnBillingServiceDisconnected
OnBillingServiceDisconnected
Handles the callback when the billing service is disconnected.
OnPurchasesUpdated
OnPurchasesUpdated
Handles the callback when purchases are updated.
Parameters:
string purchasesResultJson
OnSkuDetailsResponse
OnSkuDetailsResponse
Handles the callback when SKU details are received.
Parameters:
string skuDetailsResultJson
OnConsumeResponse
OnConsumeResponse
Handles the callback when a consumption response is received.
Parameters:
string consumeResultJson
Integration Notes
To use the AptoideBillingSDKManager
, you must create a separate class to handle the game logic for the following operations:
-
Purchase:
Implement logic to initiate purchases by callingLaunchBillingFlow
and handle the results via theOnPurchasesUpdated
callback. -
Server-Side Check:
Perform server-side validation of purchases to ensure security and prevent fraud. -
Consumption:
Manage the consumption of purchased items by callingConsumeAsync
and handling theOnConsumeResponse
callback. -
Query Purchases:
UseQueryPurchases
to retrieve the list of purchases made by the user. -
Query SKUs:
UseQuerySkuDetailsAsync
to fetch details about available SKUs.
Example Workflow
- Initialize the SDK using
InitializePlugin
. - Query available SKUs using
QuerySkuDetailsAsync
. - Launch the billing flow for a selected SKU using
LaunchBillingFlow
. - Validate the purchase on the server side.
- Consume the purchase if applicable using
ConsumeAsync
. - Query purchases to update the game state using
QueryPurchases
.
Extra - Unity Import
Import Unity Package Manager
- Open the top menu bar: Window > Package Manager.
- Click the
+
sign and select Import via git URL. - Paste the following link:
https://github.com/Catappult/appcoins-sdk-unity.git#v0.9.0.7
Android Manifest
Update your AndroidManifest.xml
file to include the necessary permissions and queries for SDK communication:
<manifest>
...
<queries>
<package android:name="com.appcoins.wallet" />
...
</queries>
<uses-permission android:name="com.appcoins.BILLING" />
<uses-permission android:name="android.permission.INTERNET" />
...
</manifest>
Gradle Files
Include the following dependency in your Gradle files to ensure proper integration of the Aptoide Billing SDK:
dependencies {
implementation("io.catappult:android-appcoins-billing:0.9.0.8") // Check the latest version in mvnrepository
}
If you don't already have build.gradle
files, you can use the approach outlined below:
Module (baseProjectTemplate.gradle
)
baseProjectTemplate.gradle
)allprojects {
buildscript {
repositories {
google()
jcenter()
}
dependencies {
// Ensure compatibility with the Android Gradle Plugin version preinstalled with Unity
classpath 'com.android.tools.build:gradle:3.4.3'
}
}
repositories {
google()
jcenter()
flatDir {
dirs "${project(':unityLibrary').projectDir}/libs"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Application (mainTemplate.gradle)
apply plugin: 'com.android.library'
repositories {
google()
mavenCentral()
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation("io.catappult:android-appcoins-billing:0.9.0.8")
implementation('org.json:json:20210307')
}
android {
compileSdkVersion 33 // Adjust as required
buildToolsVersion '33.0.2'
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
minSdkVersion 21
targetSdkVersion 33
versionCode 1
versionName '1.0'
}
lintOptions {
abortOnError false
}
aaptOptions {
noCompress = ['.unity3d', '.ress', '.resource', '.obb']
}
}
Additional Tools
Android Logcat
To debug and verify the SDK's behavior, use the Android Logcat plugin.
Steps:
- Access Windows > Analysis > Android Logcat from the Unity top bar.
2. Select the active APK and filter logs using the tag"APPC"
.
This helps track detailed information regarding initialization, purchases, and consumption.
Backend Validation
Always perform server-side validation for purchases to ensure security and prevent fraud.
Diceroll Demo App
A full demo app, Diceroll Aptoide, is available as an example to showcase SDK integration. Steps in the workflow:
- Initialize the Billing SDK.
- Load SKU information.
- Query purchases.
- Trigger billing flow for purchases or subscriptions.
- Validate purchases on the server side.
- Deliver items to the user.
- Consume the purchase when applicable.
FAQ
What is the recommended Unity version?
The most suitable Unity version for integration is 2021.3.8f1
.
Updated about 19 hours ago