Class: TransferZero::Recipient

Inherits:
Object
  • Object
show all
Defined in:
lib/transferzero-sdk/models/recipient.rb

Overview

The recipient describes the amount, the currency and the destination where the money should be sent.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Recipient

Initializes the object

Parameters:

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

    Model attributes in the form of hash



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/transferzero-sdk/models/recipient.rb', line 133

def initialize(attributes = {})
  if (!attributes.is_a?(Hash))
    fail ArgumentError, "The input argument (attributes) must be a hash in `TransferZero::Recipient` initialize method"
  end

  # check to see if the attribute exists and convert string to symbol for hash key
  attributes = attributes.each_with_object({}) { |(k, v), h|
    if (!self.class.attribute_map.key?(k.to_sym))
      fail ArgumentError, "`#{k}` is not a valid attribute in `TransferZero::Recipient`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
    end
    h[k.to_sym] = v
  }

  if attributes.key?(:'requested_amount')
    self.requested_amount = attributes[:'requested_amount']
  end

  if attributes.key?(:'requested_currency')
    self.requested_currency = attributes[:'requested_currency']
  end

  if attributes.key?(:'payout_method')
    self.payout_method = attributes[:'payout_method']
  end

  if attributes.key?(:'metadata')
    self. = attributes[:'metadata']
  end

  if attributes.key?(:'created_at')
    self.created_at = attributes[:'created_at']
  end

  if attributes.key?(:'editable')
    self.editable = attributes[:'editable']
  end

  if attributes.key?(:'retriable')
    self.retriable = attributes[:'retriable']
  end

  if attributes.key?(:'input_usd_amount')
    self.input_usd_amount = attributes[:'input_usd_amount']
  end

  if attributes.key?(:'may_cancel')
    self.may_cancel = attributes[:'may_cancel']
  end

  if attributes.key?(:'state_reason')
    self.state_reason = attributes[:'state_reason']
  end

  if attributes.key?(:'state')
    self.state = attributes[:'state']
  end

  if attributes.key?(:'transaction_id')
    self.transaction_id = attributes[:'transaction_id']
  end

  if attributes.key?(:'transaction_state')
    self.transaction_state = attributes[:'transaction_state']
  end

  if attributes.key?(:'exchange_rate')
    self.exchange_rate = attributes[:'exchange_rate']
  end

  if attributes.key?(:'fee_fractional')
    self.fee_fractional = attributes[:'fee_fractional']
  end

  if attributes.key?(:'input_amount')
    self.input_amount = attributes[:'input_amount']
  end

  if attributes.key?(:'input_currency')
    self.input_currency = attributes[:'input_currency']
  end

  if attributes.key?(:'output_amount')
    self.output_amount = attributes[:'output_amount']
  end

  if attributes.key?(:'output_currency')
    self.output_currency = attributes[:'output_currency']
  end

  if attributes.key?(:'id')
    self.id = attributes[:'id']
  end

  if attributes.key?(:'errors')
    if (value = attributes[:'errors']).is_a?(Hash)
      self.errors = value
    end
  end
end

Instance Attribute Details

#created_atObject

Date and time that the recipient was created.



30
31
32
# File 'lib/transferzero-sdk/models/recipient.rb', line 30

def created_at
  @created_at
end

#editableObject

Shows whether the recipient can be edited using the PATCH /v1/recipients/#id endpoint or not



33
34
35
# File 'lib/transferzero-sdk/models/recipient.rb', line 33

def editable
  @editable
end

#errorsObject

The fields that have some problems and don’t pass validation



75
76
77
# File 'lib/transferzero-sdk/models/recipient.rb', line 75

def errors
  @errors
end

#exchange_rateObject

The exchange rate used in this payment



55
56
57
# File 'lib/transferzero-sdk/models/recipient.rb', line 55

def exchange_rate
  @exchange_rate
end

#fee_fractionalObject

The fee for this payment in fractional units (for example cents for USD transactions)



58
59
60
# File 'lib/transferzero-sdk/models/recipient.rb', line 58

def fee_fractional
  @fee_fractional
end

#idObject

Returns the value of attribute id.



72
73
74
# File 'lib/transferzero-sdk/models/recipient.rb', line 72

def id
  @id
end

#input_amountObject

The amount that had to be paid in for this payment to proceed



61
62
63
# File 'lib/transferzero-sdk/models/recipient.rb', line 61

def input_amount
  @input_amount
end

#input_currencyObject

The currency this payment was paid in



64
65
66
# File 'lib/transferzero-sdk/models/recipient.rb', line 64

def input_currency
  @input_currency
end

#input_usd_amountObject

Shows how much this payment is worth in USD



39
40
41
# File 'lib/transferzero-sdk/models/recipient.rb', line 39

def input_usd_amount
  @input_usd_amount
end

#may_cancelObject

Shows whether the payment can be cancelled using the DELETE /v1/recipients/#id endpoint or not. The payment can not be cancelled if the payout is pending.



42
43
44
# File 'lib/transferzero-sdk/models/recipient.rb', line 42

def may_cancel
  @may_cancel
end

#metadataObject

Additional metadata that can be added to a recipient. These values will be returned on request



27
28
29
# File 'lib/transferzero-sdk/models/recipient.rb', line 27

def 
  
end

#output_amountObject

The amount that will be paid to the recipient



67
68
69
# File 'lib/transferzero-sdk/models/recipient.rb', line 67

def output_amount
  @output_amount
end

#output_currencyObject

The currency the payment will be delivered in



70
71
72
# File 'lib/transferzero-sdk/models/recipient.rb', line 70

def output_currency
  @output_currency
end

#payout_methodObject

Returns the value of attribute payout_method.



24
25
26
# File 'lib/transferzero-sdk/models/recipient.rb', line 24

def payout_method
  @payout_method
end

#requested_amountObject

the amount that should be paid to the recipient. This can be in any currency, usually either the input or the output currency. If the value here is not the output currency we will calculate how much the recipient is going to get using the exchange rates active when the transaction was created.



19
20
21
# File 'lib/transferzero-sdk/models/recipient.rb', line 19

def requested_amount
  @requested_amount
end

#requested_currencyObject

the currency of the amount in 3-character alpha ISO 4217 currency format



22
23
24
# File 'lib/transferzero-sdk/models/recipient.rb', line 22

def requested_currency
  @requested_currency
end

#retriableObject

Shows whether the transaction made to the recipient can be retried or not



36
37
38
# File 'lib/transferzero-sdk/models/recipient.rb', line 36

def retriable
  @retriable
end

#stateObject

Returns the value of attribute state.



47
48
49
# File 'lib/transferzero-sdk/models/recipient.rb', line 47

def state
  @state
end

#state_reasonObject

In case the payment is unsuccessful it holds the error message associated with the last unsuccessful payout.



45
46
47
# File 'lib/transferzero-sdk/models/recipient.rb', line 45

def state_reason
  @state_reason
end

#transaction_idObject

The ID of the transaction that is related to this recipient



50
51
52
# File 'lib/transferzero-sdk/models/recipient.rb', line 50

def transaction_id
  @transaction_id
end

#transaction_stateObject

Returns the value of attribute transaction_state.



52
53
54
# File 'lib/transferzero-sdk/models/recipient.rb', line 52

def transaction_state
  @transaction_state
end

Class Method Details

.attribute_mapObject

Attribute mapping from ruby-style variable name to JSON key.



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/transferzero-sdk/models/recipient.rb', line 78

def self.attribute_map
  {
    :'requested_amount' => :'requested_amount',
    :'requested_currency' => :'requested_currency',
    :'payout_method' => :'payout_method',
    :'metadata' => :'metadata',
    :'created_at' => :'created_at',
    :'editable' => :'editable',
    :'retriable' => :'retriable',
    :'input_usd_amount' => :'input_usd_amount',
    :'may_cancel' => :'may_cancel',
    :'state_reason' => :'state_reason',
    :'state' => :'state',
    :'transaction_id' => :'transaction_id',
    :'transaction_state' => :'transaction_state',
    :'exchange_rate' => :'exchange_rate',
    :'fee_fractional' => :'fee_fractional',
    :'input_amount' => :'input_amount',
    :'input_currency' => :'input_currency',
    :'output_amount' => :'output_amount',
    :'output_currency' => :'output_currency',
    :'id' => :'id',
    :'errors' => :'errors'
  }
end

.openapi_typesObject

Attribute type mapping.



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/transferzero-sdk/models/recipient.rb', line 105

def self.openapi_types
  {
    :'requested_amount' => :'Float',
    :'requested_currency' => :'String',
    :'payout_method' => :'PayoutMethod',
    :'metadata' => :'Object',
    :'created_at' => :'DateTime',
    :'editable' => :'Boolean',
    :'retriable' => :'Boolean',
    :'input_usd_amount' => :'Float',
    :'may_cancel' => :'Boolean',
    :'state_reason' => :'String',
    :'state' => :'RecipientState',
    :'transaction_id' => :'String',
    :'transaction_state' => :'TransactionState',
    :'exchange_rate' => :'Float',
    :'fee_fractional' => :'Float',
    :'input_amount' => :'Float',
    :'input_currency' => :'String',
    :'output_amount' => :'Float',
    :'output_currency' => :'String',
    :'id' => :'String',
    :'errors' => :'Hash<String, Array<ValidationErrorDescription>>'
  }
end

Instance Method Details

#==(o) ⇒ Object

Checks equality by comparing each attribute.

Parameters:

  • Object (Object)

    to be compared



263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/transferzero-sdk/models/recipient.rb', line 263

def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      requested_amount == o.requested_amount &&
      requested_currency == o.requested_currency &&
      payout_method == o.payout_method &&
       == o. &&
      created_at == o.created_at &&
      editable == o.editable &&
      retriable == o.retriable &&
      input_usd_amount == o.input_usd_amount &&
      may_cancel == o.may_cancel &&
      state_reason == o.state_reason &&
      state == o.state &&
      transaction_id == o.transaction_id &&
      transaction_state == o.transaction_state &&
      exchange_rate == o.exchange_rate &&
      fee_fractional == o.fee_fractional &&
      input_amount == o.input_amount &&
      input_currency == o.input_currency &&
      output_amount == o.output_amount &&
      output_currency == o.output_currency &&
      id == o.id &&
      errors == o.errors
end

#[](key) ⇒ Object



389
390
391
# File 'lib/transferzero-sdk/models/recipient.rb', line 389

def [](key)
  to_hash[key]
end

#_deserialize(type, value) ⇒ Object

Deserializes the data based on type

Parameters:

  • string

    type Data type

  • string

    value Value to be deserialized

Returns:

  • (Object)

    Deserialized data



327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
# File 'lib/transferzero-sdk/models/recipient.rb', line 327

def _deserialize(type, value)
  case type.to_sym
  when :DateTime
    DateTime.parse(value)
  when :Date
    Date.parse(value)
  when :String
    value.to_s
  when :Integer
    value.to_i
  when :Float
    value.to_f
  when :Boolean
    if value.to_s =~ /\A(true|t|yes|y|1)\z/i
      true
    else
      false
    end
  when :Object
    # generic object (usually a Hash), return directly
    value
  when /\AArray<(?<inner_type>.+)>\z/
    inner_type = Regexp.last_match[:inner_type]
    value.map { |v| _deserialize(inner_type, v) }
  when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
    k_type = Regexp.last_match[:k_type]
    v_type = Regexp.last_match[:v_type]
    {}.tap do |hash|
      value.each do |k, v|
        hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
      end
    end
  else # model
    temp_model = TransferZero.const_get(type).new
    temp_model.build_from_hash(value)
  end
end

#_to_hash(value) ⇒ Hash

Outputs non-array value in the form of hash For object, use to_hash. Otherwise, just return the value

Parameters:

  • value (Object)

    Any valid value

Returns:

  • (Hash)

    Returns the value in the form of hash



401
402
403
404
405
406
407
408
409
410
411
412
413
# File 'lib/transferzero-sdk/models/recipient.rb', line 401

def _to_hash(value)
  if value.is_a?(Array)
    value.compact.map { |v| _to_hash(v) }
  elsif value.is_a?(Hash)
    {}.tap do |hash|
      value.each { |k, v| hash[k] = _to_hash(v) }
    end
  elsif value.respond_to? :to_hash
    value.to_hash
  else
    value
  end
end

#build_from_hash(attributes) ⇒ Object

Returns the model itself

Returns:

  • (Object)

    Returns the model itself



306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# File 'lib/transferzero-sdk/models/recipient.rb', line 306

def build_from_hash(attributes)
  return nil unless attributes.is_a?(Hash)
  self.class.openapi_types.each_pair do |key, type|
    if type =~ /\AArray<(.*)>/i
      # check to ensure the input is an array given that the the attribute
      # is documented as an array but the input is not
      if attributes[self.class.attribute_map[key]].is_a?(Array)
        self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
      end
    elsif !attributes[self.class.attribute_map[key]].nil?
      self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
    end # or else data not found in attributes(hash), not an issue as the data can be optional
  end

  self
end

#dig(*args) ⇒ Object



393
394
395
# File 'lib/transferzero-sdk/models/recipient.rb', line 393

def dig(*args)
  to_hash.dig(*args)
end

#eql?(o) ⇒ Boolean

Parameters:

  • Object (Object)

    to be compared

Returns:

  • (Boolean)

See Also:

  • `==` method


291
292
293
# File 'lib/transferzero-sdk/models/recipient.rb', line 291

def eql?(o)
  self == o
end

#hashInteger

Calculates hash code according to all attributes.

Returns:

  • (Integer)

    Hash code



297
298
299
# File 'lib/transferzero-sdk/models/recipient.rb', line 297

def hash
  [requested_amount, requested_currency, payout_method, , created_at, editable, retriable, input_usd_amount, may_cancel, state_reason, state, transaction_id, transaction_state, exchange_rate, fee_fractional, input_amount, input_currency, output_amount, output_currency, id, errors].hash
end

#list_invalid_propertiesObject

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

Returns:

  • Array for valid properties with the reasons



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/transferzero-sdk/models/recipient.rb', line 235

def list_invalid_properties
  invalid_properties = Array.new
  if @requested_amount.nil?
    invalid_properties.push('invalid value for "requested_amount", requested_amount cannot be nil.')
  end

  if @requested_currency.nil?
    invalid_properties.push('invalid value for "requested_currency", requested_currency cannot be nil.')
  end

  if @payout_method.nil?
    invalid_properties.push('invalid value for "payout_method", payout_method cannot be nil.')
  end

  invalid_properties
end

#to_bodyHash

to_body is an alias to to_hash (backward compatibility)

Returns:

  • (Hash)

    Returns the object in the form of hash



373
374
375
# File 'lib/transferzero-sdk/models/recipient.rb', line 373

def to_body
  to_hash
end

#to_hashHash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



379
380
381
382
383
384
385
386
387
# File 'lib/transferzero-sdk/models/recipient.rb', line 379

def to_hash
  hash = {}
  self.class.attribute_map.each_pair do |attr, param|
    value = self.send(attr)
    next if value.nil?
    hash[param] = _to_hash(value)
  end
  ::ActiveSupport::HashWithIndifferentAccess.new(hash)
end

#to_sString

Returns the string representation of the object

Returns:

  • (String)

    String presentation of the object



367
368
369
# File 'lib/transferzero-sdk/models/recipient.rb', line 367

def to_s
  to_hash.to_s
end

#valid?Boolean

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

Returns:

  • (Boolean)

    true if the model is valid



254
255
256
257
258
259
# File 'lib/transferzero-sdk/models/recipient.rb', line 254

def valid?
  return false if @requested_amount.nil?
  return false if @requested_currency.nil?
  return false if @payout_method.nil?
  true
end