Googleplay_InAppBilling_PurchaseVeryfication 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/Googleplay_InAppBilling_PurchaseVeryfication.gemspec +35 -0
- data/LICENSE.txt +21 -0
- data/README.md +83 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/config/google_play.yml +19 -0
- data/lib/Googleplay_InAppBilling_PurchaseVeryfication.rb +8 -0
- data/lib/Googleplay_InAppBilling_PurchaseVeryfication/config.rb +25 -0
- data/lib/Googleplay_InAppBilling_PurchaseVeryfication/play.rb +37 -0
- data/lib/Googleplay_InAppBilling_PurchaseVeryfication/railtie.rb +9 -0
- data/lib/Googleplay_InAppBilling_PurchaseVeryfication/version.rb +3 -0
- data/lib/tasks/play.rake +12 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cc796d026d503bcf3115ca1dc98dfa21b53a6461
|
4
|
+
data.tar.gz: a3487de18a7e76c0e775f9756e3742c26efb1c19
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2be19c9f4cc0686c3672c779bc943089c52e397ac16238796e3ced25ce7cfb65a2c65c639a02ce5549d28baf275a95a4733aa5263a26e4a031816d2dfe545a34
|
7
|
+
data.tar.gz: 30d543b9c2131c2daa8da5735586120f0e6245e385ef20994f9c00d1a14687bca4675517560e439f544ec46e75782c645dcc10d40057147ad6e6e3e38c5f978f
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'Googleplay_InAppBilling_PurchaseVeryfication/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "Googleplay_InAppBilling_PurchaseVeryfication"
|
8
|
+
spec.version = GoogleplayInAppBillingPurchaseVeryfication::VERSION
|
9
|
+
spec.authors = ["Osman Perviz"]
|
10
|
+
spec.email = ["osmanperviz@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{This(simple) gem handle Google Play In App Purchase Receipt Verification}
|
13
|
+
spec.description = %q{Some description}
|
14
|
+
spec.homepage = "https://github.com/osmanperviz/Googleplay_InAppBilling_PurchaseVeryfication"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_development_dependency "rspec"
|
33
|
+
spec.add_runtime_dependency "google-api-client"
|
34
|
+
spec.add_runtime_dependency "rails"
|
35
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 osman
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# GoogleplayInAppBillingPurchaseVeryfication
|
2
|
+
|
3
|
+
This(simple) gem handle Google Play In App Purchase Receipt Verification, and retrieving the information associated with receipt data.
|
4
|
+
Server-side verification over SSL is the most reliable way to determine the authenticity of purchasing records.
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
|
10
|
+
gem 'Googleplay_InAppBilling_PurchaseVeryfication'
|
11
|
+
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install Googleplay_InAppBilling_PurchaseVeryfication
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
For this gem you need to provide the following credentials:
|
24
|
+
client_id , google_secret , refresh_token , app_name , app_version
|
25
|
+
|
26
|
+
## Rails version greater than 4.0
|
27
|
+
|
28
|
+
Credentials will be placed in the secrets.yml file
|
29
|
+
|
30
|
+
|
31
|
+
## Rails version less than 4.1
|
32
|
+
|
33
|
+
Just run "rake play_config" command will generate under AppRoot/config/google_play.yml file.
|
34
|
+
Credentials will be placed in this file.
|
35
|
+
|
36
|
+
|
37
|
+
## SIMPLE USAGE
|
38
|
+
|
39
|
+
receipt_data = 'purchase_token from android app'
|
40
|
+
response = GoogleplayInAppBillingPurchaseVeryfication::Play.verify(package_name, subscription_id, receipt_data)
|
41
|
+
if !response['errors']
|
42
|
+
success
|
43
|
+
else
|
44
|
+
error
|
45
|
+
end
|
46
|
+
rescue Exception => e
|
47
|
+
render json: {:message=> e.message},status: 400
|
48
|
+
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
* Fork the project.
|
53
|
+
|
54
|
+
* Make your feature addition or bug fix.
|
55
|
+
|
56
|
+
* Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
57
|
+
|
58
|
+
## Details
|
59
|
+
|
60
|
+
Need more detail on how all of this works (especially the Android implementation)? Read Google's In-app Billing Docs.
|
61
|
+
|
62
|
+
|
63
|
+
## Error
|
64
|
+
If you have ssl error in development just put this two lines of code
|
65
|
+
|
66
|
+
require 'openssl'
|
67
|
+
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
|
68
|
+
|
69
|
+
Be sure never to use this in any production environment, as it will negate benefits of using SSL in the first place. It is only ever valid to do this in your local development environment.
|
70
|
+
Here some useful links to fix this issue:
|
71
|
+
|
72
|
+
http://railsapps.github.io/openssl-certificate-verify-failed.html
|
73
|
+
https://gist.github.com/fnichol/867550
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
## License
|
81
|
+
|
82
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
83
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "Googleplay_InAppBilling_PurchaseVeryfication"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
development:
|
2
|
+
client_id:
|
3
|
+
google_secrets:
|
4
|
+
refresh_token:
|
5
|
+
app_name:
|
6
|
+
app_version:
|
7
|
+
test:
|
8
|
+
client_id:
|
9
|
+
google_secrets:
|
10
|
+
refresh_token:
|
11
|
+
app_name:
|
12
|
+
app_version:
|
13
|
+
|
14
|
+
production:
|
15
|
+
client_id: <%= CLIENT_ID %>
|
16
|
+
google_secrets: <%= GOOGLE_SECRETS %>
|
17
|
+
refresh_token: <%= REFRESH_TOKEN %>
|
18
|
+
app_name: <%= APP_NAME %>
|
19
|
+
app_version: <%= APP_VERSION %>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require "Googleplay_InAppBilling_PurchaseVeryfication/version"
|
2
|
+
require 'Googleplay_InAppBilling_PurchaseVeryfication/play'
|
3
|
+
require 'Googleplay_InAppBilling_PurchaseVeryfication/config'
|
4
|
+
require 'Googleplay_InAppBilling_PurchaseVeryfication/railtie' if defined?(Rails)
|
5
|
+
|
6
|
+
module GoogleplayInAppBillingPurchaseVeryfication
|
7
|
+
|
8
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module GoogleplayInAppBillingPurchaseVeryfication
|
2
|
+
class FileError < StandardError; end
|
3
|
+
class Config
|
4
|
+
attr_reader :app_name,:app_version,:refresh_token,:google_secret,:client_id
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
play_path = File.join(Rails.root, "config", "google_play.yml")
|
8
|
+
secrets_path = File.join(Rails.root, "config", "secrets.yml")
|
9
|
+
|
10
|
+
if !File.file?(play_path) && !File.file?(secrets_path)
|
11
|
+
raise FileError,'Missing Config File(secrets.yml or google_play.yml)'
|
12
|
+
end
|
13
|
+
custum_config = File.file?(play_path) ? YAML.load_file('config/google_play.yml') : Hash.new{ |hash, key| hash[key] = {} }
|
14
|
+
secrets_config = File.file?(secrets_path) ? YAML.load_file('config/secrets.yml') : Hash.new{ |hash, key| hash[key] = {} }
|
15
|
+
|
16
|
+
@app_name = secrets_config[Rails.env]['app_name'] || custum_config[Rails.env]['app_name']
|
17
|
+
@app_version = secrets_config[Rails.env]['app_version'] || custum_config[Rails.env]['app_version']
|
18
|
+
@refresh_token = secrets_config[Rails.env]['refresh_token'] || custum_config[Rails.env]['refresh_token']
|
19
|
+
@google_secret = secrets_config[Rails.env]['google_secret'] || custum_config[Rails.env]['google_secret']
|
20
|
+
@client_id = secrets_config[Rails.env]['client_id'] || custum_config[Rails.env]['client_id']
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'google/api_client'
|
2
|
+
module GoogleplayInAppBillingPurchaseVeryfication
|
3
|
+
class Play
|
4
|
+
|
5
|
+
def self.google_api_client
|
6
|
+
config = Config.new
|
7
|
+
@@google_client ||= Google::APIClient.new(
|
8
|
+
auto_refresh_token: true,
|
9
|
+
application_name: config.app_name,
|
10
|
+
application_version: config.app_version
|
11
|
+
).tap do |client|
|
12
|
+
|
13
|
+
client.authorization = Signet::OAuth2::Client.new(
|
14
|
+
:token_credential_uri => 'https://accounts.google.com/o/oauth2/token',
|
15
|
+
:refresh_token => config.refresh_token,
|
16
|
+
:client_id => config.client_id,
|
17
|
+
:client_secret => config.google_secret
|
18
|
+
)
|
19
|
+
client.authorization.fetch_access_token!
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.verify(package_name, subscription_id, purchase_token)
|
24
|
+
client = self.google_api_client
|
25
|
+
subscription = client.discovered_api('androidpublisher', 'v2')
|
26
|
+
api_method = subscription.purchases.products.get
|
27
|
+
purchases = client.execute(api_method: api_method, parameters: {
|
28
|
+
"packageName" => package_name,
|
29
|
+
"productId" => subscription_id,
|
30
|
+
"token" => purchase_token
|
31
|
+
}).data
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
data/lib/tasks/play.rake
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
desc 'Create play.yml file'
|
2
|
+
|
3
|
+
task :play_config do
|
4
|
+
path = File.join(Rails.root, "config", "google_play.yml")
|
5
|
+
|
6
|
+
if File.file? path
|
7
|
+
puts "You already have google_play.yml file"
|
8
|
+
next
|
9
|
+
else
|
10
|
+
copy_file("#{Gem.loaded_specs["Googleplay_InAppBilling_PurchaseVeryfication"].full_gem_path}/config/google_play.yml","config/google_play.yml")
|
11
|
+
end
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Googleplay_InAppBilling_PurchaseVeryfication
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Osman Perviz
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: google-api-client
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rails
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Some description
|
84
|
+
email:
|
85
|
+
- osmanperviz@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- CODE_OF_CONDUCT.md
|
94
|
+
- Gemfile
|
95
|
+
- Googleplay_InAppBilling_PurchaseVeryfication.gemspec
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- bin/console
|
100
|
+
- bin/setup
|
101
|
+
- config/google_play.yml
|
102
|
+
- lib/Googleplay_InAppBilling_PurchaseVeryfication.rb
|
103
|
+
- lib/Googleplay_InAppBilling_PurchaseVeryfication/config.rb
|
104
|
+
- lib/Googleplay_InAppBilling_PurchaseVeryfication/play.rb
|
105
|
+
- lib/Googleplay_InAppBilling_PurchaseVeryfication/railtie.rb
|
106
|
+
- lib/Googleplay_InAppBilling_PurchaseVeryfication/version.rb
|
107
|
+
- lib/tasks/play.rake
|
108
|
+
homepage: https://github.com/osmanperviz/Googleplay_InAppBilling_PurchaseVeryfication
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata:
|
112
|
+
allowed_push_host: https://rubygems.org
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
requirements: []
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 2.2.3
|
130
|
+
signing_key:
|
131
|
+
specification_version: 4
|
132
|
+
summary: This(simple) gem handle Google Play In App Purchase Receipt Verification
|
133
|
+
test_files: []
|