title: How can I manage in-app billing transactions on an external server securely?
body: <p>I'm attempting to implement a system for upgrading/unlocking various features of my app using "managed" purchases with in-app billing, and I'm getting bogged down by the lack of in-depth documentation or examples.</p>
  
  <p>My app's purpose is to retrieve/parse and display data from my own server, and the documentation on <a href="http://developer.android.com/guide/market/billing/billing_best_practices.html">http://developer.android.com/guide/market/billing/billing_best_practices.html</a> states:</p>
  
  <blockquote>
    <p>If you are using a remote server to deliver or manage content, have your application verify the purchase state of the unlocked content whenever a user accesses the content.</p>
  </blockquote>
  
  <p>My question is, what is the best way to go about this in terms of actual workflow?</p>
  
  <p>As far as I can tell, on successful purchase I would store the purchase information on my server as well as locally in the app. When the app runs, I would send the order ID to my server and the server would check to see if the order is valid (firstly checking that the order exists in my server's database, and secondly checking if I have not manually revoked the order for whatever reason).</p>
  
  <p>If that is verified, the server would send a response to the app that the requested features are "licensed", and the app would provide the unlocked features/content to the user.</p>
  
  <p>The obvious problems I can see with this are:</p>
  
  <ol>
  <li>A rooted user could easily just alter the local app's SQLITE database (or whatever other method I use to store order information) to inject a valid order ID.</li>
  <li>If network access is down, or my server is down, I still want the app to be able to run (with cached data) with all the user's purchased features.</li>
  </ol>
  
  <p>Potential ways around the first problem that I can see involve sending some sort of device identifier with the verification request, and monitoring that at my server's end - revoking the order if a large number of devices are accessing the order in a short period of time.</p>
  
  <p>For the second problem, I can't figure out an adequate solution. I initially thought that each time the verification is successful, the time this verification took place would be stored. Then, the app would continue to run with the unlocked features for say, 48 hours after the last successful verification. The issue with that is, how can I securely store this time value? Again, rooted users could simply alter the value and the app would be none-the-wiser.</p>
  
  <p>Has anyone designed a server-based system for managing in-app billing purchases and can offer some suggestions?</p>