Hello! Faced with this problem: a test transaction in in-ann purchase done correctly, but then displays a message saying that the transaction was not completed. LogCat is shown below
07-13 17:14:14.490: I/Corona(10459): Output string ::
07-13 17:14:14.490: I/Corona(10459): transactionCallback: Received event storeTransaction
07-13 17:14:14.490: I/Corona(10459): Output string ::
07-13 17:14:14.490: I/Corona(10459): state: purchased
07-13 17:14:14.490: I/Corona(10459): Output string ::
07-13 17:14:14.490: I/Corona(10459): Transaction successful!
07-13 17:14:14.490: I/Corona(10459): Output string ::
07-13 17:14:14.490: I/Corona(10459): Remove Ads achievement unlocked!
07-13 17:14:14.490: I/Corona(10459): Output string ::
07-13 17:14:14.490: I/Corona(10459): AchievementPopup::init()
07-13 17:14:14.620: I/Corona(10459): Output string ::
07-13 17:14:14.620: I/Corona(10459): SettingsManager::Save
07-13 17:14:14.940: I/Corona(10459): Output string ::
07-13 17:14:14.940: I/Corona(10459): transactionCallback: Received event storeTransaction
07-13 17:14:14.940: I/Corona(10459): Output string ::
07-13 17:14:14.940: I/Corona(10459): state: failed
07-13 17:14:14.940: I/Corona(10459): Output string ::
07-13 17:14:14.940: I/Corona(10459): Transaction failed
07-13 17:14:14.940: I/Corona(10459): Output string ::
07-13 17:14:14.940: I/Corona(10459): errorType: invalidClient
07-13 17:14:14.940: I/Corona(10459): Output string ::
07-13 17:14:14.940: I/Corona(10459): errorString:
Source code see below
local StoreManager = {}
local store
local platform = {}
local products = nil
local callback = nil
local function showOfflineAlert()
native.showAlert( "Offline", "Please check your internet connection.", { "OK" })
end
local function showStoreNotAvailableWarning()
if system.getInfo("environment") == "simulator" then
native.showAlert( "Notice", "In-app purchases is not supported by the Corona Simulator.", { "OK" })
else
native.showAlert( "Notice", "In-app purchases is not supported on this device.", { "OK" })
end
-- Runtime:dispatchEvent({ name = "onStoreTransaction", target = { state = "failed" } })
end
local function transactionCallback( event )
local transaction = event.transaction
local state = transaction.state
-- Log transaction info.
print( "transactionCallback: Received event " .. tostring( event.name ))
print( "state: " .. tostring( state ))
if state == "purchased" then
-- print(" !!!! transactionCallback ")
print( "Transaction successful!" )
elseif state == "cancelled" then
print( "Transaction cancelled by user." )
elseif state == "failed" then
print( "Transaction failed" )
print( "errorType: " .. tostring( transaction.errorType ))
print( "errorString: " .. tostring( transaction.errorString ))
end
-- send notifications
if callback and type( callback ) == "function" then callback( transaction ) ; callback = nil end
Runtime:dispatchEvent({ name = "onStoreTransaction", target = transaction })
-- finish transaction
store.finishTransaction( transaction )
end
local function purchase( productId )
-- Check if it is possible to purchase the item, then attempt to buy it.
if store.isActive == false then
showStoreNotAvailableWarning()
elseif store.canMakePurchases == false then
native.showAlert( "Store purchases are not available, please try again later", { "OK" })
elseif productId then
print( "StoreManager:: Purchasing " .. tostring( productId ))
store.purchase({ productId })
return true
end
return false
end
local function initStore()
-- Connect to store if available.
local stores = store.availableStores or {}
if stores.apple then
store.init("apple", transactionCallback)
print("Using Apple's in-app purchase system.")
elseif stores.google then
-- \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* --
-- TODO: DELETE AFTER TESTING --
-- ?????????????????????????? --
-- \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* --
local googleTestProductList = {
{ key = "android.test.purchased" }, { key = "android.test.purchased" },
{ key = "android.test.purchased" }, { key = "android.test.purchased" },
{ key = "android.test.purchased" }, { key = "android.test.purchased" },
{ key = "android.test.purchased" },
}
products = googleTestProductList
-- \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* --
-- ?????????????????????????? --
-- TODO: DELETE AFTER TESTING --
-- \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* --
store.init("google", transactionCallback)
print("Using Google's Android In-App Billing system.")
else
print("In-app purchases is not supported on this system/device.")
end
end
--------------------------------
-- Init Store Manager
--
-- @productsTable = { { key = "com.company.game.id1", [price = 0.99,] ... }, ... }
--------------------------------
function StoreManager:init( productsTable )
if not store then store = require "store" end
-- validate products table
products = productsTable or {}
local testId = products[1]
if not testId or not testId.key then
print( "Invalid products table, empty set or product.key is missing" )
else
initStore()
end
end
function StoreManager:buyItem( itemNumber, onCallback )
local num = itemNumber or 0
local item = products[itemNumber] or {}
local itemId = item.key
if itemId then
if onCallback then callback = onCallback end
return purchase( itemId )
else
print( "StoreManager:: Can't find products[" .. itemNumber .. "] identifier" )
end
return false
end
return StoreManager
buyItem called once, byt I do not understand why “transactionCallback: Received event storeTransaction” executed 2 times [import]uid: 158466 topic_id: 28673 reply_id: 328673[/import]