Android Question New in-app purchases questions

sorex

Expert
Licensed User
Longtime User
Hello,

A few days ago I had a look at the new in-app purchase method.

While the routines are well documented I still have some questions about it.
(the initial thread is months old so I decided not to ask it there)

1. what is the use of this BILLING_KEY variable and what value should it have?


2. in some cases for example when google play is not installed we had to use try/catch to avoid crashes. this method also allowed us to remove the "remove ads" button as it wouldn't work anyway
is this new method crash proof? if so where should we check if billing client is working correct or not?

B4X:
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
 try
        billing.Initialize("billing")
        inAppSupported=True ' <--- place here ???
catch
        inAppSupported=False ' <--- place here ???
 end try
 RestorePurchases
End Sub

Private Sub RestorePurchases
    Wait For (billing.ConnectIfNeeded) Billing_Connected (Result As BillingResult)   
    If Result.IsSuccess Then
        inAppSupported=True   ' <--- or use it here???
        Wait For (billing.QueryPurchases("inapp")) Billing_PurchasesQueryCompleted (Result As BillingResult, Purchases As List)
        Log("Query completed: " & Result.IsSuccess)
        If Result.IsSuccess Then
            For Each p As Purchase In Purchases
                Log(p.sku)
                If p.Sku = ADS_SDK_ID Then HandleAdsPurchase(p)
            Next
        End If
    Else
        inAppSupported=False   ' <--- or use it here???
    End If
End Sub


3. when pressing my button I get this fancy slide in one tap purchase menu but it mentiones that this is in test mode without charging.

is this because it detects that I'm using the same account on the phone than my dev account?
 

sorex

Expert
Licensed User
Longtime User
another rather important question...

4. Would it still be wise/advices to write purchases to a settings file just in case the user opens the app with no netwerk connection?
if the user gets network again he will see ads while he has payed to remove them.

even if the Wait for (billing) waits forever he might gets ads until billing goes through when the network connection returns.
does this wait wait forever or will it time out after a while?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1.
The answer is in point 5d:
d. Verify the order signature. This can be done locally or remotely. It is safer to do it with with a remote server.
Verifying it locally is done by calling VerifyPurchase with the base64 key you got from Google Play Console.

2. Google's documentation doesn't suggest that this method can raise an exception. There were also no such reports for now.
If the service is not available then Result.IsSuccess will return False.

3. Are you using real product ids or the test ids? If you are using real ids then it probably related to the user account.

4. Not needed. QueryPurchases is based on a local cache.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
Thanks.

1. so the signature can be dropped as the online methd is prefered (I didn't find this key in the purchases pages)

3. yes, it was a real id but as long as it works in test mode it should work for others aswell.

4. Indeed, I saw that the local settings writing was only in the B4i version. what if the cache corrupts? I guess the restorePurchases rebuilds it again?
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
corruption is never expected but it's a rare case that might happen.

all clear now!

thanks, Erel.
 
Upvote 0
Top