[Solved] Unity 5.6 amazon iap receipt verification fails

Hi

I’m using the unity iap and discovered all my receipts were invalid on amazon. Since I hadn’t looked at that code for ages, I went back to revisit it.

So I just tried the demo package included with the iap service. Set up the sandbox environment and:

  1. Any test purchase will fail, saying that “invalid receipt, not unlocking content”.
    This will happen I believe because the script has a validator of the purchase always enabled for anything that is android. In this case, it’s an amazon device. It seems to not be able to detect that you are on amazon, even if I set it up on the dropbox as an amazon store, it will still fail.

  2. Disabling the receipt validator, I get the test to work on the device but the server will always say that my receipt is invalid (error 498). I get this receipt:
    receipt:{“Store”:“AmazonApps”,“TransactionID”:“q1YqVbJSyjH28DGPKChw9c0o8nd3ySststQtzSkrzM8tCk43K6z0d_HOTcww
    N8vxCrVV0lEqBmpJzs_VS03OyE_KBzJS8tPTMtMzSlJzMktS9YxMs4GKSpSsDHSUUoBKDU0sDSwtDM1NjAwMDJRqAQ”,“Payload”:“{"receiptId":"q1YqVbJSyjH28DGPKChw9c0o8nd3ySststQtzSkrzM8tCk43K6z0d_HOTcww
    N8vxCrVV0lEqBmpJzs_VS03OyE_KBzJS8tPTMtMzSlJzMktS9YxMs4GKSpSsDHSUUoBKDU0sDSwtDM1NjAwMDJRqAQ","userId":"l3HL7XppEMhrOGDnur9-ulvqomrSg6qyODKmah76lJU=","isSandbox":true}”}

I retrieve the payload, send it out to the server with the usual
__https://appstore-sdk.amazon.__com/version/2.0/verify/developer/" + devsecret + “/user/” + userId + “/purchaseToken/” + purchaseToken;
which in this case is
__https://appstore-sdk.amazon.__com/version/2.0/verify/developer/2:SECRET_HERE0zaCPqQ==/user/l3HL7XppEMhrOGDnur9-ulvqomrSg6qyODKmah76lJU=/purchaseToken/q1YqVbJSyjH28DGPKChw9c0o8nd3ySststQtzSkrzM8tCk43K6z0d_HOTcwwN8vxCrVV0lEqBmpJzs_VS03OyE_KBzJS8tPTMtMzSlJzMktS9YxMs4GKSpSsDHSUUoBKDU0sDSwtDM1NjAwMDJRqAQ

Then error 498 is returned (invalid token). It doesn’t matter if I try this on sandbox on production. Always the same error.
So… what gives?
Things I can think of:
a) receipts need to be validated with a validator before “decrypting” them on amazon? (bug)
b) the token generated is not working or properly formatted (bug)
c) i’m missing something

solved the url part, although it says 2.0 on the url, that’s actually iap version 1.0 on amazon. there is a different url for 2.0 on the documentation

now, the validator still fails because it doesn’t work on amazon and it doesn’t detect it automatically (it assumes you are on google android)

@creat327 ,

The IAPDemo.cs script has an example of how to do this. Basically, you can get the selected store value from the StandardPurchasingModule.

private bool m_IsGooglePlayStoreSelected;
var module = StandardPurchasingModule.Instance();
var builder = ConfigurationBuilder.Instance(module);

m_IsGooglePlayStoreSelected = Application.platform == RuntimePlatform.Android && module.androidStore == AndroidStore.GooglePlay;

I think we are misunderstanding each other. Get the demo script, set up the receipt validation keys and all that jazz. compile and run on android, make a purchase. Perfect, it works, it gets validated. Now, from the dropdown switch to Amazon, compile and run on a kindle. Make a purchase, it fails, it will try to validate the purchase using the receipt. The demos script the way it is right now will fail since the ReceiptValidation is a define per platform (android) not at runtime (amazon)

And this is not even a serious problem to me because I can easily fix it manually. The biggest problem is the purchase receipt from non-consumables and subscriptions on Amazon. It’s always empty when you load the game a second time. It was reported a while back and it’s not fixed on any updates so I can’t verify purchases if I remove and reinstall the app.