Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i verify google play in-app purchase in php?

I wish to verify a receipt of in-app purchase in an app through google play using a php page. How should i do it?

like image 770
AJ222 Avatar asked Jun 17 '13 08:06

AJ222


People also ask

Can you use Google play for in-app purchases?

On the Google Play Store app, in-app purchases will be by the Price or Install button. On play.google.com/store, you'll see "Offers in-app purchases" below the name of the app.


1 Answers

I'm no PHP expert so I'm not going to post any code, but the overall process is very straight forward and it should be dead easy to port to PHP. You need three things to verify a purchase:

  1. Your app's public key (from Services & APIs in Google Play Developer console)
  2. The original JSON of the purchase
  3. The purchase signature

If you implement in-app billing on Android using the IabHelper classes you'll get a Purchase object when you make a successful purchase or when you query the inventory. The Purchase object contains two methods that you need: Purchase.getOriginalJson() and Purchase.getSignature().

Securely store your app's public key on your server and POST the signature and the original JSON (base64 encode it before you send it) to you server. Retrieve the signature and json from $_POST and refer to Google's Java implementation of how to verify a purchase. It seems as though you can use PHPs built in openssl_verify function.

like image 139
britzl Avatar answered Oct 06 '22 06:10

britzl