itunes-iap 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YmE1M2Y1M2FkMDI0NDRhMmYwMTJhOTdlOTljMWFjZDI0OTYyYTNiNA==
5
+ data.tar.gz: !binary |-
6
+ NzFhYWIwMjgyODk0YmMxMTk3ZTQzOGIzYjc4ZmY4MDNhMzM3ZjU5OA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZDQyNWViODU5NjcxYTcwM2M3N2Y2NWVmYTRjOGI5Njg0ZjRlN2QzNTZiZTQ1
10
+ MjI4MzlkNTk3Yzc3YTRkZTU2Y2E4Y2MzOTU0YzNkYmMzMDczMjQ4MWJiZDA5
11
+ Mjg2ZTA1OTljMmJlZTEzNzlmOTA1MGJhYmMxMTA0OTkxZTNiNzQ=
12
+ data.tar.gz: !binary |-
13
+ MTVhNzI2NWU0MTliZWVhZjBjYzBmOWFiOGRmNTllMDY5MDZjZTJjOThkZTFh
14
+ YTkyNmUzZDk3ZDIxYmMyZjU2Y2IzM2FkMzJlNDcwNjUyMzljOTVjNzQzYzJm
15
+ YjJkMjE1OTk2YTY0MGQyMDNiOGRiNDczOGVhYWY2NmY0ZGEwM2U=
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in itunes-iap.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Chris Cashwell
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,44 @@
1
+ # ITunes IAP Receipt Analyzer & Validator
2
+
3
+ Validates iTunes In-App Purchase receipts with Apple and reports on status.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'itunes-iap'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install itunes-iap
18
+
19
+ ## Usage
20
+
21
+ require 'itunes/iap'
22
+ receipt = Itunes::IAP::Receipt.analyze(
23
+ base64_receipt_data,
24
+ shared_secret: shared_secret,
25
+ sandbox: true
26
+ )
27
+
28
+ ### Attributes
29
+
30
+ - `:status` is the status code returned by Apple during validation
31
+ - `:response` is the raw response object from Apple
32
+ - `:original_transaction_id` is the original transaction ID, useful for validating uniqueness among users
33
+ - `:latest_transaction_id` is the most recent transaction ID
34
+ - `:product_id` is the product ID the purchase covers
35
+ - `:valid_until` is the expiration date of the purchase
36
+ - `:valid` is true only when Apple validated the provided receipt and the expiration date is in the future
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it ( http://github.com/litehouselabs/itunes-iap/fork )
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'itunes/iap/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "itunes-iap"
8
+ spec.version = Itunes::IAP::VERSION
9
+ spec.authors = ["Chris Cashwell"]
10
+ spec.email = ["ccashwell@gmail.com"]
11
+ spec.summary = "iTunes In-App Purchase and Subscription Receipt Analysis and Validation"
12
+ spec.description = "iTunes In-App Purchase and Subscription Receipt Analysis and Validation"
13
+ spec.homepage = "https://github.com/litehouselabs/itunes-iap"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,84 @@
1
+ require 'json'
2
+ require 'net/https'
3
+ require 'ostruct'
4
+ require 'uri'
5
+
6
+ require 'itunes/iap/version'
7
+
8
+ module Itunes
9
+ module IAP
10
+ class Receipt
11
+ PRODUCTION_VALIDATION_URL = 'https://buy.itunes.apple.com/verifyReceipt'
12
+ SANDBOX_VALIDATION_URL = 'https://sandbox.itunes.apple.com/verifyReceipt'
13
+
14
+ attr_reader :verified_receipt
15
+
16
+ class << self
17
+ def analyze base64_receipt, options = {}
18
+ receipt = new(base64_receipt, options)
19
+ out = Hash.new.tap do |r|
20
+ r[:status] = receipt.verified_receipt['status']
21
+ r[:response] = receipt.verified_receipt
22
+ if r[:status] == 0
23
+ newest_transaction = receipt.verified_receipt['latest_receipt_info'].last
24
+ r[:original_transaction_id] = newest_transaction['original_transaction_id']
25
+ r[:latest_transaction_id] = newest_transaction['transaction_id']
26
+ r[:product_id] = newest_transaction['product_id']
27
+ r[:valid_until] = Time.at(
28
+ receipt
29
+ .verified_receipt['latest_receipt_info']
30
+ .last['expires_date_ms']
31
+ .to_i / 1000
32
+ )
33
+ r[:valid] = Time.now < r[:valid_until]
34
+ else
35
+ r[:valid] = false
36
+ end
37
+ end
38
+
39
+ out
40
+ end
41
+ end
42
+
43
+ def initialize base64_receipt, options = {}
44
+ @base64_receipt = base64_receipt
45
+ @options = options
46
+ @verified_receipt = update_receipt
47
+ end
48
+
49
+ private
50
+
51
+ def update_receipt
52
+ request_parameters = Hash.new.tap do |params|
53
+ params['receipt-data'] = @base64_receipt
54
+ params['password'] = @options[:shared_secret] if @options[:shared_secret]
55
+ end
56
+
57
+ validation_uri = URI(validation_url)
58
+ adapter = Net::HTTP.new(validation_uri.host, validation_uri.port)
59
+ adapter.use_ssl = true
60
+ adapter.verify_mode = OpenSSL::SSL::VERIFY_PEER
61
+
62
+ request = Net::HTTP::Post.new(validation_uri.request_uri)
63
+ request['Accept'] = "application/json"
64
+ request['Content-Type'] = "application/json"
65
+ request.body = request_parameters.to_json
66
+
67
+ response = adapter.request(request)
68
+
69
+ json = JSON.parse(response.body)
70
+ end
71
+
72
+ def validation_url
73
+ if @options[:validation_url]
74
+ @options[:validation_url]
75
+ elsif @options[:sandbox]
76
+ SANDBOX_VALIDATION_URL
77
+ else
78
+ PRODUCTION_VALIDATION_URL
79
+ end
80
+ end
81
+ end
82
+
83
+ end
84
+ end
@@ -0,0 +1,5 @@
1
+ module Itunes
2
+ module IAP
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: itunes-iap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Chris Cashwell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-23 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.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: iTunes In-App Purchase and Subscription Receipt Analysis and Validation
42
+ email:
43
+ - ccashwell@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - itunes-iap.gemspec
54
+ - lib/itunes/iap.rb
55
+ - lib/itunes/iap/version.rb
56
+ homepage: https://github.com/litehouselabs/itunes-iap
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.1.11
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: iTunes In-App Purchase and Subscription Receipt Analysis and Validation
80
+ test_files: []