monza 1.3.8 → 1.3.9
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/lib/monza.rb +1 -1
- data/lib/monza/bool_typecasting.rb +31 -28
- data/lib/monza/renewal_info.rb +2 -0
- data/lib/monza/status_response.rb +88 -1
- data/lib/monza/transaction_receipt.rb +11 -3
- data/lib/monza/version.rb +1 -1
- data/monza.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 352558d4ab4014083ece9624e7361abf178e7930b85f734eadc1b7bf7f2ae251
|
4
|
+
data.tar.gz: 59fbaee7463a1e76f28cca6ab8f8d677b6461249d7f5e84d6eb1fe75f21117ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab12f4fa179c45495ada0bd05b6a706cdd94948aff4af9dd9f8e84c00adc19b49fec36b52483687989b92a2c25e679a5a7ce205d47d713ee22e15140dae4de30
|
7
|
+
data.tar.gz: 1911b4a5e8dea7cfd152394fcb92b58affc6a5a0c610f9b8a48ff70a073296889209de90d06725ab640b9aab074126e98d91089338c3a42e6412b7dbe7f70995
|
data/lib/monza.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require "monza/bool_typecasting"
|
1
2
|
require "monza/version"
|
2
3
|
require "monza/client"
|
3
4
|
require "monza/renewal_info"
|
@@ -5,5 +6,4 @@ require "monza/verification_response"
|
|
5
6
|
require "monza/status_response"
|
6
7
|
require "monza/receipt"
|
7
8
|
require "monza/transaction_receipt"
|
8
|
-
require "monza/bool_typecasting"
|
9
9
|
require "monza/config"
|
@@ -1,35 +1,38 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module BoolTypecasting
|
2
|
+
refine String do
|
3
|
+
def to_bool
|
4
|
+
return true if self == true || self =~ (/^(true|t|yes|y|1)$/i)
|
5
|
+
return false if self == false || self.empty? || self =~ (/^(false|f|no|n|0)$/i)
|
6
|
+
raise ArgumentError.new("invalid value for Boolean: \"#{self}\"")
|
7
|
+
end
|
8
|
+
# if using Rails empty? can be changed for blank?
|
6
9
|
end
|
7
|
-
# if using Rails empty? can be changed for blank?
|
8
|
-
end
|
9
10
|
|
10
|
-
if RUBY_VERSION >= "2.4"
|
11
|
-
|
12
|
-
else
|
13
|
-
|
14
|
-
end
|
15
|
-
integer_class::class_eval do
|
16
|
-
def to_bool
|
17
|
-
return true if self == 1
|
18
|
-
return false if self == 0
|
19
|
-
raise ArgumentError.new("invalid value for Boolean: \"#{self}\"")
|
11
|
+
if RUBY_VERSION >= "2.4"
|
12
|
+
integer_class = Object.const_get("Integer")
|
13
|
+
else
|
14
|
+
integer_class = Object.const_get("Fixnum")
|
20
15
|
end
|
21
|
-
end
|
22
16
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
17
|
+
refine integer_class do
|
18
|
+
def to_bool
|
19
|
+
return true if self == 1
|
20
|
+
return false if self == 0
|
21
|
+
raise ArgumentError.new("invalid value for Boolean: \"#{self}\"")
|
22
|
+
end
|
23
|
+
end
|
27
24
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
25
|
+
refine TrueClass do
|
26
|
+
def to_i; 1; end
|
27
|
+
def to_bool; self; end
|
28
|
+
end
|
32
29
|
|
33
|
-
|
34
|
-
|
30
|
+
refine FalseClass do
|
31
|
+
def to_i; 0; end
|
32
|
+
def to_bool; self; end
|
33
|
+
end
|
34
|
+
|
35
|
+
refine NilClass do
|
36
|
+
def to_bool; false; end
|
37
|
+
end
|
35
38
|
end
|
data/lib/monza/renewal_info.rb
CHANGED
@@ -1,17 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'time'
|
2
3
|
|
3
4
|
module Monza
|
4
5
|
class StatusResponse
|
6
|
+
using BoolTypecasting
|
7
|
+
|
5
8
|
# https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html
|
9
|
+
# https://developer.apple.com/documentation/appstoreservernotifications/responsebody
|
10
|
+
module Type
|
11
|
+
CANCEL = 'CANCEL'
|
12
|
+
DID_CHANGE_RENEWAL_PREF = 'DID_CHANGE_RENEWAL_PREF'
|
13
|
+
DID_CHANGE_RENEWAL_STATUS = 'DID_CHANGE_RENEWAL_STATUS'
|
14
|
+
DID_FAIL_TO_RENEW = 'DID_FAIL_TO_RENEW'
|
15
|
+
DID_RECOVER = 'DID_RECOVER'
|
16
|
+
INITIAL_BUY = 'INITIAL_BUY'
|
17
|
+
INTERACTIVE_RENEWAL = 'INTERACTIVE_RENEWAL'
|
18
|
+
RENEWAL = 'RENEWAL'
|
19
|
+
REFUND = 'REFUND'
|
20
|
+
end
|
21
|
+
|
6
22
|
|
7
23
|
attr_reader :auto_renew_product_id
|
8
24
|
attr_reader :auto_renew_status
|
25
|
+
attr_reader :auto_renew_status_change_date
|
26
|
+
attr_reader :auto_renew_status_change_date_ms
|
27
|
+
attr_reader :auto_renew_status_change_date_pst
|
9
28
|
attr_reader :environment
|
29
|
+
attr_reader :expiration_intent
|
30
|
+
|
10
31
|
attr_reader :latest_receipt
|
11
32
|
|
12
33
|
attr_reader :notification_type
|
13
34
|
attr_reader :password
|
14
35
|
|
36
|
+
attr_reader :latest_receipt_info
|
37
|
+
attr_reader :renewal_info
|
15
38
|
attr_reader :bundle_id
|
16
39
|
attr_reader :bvrs
|
17
40
|
attr_reader :item_id
|
@@ -42,8 +65,20 @@ module Monza
|
|
42
65
|
|
43
66
|
@auto_renew_product_id = attributes['auto_renew_product_id']
|
44
67
|
@auto_renew_status = attributes['auto_renew_status'].to_bool
|
68
|
+
if attributes['auto_renew_status_change_date']
|
69
|
+
@auto_renew_status_change_date = DateTime.parse(attributes['auto_renew_status_change_date'])
|
70
|
+
end
|
71
|
+
if attributes['auto_renew_status_change_date_ms']
|
72
|
+
@auto_renew_status_change_date_ms = Time.zone.at(attributes['auto_renew_status_change_date_ms'].to_i / 1000)
|
73
|
+
end
|
74
|
+
if attributes['auto_renew_status_change_date_pst']
|
75
|
+
@auto_renew_status_change_date_pst = DateTime.parse(attributes['auto_renew_status_change_date_pst'].gsub("America/Los_Angeles", "PST"))
|
76
|
+
end
|
77
|
+
|
45
78
|
@environment = attributes['environment']
|
46
|
-
@
|
79
|
+
@expiration_intent = attributes['expiration_intent']
|
80
|
+
|
81
|
+
@latest_receipt = attributes['latest_receipt'] || attributes['latest_expired_receipt']
|
47
82
|
@notification_type = attributes['notification_type']
|
48
83
|
|
49
84
|
if attributes['password']
|
@@ -95,6 +130,22 @@ module Monza
|
|
95
130
|
if latest_receipt_info['cancellation_date']
|
96
131
|
@cancellation_date = DateTime.parse(latest_receipt_info['cancellation_date'])
|
97
132
|
end
|
133
|
+
|
134
|
+
@latest_receipt_info = []
|
135
|
+
case attributes.dig('unified_receipt', 'latest_receipt_info')
|
136
|
+
when Array
|
137
|
+
attributes.dig('unified_receipt', 'latest_receipt_info').each do |transaction_receipt_attributes|
|
138
|
+
@latest_receipt_info << TransactionReceipt.new(transaction_receipt_attributes)
|
139
|
+
end
|
140
|
+
when Hash
|
141
|
+
@latest_receipt_info << TransactionReceipt.new(attributes.dig('unified_receipt', 'latest_receipt_info'))
|
142
|
+
end
|
143
|
+
@renewal_info = []
|
144
|
+
if attributes.dig('unified_receipt', 'pending_renewal_info')
|
145
|
+
attributes.dig('unified_receipt', 'pending_renewal_info').each do |renewal_info_attributes|
|
146
|
+
@renewal_info << RenewalInfo.new(renewal_info_attributes)
|
147
|
+
end
|
148
|
+
end
|
98
149
|
end
|
99
150
|
|
100
151
|
def date_for_pacific_time pt
|
@@ -103,6 +154,42 @@ module Monza
|
|
103
154
|
ActiveSupport::TimeZone["Pacific Time (US & Canada)"].parse(pt).to_datetime
|
104
155
|
end
|
105
156
|
|
157
|
+
def cancel?
|
158
|
+
notification_type == Type::CANCEL
|
159
|
+
end
|
160
|
+
|
161
|
+
def did_change_renewal_pref?
|
162
|
+
notification_type == Type::DID_CHANGE_RENEWAL_PREF
|
163
|
+
end
|
164
|
+
|
165
|
+
def did_change_renewal_status?
|
166
|
+
notification_type == Type::DID_CHANGE_RENEWAL_STATUS
|
167
|
+
end
|
168
|
+
|
169
|
+
def did_fail_to_renew?
|
170
|
+
notification_type == Type::DID_FAIL_TO_RENEW
|
171
|
+
end
|
172
|
+
|
173
|
+
def did_recover?
|
174
|
+
notification_type == Type::DID_RECOVER
|
175
|
+
end
|
176
|
+
|
177
|
+
def initial_buy?
|
178
|
+
notification_type == Type::INITIAL_BUY
|
179
|
+
end
|
180
|
+
|
181
|
+
def interactive_renewal?
|
182
|
+
notification_type == Type::INTERACTIVE_RENEWAL
|
183
|
+
end
|
184
|
+
|
185
|
+
def renewal?
|
186
|
+
notification_type == Type::RENEWAL
|
187
|
+
end
|
188
|
+
|
189
|
+
def refund?
|
190
|
+
notification_type == Type::REFUND
|
191
|
+
end
|
192
|
+
|
106
193
|
end # class
|
107
194
|
end # module
|
108
195
|
|
@@ -3,6 +3,8 @@ require 'active_support/core_ext/time'
|
|
3
3
|
|
4
4
|
module Monza
|
5
5
|
class TransactionReceipt
|
6
|
+
using BoolTypecasting
|
7
|
+
|
6
8
|
# Receipt Fields Documentation
|
7
9
|
# https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ReceiptFields.html#//apple_ref/doc/uid/TP40010573-CH106-SW1
|
8
10
|
|
@@ -22,10 +24,15 @@ module Monza
|
|
22
24
|
attr_reader :expires_date_ms
|
23
25
|
attr_reader :expires_date_pst
|
24
26
|
attr_reader :is_trial_period
|
27
|
+
attr_reader :cancellation_reason
|
25
28
|
attr_reader :cancellation_date
|
29
|
+
attr_reader :cancellation_date_ms
|
30
|
+
attr_reader :cancellation_date_pst
|
26
31
|
attr_reader :is_in_intro_offer_period
|
32
|
+
attr_reader :original_attributes
|
27
33
|
|
28
34
|
def initialize(attributes)
|
35
|
+
@original_attributes = attributes
|
29
36
|
@quantity = attributes['quantity'].to_i
|
30
37
|
@product_id = attributes['product_id']
|
31
38
|
@transaction_id = attributes['transaction_id']
|
@@ -37,6 +44,10 @@ module Monza
|
|
37
44
|
@original_purchase_date_ms = Time.zone.at(attributes['original_purchase_date_ms'].to_i / 1000)
|
38
45
|
@original_purchase_date_pst = DateTime.parse(attributes['original_purchase_date_pst'].gsub("America/Los_Angeles","PST")) if attributes['original_purchase_date_pst']
|
39
46
|
@web_order_line_item_id = attributes['web_order_line_item_id']
|
47
|
+
@cancellation_reason = attributes['cancellation_reason'] if attributes['cancellation_reason']
|
48
|
+
@cancellation_date = DateTime.parse(attributes['cancellation_date']) if attributes['cancellation_date']
|
49
|
+
@cancellation_date_ms = Time.zone.at(attributes['cancellation_date_ms'].to_i / 1000) if attributes['cancellation_date_ms']
|
50
|
+
@cancellation_date_pst = DateTime.parse(attributes['cancellation_date_pst'].gsub("America/Los_Angeles","PST")) if attributes['cancellation_date_pst']
|
40
51
|
|
41
52
|
if attributes['expires_date']
|
42
53
|
begin
|
@@ -61,9 +72,6 @@ module Monza
|
|
61
72
|
if attributes['is_in_intro_offer_period']
|
62
73
|
@is_in_intro_offer_period = attributes['is_in_intro_offer_period'].to_bool
|
63
74
|
end
|
64
|
-
if attributes['cancellation_date']
|
65
|
-
@cancellation_date = DateTime.parse(attributes['cancellation_date'])
|
66
|
-
end
|
67
75
|
end # end initialize
|
68
76
|
|
69
77
|
#
|
data/lib/monza/version.rb
CHANGED
data/monza.gemspec
CHANGED
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_dependency "json"
|
31
31
|
spec.add_dependency "activesupport"
|
32
32
|
|
33
|
-
spec.add_development_dependency "bundler", "~> 1
|
33
|
+
spec.add_development_dependency "bundler", "~> 2.1"
|
34
34
|
spec.add_development_dependency "rake", "~> 10.0"
|
35
35
|
spec.add_development_dependency "rspec"
|
36
36
|
end
|
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: 1.3.
|
4
|
+
version: 1.3.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Garza
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '1
|
47
|
+
version: '2.1'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '1
|
54
|
+
version: '2.1'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|