Android Question In app billing questions

Discussion in 'Android Questions' started by Sub7, Feb 22, 2015.

  1. Sub7

    Sub7 Active Member Licensed User

    Hello, i have a about in app billing.

    In my app i sell one item, this item can be purchased over and over.
    So i have followed the in app billing tutorial and setup a managed product in google developer console.

    I am using this code for testing:

    Code:
    If FirstTime Then
      manager.Initialize(
    "manager", key)
      manager.DebugLogging = 
    True
      
    End If


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



    Sub manager_OwnedProducts (Success As Boolean, purchases As Map)
      
    If Success Then
      
    For Each p As Purchase In purchases.Values
      
    Log(p.ProductId & ", Purchased? " & (p.PurchaseState = p.STATE_PURCHASED))


             
    'Consume the product > raise Product Consumed
             If purchases.ContainsKey("android.test.purchased"Then
             manager.ConsumeProduct(purchases.Get(
    "android.test.purchased"))
             
    End If

      
    Next
      
    End If
    End sub



    Sub manager_ProductConsumed (Success As Boolean, Product As Purchase)

       
    Log("product cosumed")

    End Sub

    'The PurchaseCompleted event will be raised when the operation completes.
    Sub manager_PurchaseCompleted (Success As Boolean, Product As Purchase)

    If Success = True Then
    manager.GetOwnedProducts
    Log("success")
    Else
    Log("failed")
    'What to do here? if i don't call productConsumed then the product cannot be purchased again.
    End If

    End Sub


    Sub buy

    manager.RequestPayment(
    "android.test.purchased","inapp""loadXy")

    End sub

    First off i want to ask if consumeproduct should called in both cases of success and failure, because if i don't call manager.ConsumeProduct(Product) then i get the error response that the product has been already owned.

    I am right to think this?

    Code:
    Sub manager_PurchaseCompleted (Success As Boolean, Product As Purchase)

    if success True Then
    'Payment success give the item
    Else
    'Payment failed > error message
    End if

    End sub

    I get a bunch of errors even in google popup (0,99 fake visa) say the payment is okay, here the log:


    Code:
    Starting async operation: launchPurchaseFlow
    Constructing buy 
    intent for android.test.purchased, item type: inapp
    requestCode = 
    4
    ** 
    Activity (preview_grave) Pause, UserClosed = false **
    sending message 
    to waiting queue (OnActivityResult)
    running waiting messages (
    1)
    Arrived: 
    44
    Ending async operation: launchPurchaseFlow
    Successful resultcode from 
    purchase activity.
    Purchase data: {"packageName":"com.billtest.xxx","orderId":"transactionId.android.test.purchased","productId":"android.test.purchased","developerPayload":"loadXy","purchaseTime":0,"purchaseState":0,"purchaseToken":"inapp:com.billtest.xxx:android.test.purchased"}
    Data signature:
    Extras: Bundle[{INAPP_PURCHASE_DATA={"packageName":"com.billtest.xxx","orderId":"transactionId.android.test.purchased","productId":"android.test.purchased","developerPayload":"loadXy","purchaseTime":0,"purchaseState":0,"purchaseToken":"inapp:com.billtest.xxx:android.test.purchased"}, INAPP_DATA_SIGNATURE=, RESPONSE_CODE=0}]
    Expected item type: inapp
    Purchase signature verification FAILED for sku android.test.purchased
    Signature verification failed for Product ID android.test.purchased (response: -1003:Purchase signature verification failed)
    failed
    Starting async operation: refresh inventory
    Querying owned items, item type: inapp
    Package name: com.billtest.xxx
    ** Activity (preview_grave) Resume **
    Calling getPurchases with continuation token: null
    Owned items response: 0
    Purchase signature verification **FAILED**. Not adding item.
      Purchase data: {"packageName":"com.billtest.xxx","orderId":"transactionId.android.test.purchased","productId":"android.test.purchased","developerPayload":"loadXy","purchaseTime":0,"purchaseState":0,"purchaseToken":"inapp:com.billtest.xxx:android.test.purchased"}
      Signature:
    Consuming sku: android.test.purchased, token: inapp:com.billtest.xxx:android.test.purchased
    Successfully consumed sku: android.test.purchased
    Continuation token: null
    Ending async operation: refresh inventory
    I am not really familiar with all this, thanks.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    It is better in this case to consume the product in PurchaseCompleted event. This way you won't need to call GetOwnedProducts at all.

    Is the PurchaseCompleted event raised with Success = True ?
     
    luke2012 likes this.
  3. Sub7

    Sub7 Active Member Licensed User

    Should be that way no? payment success = True, fail or cancel False:

    I am right to think that PurchaseCompleted is raised whent the operation is complete and the payment successful?
    or it is raised in both cases? user cancel for example?

    The order is consumed by calling manager.ConsumeProduct(Product) which will raise the event ProductConsumed.

    But product consume must be called in both cases??

    Additionally i need to access the Purchase data: {} json array as i need to store on a db the order_id and the purchaseToken,
    i did not test this code jet:

    Code:
    Dim r As Reflector
    r.Target = Product 
    Dim orderID As String = r.GetField("order_id")
    r.Target = Product 
    Dim tokenP As String = r.GetField("purchaseToken")

    Thanks for your time
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    You must handle PurchaseCompleted event. It is raised after you call RequestPayment. Lets solve the issues one by one.
     
  5. Sub7

    Sub7 Active Member Licensed User

    Ok so the PurchaseCompleted event will return true if success and false if no.

    My question is do i have to consume the product in both cases?
    with product id: android.test.purchased if you dont call cosumeproduct you wont be able to buy again, however i tried with a real account and consumproduct is needed only if the payment has been made, you know something about this?
    I think that android.test.purchased is bugged, or i am bugged (most probably)

    Thanks for your time
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    No. Only if the purchase was completed successfully.
     
  7. Sub7

    Sub7 Active Member Licensed User

    Ok thanks, by using android.test.purchased you need do consume the managed product in both cases or wont be able to buy.
     
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