Android Question In-App billing fails occassionally

Discussion in 'Android Questions' started by Inman, Sep 30, 2018.

  1. Inman

    Inman Well-Known Member Licensed User

    I am using InAppBilling3 (1.31) in an app of mine. I have about 14000 active users, out of which I have received emails from maybe 40-50 users saying they can't upgrade. Apparently when they click upgrade button, the popup from Play Store won't appear. Here is the code for upgrade button.
    Code:
    If BillingSupported Then
       manager.RequestPayment(ProductID,
    "inapp","upgrade")
    End If
    Now regarding the variable BillingSupported, manager.Initialize("manager", key) is called in Activity_Create. And then this happens.
    Code:
    Sub manager_BillingSupported (Supported As Boolean, Message As String)
        BillingSupported=Supported   
        
    If Supported Then manager.GetOwnedProducts Else ProgressDialogHide
    End Sub
    Since the user is complaining that he doesn't see the in-app upgrade pop-up from Play Store, it could mean either BillingSupported=False or manager.RequestPayment(ProductID,"inapp","upgrade") is not working. Some of the users who complained later informed me that in-app purchase worked after restarting the app a few times.

    The same issue is happening with some users who are trying to restore their previous purchases. As you can see I am calling manager.GetOwnedProducts if BillingSupported=True. Here also it has worked for users after 3-4 attempts.

    In both cases the common factor is the check for BillingSupported=True. I am wondering if it returns False sometimes. Personally I couldn't recreate this on any of my test devices.

    Is the B4A version of the library on a par with Google's latest release?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    You are probably doing something wrong.

    Where is the code that initializes BillingManager? Where is BillingSupported declared?

    You should show a message if BillingSupported is False.
     
  3. Inman

    Inman Well-Known Member Licensed User

    BillingManager is initialized in Activity_Create with manager.Initialize("manager", key), where manager is a Process_Globals variable. BillingSupport is declared in Globals.

    That's a good idea. I will add it to the next update.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    This is the mistake.

    Watch this video:

     
  5. Inman

    Inman Well-Known Member Licensed User

    Ok I watched the video again. I will try moving BillingSupported to Process_Globals and see if it makes a difference.

    But I still have a doubt. BillingSupported is used only in one activity, which is the Main activity. User runs the app, manager checks for BillingSupported, displays the result, all happening in sequence within the same activity. In this case, will it make a difference if BillingSupported is in Process_Globals, as opposed to Globals?
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    Are you initializing BillingManager when FirstTime = True? You should.
     
  7. Inman

    Inman Well-Known Member Licensed User

    No, I will do that now. Will it make a difference when the process is a straightforward Install-Run-Check Billing Supported-False?

    EDIT:

    Actually I do have it inside If FirstTime=True check.
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    This means that if the activity was destroyed and recreated then BillingSupported will be False. This happens because it was a Global variable instead of a Process_Global variable.
     
  9. Inman

    Inman Well-Known Member Licensed User

    Even though the chance of activity getting destroyed is pretty low when the user experiences this in the very first run of the app (while activity is still in foreground), I guess it is worth a try. Thanks Erel.
     
  10. Erel

    Erel Administrator Staff Member Licensed User

    If orientation is not locked then it will happen very quickly. It can also happen in other cases (user clicks on the back key and then returns to your app as well as other cases).
     
  11. Inman

    Inman Well-Known Member Licensed User

    I have orientation locked to portrait mode but you are right about the back key issue, which is probably why only a small subset of users are experiencing this. I will definitely move the variable to Process_Globals and see.
     
  12. Inman

    Inman Well-Known Member Licensed User

    I released an update yesterday with the changes mentioned above and I am still getting error reports on latest version. Now that there is a popup for BillingSupported, it is returning false for some users.

    To recap, here is the in-app billing implementation in my app
    • Dim manager As BillingManager3, BillingSupported As Boolean inside Process_Globals of Main activity
    • If FirstTime=True, then manager.Initialize("manager", key)
    Code:
    Sub manager_BillingSupported (Supported As Boolean, Message As String)
        BillingSupported=Supported   
        
    If Supported Then manager.GetOwnedProducts Else ProgressDialogHide
    End Sub
    When user clicks upgrade/restore button
    Code:
    If BillingSupported Then
       manager.RequestPayment(ProductID,
    "inapp","upgrade")
    Else
       
    Msgbox("Play Store billing is not working on your device","Error")
    End If
     
  13. npsonic

    npsonic Active Member Licensed User

    This is just a guess, but have you think about possibility that these users may have flashed devices, so there might be some Google components missing.
    You usually decide your self what Google services to install when flashing device with new os.
     
  14. Erel

    Erel Administrator Staff Member Licensed User

    Are they able to make a purchase if they kill the app and start it again?

    As @npsonic wrote it is possible that IAP is not supported.
     
  15. Inman

    Inman Well-Known Member Licensed User

    I actually asked these users that and every one of them seem to have no issues purchasing other apps.

    They didn't say "kill" specifically. But apparently, multiple closing and opening attempts seem to work for many users.

    I am thinking maybe when BillingSupported=False, I should tell the user to restart the app and call ExitApplication myself. That is equivalent to killing the app, right?

    Also is it possible to restart the app via code? I think I have seen some apps do it.
     
  16. Erel

    Erel Administrator Staff Member Licensed User

    If you can, try to debug it. Add some log messages and try to understand what happens. Many developers use this feature and I don't remember seeing other similar reports.
     
  17. Computersmith64

    Computersmith64 Well-Known Member Licensed User

    FWIW - I use InAppBilling3 in several apps & haven't had this issue. I put the initialization & BillingSupported & OwnedProducts callbacks into my Starter service & everything else in a separate "Purchase" activity. Because I also use Firebase Analytics I also do an IsGooglePlayServicesAvailable check before I initialize my billing manager.

    I do occasionally see IAP related crashes in Crashlytics, however these are always related to devices that have been rooted.

    - Colin.
     
    asales, Inman and Peter Simpson like this.
  18. Inman

    Inman Well-Known Member Licensed User

    Ok. What about calling ExitApplication or a way to restart the app via code?
    Never tried moving the code to Starter service. Will do that next.

    What was the reason you put in Starter service?
     
  19. asales

    asales Well-Known Member Licensed User

    Very nice.
    Can you put an example of the subs in Starter service and in the separate activities?
    Thanks.
     
  20. Erel

    Erel Administrator Staff Member Licensed User

    This is generally a bad idea.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice