Android Question In App Billing (Querying for Purchased Items)

Discussion in 'Android Questions' started by tucano2000, Jan 25, 2015.

  1. tucano2000

    tucano2000 Active Member Licensed User

    Is there an equivalent method to the code below into B4A using InAppBilling3 library to retrieve information about purchases made by the user from your app ?

    Code:
    Bundle ownedItems = mService.getPurchases(3, getPackageName(), "inapp"null);

    int response = ownedItems.getInt(
    "RESPONSE_CODE");
    if (response == 0) {
       ArrayList<
    String> ownedSkus =
          ownedItems.getStringArrayList(
    "INAPP_PURCHASE_ITEM_LIST");
       ArrayList<
    String>  purchaseDataList =
          ownedItems.getStringArrayList(
    "INAPP_PURCHASE_DATA_LIST");
       ArrayList<
    String>  signatureList =
          ownedItems.getStringArrayList(
    "INAPP_DATA_SIGNATURE");
       
    String continuationToken =
          ownedItems.getString(
    "INAPP_CONTINUATION_TOKEN");
      
       
    for (int i = 0; i < purchaseDataList.size(); ++i) {
          
    String purchaseData = purchaseDataList.get(i);
          
    String signature = signatureList.get(i);
          
    String sku = ownedSkus.get(i);
     
          // 
    do something with this purchase information
          // e.g. display the updated 
    list of products owned by user
       
    }

       // if continuationToken != null, call getPurchases again
       // and pass in the token to retrieve more items
    }
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    See Manager.GetOwnedProducts.
     
    Peter Simpson likes this.
  3. tucano2000

    tucano2000 Active Member Licensed User

    I used Manager.GetOwnedProducts, but this only returns Products (Purchases) if I buy something in the same session that I have opened the application.

    See what I did in my code.

    Code:
    Sub Activity_Create(FirstTime As Boolean)
        
    Activity.LoadLayout("teste")
      
    If FirstTime Then
          manager.Initialize(
    "manager", key)
          manager.DebugLogging = 
    True

      
    End If
    End Sub

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

    Sub manager_OwnedProducts (Success As Boolean, purchases As Map)
        
    Log("manager_OwnedProducts Success = " & Success)
        
    Log("purchases size = " & purchases.Size)
        
    If Success  Then
            
    For Each k As String In purchases.Keys
                 
    Log(k)
            
    Next
        
    End If
    End Sub
    The above code returns zero . It is as if I had not bought anything or signed anything. What am I doing wrong ?

    I need to check if a subscription has expired every time you open the application.

    In the documentation of google says:

     
    Last edited: Jan 26, 2015
  4. Erel

    Erel Administrator Staff Member Licensed User

    GetOwnedProducts should return all the owned products (not including consumed products). The "session" doesn't matter.
     
  5. tucano2000

    tucano2000 Active Member Licensed User

    Ok Erel, then how I can check to check if the subscription has expired using InAppBilling3 ? Is possible ? There is another method ?
     
    Last edited: Jan 26, 2015
  6. ivan.tellez

    ivan.tellez Active Member Licensed User

    GetOwnedProducts is for managed purchases, a subscription will not be listed calling GetOwnedProducts.
     
  7. tucano2000

    tucano2000 Active Member Licensed User

    How do I make managing subscriptions ?
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    GetOwnedProducts should return subscriptions as well.
     
  9. tucano2000

    tucano2000 Active Member Licensed User

    Finally I'm getting use InAppBilling3 library to retrieve information of purchased products or subscriptions. Now how do I get the Server Response Codes when the user tries to buy a product and no success ?

    _PurchaseCompleted event only returns state success true or false. I need the other server response as well:

    https://developer.android.com/google/play/billing/billing_reference.html#billing-codes

    BILLING_RESPONSE_RESULT_OK 0 Success
    BILLING_RESPONSE_RESULT_USER_CANCELED 1 User pressed back or canceled the dialog
    BILLING_RESPONSE_RESULT_SERVICE_UNAVAILABLE 2 Network connection is down
    BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE 3 Billing API version is not supported for the type requested
    BILLING_RESPONSE_RESULT_ITEM_UNAVAILABLE 4 Requested product is not available for purchase
    5 BILLING_RESPONSE_RESULT_DEVELOPER_ERROR Invalid arguments provided to the API. This error can que Also Indicate the application was not signed or enquiry.c Correctly set-up for In-app Billing in Google Play, or does not have the Necessary permissions in its manifest
    BILLING_RESPONSE_RESULT_ERROR 6 Fatal error during the API action
    BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED 7 Failure to purchase since item is already owned
    BILLING_RESPONSE_RESULT_ITEM_NOT_OWNED 8 Failure to consume since item is not owned
     
    Last edited: Mar 6, 2015
    Humberto likes this.
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