Skip to content

Instantly share code, notes, and snippets.

@cjanis
Created November 28, 2012 06:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cjanis/4159348 to your computer and use it in GitHub Desktop.
Save cjanis/4159348 to your computer and use it in GitHub Desktop.
Corona SDK: IAP
-- iap results
function iapTransaction(event)
if (event.transaction.state == "purchased") or (event.transaction.state == "restored") then
if (event.transaction.productIdentifier == "playmaticBalloons") then
data.iap.iapBalloons = "yes"
iconBalloonsPrice.alpha = 0
end
writeData()
elseif (event.transaction.state == "cancelled") then
elseif (event.transaction.state == "failed") then
local alert = native.showAlert( "Error", "Sorry, your purchase seems to have failed. Please try again later. :( If this happens frequently send an email to help@fube.ca.", { "Ok" } )
else
end
store.finishTransaction(event.transaction)
end
-- initiate a purchase
function iapPurchase(product)
if (store.canMakePurchases) then
if (product == "iapBalloons") then
store.purchase({ iapProducts[1] })
else
end
else
end
end
-- initialize products
iapProducts = {
"playmaticBalloons"
}
function iapProductsLoaded(event)
end
-- initalize store
local store = require("store")
function storeInit()
store.init(iapTransaction)
store.loadProducts(iapProducts, iapProductsLoaded)
end
storeInit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment