play_billing_validator 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,49 @@
1
+ # rcov generated
2
+ coverage
3
+
4
+ # rdoc generated
5
+ rdoc
6
+
7
+ # yard generated
8
+ doc
9
+ .yardoc
10
+
11
+ # bundler
12
+ .bundle
13
+
14
+ # jeweler generated
15
+ pkg
16
+
17
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
18
+ #
19
+ # * Create a file at ~/.gitignore
20
+ # * Include files you want ignored
21
+ # * Run: git config --global core.excludesfile ~/.gitignore
22
+ #
23
+ # After doing this, these files will be ignored in all your git projects,
24
+ # saving you from having to 'pollute' every project you touch with them
25
+ #
26
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
27
+ #
28
+ # For MacOS:
29
+ #
30
+ .DS_Store
31
+ #
32
+ # For TextMate
33
+ #*.tmproj
34
+ #tmtags
35
+ #
36
+ # For emacs:
37
+ #*~
38
+ #\#*
39
+ #.\#*
40
+ #
41
+ # For vim:
42
+ #*.swp
43
+
44
+ bin
45
+ cache
46
+ gems
47
+ specifications
48
+ Gemfile.lock
49
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010-2013 Amro Mousa
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,46 @@
1
+ # Google Play In-app Billing Validation
2
+
3
+ This (simple) gem validates In-app Billing transactions. Pass your base64
4
+ encoded public key, the transaction data (json) and the base64 encoded signature
5
+ and it will return a boolean value telling you whether or not your transaction is valid.
6
+
7
+ ##Installation
8
+
9
+ $ gem install play_billing_validator
10
+
11
+ ##Requirements
12
+
13
+ A public key for your Android app's in app billing. Get it from the Google Play [Developer Console](https://play.google.com/apps/publish).
14
+
15
+ ##Usage
16
+
17
+ Implement the In-app Billing v3 in your Android app:
18
+
19
+ String data = data.getStringExtra(RESPONSE_INAPP_PURCHASE_DATA);
20
+ String signature = data.getStringExtra(RESPONSE_INAPP_SIGNATURE);
21
+
22
+ Then send the data and signature to your server and validate like this:
23
+
24
+ data = params[:data]
25
+ signature = params[:signature]
26
+ if (GooglePlay::Transaction.valid(public_key, data, signature))
27
+ # success. save the transaction, give away cookies and so on.
28
+ else
29
+ # booo. bad transaction data. reprimand the crook or give them a cookie anyway.
30
+ end
31
+
32
+ I recommend keeping a record of valid transactions in your database to prevent malicious users
33
+ from replaying them for free loot.
34
+
35
+ ## Details
36
+
37
+ Need more detail on how all of this works (especially the Android implementation)? Read Google's [In-app Billing Docs](http://developer.android.com/google/play/billing/index.html).
38
+
39
+ ## Thanks
40
+
41
+ Thanks to [Walt Schlender](http://stackoverflow.com/users/749709/walta) for his answer to
42
+ this [StackOverflow](http://stackoverflow.com/questions/5971031/how-do-i-verify-android-in-app-billing-with-a-server-with-ruby) question. This gem is based on that post.
43
+
44
+ ##Copyrights and License
45
+
46
+ * Copyright (c) 2013 Amro Mousa. This gem is licensed under the MIT license. See LICENSE.txt for details.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ module PlayBilling
2
+ VERSION = "0.0.1"
3
+ end
4
+
5
+ require 'play_billing/transaction'
@@ -0,0 +1,16 @@
1
+ require 'multi_json'
2
+ require 'openssl'
3
+ require 'base64'
4
+
5
+ module PlayBilling
6
+ class Transaction
7
+ def self.valid(public_key, data, signature)
8
+ begin
9
+ public_key = OpenSSL::PKey::RSA.new(Base64.decode64(public_key))
10
+ public_key.verify(OpenSSL::Digest::SHA1.new, Base64.decode64(signature), data)
11
+ rescue Exception => e
12
+ false
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ require "play_billing"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "play_billing_validator"
8
+ s.authors = ["Amro Mousa"]
9
+ s.email = ["amromousa@gmail.com"]
10
+ s.homepage = "http://github.com/amro/play_billing_validator"
11
+ s.summary = %q{Validates Google Play In-app Billing transactions}
12
+ s.description = %q{Validates Google Play In-app Billing transactions}
13
+ s.license = "MIT"
14
+ s.version = PlayBilling::VERSION
15
+ s.platform = Gem::Platform::RUBY
16
+ s.rubyforge_project = "play_billing_validator"
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+
23
+ s.add_dependency('multi_json', '>= 1.3.4')
24
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: play_billing_validator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Amro Mousa
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: multi_json
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.3.4
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.3.4
30
+ description: Validates Google Play In-app Billing transactions
31
+ email:
32
+ - amromousa@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - LICENSE.txt
40
+ - README.markdown
41
+ - Rakefile
42
+ - lib/play_billing.rb
43
+ - lib/play_billing/transaction.rb
44
+ - play_billing_validator.gemspec
45
+ homepage: http://github.com/amro/play_billing_validator
46
+ licenses:
47
+ - MIT
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project: play_billing_validator
66
+ rubygems_version: 1.8.24
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Validates Google Play In-app Billing transactions
70
+ test_files: []