Class: CandyCheck::PlayStore::Receipt

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

Overview

Describes a successful response from the Google verification server

Constant Summary collapse

PURCHASE_STATE_PURCHASED =

Purchased product (0 is purchased, don’t ask me why)

0
CONSUMPTION_STATE_CONSUMED =

A consumed product

1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Receipt

Initializes a new instance which bases on a JSON result from Google API servers



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

def initialize(attributes)
  @attributes = attributes
end

Instance Attribute Details

#attributesHash (readonly)



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

def attributes
  @attributes
end

Instance Method Details

#consumed?Boolean

A purchased product may already be consumed. In this case you should grant candy even if it’s valid.



34
35
36
# File 'lib/candy_check/play_store/receipt.rb', line 34

def consumed?
  consumption_state == CONSUMPTION_STATE_CONSUMED
end

#consumption_stateFixnum

The consumption state of the inapp product. Possible values are:

* 0: Yet to be consumed
* 1: Consumed


50
51
52
# File 'lib/candy_check/play_store/receipt.rb', line 50

def consumption_state
  read_integer('consumptionState')
end

#developer_payloadString

The developer payload which was used when buying the product



56
57
58
# File 'lib/candy_check/play_store/receipt.rb', line 56

def developer_payload
  read('developerPayload')
end

#kindString

This kind represents an inappPurchase object in the androidpublisher service.



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

def kind
  read('kind')
end

#purchase_stateFixnum

The purchase state of the order. Possible values are:

* 0: Purchased
* 1: Cancelled


42
43
44
# File 'lib/candy_check/play_store/receipt.rb', line 42

def purchase_state
  read_integer('purchaseState')
end

#purchase_time_millisFixnum

The time the product was purchased, in milliseconds since the epoch (Jan 1, 1970)



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

def purchase_time_millis
  read_integer('purchaseTimeMillis')
end

#purchased_atDateTime

The date and time the product was purchased



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

def purchased_at
  read_datetime_from_millis('purchaseTimeMillis')
end

#valid?Boolean

A product may be purchased or canceled. Ensure a receipt is valid before granting some candy



27
28
29
# File 'lib/candy_check/play_store/receipt.rb', line 27

def valid?
  purchase_state == PURCHASE_STATE_PURCHASED
end