Class: CandyCheck::AppStore::Receipt

Inherits:
Object
  • Object
show all
Includes:
Utils::AttributeReader
Defined in:
lib/candy_check/app_store/receipt.rb

Overview

Describes a successful response from the AppStore verification server

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Receipt

Initializes a new instance which bases on a JSON result from Apple’s verification server



13
14
15
# File 'lib/candy_check/app_store/receipt.rb', line 13

def initialize(attributes)
  @attributes = attributes
end

Instance Attribute Details

#attributesHash (readonly)



8
9
10
# File 'lib/candy_check/app_store/receipt.rb', line 8

def attributes
  @attributes
end

Instance Method Details

#app_versionString

The version number for the app



39
40
41
# File 'lib/candy_check/app_store/receipt.rb', line 39

def app_version
  read('bvrs')
end

#bundle_identifierString

The app’s bundle identifier



45
46
47
# File 'lib/candy_check/app_store/receipt.rb', line 45

def bundle_identifier
  read('bid')
end

#cancellation_dateDateTime

The date of when Apple has canceled this transaction. From Apple’s documentation: “Treat a canceled receipt the same as if no purchase had ever been made.”



84
85
86
# File 'lib/candy_check/app_store/receipt.rb', line 84

def cancellation_date
  read_datetime_from_string('cancellation_date')
end

#expires_dateDateTime

The date of a subscription’s expiration



90
91
92
# File 'lib/candy_check/app_store/receipt.rb', line 90

def expires_date
  read_datetime_from_string('expires_date')
end

#is_trial_periodObject

rubocop:disable PredicateName



95
96
97
98
# File 'lib/candy_check/app_store/receipt.rb', line 95

def is_trial_period
  # rubocop:enable PredicateName
  read_bool('is_trial_period')
end

#item_idString

The app’s item id of the product



57
58
59
# File 'lib/candy_check/app_store/receipt.rb', line 57

def item_id
  read('item_id')
end

#original_purchase_dateDateTime

The original purchase date which might differ from the actual purchase date for restored products



76
77
78
# File 'lib/candy_check/app_store/receipt.rb', line 76

def original_purchase_date
  read_datetime_from_string('original_purchase_date')
end

#original_transaction_idString

The receipt’s original transaction id which might differ from the transaction id for restored products



33
34
35
# File 'lib/candy_check/app_store/receipt.rb', line 33

def original_transaction_id
  read('original_transaction_id')
end

#product_idString

The app’s identifier of the product (SKU)



51
52
53
# File 'lib/candy_check/app_store/receipt.rb', line 51

def product_id
  read('product_id')
end

#purchase_dateDateTime

The purchase date



69
70
71
# File 'lib/candy_check/app_store/receipt.rb', line 69

def purchase_date
  read_datetime_from_string('purchase_date')
end

#quantityFixnum

The quantity of the product



63
64
65
# File 'lib/candy_check/app_store/receipt.rb', line 63

def quantity
  read_integer('quantity')
end

#transaction_idString

The receipt’s transaction id



26
27
28
# File 'lib/candy_check/app_store/receipt.rb', line 26

def transaction_id
  read('transaction_id')
end

#valid?Boolean

In most cases a receipt is a valid transaction except when the transaction was canceled.



20
21
22
# File 'lib/candy_check/app_store/receipt.rb', line 20

def valid?
  !has?('cancellation_date')
end