Nakama Google In-App Purchase Validation

Hello,

May I ask a question about an error message I got when trying to validate a Google In-App Purchase?

I’m using Unity client and call Client.ValidatePurchaseGoogleAsync to valiadatee the receipt.

Here‘s the receipt:

2024/06/18 21:57:54.494 7434 7464 Info Unity !!! Receipt: {“Payload”:"{"json":"{\"orderId\":\"GPA.3371-5367-4976-34250\",\"packageName\":\"com.Snowbornever.projectcatclient\",\"productId\":\"petidle.gold\",\"purchaseTime\":1718762270926,\"purchaseState\":0,\"purchaseToken\":\"gfddgiphabcjafjbanomlaae.AO-J1OyiQTiyVj_BgAdSULfyEWfz8CD3vd64Za8d168I_D4OKxD6vAsje578l0XcHkoAIyqeh3qaNB3HjhQc5AZ4VRv0pjIJ9cYDrnAIa7P8Sm6RWVj7ows\",\"quantity\":1,\"acknowledged\":false}","signature":"XaZYW1wk8rJM3TFoWd+p4wxuF0xG7Or8nA6gxSgpORWeIDe3jxtySpRaxRXp+BYpG9bG3tOXtZhlmut0OQbLOgdihnEppzGgKGLktiQTQEmh11wI5rgZL8UcBe4bvjPSr3qpEzyKNeCBaKW+SGmVQahfXTg1ulBiD2zdwzhFj1NiExgLMI0wlfYhenBMfbBOkGVJemBNz5Z7KQV00dXin5d84nZw4xhywtqCQsShho93zO7lGx6IFUsSJIe5GPjldgfc9wsfN2C4txqo1vbiHv/dOX+VXR/HWtceIwUoqEi+RwWaL0Jfh595UG+I8RzeAYtvqIsJDl4Z6mXdUAIQ1Q==","skuDetails":["{\"productId\":\"petidle.gold\",\"type\":\"inapp\",\"title\":\"Gold (com.Snowbornever.projectcatclient (unreviewed))\",\"name\":\"Gold\",\

here’s the server log:

2024/06/18 21:58:00.075 7434 7464 Error Unity ApiResponseException: {“code”:2,“message”:“receipt is malformed”}

{“level”:“error”,“ts”:“2024-06-19T01:58:00.198Z”,“caller”:“server/core_purchase.go:185”,“msg”:“Error validating Google receipt”,“error”:“receipt is malformed”}

I think I’ve followed the instructions well. Please help!

it seems that Nakama wasn’t able to use the service account I provided to do receipt validation.
I tried to disable the service account and it gave me the same “receipt is malformed” error.

here’s the permissions I gave to the service account.

Hello @lichengz,

What Nakama version are you running?

Hi, I’m running the latest 3.22

Please make sure you’re sending the receipt as a JSON encoded string.

do you mean that the following is wrong?

{"name":"Error","message":"hello"}

instead, it should be the following?

"{\"name\":\"Error\",\"message\":\"hello\"}"

Sorry, I’m new to Json encoding.

I’m using Unity IAP package and passing the following “receipt” json string to Nakama.

Yes, but also, only what’s contained in Payload should be sent to Nakama for validation.

thanks for pointing this out!

now I got the following, which I think is one step further :smiley:
2024/06/19 12:24:35.584 8856 8881 Error Unity ApiResponseException: {“code”:2,“message”:“non-200 response from Google service, status=401, payload={\n "error": {\n "code": 401,\n "message": "The current user has insufficient permissions to perform the requested operation.",\n "errors": [\n {\n "message": "The current user has insufficient permissions to perform the requested operation.",\n "domain": "androidpublisher",\n "reason": "permissionDenied"\n }\n ]\n }\n}\n”}

ok, problem solved!
another note here:
the activation of service account could take many hours. My most recently created services account failed to work and my another older account works perferctly now.

Thanks for your help!!!

2 Likes