Purchases
SDK configuration to send purchases info to Appflow.ai
This part of SDK is important for subscriptions information
Ready to work Configure product information in Google Play
Displaying Products
To fetch the products, you have to call method:
/**
* parameter1:skus,The product id list
*/
Appflow.getSkuDetails(skus: List<String>, listener: SkuDetailsListener)
Example
val skus = listOf("SKU_WEEKLY", "SKU_MONTHLY", "SKU_YEARLY")
Appflow.getSkuDetails(skus, object : SkuDetailsListener {
override fun onError(error: PurchasesError) {}
override fun onReceived(map: HashMap<String, ProductDetails>) {
for (product in map) {
val skuDetails = product.value
Log.d(TAG,"productId:${skuDetails.productId}")
Log.d(TAG,"title:${skuDetails.title}")
Log.d(TAG,"description:${skuDetails.description}")
Log.d(TAG,"name:${skuDetails.name}")
Log.d(TAG,"subscriptionOfferDetails:${skuDetails.subscriptionOfferDetails}")
}
}
})
API Reference
Making Purchases
Making Purchases, you have to call method:
/**
* parameter1:activity,The context must be of type Activity
* parameter2:productDetails,The ProductDetails object corresponding to the product
* parameter3:offerToken,to get an offer token, call ProductDetails.subscriptionOfferDetails() for a list of
* offers that are available to the user
*/
Appflow.purchasePackage(activity: Activity, productDetails: ProductDetails, offerToken: String, listener: MakePurchaseListener)
/**
* parameter1:activity,The context must be of type Activity
* parameter2:productDetails,The ProductDetails object corresponding to the product
* Notice:The first offer token is used by default
*/
Appflow.purchasePackage(activity: Activity, productDetails: ProductDetails, listener: MakePurchaseListener)
Example
Appflow.purchasePackage(activity, productDetails, offerToken, object : MakePurchaseListener{
override fun onCompleted(purchase: Purchase) {
//After the purchase is successful, you can obtain the order id,
//order token and other information through the Purchase object
}
override fun onError(error: PurchasesError, userCancelled: Boolean) {
//When userCancelled is true, it means that the user cancels the purchase;
//when userCancelled is true, it means that the purchase fails
//You can get specific failure information through PurchasesError
}
})
API Reference
Subscription Status
Get the subscription status of a product, you have to call method:
Appflow.getSubscriberInfo(listener: ReceivePurchaserInfoListener)
Example
Appflow.getSubscriberInfo(object : ReceivePurchaserInfoListener {
override fun onReceived(subscriber: IapIap.Subscriber) {
for (info in subscriber.entitlementsList) {
Log.d(TAG,"sku:${info.productId}")
Log.d(TAG,"isActive:${info.isActive}")
}
}
override fun onError(error: PurchasesError) {}
})
API Reference
Upgrade/Downgrade product
**To upgrade/downgrade a product, you have to call method:
/**
* parameter1:activity,The context must be of type Activity
* parameter2:packageToPurchase,The ProductDetails object corresponding to the product
* parameter3:offerToken,to get an offer token, call ProductDetails.subscriptionOfferDetails() for a list of
* offers that are available to the user
* parameter4:upgradeInfo,Upgrade/Downgrade Product Information Object
*/
Appflow.purchasePackage(
activity: Activity,
packageToPurchase: ProductDetails,
offerToken: String,
upgradeInfo: UpgradeInfo,
listener: MakePurchaseListener
)
/**
* parameter1:activity,The context must be of type Activity
* parameter2:packageToPurchase,The ProductDetails object corresponding to the product
* parameter3:upgradeInfo,Upgrade/Downgrade Product Information Object
* Notice:The first offer token is used by default
*/
Appflow.purchasePackage(
activity: Activity,
packageToPurchase: ProductDetails,
upgradeInfo: UpgradeInfo,
listener: MakePurchaseListener
)
Example
val upgradeInfo = UpgradeInfo(productId, BillingFlowParams.ProrationMode.DEFERRED)
Appflow.purchasePackage(activity, packageToPurchase, offerToken, upgradeInfo, object : MakePurchaseListener{
override fun onCompleted(purchase: Purchase) {}
override fun onError(error: PurchasesError, userCancelled: Boolean) {}
})
API Reference
Last updated