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

Parameters:

  • attributes (Hash)


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

def initialize(attributes)
  @attributes = attributes
end

Instance Attribute Details

#attributesHash (readonly)

Returns the raw attributes returned from the server.

Returns:

  • (Hash)

    the raw attributes returned from the server



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

Returns:

  • (String)


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

Returns:

  • (String)


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

Returns:

  • (DateTime)


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

Returns:

  • (DateTime)


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 Naming/PredicateName



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

def is_trial_period
  # rubocop:enable Naming/PredicateName
  read_bool("is_trial_period")
end

#item_idString

The app’s item id of the product

Returns:

  • (String)


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

Returns:

  • (DateTime)


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

Returns:

  • (String)


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)

Returns:

  • (String)


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

Returns:

  • (DateTime)


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

def purchase_date
  read_datetime_from_string("purchase_date")
end

#quantityInteger

The quantity of the product

Returns:

  • (Integer)


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

Returns:

  • (String)


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.

Returns:

  • (Boolean)


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

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