Class: Monza::VerificationResponse
- Inherits:
-
Object
- Object
- Monza::VerificationResponse
- Defined in:
- lib/monza/verification_response.rb
Defined Under Namespace
Classes: VerificationError
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#latest_receipt ⇒ Object
readonly
Returns the value of attribute latest_receipt.
-
#latest_receipt_info ⇒ Object
readonly
Returns the value of attribute latest_receipt_info.
-
#original_json_response ⇒ Object
readonly
Returns the value of attribute original_json_response.
-
#receipt ⇒ Object
readonly
Returns the value of attribute receipt.
-
#renewal_info ⇒ Object
readonly
Returns the value of attribute renewal_info.
- #status ⇒ Object readonly
Instance Method Summary collapse
-
#initialize(attributes) ⇒ VerificationResponse
constructor
A new instance of VerificationResponse.
-
#is_any_subscription_active? ⇒ Boolean
Deprecated, only left here for backwards compatibility, please use is_subscription_active?.
- #is_subscription_active? ⇒ Boolean
- #latest_active_transaction_receipt ⇒ Object
- #latest_expiry_date ⇒ Object
Constructor Details
#initialize(attributes) ⇒ VerificationResponse
Returns a new instance of VerificationResponse.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/monza/verification_response.rb', line 16 def initialize(attributes) @original_json_response = attributes @status = attributes['status'] @environment = attributes['environment'] @receipt = Receipt.new(attributes['receipt']) @latest_receipt_info = [] latest_receipt_info = attributes['latest_receipt_info'] || attributes.dig('unified_receipt', 'latest_receipt_info') case latest_receipt_info when Array latest_receipt_info.each do |transaction_receipt_attributes| @latest_receipt_info << TransactionReceipt.new(transaction_receipt_attributes) end when Hash @latest_receipt_info << TransactionReceipt.new(latest_receipt_info) end @renewal_info = [] if attributes['pending_renewal_info'] attributes['pending_renewal_info'].each do |renewal_info_attributes| @renewal_info << RenewalInfo.new(renewal_info_attributes) end end @latest_receipt = attributes['latest_receipt'] || attributes.dig('unified_receipt', 'latest_receipt') end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
8 9 10 |
# File 'lib/monza/verification_response.rb', line 8 def environment @environment end |
#latest_receipt ⇒ Object (readonly)
Returns the value of attribute latest_receipt.
12 13 14 |
# File 'lib/monza/verification_response.rb', line 12 def latest_receipt @latest_receipt end |
#latest_receipt_info ⇒ Object (readonly)
Returns the value of attribute latest_receipt_info.
10 11 12 |
# File 'lib/monza/verification_response.rb', line 10 def latest_receipt_info @latest_receipt_info end |
#original_json_response ⇒ Object (readonly)
Returns the value of attribute original_json_response.
13 14 15 |
# File 'lib/monza/verification_response.rb', line 13 def original_json_response @original_json_response end |
#receipt ⇒ Object (readonly)
Returns the value of attribute receipt.
9 10 11 |
# File 'lib/monza/verification_response.rb', line 9 def receipt @receipt end |
#renewal_info ⇒ Object (readonly)
Returns the value of attribute renewal_info.
11 12 13 |
# File 'lib/monza/verification_response.rb', line 11 def renewal_info @renewal_info end |
#status ⇒ Object (readonly)
7 8 9 |
# File 'lib/monza/verification_response.rb', line 7 def status @status end |
Instance Method Details
#is_any_subscription_active? ⇒ Boolean
Deprecated, only left here for backwards compatibility, please use is_subscription_active?
47 48 49 |
# File 'lib/monza/verification_response.rb', line 47 def is_any_subscription_active? is_subscription_active? end |
#is_subscription_active? ⇒ Boolean
42 43 44 |
# File 'lib/monza/verification_response.rb', line 42 def is_subscription_active? latest_active_transaction_receipt.present? end |
#latest_active_transaction_receipt ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/monza/verification_response.rb', line 51 def latest_active_transaction_receipt latest_active_sub = @latest_receipt_info .reject(&:cancellation_date) .select(&:expires_date_ms) .max_by(&:expires_date_ms) if latest_active_sub && latest_active_sub.expires_date_ms >= Time.zone.now return latest_active_sub else return nil end end |
#latest_expiry_date ⇒ Object
64 65 66 |
# File 'lib/monza/verification_response.rb', line 64 def latest_expiry_date @latest_receipt_info.last.expires_date_ms if @latest_receipt_info.last end |