Implementation
With the Notificare's Monetize add-on you can easily sell virtual goods in Google Play. Our library will provide you all the mechanisms to quickly develop an engaging in-app store experience where you can sell digital products.
To be able to use In-App Billing in your application, make you sure you add the following permission to your AndroidManifest.xml:
<uses-permission android:name="com.android.vending.BILLING" />
Add the following event listener that will be trigger as soon as your products are ready to be consumed:
notificare.onEventReceived.listen((NotificareEvent event) async {
if (event.name == "storeLoaded") {
//Load your UI
}
});
If there is some issue with your products or your account, the following event is triggered instead:
notificare.onEventReceived.listen((NotificareEvent event) async {
if (event.name == "storeFailedToLoad") {
//Handle error
}
});
If your store is loaded successfully, at any time you can request the list of products with the following method:
try {
List<NotificareProduct> products = await notificare.fetchProducts();
//Handle Success
} catch(e){
//Handle Error
}
You can also retrieve a list of the purchased products, this can be used to allow or not products to be bought again (depending on their type) or automatically give access to the content they unlock. To do that, simply invoke the following method:
try {
List<NotificareProduct> products = await notificare.fetchPurchasedProducts();
//Handle Success
} catch(e){
//Handle Error
}
To get a specific product, using any of the objects return from your list of products, invoke the following method:
try {
var product = products[0];
NotificareProduct response = await notificare.fetchProduct(product);
//Handle Success
} catch(e){
//Handle Error
}
Finally to allow a user to buy a product, simply invoke the method below. Invoking this method, will start teh buying process flow which will return some of the events described below in this page.
var product = products[0];
notificare.buyProduct(product);
In-App Purchase Delegates
The method above will start the purchase flow handled by iOS and the App Store. You can then use the following delegates to understand the state of the purchase or the hosted content associated to the product. Use should use them to update UI or show errors.
notificare.onEventReceived.listen((NotificareEvent event) async {
if (event.name == "productTransactionCompleted") {
}
if (event.name == "productTransactionRestored") {
}
if (event.name == "productTransactionFailed") {
}
});
This is all you need to display, sell and handle hosted content for your in-app products.