How to have seperate buttons for In App Purchase?

Hi I need help I’ve been doing is In App Purchase having a separate button for when a person buy’s something. This is how I have it

[code]store = require(“store”)

local button1 = display.newRect (160, 240, 40,40)

local listOfProducts =
{
– These Product IDs must already be set up in your store
– We’ll use this list to retrieve prices etc. for each item
– Note, this simple test only has room for about 4 items, please adjust accordingly

– The iTunes store will not validate bad Product IDs
“com.quiz.minecraft”,
}

function transactionCallback( event )
local transaction = “com.quiz.minecraft”
if transaction.state == “purchased” then
print(“Transaction succuessful!”)
print(“productIdentifier”, transaction.productIdentifier)
print(“receipt”, transaction.receipt)
print(“transactionIdentifier”, transaction.identifier)
print(“date”, transaction.date)

elseif transaction.state == “restored” then
print(“Transaction restored (from previous session)”)
print(“productIdentifier”, transaction.productIdentifier)
print(“receipt”, transaction.receipt)
print(“transactionIdentifier”, transaction.identifier)
print(“date”, transaction.date)
print(“originalReceipt”, transaction.originalReceipt)
print(“originalTransactionIdentifier”, transaction.originalIdentifier)
print(“originalDate”, transaction.originalDate)

elseif transaction.state == “cancelled” then
print(“User cancelled transaction”)

elseif transaction.state == “failed” then
print(“Transaction failed, type:”, transaction.errorType, transaction.errorString)

else
print(“unknown event”)
end

– Once we are done with a transaction, call this to tell the store
– we are done with the transaction.
– If you are providing downloadable content, wait to call this until
– after the download completes.
store.finishTransaction( “com.quiz.minecraft” )
end

store.init( transactionCallback )

button1:addEventListener(“touch”, transactionCallback) [/code]

What I try to do here is when the person clicks on button1 the item is bought but when I do this I get an error. Also how would I do it for button2 for when they want to buy another item with different price. So can anyone please help me this is the last thing I need to get done for my game is very important to my game anyone help, is appreciated. [import]uid: 17058 topic_id: 22208 reply_id: 322208[/import]

Well the first thing to address is the error - what’s the error? You need to resolve it before you can do anything else. [import]uid: 52491 topic_id: 22208 reply_id: 88402[/import]

the error is this

Runtime error
/Users/sebitttas/Desktop/Test/Test 2 copy 3/main.lua:49: bad argument #1 to ‘finishTransaction’ (store.transaction expected, got string)
stack traceback:
[C]: ?
[C]: in function ‘finishTransaction’
/Users/sebitttas/Desktop/Test/Test 2 copy 3/main.lua:49: in function
?: in function <?:215>
[import]uid: 17058 topic_id: 22208 reply_id: 88403[/import]

@peach ok here is the fix

[code] store = require(“store”)

local button1 = display.newRect (160, 240, 40,40)

local listOfProducts =
{
– These Product IDs must already be set up in your store
– We’ll use this list to retrieve prices etc. for each item
– Note, this simple test only has room for about 4 items, please adjust accordingly

– The iTunes store will not validate bad Product IDs
“com.quiz.minecraft”,
}

function transactionCallback( event )
local transaction = event.transaction
if transaction.state == “purchased” then
print(“Transaction succuessful!”)
print(“productIdentifier”, transaction.productIdentifier)
print(“receipt”, transaction.receipt)
print(“transactionIdentifier”, transaction.identifier)
print(“date”, transaction.date)

elseif transaction.state == “restored” then
print(“Transaction restored (from previous session)”)
print(“productIdentifier”, transaction.productIdentifier)
print(“receipt”, transaction.receipt)
print(“transactionIdentifier”, transaction.identifier)
print(“date”, transaction.date)
print(“originalReceipt”, transaction.originalReceipt)
print(“originalTransactionIdentifier”, transaction.originalIdentifier)
print(“originalDate”, transaction.originalDate)

elseif transaction.state == “cancelled” then
print(“User cancelled transaction”)

elseif transaction.state == “failed” then
print(“Transaction failed, type:”, transaction.errorType, transaction.errorString)

else
print(“unknown event”)
end

– Once we are done with a transaction, call this to tell the store
– we are done with the transaction.
– If you are providing downloadable content, wait to call this until
– after the download completes.
store.finishTransaction( transaction )
end

store.init( transactionCallback ) [/code] [import]uid: 17058 topic_id: 22208 reply_id: 88404[/import]

Line 20 is where you’d see what button was pressed.

myVariable = 0

if button 1 pressed myVariable =1, for 2 make it =2.

Around line 20 if myVariable = 1 you know 1 was purchased, if 2, you know 2 was purchased. [import]uid: 52491 topic_id: 22208 reply_id: 88417[/import]