|
|
@@ -0,0 +1,46 @@ |
|
|
class GooglePlayVerification |
|
|
require 'google/api_client' |
|
|
|
|
|
# Refer: |
|
|
# https://code.google.com/p/google-api-ruby-client/issues/detail?id=72 |
|
|
# and |
|
|
# http://jonathanotto.com/blog/google_oauth2_api_quick_tutorial.html |
|
|
GOOGLE_KEY = 'xxx-xxx.apps.googleusercontent.com' |
|
|
GOOGLE_SECRET = 'xxx' |
|
|
ACCESS_TOKEN = 'xxx' |
|
|
REFRESH_TOKEN = '1/4Qxxx' |
|
|
APP_NAME = 'xxx' |
|
|
APP_VERSION = '1.0.1' |
|
|
|
|
|
def self.google_api_client |
|
|
@@google_client ||= Google::APIClient.new( |
|
|
auto_refresh_token: true, |
|
|
application_name: APP_NAME, |
|
|
application_version: APP_VERSION |
|
|
).tap do |client| |
|
|
client.authorization.client_id = GOOGLE_KEY |
|
|
client.authorization.client_secret = GOOGLE_SECRET |
|
|
client.authorization.access_token = ACCESS_TOKEN |
|
|
client.authorization.refresh_token = REFRESH_TOKEN |
|
|
end |
|
|
end |
|
|
|
|
|
# ie. https://developers.google.com/android-publisher/v1/ |
|
|
# eg. |
|
|
# @package_name com.stocklight.stocklightapp |
|
|
# @subscription_id com.stocklight.stocklight.standardsubscription |
|
|
# @purchase_token xxx |
|
|
def self.verify_subscription(package_name, subscription_id, purchase_token) |
|
|
client = self.google_api_client |
|
|
|
|
|
# Verify whether the transaction_receipt is valid |
|
|
subscriptions = client.discovered_api('androidpublisher', 'v1') |
|
|
api_method = subscriptions.purchases.get |
|
|
purchases = client.execute(api_method: api_method, parameters: { |
|
|
"packageName" => package_name, |
|
|
"subscriptionId" => subscription_id, |
|
|
"token" => purchase_token |
|
|
}).data |
|
|
end |
|
|
|
|
|
end |