Class: ItunesReceiptValidator::Transaction
- Inherits:
-
Object
- Object
- ItunesReceiptValidator::Transaction
- Defined in:
- lib/itunes_receipt_validator/transaction.rb
Overview
ItunesReceiptValidator::Transaction
Constant Summary collapse
- ATTR_MAP =
{ id: :transaction_id, original_id: :original_transaction_id, product_id: :product_id, quantity: :quantity, web_order_line_item_id: proc do |hash| hash[:web_order_line_item_id].to_s if hash.fetch(:web_order_line_item_id, 0).to_i > 0 end, trial_period: ->(hash) { hash[:is_trial_period] == 'true' }, purchased_at: proc do |hash| parse_date(hash[:purchase_date_ms] || hash[:purchase_date]) end, first_purchased_at: proc do |hash| parse_date hash[:original_purchase_date_ms] || hash[:original_purchase_date] end, cancelled_at: proc do |hash| parse_date(hash[:cancelled_date_ms] || hash[:cancelled_date]) end, expires_at: proc do |hash| if hash[:bid] parse_date(hash[:expires_date] || hash[:expires_date_formatted]) else parse_date(hash[:expires_date_ms] || hash[:expires_date]) end end }.freeze
Instance Attribute Summary collapse
-
#cancelled_at ⇒ Object
readonly
Returns the value of attribute cancelled_at.
-
#expires_at ⇒ Object
readonly
Returns the value of attribute expires_at.
-
#first_purchased_at ⇒ Object
readonly
Returns the value of attribute first_purchased_at.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#original_id ⇒ Object
readonly
Returns the value of attribute original_id.
-
#product_id ⇒ Object
readonly
Returns the value of attribute product_id.
-
#purchased_at ⇒ Object
readonly
Returns the value of attribute purchased_at.
-
#quantity ⇒ Object
readonly
Returns the value of attribute quantity.
-
#receipt ⇒ Object
readonly
Returns the value of attribute receipt.
-
#trial_period ⇒ Object
readonly
Returns the value of attribute trial_period.
-
#web_order_line_item_id ⇒ Object
readonly
Returns the value of attribute web_order_line_item_id.
Instance Method Summary collapse
- #auto_renewing? ⇒ Boolean
- #cancelled? ⇒ Boolean
- #expired? ⇒ Boolean
-
#initialize(hash, receipt) ⇒ Transaction
constructor
A new instance of Transaction.
- #latest ⇒ Object
- #trial_period? ⇒ Boolean
Constructor Details
#initialize(hash, receipt) ⇒ Transaction
Returns a new instance of Transaction.
42 43 44 45 |
# File 'lib/itunes_receipt_validator/transaction.rb', line 42 def initialize(hash, receipt) normalize(hash) @receipt = receipt end |
Instance Attribute Details
#cancelled_at ⇒ Object
Returns the value of attribute cancelled_at.
38 39 40 |
# File 'lib/itunes_receipt_validator/transaction.rb', line 38 def cancelled_at @cancelled_at end |
#expires_at ⇒ Object
Returns the value of attribute expires_at.
38 39 40 |
# File 'lib/itunes_receipt_validator/transaction.rb', line 38 def expires_at @expires_at end |
#first_purchased_at ⇒ Object
Returns the value of attribute first_purchased_at.
38 39 40 |
# File 'lib/itunes_receipt_validator/transaction.rb', line 38 def first_purchased_at @first_purchased_at end |
#id ⇒ Object
Returns the value of attribute id.
38 39 40 |
# File 'lib/itunes_receipt_validator/transaction.rb', line 38 def id @id end |
#original_id ⇒ Object
Returns the value of attribute original_id.
38 39 40 |
# File 'lib/itunes_receipt_validator/transaction.rb', line 38 def original_id @original_id end |
#product_id ⇒ Object
Returns the value of attribute product_id.
38 39 40 |
# File 'lib/itunes_receipt_validator/transaction.rb', line 38 def product_id @product_id end |
#purchased_at ⇒ Object
Returns the value of attribute purchased_at.
38 39 40 |
# File 'lib/itunes_receipt_validator/transaction.rb', line 38 def purchased_at @purchased_at end |
#quantity ⇒ Object
Returns the value of attribute quantity.
38 39 40 |
# File 'lib/itunes_receipt_validator/transaction.rb', line 38 def quantity @quantity end |
#receipt ⇒ Object (readonly)
Returns the value of attribute receipt.
38 39 40 |
# File 'lib/itunes_receipt_validator/transaction.rb', line 38 def receipt @receipt end |
#trial_period ⇒ Object
Returns the value of attribute trial_period.
38 39 40 |
# File 'lib/itunes_receipt_validator/transaction.rb', line 38 def trial_period @trial_period end |
#web_order_line_item_id ⇒ Object
Returns the value of attribute web_order_line_item_id.
38 39 40 |
# File 'lib/itunes_receipt_validator/transaction.rb', line 38 def web_order_line_item_id @web_order_line_item_id end |
Instance Method Details
#auto_renewing? ⇒ Boolean
57 58 59 |
# File 'lib/itunes_receipt_validator/transaction.rb', line 57 def auto_renewing? !web_order_line_item_id.nil? end |
#cancelled? ⇒ Boolean
53 54 55 |
# File 'lib/itunes_receipt_validator/transaction.rb', line 53 def cancelled? !cancelled_at.nil? end |
#expired? ⇒ Boolean
47 48 49 50 51 |
# File 'lib/itunes_receipt_validator/transaction.rb', line 47 def expired? !auto_renewing? || receipt.remote.expired? || latest.expires_at < Time.now.utc end |
#latest ⇒ Object
65 66 67 |
# File 'lib/itunes_receipt_validator/transaction.rb', line 65 def latest receipt.latest_transactions.where(original_id: original_id).last end |
#trial_period? ⇒ Boolean
61 62 63 |
# File 'lib/itunes_receipt_validator/transaction.rb', line 61 def trial_period? trial_period end |