Class: Cryptopay::Subscription

Inherits:
Object
  • Object
show all
Defined in:
lib/cryptopay/models/subscription.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Subscription

Initializes the object

Parameters:

  • attributes (Hash) (defaults to: {})

    Model attributes in the form of hash



74
75
76
# File 'lib/cryptopay/models/subscription.rb', line 74

def initialize(attributes = {})
  @attributes = ENCODER.sanitize(attributes)
end

Class Method Details

.build_from_hash(data) ⇒ Cryptopay::Subscription

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:



67
68
69
70
# File 'lib/cryptopay/models/subscription.rb', line 67

def self.build_from_hash(data)
  attributes = ENCODER.build_from_hash(data)
  new(attributes)
end

Instance Method Details

#amountObject

Subscription amount



98
99
100
# File 'lib/cryptopay/models/subscription.rb', line 98

def amount
  @attributes[:amount]
end

#cancelled_atObject



156
157
158
# File 'lib/cryptopay/models/subscription.rb', line 156

def cancelled_at
  @attributes[:cancelled_at]
end

#created_atObject



152
153
154
# File 'lib/cryptopay/models/subscription.rb', line 152

def created_at
  @attributes[:created_at]
end

#currencyObject

Subscription amount currency



103
104
105
# File 'lib/cryptopay/models/subscription.rb', line 103

def currency
  @attributes[:currency]
end

#current_period_ends_atObject



119
120
121
# File 'lib/cryptopay/models/subscription.rb', line 119

def current_period_ends_at
  @attributes[:current_period_ends_at]
end

#current_period_paidObject



123
124
125
# File 'lib/cryptopay/models/subscription.rb', line 123

def current_period_paid
  @attributes[:current_period_paid]
end

#current_period_starts_atObject



115
116
117
# File 'lib/cryptopay/models/subscription.rb', line 115

def current_period_starts_at
  @attributes[:current_period_starts_at]
end

#custom_idObject

Subscription reference ID in your system



88
89
90
# File 'lib/cryptopay/models/subscription.rb', line 88

def custom_id
  @attributes[:custom_id]
end

#idObject

Subscription ID



79
80
81
# File 'lib/cryptopay/models/subscription.rb', line 79

def id
  @attributes[:id]
end

#inspectObject



218
219
220
# File 'lib/cryptopay/models/subscription.rb', line 218

def inspect
  "#<#{self.class}:0x#{object_id.to_s(16)}> JSON: " + JSON.pretty_generate(to_hash)
end

#invalid_propertiesObject

Show invalid properties with the reasons. Usually used together with valid?

Returns:

  • Array for valid properties with the reasons



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/cryptopay/models/subscription.rb', line 162

def invalid_properties
  properties = []

  properties.push('invalid value for "id", id cannot be nil.') if id.nil?

  properties.push('invalid value for "status", status cannot be nil.') if status.nil?

  if !status.nil? && !%w[active cancelled].include?(status)
    properties.push('invalid value for status, must be one of "active", "cancelled"')
  end

  properties.push('invalid value for "name", name cannot be nil.') if name.nil?

  properties.push('invalid value for "amount", amount cannot be nil.') if amount.nil?

  properties.push('invalid value for "currency", currency cannot be nil.') if currency.nil?

  properties.push('invalid value for "period", period cannot be nil.') if period.nil?

  if !period.nil? && !%w[day week month year].include?(period)
    properties.push('invalid value for period, must be one of "day", "week", "month", "year"')
  end

  properties.push('invalid value for "period_quantity", period_quantity cannot be nil.') if period_quantity.nil?

  if current_period_starts_at.nil?
    properties.push('invalid value for "current_period_starts_at", current_period_starts_at cannot be nil.')
  end

  if current_period_ends_at.nil?
    properties.push('invalid value for "current_period_ends_at", current_period_ends_at cannot be nil.')
  end

  if current_period_paid.nil?
    properties.push('invalid value for "current_period_paid", current_period_paid cannot be nil.')
  end

  properties.push('invalid value for "payer_email", payer_email cannot be nil.') if payer_email.nil?

  properties.push('invalid value for "created_at", created_at cannot be nil.') if created_at.nil?

  properties
end

#nameObject

Subscription name



93
94
95
# File 'lib/cryptopay/models/subscription.rb', line 93

def name
  @attributes[:name]
end

#payer_emailObject



127
128
129
# File 'lib/cryptopay/models/subscription.rb', line 127

def payer_email
  @attributes[:payer_email]
end

#payer_nameObject



131
132
133
# File 'lib/cryptopay/models/subscription.rb', line 131

def payer_name
  @attributes[:payer_name]
end

#periodObject



107
108
109
# File 'lib/cryptopay/models/subscription.rb', line 107

def period
  @attributes[:period]
end

#period_quantityObject



111
112
113
# File 'lib/cryptopay/models/subscription.rb', line 111

def period_quantity
  @attributes[:period_quantity]
end

#product_descriptionObject



139
140
141
# File 'lib/cryptopay/models/subscription.rb', line 139

def product_description
  @attributes[:product_description]
end

#product_nameObject



135
136
137
# File 'lib/cryptopay/models/subscription.rb', line 135

def product_name
  @attributes[:product_name]
end

#statusObject



83
84
85
# File 'lib/cryptopay/models/subscription.rb', line 83

def status
  @attributes[:status]
end

#success_redirect_urlObject

The URL that the customer will be redirected to upon transaction confirmation



144
145
146
# File 'lib/cryptopay/models/subscription.rb', line 144

def success_redirect_url
  @attributes[:success_redirect_url]
end

#to_hashHash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



214
215
216
# File 'lib/cryptopay/models/subscription.rb', line 214

def to_hash
  ENCODER.to_hash(@attributes)
end

#unsuccess_redirect_urlObject



148
149
150
# File 'lib/cryptopay/models/subscription.rb', line 148

def unsuccess_redirect_url
  @attributes[:unsuccess_redirect_url]
end

#valid?Boolean

Check to see if the all the properties in the model are valid

Returns:

  • (Boolean)

    true if the model is valid



208
209
210
# File 'lib/cryptopay/models/subscription.rb', line 208

def valid?
  invalid_properties.empty?
end