Search code examples
cordovain-app-purchasecordova-plugins

Cordova InAppBilling can only buy once


I am using Cordova and this plugin and I'm currently testing In-App_ purchases on Google Play.

Here's the plugin url:

LINK HERE

It works great when I use:

function buy(){
    // make the purchase
   inappbilling.buy(successHandler, errorHandler,"myProduct");
}

BUT, it's only letting my buy the product once...After the first purchase if I try again I get error:

"ERROR: Error purchasing: labResult: Unable to buy item. (response 7:Error)

So, I'm now trying:

function consumePurchase(){

   inappbilling.consumePurchase(successHandler, errorHandler, "myProduct");

}

But this is giving me an error too:

"ERROR: myProduct is not owned so it cannot be consumed"

Hope can I get it so I can purchase the same product multiple times?


Solution

  • This is somewhat wild guess since can't see details about your products, but your products seem to be non-consumable. About consumable and non-consumable products, refer to here (under subtitle Non-consumable and Consumable In-app Products), where it says the following:

    Non-consumable products

    Typically, you would not implement consumption for in-app products that can only be purchased once in your application and provide a permanent benefit. Once purchased, these items will be permanently associated to the user's Google account. An example of a non-consumable in-app product is a premium upgrade or a level pack.

    Consumable products

    In contrast, you can implement consumption for items that can be made available for purchase multiple times. Typically, these items provide certain temporary effects. For example, the user's in-game character might gain life points or gain extra gold coins in their inventory. Dispensing the benefits or effects of the purchased item in your application is called provisioning the in-app product. You are responsible for controlling and tracking how in-app products are provisioned to the users.

    Reasoning

    Why it seems like your products are non-consumable currently? When you try to buy the product second time, it is giving you error code 7. This error code is

    BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED: Failure to purchase since item is already owned
    

    which only happens for non-consumable items which by definition can only be bought once.

    Whilst these non-consumable products can't be bought more than one time, they also can't be consumed as the name indicates. This leads to your second error message about not being able to consume the product.

    How to fix

    Simple: change the items you want to be consumable to be consumable instead of non-consumable. If you can't find how to do this, please let me know. All I can tell you about it (since I've never even read about In-app billing before) is that it should be done in Google Play Developer Console like specified here:

    You can specify these types of products for your In-app Billing application — managed >in-app products and subscriptions. Google Play handles and tracks ownership for in-app >products and subscriptions on your application on a per user account basis.