Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Having problem fetching product price at onProductsFetched #52

Open
kusyuk opened this issue Jun 12, 2023 · 5 comments
Open

Having problem fetching product price at onProductsFetched #52

kusyuk opened this issue Jun 12, 2023 · 5 comments

Comments

@kusyuk
Copy link

kusyuk commented Jun 12, 2023

Hi,

I'm having an "Attempt to invoke interface method 'java.lang.Object java.util.List.get(int)' on a null object reference" on onProductsFetched while trying to fetch prices for both IAPP and SUBS. The pricePro is a non-consumable IAPP and both subs doesn't have multiple offers.

Below is the code snipped:

'public void onProductsFetched(@nonnull List productDetails) {

String product, pricePro, priceSubMontly, priceSubYearly;

           for (ProductInfo productInfo : productDetails) {
                product = productInfo.getProduct();
                pricePro = productInfo.getOneTimePurchaseOfferPrice();
                priceSubMontly = productInfo.getSubscriptionOfferPrice(0,0);
                priceSubYearly = productInfo.getSubscriptionOfferPrice(0,0);

                if (product.equalsIgnoreCase(purchasePro)) {
                    Log.d("BillingConnector", "Product fetched: " + product);
                    Log.d("BillingConnector", "Product price: " + pricePro);
                    purchasePrice = pricePro;
                }
                if (product.equalsIgnoreCase(subMonthly)) {
                    Log.d("BillingConnector", "Product fetched: " + product);
                    Log.d("BillingConnector", "Product price: " + priceSubMontly);
                    monthlyPrice = priceSubMontly;
                }
                if (product.equalsIgnoreCase(subYearly)) {
                    Log.d("BillingConnector", "Product fetched: " + product);
                    Log.d("BillingConnector", "Product price: " + priceSubYearly);
                    yearlyPrice = priceSubYearly;
                }

}`

@duckyngo
Copy link

I have same problem

ava.lang.NullPointerException: productInfo.oneTimePurchaseOfferFormattedPrice must not be null
                                                                                                    	at com.***.***.ui.settings.PurchaseDialogFragment$initializeBillingClient$1.onProductsFetched(PurchaseDialogFragment.kt:170)
                                                                                                    	at games.moisoni.google_iab.BillingConnector.lambda$queryProductDetails$13$BillingConnector(BillingConnector.java:377)
                                                                                                    	at games.moisoni.google_iab.-$$Lambda$BillingConnector$7SWEfAJHP2O1ZHGnBXxKybJcbYc.run(Unknown Source:4)
                                                                                                    	at android.os.Handler.handleCallback(Handler.java:938)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:226)
                                                                                                    	at android.os.Looper.loop(Looper.java:313)
                                                                                                    	at android.app.ActivityThread.main(ActivityThread.java:8751)
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method)
                                                                                                    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
                                                                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

Only the productInfo.title and productInfo.product are available.

My previous code with Billing V4 worked fine

Help me please!

@duckyngo
Copy link

duckyngo commented Sep 1, 2023

Hope this can help anyone with same issue, We can get the formattedPrice and priceAmountMicros in subscriptionOfferDetails, not in getOneTimePurchaseOfferPrice as below":

var priceAmountMicros: Long? = null
var price: String? = null
for (subscriptionOfferDetails in productInfo.subscriptionOfferDetails) {
    for (pricingPhases in subscriptionOfferDetails.pricingPhases) {
        price = pricingPhases.formattedPrice
        priceAmountMicros = pricingPhases.priceAmountMicros
    }
}

@boronov
Copy link

boronov commented Sep 18, 2023

@duckyngo Thanks dude. For half a day I thought that the error was on my side because I just used sample app code

@moisoni97
Copy link
Owner

@duckyngo Thanks dude. For half a day I thought that the error was on my side because I just used sample app code

Things changed, the API changed, latest updates were made by contributors so the sample app could be broken.
Maybe I'll find time to update everything myself.

@boronov
Copy link

boronov commented Sep 18, 2023

@moisoni97 Thank you for your quick reply. Maybe you should say this in the README to avoid issues like this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants