itunes-receipt-validate 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 +17 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/itunes-receipt-validate.gemspec +42 -0
- data/lib/itunes-receipt.rb +1 -0
- data/lib/itunes/receipt.rb +9 -0
- data/lib/itunes/receipt/error.rb +83 -0
- data/lib/itunes/receipt/properties.rb +89 -0
- data/lib/itunes/receipt/response.rb +68 -0
- data/lib/itunes/receipt/service.rb +27 -0
- data/lib/itunes/receipt/v1.rb +23 -0
- data/lib/itunes/receipt/v2.rb +25 -0
- data/lib/itunes/receipt/version.rb +5 -0
- metadata +177 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4c92edaba3692021b79657d2a919f923dfd31019
|
4
|
+
data.tar.gz: 082a6a9b678393d12c2b0242c0043cb57a8fda70
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 685e38732038fd47e4d9cd013730cfd9ffaf9afab8e2af741461d79863d6c47995f94daf91be49c05338c80428558795a1f3080a9693d97acedb082e9cda3d93
|
7
|
+
data.tar.gz: 7ae300a394c872d690cc81373fa147a31d62e8a44f1f0dc36fa0d0becbefb6e3ee9d1ac02254839d8d7e77839abc1000d91e4bc3dba1ceb63730175c58b0c8ac
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at majioa@yandex.ru. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Malo Skrylevo
|
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,41 @@
|
|
1
|
+
# Itunes::Receipt
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/itunes/receipt`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'itunes-receipt'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install itunes-receipt
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/majioa/itunes-receipt. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "itunes/receipt"
|
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(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'itunes/receipt/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "itunes-receipt-validate"
|
8
|
+
spec.version = Itunes::Receipt::VERSION
|
9
|
+
spec.authors = ["Malo Skrylevo"]
|
10
|
+
spec.email = ["majioa@yandex.ru"]
|
11
|
+
|
12
|
+
spec.summary = %q{iTunes Receipt validation library}
|
13
|
+
spec.description = %q{iTunes Receipt validation library}
|
14
|
+
spec.homepage = "http://github.com/majioa/itunes-receipt-validate"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing 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 " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_runtime_dependency "excon", "~> 0.55.0"
|
34
|
+
|
35
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
36
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
37
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
38
|
+
spec.add_development_dependency "vcr", "~> 3.0.3"
|
39
|
+
spec.add_development_dependency "webmock", "~> 2.3.2"
|
40
|
+
spec.add_development_dependency "pry", "~> 0.10.4"
|
41
|
+
spec.add_development_dependency "timecop", "~> 0.8.1"
|
42
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'itunes/receipt'
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require "itunes/receipt/version"
|
2
|
+
require "itunes/receipt/service"
|
3
|
+
require "itunes/receipt/properties"
|
4
|
+
require "itunes/receipt/v1"
|
5
|
+
require "itunes/receipt/v2"
|
6
|
+
require "itunes/receipt/error"
|
7
|
+
require "itunes/receipt/response"
|
8
|
+
|
9
|
+
module Itunes::Receipt; end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require "itunes/receipt/version"
|
2
|
+
|
3
|
+
module Itunes::Receipt
|
4
|
+
class Error < StandardError
|
5
|
+
attr_reader :status
|
6
|
+
|
7
|
+
def initialize code
|
8
|
+
@status = code
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.new code
|
12
|
+
return super if self != Itunes::Receipt::Error
|
13
|
+
|
14
|
+
type = Itunes::Receipt::ERRORS[code]
|
15
|
+
type.is_a?(NilClass) && super || type.new(code)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class InvalidJsonError < Error
|
20
|
+
def message
|
21
|
+
'The App Store could not read the JSON object you provided (21000)'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class InvalidReceiptFormatError < Error
|
26
|
+
def message
|
27
|
+
'The App Store could not read the JSON object you provided (21002)'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class ReceiptAuthenticationError < Error
|
32
|
+
def message
|
33
|
+
'The receipt could not be authenticated (21003)'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class InvalidSharedSecretError < Error
|
38
|
+
def message
|
39
|
+
'The shared secret you provided does not match the shared secret on file for your account (21004)'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class ReceiptServerUnavailableError < Error
|
44
|
+
def message
|
45
|
+
'The receipt server is not currently available (21005)'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class SubscriptionExpiredError < Error
|
50
|
+
def message
|
51
|
+
'This receipt is valid but the subscription has expired (21006)'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class TestEnvironmentRequiredError < Error
|
56
|
+
def message
|
57
|
+
<<-'end;'
|
58
|
+
This receipt is from the test environment, but it was sent to the production environment
|
59
|
+
for verification. Send it to the test environment instead (21007)
|
60
|
+
end;
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class ProductionEnvironmentRequiredError < Error
|
65
|
+
def message
|
66
|
+
<<-'end;'
|
67
|
+
This receipt is from the production environment, but it was sent to the test environment
|
68
|
+
for verification. Send it to the production environment instead (21008)
|
69
|
+
end;
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
ERRORS = {
|
74
|
+
21000 => InvalidJsonError,
|
75
|
+
21002 => InvalidReceiptFormatError,
|
76
|
+
21003 => ReceiptAuthenticationError,
|
77
|
+
21004 => InvalidSharedSecretError,
|
78
|
+
21005 => ReceiptServerUnavailableError,
|
79
|
+
21006 => SubscriptionExpiredError,
|
80
|
+
21007 => TestEnvironmentRequiredError,
|
81
|
+
21008 => ProductionEnvironmentRequiredError,
|
82
|
+
}
|
83
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require "itunes/receipt/version"
|
2
|
+
|
3
|
+
module Itunes::Receipt::Properties
|
4
|
+
LIST = {
|
5
|
+
'unique_identifier' => true,
|
6
|
+
'product_id' => true,
|
7
|
+
'bid' => true,
|
8
|
+
'unique_vendor_identifier' => true,
|
9
|
+
'bvrs' => true,
|
10
|
+
'transaction_id' => proc { |v| v.to_i },
|
11
|
+
'original_transaction_id' => proc { |v| v.to_i },
|
12
|
+
'quantity' => proc { |v| v.to_i },
|
13
|
+
'item_id' => proc { |v| v.to_i },
|
14
|
+
'web_order_line_item_id' => proc { |v| v.to_i },
|
15
|
+
'original_purchase_date' => {
|
16
|
+
name: 'original_purchase_date_ms',
|
17
|
+
prc: proc { |v| Time.at(v.to_f / 1_000) },
|
18
|
+
},
|
19
|
+
'purchase_date' => {
|
20
|
+
name: 'purchase_date_ms',
|
21
|
+
prc: proc { |v| Time.at(v.to_f / 1_000) },
|
22
|
+
},
|
23
|
+
'expires_date' => {
|
24
|
+
name: [ 'expires_date_ms', 'expires_date' ],
|
25
|
+
prc: proc { |v| Time.at(v.to_f / 1_000) },
|
26
|
+
},
|
27
|
+
'receipt_type' => true,
|
28
|
+
'adam_id' => proc { |v| v.to_i },
|
29
|
+
'app_item_id' => proc { |v| v.to_i },
|
30
|
+
'bundle_id' => true,
|
31
|
+
'application_version' => true,
|
32
|
+
'download_id' => proc { |v| v.to_i },
|
33
|
+
'version_external_identifier' => proc { |v| v.to_i },
|
34
|
+
'receipt_creation_date' => {
|
35
|
+
name: 'receipt_creation_date_ms',
|
36
|
+
prc: proc { |v| Time.at(v.to_f / 1_000) },
|
37
|
+
},
|
38
|
+
'request_date' => {
|
39
|
+
name: 'request_date_ms',
|
40
|
+
prc: proc { |v| Time.at(v.to_f / 1_000) },
|
41
|
+
},
|
42
|
+
'original_application_version' => true,
|
43
|
+
'is_trial_period' => proc { |v| v == 'true' },
|
44
|
+
}
|
45
|
+
|
46
|
+
def self.included klass
|
47
|
+
klass.class_eval do
|
48
|
+
attr_reader :data
|
49
|
+
end
|
50
|
+
|
51
|
+
(LIST.keys & klass::PROPERTY_LIST).each do |prop|
|
52
|
+
case value = LIST[prop]
|
53
|
+
when TrueClass
|
54
|
+
klass.class_eval <<-"end;", __FILE__, __LINE__+1
|
55
|
+
def #{prop}
|
56
|
+
data['#{prop}']
|
57
|
+
end
|
58
|
+
end;
|
59
|
+
when Hash
|
60
|
+
case value[:name]
|
61
|
+
when String
|
62
|
+
klass.class_eval <<-"end;", __FILE__, __LINE__+1
|
63
|
+
def #{prop}
|
64
|
+
Itunes::Receipt::Properties::LIST['#{prop}'][:prc][data['#{value[:name]}']]
|
65
|
+
end
|
66
|
+
end;
|
67
|
+
when Array
|
68
|
+
klass.class_eval <<-"end;", __FILE__, __LINE__+1
|
69
|
+
def #{prop}
|
70
|
+
#{value[:name]}.reduce(nil) do |res, name|
|
71
|
+
if not res and data[name]
|
72
|
+
Itunes::Receipt::Properties::LIST['#{prop}'][:prc][data[name]]
|
73
|
+
else
|
74
|
+
res
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end;
|
79
|
+
end
|
80
|
+
when Proc
|
81
|
+
klass.class_eval <<-"end;", __FILE__, __LINE__+1
|
82
|
+
def #{prop}
|
83
|
+
Itunes::Receipt::Properties::LIST['#{prop}'][data['#{prop}']]
|
84
|
+
end
|
85
|
+
end;
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'itunes/receipt/version'
|
2
|
+
|
3
|
+
class Itunes::Receipt::Response
|
4
|
+
attr_reader :data, :response, :request
|
5
|
+
|
6
|
+
def latest_receipt
|
7
|
+
info = data['latest_receipt_info'] || data['latest_expired_receipt_info']
|
8
|
+
|
9
|
+
@latest_receipt ||=
|
10
|
+
case info
|
11
|
+
when Array
|
12
|
+
base_receipt = data['receipt'].dup
|
13
|
+
base_receipt.delete('in_app')
|
14
|
+
receipt = info.sort_by { |x| x['expires_date'] }.last
|
15
|
+
Itunes::Receipt::V2.new(data: base_receipt.merge(receipt))
|
16
|
+
when Hash
|
17
|
+
Itunes::Receipt::V1.new(data: info)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def receipt
|
22
|
+
if receipt = data['receipt']
|
23
|
+
@receipt ||=
|
24
|
+
if data['receipt']['in_app']
|
25
|
+
base_receipt = data['receipt'].dup
|
26
|
+
base_receipt.delete('in_app')
|
27
|
+
Itunes::Receipt::V2.new(data: base_receipt)
|
28
|
+
else
|
29
|
+
Itunes::Receipt::V1.new(data: receipt)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def receipts
|
35
|
+
@receipts ||=
|
36
|
+
if receipts = data['receipt']['in_app']
|
37
|
+
base_receipt = data['receipt'].dup
|
38
|
+
base_receipt.delete('in_app')
|
39
|
+
receipts.sort_by { |x| x['expires_date'] }.map { |r| Itunes::Receipt::V2.new(data: base_receipt.merge(r)) }
|
40
|
+
else
|
41
|
+
[ receipt, latest_receipt ]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def status
|
46
|
+
@status ||= data['status']
|
47
|
+
end
|
48
|
+
|
49
|
+
def valid?
|
50
|
+
status == 0
|
51
|
+
end
|
52
|
+
|
53
|
+
def validate!
|
54
|
+
if not valid?
|
55
|
+
raise(Itunes::Receipt::Error.new(status))
|
56
|
+
end
|
57
|
+
|
58
|
+
true
|
59
|
+
end
|
60
|
+
|
61
|
+
protected
|
62
|
+
|
63
|
+
def initialize response: nil, request: nil
|
64
|
+
@response = response
|
65
|
+
@request = request
|
66
|
+
@data = JSON.parse(response.body)
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'itunes/receipt/version'
|
2
|
+
require 'itunes/receipt/v1'
|
3
|
+
require 'excon'
|
4
|
+
|
5
|
+
class Itunes::Receipt::Service
|
6
|
+
TEST_HOST = 'sandbox.itunes.apple.com'
|
7
|
+
PRODUCTION_HOST = 'buy.itunes.apple.com'
|
8
|
+
|
9
|
+
attr_reader :host, :password, :connection
|
10
|
+
|
11
|
+
def initialize host: PRODUCTION_HOST, password: nil
|
12
|
+
@host = host
|
13
|
+
@password = password
|
14
|
+
@connection = Excon.new("https://#{host}")
|
15
|
+
end
|
16
|
+
|
17
|
+
def validate receipt_data: nil
|
18
|
+
request = {
|
19
|
+
'receipt-data' => receipt_data,
|
20
|
+
'password' => password
|
21
|
+
}
|
22
|
+
|
23
|
+
response = connection.post(path: '/verifyReceipt', body: request.to_json)
|
24
|
+
|
25
|
+
Itunes::Receipt::Response.new(response: response, request: request)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "itunes/receipt/version"
|
2
|
+
require "itunes/receipt/properties"
|
3
|
+
|
4
|
+
class Itunes::Receipt::V1
|
5
|
+
PROPERTY_LIST = %w(unique_identifier product_id bid unique_vendor_identifier bvrs transaction_id original_transaction_id
|
6
|
+
quantity item_id web_order_line_item_id original_purchase_date purchase_date expires_date)
|
7
|
+
|
8
|
+
include Itunes::Receipt::Properties
|
9
|
+
|
10
|
+
def to_h
|
11
|
+
data.dup
|
12
|
+
end
|
13
|
+
|
14
|
+
def expired?
|
15
|
+
self.expires_date < Time.now
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
|
20
|
+
def initialize data: nil
|
21
|
+
@data = data
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "itunes/receipt/version"
|
2
|
+
require "itunes/receipt/properties"
|
3
|
+
|
4
|
+
class Itunes::Receipt::V2
|
5
|
+
PROPERTY_LIST = %w(receipt_type adam_id app_item_id bundle_id application_version download_id version_external_identifier
|
6
|
+
product_id receipt_creation_date request_date original_purchase_date original_application_version
|
7
|
+
transaction_id original_transaction_id quantity purchase_date expires_date web_order_line_item_id
|
8
|
+
is_trial_period)
|
9
|
+
|
10
|
+
include Itunes::Receipt::Properties
|
11
|
+
|
12
|
+
def to_h
|
13
|
+
YAML.load(data.to_yaml)
|
14
|
+
end
|
15
|
+
|
16
|
+
def expired?
|
17
|
+
self.expires_date < Time.now
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
def initialize data: nil
|
23
|
+
@data = data
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: itunes-receipt-validate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Malo Skrylevo
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: excon
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.55.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.55.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.14'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.14'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: vcr
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.0.3
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.0.3
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.3.2
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 2.3.2
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.10.4
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.10.4
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: timecop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.8.1
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.8.1
|
125
|
+
description: iTunes Receipt validation library
|
126
|
+
email:
|
127
|
+
- majioa@yandex.ru
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rspec"
|
134
|
+
- ".travis.yml"
|
135
|
+
- CODE_OF_CONDUCT.md
|
136
|
+
- Gemfile
|
137
|
+
- LICENSE.txt
|
138
|
+
- README.md
|
139
|
+
- Rakefile
|
140
|
+
- bin/console
|
141
|
+
- bin/setup
|
142
|
+
- itunes-receipt-validate.gemspec
|
143
|
+
- lib/itunes-receipt.rb
|
144
|
+
- lib/itunes/receipt.rb
|
145
|
+
- lib/itunes/receipt/error.rb
|
146
|
+
- lib/itunes/receipt/properties.rb
|
147
|
+
- lib/itunes/receipt/response.rb
|
148
|
+
- lib/itunes/receipt/service.rb
|
149
|
+
- lib/itunes/receipt/v1.rb
|
150
|
+
- lib/itunes/receipt/v2.rb
|
151
|
+
- lib/itunes/receipt/version.rb
|
152
|
+
homepage: http://github.com/majioa/itunes-receipt-validate
|
153
|
+
licenses:
|
154
|
+
- MIT
|
155
|
+
metadata:
|
156
|
+
allowed_push_host: https://rubygems.org
|
157
|
+
post_install_message:
|
158
|
+
rdoc_options: []
|
159
|
+
require_paths:
|
160
|
+
- lib
|
161
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
|
+
requirements:
|
168
|
+
- - ">="
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: '0'
|
171
|
+
requirements: []
|
172
|
+
rubyforge_project:
|
173
|
+
rubygems_version: 2.6.10
|
174
|
+
signing_key:
|
175
|
+
specification_version: 4
|
176
|
+
summary: iTunes Receipt validation library
|
177
|
+
test_files: []
|