Skip to content

Instantly share code, notes, and snippets.

@raulsouzalima
Created February 5, 2016 17:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save raulsouzalima/e47d2767a2ed8c7579fc to your computer and use it in GitHub Desktop.
Save raulsouzalima/e47d2767a2ed8c7579fc to your computer and use it in GitHub Desktop.
Google Play receipt validation with Google API
# Versão 0.9.1
require 'google/apis/androidpublisher_v2'
receipt = JSON.parse(File.read('spec/support/receipts/android.json'))
package_name = receipt['packageName']
product_id = receipt['productId']
purchase_token = receipt['purchaseToken']
Google::Apis::ClientOptions.default.application_name = "Application Name"
Google::Apis::ClientOptions.default.application_version = "1.0"
key_content = File.open("config/p12_key.p12", "rb") { |io| io.read }
key = OpenSSL::PKCS12.new(key_content, 'notasecret').key
Google::Apis::RequestOptions.default.authorization = Signet::OAuth2::Client.new(
:token_credential_uri => 'https://accounts.google.com/o/oauth2/token',
:audience => 'https://accounts.google.com/o/oauth2/token',
:scope => 'https://www.googleapis.com/auth/androidpublisher',
:issuer => 'xxxcc.apps.googleusercontent.com',
:signing_key => key
)
service = Google::Apis::AndroidpublisherV2::AndroidPublisherService.new
service.get_purchase_product(package_name, product_id, purchase_token).as_json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment