Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I verify Android in-app-billing transactions on MY server?

I have made an Android app where items can be purchased using in-app-billing. When an item is purchased the transaction can easily be synced between Android Market and the phone - to be used in the app. But, I need MY server to be aware of the purchase. The decision to deliver app-specific data should be made on my server, not in the client app.

E.g.

  1. User buys item X from Android Market.
  2. Transaction data Y is sent to the client.
  3. Client sends Y to my server.
  4. Client asks the server to deliver content for X.
  5. Server delivers content if Y is valid. How can this be accomplished?

Q: How do I verify that transaction data coming from the Android client (presumably originating from Google servers) is not fake? I.e. a hacker didn't generate the data.

Google Server -> Android client -> My server -> Android client

Perhaps this is more of a PHP question than anything else. Exactly what should my server script (PHP) do in order to verify that the retrieved data is real?

like image 316
l33t Avatar asked Dec 05 '11 00:12

l33t


People also ask

How to verify purchase for Android app in server side?

Go get a google api client library for your server platform from https://developers.google.com/api-client-library. Use your particular platform's client library to build a service interface and directly read the result of your purchase verification.

Do I need a server for in-app purchases?

It should be noted that server validation isn't mandatory — in-app purchases will still work without it. It grants some advantages, though: Advanced payment analytics, which is especially important for subscriptions since everything that happens after the activation isn't processed by the device.

How do I integrate in-app purchases on Android?

Simply create a Signed APK and publish it to the Play Store, then wait for it to be accepted. After that, all we have to do is set up the card and buy it. That's it for this article, hope you get the exact idea on how to implement in-app purchases in your app and start earning!

What is in-app billing API?

The In-app Billing Version 3 API makes it easier for you to integrate In-app Billing into your applications. The features in this version include improved synchronous purchase flow, APIs to let you easily track ownership of consumable goods, and local caching of in-app purchase data.


1 Answers

Use openssl_verify ($data, $signature, $key)

The variables $data and $signature should be sent from the android client to your php server using https. The transaction contains both of these items. Send that to your servers before you acknowledge the transaction on the client.(see documentation here - http://developer.android.com/guide/market/billing/billing_integrate.html)

The variable $key is your google public key available from your publisher account from the Licensing & In-app Billing panel. Copy the public key and use that in your php code, preferably using a config file you install on your servers rather than in your actual php code.

If the openssl_verify call succeeds you should store the order numbers on your servers and ensure they are unique so they cannot be replayed. Be aware that a single data receipt and signature pair could contain many order numbers though its usually one order.

like image 71
abdollar Avatar answered Oct 08 '22 18:10

abdollar