Class: CandyCheck::PlayStore::ProductPurchases::ProductPurchase
- Inherits:
-
Object
- Object
- CandyCheck::PlayStore::ProductPurchases::ProductPurchase
- 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
-
#product_purchase ⇒ Google::Apis::AndroidpublisherV3::ProductPurchase
readonly
Returns the raw ProductPurchase from google-api-client gem.
Instance Method Summary collapse
-
#consumed? ⇒ Boolean
A purchased product may already be consumed.
-
#consumption_state ⇒ Integer
The consumption state of the inapp product.
-
#developer_payload ⇒ String
The developer payload which was used when buying the product.
-
#initialize(product_purchase) ⇒ ProductPurchase
constructor
Initializes a new instance which bases on a JSON result from PlayStore API servers.
-
#kind ⇒ String
This kind represents an inappPurchase object in the androidpublisher service.
-
#order_id ⇒ String
The order id.
-
#purchase_state ⇒ Integer
The purchase state of the order.
-
#purchase_time_millis ⇒ Integer
The time the product was purchased, in milliseconds since the epoch (Jan 1, 1970).
-
#purchased_at ⇒ DateTime
The date and time the product was purchased.
-
#valid? ⇒ Boolean
A product may be purchased or canceled.
Constructor Details
#initialize(product_purchase) ⇒ ProductPurchase
Initializes a new instance which bases on a JSON result from PlayStore API servers
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_purchase ⇒ Google::Apis::AndroidpublisherV3::ProductPurchase (readonly)
Returns the raw ProductPurchase from google-api-client gem
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.
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_state ⇒ Integer
The consumption state of the inapp product. Possible values are:
* 0: Yet to be consumed
* 1: Consumed
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_payload ⇒ String
The developer payload which was used when buying the product
44 45 46 |
# File 'lib/candy_check/play_store/product_purchases/product_purchase.rb', line 44 def developer_payload @product_purchase.developer_payload end |
#kind ⇒ String
This kind represents an inappPurchase object in the androidpublisher service.
51 52 53 |
# File 'lib/candy_check/play_store/product_purchases/product_purchase.rb', line 51 def kind @product_purchase.kind end |
#order_id ⇒ String
The order id
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_state ⇒ Integer
The purchase state of the order. Possible values are:
* 0: Purchased
* 1: Cancelled
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_millis ⇒ Integer
The time the product was purchased, in milliseconds since the epoch (Jan 1, 1970)
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_at ⇒ DateTime
The date and time the product was purchased
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
71 72 73 |
# File 'lib/candy_check/play_store/product_purchases/product_purchase.rb', line 71 def valid? purchase_state == PURCHASE_STATE_PURCHASED end |