Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
Validating iOS iAP receipt - Gideros Forum

Validating iOS iAP receipt

NascodeNascode Guru
edited May 2013 in General questions
Hello all,

Would like to get help on step-by-step method to verify receipt on iOS iAP with Gideros StoreKit Plugin. What would we do if we want to use our server or withour server?

For validating from our own server i found this code https://github.com/chrismaddern/validate-in-app-purchase-iphone-ios-receipts .But what parameter should we send? And what if we dont want to use our own server (less secure)? Could we use UrlLoader?

I saw Apple tutorial on how to do this, would like to know if anyone have lua snippet? :)

Dislikes: vitalitymobile, octotod

have fun with our games~
http://www.nightspade.com
+1 -1 (+0 / -2 ) Share on Facebook

Comments

  • ar2rsawseenar2rsawseen Maintainer
    Without testing, just converting php code to lua, it should be something like this:
    --class
    ValidateReceipt = Core.class(EventDispatcher)
     
    function ValidateReceipt:init(receipt, sandboxed)
        sandboxed = sandboxed or true
        local url
        if sandboxed then
            url = "<a href="https://sandbox.itunes.apple.com/verifyReceipt&quot" target="_blank" rel="nofollow">https://sandbox.itunes.apple.com/verifyReceipt&quot</a>;
        else
            url = "<a href="https://buy.itunes.apple.com/verifyReceipt&quot" target="_blank" rel="nofollow">https://buy.itunes.apple.com/verifyReceipt&quot</a>;
        end
        local headers = {
            ["Content-Type"]  = "application/x-www-form-urlencoded"
        }
        local body = "receipt-data="..receipt
        local loader = UrlLoader.new(url, UrlLoader.POST, headers, body)
     
        local function onComplete(event)
             local e = Event.new(Event.COMPLETE)
             e.data = event.data
            self:dispatchEvent(e)
        end
     
        loader:addEventListener(Event.COMPLETE, onComplete)
    end
     
    --usage
    local validate = ValidateReceipt.new("YOUR-RECEIPT-HERE")
    validate:addEventListener(Event.COMPLETE, function(e)
        local data = Json.decode(e.data)
        if data.status ~= 0 then
            --invalid
        else
            --valid
        end
    end)
  • NascodeNascode Guru
    edited May 2013
    Hi @ar2rsawseen

    Thanks for you lua snippet. What should i put as parameter on "YOUR-RECEIPT-HERE"?

    This is the snippet code from a thread by @atilim
    require "storekit"
     
    local function onRequestProductsComplete(event)
        if event.errorCode ~= nil then
            print("error", event.errorCode, event.errorDescription)
            return
        end
     
        print("products:")
        for i=1,#event.products do
            print("title", event.products[i].title)
            print("description", event.products[i].description)
            print("price", event.products[i].price)
            print("productIdentifier", event.products[i].productIdentifier)
        end
     
        print("invalidProductIdentifiers:")
        for i=1,#event.invalidProductIdentifiers do
            print(event.invalidProductIdentifiers[i])
        end
    end
     
    local function onTransaction(event)
        print("payment.productIdentifier", event.payment.productIdentifier)
        print("payment.quantity", event.payment.quantity)
     
        print("transaction.state", event.transaction.state)
     
        if event.transaction.state == StoreKit.FAILED then
            print("error", event.errorCode, event.errorDescription)
        else        
            print("transaction.identifier", event.transaction.identifier)
            print("transaction.date", event.transaction.date)
     
            if event.transaction.state == StoreKit.PURCHASED then
                print("transaction.receipt", event.transaction.receipt)
            end
     
            if event.transaction.state == StoreKit.RESTORED then
                print("originalTransaction.identifier", event.originalTransaction.identifier)
                print("originalTransaction.date", event.originalTransaction.date)
            end
     
            -- unlock the functionality purchased by the user
        end
     
        storekit:finishTransaction(event.transaction)
    end
     
     
    storekit:addEventListener(Event.REQUEST_PRODUCTS_COMPLETE, onRequestProductsComplete)
    storekit:addEventListener(Event.TRANSACTION, onTransaction)
     
     
    storekit:requestProducts({
    	"com.giderosmobile.iaptest.consumable",
    	"com.giderosmobile.iaptest.nonconsumable",
    })
     
    stage:addEventListener(Event.MOUSE_DOWN, function()
    	storekit:purchase("com.giderosmobile.iaptest.consumable", 1)
    end)
    Should i put event.transaction.receipt here or based on my finding, we must base64 it first?
    have fun with our games~
    http://www.nightspade.com
  • ar2rsawseenar2rsawseen Maintainer
    Yes I think it should be a:
    event.transaction.receipt
    I just don't know what is an example of event.transaction.receipt contents? Maybe it's already encoded

    Dislikes: GamingGkRE

    +1 -1 (+0 / -1 ) Share on Facebook
Sign In or Register to comment.