locked
Problem with Xamarin.Inappbilling - possible bug? RRS feed

  • Question

  • User134801 posted

    Hello!

    I'm working with the Xamarin.InAppBilling component, and consistently encountering an error. The problem is with the override method:

    protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) {
      // Ask the open service connection's billing handler to process this request
      _serviceConnection.BillingHandler.HandleActivityResult(requestCode, resultCode, data);
    
      // Ask the open connection's billing handler to get any purchases
      var purchases = _serviceConnection.BillingHandler.GetPurchases(ItemType.Product);mType.Product);
      foreach (var purchase in purchases) {
        FufillOrder(purchase);
      }
    }
    

    When using the reserved id:

    ReservedTestProductIDs.Purchased

    This override method works fine, both locally and in the live Beta channel of my application. The method is invoked, and the product is fulfilled.

    However with any live In-App Products, those populated by a id string:

     Products = await _serviceConnection.BillingHandler.QueryInventoryAsync(new List<string> {
              "example",
              ReservedTestProductIDs.Purchased
            }, ItemType.Product);
    

    this method is not invoked when the user completes the purchase cycle. Obviously, this is a problem, as there is then no way to fulfil the order.

    Wednesday, July 1, 2015 10:49 PM

All replies

  • User134801 posted

    Attempting to dodge the issue entirely, I added a method to OnProductPurchaseCompleted:

    _serviceConnection.BillingHandler.OnProductPurchased += UpdatePurchasedItems;
    

    With the exact same results. The UpdatePurchasedItems is called when ReservedTestProductIDs.Purchased has completed a purchase. The product is fulfilled. But with actual, live products, the method is not called.

    Thursday, July 2, 2015 4:28 PM
  • User134801 posted

    To further confuse things - in the Android Merchant Console, the orders were successfully processed, and reported as 'Delivered', so no problem there.

    However, the issue remains the same. The following code does not work for LIVE products:

     protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) {
      // Ask the open service connection's billing handler to process this request
      _serviceConnection.BillingHandler.HandleActivityResult(requestCode, resultCode, data);
    
      // Ask the open connection's billing handler to get any purchases
      var purchases = _serviceConnection.BillingHandler.GetPurchases(ItemType.Product);
      foreach (var purchase in purchases) {
        FufillOrder(purchase);
      }
    }
    

    The orders are not fulfilled, or consumed. Interestingly, I threw this on _serviceConnection.OnConnected:

    var purchases = _serviceConnection.BillingHandler.GetPurchases(ItemType.Product);
    foreach (var purchase in purchases) {
      _serviceConnection.BillingHandler.ConsumePurchase(purchase);
    }
    

    And THAT doesn't work either for live products (though, again, it does work for android.test.purchased).

    Saturday, July 4, 2015 12:15 AM
  • User143835 posted

    Did you manage to work it through?

    I have this idea that (if OnProductPurchased doesn't work): i would raise a flag (UserTriedToBuy) before showing popup with product and than after resume (i'm developing a Monogame game so the update method will start it's loop again) I would check for purchased products. It might be a work around for this issue...

    Tuesday, January 12, 2016 9:15 AM
  • User62973 posted

    Im also experiencing this issue.

    I'm able to see the prices and descriptions of my iaps, and I can also purchase them. But after getting the confirmation in my app and on my testing account email, the product purchased event is never raised and the purchases are not unlocked. I also tried closing and reopening my app to see if getpurchases would unlock the content and nothing.

    I installed my app trough the app store, and the Android.test.purchased works, but my real skus wont work for some reason.

    Any help would be appreciated.

    Tuesday, March 1, 2016 6:49 AM
  • User62973 posted

    I just tested it again in another device, on another account, with real money this time and I still cannot get the event to launch. The billing dialog pops up, processes the purchase, confirms it, and then I also get a purchase confirmation email from google but there is no way for my app to know this. Neither GetPurchases nor OnProductPurchased seems to be getting a response.

    QueryInventoryAsync is working fine since I can see the descriptions and prices that I wrote and specified in the play console.

    The application is ready for release, this is the only thing holding the whole project back.

    Tuesday, March 1, 2016 6:53 PM
  • User132171 posted

    I've got this exact same problem. Months of work and I can't release to the store because you can't actually buy things. At first I thought it was subscriptions, so I unpublished my app created another one and switched the IAPs to standard products. GetPurchases still refuses to return anything.

    Tuesday, March 1, 2016 9:41 PM
  • User62973 posted

    @JeffDalby I managed to fix it! I stored my key as a string instead of obfuscating it and now it works.

    One thing that I didn't know is that even if your key is wrong, the onconnected event will launch, and you should also be able to get your products. However, you wont be able to get get or make purchases.

    I hope this helps.

    Monday, March 7, 2016 3:45 AM
  • User167260 posted

    We are also having this problem. Our app is in the store as of this week with 3 auto-renewing subscriptions. Everything worked fine in testing and alpha, but with the store version, we are NOT notified after the user makes a subscription purchase. After about 5 minutes and restarting the app, we are finally notified from the store about the purchase. Our HandleActivityResult code looks very similar to what @WednesdayWolf showed above.

    I'm using Security.Unity on the public key. Hope I don't have to change that as implied by @JoseMiralles since everyone says it should be used.

    Has anyone else gotten past this problem?

    Friday, May 20, 2016 11:59 PM
  • User1278 posted

    Did anyone make any progress on this? I cannot seem to get OnProductPurchased to fire. I get a the screen that says Purchase Succeeded, but no event is ever fired. This happens on my real device and release build. I tried both my real product and test products. I verified that my public key is correct. I am out of ideas.

    Friday, February 17, 2017 3:15 PM
  • User305723 posted

    Hello to everybody. I think that this link can be helpful (it helped me anyway) - https://stackoverflow.com/questions/21102119/xamarin-inappbilling-onproductpurchase-onproductpurchasederror-events. See answer.

    Thursday, June 15, 2017 9:13 AM
  • User248282 posted

    Hi Guys, I managed to make it worked! Just simply put the key into a variable without white spaces. Hope it helps.

    var key = "[Your InAppBilling Key]";
    _serviceConnection = new InAppBillingServiceConnection(this, key);
    
    Friday, July 28, 2017 1:15 AM