monza 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -6
- data/lib/monza/bool_typecasting.rb +30 -0
- data/lib/monza/receipt.rb +7 -7
- data/lib/monza/transaction_receipt.rb +18 -13
- data/lib/monza/verification_response.rb +2 -2
- data/lib/monza/version.rb +1 -1
- data/lib/monza.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20ee01b81cd55484be9f5f9a621211e7479e6fb0
|
4
|
+
data.tar.gz: 0ed6fdacbc5c7e7d1fed8fe79a244a60da819a90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f8421aeed55dce4d237185488611e52cf920e1b8a7a202813d9a7fc796e3ecfdcedba98f5186eb505a33db89853561677ac0327b1cfb8a45dd11b6ec29392a8
|
7
|
+
data.tar.gz: f25763953a76f71f0c4e99192f9a71c1eb0827a7ed1427ca6dec15d821f540a5a1b9f565d921409a7783ea5da9fa183a934bff0cf95ba13ed59ae1bd1cdfd21d
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
|
1
|
+
#![monza_asset](https://cloud.githubusercontent.com/assets/1076706/16257552/1baa36f8-380e-11e6-8730-cbbd1fe73c6c.png)
|
2
2
|
|
3
|
-
Monza is a ruby gem that makes
|
3
|
+
#### Monza is a ruby gem that makes In-App Purchase receipt and Auto-Renewable subscription validation easy.
|
4
4
|
|
5
5
|
You should always validate receipts on the server, in [Apple's words] (https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html#//apple_ref/doc/uid/TP40010573-CH104-SW1):
|
6
6
|
> Use a trusted server to communicate with the App Store. Using your own server lets you design your app to recognize and trust only your server, and lets you ensure that your server connects with the App Store server. It is not possible to build a trusted connection between a user’s device and the App Store directly because you don’t control either end of that connection.
|
@@ -39,19 +39,19 @@ response = Monza::Receipt.verify(data, options)
|
|
39
39
|
response.is_subscription_active? # => true or false
|
40
40
|
|
41
41
|
# Check most recent expiry date
|
42
|
-
#
|
43
|
-
response.latest_expiry_date # => Fri, 17 Jun 2016 01:57:28 +
|
42
|
+
# ActiveSupport::TimeWithZone
|
43
|
+
response.latest_expiry_date # => Fri, 17 Jun 2016 01:57:28 UTC +00:00
|
44
44
|
|
45
45
|
```
|
46
46
|
|
47
47
|
##### Response Objects
|
48
48
|
```ruby
|
49
49
|
# Receipt object
|
50
|
-
# See Receipt class
|
50
|
+
# See Receipt class or sample JSON below for full attributes
|
51
51
|
response.receipt
|
52
52
|
|
53
53
|
# Receipt In App Transactions
|
54
|
-
# Returns array of TransactionReceipt objects, see TransactionReceipt class
|
54
|
+
# Returns array of TransactionReceipt objects, see TransactionReceipt class or sample JSON below for full attributes
|
55
55
|
response.receipt.in_app
|
56
56
|
|
57
57
|
# Receipt Latest Transactions List, use these instead if in_app to ensure you always have the latest
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class String
|
2
|
+
def to_bool
|
3
|
+
return true if self == true || self =~ (/^(true|t|yes|y|1)$/i)
|
4
|
+
return false if self == false || self.empty? || self =~ (/^(false|f|no|n|0)$/i)
|
5
|
+
raise ArgumentError.new("invalid value for Boolean: \"#{self}\"")
|
6
|
+
end
|
7
|
+
# if using Rails empty? can be changed for blank?
|
8
|
+
end
|
9
|
+
|
10
|
+
class Fixnum
|
11
|
+
def to_bool
|
12
|
+
return true if self == 1
|
13
|
+
return false if self == 0
|
14
|
+
raise ArgumentError.new("invalid value for Boolean: \"#{self}\"")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class TrueClass
|
19
|
+
def to_i; 1; end
|
20
|
+
def to_bool; self; end
|
21
|
+
end
|
22
|
+
|
23
|
+
class FalseClass
|
24
|
+
def to_i; 0; end
|
25
|
+
def to_bool; self; end
|
26
|
+
end
|
27
|
+
|
28
|
+
class NilClass
|
29
|
+
def to_bool; false; end
|
30
|
+
end
|
data/lib/monza/receipt.rb
CHANGED
@@ -38,14 +38,14 @@ module Monza
|
|
38
38
|
@application_version = attributes['application_version']
|
39
39
|
@download_id = attributes['download_id']
|
40
40
|
@receipt_creation_date = DateTime.parse(attributes['receipt_creation_date'])
|
41
|
-
@receipt_creation_date_ms = Time.at(attributes['receipt_creation_date_ms'].to_i / 1000)
|
42
|
-
@receipt_creation_date_pst = DateTime.parse(attributes['receipt_creation_date_pst'])
|
41
|
+
@receipt_creation_date_ms = Time.zone.at(attributes['receipt_creation_date_ms'].to_i / 1000)
|
42
|
+
@receipt_creation_date_pst = DateTime.parse(attributes['receipt_creation_date_pst'].gsub("America/Los_Angeles","PST"))
|
43
43
|
@request_date = DateTime.parse(attributes['request_date'])
|
44
|
-
@request_date_ms = Time.at(attributes['request_date_ms'].to_i / 1000)
|
45
|
-
@request_date_pst = DateTime.parse(attributes['request_date_pst'])
|
44
|
+
@request_date_ms = Time.zone.at(attributes['request_date_ms'].to_i / 1000)
|
45
|
+
@request_date_pst = DateTime.parse(attributes['request_date_pst'].gsub("America/Los_Angeles","PST"))
|
46
46
|
@original_purchase_date = DateTime.parse(attributes['original_purchase_date'])
|
47
|
-
@original_purchase_date_ms = Time.at(attributes['original_purchase_date_ms'].to_i / 1000)
|
48
|
-
@original_purchase_date_pst = DateTime.parse(attributes['original_purchase_date_pst'])
|
47
|
+
@original_purchase_date_ms = Time.zone.at(attributes['original_purchase_date_ms'].to_i / 1000)
|
48
|
+
@original_purchase_date_pst = DateTime.parse(attributes['original_purchase_date_pst'].gsub("America/Los_Angeles","PST"))
|
49
49
|
@original_application_version = attributes['original_application_version']
|
50
50
|
|
51
51
|
if attributes['version_external_identifier']
|
@@ -55,7 +55,7 @@ module Monza
|
|
55
55
|
@app_item_id = attributes['app_item_id']
|
56
56
|
end
|
57
57
|
if attributes['expiration_date']
|
58
|
-
@expires_at = Time.at(attributes['expiration_date'].to_i / 1000)
|
58
|
+
@expires_at = Time.zone.at(attributes['expiration_date'].to_i / 1000)
|
59
59
|
end
|
60
60
|
|
61
61
|
@in_app = []
|
@@ -28,34 +28,39 @@ module Monza
|
|
28
28
|
@transaction_id = attributes['transaction_id']
|
29
29
|
@original_transaction_id = attributes['original_transaction_id']
|
30
30
|
@purchase_date = DateTime.parse(attributes['purchase_date']) if attributes['purchase_date']
|
31
|
-
@purchase_date_ms = Time.at(attributes['purchase_date_ms'].to_i / 1000)
|
32
|
-
@purchase_date_pst = DateTime.parse(attributes['purchase_date_pst']) if attributes['purchase_date_pst']
|
31
|
+
@purchase_date_ms = Time.zone.at(attributes['purchase_date_ms'].to_i / 1000)
|
32
|
+
@purchase_date_pst = DateTime.parse(attributes['purchase_date_pst'].gsub("America/Los_Angeles","PST")) if attributes['purchase_date_pst']
|
33
33
|
@original_purchase_date = DateTime.parse(attributes['original_purchase_date']) if attributes['original_purchase_date']
|
34
|
-
@original_purchase_date_ms = Time.at(attributes['original_purchase_date_ms'].to_i / 1000)
|
35
|
-
@original_purchase_date_pst = DateTime.parse(attributes['original_purchase_date_pst']) if attributes['original_purchase_date_pst']
|
34
|
+
@original_purchase_date_ms = Time.zone.at(attributes['original_purchase_date_ms'].to_i / 1000)
|
35
|
+
@original_purchase_date_pst = DateTime.parse(attributes['original_purchase_date_pst'].gsub("America/Los_Angeles","PST")) if attributes['original_purchase_date_pst']
|
36
36
|
@web_order_line_item_id = attributes['web_order_line_item_id']
|
37
37
|
|
38
38
|
if attributes['expires_date']
|
39
39
|
@expires_date = DateTime.parse(attributes['expires_date'])
|
40
40
|
end
|
41
41
|
if attributes['expires_date_ms']
|
42
|
-
@expires_date_ms = Time.at(attributes['expires_date_ms'].to_i / 1000)
|
42
|
+
@expires_date_ms = Time.zone.at(attributes['expires_date_ms'].to_i / 1000)
|
43
43
|
end
|
44
44
|
if attributes['expires_date_pst']
|
45
|
-
@expires_date_pst = DateTime.parse(attributes['expires_date_pst'])
|
45
|
+
@expires_date_pst = DateTime.parse(attributes['expires_date_pst'].gsub("America/Los_Angeles","PST"))
|
46
46
|
end
|
47
47
|
if attributes['is_trial_period']
|
48
48
|
@is_trial_period = attributes['is_trial_period'].to_bool
|
49
49
|
end
|
50
50
|
end # end initialize
|
51
51
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
52
|
+
#
|
53
|
+
# Depcrecating - don't use these
|
54
|
+
# These will only work if the user never cancels and then resubscribes
|
55
|
+
# The original_transaction_id does not reset after the user resubscribes
|
56
|
+
#
|
57
|
+
# def is_renewal?
|
58
|
+
# !is_first_transaction?
|
59
|
+
# end
|
60
|
+
#
|
61
|
+
# def is_first_transaction?
|
62
|
+
# @original_transaction_id == @transaction_id
|
63
|
+
# end
|
59
64
|
|
60
65
|
|
61
66
|
end # end class
|
@@ -26,14 +26,14 @@ module Monza
|
|
26
26
|
|
27
27
|
def is_subscription_active?
|
28
28
|
if @latest_receipt_info.last
|
29
|
-
@latest_receipt_info.last.
|
29
|
+
@latest_receipt_info.last.expires_date_ms >= Time.zone.now
|
30
30
|
else
|
31
31
|
false
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
35
|
def latest_expiry_date
|
36
|
-
@latest_receipt_info.last.
|
36
|
+
@latest_receipt_info.last.expires_date_ms if @latest_receipt_info.last
|
37
37
|
end
|
38
38
|
|
39
39
|
class VerificationError < StandardError
|
data/lib/monza/version.rb
CHANGED
data/lib/monza.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: monza
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Garza
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- bin/console
|
86
86
|
- bin/setup
|
87
87
|
- lib/monza.rb
|
88
|
+
- lib/monza/bool_typecasting.rb
|
88
89
|
- lib/monza/client.rb
|
89
90
|
- lib/monza/receipt.rb
|
90
91
|
- lib/monza/transaction_receipt.rb
|