Class: Honeycrisp::Receipt
- Inherits:
-
Object
- Object
- Honeycrisp::Receipt
- Defined in:
- lib/honeycrisp/receipt.rb
Instance Attribute Summary collapse
-
#app_item_id ⇒ Object
Receipt fields.
-
#application_version ⇒ Object
Receipt fields.
-
#bundle_id ⇒ Object
Receipt fields.
-
#environment ⇒ Object
Meta fields.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#in_app_purchases ⇒ Object
readonly
Returns the value of attribute in_app_purchases.
-
#latest_receipt ⇒ Object
Receipt fields.
-
#original_application_version ⇒ Object
Receipt fields.
-
#original_purchase_date_ms ⇒ Object
Receipt fields.
-
#raw ⇒ Object
Meta fields.
-
#receipt_type ⇒ Object
Receipt fields.
-
#status ⇒ Object
Meta fields.
-
#subscriptions ⇒ Object
readonly
Returns the value of attribute subscriptions.
-
#version_external_identifier ⇒ Object
Receipt fields.
Instance Method Summary collapse
-
#initialize(receipt_hash) ⇒ Receipt
constructor
A new instance of Receipt.
- #latest_purchase ⇒ Object
- #latest_subscription ⇒ Object
- #original_purchase_date ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(receipt_hash) ⇒ Receipt
Returns a new instance of Receipt.
13 14 15 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 41 42 43 44 45 |
# File 'lib/honeycrisp/receipt.rb', line 13 def initialize(receipt_hash) # Initialize the errors array @in_app_purchases, @subscriptions = [], [] # Set the meta-fields self.raw = receipt_hash self.status = receipt_hash['status'].to_i self.environment = receipt_hash['environment'] self.latest_receipt = receipt_hash['latest_receipt'] # Set the receipt fields receipt = receipt_hash.fetch('receipt', {}) subscriptions = receipt_hash.fetch('latest_receipt_info', []) purchases = receipt.fetch('in_app', []) receipt.each do |k, v| send("#{k}=", v) if respond_to?("#{k}=".to_sym) end purchases.each do |purchase_hash| @in_app_purchases << Honeycrisp::InAppPurchase.new(purchase_hash) end subscriptions.each do |subscription_hash| @subscriptions << Honeycrisp::Subscription.new(subscription_hash) end @in_app_purchases.sort_by{ |s| s.purchase_date_ms.to_i } @subscriptions.sort_by{ |s| s.expires_date_ms.to_i } # Return self self end |
Instance Attribute Details
#app_item_id ⇒ Object
Receipt fields
7 8 9 |
# File 'lib/honeycrisp/receipt.rb', line 7 def app_item_id @app_item_id end |
#application_version ⇒ Object
Receipt fields
7 8 9 |
# File 'lib/honeycrisp/receipt.rb', line 7 def application_version @application_version end |
#bundle_id ⇒ Object
Receipt fields
7 8 9 |
# File 'lib/honeycrisp/receipt.rb', line 7 def bundle_id @bundle_id end |
#environment ⇒ Object
Meta fields
4 5 6 |
# File 'lib/honeycrisp/receipt.rb', line 4 def environment @environment end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
11 12 13 |
# File 'lib/honeycrisp/receipt.rb', line 11 def errors @errors end |
#in_app_purchases ⇒ Object (readonly)
Returns the value of attribute in_app_purchases.
11 12 13 |
# File 'lib/honeycrisp/receipt.rb', line 11 def in_app_purchases @in_app_purchases end |
#latest_receipt ⇒ Object
Receipt fields
7 8 9 |
# File 'lib/honeycrisp/receipt.rb', line 7 def latest_receipt @latest_receipt end |
#original_application_version ⇒ Object
Receipt fields
7 8 9 |
# File 'lib/honeycrisp/receipt.rb', line 7 def original_application_version @original_application_version end |
#original_purchase_date_ms ⇒ Object
Receipt fields
7 8 9 |
# File 'lib/honeycrisp/receipt.rb', line 7 def original_purchase_date_ms @original_purchase_date_ms end |
#raw ⇒ Object
Meta fields
4 5 6 |
# File 'lib/honeycrisp/receipt.rb', line 4 def raw @raw end |
#receipt_type ⇒ Object
Receipt fields
7 8 9 |
# File 'lib/honeycrisp/receipt.rb', line 7 def receipt_type @receipt_type end |
#status ⇒ Object
Meta fields
4 5 6 |
# File 'lib/honeycrisp/receipt.rb', line 4 def status @status end |
#subscriptions ⇒ Object (readonly)
Returns the value of attribute subscriptions.
11 12 13 |
# File 'lib/honeycrisp/receipt.rb', line 11 def subscriptions @subscriptions end |
#version_external_identifier ⇒ Object
Receipt fields
7 8 9 |
# File 'lib/honeycrisp/receipt.rb', line 7 def version_external_identifier @version_external_identifier end |
Instance Method Details
#latest_purchase ⇒ Object
51 52 53 |
# File 'lib/honeycrisp/receipt.rb', line 51 def latest_purchase @in_app_purchases.last end |
#latest_subscription ⇒ Object
55 56 57 |
# File 'lib/honeycrisp/receipt.rb', line 55 def latest_subscription @subscriptions.last end |
#original_purchase_date ⇒ Object
47 48 49 |
# File 'lib/honeycrisp/receipt.rb', line 47 def original_purchase_date Time.at(original_purchase_date_ms.to_i / 1000).utc end |
#valid? ⇒ Boolean
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/honeycrisp/receipt.rb', line 59 def valid? # Clear out any errors so we can revalidate @errors = [] # Check the status @errors << Honeycrisp::Itunes::Error.new(self.status) if self.status != 0 # Valid if errors array is empty @errors.length == 0 end |