Class: CandyCheck::PlayStore::Subscription

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Subscription

Initializes a new instance which bases on a JSON result from Google’s servers

Parameters:

  • attributes (Hash)


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

def initialize(attributes)
  @attributes = attributes
end

Instance Attribute Details

#attributesHash (readonly)

Returns the raw attributes returned from the server.

Returns:

  • (Hash)

    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

Returns:

  • (bool)

    true if renewing automatically, false otherwise



73
74
75
# File 'lib/candy_check/play_store/subscription.rb', line 73

def auto_renewing?
  read_bool('autoRenewing')
end

#cancel_reasonInteger

Get the cancel reason, as given by Google

Returns:

  • (Integer)


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

Returns:

  • (bool)


61
62
63
# File 'lib/candy_check/play_store/subscription.rb', line 61

def canceled_by_user?
  cancel_reason == PAYMENT_CANCELED
end

#developer_payloadString

Get developer-specified supplemental information about the order

Returns:

  • (String)


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

Returns:

  • (bool)


28
29
30
# File 'lib/candy_check/play_store/subscription.rb', line 28

def expired?
  overdue_days > 0
end

#expires_atDateTime

Get expiration time in UTC

Returns:

  • (DateTime)


134
135
136
# File 'lib/candy_check/play_store/subscription.rb', line 134

def expires_at
  read_datetime_from_millis('expiryTimeMillis')
end

#expiry_time_millisInteger

Get expiry time for subscription in milliseconds since Epoch

Returns:

  • (Integer)


122
123
124
# File 'lib/candy_check/play_store/subscription.rb', line 122

def expiry_time_millis
  read_integer('expiryTimeMillis')
end

#kindString

Get the kind of subscription as stored in the android publisher service

Returns:

  • (String)


98
99
100
# File 'lib/candy_check/play_store/subscription.rb', line 98

def kind
  read('kind')
end

#overdue_daysInteger

Get number of overdue days. If this is negative, it is not overdue.

Returns:

  • (Integer)


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

Returns:

  • (bool)


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

Returns:

  • (bool)


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

Returns:

  • (bool)


43
44
45
# File 'lib/candy_check/play_store/subscription.rb', line 43

def payment_received?
  payment_state == PAYMENT_RECEIVED
end

#payment_stateInteger

Get the payment state as given by Google

Returns:

  • (Integer)


79
80
81
# File 'lib/candy_check/play_store/subscription.rb', line 79

def payment_state
  read_integer('paymentState')
end

#price_amount_microsInteger

Get the price amount for the subscription in micros in the payed currency

Returns:

  • (Integer)


86
87
88
# File 'lib/candy_check/play_store/subscription.rb', line 86

def price_amount_micros
  read_integer('priceAmountMicros')
end

#price_currency_codeString

Get the currency code in ISO 4217 format, e.g. “GBP” for British pounds

Returns:

  • (String)


110
111
112
# File 'lib/candy_check/play_store/subscription.rb', line 110

def price_currency_code
  read('priceCurrencyCode')
end

#start_time_millisInteger

Get start time for subscription in milliseconds since Epoch

Returns:

  • (Integer)


116
117
118
# File 'lib/candy_check/play_store/subscription.rb', line 116

def start_time_millis
  read_integer('startTimeMillis')
end

#starts_atDateTime

Get start time in UTC

Returns:

  • (DateTime)


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.

Returns:

  • (bool)


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