Google-IAP icon indicating copy to clipboard operation
Google-IAP copied to clipboard

How can i get product details (price, title, desc)

Open isacoskun opened this issue 2 years ago • 1 comments

I am getting a data array of products with IapConnector. I get the details of the products with the "Map" method in PurchaseListener. I couldn't parse this data as it was not suitable for json format and I didn't want to create a custom method. I'm sure there is an easier way. Can I get details such as the name, price and description of the product only with the "Map" method? thanks

isacoskun avatar Apr 12 '22 03:04 isacoskun

 override fun onPricesUpdated(iapKeyPrices: Map<String, DataWrappers.ProductDetails>) {
                Log.e("InAPP", "onPricesUpdated: ${iapKeyPrices.entries.toString()}\n")
                if (iapKeyPrices.entries.isNotEmpty()) {
                    basicPrice.text =
                        iapKeyPrices[resources.getString(R.string.weekly_id)]?.price.toString()
                    standardPrice.text =
                        iapKeyPrices[resources.getString(R.string.monthly_id)]?.price.toString()
                    premiumPrice.text =
                        iapKeyPrices[resources.getString(R.string.yearly_id)]?.price.toString()
                }
            }

mujahid-dzinemedia avatar Jul 29 '22 12:07 mujahid-dzinemedia

Hello, i am using java only and don't know anything about kotlin yet, can you write this into java language please? Thanks alot

 override fun onPricesUpdated(iapKeyPrices: Map<String, DataWrappers.ProductDetails>) {
                Log.e("InAPP", "onPricesUpdated: ${iapKeyPrices.entries.toString()}\n")
                if (iapKeyPrices.entries.isNotEmpty()) {
                    basicPrice.text =
                        iapKeyPrices[resources.getString(R.string.weekly_id)]?.price.toString()
                    standardPrice.text =
                        iapKeyPrices[resources.getString(R.string.monthly_id)]?.price.toString()
                    premiumPrice.text =
                        iapKeyPrices[resources.getString(R.string.yearly_id)]?.price.toString()
                }
            }

badnguyenky avatar Sep 23 '22 08:09 badnguyenky

I get the same issue, please as soon as you provide a solution

bhautikvirani avatar Sep 23 '22 10:09 bhautikvirani

For Java

@Override
            public void onPricesUpdated(@NotNull Map<String, DataWrappers.ProductDetails> map) {
                try {
                    Toasty.success(MainActivity.this, map.get("1").getPrice()+", "+
                            map.get("1").getPriceAmount()+", "+
                                    map.get("1").getPriceCurrencyCode()).show();
                }catch (Exception e){
                    e.printStackTrace();
                }
            }

I am using with "1" id, replace with your id and remove try catch also.

jmimohsin avatar Jun 15 '23 07:06 jmimohsin

``

For JAVA

for (Map.Entry<String, ? extends List<DataWrappers.ProductDetails>> entry : iapKeyPrices.entrySet()) {
                            if (entry.getKey() != null) {
                                if (entry.getKey().equalsIgnoreCase(PRODUCT_ID1))
                                    text1.setText(entry.getValue().get(0).getPrice());
                                else if (entry.getKey().equalsIgnoreCase(PRODUCT_ID2))
                                    text2.setText(entry.getValue().get(0).getPrice());
                                else if (entry.getKey().equalsIgnoreCase(PRODUCT_ID3))
                                    text3.setText(entry.getValue().get(0).getPrice());
                                else if (entry.getKey().equalsIgnoreCase(PRODUCT_ID4))
                                    text4.setText(entry.getValue().get(0).getPrice());
                                else if (entry.getKey().equalsIgnoreCase(PRODUCT_ID5))
                                    text5.setText(entry.getValue().get(0).getPrice());
                            }
}

akash55 avatar Nov 01 '23 06:11 akash55