You should generate the tokens when the user opens the in-game store. Allowing for a 5-10 minutes expiration is ok.
Ajax is a good way to do it. You can also have a look at the samples page below for more examples:
https://developers.google.com/commerce/wallet/digital/docs/samples