Skip to content

Instantly share code, notes, and snippets.

@oojikoo-gist
Created November 1, 2015 02:22
Show Gist options
  • Save oojikoo-gist/59e753c5b2cc1fc28bbf to your computer and use it in GitHub Desktop.
Save oojikoo-gist/59e753c5b2cc1fc28bbf to your computer and use it in GitHub Desktop.
rails: in app billing server verify
ISSUER = '362508889713-np8nvipb8cank17t68i4ekggvcm3ogd5.apps.googleusercontent.com'
APP_NAME = 'ossumapp' # This value didn't seem to matter. I think it is for logging
APP_VERSION = '0.9.0' # This value didn't seem to matter. I think it is for logging
GOOGLE_API_KEY = 'AIzaSyAVMfAxfWmHaUzVy8IXjuGpM9U3ciW81cU'
class Billing
def self.google_api_client
@@google_client ||= Google::APIClient.new(
application_name: APP_NAME,
application_version: APP_VERSION
).tap do |client|
# Load the key downloaded from the Google Developer Console
if ENV['GOOGLE_API_KEY'].nil?
puts "Be sure that you have ENV['GOOGLE_API_KEY'] defined in your environment."
return
end
key = OpenSSL::PKey::RSA.new GOOGLE_API_KEY, 'notasecret'
# Initialize the connection
client.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 => ISSUER,
:signing_key => key)
client.authorization.fetch_access_token!
end
end
def self.test_server(package_name, product_id, token)
# Get the client
client = self.google_api_client
# Discover the subscriptions API
publisher = client.discovered_api('androidpublisher', 'v2')
# Make the API call
result = client.execute(
:api_method => publisher.purchases.products.get,
:parameters => {'packageName' => package_name, 'productId' => product_id, 'token' => token}
)
puts result
result
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment