monza 1.3.8 → 1.3.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fac0efa28ee221749882e9916647707b5bc971b4e69d2130b060fe4edae76116
4
- data.tar.gz: c868069c62c1d57b6e1342c7461913f098784ef78fa4a0ee49918154b8ce996e
3
+ metadata.gz: 352558d4ab4014083ece9624e7361abf178e7930b85f734eadc1b7bf7f2ae251
4
+ data.tar.gz: 59fbaee7463a1e76f28cca6ab8f8d677b6461249d7f5e84d6eb1fe75f21117ee
5
5
  SHA512:
6
- metadata.gz: eb65d134815099da534f82ca3209b5a5c829ba911b5b6c51e9fb8b0b9d8eea6fbb42229342a2071726fa99380848d9b7523c5abea1218fb5ba57ac69d39ebbf3
7
- data.tar.gz: bfb32460c257fc67f167faaedeba680b9045f6fa9b4a67be10418739536ea181956c5005a08c7f923fa649949644ad9f3fedecb2f4fed983522c783f99c3bcdf
6
+ metadata.gz: ab12f4fa179c45495ada0bd05b6a706cdd94948aff4af9dd9f8e84c00adc19b49fec36b52483687989b92a2c25e679a5a7ce205d47d713ee22e15140dae4de30
7
+ data.tar.gz: 1911b4a5e8dea7cfd152394fcb92b58affc6a5a0c610f9b8a48ff70a073296889209de90d06725ab640b9aab074126e98d91089338c3a42e6412b7dbe7f70995
@@ -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
- 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}\"")
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
- integer_class = Object.const_get("Integer")
12
- else
13
- integer_class = Object.const_get("Fixnum")
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
- class TrueClass
24
- def to_i; 1; end
25
- def to_bool; self; end
26
- end
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
- class FalseClass
29
- def to_i; 0; end
30
- def to_bool; self; end
31
- end
25
+ refine TrueClass do
26
+ def to_i; 1; end
27
+ def to_bool; self; end
28
+ end
32
29
 
33
- class NilClass
34
- def to_bool; false; end
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
@@ -1,5 +1,7 @@
1
1
  module Monza
2
2
  class RenewalInfo
3
+ using BoolTypecasting
4
+
3
5
  # Receipt Fields Documentation
4
6
  # https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ReceiptFields.html#//apple_ref/doc/uid/TP40010573-CH106-SW1
5
7
 
@@ -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
- @latest_receipt = attributes['latest_receipt']
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
  #
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Monza
4
- VERSION = '1.3.8'
4
+ VERSION = '1.3.9'
5
5
  end
@@ -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.10"
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.8
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-07-18 00:00:00.000000000 Z
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.10'
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.10'
54
+ version: '2.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement