Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

IAP Badger: a unified approach to in-app purchases
Started by happymongoose Sep 13 2015 09:59 AM

347 replies to this topic
release lua plugin iap in app purchases monetization inventory
[TOPIC CONTROLS]
Page 1 of 14 1 2 3 »
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

happymongoose

[GLOBAL: userInfoPane.html]
happymongoose
  • Contributor

  • 302 posts
  • Corona SDK

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.
 
 
Simon



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 22,041 posts
  • Corona Staff

This looks really cool....

 

Rob



[TOPIC: post.html]
#3

happymongoose

[GLOBAL: userInfoPane.html]
happymongoose
  • Contributor

  • 302 posts
  • Corona SDK

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.



[TOPIC: post.html]
#4

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 4,842 posts
  • Corona SDK

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



[TOPIC: post.html]
#5

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 22,041 posts
  • Corona Staff

Have you considered making this into a plugin?

 

https://coronalabs.com/blog/2015/06/23/tutorial-building-a-pure-lua-plugin-for-corona/

 

Rob



[TOPIC: post.html]
#6

happymongoose

[GLOBAL: userInfoPane.html]
happymongoose
  • Contributor

  • 302 posts
  • Corona SDK

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

 

 

Simon



[TOPIC: post.html]
#7

happymongoose

[GLOBAL: userInfoPane.html]
happymongoose
  • Contributor

  • 302 posts
  • Corona SDK

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.

 

 

Simon



[TOPIC: post.html]
#8

graham07

[GLOBAL: userInfoPane.html]
graham07
  • Contributor

  • 202 posts
  • Corona SDK

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 :)

 

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



[TOPIC: post.html]
#9

happymongoose

[GLOBAL: userInfoPane.html]
happymongoose
  • Contributor

  • 302 posts
  • Corona SDK

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.   :)



[TOPIC: post.html]
#10

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 4,842 posts
  • Corona SDK

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.



[TOPIC: post.html]
#11

happymongoose

[GLOBAL: userInfoPane.html]
happymongoose
  • Contributor

  • 302 posts
  • Corona SDK

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  :)



[TOPIC: post.html]
#12

ciabucagames

[GLOBAL: userInfoPane.html]
ciabucagames
  • Observer

  • 27 posts
  • Corona SDK

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



[TOPIC: post.html]
#13

happymongoose

[GLOBAL: userInfoPane.html]
happymongoose
  • Contributor

  • 302 posts
  • Corona SDK

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.

[TOPIC: post.html]
#14

ciabucagames

[GLOBAL: userInfoPane.html]
ciabucagames
  • Observer

  • 27 posts
  • Corona SDK

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!



[TOPIC: post.html]
#15

happymongoose

[GLOBAL: userInfoPane.html]
happymongoose
  • Contributor

  • 302 posts
  • Corona SDK

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.

 

 

Simon.



[TOPIC: post.html]
#16

ciabucagames

[GLOBAL: userInfoPane.html]
ciabucagames
  • Observer

  • 27 posts
  • Corona SDK

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!



[TOPIC: post.html]
#17

happymongoose

[GLOBAL: userInfoPane.html]
happymongoose
  • Contributor

  • 302 posts
  • Corona SDK

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?



[TOPIC: post.html]
#18

ciabucagames

[GLOBAL: userInfoPane.html]
ciabucagames
  • Observer

  • 27 posts
  • Corona SDK

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
        print("yo")
 
iap.saveInventory()
        --Tell the user the ads have been removed
        native.showAlert("Purchase complete", "The test has been unlocked!", {"Okay"})
    end
 
end
 
my print statement is never executed. Am i not doing that correctly?


[TOPIC: post.html]
#19

ciabucagames

[GLOBAL: userInfoPane.html]
ciabucagames
  • Observer

  • 27 posts
  • Corona SDK

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



[TOPIC: post.html]
#20

ciabucagames

[GLOBAL: userInfoPane.html]
ciabucagames
  • Observer

  • 27 posts
  • Corona SDK

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?



[TOPIC: post.html]
#21

happymongoose

[GLOBAL: userInfoPane.html]
happymongoose
  • Contributor

  • 302 posts
  • Corona SDK

Hi again,

 

Try adding the following line at the start of your purchase listener:

local function purchaseListener(product, transaction)

   -- Before doing anything else, check what product is being passed to the listener function
  print ("Product purchased was: " .. product)


    --Check the product name...
    if (product=="test") then
       -- Then the rest of your code as before


This will tell you the product name of the item being purchased when the listener is called from IAP Badger - this should be the same as the key for the product in your catalogue.

 

If you want to use the debug testing mode on your device, remember to set debugMode to true when you initialise IAP Badger - you do this when you call iap.init() (check here for more info).  When in testing mode, the module won't connect to an app store, but present you with dialogs and fake callbacks so you can debug your code.



[TOPIC: post.html]
#22

ciabucagames

[GLOBAL: userInfoPane.html]
ciabucagames
  • Observer

  • 27 posts
  • Corona SDK

I figured out the product thing, I wasn't using he correct variable for my productNames Lol. But I'm still having the issue with the appstore. I'm not in debug mode and whenever I use the method 'IAP.purchase()' on my device, nothing happens. What's strange is I tried setting it up with a button and when u click the button a sound is supposed to play. In this case, it plays twice. I'm not sure if that helps in any way. :/

[TOPIC: post.html]
#23

happymongoose

[GLOBAL: userInfoPane.html]
happymongoose
  • Contributor

  • 302 posts
  • Corona SDK

Have you set up all your products ready in the Google Play console?

 

This will involve:

  • uploading and publishing an alpha APK to the Google Play console
  • registering your IAP products into the Google Play console and releasing / publishing them
  • registering a Google account with which to test your IAP products (you can't use a developer account for this)
  • logging into Google Play via your test account before running and testing your app.

The process behind setting up IAP on any of the real app store consoles is a bit longwinded / convoluted / painful - that's why IAP Badger has a debug mode, so you can get your app up and running before having to dig into the above...  However, if you app does work with IAP Badger in debug mode, then you'll know that any problems you have are more likely to be with how your products on set up on an app store console rather than with your own Corona code.

 

Hope that makes sense (!?)



[TOPIC: post.html]
#24

ciabucagames

[GLOBAL: userInfoPane.html]
ciabucagames
  • Observer

  • 27 posts
  • Corona SDK

alright, yes that makes perfect sense. Soooo I guess ive been going about this all wrong lol. I never tested in debug mode for my device to see if the dialogs are showing up, and lo and behold, they are not showing up. I figured maybe it was because of my specific setup in my project, so I used the sample project from your above post, and the alerts dont show either. any suggestions? thanks for all the help! :|



[TOPIC: post.html]
#25

happymongoose

[GLOBAL: userInfoPane.html]
happymongoose
  • Contributor

  • 302 posts
  • Corona SDK

So - just to clarify:

  • on the simulator, you get messages / dialog boxes and your purchase listener is being called
  • on a real device, when you run in debug mode, you don't see anything at all.

Is that correct?

 

Plus - are you including the Google IAP plug-in inside your build.settings file, and enabling the BILLING permission (see here)?  




[topic_controls]
Page 1 of 14 1 2 3 »
 
[/topic_controls]

Also tagged with one or more of these keywords: release, lua plugin, iap, in app purchases, monetization, inventory