amazon-iap2 0.1 → 0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +34 -47
- data/lib/amazon/iap2/result.rb +21 -2
- data/lib/amazon/iap2/version.rb +1 -1
- data/spec/specs/client_spec.rb +24 -5
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d71a8c3964b2b99ff8b1ba4b55f58fd2e96c788a
|
4
|
+
data.tar.gz: 254d4f47003497c215295325218777a09be96831
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6b717e79ad9a3aca11c30ab8729b4f7ad2467b66375249445ec65031ba3dbdbb53beca6d27e9ae4f803f67fea8f8890211eb1d9c09016eb6906a8017977ee97
|
7
|
+
data.tar.gz: 67787a971156ee81687e054369a7cf7d4229a88659f45181bf94418e2068eb2a64f9190d0d96627b75b5ef7b9dba7c6e4de828e7c4f29605c1e71acec8aa2c42
|
data/README.md
CHANGED
@@ -1,14 +1,18 @@
|
|
1
|
-
# Amazon::
|
1
|
+
# Amazon::Iap2
|
2
|
+
|
3
|
+
[](https://www.codeship.io/projects/39519)
|
4
|
+
[](https://www.versioneye.com/user/projects/5645bcefb5b03d002200084e)
|
5
|
+
[](http://badge.fury.io/rb/amazon-iap2)
|
2
6
|
|
3
7
|
This gem is a simple implementation of the Amazon receipt verfication service outlined
|
4
|
-
[here](https://developer.amazon.com/sdk/in-app-purchasing/documentation/rvs.html).
|
8
|
+
[here](https://developer.amazon.com/sdk/in-app-purchasing/documentation/rvs.html) with migrations from [here](https://developer.amazon.com/public/apis/earn/in-app-purchasing/docs-v2/verifying-receipts-in-iap-2.0)
|
5
9
|
|
6
10
|
|
7
11
|
## Installation
|
8
12
|
|
9
13
|
Add this line to your application's Gemfile:
|
10
14
|
|
11
|
-
gem 'amazon-
|
15
|
+
gem 'amazon-iap2'
|
12
16
|
|
13
17
|
And then execute:
|
14
18
|
|
@@ -16,7 +20,7 @@ And then execute:
|
|
16
20
|
|
17
21
|
Or install it yourself as:
|
18
22
|
|
19
|
-
$ gem install amazon-
|
23
|
+
$ gem install amazon-iap2
|
20
24
|
|
21
25
|
## Usage
|
22
26
|
|
@@ -33,73 +37,56 @@ client = Amazon::Iap::Client.new 'my_developer_secret', 'http://iap-staging.doma
|
|
33
37
|
client = Amazon::Iap::Client.new 'my_developer_secret' # production server
|
34
38
|
```
|
35
39
|
|
36
|
-
From there, you can call either `verify` or `renew` on the client and pass in the user id and purchase token:
|
37
|
-
|
38
|
-
```ruby
|
39
|
-
result = client.verify 'some-user-id', 'some-purchase-token'
|
40
|
-
result = client.renew 'some-user-id', 'some-purchase-token'
|
41
|
-
```
|
42
|
-
|
43
|
-
By default, the `verify` method will automatically try to renew expired tokens, and will recall `verify`
|
44
|
-
against the new token returned. If you do not want this behavior, simply pass in `false` as the third
|
45
|
-
attribute to the `verify` method:
|
46
|
-
|
47
|
-
```ruby
|
48
|
-
result = client.verify 'some-user-id', 'some-purchase-token', false
|
49
|
-
```
|
50
40
|
|
51
41
|
## Returned Values
|
52
42
|
|
53
|
-
An instance of Amazon::
|
54
|
-
of the hash keys returned in the JSON object. For convenience, we also add `
|
55
|
-
which are `Time` representations of the milliseconds returned in `
|
56
|
-
|
57
|
-
```ruby
|
58
|
-
result = client.verify 'some-user-id', 'some-purchase-token'
|
59
|
-
|
60
|
-
result.class.name # "Amazon::Iap::Result"
|
61
|
-
result.item_type # "SUBSCRIPTION"
|
62
|
-
result.sku # "some-sku"
|
63
|
-
result.start_date # 1378751554943
|
64
|
-
result.start_time # 2013-09-09 14:32:34 -0400
|
65
|
-
result.end_date # nil
|
66
|
-
result.end_time # nil
|
67
|
-
result.purchase_token # "some-purchase-token"
|
68
|
-
```
|
69
|
-
|
70
|
-
<!-- -->
|
43
|
+
An instance of Amazon::Iap2::Result is returned from both methods, the attributes being the underscored versions
|
44
|
+
of the hash keys returned in the JSON object. For convenience, we also add `purchase_time` and `cancel_time` attributes
|
45
|
+
which are `Time` representations of the milliseconds returned in `cancel_date` and `cancel_date` respectively. E.g.,
|
71
46
|
|
72
47
|
```ruby
|
73
|
-
result = client.
|
74
|
-
|
75
|
-
result.class.name
|
76
|
-
result.
|
48
|
+
result = client.verify 'some-user-id', 'some-receipt-id'
|
49
|
+
|
50
|
+
result.class.name # "Amazon::Iap2::Result"
|
51
|
+
result.product_type # "SUBSCRIPTION"
|
52
|
+
result.product_id # "some-sku"
|
53
|
+
result.parent_product_id # nil
|
54
|
+
result.purchase_date # 1378751554943
|
55
|
+
result.purchase_time # 2013-09-09 14:32:34 -0400
|
56
|
+
result.cancel_date # nil
|
57
|
+
result.cancel_time # nil
|
58
|
+
result.quantity # 1
|
59
|
+
result.test_transaction # false
|
60
|
+
result.beta_product # false
|
61
|
+
result.term # term length of product type is Subscription e.g"1 YEAR"
|
62
|
+
result.term_sku # sku of the product subscription
|
63
|
+
result.renewal_date # renewal date of subscription product (in ms)
|
77
64
|
```
|
78
65
|
|
79
66
|
## Exception Handling
|
80
67
|
|
81
68
|
Any non-200 status code will raise an exception. For convenience in internal controls, each status code raises
|
82
|
-
a distinct exception. Take a look at the [Amazon::
|
69
|
+
a distinct exception. Take a look at the [Amazon::Iap2::Result class](lib/amazon/iap2/result.rb) for specifics.
|
83
70
|
|
84
71
|
Example exception handling:
|
85
72
|
|
86
73
|
```ruby
|
87
74
|
begin
|
88
|
-
result = client.verify 'some-user-id', 'some-
|
89
|
-
rescue Amazon::
|
75
|
+
result = client.verify 'some-user-id', 'some-receipt-id'
|
76
|
+
rescue Amazon::Iap2::Exceptions::InternalError => e
|
90
77
|
# enqueue to try again later
|
91
78
|
end
|
92
79
|
```
|
93
80
|
|
94
|
-
For convenience, all exceptions inherit from `Amazon::
|
81
|
+
For convenience, all exceptions inherit from `Amazon::Iap2::Exceptions::Exception` so you can rescue from
|
95
82
|
any exception (or as a default):
|
96
83
|
|
97
84
|
```ruby
|
98
85
|
begin
|
99
|
-
result = client.verify 'some-user-id', '
|
100
|
-
rescue Amazon::
|
86
|
+
result = client.verify 'some-user-id', 'receipt-id'
|
87
|
+
rescue Amazon::Iap2::Exceptions::InternalError => e
|
101
88
|
# enqueue to try again later
|
102
|
-
rescue Amazon::
|
89
|
+
rescue Amazon::Iap2::Exceptions::Exception => e
|
103
90
|
# log the exception
|
104
91
|
end
|
105
92
|
```
|
data/lib/amazon/iap2/result.rb
CHANGED
@@ -7,7 +7,26 @@ class Amazon::Iap2::Result
|
|
7
7
|
:receipt_id,
|
8
8
|
:quantity,
|
9
9
|
:test_transaction,
|
10
|
-
:beta_product
|
10
|
+
:beta_product,
|
11
|
+
:term, :term_sku,
|
12
|
+
:renewal_date
|
13
|
+
|
14
|
+
VALID_ATTRIBUTES = %w(
|
15
|
+
product_type
|
16
|
+
product_id
|
17
|
+
parent_product_id
|
18
|
+
purchase_date
|
19
|
+
purchase_time
|
20
|
+
cancel_date
|
21
|
+
cancel_time
|
22
|
+
receipt_id
|
23
|
+
quantity
|
24
|
+
test_transaction
|
25
|
+
beta_product
|
26
|
+
term
|
27
|
+
term_sku
|
28
|
+
renewal_date
|
29
|
+
)
|
11
30
|
|
12
31
|
def initialize(response)
|
13
32
|
case response.code.to_i
|
@@ -25,7 +44,7 @@ class Amazon::Iap2::Result
|
|
25
44
|
|
26
45
|
parsed.each do |key, value|
|
27
46
|
underscore = key.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').gsub(/([a-z\d])([A-Z])/, '\1_\2').tr('-', '_').downcase
|
28
|
-
send "#{underscore}=", value
|
47
|
+
send "#{underscore}=", value if VALID_ATTRIBUTES.include?(underscore.to_s.downcase)
|
29
48
|
end
|
30
49
|
when 400 then raise Amazon::Iap2::Exceptions::InvalidTransaction
|
31
50
|
when 496 then raise Amazon::Iap2::Exceptions::InvalidSharedSecret
|
data/lib/amazon/iap2/version.rb
CHANGED
data/spec/specs/client_spec.rb
CHANGED
@@ -35,9 +35,18 @@ describe Amazon::Iap2::Client do
|
|
35
35
|
|
36
36
|
expect(result.purchase_date).to eql(response["purchaseDate"])
|
37
37
|
expect(result.purchase_time).to eql(Time.at(response["purchaseDate"] / 1000))
|
38
|
-
expect(result.cancel_date).to eql
|
39
|
-
expect(result.cancel_time).to eql(Time.at(response["cancelDate"] / 1000))
|
38
|
+
expect(result.cancel_date).to eql nil
|
40
39
|
|
40
|
+
expect(result.term).to eql(response["term"])
|
41
|
+
expect(result.term_sku).to eql(response["termSku"])
|
42
|
+
expect(result.renewal_date).to eql(response["renewalDate"])
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should succeed if unexpected key is returned' do
|
46
|
+
response = unexpected_response receipt_id
|
47
|
+
build_stub user_id, receipt_id, 200, response
|
48
|
+
|
49
|
+
result = subject.verify user_id, receipt_id
|
41
50
|
end
|
42
51
|
|
43
52
|
end
|
@@ -56,13 +65,23 @@ describe Amazon::Iap2::Client do
|
|
56
65
|
def build_response(receipt_id)
|
57
66
|
{
|
58
67
|
"betaProduct" => true,
|
59
|
-
"cancelDate" =>
|
60
|
-
"productId" => "sub1",
|
68
|
+
"cancelDate" => nil,
|
69
|
+
"productId" => "sub1.sku",
|
61
70
|
"productType" => "SUBSCRIPTION",
|
62
71
|
"purchaseDate" => Time.now.to_i * 1000,
|
63
72
|
"receiptId" => "#{receipt_id}",
|
64
|
-
"testTransaction" => true
|
73
|
+
"testTransaction" => true,
|
74
|
+
"term" => "1 YEAR",
|
75
|
+
"termSku" => "sub1",
|
76
|
+
"renewalDate" => (Time.now.to_i + 2629743) * 1000,
|
65
77
|
}
|
66
78
|
end
|
67
79
|
|
80
|
+
def unexpected_response(receipt_id)
|
81
|
+
{
|
82
|
+
"newValue" => 1
|
83
|
+
}
|
84
|
+
end
|
85
|
+
|
86
|
+
|
68
87
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amazon-iap2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Blinkist
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-11-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -65,10 +65,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
65
|
version: '0'
|
66
66
|
requirements: []
|
67
67
|
rubyforge_project:
|
68
|
-
rubygems_version: 2.4.
|
68
|
+
rubygems_version: 2.4.8
|
69
69
|
signing_key:
|
70
70
|
specification_version: 4
|
71
71
|
summary: Verify Amazon in app purchases with IAP 2
|
72
72
|
test_files:
|
73
73
|
- spec/spec_helper.rb
|
74
74
|
- spec/specs/client_spec.rb
|
75
|
+
has_rdoc:
|