How can I create Amazon IAP function in the prject?

Hi there! I have developed Corona SDK project using amazon IAP function.

I think I have done all required, but IAP doesnt work.

Here is the all code and settings I hade.


in “build.settings” fine


   plugins =
    {
        – key is the name passed to Lua’s ‘require()’
        [“plugin.amazon.iap”] =
        {
            – required
            publisherId = “com.amazon”,
        },
    },    


in main.lua


local amazonProductList =
{
    “comstormyweatherlightning”,
    “comstormyweatherrainbow”,
    “comstormyweatherhotcold”,
    “comstormyweatherbonusmoves”,
    “comstormyweatherbuyall”,
}

local function storeListener( event )
    local transaction = event.transaction
    if transaction.state == “purchased” then
        print(“productIdentifier”, transaction.productIdentifier)
        print(“receipt”, transaction.receipt)
        print(“transactionIdentifier”, transaction.identifier)
        print (“The user who made the purchase was”, transaction.userId)

        --Entitle this SKU here:

        if(transaction.productIdentifier == “comstormyweatherbonusmoves”) then
            _G.MoveBonus = _G.MoveBonus + 3
        elseif(transaction.productIdentifier == “comstormyweatherlightning”) then
            _G.LightningBonus = _G.LightningBonus + 3
        elseif(transaction.productIdentifier == “comstormyweatherrainbow”) then
            _G.RainbowBonus = _G.RainbowBonus + 3
        elseif(transaction.productIdentifier == “comstormyweatherhotcold”) then
            if(HotCold) then
                _G.Therm1Bonus = _G.Therm1Bonus + 3
            else
                _G.Therm2Bonus = _G.Therm2Bonus + 3
            end    
        elseif(transaction.productIdentifier == “comstormyweatherbuyall”) then
           _G.MoveBonus = _G.MoveBonus + 3
           _G.RainbowBonus = _G.RainbowBonus + 3
           _G.LightningBonus = _G.LightningBonus + 3
           _G.Therm1Bonus = _G.Therm1Bonus + 3
           _G.Therm2Bonus = _G.Therm2Bonus + 3
        end

    elseif  transaction.state == “restored” then
        print(“productIdentifier”, transaction.productIdentifier)
        print(“receipt”, transaction.receipt)
        print(“transactionIdentifier”, transaction.identifier)
        print (“The user who made the purchase was”, transaction.userId)
        --Entitle this SKU here:

    elseif  transaction.state == “revoked” then
        print(“productIdentifier”, transaction.productIdentifier)
        print(“receipt”, transaction.receipt)
        print(“transactionIdentifier”, transaction.identifier)
        print (“The user who has a revoked purchase is”, transaction.userId)
        --Revoke this SKU here:

    elseif transaction.state == “failed” then
        print(“Transaction failed”, transaction.errorType, transaction.errorString)
        --display an error message here
    end
end

local function loadProductsListener( event )
    local products = event.products
    for i=1, #event.products do
        print(event.products[i].title)
        print(event.products[i].description)
        print(event.products[i].localizedPrice)
        print(event.products[i].productIdentifier)
    end
    for i=1, #event.invalidProducts do
        print(event.invalidProducts[i])
    end
end

store = require “store”

if system.getInfo(“targetAppStore”) == “amazon”  or system.getInfo(“environment”) == “simulator” then
            
    store = require “plugin.amazon.iap”

    store.init( storeListener )
    print("The currently logged in user is: ", store.getUserId())
    
    store.restore()
    store.loadProducts(amazonProductList, loadProductsListener)

end


purchase calling


store.purchase(“comstormyweatherbonusmoves”)

store.purchase(“comstormyweatherbuyall”)

store.purchase(“comstormyweatherlightning”)

store.purchase(“comstormyweatherrainbow”)


Please help me why it doesn not work?

where I made mistake?

PS: I add amazon app tester’s json file

amazon.sdktester.json


{
  “comstormyweatherlightning” : {
    “itemType”: “CONSUMABLE”,
    “price”: 0.99,
    “title”: “LightningBolt”,
    “description”: “Gain 3 Lightning Bolts”
  },
  “comstormyweatherrainbow” : {
    “itemType”: “CONSUMABLE”,
    “price”: 0.99,
    “title”: “Rainbow”,
    “description”: “Gain 3 Rainbow bonuses”
  },
  “comstormyweatherhotcold” : {
    “itemType”: “CONSUMABLE”,
    “price”: 0.99,
    “title”: “HotCold”,
    “description”: " Gain 3 of Hot or Cold bonuses"
  },
  “comstormyweatherbonusmoves” : {
    “itemType”: “CONSUMABLE”,
    “price”: 0.99,
    “title”: “BonusMoves”,
    “description”: “Gain 3 Bonus Moves (each adding 5 extra moves)”
  },
  “comstormyweatherbuyall” : {
    “itemType”: “CONSUMABLE”,
    “price”: 2.99,
    “title”: “BuyAll”,
    “description”: “Gain 3 additional of ALL bonuses”
  }
}
 


Hi lstar99999,

Can you expand a little bit on what you mean when you say it does not work? Are you getting an error message? Does the application just not respond?

Are you able to provide a copy of logcat when you run your application?

Can you confirm that you have the Amazon SDK Tester installed?

I installed AmazonSDK tester, but when I click transaction button, there are no availible item in it, I search on google, finded that consumable item doesnt appear in transaction, so I have changed “itemType”: “CONSUMABLE” to “itemType”: “ENTITLED”,but it’s the same result.

I think the code is correct, but the application doesnt respond at all.

I want to know if my code correct or not.

I have not getting message, just not respond

Would you please review my code concretly?

where I have mistake?

Hi lstar99999,

Are you able to provide a copy of the logcat from your device when you run your app? This forum post will help you get this if you have not done it before: http://forums.coronalabs.com/topic/16702-how-to-use-adb-logcat/

Your code looks correct, but is obviously not exactly what you have so it’s difficult to help without the log.

For example, you have some print statements in your code. What is the last print statement that you see?

What kind of device do you have? This is a shot in the dark, but try restarting your device. Sometimes the Amazon IAP SDK in your app and the Amazon SDK Tester have trouble communicating and a restart fixes this.

ok. I’ll catch logcat and send you. thank you

I cannot catch logcat.

is this code right? on Buy section


  if(transaction.productIdentifier == “comstormyweatherbonusmoves”) then
            _G.MoveBonus = _G.MoveBonus + 3
        elseif(transaction.productIdentifier == “comstormyweatherlightning”) then
            _G.LightningBonus = _G.LightningBonus + 3
        elseif(transaction.productIdentifier == “comstormyweatherrainbow”) then
            _G.RainbowBonus = _G.RainbowBonus + 3
        elseif(transaction.productIdentifier == “comstormyweatherhotcold”) then
            if(HotCold) then
                _G.Therm1Bonus = _G.Therm1Bonus + 3
            else
                _G.Therm2Bonus = _G.Therm2Bonus + 3
            end    
        elseif(transaction.productIdentifier == “comstormyweatherbuyall”) then
           _G.MoveBonus = _G.MoveBonus + 3
           _G.RainbowBonus = _G.RainbowBonus + 3
           _G.LightningBonus = _G.LightningBonus + 3
           _G.Therm1Bonus = _G.Therm1Bonus + 3
           _G.Therm2Bonus = _G.Therm2Bonus + 3
        end


Hi lstar99999,

This looks like it could be correct, but it is not your complete source code so I cannot determine for sure that the problem isn’t elsewhere.

Before the code you posted above, can you do a print() or popup() of ‘transaction.productIdentifier’ to make sure you know what value you’re getting? Are you sure your callback is being called?

Hi lstar99999,

Can you expand a little bit on what you mean when you say it does not work? Are you getting an error message? Does the application just not respond?

Are you able to provide a copy of logcat when you run your application?

Can you confirm that you have the Amazon SDK Tester installed?

I installed AmazonSDK tester, but when I click transaction button, there are no availible item in it, I search on google, finded that consumable item doesnt appear in transaction, so I have changed “itemType”: “CONSUMABLE” to “itemType”: “ENTITLED”,but it’s the same result.

I think the code is correct, but the application doesnt respond at all.

I want to know if my code correct or not.

I have not getting message, just not respond

Would you please review my code concretly?

where I have mistake?

Hi lstar99999,

Are you able to provide a copy of the logcat from your device when you run your app? This forum post will help you get this if you have not done it before: http://forums.coronalabs.com/topic/16702-how-to-use-adb-logcat/

Your code looks correct, but is obviously not exactly what you have so it’s difficult to help without the log.

For example, you have some print statements in your code. What is the last print statement that you see?

What kind of device do you have? This is a shot in the dark, but try restarting your device. Sometimes the Amazon IAP SDK in your app and the Amazon SDK Tester have trouble communicating and a restart fixes this.

ok. I’ll catch logcat and send you. thank you

I cannot catch logcat.

is this code right? on Buy section


  if(transaction.productIdentifier == “comstormyweatherbonusmoves”) then
            _G.MoveBonus = _G.MoveBonus + 3
        elseif(transaction.productIdentifier == “comstormyweatherlightning”) then
            _G.LightningBonus = _G.LightningBonus + 3
        elseif(transaction.productIdentifier == “comstormyweatherrainbow”) then
            _G.RainbowBonus = _G.RainbowBonus + 3
        elseif(transaction.productIdentifier == “comstormyweatherhotcold”) then
            if(HotCold) then
                _G.Therm1Bonus = _G.Therm1Bonus + 3
            else
                _G.Therm2Bonus = _G.Therm2Bonus + 3
            end    
        elseif(transaction.productIdentifier == “comstormyweatherbuyall”) then
           _G.MoveBonus = _G.MoveBonus + 3
           _G.RainbowBonus = _G.RainbowBonus + 3
           _G.LightningBonus = _G.LightningBonus + 3
           _G.Therm1Bonus = _G.Therm1Bonus + 3
           _G.Therm2Bonus = _G.Therm2Bonus + 3
        end


Hi lstar99999,

This looks like it could be correct, but it is not your complete source code so I cannot determine for sure that the problem isn’t elsewhere.

Before the code you posted above, can you do a print() or popup() of ‘transaction.productIdentifier’ to make sure you know what value you’re getting? Are you sure your callback is being called?