Authentication required error

Hi, I am alpha-testing an app which contains in-app purchases and get an error from google (Authentication required).

I have seen a this is not a new problem, but what I found has not helped me :frowning:

this is my build setting:

android =
    {

        googlePlayGamesAppId=“40XXX65XX9XX”,
        – usesExpantionsFile=true

        usesPermissions =
        {
            “android.permission.INTERNET”,
            “android.permission.ACCESS_NETWORK_STATE”,
            “android.permission.RECEIVE_BOOT_COMPLETED”,
            “android.permission.WRITE_EXTERNAL_STORAGE”,
            “com.android.vending.CHECK_LICENSE”,
            “com.android.vending.BILLING”
        },
    },

and this is the code section that deals with purchases:

        local function transactionCallback( event )
         
           print(“In transactionCallback”, event.transaction.state)
           local transaction = event.transaction
           local tstate = event.transaction.state
           –
           --Google does not return a “restored” state when you call store.restore()
           --You’re only going to get “purchased” with Google. This is a work around
           --to the problem.
           –
           --The assumption here is that any real purchase should happen reasonably
           --quick while restores will have a transaction date sometime in the past.
           --5 minutes seems sufficient to separate a purchase from a restore.
           –
           if store.availableStores.google and tstate == “purchased” then
              local timeStamp = utility.makeTimeStamp(transaction.date,“ctime”)
              if timeStamp + 360 > os.time() then  – if the time stamp is older than 5 minutes, we will assume a restore.
                 print(“map this purchase to a restore”)
                 tstate = “restored”
                 print("I think tstate is ", tstate)
                 restoring = false
              end
           end
         
           if tstate == “purchased” then
              print(“Transaction succuessful!”)
              mySettings.isPaid = true
              utility.saveTable(mySettings, “settings.json”)
              native.showAlert(“Thank you!”, “Your support is greatly appreciated!”, “Okay”)
              store.finishTransaction( transaction )
           elseif  tstate == “restored” then
              print(“Transaction restored (from previous session)”)
              mySettings.isPaid = true
              utility.saveTable(mySettings, “settings.json”)
              store.finishTransaction( transaction )
           elseif tstate == “refunded” then
              print(“User requested a refund – locking app back”)
              mySettings.isPaid = false
              utility.saveTable(mySettings, “settings.json”)
                store.finishTransaction( transaction )
           elseif tstate == “revoked” then – Amazon feature
              print (“The user who has a revoked purchase is”, transaction.userId)
              --Revoke this SKU here:
              mySettings.isPaid = false
              utility.saveTable(mySettings, “settings.json”)
           elseif tstate == “cancelled” then
              print(“User cancelled transaction”)
              store.finishTransaction( transaction )
           elseif tstate == “failed” then
              print(“Transaction failed, type:”, transaction.errorType, transaction.errorString)
              store.finishTransaction( transaction )
           else
              print(“unknown event”)
              store.finishTransaction( transaction )
           end
         
           print(“done with store business for now”)
        end
         
        local function loadProductsListener( event )
           print(“In loadProductsListener”)
           local products = event.products
           for i=1, #event.products do
              print(event.products[i].title)
              print(event.products[i].description)
              print(event.products[i].localizedPrice)
              print(event.products[i].productIdentifier)
           end
           for i=1, #event.invalidProducts do
              print(event.invalidProducts[i])
           end
        end

        local function appPurchase( event )
            print(“Now in appPurchase”)
            if event.phase == “began” then
               event.target.xScale=0.95
               event.target.yScale=0.95
            elseif event.phase == “ended” then
               event.target.xScale=1
               event.target.yScale=1
               if system.getInfo(“targetAppStore”) == “amazon” then
                  store.purchase( “com.gmail.lcazzulani.xxxxx.yyyy” )
               else
                  store.purchase( “com.gmail.lcazzulani.xxxxx.yyyy” )
               end
               event.target.x=5000
               buyInProgress=false

            end
            return true
        end

        local function purchaseButtonHandler()

            local buyBtn = display.newImage(“buyButton.png”)
            buyBtn.x = W
            buyBtn.y = H
            buyInProgress=true
            buyBtn:addEventListener( “touch”, appPurchase )

        end

the app is published regularly (in alpa)

I am logged inn google with an account different from my own, which I have also enabled as a tester in the developer console.

what are the possible reasons for the error message?

many thanks

Luca

Hi Luca,

Did you add the proper “license > google > key” details to your “config.lua” file? See the third sub-section down in the documentation linked below (there are three essential steps to setting up Google IAP in your Corona app).

https://docs.coronalabs.com/plugin/google-iap-v3/index.html#project-settings

Take care,

Brent

Hi

Thanks for your answer, and sorry for my late reply

The problem was that I had not properly activated the product in the developer console

Now everything works fine with the purchase…but even if I get the message from Google “purchase successful”, the levels do not get unlocked 

I think the issue is that there is no setting.json saved in the tablet (although I see it in the sandobox).
when I look in my tablet, I check the documents directory, and there is no “settings.json” file there. Is this the problem?

I also read that transaction.state=“purchased” can create problems, but that is an old post, so not sure if the problem still persists. As store.init does not work in the simulator, how can I check if state=“purchased” actually works?

Many thanks

Luca

Normally you would put print statements in your transaction listener to see what’s going on and monitor the console log to see the messages.

If you are getting a transaction.state of “purchased” that is your signal from the server that it was successful and it’s your responsibility to write the code when you get that state to unlock the item as needed by your app.

See our IAP guide: https://docs.coronalabs.com/guide/monetization/IAP/index.html

Rob

Thanks Rob! A few questions, if I may 1 how do I see the app log? I mean not the corona simulator, but what does the app on the device. I’ve installed adb, but I have troubles with it. Adb devices returns me an empty list, even if the device is plugged in the usd and unlocked. Is there another way? 2 where on the device can I find the file settings.json? It appears to be nowhere, and I think this may be the problem: the file does not get saved 3 does IAP v3 work with corona light or do I need the enterprise version? 4 is there a way to see if transaction.state = purchased returns true in the corona simulator ? Many my thanks for any reply

Hi Luca,

Did you add the proper “license > google > key” details to your “config.lua” file? See the third sub-section down in the documentation linked below (there are three essential steps to setting up Google IAP in your Corona app).

https://docs.coronalabs.com/plugin/google-iap-v3/index.html#project-settings

Take care,

Brent

Hi

Thanks for your answer, and sorry for my late reply

The problem was that I had not properly activated the product in the developer console

Now everything works fine with the purchase…but even if I get the message from Google “purchase successful”, the levels do not get unlocked 

I think the issue is that there is no setting.json saved in the tablet (although I see it in the sandobox).
when I look in my tablet, I check the documents directory, and there is no “settings.json” file there. Is this the problem?

I also read that transaction.state=“purchased” can create problems, but that is an old post, so not sure if the problem still persists. As store.init does not work in the simulator, how can I check if state=“purchased” actually works?

Many thanks

Luca

Normally you would put print statements in your transaction listener to see what’s going on and monitor the console log to see the messages.

If you are getting a transaction.state of “purchased” that is your signal from the server that it was successful and it’s your responsibility to write the code when you get that state to unlock the item as needed by your app.

See our IAP guide: https://docs.coronalabs.com/guide/monetization/IAP/index.html

Rob

Thanks Rob! A few questions, if I may 1 how do I see the app log? I mean not the corona simulator, but what does the app on the device. I’ve installed adb, but I have troubles with it. Adb devices returns me an empty list, even if the device is plugged in the usd and unlocked. Is there another way? 2 where on the device can I find the file settings.json? It appears to be nowhere, and I think this may be the problem: the file does not get saved 3 does IAP v3 work with corona light or do I need the enterprise version? 4 is there a way to see if transaction.state = purchased returns true in the corona simulator ? Many my thanks for any reply