Created
February 5, 2016 17:04
-
-
Save raulsouzalima/e47d2767a2ed8c7579fc to your computer and use it in GitHub Desktop.
Google Play receipt validation with Google API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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