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

SubscriptionOfferDetails NullPointerException #418

Closed
aniealss opened this issue Apr 6, 2023 · 2 comments
Closed

SubscriptionOfferDetails NullPointerException #418

aniealss opened this issue Apr 6, 2023 · 2 comments

Comments

@aniealss
Copy link

aniealss commented Apr 6, 2023

Version of flutter_inapp_purchase 5.4.1

Platforms you faced the error (IOS or Android or both?) Android

if (offerToken == null) {
offerToken = selectedProductDetails.subscriptionOfferDetails!![0].offerToken
}
query BillingClient.ProductType.INAPP product, subscriptionOfferDetails is null

This line throws a NullPointerException

@deakjahn
Copy link
Contributor

deakjahn commented Apr 27, 2023

I second that. Set out to find a fix and PR it.

@aniealss Did you by any chance proceed any further?

@deakjahn
Copy link
Contributor

deakjahn commented Apr 27, 2023

Before PR-ing it, let's discuss because the following modifications seem to solve it for one-off in-app purchases but subscriptions should also be checked first. In AndroidInappPurchasePlugin.kt:

private fun buyProduct(
...
  // Get the selected offerToken from the product, or first one if this is a migrated from 4.0 product
  // or if the offerTokenIndex was not provided
  var offerToken : String? = null
  if (offerTokenIndex != null) {
      offerToken = selectedProductDetails.subscriptionOfferDetails?.get(offerTokenIndex)?.offerToken
  }
  if (offerToken == null && selectedProductDetails.subscriptionOfferDetails != null) {
      offerToken = selectedProductDetails.subscriptionOfferDetails!![0].offerToken
  }

  val details = ProductDetailsParams.newBuilder().setProductDetails(selectedProductDetails) 
  if (offerToken != null)
    details.setOfferToken(offerToken)
  val productDetailsParamsList = listOf(details.build())
  builder.setProductDetailsParamsList(productDetailsParamsList)
  ...

https://stackoverflow.com/questions/73027160/how-to-pass-token-of-a-one-time-purchase-product-to-google-play-billing-library suggests and this coincides with my experience, too, that there's no need for setOfferToken(offerToken) in the case of non-subscription purchases.

@deakjahn deakjahn mentioned this issue Apr 28, 2023
@aniealss aniealss closed this as completed Jul 3, 2023
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

2 participants