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.”



78
79
80
# File 'lib/candy_check/app_store/receipt.rb', line 78

def cancellation_date
  read_datetime_from_string('cancellation_date')
end

#item_idString

The app’s item id of the product



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

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



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

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

#purchase_dateDateTime

The purchase date



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

def purchase_date
  read_datetime_from_string('purchase_date')
end

#quantityFixnum

The quantity of the product



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

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