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
24 25 26 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 24 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.
10 11 12 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 10 def subscription_purchase @subscription_purchase end |
Instance Method Details
#auto_renewing? ⇒ bool
Get the auto renewal status as given by Google
75 76 77 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 75 def auto_renewing? @subscription_purchase.auto_renewing end |
#cancel_reason ⇒ Integer
Get the cancel reason, as given by Google
94 95 96 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 94 def cancel_reason @subscription_purchase.cancel_reason end |
#canceled_at ⇒ DateTime
Get cancellation time in UTC
149 150 151 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 149 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
63 64 65 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 63 def canceled_by_user? cancel_reason == PAYMENT_CANCELED end |
#developer_payload ⇒ String
Get developer-specified supplemental information about the order
106 107 108 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 106 def developer_payload @subscription_purchase.developer_payload end |
#expired? ⇒ bool
Check if the expiration date is passed
30 31 32 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 30 def expired? overdue_days > 0 end |
#expires_at ⇒ DateTime
Get expiration time in UTC
143 144 145 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 143 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
124 125 126 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 124 def expiry_time_millis @subscription_purchase.expiry_time_millis end |
#kind ⇒ String
Get the kind of subscription as stored in the android publisher service
100 101 102 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 100 def kind @subscription_purchase.kind end |
#overdue_days ⇒ Integer
Get number of overdue days. If this is negative, it is not overdue.
69 70 71 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 69 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
57 58 59 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 57 def payment_failed? cancel_reason == PAYMENT_FAILED end |
#payment_pending? ⇒ bool
see if payment is pending
51 52 53 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 51 def payment_pending? payment_state == PAYMENT_PENDING end |
#payment_received? ⇒ bool
see if payment is ok
45 46 47 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 45 def payment_received? payment_state == PAYMENT_RECEIVED end |
#payment_state ⇒ Integer
Get the payment state as given by Google
81 82 83 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 81 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
88 89 90 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 88 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
112 113 114 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 112 def price_currency_code @subscription_purchase.price_currency_code end |
#start_time_millis ⇒ Integer
Get start time for subscription in milliseconds since Epoch
118 119 120 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 118 def start_time_millis @subscription_purchase.start_time_millis end |
#starts_at ⇒ DateTime
Get start time in UTC
137 138 139 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 137 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.
38 39 40 41 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 38 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.
131 132 133 |
# File 'lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb', line 131 def user_cancellation_time_millis @subscription_purchase.user_cancellation_time_millis if canceled_by_user? end |