IAP Badger: a unified approach to in-app purchases

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.

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

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 (!?)

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! :expressionless:

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

Yes exactly. Thats odd right? lol

Could you post your build.settings code and which build version of Corona you’re using?

build settings file: 

– For more information on build.settings see the Corona SDK Build Guide at:

http://docs.coronalabs.com/guide/distribution/buildSettings/index.html

settings =

{

orientation =

{

– Supported values for orientation:

– portrait, portraitUpsideDown, landscapeLeft, landscapeRight

default = “portrait”,

supported = { “portrait”, }

},

excludeFiles =

{

– Include only the necessary icon files on each platform

iphone = { “Icon-*dpi.png”, },

android = { “Icon.png”, “Icon-Small-*.png”, “Icon*@2x.png”, },

},

– iOS Section

iphone =

{

plist =

{

UIStatusBarHidden = true,

UIPrerenderedIcon = true, – set to false for “shine” overlay

–UIApplicationExitsOnSuspend = true, – uncomment to quit app on suspend

CFBundleIconFiles =

{

“Icon.png”,

“Icon@2x.png”,

“Icon-60.png”,

“Icon-60@2x.png”,

“Icon-60@3x.png”,

“Icon-72.png”,

“Icon-72@2x.png”,

“Icon-76.png”,

“Icon-76@2x.png”,

“Icon-Small.png”,

“Icon-Small@2x.png”,

“Icon-Small@3x.png”,

“Icon-Small-40.png”,

“Icon-Small-40@2x.png”,

“Icon-Small-50.png”,

“Icon-Small-50@2x.png”,

},

–[[

– iOS app URL schemes:

CFBundleURLTypes =

{

{

CFBundleURLSchemes =

{

“fb862052867225723”,  – replace XXXXXXXXX with your Facebook appId

}

}

}

–]]

}

},

– Android Section

android =

{

googlePlayGamesAppId = “994096497629”, 

usesPermissions = {

“android.permission.INTERNET”,

“android.permission.ACCESS_WIFI_STATE”,

“com.android.vending.BILLING”,

      “com.android.vending.CHECK_LICENSE”,

},

},

plugins =

{

[“plugin.google.play.services”] = 

publisherId = “com.coronalabs”, 

supportedPlatforms = { android = true }

},

    [“CoronaProvider.gameNetwork.google”] = 

    {

    publisherId = “com.coronalabs”

    },

    [“plugin.toast”] = 

    {

    publisherId = “com.spiralcodestudio”

    },

    [“facebook”] = 

    {

    publisherId = “com.coronalabs”

    },

    

    [“plugin.google.play.services”] = 

    {

    publisherId = “com.coronalabs”

      },

        [“plugin.google.iap.v3”] =

        {

            – required

            publisherId = “com.coronalabs”,

            supportedPlatforms = { android = true },

        },  

},

}

corona build: 2015.2646

Do you get any system error messages in the device error log?

(If you’re not sure how to do this, you need to use the adb logcat command - for more info, look at the Device Debbuging - Android section of this page.   adb logcat can generate a ton of message text, so it may be best to call a print statement with something like “Iniitalizing now” before calling iap.init, and “Making purchase now” before your call iap.purchase, so you can find the relevant output).

Also, try commenting out lines 1439 and 1440 from the init function in the iap_badger.lua module, so it looks as below:

elseif targetStore=="google" then -- store=require("plugin.google.iap.v3") -- store.init("google", storeTransactionCallback) storeAvailable = true elseif targetStore=="amazon" then

…then run your app, making sure you initialise IAP Badger in debug mode.

If the above change works, it means that the module is trying to initialise the Google Play store before your app is ready for in app purchases in Google Play Console.  If this is the case, then I should be able to re-jig the code, so that in debug mode, no such initialisation is ever made.  (The above is only a temporary fix for running in debug mode on a device - it wouldn’t work in production).

Let me know if this helps / what errors messages you get.

for debugmode i am doing this initialization: 
 

local iapOptions = {

    --The catalogue generated above

    catalogue=catalogue,

    --The filename in which to save the inventory

    filename=“SpacecraftsInventory.txt”,

    --Salt for the hashing algorithm

    salt = “hey whats up”,

      debugMode = true,

      debugStore = “google”

}

is that okay considering were taking out those lines?

Yes - keep everything else exactly the same.  Only comment out those two lines in iap_badger.lua and see what happens.

how do i upload an image on here? lol

I think you click on My Media and add it as an attachment.

No guarantees on that one though…

alright i just uploaded them to imgur lol

so here’s the logcat error before the changes:

http://imgur.com/2YY6EQy

here it is after the changes:

http://imgur.com/Dzgp0ng

let me know if those links work for you…

so i guess there was no difference. I have no idea what I’m doing wrong lol

sorry for all the trouble man, thanks for sticking around

Can you upload your catalogue and the code your using to call iap.purchase?

Blank out any stuff that shouldn’t be shared in public (eg. identifiers for your products from Google Play or the App Store).  For example:

local catalogue = { --Information about the product on the app stores products = { --removeAds is the product identifier. removeAds = { --Hide your real product names here productNames = { apple="AAAAAAAA", google="BBBBBBB", amazon="CCCCCCC" }, --The product type productType = "non-consumable", --Any other code that's safe to share in public about your purchase and refund listeners... } }, --Then the code for your inventory items that's safe to share in public --... }
local catalogue = { products = { buyThis= { productNames = { apple ="something", google = "blrub", amazon = "derp"}, onPurchase=function() iap.setInventoryValue("iBoughtThis", true) end, onRefund=function() iap.removeFromInventory("iBoughtThis", true) end, productType = "non-consumable", } }, inventoryItems = { iBoughtThis = { productType="non-consumable" } } } iap.purchase("buyThis", purchaseListener)

ive changed up my variable names as well. hopefully this helps!

local function purchaseListener(product, transaction) --Check the product name... if (product=="buyThis") then print("yo") --Tell the user the ads have been removed native.showAlert("Purchase complete", "The thing has been unlocked!", {"Okay"}) end end

sorry forgot this

That looks perfect.

Baffled  :huh:

I’m on holiday with my family at the moment, so I don’t have access to any of my development kit.  When I get home at the weekend, I’ll download the same daily build of Corona as you’re using and hopefully I’ll be able to help you more.