IAP Badger: a unified approach to in-app purchases

View and activate on the Corona Store | Documentation

Hi everyone,
I’ve just uploaded my code for a unified approach to in-app purchases in Corona on Github.
General features:

  • a unified approach to calling store and IAP whether you’re on the App Store, Google Play or Amazon
  • simplified calling and testing of IAP functions - just provide IAP Badger with a list of products and some simple callbacks for when items are purchased / restored or refunded
  • a testing mode, so your IAP functions can be tested on the simulator or a real device without having to contact an actual app store.
  • simplified product maintenance (adding/removing products from the inventory)
  • handling of loading / saving of items that have been purchased
  • products can have different names across the range of stores (so an upgrade called ‘COIN_UPGRADE’ in iTunes Connect could be called ‘coins_purchased’ in Google Play) without the need for additional code
  • different product types available (consumable or non-consumable)

Inventory / security features:

  • customise the filename used to save the contents of the inventory
  • inventory file contents can be hashed to prevent unauthorised changes (specify a ‘salt’ in the init() function).
  • a customisable ‘salt’ can be applied to the contents so no two Corona apps produce the same hash for the same inventory contents.  (Empty inventories are saved without a hash, to make it more difficult to reverse engineer the salt.)
  • product names can be refactored (renamed) in the save file to disguise their true function
  • quantities / values can also be disguised / obfuscated
  • fake items can be added to the inventory, whose values change randomly with each save, to help disguise the function of other quantities being saved at the same time.
  • IAP badger can generate a Amazon test JSON file for you, to help with testing on Amazon hardware

It’s called IAP Badger because - well, you know.
Hope this makes using IAP’s simpler for some of you - you can find the repository at https://github.com/happymongoose/iap_badger.

This looks really cool…


Thanks Rob.  Should have mentioned I’m releasing this on an MIT license, so you’re all free to use it / adapt it as you wish.  Feel especially free to fork it and improve it.

Super sweet and thanks for sharing this, especially under the MIT license.  Rock-n-Rolla.

Have you considered making this into a plugin?



I’ll have a look over the next couple of days.


Hi again,

I’ve started the process of converting IAP Badger into a plugin.  The code is simple enough to convert, but I think writing the documentation may take some time.


Good luck Simon, I’m sure many folks, experienced and not would love to see this as a plugin! Having had to dig through the IAP process, it wasn’t the most fun time I’ve had :slight_smile:

Look forward to what you may be able to come up with in the future!

The documentation is written, the module is converted and the application for the plug-in is submitted.

It is in the hands of the Corona gods now.   :slight_smile:

You totally rock!

Did you make any changes since the original release?  I’ve still got the code you released and am asking so I don’t use your docs and then find a difference in functionality.  No big deal, just trying to avoid making silly mistakes.

Note: I have used this on one project and am now integrating in a second.  Thus far, this has been much nicer than my own (private) module.

Thanks again for releasing this.

No problem - glad you’re finding it useful.

The good news is that there aren’t any changes between the version on Github and the library version.

If it helps, I’ve written much more complete documentation for IAP Badger that can be found on my website.  It contains a full API breakdown with working sample code for most functions, as well as two complete sample projects for consumables and non-consumables.  It’s all written in the standard documentation style recommended by Corona.

I’ve tested the code samples and they all definitely all work, but if anyone finds any typos / errors / thinks other areas need clarification, let me know  :slight_smile:

hi, im having trouble implementing the plugin you made. i believe I copied it correctly: 

– key is the name passed to Lua’s ‘require()’

[“plugin.iap_badger”] =
– required
publisherId = “co.uk.happymongoose”,

however the simulator keeps telling me that the plugin could not be downloaded. any suggestions? Thanks for the help! cant wait to start using this

Hi there,

The documentation is written for the plug in, which is still waiting for approval (it is with Corona now and they are looking at it). In the meantime, you’ll need to download the source code from Github (see the link at the top of this thread) and include it like you would with a regular lua file.

I’ll post a message here when/if the plug in is approved and available as part of a daily build.

Awesome! got it working! Thanks!

But i ran into a another problem lol
when i use the purchase function i get an error saying that "iap_badger.lua.974: attempt to index field ‘?’ a nil value 

im trying to do this using the simulator, i test up the debugmode mimicking google play. 

What could be the issue here? not using the correct product ID? at least i though i was using the right one…lol

Thanks in advance for the help!

When you call the purchase function, you need to give it the name of the product as specified in your product catalogue, not the identifier stored in Google Play.

If you have a look here, there’s a detailed walkthrough of how to set up your product catalogue and then make a purchase.  The purchase function in the documentation (found here) also contains bare bones sample code that sets up a product catalogue and initiates a purchase.  If you’re having problems setting things up, it might be advisable to copy and paste this code into your own project, and then amend it to fit your own needs.

Let me know if you need any more help.


alright that worked! lmao thanks again!

Im so sorry but this whole process of setting up IAP is really daunting. I ran into another issue. 

Im able to initiate a purchase, however nothing happens that i have set up in my listener. and in the terminal all it says is: “purchasing test” 

test is my sample product. Initially i thought this was because i was on the simulator and in debug mode, but i tried on the device and it didnt work either! Any suggestions? Thanks again for all the help!

If the code isn’t working on the simulator, it sounds as though there’s a problem with the way your purchase listener has been set up (maybe you’ve created a local function for the listener that is then out of scope when you call iap.purchase?)

Try copying and pasting the example code from this page into a separate, empty project (you’ll also need to include to IAP Badger module) - does this work correctly for you?

alright so that worked sorta. It says basically the same thing “purchasing remove_ads”. I guess what my problem is then is that in my code:

local function purchaseListener(product, transaction)

    --Check the product name…

    if (product==“test”) then



        --Tell the user the ads have been removed

        native.showAlert(“Purchase complete”, “The test has been unlocked!”, {“Okay”})



my print statement is never executed. Am i not doing that correctly?

plus, when i run this on a device, that dialog never comes up

ok ok, i take back everything i just said. It all works, except for the if statement inside my listener. It never fires for some reason. Also, When I build the project and run it on a device, the store never pulls up?