Class: IappValidator::GooglePlayValidator
- Inherits:
-
Object
- Object
- IappValidator::GooglePlayValidator
- Defined in:
- lib/iapp_validator.rb
Constant Summary collapse
- AndroidPublisher =
Google::Apis::AndroidpublisherV3
Instance Method Summary collapse
-
#initialize(json_key_path: nil) ⇒ GooglePlayValidator
constructor
A new instance of GooglePlayValidator.
- #verify_purchase(package_name, product_id, token) ⇒ Object
Constructor Details
#initialize(json_key_path: nil) ⇒ GooglePlayValidator
Returns a new instance of GooglePlayValidator.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/iapp_validator.rb', line 13 def initialize(json_key_path: nil) json_key_path ||= File.("config/credentials/google_play_service_account.json", Dir.pwd) scope = "https://www.googleapis.com/auth/androidpublisher" @service = AndroidPublisher::AndroidPublisherService.new @service. = Google::Auth::ServiceAccountCredentials.make_creds( json_key_io: File.open(json_key_path), scope: scope ) end |
Instance Method Details
#verify_purchase(package_name, product_id, token) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/iapp_validator.rb', line 24 def verify_purchase(package_name, product_id, token) begin purchase = @service.get_purchase_product(package_name, product_id, token) { success: purchase.purchase_state == 0, error: nil } rescue Google::Apis::Error => e { success: false, error: e. } end end |