In app purchase : Transaction type failed error

Hello,

in my game application i am implement in app purchase functionality. when i request for Buy a product at that time “Transaction type failed” error generate.

is there any solution for this error. please help me.

Right now i am use below code for in app purchase file…

module(…, package.seeall)
local store = require(“store”) – Available in Corona build #261 or later
local validProducts, invalidProducts = {}, {}
local product = “newworld”
local purchased_flag = false

local listOfProducts =
{
“newworld” – HB
}

function buy_product()
print ("Ka-ching! Purchasing " )
– Purchase the item
native.setActivityIndicator( true )
if store.canMakePurchases then
store.purchase( {product} )
else
native.showAlert(“Store purchases are not available, please try again later”,
{ “OK” } )
native.setActivityIndicator( false )
end

end


– Process and display product information obtained from store.
– Constructs a button for each item

function unpackValidProducts()

print (“Loading product list”)
if not validProducts then
native.showAlert( “In App features not available”, “initStore() failed”, { “OK” } )
else

–native.showAlert( "total Valid product :- ",validProducts, { “OK” } )
– native.showAlert( "total Valid product :- ", "Valid product = "…#validProducts, { “OK” } )

– display the valid products in buttons
–product = validProducts[1].productIdentifier
for i=1, #validProducts do
– Debug: print out product info

print ("Item " … i … “: " … validProducts[i].productIdentifier
… " (” … validProducts[i].price … “)”)
print (validProducts[i].title … ", "… validProducts[i].description)

end

for i=1, #invalidProducts do
– Debug: display the product info
native.showAlert( “Item " … invalidProducts[i] … " is invalid.”,
{ “OK” } )
print(“Item " … invalidProducts[i] … " is invalid.”)
end

end
end

– Handler to receive product information
– This callback is set up by store.loadProducts()

function loadProductsCallback( event )
– Debug info for testing
print(“In loadProductsCallback()”)
print(“event, event.name”, event, event.name)
print(event.products)
print("#event.products", #event.products)
io.flush() – remove for production

– save for later use
validProducts = event.products
invalidProducts = event.invalidProducts
unpackValidProducts ()

end


– Handler for all store transactions
– This callback is set up by store.init()

function transactionCallback( event )
local infoString
print("transactionCallback: Received event ", event.name)
if event.transaction.state == “purchased” then
native.showAlert( “Congratulations!”, “You have unlocked all available world. Now you can play Desert and Snow world.”, { “OK” } )
end

if event.transaction.state == “restored” then
native.showAlert( “Success”, “You have restored all available world. Now you can play Desert and Snow world.”, { “OK” } )
end

–[[
– Also available for your app to use:
print(“transaction”, event.transaction)
print(“state”, event.transaction.state)
print(“errorType”, event.transaction.errorType)
print(“errorString”, event.transaction.errorString)
–]]
– print(“testing”, store.transactionStatePurchased, store.transactionErrorPaymentCancelled, store.transactionStateFailed )

if event.transaction.state == “purchased” then
–native.showAlert(“Message”, “Transaction successful!”,
– { “OK” } )
–store.finishTransaction( event.transaction )
_G.gameData.clearedWorld = “desert”
_G.gameData.clearedLevel = 0
_G.gameData.currentLevel = 6

_G.gameData.item_purchase = true
Save(_G.gameData);
infoString = “Transaction successful!”
print (infoString)
purchased_flag =true

– descriptionArea.text = infoString

elseif event.transaction.state == “restored” then
– Reminder: your app must store this information somewhere
– Here we just display some of it
infoString = “Restoring transaction:” …
"\n Original ID: " …event.transaction.originalTransactionIdentifier …
"\n Original date: "…event.transaction.originalDate
print (infoString)
– descriptionArea.text = infoString
–print(“productIdentifier”, event.transaction.productIdentifier)
–print(“receipt”, event.transaction.receipt)
–print(“transactionIdentifier”, event.transaction.transactionIdentifier)
–print(“date”, event.transaction.date)
–print(“originalReceipt”, event.transaction.originalReceipt)

_G.gameData.clearedWorld = “desert”
_G.gameData.clearedLevel = 0
_G.gameData.currentLevel = 6

_G.gameData.item_purchase = true
Save(_G.gameData);
purchased_flag =true

elseif event.transaction.state == “cancelled” then
infoString = “Transaction cancelled by user.”
print (infoString)
native.showAlert( "Message ", “”…infoString, { “OK” } )
– descriptionArea.text = infoString

elseif event.transaction.state == “failed” then
infoString = "Transaction failed, type: ",
event.transaction.errorType, event.transaction.errorString
native.showAlert( “Message”, “”…infoString, { “OK” } )
print (infoString)
– descriptionArea.text = infoString
else
infoString = “Unknown event”
print (infoString)
native.showAlert( "Message ", “”…infoString, { “OK” } )
– descriptionArea.text = infoString
end

– Tell the store we are done with the transaction.
– If you are providing downloadable content, do not call this until
– the download has completed.
store.finishTransaction( event.transaction )
native.setActivityIndicator( false )
unlock_products(event.transaction.state)

end

– Connect to store at startup
store.init (transactionCallback )
store.loadProducts( listOfProducts, loadProductsCallback )
print (“After init”)

Thank you,

Dipak Baraiya [import]uid: 56106 topic_id: 30280 reply_id: 330280[/import]