IAP Badger: a unified approach to in-app purchases

Could you try taking iap.loadProducts out of the if statement?  This will help eliminate whether this is a problem with iap.getInventoryValue or iap.loadProducts.

So:

        if not iap.getInventoryValue("purchase") then              iap.loadProducts(onProductsLoaded)         end

Becomes just:

        -- Comment out the conditional part of the if statement         -- if not iap.getInventoryValue("purchase") then              iap.loadProducts(onProductsLoaded)         -- end

(I know this will affect your program flow for the moment).

Simon

Hi Simon,

I did remove it from the if statement, and I get the same results.

I also added a breakpoint at the loadProducts command prior to these changes (while in the simulator), it it does look like getInventoryValue was successful.

Hi again,

I’ve uploaded some alterations to the code on Github - I’ve run a test module both on the simulator and on a device and it appears to run correctly, calling a specified listener as expected.  (It’s easier to add fixes and changes on Github than making changes to the plug-in.)

Hopefully, this will work for you now as well - let me know either way.  If it does work correctly, I’ll upgrade the plug-in version as well.  (Remember to comment out the plug-in information for IAP Badger in build.settings when testing the Github version though).

Simon :slight_smile:

PS: I have made a slight alteration to the parameters that are passed to the user listener called by loadProducts.

  • You will now get a second parameter that returns the generated loadProductsCatalogue (I figure most people will want to access this immediately).
  • On the simulator, the first parameter passed will be an empty table, instead of the raw product data passed from the server. (IAP Badger never correctly computed this table in simulator mode anyway, and although reconstructing the data from the catalogue is a pleasant programming exercise, I’m not sure how much application it has in the real world).

Yes!  The latest code on Git works!  

Thanks Simon… I appreciate your support.

–john

Cool.  I’ll update the plug-in at some point over the weekend.

I’ve updated the plug-in and the changes should appear on a server near you very soon.

Simon

PS - remember it can take over an hour for the changes to reach you.

PPS - I’ve also updated/improved the documentation and example code for loadProducts here

hello sir, want to ask again :slight_smile:

is there any example for dealing with IAP for montlhy Subscription? Thank you

Hi again,

IAP doesn’t implement subscription payments - it’s not something I’ve ever needed in my own apps.

(IAP Badger is the code I developed for my own apps and then decided to share - it was never originally designed to be a plug in.)

Simon

PS - the original code is on Github, so if anyone wants to fork the project and add subscription functionality, I’d be happy to include the update back into the main project.

Don’t forget folks.  Simon has given this to us for free on his own dime and his own time.  Additionally, you can get the code and modify it, so don’t badger (pun intended) him too much for feature updates and additions.

@Simon,

Having said the above I do want to say, “You rock!”.  I love this module/plugin (I use the gitHub version).  You sir have saved me hours of time and effort.

Peace,

Ed

:slight_smile:

Ditto, thanks Simon you’re a superstar for sharing this and your help and patience has been invaluable.

I see… hmm… do u think it is ok if I use my own server to write the subscription, but in IAP product I just use normal product (not subscription)… so after the purchase is successful, I’ll write manually in the server to add 30 days of access/VIP for the game… summary, it’ll be like prepaid product…
Btw thank you for all of your help! :smiley:

Thanks everyone  :smiley:

I’ve not really looked into this, but I know that both Apple and Google support subscription products natively through their consoles - although I don’t know whether this is supported in Corona (does anyone know the answer to this?)

Personally, I would avoid running your own server - it adds to the expense of running the app, and whilst the netcode isn’t that complicated, it means you have to program in lots of extra contingencies on the app side (for example - what happens if the user’s IAP is in date, but they don’t have access to the internet?)

It would probably be easier to add the ‘subscription’ product type to IAP Badger, if Corona supports them.  I guess a subscription would come back as a different product type, that would then have to be plumbed into IAP Badger (which wouldn’t be that hard or time consuming to implement… maybe).

More questions than answers, I’m afraid…

Simon

Hi Simon,

First off, great plugin, it has simplified a lot of things involved in IAP. Thanks for releasing it to the public. 

I have 2 questions for you:

1.) I’m working on my first game and this is the last thing I need to get out of the way. I have 4 products in the catalogue - removeAds, 50 coins, 250 coins, and 500 coins.

Here’s the problem I’m having, for the coins, the purchaseListener function is only picking up one product no matter what I choose. It’s completely ignoring the rest of them for some reason. The inventory value does get saved in the text file, but since it’s picking up the wrong one each each time, an incorrect value gets saved.

What’s causing this? And go can I go about fixing this?

2.) My app uses a database and I have data for in game powerups stored within that database. Would it break anything if I stored the coin value inside the database instead of the text file?

Hi there,

  1. It sounds like there is either an issue with re-definitions in your catalogue, or something is happening with the way you are calling iap.purchase - could you share the code for your catalogue to start with so I can see for sure?

  2. You’re free to store information about your purchases wherever and however you want - nothing will break.  Just replace IAP Badger’s inventory management functions with your own.

Simon

Here’s the code for the catalogue:

[lua]

local catalogue = {

    products = {    

        removeAds = {

            --A list of product names or identifiers specific to apple’s App Store or Google Play.

            productNames = { apple="", google=“XXXXXXX”, amazon="" },

            productType = “non-consumable”,

            onPurchase = function() iap.setInventoryValue(“unlock”, true) end,

            onRefund = function() iap.removeFromInventory(“unlock”, true) end,

        },

        500coins = {

            --A list of product names or identifiers specific to apple’s App Store or Google Play.

            productNames = { apple="", google=“XXXXXXX”, amazon="" },

            productType = “consumable”,

            onPurchase = function() iap.addToInventory(“coins”, 500) end,

            onRefund = function() iap.removeFromInventory(“coins”, 500) end,

        },

        200coins = {

            --A list of product names or identifiers specific to apple’s App Store or Google Play.

            productNames = { apple="", google=“XXXXXXX”, amazon="" },

            productType = “consumable”,

            onPurchase = function() iap.addToInventory(“coins”, 200) end,

            onRefund = function() iap.removeFromInventory(“coins”, 200) end,

        },

    

        50coins = {

            --A list of product names or identifiers specific to apple’s App Store or Google Play.

            productNames = { apple="", google=“XXXXXXX”, amazon="" },

            productType = “consumable”,

            onPurchase = function() iap.addToInventory(“coins”, 50) end,

            onRefund = function() iap.removeFromInventory(“coins”, 50) end,

        },    

    },

    --Information about how to handle the inventory item

    inventoryItems = {

        unlock = { productType=“non-consumable” },

        coins = { productType=“consumable” },

    }

}

[/lua]

I got it to work somewhat. I uncommented the line(s) [lua]onPurchase = function() iap.addToInventory(“coins”, 50) end,[/lua] and placed the [lua]iap.addToInventory(“coins”, 50)[/lua] directly within the purchaseListener. I assign the item name to a variable called purchaseChoice.

[lua]

local function purchaseListener()

    --Remove the ads

    if(purchaseChoice == “removeAds”) then 

         removeAds()

    elseif(purchaseChoice == “50coins”) then

        iap.addToInventory(“coins”, 50)

   

    elseif(purchaseChoice == “200coins”) then

        iap.addToInventory(“coins”, 200)

    elseif(purchaseChoice == “500coins”) then

        iap.addToInventory(“coins”, 500)

        

    end

    iap.saveInventory()

    native.showAlert(“Info”, “Congrats! Your purchase was successful.”, {“Okay”})

end

[/lua]

However, while this does add the correct value to inventory, I find that I can’t make consecutive purchases without the coin value getting all messed up. For instance, the first purchase is successful and everything goes accordingly. However, if I try again immediately after, the second purchase does not increment the value.

I have to exit the store scene and return to it for it to function normally.

Is this by design?

Simon,

I GOT IT TO WORK!

Device testing as successful on a test account. Thank you very much again for this plugin, it makes life a whole lot easier.

However, I believe there’s a bug where onPurchase doesn’t work quite well when specified in the catalogue. It doesn’t pick up the correct item name.

You might want to look into that.

Anyways, thanks again. With this out of the way, I just have a few small bugs to fix and things to do before launch. Hopefully I’ll finish up by the end of the month!

Hi there,

I’m glad you got it to work - and good luck with your app  :slight_smile:

Out of curiosity, in your purchaseListener function listed above, where were you defining the purchaseChoice variable?  It doesn’t look like it’s declared in the function.

Kind regards,

Simon

I declared it up top as a local.

Can someone please be kind to me to make an update so we can use subscription system for IAP without need of server/building online database :’)

It’ll help me a lot so I don’t need to have my own online database and user don’t need create another additional account…

ttttthhhhhaaaannnkkkk yyyooouuu very much  :smiley: