Class: CandyCheck::PlayStore::ProductPurchases::ProductPurchase

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

Overview

Describes a successful response from the PlayStore 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(product_purchase) ⇒ ProductPurchase

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

Parameters:

  • product_purchase (Google::Apis::AndroidpublisherV3::ProductPurchase)


22
23
24
# File 'lib/candy_check/play_store/product_purchases/product_purchase.rb', line 22

def initialize(product_purchase)
  @product_purchase = product_purchase
end

Instance Attribute Details

#product_purchaseGoogle::Apis::AndroidpublisherV3::ProductPurchase (readonly)

Returns the raw ProductPurchase from google-api-client gem

Returns:

  • (Google::Apis::AndroidpublisherV3::ProductPurchase)


10
11
12
# File 'lib/candy_check/play_store/product_purchases/product_purchase.rb', line 10

def product_purchase
  @product_purchase
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.

Returns:

  • (Boolean)


78
79
80
# File 'lib/candy_check/play_store/product_purchases/product_purchase.rb', line 78

def consumed?
  consumption_state == CONSUMPTION_STATE_CONSUMED
end

#consumption_stateInteger

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

* 0: Yet to be consumed
* 1: Consumed

Returns:

  • (Integer)


38
39
40
# File 'lib/candy_check/play_store/product_purchases/product_purchase.rb', line 38

def consumption_state
  @product_purchase.consumption_state
end

#developer_payloadString

The developer payload which was used when buying the product

Returns:

  • (String)


44
45
46
# File 'lib/candy_check/play_store/product_purchases/product_purchase.rb', line 44

def developer_payload
  @product_purchase.developer_payload
end

#kindString

This kind represents an inappPurchase object in the androidpublisher service.

Returns:

  • (String)


51
52
53
# File 'lib/candy_check/play_store/product_purchases/product_purchase.rb', line 51

def kind
  @product_purchase.kind
end

#order_idString

The order id

Returns:

  • (String)


57
58
59
# File 'lib/candy_check/play_store/product_purchases/product_purchase.rb', line 57

def order_id
  @product_purchase.order_id
end

#purchase_stateInteger

The purchase state of the order. Possible values are:

* 0: Purchased
* 1: Cancelled

Returns:

  • (Integer)


30
31
32
# File 'lib/candy_check/play_store/product_purchases/product_purchase.rb', line 30

def purchase_state
  @product_purchase.purchase_state
end

#purchase_time_millisInteger

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

Returns:

  • (Integer)


64
65
66
# File 'lib/candy_check/play_store/product_purchases/product_purchase.rb', line 64

def purchase_time_millis
  @product_purchase.purchase_time_millis
end

#purchased_atDateTime

The date and time the product was purchased

Returns:

  • (DateTime)


84
85
86
# File 'lib/candy_check/play_store/product_purchases/product_purchase.rb', line 84

def purchased_at
  Time.at(purchase_time_millis / 1000).utc.to_datetime
end

#valid?Boolean

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

Returns:

  • (Boolean)


71
72
73
# File 'lib/candy_check/play_store/product_purchases/product_purchase.rb', line 71

def valid?
  purchase_state == PURCHASE_STATE_PURCHASED
end