iap_verify 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +25 -0
- data/Manifest +8 -0
- data/README.md +4 -0
- data/Rakefile +14 -0
- data/iap_verify.gemspec +33 -0
- data/init.rb +1 -0
- data/lib/iap_verify.rb +3 -0
- data/lib/iap_verify/client.rb +25 -0
- data/lib/iap_verify/receipt_ios7.rb +131 -0
- metadata +75 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 72479c8a319c41a8270d9b93e59061e5194c9e3f
|
4
|
+
data.tar.gz: 90dfbba626b1c5c27d65f8c95bd82ceeb7f4576e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c19db4bcdefce2887061fa518cfc07b319ef52749ea677395631994d2446c8bb54cbd0ff5aebbfd17be1ef603383105e459f265066b4b3e56a6f8bbb5d300caa
|
7
|
+
data.tar.gz: dfaca3a0959d23d87f8e9dada0d4d915e258684d3f82775936d3be10bec6db9198ea5d18f5cdcbd6204d96d233a0150d54668cfe49aad9aca380bb700e8dd54a
|
data/LICENSE
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
Copyright (c) 2014, Web factory
|
3
|
+
All rights reserved.
|
4
|
+
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
7
|
+
|
8
|
+
* Redistributions of source code must retain the above copyright notice, this
|
9
|
+
list of conditions and the following disclaimer.
|
10
|
+
|
11
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
13
|
+
and/or other materials provided with the distribution.
|
14
|
+
|
15
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
16
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
17
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
18
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
19
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
20
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
21
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
22
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
23
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
24
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
25
|
+
|
data/Manifest
ADDED
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('iap_verify', '0.1.0') do |p|
|
6
|
+
p.description = "Verify in app purchase"
|
7
|
+
p.url = "https://github.com/WebFactoryMk/iap_verify"
|
8
|
+
p.author = "WF|Todor Panev"
|
9
|
+
p.email = "toshe@webfactory.mk"
|
10
|
+
p.ignore_pattern = ["tmp/*", "script/*"]
|
11
|
+
p.dependencies = ['venice']
|
12
|
+
end
|
13
|
+
|
14
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
data/iap_verify.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# stub: iap_verify 0.1.0 ruby lib
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "iap_verify"
|
6
|
+
s.version = "0.1.0"
|
7
|
+
|
8
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
9
|
+
s.require_paths = ["lib"]
|
10
|
+
s.authors = ["WF|Todor Panev"]
|
11
|
+
s.date = "2014-09-04"
|
12
|
+
s.description = "Verify in app purchase"
|
13
|
+
s.email = "toshe@webfactory.mk"
|
14
|
+
s.extra_rdoc_files = ["LICENSE", "README.md", "lib/iap_verify.rb", "lib/iap_verify/client.rb", "lib/iap_verify/receipt_ios7.rb"]
|
15
|
+
s.files = ["LICENSE", "Manifest", "README.md", "Rakefile", "iap_verify.gemspec", "init.rb", "lib/iap_verify.rb", "lib/iap_verify/client.rb", "lib/iap_verify/receipt_ios7.rb"]
|
16
|
+
s.homepage = "https://github.com/WebFactoryMk/iap_verify"
|
17
|
+
s.rdoc_options = ["--line-numbers", "--title", "Iap_verify", "--main", "README.md"]
|
18
|
+
s.rubyforge_project = "iap_verify"
|
19
|
+
s.rubygems_version = "2.3.0"
|
20
|
+
s.summary = "Verify in app purchase"
|
21
|
+
|
22
|
+
if s.respond_to? :specification_version then
|
23
|
+
s.specification_version = 4
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
+
s.add_runtime_dependency(%q<venice>, [">= 0"])
|
27
|
+
else
|
28
|
+
s.add_dependency(%q<venice>, [">= 0"])
|
29
|
+
end
|
30
|
+
else
|
31
|
+
s.add_dependency(%q<venice>, [">= 0"])
|
32
|
+
end
|
33
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'iap_verify'
|
data/lib/iap_verify.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module IapVerify
|
2
|
+
class Client < Venice::Client
|
3
|
+
def verify!(data, options = {})
|
4
|
+
json = json_response_from_verifying_data(data)
|
5
|
+
status, receipt_attributes = json['status'].to_i, json['receipt']
|
6
|
+
|
7
|
+
case status
|
8
|
+
when 0, 21006
|
9
|
+
receipt = Receipt_iOS7.new(receipt_attributes)
|
10
|
+
|
11
|
+
if latest_receipt_attributes = json['latest_receipt_info']
|
12
|
+
receipt.latest = Receipt_iOS7.new(latest_receipt_attributes)
|
13
|
+
end
|
14
|
+
|
15
|
+
if latest_expired_receipt_attributes = json['latest_expired_receipt_info']
|
16
|
+
receipt.latest_expired = Receipt_iOS7.new(latest_expired_receipt_attributes)
|
17
|
+
end
|
18
|
+
|
19
|
+
return receipt
|
20
|
+
else
|
21
|
+
raise Receipt_iOS7::VerificationError.new(status)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
require 'venice'
|
2
|
+
|
3
|
+
module IapVerify
|
4
|
+
class Receipt_iOS7
|
5
|
+
|
6
|
+
attr_reader :application_version
|
7
|
+
attr_reader :bundle_id
|
8
|
+
attr_accessor :in_app
|
9
|
+
attr_reader :receipt_type
|
10
|
+
attr_reader :original_purchase_date
|
11
|
+
attr_reader :original_application_version
|
12
|
+
attr_reader :original_transaction_id
|
13
|
+
attr_reader :request_date
|
14
|
+
attr_reader :is_trial_period
|
15
|
+
attr_reader :product_id
|
16
|
+
attr_reader :purchase_date
|
17
|
+
attr_reader :transaction_id
|
18
|
+
attr_reader :quantity
|
19
|
+
|
20
|
+
def initialize(attributes = {})
|
21
|
+
|
22
|
+
@original_application_version = attributes['original_application_version'] if attributes['original_application_version']
|
23
|
+
@application_version = attributes['application_version'] if attributes['application_version']
|
24
|
+
@bundle_id = attributes['bundle_id'] if attributes['bundle_id']
|
25
|
+
@receipt_type = attributes['receipt_type'] if attributes['receipt_type']
|
26
|
+
@request_date = DateTime.parse(attributes['request_date']) if attributes['request_date']
|
27
|
+
|
28
|
+
|
29
|
+
if attributes['in_app']
|
30
|
+
@in_app = Array.new
|
31
|
+
attributes['in_app'].each do |purchase|
|
32
|
+
@in_app << Receipt_iOS7.new(purchase)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
@original_purchase_date = DateTime.parse(attributes['original_purchase_date']) if attributes['original_purchase_date']
|
37
|
+
|
38
|
+
|
39
|
+
if attributes != nil & attributes['in_app'].nil?
|
40
|
+
@is_trial_period = attributes['is_trial_period'] if attributes['is_trial_period']
|
41
|
+
@original_transaction_id = attributes['original_transaction_id'] if attributes['original_transaction_id']
|
42
|
+
@product_id = attributes['product_id'] if attributes['product_id']
|
43
|
+
@purchase_date = DateTime.parse(attributes['purchase_date']) if attributes['purchase_date']
|
44
|
+
@transaction_id = attributes['transaction_id'] if attributes['transaction_id']
|
45
|
+
@quantity = Integer(attributes['quantity']) if attributes['quantity']
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def to_h
|
50
|
+
{
|
51
|
+
:bundle_id => @bundle_id,
|
52
|
+
:receipt_type => @receipt_type,
|
53
|
+
:original_transaction_id => (@original_transaction_id.transaction_id rescue nil),
|
54
|
+
:original_purchase_date => (@original_purchase_date.purchase_date.httpdate rescue nil),
|
55
|
+
:in_app => @in_app.map{ |purchase| {is_trial_period: purchase.is_trial_period,
|
56
|
+
product_id: purchase.product_id,
|
57
|
+
purchase_date: (purchase.purchase_date.httpdate rescue nil),
|
58
|
+
transaction_id: (purchase.transaction_id rescue nil),
|
59
|
+
quantity: purchase.quantity,
|
60
|
+
original_purchase_date: (purchase.original_purchase_date.httpdate rescue nil),
|
61
|
+
original_transaction_id: (purchase.original_transaction_id rescue nil)
|
62
|
+
}
|
63
|
+
}
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
def to_json
|
68
|
+
self.to_h.to_json
|
69
|
+
end
|
70
|
+
|
71
|
+
class << self
|
72
|
+
|
73
|
+
def verify(data, options = {})
|
74
|
+
verify!(data, options) #rescue false
|
75
|
+
end
|
76
|
+
|
77
|
+
def verify!(data, options = {})
|
78
|
+
client = IapVerify::Client.development
|
79
|
+
|
80
|
+
begin
|
81
|
+
client.verify!(data, options)
|
82
|
+
rescue VerificationError => error
|
83
|
+
case error.code
|
84
|
+
when 21007
|
85
|
+
client = IapVerify::Client.development
|
86
|
+
retry
|
87
|
+
when 21008
|
88
|
+
client = IapVerify::Client.production
|
89
|
+
retry
|
90
|
+
else
|
91
|
+
raise error
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
alias :validate :verify
|
97
|
+
alias :validate! :verify!
|
98
|
+
end
|
99
|
+
|
100
|
+
class VerificationError < StandardError
|
101
|
+
attr_accessor :code
|
102
|
+
|
103
|
+
def initialize(code)
|
104
|
+
@code = Integer(code)
|
105
|
+
end
|
106
|
+
|
107
|
+
def message
|
108
|
+
case @code
|
109
|
+
when 21000
|
110
|
+
"The App Store could not read the JSON object you provided."
|
111
|
+
when 21002
|
112
|
+
"The data in the receipt-data property was malformed."
|
113
|
+
when 21003
|
114
|
+
"The receipt could not be authenticated."
|
115
|
+
when 21004
|
116
|
+
"The shared secret you provided does not match the shared secret on file for your account."
|
117
|
+
when 21005
|
118
|
+
"The receipt server is not currently available."
|
119
|
+
when 21006
|
120
|
+
"This receipt is valid but the subscription has expired. When this status code is returned to your server, the receipt data is also decoded and returned as part of the response."
|
121
|
+
when 21007
|
122
|
+
"This receipt is a sandbox receipt, but it was sent to the production service for verification."
|
123
|
+
when 21008
|
124
|
+
"This receipt is a production receipt, but it was sent to the sandbox service for verification."
|
125
|
+
else
|
126
|
+
"Unknown Error: #{@code}"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: iap_verify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- WF|Todor Panev
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: venice
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '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'
|
27
|
+
description: Verify in app purchase
|
28
|
+
email: toshe@webfactory.mk
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.md
|
34
|
+
- lib/iap_verify.rb
|
35
|
+
- lib/iap_verify/client.rb
|
36
|
+
- lib/iap_verify/receipt_ios7.rb
|
37
|
+
files:
|
38
|
+
- LICENSE
|
39
|
+
- Manifest
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- iap_verify.gemspec
|
43
|
+
- init.rb
|
44
|
+
- lib/iap_verify.rb
|
45
|
+
- lib/iap_verify/client.rb
|
46
|
+
- lib/iap_verify/receipt_ios7.rb
|
47
|
+
homepage: https://github.com/WebFactoryMk/iap_verify
|
48
|
+
licenses: []
|
49
|
+
metadata: {}
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options:
|
52
|
+
- "--line-numbers"
|
53
|
+
- "--title"
|
54
|
+
- Iap_verify
|
55
|
+
- "--main"
|
56
|
+
- README.md
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.2'
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project: iap_verify
|
71
|
+
rubygems_version: 2.4.1
|
72
|
+
signing_key:
|
73
|
+
specification_version: 4
|
74
|
+
summary: Verify in app purchase
|
75
|
+
test_files: []
|