Skip to main content

Fetching Products

Before fetching products from Appmate, ensure that you created products by following Creating Products page.

Fetching Products from Appmate#

This page describes how to fetch the products. With the getProducts method of PurchaseClient, you will get the active products synced with the Google Play Store and Huawei App Gallery.

If you have created some products for your app for the first time, it may take time to get synced products, as Google has a time delay in activating the products. Synchronization of product prices with Google may take some time.

After you called getProducts method, the products will be cached in the sdk for 10 minutes. So you will be able to get the response faster than getting directly from the network. If you add a new product and want to see it in your app for testing purposes, you can delete your app's cache. The products will be fetched from the network the next time you open your app. getProducts method returns products in the form of List<Product>. If you failed to fetch products and getting a GenericError , note the following:

You can access the list of all products, list of some spesific products or the list of products filtered by product types.

To handle the result of the asynchronous operation, you must specify a listener which implements the ReceivedDataListener interface. You can then override onSucceeded(), which notifies the listener when the query finishes successfully or with failure, as shown in the following code:

1. Fetching all products:#

Request#

Parameter NameType
listenerReceivedDataListener<List<Product>, GenericError>

Response#

Parameter NameType
onSucceededList<Product>
onFailedGenericError
PurchaseClient.instance.getProducts(    object : ReceivedDataListener<List<Product>, GenericError> {        override fun onSucceeded(data: List<Product>) {        }
        override fun onError(error: GenericError) {        }    })

2. Fetching products by specifying a list of some productIds: #

When calling getProductsByProductIdList(), pass a productIdList that specifies a list of product ID strings created in the Creating Products page of our web console.

Request#

Parameter NameType
productIdListList<String>
listenerReceivedDataListener<List<Product>, GenericError>

Response#

Parameter NameType
onSucceededList<Product>
onFailedGenericError
PurchaseClient.instance.getProductsByProductIdList(productIdList,     object : ReceivedDataListener<List<Product>, GenericError> {        override fun onSucceeded(data: List<Product>) {        }
        override fun onError(error: GenericError) {        }    })

3. Fetching products filtered by product types: #

Request#

Parameter NameType
productTypeProductType
listenerReceivedDataListener<List<Product>, GenericError>

Response#

Parameter NameType
onSucceededList<Product>
onFailedGenericError
PurchaseClient.instance.getProductsByProductType(productType,     object : ReceivedDataListener<List<Product>, GenericError> {        override fun onSucceeded(data: List<Product>) {        }
        override fun onError(error: GenericError) {        }    })

Displaying Products#

You can download the code of the sample client application from github and examine it.

fetch_products