Class: CandyCheck::PlayStore::Subscription
- Inherits:
-
Object
- Object
- CandyCheck::PlayStore::Subscription
- Includes:
- Utils::AttributeReader
- Defined in:
- lib/candy_check/play_store/subscription.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
-
#attributes ⇒ Hash
readonly
The raw attributes returned from the server.
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_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(attributes) ⇒ Subscription
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.
Constructor Details
#initialize(attributes) ⇒ Subscription
Initializes a new instance which bases on a JSON result from Google’s servers
22 23 24 |
# File 'lib/candy_check/play_store/subscription.rb', line 22 def initialize(attributes) @attributes = attributes end |
Instance Attribute Details
#attributes ⇒ Hash (readonly)
Returns the raw attributes returned from the server.
8 9 10 |
# File 'lib/candy_check/play_store/subscription.rb', line 8 def attributes @attributes end |
Instance Method Details
#auto_renewing? ⇒ bool
Get the auto renewal status as given by Google
73 74 75 |
# File 'lib/candy_check/play_store/subscription.rb', line 73 def auto_renewing? read_bool('autoRenewing') end |
#cancel_reason ⇒ Integer
Get the cancel reason, as given by Google
92 93 94 |
# File 'lib/candy_check/play_store/subscription.rb', line 92 def cancel_reason read_integer('cancelReason') end |
#canceled_by_user? ⇒ bool
see if this the user has canceled its subscription
61 62 63 |
# File 'lib/candy_check/play_store/subscription.rb', line 61 def canceled_by_user? cancel_reason == PAYMENT_CANCELED end |
#developer_payload ⇒ String
Get developer-specified supplemental information about the order
104 105 106 |
# File 'lib/candy_check/play_store/subscription.rb', line 104 def developer_payload read('developerPayload') end |
#expired? ⇒ bool
Check if the expiration date is passed
28 29 30 |
# File 'lib/candy_check/play_store/subscription.rb', line 28 def expired? overdue_days > 0 end |
#expires_at ⇒ DateTime
Get expiration time in UTC
134 135 136 |
# File 'lib/candy_check/play_store/subscription.rb', line 134 def expires_at read_datetime_from_millis('expiryTimeMillis') end |
#expiry_time_millis ⇒ Integer
Get expiry time for subscription in milliseconds since Epoch
122 123 124 |
# File 'lib/candy_check/play_store/subscription.rb', line 122 def expiry_time_millis read_integer('expiryTimeMillis') end |
#kind ⇒ String
Get the kind of subscription as stored in the android publisher service
98 99 100 |
# File 'lib/candy_check/play_store/subscription.rb', line 98 def kind read('kind') end |
#overdue_days ⇒ Integer
Get number of overdue days. If this is negative, it is not overdue.
67 68 69 |
# File 'lib/candy_check/play_store/subscription.rb', line 67 def overdue_days (Date.today - expires_at.to_date).to_i end |
#payment_failed? ⇒ bool
see if payment has failed according to Google
55 56 57 |
# File 'lib/candy_check/play_store/subscription.rb', line 55 def payment_failed? cancel_reason == PAYMENT_FAILED end |
#payment_pending? ⇒ bool
see if payment is pending
49 50 51 |
# File 'lib/candy_check/play_store/subscription.rb', line 49 def payment_pending? payment_state == PAYMENT_PENDING end |
#payment_received? ⇒ bool
see if payment is ok
43 44 45 |
# File 'lib/candy_check/play_store/subscription.rb', line 43 def payment_received? payment_state == PAYMENT_RECEIVED end |
#payment_state ⇒ Integer
Get the payment state as given by Google
79 80 81 |
# File 'lib/candy_check/play_store/subscription.rb', line 79 def payment_state read_integer('paymentState') end |
#price_amount_micros ⇒ Integer
Get the price amount for the subscription in micros in the payed currency
86 87 88 |
# File 'lib/candy_check/play_store/subscription.rb', line 86 def price_amount_micros read_integer('priceAmountMicros') end |
#price_currency_code ⇒ String
Get the currency code in ISO 4217 format, e.g. “GBP” for British pounds
110 111 112 |
# File 'lib/candy_check/play_store/subscription.rb', line 110 def price_currency_code read('priceCurrencyCode') end |
#start_time_millis ⇒ Integer
Get start time for subscription in milliseconds since Epoch
116 117 118 |
# File 'lib/candy_check/play_store/subscription.rb', line 116 def start_time_millis read_integer('startTimeMillis') end |
#starts_at ⇒ DateTime
Get start time in UTC
128 129 130 |
# File 'lib/candy_check/play_store/subscription.rb', line 128 def starts_at read_datetime_from_millis('startTimeMillis') 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.
36 37 38 39 |
# File 'lib/candy_check/play_store/subscription.rb', line 36 def trial? price_is_zero = price_amount_micros == 0 price_is_zero && payment_received? end |