I did use Apple plugins and refer to this sample:
, but strangely event.transaction is not activated after click the purchase button( showMessage(productID…“buying…please wait”)).
here is the code:
store = require "plugin.apple.iap"
popMessage=function(itemNo)
local dialogText
if(itemNo==1) then
dialogText="Spend NT$30,buy 300 golds?"
elseif(itemNo==2) then
dialogText="Spend NT$150,buy 1725golds?"
elseif(itemNo==3) then
dialogText="Spend NT$990,buy 12150golds?"
end
local productIDs = {
"com.long88long.30golds",
"com.long88long.150golds",
"com.long88long.990golds",
}
local prodList = {
"com.long88long.30golds",
"com.long88long.150golds",
"com.long88long.990golds",
}
native.showAlert(
"buy golds ",
dialogText,
{ "OK", "Cancel" },
function(event)
-- listener callback
if event.action == "clicked" then
local index = event.index
if index == 1 then
if soundOn then
local buttonSound=audio.play(soundTable["buttonSound"])
end
print("buy")
if itemNo == 1 then
--store.purchase( "com.long88long.30golds" )
--buyItem()
purchaseProduct(productIDs[1])
elseif itemNo == 2 then
--store.purchase( "com.long88long.150golds" )
purchaseProduct(productIDs[2])
elseif itemNo == 3 then
--store.purchase( "com.long88long.990golds" )
purchaseProduct(productIDs[3])
end
elseif index == 2 then
if soundOn then
local cancelSound=audio.play(soundTable["cancelSound"])
end
print("cancel")
end
end
end
)
end
purchaseProduct = function(productID)
--local function purchaseProduct(productID)
if store.isActive then
showMessage(productID.."buying..please wait")
store.purchase({ productID })
else
showMessage("❌ store not activated")
end
end
store.init( "apple", function(event)
local t = event.transaction
showMessage("store.init")
if t then
showMessage("t.state")
if t.state == "restored" or t.state == "purchased" then
local verified = verifyPurchase(t.originalIdentifier or t.identifier)
print("Verified purchase", verified)
native.showAlert("Purchase Verified", tostring(verified), {"OK"})
-- purchase sucessfully
local productID = transaction.productIdentifier
local diamonds = productDiamonds[productID]
--currentGold = currentGold + diamonds
giveGameDiamond(diamonds)
--playerDiamonds = playerDiamonds + diamonds
showMessage("✅ Purchase Verified!get " .. diamonds .. " golds!")
end
end
store.finishTransaction( t )
--native.setActivityIndicator( false )
end)
verifyPurchase = function(originalIdentifier)
print("Verifying", originalIdentifier)
showMessage("verifyPurchase")
local iaps = store.receiptDecrypted().in_app
for i=1,#iaps do
local iap = iaps[i]
if iap.original_transaction_id == originalIdentifier then
return true
end
end
return false
end
I don’t know what went wrong.
Is there any sample code and guide to setup the apple store connect sandbox?
Thanks!