Class: Verona::Receipt

Inherits:
Object
  • Object
show all
Defined in:
lib/verona/receipt.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Receipt

Returns a new instance of Receipt.



26
27
28
29
30
31
32
33
34
# File 'lib/verona/receipt.rb', line 26

def initialize(attributes = {})
  @package_name = attributes[:package_name] if attributes[:package_name]
  @product_id = attributes[:product_id] if attributes[:product_id]
  @token = attributes[:token] if attributes[:token]
  @purchase_date = Time.at(attributes['purchaseTime'].to_i / 1000) if attributes['purchaseTime']
  @purchase_state = Integer(attributes['purchaseState']) if attributes['purchaseState']
  @consumed = Integer(attributes['consumptionState']) if attributes['consumptionState']
  @developer_payload = attributes['developerPayload'] if attributes['developerPayload']
end

Instance Attribute Details

#consumedObject (readonly)

The consumption state of the purchase



21
22
23
# File 'lib/verona/receipt.rb', line 21

def consumed
  @consumed
end

#developer_payloadObject (readonly)

Developer payload



24
25
26
# File 'lib/verona/receipt.rb', line 24

def developer_payload
  @developer_payload
end

#package_nameObject (readonly)

The package name for the application



6
7
8
# File 'lib/verona/receipt.rb', line 6

def package_name
  @package_name
end

#product_idObject (readonly)

The product identifier of the item that was purchased.



9
10
11
# File 'lib/verona/receipt.rb', line 9

def product_id
  @product_id
end

#purchase_dateObject (readonly)

The date and time this transaction occurred.



15
16
17
# File 'lib/verona/receipt.rb', line 15

def purchase_date
  @purchase_date
end

#purchase_stateObject (readonly)

The state of the purchase



18
19
20
# File 'lib/verona/receipt.rb', line 18

def purchase_state
  @purchase_state
end

#tokenObject (readonly)

The receipt’s token



12
13
14
# File 'lib/verona/receipt.rb', line 12

def token
  @token
end

Class Method Details

.verify(data, options = {}) ⇒ Object Also known as: validate



52
53
54
# File 'lib/verona/receipt.rb', line 52

def verify(data, options = {})
  return verify!(data, options) rescue false
end

.verify!(data, options = {}) ⇒ Object Also known as: validate!



56
57
58
59
# File 'lib/verona/receipt.rb', line 56

def verify!(data, options = {})
  client = Client.new
  client.verify!(data, options) rescue false
end

Instance Method Details

#to_hObject



36
37
38
39
40
41
42
43
44
45
# File 'lib/verona/receipt.rb', line 36

def to_h
  {
    :package_name => @package_name,
    :product_id => @product_id,
    :purchase_date => @purchase_date.httpdate,
    :purchase_state => @purchase_state,
    :consumed => @consumed,
    :developer_payload => (@developer_payload rescue nil)
  }
end

#to_jsonObject



47
48
49
# File 'lib/verona/receipt.rb', line 47

def to_json
  self.to_h.to_json
end