IAP Purchase Validation issue android

I’m using Unity + LUA

https://heroiclabs.com/docs/in-app-purchase-validation/#google
For Android IAP validation i followed above documentation and done all parts except the last one
i.e
Following Part:
**
Lastly, you’ll need to update Nakama’s configuration with the following information:

purchase.google.package_name: Package name for your Android app, as you’ve listed in Google Play.

purchase.google.service_key_file: Path of the JSON file you download in previous steps. This file contains authentication information that allows Nakama to communicate with Google Play on your behalf. Make sure that the file is kept safe and is only accessible by Nakama and other authorized parties.


I am confused where and how to put these flags into Nakama’s configuration

If i didn’t put those flags I am getting following error:

“Runtime RPC function caused an error”,“id”:“iap.google_verify_payment”,“error”:“data/modules/Iap_verifier_rpc.lua:100: bad argument #1 to base64_decode (string expected, got nil)\nstack traceback:\n\t[G]: in function ‘base64_decode’\n\tdata/modules/Iap_verifier_rpc.lua:100: in main chunk\n\t[G]: ?”,“stacktrace”:“github.com/heroiclabs/nakama/v2/server.(*RuntimeProviderLua).Rpc\n\tgithub.com/heroiclabs/nakama/v2/server/runtime_lua.go:1073\ngithub.com/heroiclabs/nakama/v2/server.NewRuntimeProviderLua.func3.1\n\tgithub.com/heroiclabs/nakama/v2/server/runtime_lua.go:179\ngithub.com/heroiclabs/nakama/v2/server.(*ApiServer).RpcFuncHttp\n\tgithub.com/heroiclabs/nakama/v2/server/api_rpc.go:160\nnet/http.HandlerFunc.ServeHTTP\n\tnet/http/server.go:2012\ngithub.com/gorilla/mux.(*Router).ServeHTTP\n\tgithub.com/gorilla/mux@v1.7.4/mux.go:210\ngo.opencensus.io/plugin/ochttp.(*Handler).ServeHTTP\n\tgo.opencensus.io@v0.22.3/plugin/ochttp/server.go:92\ngithub.com/heroiclabs/nakama/v2/server.decompressHandler.func1\n\tgithub.com/heroiclabs/nakama/v2/server/api.go:463\nnet/http.HandlerFunc.ServeHTTP\n\tnet/http/server.go:2012\ngithub.com/gorilla/handlers.CompressHandlerLevel.func1\n\tgithub.com/gorilla/handlers@v1.4.2/compress.go:148\nnet/http.HandlerFunc.ServeHTTP\n\tnet/http/server.go:2012\ngithub.com/heroiclabs/nakama/v2/server.StartApiServer.func5\n\tgithub.com/heroiclabs/nakama/v2/server/api.go:216\nnet/http.HandlerFunc.ServeHTTP\n\tnet/http/server.go:2012\ngithub.com/heroiclabs/nakama/v2/server.StartApiServer.func6\n\tgithub.com/heroiclabs/nakama/v2/server/api.go:227\nnet/http.HandlerFunc.ServeHTTP\n\tnet/http/server.go:2012\ngithub.com/gorilla/mux.(*Router).ServeHTTP\n\tgithub.com/gorilla/mux@v1.7.4/mux.go:210\ngithub.com/gorilla/handlers.(*cors).ServeHTTP\n\tgithub.com/gorilla/handlers@v1.4.2/cors.go:54\nnet/http.serverHandler.ServeHTTP\n\tnet/http/server.go:2807\nnet/http.(*conn).serve\n\tnet/http/server.go:1895”}

1 Like

Part of the documentation that you’ve linked to is outdated and will be updated shortly.

The following is relevant to Nakama 3.0.0 or older, and will be changed in the newer versions with dedicated IAP APIs.

The best way to validate purchases against iOS and Android is importing the following two Lua files:

Once you have imported these files into your local Nakama installation, you’ll need to download the JSON file that contains your Google Service Account. Convert the content of the entire file into a Base64 String:

base64 serviceaccount.json

and store the output as part of the Runtime Env in the Nakama configuration like this:

...
runtime:
  env:
    - "iap_google_service_account=<base64 service account>"
    - "iap_apple_password=<apple password>"

Once Nakama has started with the above configuration, you have the following two RPCs to validate against iOS and Android:

var payload = "{\"receipt\": \"base64_receipt\"}";
var rpcid = "iap.apple_verify_payment";
var response = await client.RpcAsync(session, rpcid, payload);
System.Console.WriteLine("Retrieved response: {0}", response);

More info here: nakama/iap_verifier_rpc.lua at master · heroiclabs/nakama · GitHub

var payload = "{\"product_id\": \"example_product\", \"package_name\": \"com.example.product\", \"purchase_token\": \"token\", \"is_subscription\": \"false\"}";
var rpcid = "iap.google_verify_payment";
var response = await client.RpcAsync(session, rpcid, payload);
System.Console.WriteLine("Retrieved response: {0}", response);

More info here: nakama/iap_verifier_rpc.lua at master · heroiclabs/nakama · GitHub

2 Likes

Thank you for response , will check

@mofirouz
I done config.yml file set up like below

runtime:
env:
- “iap_google_service_account:ewogICJ0eXBlIjogInNlcnZpY2VfYWNjb3VudCIs…”

With Entire base64string

but while requesting data in Iap_verifier_rpc.lua file i am getting nil

print(context.env[“iap_google_service_account”]) // Even this line also returning nil
local service_account = nk.json_decode(nk.base64_decode(context.env[“iap_google_service_account”]))

From logger:
{“level”:“error”,“ts”:“2021-02-01T13:12:49.945Z”,“msg”:“Runtime RPC function caused an error”,“id”:“iap.google_verify_payment”,“error”:"data/modules/Iap_verifier_rpc.lua:113: bad argument #1 to base64_decode (string expected, got nil)\nstack traceback

Can you check this once.

Thank you

Apologies, there was a typo in my original answer (I’ve updated it already). Please update your config so it looks like this:

- “iap_google_service_account=ewogICJ0eXBlIjogInNlcnZpY2VfYWNjb3VudCIs…”
1 Like

Thank you so much its working fine… :+1: