Hi TheBusey,
There is the project I did dedicated especially for the beginners in Corona SDK called “OOP Samples for Corona SDK”. I wrote about that at this forum
in “New a New Apps / Works in Progress” section here
https://forums.coronalabs.com/topic/68516-new-free-edu-app-oop-samples-for-corona-sdk/
This is app inspired by original Corona SDK samples, rewritten as object oriented programming code.
What you are looking for you can find on my GIT https://github.com/sebastianlis/OOP-Samples-for-Corona-SDK exactly here:
classes/samples/Monetization folder of this project in GitHub:
https://github.com/sebastianlis/OOP-Samples-for-Corona-SDK/blob/master/classes/samples/Monetization/InAppPurchase.lua
These 141 lines of code show you a simple in app-purchase action, when you can buy the three types of coffee - small, strong or for all night.
For example in line 84 purchased item productID is checked and the final code is executed in anonymous function with some delay.
timer.performWithDelay(1000, function() store.consumePurchase( “com.yourcompany.coffeesmall”, private.transactionCallback) end )
If you have a consumable product the last thing to do is :
store.consumePurchase( “com.yourcompany.coffeesmall”, private.transactionCallback)
If it’s not a consumable you don’t need to do that.
Now the most important part from the user perspective.
The user wants to see the result of his purchase for e.g. number of the coins, new weapon enabled, noAds, more lives, weapon upgrades …
So the final code in line 84 with this user issue should looks like this:
timer.performWithDelay(1000,
function()
store.consumePurchase( “com.yourcompany.coffeesmall”, private.transactionCallback)
ShopManager.addFiveCoins()
end )
or
timer.performWithDelay(1000,
function()
store.consumePurchase( “com.yourcompany.coffeesmall”, private.transactionCallback)
ShopManager.enableSuperLaserWeapon()
end )
or
timer.performWithDelay(1000,
function()
store.consumePurchase( “com.yourcompany.coffeesmall”, private.transactionCallback)
ShopManager.noAds()
end )
or
timer.performWithDelay(1000,
function()
store.consumePurchase( “com.yourcompany.coffeesmall”, private.transactionCallback)
ShopManager.upgradeLaserWeapon(25)
end )
Where ShopManager is a singleton object. If you don’t like this way you can just put a simple function:
addFiveCoins()
enableSuperLaserWeapon()
noAds()
upgradeLaserWeapon(25)
called from the same file.
By the way. Normally timer.performWithDelay(1000 ……… ) would not be needed.
It’s a hack taken from the forum (I think Rob mentioned that).
No delay caused problem with the transaction. To be specific as I remember the window for a purchase action didn’t appear. Using this hack there is no problem.
——————————— Quotation ————————————
While there is a guide on how to implement IAP:
https://docs.coronalabs.com/guide/monetization/IAP/index.html
There is no guide in making an actual in game shop.
I have looked into the forums and there is no clear way of doing it.
I think there should be a small tutorial in making an in-game shop system.
It would help a lot of new/basic coders like me and countless others.
—————————————————————————————
I’ve struggled with that before. This is the main reason why I created OOP Samples. Hope it will help you.
Take care
Sebastian