I just post the code I use here (IOS only). Remember to store your receipt somewhere safe - I use AES coding and store it in a file on the device. Its not 100% hacker proof, but at least they can´t read my stored data.
Here is the code snippet that I use to check for premium subscriptions (cut-n-paste):
function validateListner(event) --json-decoded itunes Response storeResponse=json.decode(event.response) print("Validation status:"..storeResponse.status) --print("Restore table:"..table\_print (storeResponse)) -- Must go through receipt records to find important values: local idex=0 for key, value in pairs (storeResponse) do idex=idex+1 if type (value) == "table" then --print(idex..". "..key.." is a table") if key=="receipt" then -- Third record is usually the receipt table (but no certainity of that): local idex2=0 for key, value in pairs (value) do idex2=idex2+1 if key=="purchase\_date" then --scoreitems[6]=makeTimeStamp(lastchecktime) RestorePurchaseDate=string.sub(value,1,19) end if key=="expires\_date\_formatted" then RestoreExpiresDate=string.sub(value,1,19) end if key=="product\_id" then RestoreProductID=string.sub(value,1) end if key=="quantity" then RestoreQuantity=tonumber(value) end end end -- elseif "number" == type(key) then -- print(idex..". "..key.."="..tostring(value)) -- else -- print(idex..". "..key.."="..value) end end print("purchasedate:"..RestorePurchaseDate) print("expiresdate:"..RestoreExpiresDate) print("quantity:"..RestoreQuantity) print("id:"..RestoreProductID) if RestoreProductID=="com.yourcompany.yourgame.yoursubscription" then -- receipt for current subscription obtained. Check further: if RestoreQuantity\>0 and tonumber(storeResponse.status)==0 then -- more than zero products purchased and valid, so keep premium on: premiumon=true print("premium on!") premiumchk=premiumchk+1 else print("subscription not active..") premiumoff=premiumoff+1 -- May be active in another record.. end end end -- for testing: --premiumreceipt=fromhex(\*\*\*\*\*) \<-- Put a real reciept here to test (paste it from console during sandbox testing) if premiumreceipt~=nil then --if premiumreceipt~=nil then premium has been purchased so -- Check subscription (if still within subscription period) validate.start { receipt = premiumreceipt, password = \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*, -- Your store secret here listener = validateListner, testing = testingproduct, --Should be true if you use sandbox receipt, false if you use actual receipt } validtimer=timer.performWithDelay(5000, function() if premiumoff2==premiumoff then if premiumchk\>0 then premiumon=true timer.cancel(validtimer) elseif premiumoff\>0 then print("premiumon switched off by premium receipt check") premiumon=false timer.cancel(validtimer) end else premiumoff2=premiumoff end end,10) end
The code will go through all the responses from the store; E.g. even if you supply only the last recipe, iTunes store will respond with multiple transactions (if the user made several). In sandbox mode during testing it can easily become 50+. Change test account if you want to get clear of all those old transactions.
For subscriptions you want to check the purchase date and expiration date. Add the days for all those transactions and check with current date (Use first purchase date from all the valid ones to see how many days have passed with an subscription).
Hope it helps you!