Android Question Price from in-app purchase

aaronk

Well-Known Member
Licensed User
Longtime User
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
As the user hasn't yet purchased any products how does it know to return the price ?

when I run the code:

B4X:
manager.GetOwnedProducts

It does nothing.

If I then enable the Debuglogging it say:

Calling getPurchases with continuation token: null
Owned items response: 0
Continuation token: null
Querying SKU details.
queryPrices: nothing to do because there are no SKUs.
Ending async operation: refresh inventory

I think it's saying that the user hasn't yet purchased any in-app purchases. (which is correct).

Before the user makes the order, I like to get the price of the in-app purchase from Google Play and show it in my app so the user knows how much that in app purchase is going to cost before they make that purchase.

I know when you do:

B4X:
manager.RequestPayment("product_id_here")

It will display the price, but since I have multiple in app purchases the user can select, I like to display them in a list with the price showing so they can see the price from the list.

Think of it like purchasing credits for a game.
10 credits = $5
20 credit = $7
etc.

Rather than the user selecting each just to see the price, I like to have it in a list with the price showing so it's makes it easier to know which one to tap on.

Based on the link in the first post, https://developer.android.com/training/in-app-billing/list-iab-products.html
It shows how to receive this information at the bottom (Query Items Available for Purchase). Well I think it's showing what I am after.

Is there a way to get the price before the user places the order, other than that Google Play in app purchase popup asking for the payment?
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I have the following in a code module
This does not work. Code Modules can not receive events.

Use a Service (Starter Service is a good Place for it) or a Class or an Activity.
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
I have the following in a code module (Code Module Named: AppPurchase):

B4X:
'Code module
'Subs in this code module will be accessible from all modules.
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim manager As BillingManager3
    Private key As String = "MIIBIjANBg.."
    Public PurchasesSupported As Boolean
End Sub
Sub Initialize
  
    ' in-App Billing - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    manager.Initialize("manager", key)
    manager.DebugLogging = True
  
    Log("** In-App Billing Initialize **")
End Sub

Sub Manager_OwnedProducts (Success As Boolean, Purchases As Map)
    Log("** Manager_OwnedProducts triggered **")
    If Success Then
        Dim skus As JavaObject = manager
        Dim items As List = skus.GetField("SkuDetails")
        For Each sku As JavaObject In items
            Log(sku.RunMethod("getSku", Null))
            Log(sku.RunMethod("getPrice", Null))
            Log(sku.RunMethod("getTitle", Null))
            Log(sku.RunMethod("getDescription", Null))
        Next
    End If
End Sub

Sub Manager_BillingSupported (Supported As Boolean, Message As String)
    Log(Supported & ", " & Message)
    Log("Subscriptions supported: " & manager.SubscriptionsSupported)
    PurchasesSupported = Supported
End Sub

Sub manager_PurchaseCompleted (Success As Boolean, Product As Purchase)
    Log("PurchaseCompleted = " & Success)
End Sub

In the starter service I am doing:
B4X:
Sub Service_Create
    'This is the program entry point.
    'This is a good place to load resources that are not specific to a single activity.
    AppPurchase.Initialize
End Sub

On my Main Activity I have a button and when I press it I am using the following code:
B4X:
AppPurchase.manager.GetOwnedProducts

Manager_OwnedProducts never gets triggered.

Here is the log when I run the app:
(I renamed the package name below while I post it on the forum)
*** Service (starter) Create ***
** In-App Billing Initialize **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Billing service connected.
Checking for in-app billing 3 support.
In-app billing version 3 supported for my.app.name
Subscriptions AVAILABLE.
Starting async operation: refresh inventory
Querying owned items, item type: inapp
Package name: my.app.name
Calling getPurchases with continuation token: null
Owned items response: 0
Continuation token: null
Querying SKU details.
queryPrices: nothing to do because there are no SKUs.
Querying owned items, item type: subs
Package name: my.app.name
Calling getPurchases with continuation token: null
Owned items response: 0
Continuation token: null
Querying SKU details.
queryPrices: nothing to do because there are no SKUs.
Ending async operation: refresh inventory
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
This does not work. Code Modules can not receive events.

Use a Service (Starter Service is a good Place for it) or a Class or an Activity.
I just used a class and initialized it in the service module.

Got the same result.
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
The event sub should be in the same module where you call GetOwnedProducts. Put it in the main activity.
I got it to trigger that sub now.

Problem now is that it doesn't do anything.

When I run this code:

B4X:
manager.GetOwnedProducts

It now triggers Manager_OwnedProducts.

B4X:
Sub Manager_OwnedProducts (Success As Boolean, Purchases As Map)
    Log("** Manager_OwnedProducts triggered **")
    If Success Then

        Dim skus As JavaObject = manager

        Dim items As List = skus.GetField("SkuDetails")

        For Each sku As JavaObject In items

            Log("getSku = " & sku.RunMethod("getSku", Null))
            Log("getPrice = " & sku.RunMethod("getPrice", Null))
            Log("getTitle = " & sku.RunMethod("getTitle", Null))
            Log("getDescription = " & sku.RunMethod("getDescription", Null))

        Next

    End If

End Sub

In the Log it shows ** Manager_OwnedProducts triggered **

But that is all. Doesn't seem to log any of the other items in that sub.

** Activity (main) Pause, UserClosed = true **
*** Service (starter) Create ***
** In-App Billing Initialize **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Billing service connected.
Checking for in-app billing 3 support.
In-app billing version 3 supported for my.app.name
Subscriptions AVAILABLE.
true, Setup successful. (response: 0:OK)
Subscriptions supported: true
Starting async operation: refresh inventory
Querying owned items, item type: inapp
Package name: my.app.name
Calling getPurchases with continuation token: null
Owned items response: 0
Continuation token: null
Querying SKU details.
queryPrices: nothing to do because there are no SKUs.
Querying owned items, item type: subs
Package name: my.app.name
Calling getPurchases with continuation token: null
Owned items response: 0
Continuation token: null
Querying SKU details.
queryPrices: nothing to do because there are no SKUs.
Ending async operation: refresh inventory
** Manager_OwnedProducts triggered **
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
I am finding I can't make in app purchases now. Comes up saying 'The item you requested is not available for your purchase'. This has only happened since updating the lib.

I wonder if this is why Manager_OwnedProducts is returning nothing ?

Can someone use the same version lib 1.15 and do a quick test and confirm if it should be working ?

Does anyone have version 1.11 of the inAppBilling3 available that they can post? I like to check and confirm if it then works with that version or if there is another issue.
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
I can now make purchases again but it still doesn't let me request the details of the in-app purchase before the user makes the purchase.

I have my app published as a beta app (no production app uploaded yet).
When I request for the payment using:

B4X:
manager.RequestPayment("productid_is_here","inapp","aaa")

it pops up requesting for the payment (I never follow though with the payment).
So I know I have a in-app purchase available.

When I run the code:

B4X:
manager.GetOwnedProducts

it returns nothing other than:

** Activity (main) Pause, UserClosed = true **
*** Service (starter) Create ***
** In-App Billing Initialize **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Billing service connected.
Checking for in-app billing 3 support.
In-app billing version 3 supported for my.app.name
Subscriptions AVAILABLE.
true, Setup successful. (response: 0:OK)
Subscriptions supported: true
Starting async operation: refresh inventory
Querying owned items, item type: inapp
Package name: my.app.name
Calling getPurchases with continuation token: null
Owned items response: 0
Continuation token: null
Querying SKU details.
queryPrices: nothing to do because there are no SKUs.
Querying owned items, item type: subs
Package name: my.app.name
Calling getPurchases with continuation token: null
Owned items response: 0
Continuation token: null
Querying SKU details.
queryPrices: nothing to do because there are no SKUs.
Ending async operation: refresh inventory
** Manager_OwnedProducts triggered **

It triggers that OwnedProducts sub, but Success = False.

If Success = False then there is a different problem which you need to first solve.
Any ideas on where to start ?

I can confirm it allows me to purchase the item (as per the above), so I know there is a valid in-app product it should be returning, and since it allows me to purchase the item it is able to communicate to the Google Play store.

Since I haven't purchased any items yet, I guess this is why it's returning false or doesn't that matter if I have purchase a product or not ?

For testing, I now have just created a small demo project which I uploaded to Google Play as a production app to test it out.

I got the same result, where it allows the user to purchase the in-app purchase etc, but when I request GetOwnProducts it returns nothing. It seems to trigger the OwnedProducts sub but never any details about what products are available for purchase. So success is still returning False.

Either I am doing something wrong, or GetOwnProducts only returns the products the user has purchased and not what is available for purchase.

I have attached my demo project as an attached file to this post, hoping someone can see what I might of done wrong.

My In-App Purchase in Google Play looks like:
(I put a high amount for the in-app purchase so people don't follow though with the purchase while I testing it, if they do purchase it, well lucky me)

upload_2017-6-27_11-54-42.png


I have now unpublished the app as I didn't want anyone to download the app etc.
 

Attachments

  • testing_app.zip
    5.8 KB · Views: 319
Upvote 0
Top