iap-validator 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
@@ -0,0 +1,48 @@
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
+ # For redcar:
45
+ #.redcar
46
+
47
+ # For rubinius:
48
+ #*.rbc
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Carson McDonald
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.
@@ -0,0 +1,46 @@
1
+ iap-validator can be used to validate base64 encoded iTunes in app purchase receipts.
2
+
3
+ ## Getting started
4
+
5
+ If you haven't read the [Apple StoreKit Guide](http://developer.apple.com/library/mac/#documentation/NetworkingInternet/Conceptual/StoreKitGuide/Introduction/Introduction.html) do that first to get an understanding of StoreKit.
6
+
7
+ Next take a look at this greate [introduction to in app purchases](http://www.raywenderlich.com/2797/introduction-to-in-app-purchases) by Ray Wenderlich.
8
+
9
+ Once you are able to make purchases you are ready to use this gem. Check out the [reference for validating receipts](http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/StoreKitGuide/VerifyingStoreReceipts/VerifyingStoreReceipts.html) if you want to know more details of how the gem works.
10
+
11
+ The gem only works with base64 encoded data so you will need to do that first. There are a number of good libraries for doing that in Objective-C: [NSDataBase64](https://github.com/reklis/NSDataBase64) or [the Google toolbox for mac](http://code.google.com/p/google-toolbox-for-mac/)
12
+
13
+ Assuming you have read the introduction to in app purchases post above and are using the NSDataBase64 library you would add something like this to the example code to print out a base64 encoded receipt:
14
+
15
+ ``` C
16
+ - (void)recordTransaction:(SKPaymentTransaction *)transaction
17
+ {
18
+ NSLog(@"Test transaction receipt: %@", [transaction.transactionReceipt base64EncodedString]);
19
+ }
20
+ ```
21
+
22
+ Once you have your receipt base64 encoded you can verify it with the following code:
23
+
24
+ ``` rb
25
+ require 'iap-validator'
26
+
27
+ receipt_data = 'PUT THE BASE64 ENCODED RECEIPT HERE'
28
+
29
+ # Is this a valid receipt?
30
+ if IAPValidator::IAPValidator.valid?(receipt_data, true)
31
+ puts "Receipt is valid"
32
+ else
33
+ puts "Receipt is not valid"
34
+ end
35
+
36
+ # You can also get more information about the receipt
37
+ resp = IAPValidator::IAPValidator.validate(receipt_data, true)
38
+ puts resp["status"]
39
+ ```
40
+
41
+ In the above example the calls take true as the second argument indicating sandbox use. Without the second argument the calls will default to using the production validation system.
42
+
43
+ ## Copyright
44
+
45
+ Copyright (c) 2011 Carson McDonald. See LICENSE.txt for further details.
46
+
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "iap-validator/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "iap-validator"
7
+ s.version = IAPValidator::VERSION
8
+ s.authors = ["Carson McDonald"]
9
+ s.email = ["carson@ioncannon.net"]
10
+ s.homepage = "http://github.com/carsonmcdonald/iap-validator"
11
+ s.license = "MIT"
12
+ s.summary = %Q{Apple iTunes in app purchase receipt validator}
13
+ s.description = %Q{This gem will validate base64 encoded receipts from iTunes in app purchases.}
14
+
15
+ s.rubyforge_project = "iap-validator"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency "httparty"
23
+ end
@@ -0,0 +1,34 @@
1
+ require "iap-validator/version"
2
+
3
+ require 'httparty'
4
+
5
+ module IAPValidator
6
+ class IAPValidator
7
+ include HTTParty
8
+
9
+ SANDBOX_URL = 'https://sandbox.itunes.apple.com'
10
+ PRODUCTION_URL = 'https://buy.itunes.apple.com'
11
+
12
+ base_uri PRODUCTION_URL
13
+
14
+ headers 'Content-Type' => 'application/json'
15
+ format :json
16
+
17
+ def self.validate(data, sandbox = false)
18
+ base_uri SANDBOX_URL if sandbox
19
+
20
+ resp = post('/verifyReceipt', :body => MultiJson.encode({ 'receipt-data' => data }) )
21
+
22
+ if resp.code == 200
23
+ MultiJson.decode(resp.body())
24
+ else
25
+ nil
26
+ end
27
+ end
28
+
29
+ def self.valid?(data, sandbox = false)
30
+ resp = validate(data, sandbox)
31
+ !resp.nil? && resp['status'] == 0
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module IAPValidator
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'iap-validator'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,4 @@
1
+ require 'helper'
2
+
3
+ class TestIapValidator < Test::Unit::TestCase
4
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iap-validator
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.0.0
6
+ platform: ruby
7
+ authors:
8
+ - Carson McDonald
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-10-18 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: httparty
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ description: This gem will validate base64 encoded receipts from iTunes in app purchases.
27
+ email:
28
+ - carson@ioncannon.net
29
+ executables: []
30
+
31
+ extensions: []
32
+
33
+ extra_rdoc_files: []
34
+
35
+ files:
36
+ - .document
37
+ - .gitignore
38
+ - Gemfile
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - iap-validator.gemspec
43
+ - lib/iap-validator.rb
44
+ - lib/iap-validator/version.rb
45
+ - test/helper.rb
46
+ - test/test_iap-validator.rb
47
+ homepage: http://github.com/carsonmcdonald/iap-validator
48
+ licenses:
49
+ - MIT
50
+ post_install_message:
51
+ rdoc_options: []
52
+
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ requirements: []
68
+
69
+ rubyforge_project: iap-validator
70
+ rubygems_version: 1.8.11
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: Apple iTunes in app purchase receipt validator
74
+ test_files:
75
+ - test/helper.rb
76
+ - test/test_iap-validator.rb