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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8e2ea5bc00fa3737874d5678fc2dc174da91728a
4
- data.tar.gz: ab7cb4564cf7c4a8c4e5d8ba46d162acd1c1f505
3
+ metadata.gz: d71a8c3964b2b99ff8b1ba4b55f58fd2e96c788a
4
+ data.tar.gz: 254d4f47003497c215295325218777a09be96831
5
5
  SHA512:
6
- metadata.gz: 60f70a661b9c409e6d73b55e65ce97f5e9fac4281fc5d1b97fb71acf1bd9303becba9b73aa7afddb0b79c72e4666e9ba6c84313b589f5d347da5a0cfea6b1574
7
- data.tar.gz: 2021fbb12b7a4ed45a3538b2a62fe57977930c29456775c40d03e42287c7da5a63c3af82c4decbc0fc75c19874570c648705351f420e453e081b88bf98a8389c
6
+ metadata.gz: f6b717e79ad9a3aca11c30ab8729b4f7ad2467b66375249445ec65031ba3dbdbb53beca6d27e9ae4f803f67fea8f8890211eb1d9c09016eb6906a8017977ee97
7
+ data.tar.gz: 67787a971156ee81687e054369a7cf7d4229a88659f45181bf94418e2068eb2a64f9190d0d96627b75b5ef7b9dba7c6e4de828e7c4f29605c1e71acec8aa2c42
data/README.md CHANGED
@@ -1,14 +1,18 @@
1
- # Amazon::Iap
1
+ # Amazon::Iap2
2
+
3
+ [![Codeship Status for blinkist/amazon-iap2](https://www.codeship.io/projects/e6c868f0-2f7e-0132-4314-02ba1e9dff5b/status)](https://www.codeship.io/projects/39519)
4
+ [![Dependency Status](https://www.versioneye.com/user/projects/5645bcefb5b03d002200084e/badge.svg?style=flat)](https://www.versioneye.com/user/projects/5645bcefb5b03d002200084e)
5
+ [![Gem Version](https://badge.fury.io/rb/amazon-iap2.svg)](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-iap'
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-iap
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::Iap::Result is returned from both methods, the attributes being the underscored versions
54
- of the hash keys returned in the JSON object. For convenience, we also add `start_time` and `end_time` attributes
55
- which are `Time` representations of the milliseconds returned in `start_date` and `end_date` respectively. E.g.,
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.renew 'some-user-id', 'some-purchase-token'
74
-
75
- result.class.name # "Amazon::Iap::Result"
76
- result.purchase_token # "some-new-purchase-token"
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::Iap::Result class](lib/amazon/iap/result.rb) for specifics.
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-purchase-token'
89
- rescue Amazon::Iap::Exceptions::InternalError => e
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::Iap::Exceptions::Exception` so you can rescue from
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', 'some-purchase-token'
100
- rescue Amazon::Iap::Exceptions::InternalError => e
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::Iap::Exceptions::Exception => e
89
+ rescue Amazon::Iap2::Exceptions::Exception => e
103
90
  # log the exception
104
91
  end
105
92
  ```
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Amazon
2
2
  module Iap2
3
- VERSION = "0.1"
3
+ VERSION = "0.2"
4
4
  end
5
5
  end
@@ -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(response["cancelDate"])
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" => (Time.now.to_i + 2629743) * 1000, # one month from now
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.1'
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: 2014-10-02 00:00:00.000000000 Z
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.2
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: