Google-IAP
Google-IAP copied to clipboard
How can i get product details (price, title, desc)
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
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()
}
}
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() } }
I get the same issue, please as soon as you provide a solution
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.
``
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());
}
}