PurchaseStacks is a framework for in app purchase. It works with both Java and Kotlin. API reference is available at android-sdk.purchasestacks.com
Installation# PurchaseStacks for Android can be included via Gradle.
build.gradle
Copy implementation 'com.purchasestacks.androidsdk:1.0.4'
Importing PurchaseStacks# You should now be able in import PurchaseStacks
Copy import com.purchasestacks.androidsdk.*
Configure Proguard# You should add -keep class com.purchasestacks.androidsdk.** { *; } to your Proguard configuration.
Intialization# Be sure you're configuring PurchaseStacks with your API Key & API Secret.
Copy PSPurchase
.config(this, "API_KEY", "API_SECRET")
If you have user info, it's recommended to track directly in config
Copy PSPurchase
.config(this, "API_KEY", "API_SECRET", "USER_ID", "USER@email.com");
Only one instance of PSPurchase should be instantiated at a time! Use the configure method to let the framework handle the singleton instance for you.
Track user info# Copy PSPurchase
.sharedInstance
.trackUser("USER_ID","USER@Email.com", "USER_NAME", "FB_ID")
Get Groups# You can organize the groups in PurchaseStacks Dashboard and access them here.
PurchaseStacks will automatically fetch the and get the product information from Google. This means when users launch purchase screen, products will already be loaded.
This returns all groups array, active groups array and additional information
Copy PSPurchase
.sharedInstance
.groups(object : PSReceiveGroupsBlock{
override fun onSuccess(psGroupsInfo: PSGroupsInfo?) {
// groupsInfo contains all groups information
}
override fun onError(error: Error?) { }
})
This returns a dictionary of groups with names as keys
Copy PSPurchase
.sharedInstance
.groupByName(object : PSReceiveGroupByNameBlock{
override fun onSuccess(psGroupByName: PSGroupByName?) {
var group = psGroupByName?.get("PREMIUM")
}
override fun onError(error: Error?) { }
})
Get Package & Product# Copy psGroup.packageByName?.let {
packages -> {
val monthlyPackage = packages.get("Monthly")
monthlyPackage?.let {
pkg-> {
val monthlyProduct = pkg.activeProduct
}
}
val yearlyPackage = packages.get("Yearly")
yearlyPackage?.let {
pkg-> {
val yearlyProduct = pkg.activeProduct
}
}
}
}
Make a Purchase# Purchase with product# Copy PSPurchase
.sharedInstance
.makePurchaseWithProduct(this, product, object : PSPurchaseCompletedBlock{
override fun onSuccess(psTransaction: PSTransaction?, psGroup: PSGroup?, complete: Boolean) {
psGroup?.let { group ->
if(group.isActive){
// Purchase is successful
}
}
}
override fun onError(error: PurchasesError?) { }
});
Purchase with package# Copy PSPurchase
.sharedInstance
.makePurchaseWithPackageInfo(this, packageInfo, object : PSPurchaseCompletedBlock{
override fun onSuccess(psTransaction: PSTransaction?, psGroup: PSGroup?, complete: Boolean) {
psGroup?.let { group ->
if(group.isActive){
// Purchase is successful
}
}
}
override fun onError(error: PurchasesError?) { }
})
Get Consumable products# Copy PSPurchase
.sharedInstance
.products(object: PSReceiveConsumablesBlock{
override fun onSuccess(psProducts: List<PSProduct>?) {
psProducts.let {
// These are only consumable products
}
}
override fun onError(error: Error?) { }
})
Get associated user info# Copy PSPurchase
.sharedInstance
.userInfo(object : PSReceiveUserInfoBlock{
override fun onSuccess(psUserInfo: PSUserInfo?) {
psUserInfo.let {
// Tracked user
}
}
override fun onError(error: Error?) { }
})