Class: CandyCheck::PlayStore::SubscriptionPurchases::SubscriptionPurchase
- Inherits:
-
Object
- Object
- CandyCheck::PlayStore::SubscriptionPurchases::SubscriptionPurchase
- Includes:
- Utils::AttributeReader
- Defined in:
- lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb
Overview
Describes a successfully validated subscription
Constant Summary collapse
- PAYMENT_PENDING =
The payment of the subscription is pending (paymentState)
0
- PAYMENT_RECEIVED =
The payment of the subscript is received (paymentState)
1
- PAYMENT_CANCELED =
The subscription was canceled by the user (cancelReason)
0
- PAYMENT_FAILED =
The payment failed during processing (cancelReason)
1
Instance Attribute Summary collapse
-
#subscription_purchase ⇒ Google::Apis::AndroidpublisherV3::SubscriptionPurchase
readonly
The raw subscription purchase from google-api-client.
Instance Method Summary collapse
-
#auto_renewing? ⇒ bool
Get the auto renewal status as given by Google.
-
#cancel_reason ⇒ Integer
Get the cancel reason, as given by Google.
-
#canceled_at ⇒ DateTime
Get cancellation time in UTC.
-
#canceled_by_user? ⇒ bool
see if this the user has canceled its subscription.
-
#developer_payload ⇒ String
Get developer-specified supplemental information about the order.
-
#expired? ⇒ bool
Check if the expiration date is passed.
-
#expires_at ⇒ DateTime
Get expiration time in UTC.
-
#expiry_time_millis ⇒ Integer
Get expiry time for subscription in milliseconds since Epoch.
-
#initialize(subscription_purchase) ⇒ SubscriptionPurchase
constructor
Initializes a new instance which bases on a JSON result from Google's servers.
-
#kind ⇒ String
Get the kind of subscription as stored in the android publisher service.
-
#overdue_days ⇒ Integer
Get number of overdue days.
-
#payment_failed? ⇒ bool
see if payment has failed according to Google.
-
#payment_pending? ⇒ bool
see if payment is pending.
-
#payment_received? ⇒ bool
see if payment is ok.
-
#payment_state ⇒ Integer
Get the payment state as given by Google.
-
#price_amount_micros ⇒ Integer
Get the price amount for the subscription in micros in the payed currency.
-
#price_currency_code ⇒ String
Get the currency code in ISO 4217 format, e.g.
-
#start_time_millis ⇒ Integer
Get start time for subscription in milliseconds since Epoch.
-
#starts_at ⇒ DateTime
Get start time in UTC.
-
#trial? ⇒ bool
Check if in trial.
-
#user_cancellation_time_millis ⇒ Integer
Get cancellation time for subscription in milliseconds since Epoch.
Constructor Details
#initialize(subscription_purchase) ⇒ SubscriptionPurchase
Initializes a new instance which bases on a JSON result from Google's servers
23 24 25 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 23 def initialize(subscription_purchase) @subscription_purchase = subscription_purchase end |
Instance Attribute Details
#subscription_purchase ⇒ Google::Apis::AndroidpublisherV3::SubscriptionPurchase (readonly)
Returns the raw subscription purchase from google-api-client.
9 10 11 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 9 def subscription_purchase @subscription_purchase end |
Instance Method Details
#auto_renewing? ⇒ bool
Get the auto renewal status as given by Google
74 75 76 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 74 def auto_renewing? @subscription_purchase.auto_renewing end |
#cancel_reason ⇒ Integer
Get the cancel reason, as given by Google
93 94 95 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 93 def cancel_reason @subscription_purchase.cancel_reason end |
#canceled_at ⇒ DateTime
Get cancellation time in UTC
148 149 150 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 148 def canceled_at Time.at(user_cancellation_time_millis / 1000).utc.to_datetime if user_cancellation_time_millis end |
#canceled_by_user? ⇒ bool
see if this the user has canceled its subscription
62 63 64 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 62 def canceled_by_user? cancel_reason == PAYMENT_CANCELED end |
#developer_payload ⇒ String
Get developer-specified supplemental information about the order
105 106 107 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 105 def developer_payload @subscription_purchase.developer_payload end |
#expired? ⇒ bool
Check if the expiration date is passed
29 30 31 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 29 def expired? overdue_days > 0 end |
#expires_at ⇒ DateTime
Get expiration time in UTC
142 143 144 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 142 def expires_at Time.at(expiry_time_millis / 1000).utc.to_datetime end |
#expiry_time_millis ⇒ Integer
Get expiry time for subscription in milliseconds since Epoch
123 124 125 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 123 def expiry_time_millis @subscription_purchase.expiry_time_millis end |
#kind ⇒ String
Get the kind of subscription as stored in the android publisher service
99 100 101 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 99 def kind @subscription_purchase.kind end |
#overdue_days ⇒ Integer
Get number of overdue days. If this is negative, it is not overdue.
68 69 70 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 68 def overdue_days (Time.now.utc.to_date - expires_at.to_date).to_i end |
#payment_failed? ⇒ bool
see if payment has failed according to Google
56 57 58 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 56 def payment_failed? cancel_reason == PAYMENT_FAILED end |
#payment_pending? ⇒ bool
see if payment is pending
50 51 52 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 50 def payment_pending? payment_state == PAYMENT_PENDING end |
#payment_received? ⇒ bool
see if payment is ok
44 45 46 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 44 def payment_received? payment_state == PAYMENT_RECEIVED end |
#payment_state ⇒ Integer
Get the payment state as given by Google
80 81 82 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 80 def payment_state @subscription_purchase.payment_state end |
#price_amount_micros ⇒ Integer
Get the price amount for the subscription in micros in the payed currency
87 88 89 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 87 def price_amount_micros @subscription_purchase.price_amount_micros end |
#price_currency_code ⇒ String
Get the currency code in ISO 4217 format, e.g. “GBP” for British pounds
111 112 113 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 111 def price_currency_code @subscription_purchase.price_currency_code end |
#start_time_millis ⇒ Integer
Get start time for subscription in milliseconds since Epoch
117 118 119 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 117 def start_time_millis @subscription_purchase.start_time_millis end |
#starts_at ⇒ DateTime
Get start time in UTC
136 137 138 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 136 def starts_at Time.at(start_time_millis / 1000).utc.to_datetime end |
#trial? ⇒ bool
Check if in trial. This is actually not given by Google, but we assume that it is a trial going on if the paid amount is 0 and renewal is activated.
37 38 39 40 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 37 def trial? price_is_zero = price_amount_micros == 0 price_is_zero && payment_received? end |
#user_cancellation_time_millis ⇒ Integer
Get cancellation time for subscription in milliseconds since Epoch. Only present if cancelReason is 0.
130 131 132 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 130 def user_cancellation_time_millis @subscription_purchase.user_cancellation_time_millis if canceled_by_user? end |