Class: Verona::Receipt
- Inherits:
-
Object
- Object
- Verona::Receipt
- Defined in:
- lib/verona/receipt.rb
Instance Attribute Summary collapse
-
#consumed ⇒ Object
readonly
The consumption state of the purchase.
-
#developer_payload ⇒ Object
readonly
Developer payload.
-
#package_name ⇒ Object
readonly
The package name for the application.
-
#product_id ⇒ Object
readonly
The product identifier of the item that was purchased.
-
#purchase_date ⇒ Object
readonly
The date and time this transaction occurred.
-
#purchase_state ⇒ Object
readonly
The state of the purchase.
-
#token ⇒ Object
readonly
The receipt’s token.
Class Method Summary collapse
- .verify(data, options = {}) ⇒ Object (also: validate)
- .verify!(data, options = {}) ⇒ Object (also: validate!)
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Receipt
constructor
A new instance of Receipt.
- #to_h ⇒ Object
- #to_json ⇒ Object
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
#consumed ⇒ Object (readonly)
The consumption state of the purchase
21 22 23 |
# File 'lib/verona/receipt.rb', line 21 def consumed @consumed end |
#developer_payload ⇒ Object (readonly)
Developer payload
24 25 26 |
# File 'lib/verona/receipt.rb', line 24 def developer_payload @developer_payload end |
#package_name ⇒ Object (readonly)
The package name for the application
6 7 8 |
# File 'lib/verona/receipt.rb', line 6 def package_name @package_name end |
#product_id ⇒ Object (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_date ⇒ Object (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_state ⇒ Object (readonly)
The state of the purchase
18 19 20 |
# File 'lib/verona/receipt.rb', line 18 def purchase_state @purchase_state end |
#token ⇒ Object (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, = {}) return verify!(data, ) rescue false end |
Instance Method Details
#to_h ⇒ Object
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_json ⇒ Object
47 48 49 |
# File 'lib/verona/receipt.rb', line 47 def to_json self.to_h.to_json end |