I’m not really sure where to do that. This is the code for the buttons. This is pretty much taken from the sample code.
unction addProductFields() -- Utility function to build a buy button. function newBuyButton (index) -- Handler for buy button local buttonDefault = "buttonBuy.png" local buttonOver = "buttonBuyDown.png" local buyThis = function ( 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("Purchasing.. " .. tostring(productId)) store.purchase( {productId} ) end end function buyThis\_closure ( index ) -- Closure wrapper for buyThis() to remember which button return function ( event ) buyThis(validProducts[index].productIdentifier) return true end end local hideDescription = function ( ) descriptionArea.text = "Select a product..." end local describeThis = function ( description ) -- Display product description for testing print ("About this product: " ..description) -- TODO wrap if necessary descriptionArea.text = description timer.performWithDelay( 2000, hideDescription) end function describeThis\_closure ( index ) -- Closure wrapper for describeThis() to remember which button return function ( event ) describeThis (validProducts[index].description) return true end end local label = validProducts[index].title if validProducts[index].price then -- Product price is known. In this case, display the price in the button. label = label .. " " string.format("%.2f", validProducts[index].price) else -- Product price is not known. In this case we expect a localized price to be -- displayed via the in-app purchase system's own UI. end local myButton = widget.newButton { defaultFile = buttonDefault, overFile = buttonOver, label = "", labelColor = { default = { 2/255, 0, 127/255 }, over = { 2/255, 0, 127/255 } }, font = "Marker Felt", fontSize = 14, emboss = false, onPress = describeThis\_closure (index), onRelease = buyThis\_closure (index), } -- myButton:setReferencePoint(display.CenterLeftReferencePoint) myButton.anchorX = .8 -- left myButton:setLabel(label) return myButton end -- Utility to build a restore button function newRestoreButton () local buttonDefault = "buttonRestore.png" local buttonOver = "buttonRestoreDown.png" local restore = function ( product ) -- Request the store to restore all previously purchased products. if store.isActive then print ("Restoring " ) store.restore() else showStoreNotAvailableWarning() end end local hideDescription = function ( ) descriptionArea.text = "Select a product..." end local describeThis = function () -- Display info in description area print ("Restore feature") descriptionArea.text = "Restore feature" timer.performWithDelay( 2000, hideDescription) end local label = "" local myButton = widget.newButton { defaultFile = buttonDefault, overFile = buttonOver, label = "", labelColor = { default = { 2/255, 0, 127/255 }, over = { 2/255, 0, 127/255 } }, font = "Marker Felt", fontSize = 14, emboss = false, onPress = describeThis, onRelease = restore, } -- myButton:setReferencePoint(display.CenterLeftReferencePoint) myButton.anchorX = 100 -- left myButton:setLabel(label) return myButton end -- Display product purchasing options print ("Loading product list") if (not validProducts) or (#validProducts \<= 0) then -- There are no products to purchase. This indicates that in-app purchasing is not supported. local noProductsLabel = display.newText( "", display.contentWidth / 2, display.contentHeight / 3, display.contentWidth / 2, 0, native.systemFont, 16) noProductsLabel:setFillColor(0, 0, 0) noProductsLabel.anchorX = 0 noProductsLabel.anchorY = 0 showStoreNotAvailableWarning() else -- Products for purchasing have been received. Create options to purchase them below. print("Product list loaded") print("Country: " .. tostring(system.getPreference("locale", "country"))) -- Set up native text box for displaying current transaction status. descriptionArea = native.newTextBox( -1000, 0 \* display.contentHeight, display.contentCenterX, display.contentCenterY) descriptionArea.text = "Select a product..." descriptionArea:setTextColor(2/255, 0, 127/255) descriptionArea.size = 0 descriptionArea.hasBackground = false descriptionArea.anchorX = - 1 descriptionArea.anchorY = - 1 local buttonSpacing = 10 print( "Found " .. #validProducts .. " valid items ") -- display the valid products in buttons for i=1, #validProducts do -- Debug: print out product info print("Item " .. tostring(i) .. ": " .. tostring(validProducts[i].productIdentifier) .. " (" .. tostring(validProducts[i].price) .. ")") print(validProducts[i].title .. ", ".. validProducts[i].description) -- create and position product button local myButton = newBuyButton(i) myButton.x = display.contentWidth - myButton.width - buttonSpacing myButton.y = 170 - i \* buttonSpacing + (3.5 \* i - 1) \* myButton.height / 2 end -- Create and position Restore button. if store.isActive or isSimulator then local myButton = newRestoreButton() myButton.x = display.contentWidth - myButton.width - buttonSpacing - 100 myButton.y = display.contentHeight - myButton.height / .5 - buttonSpacing end -- Debug: Display invalid prodcut info loaded from the store. -- You would not normally do this in a relese build of your app. for i=1, #invalidProducts do native.showAlert( "Item " .. tostring(invalidProducts[i]) .. " is invalid.", {"OK"} ) print("Item " .. tostring(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 addProductFields() end
Thanks for your help!