Search in sources :

Example 1 with SkuDetails

use of com.codename1.payments.v3.SkuDetails in project CodenameOne by codenameone.

the class CodenameOneActivity method getProducts.

Product[] getProducts(String[] skus, boolean fromCacheOnly) {
    if (inventory != null) {
        ArrayList pList = new ArrayList<Product>();
        ArrayList moreskusList = new ArrayList<Product>();
        for (int i = 0; i < skus.length; i++) {
            String sku = skus[i];
            if (inventory.hasDetails(sku)) {
                SkuDetails details = inventory.getSkuDetails(sku);
                Product p = new Product();
                p.setSku(sku);
                p.setDescription(details.getDescription());
                p.setDisplayName(details.getTitle());
                p.setLocalizedPrice(details.getPrice());
                pList.add(p);
            } else {
                moreskusList.add(sku);
            }
        }
        // if the inventory does not all the requestes sku make an update.
        if (moreskusList.size() > 0 && !fromCacheOnly) {
            try {
                inventory = mHelper.queryInventory(true, moreskusList);
                return getProducts(skus, true);
            } catch (IabException ex) {
                Logger.getLogger(CodenameOneActivity.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        Product[] products = new Product[pList.size()];
        products = (Product[]) pList.toArray(products);
        return products;
    }
    return null;
}
Also used : SkuDetails(com.codename1.payments.v3.SkuDetails) ArrayList(java.util.ArrayList) Product(com.codename1.payment.Product) IabException(com.codename1.payments.v3.IabException)

Aggregations

Product (com.codename1.payment.Product)1 IabException (com.codename1.payments.v3.IabException)1 SkuDetails (com.codename1.payments.v3.SkuDetails)1 ArrayList (java.util.ArrayList)1