# IAP Purchase Validation issue android

**URL:** <https://forum.heroiclabs.com/t/iap-purchase-validation-issue-android/1330>\
**Category:** Game Design\
**Created:** [January 28, 2021, 8:55am UTC](https://forum.heroiclabs.com/t/iap-purchase-validation-issue-android/1330 "2021-01-28T08:55:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raja\_Nukala](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/raja_nukala/32/233_2.png) [@Raja\_Nukala](https://forum.heroiclabs.com/u/Raja_Nukala)\
**Post date:** [January 28, 2021, 8:55am UTC](https://forum.heroiclabs.com/t/iap-purchase-validation-issue-android/1330/1 "2021-01-28T08:55:18Z")

</div>

I’m using Unity + LUA

[https://heroiclabs.com/docs/in-app-purchase-validation/#google](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](http://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](http://tgithub.com/heroiclabs/nakama/v2/server/runtime_lua.go:1073%5Cngithub.com/heroiclabs/nakama/v2/server.NewRuntimeProviderLua.func3.1%5Cn%5Ctgithub.com/heroiclabs/nakama/v2/server/runtime_lua.go:179%5Cngithub.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](http://tgithub.com/heroiclabs/nakama/v2/server/api_rpc.go:160%5Cnnet/http.HandlerFunc.ServeHTTP%5Cn%5Ctnet/http/server.go:2012%5Cngithub.com/gorilla/mux.(*Router)).ServeHTTP\n\[tgithub.com/gorilla/mux@v1.7.4/mux.go:210\ngo.opencensus.io/plugin/ochttp.(\*Handler](http://tgithub.com/gorilla/mux@v1.7.4/mux.go:210%5Cngo.opencensus.io/plugin/ochttp.(*Handler)).ServeHTTP\n\[tgo.opencensus.io](http://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](http://ngithub.com/heroiclabs/nakama/v2/server.decompressHandler.func1%5Cn%5Ctgithub.com/heroiclabs/nakama/v2/server/api.go:463%5Cnnet/http.HandlerFunc.ServeHTTP%5Cn%5Ctnet/http/server.go:2012%5Cngithub.com/gorilla/handlers.CompressHandlerLevel.func1%5Cn%5Ctgithub.com/gorilla/handlers@v1.4.2/compress.go:148%5Cnnet/http.HandlerFunc.ServeHTTP%5Cn%5Ctnet/http/server.go:2012%5Cngithub.com/heroiclabs/nakama/v2/server.StartApiServer.func5%5Cn%5Ctgithub.com/heroiclabs/nakama/v2/server/api.go:216%5Cnnet/http.HandlerFunc.ServeHTTP%5Cn%5Ctnet/http/server.go:2012%5Cngithub.com/heroiclabs/nakama/v2/server.StartApiServer.func6%5Cn%5Ctgithub.com/heroiclabs/nakama/v2/server/api.go:227%5Cnnet/http.HandlerFunc.ServeHTTP%5Cn%5Ctnet/http/server.go:2012%5Cngithub.com/gorilla/mux.(*Router)).ServeHTTP\n\[tgithub.com/gorilla/mux@v1.7.4/mux.go:210\ngithub.com/gorilla/handlers.(\*cors](http://tgithub.com/gorilla/mux@v1.7.4/mux.go:210%5Cngithub.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](http://tgithub.com/gorilla/handlers@v1.4.2/cors.go:54%5Cnnet/http.serverHandler.ServeHTTP%5Cn%5Ctnet/http/server.go:2807%5Cnnet/http.(*conn)).serve\n\tnet/http/server.go:1895”}

---

<div class="post-metadata">

**Author:** ![mofirouz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/mofirouz/32/1523_2.png) [@mofirouz](https://forum.heroiclabs.com/u/mofirouz)\
**Post date:** [February 1, 2021, 10:38am UTC](https://forum.heroiclabs.com/t/iap-purchase-validation-issue-android/1330/2 "2021-02-01T10:38:58Z")

</div>

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:

> <https://github.com/heroiclabs/nakama/blob/master/data/modules/iap_verifier.lua>

> <https://github.com/heroiclabs/nakama/blob/master/data/modules/iap_verifier_rpc.lua>

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:

```auto
base64 serviceaccount.json

```

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

```auto
...
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:

```auto
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](https://github.com/heroiclabs/nakama/blob/master/data/modules/iap_verifier_rpc.lua#L25)

```auto
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](https://github.com/heroiclabs/nakama/blob/master/data/modules/iap_verifier_rpc.lua#L79)

---

<div class="post-metadata">

**Author:** ![Raja\_Nukala](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/raja_nukala/32/233_2.png) [@Raja\_Nukala](https://forum.heroiclabs.com/u/Raja_Nukala)\
**Post date:** [February 1, 2021, 10:57am UTC](https://forum.heroiclabs.com/t/iap-purchase-validation-issue-android/1330/3 "2021-02-01T10:57:46Z")

</div>

Thank you for response , will check

---

<div class="post-metadata">

**Author:** ![Raja\_Nukala](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/raja_nukala/32/233_2.png) [@Raja\_Nukala](https://forum.heroiclabs.com/u/Raja_Nukala)\
**Post date:** [February 1, 2021, 1:18pm UTC](https://forum.heroiclabs.com/t/iap-purchase-validation-issue-android/1330/4 "2021-02-01T13:18:11Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![mofirouz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/mofirouz/32/1523_2.png) [@mofirouz](https://forum.heroiclabs.com/u/mofirouz)\
**Post date:** [February 1, 2021, 1:29pm UTC](https://forum.heroiclabs.com/t/iap-purchase-validation-issue-android/1330/5 "2021-02-01T13:29:04Z")

</div>

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

```auto
- “iap_google_service_account=ewogICJ0eXBlIjogInNlcnZpY2VfYWNjb3VudCIs…”

```

---

<div class="post-metadata">

**Author:** ![Raja\_Nukala](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/raja_nukala/32/233_2.png) [@Raja\_Nukala](https://forum.heroiclabs.com/u/Raja_Nukala)\
**Post date:** [February 2, 2021, 4:23am UTC](https://forum.heroiclabs.com/t/iap-purchase-validation-issue-android/1330/6 "2021-02-02T04:23:38Z")

</div>

Thank you so much its working fine… 👍

---

<div class="post-metadata">

**Author:** ![mofirouz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/mofirouz/32/1523_2.png) [@mofirouz](https://forum.heroiclabs.com/u/mofirouz)\
**Post date:** [August 18, 2021, 12:21pm UTC](https://forum.heroiclabs.com/t/iap-purchase-validation-issue-android/1330/7 "2021-08-18T12:21:00Z")

</div>

Just as an update for this thread - We’ve added IAP APIs directly into Nakama for Nakama 3.3.0:  
[https://heroiclabs.com/docs/nakama/concepts/iap-validation](https://heroiclabs.com/docs/nakama/concepts/iap-validation)
