Class: AdvancedBilling::RefundPrepayment

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/advanced_billing/models/refund_prepayment.rb

Overview

RefundPrepayment Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(amount_in_cents = nil, amount = nil, memo = nil, external = SKIP) ⇒ RefundPrepayment

Returns a new instance of RefundPrepayment.



52
53
54
55
56
57
58
# File 'lib/advanced_billing/models/refund_prepayment.rb', line 52

def initialize(amount_in_cents = nil, amount = nil, memo = nil,
               external = SKIP)
  @amount_in_cents = amount_in_cents
  @amount = amount
  @memo = memo
  @external = external unless external == SKIP
end

Instance Attribute Details

#amountObject

‘amount_in_cents` is not required if you pass `amount`.

Returns:

  • (Object)


18
19
20
# File 'lib/advanced_billing/models/refund_prepayment.rb', line 18

def amount
  @amount
end

#amount_in_centsFloat

‘amount` is not required if you pass `amount_in_cents`.

Returns:

  • (Float)


14
15
16
# File 'lib/advanced_billing/models/refund_prepayment.rb', line 14

def amount_in_cents
  @amount_in_cents
end

#externalTrueClass | FalseClass

Specify the type of refund you wish to initiate. When the prepayment is external, the ‘external` flag is optional. But if the prepayment was made through a payment profile, the `external` flag is required.

Returns:

  • (TrueClass | FalseClass)


28
29
30
# File 'lib/advanced_billing/models/refund_prepayment.rb', line 28

def external
  @external
end

#memoString

‘amount_in_cents` is not required if you pass `amount`.

Returns:

  • (String)


22
23
24
# File 'lib/advanced_billing/models/refund_prepayment.rb', line 22

def memo
  @memo
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/advanced_billing/models/refund_prepayment.rb', line 61

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  amount_in_cents =
    hash.key?('amount_in_cents') ? hash['amount_in_cents'] : nil
  amount = hash.key?('amount') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:RefundPrepaymentAmount), hash['amount']
  ) : nil
  memo = hash.key?('memo') ? hash['memo'] : nil
  external = hash.key?('external') ? hash['external'] : SKIP

  # Create object from extracted values.
  RefundPrepayment.new(amount_in_cents,
                       amount,
                       memo,
                       external)
end

.namesObject

A mapping from model property names to API property names.



31
32
33
34
35
36
37
38
# File 'lib/advanced_billing/models/refund_prepayment.rb', line 31

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['amount_in_cents'] = 'amount_in_cents'
  @_hash['amount'] = 'amount'
  @_hash['memo'] = 'memo'
  @_hash['external'] = 'external'
  @_hash
end

.nullablesObject

An array for nullable fields



48
49
50
# File 'lib/advanced_billing/models/refund_prepayment.rb', line 48

def self.nullables
  []
end

.optionalsObject

An array for optional fields



41
42
43
44
45
# File 'lib/advanced_billing/models/refund_prepayment.rb', line 41

def self.optionals
  %w[
    external
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/advanced_billing/models/refund_prepayment.rb', line 82

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.amount_in_cents,
                            ->(val) { val.instance_of? Float }) and
        UnionTypeLookUp.get(:RefundPrepaymentAmount)
                       .validate(value.amount) and
        APIHelper.valid_type?(value.memo,
                              ->(val) { val.instance_of? String })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['amount_in_cents'],
                          ->(val) { val.instance_of? Float }) and
      UnionTypeLookUp.get(:RefundPrepaymentAmount)
                     .validate(value['amount']) and
      APIHelper.valid_type?(value['memo'],
                            ->(val) { val.instance_of? String })
  )
end