Class: AdvancedBilling::RemovePaymentEventData

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

Overview

Example schema for an ‘remove_payment` event

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(transaction_id:, memo:, applied_amount:, transaction_time:, payment_method:, prepayment:, original_amount: SKIP, additional_properties: {}) ⇒ RemovePaymentEventData

Returns a new instance of RemovePaymentEventData.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/advanced_billing/models/remove_payment_event_data.rb', line 67

def initialize(transaction_id:, memo:, applied_amount:, transaction_time:,
               payment_method:, prepayment:, original_amount: SKIP,
               additional_properties: {})
  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end

  @transaction_id = transaction_id
  @memo = memo
  @original_amount = original_amount unless original_amount == SKIP
  @applied_amount = applied_amount
  @transaction_time = transaction_time
  @payment_method = payment_method
  @prepayment = prepayment
end

Instance Attribute Details

#applied_amountString

Applied amount of the original payment

Returns:

  • (String)


27
28
29
# File 'lib/advanced_billing/models/remove_payment_event_data.rb', line 27

def applied_amount
  @applied_amount
end

#memoString

Memo of the original payment

Returns:

  • (String)


19
20
21
# File 'lib/advanced_billing/models/remove_payment_event_data.rb', line 19

def memo
  @memo
end

#original_amountString

Full amount of the original payment

Returns:

  • (String)


23
24
25
# File 'lib/advanced_billing/models/remove_payment_event_data.rb', line 23

def original_amount
  @original_amount
end

#payment_methodObject

A nested data structure detailing the method of payment

Returns:

  • (Object)


36
37
38
# File 'lib/advanced_billing/models/remove_payment_event_data.rb', line 36

def payment_method
  @payment_method
end

#prepaymentTrueClass | FalseClass

The flag that shows whether the original payment was a prepayment or not

Returns:

  • (TrueClass | FalseClass)


40
41
42
# File 'lib/advanced_billing/models/remove_payment_event_data.rb', line 40

def prepayment
  @prepayment
end

#transaction_idInteger

Transaction ID of the original payment that was removed

Returns:

  • (Integer)


15
16
17
# File 'lib/advanced_billing/models/remove_payment_event_data.rb', line 15

def transaction_id
  @transaction_id
end

#transaction_timeDateTime

Transaction time of the original payment, in ISO 8601 format, i.e. “2019-06-07T17:20:06Z”

Returns:

  • (DateTime)


32
33
34
# File 'lib/advanced_billing/models/remove_payment_event_data.rb', line 32

def transaction_time
  @transaction_time
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/advanced_billing/models/remove_payment_event_data.rb', line 85

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  transaction_id =
    hash.key?('transaction_id') ? hash['transaction_id'] : nil
  memo = hash.key?('memo') ? hash['memo'] : nil
  applied_amount =
    hash.key?('applied_amount') ? hash['applied_amount'] : nil
  transaction_time = if hash.key?('transaction_time')
                       (DateTimeHelper.from_rfc3339(hash['transaction_time']) if hash['transaction_time'])
                     end
  payment_method = hash.key?('payment_method') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:InvoiceEventPayment), hash['payment_method']
  ) : nil
  prepayment = hash.key?('prepayment') ? hash['prepayment'] : nil
  original_amount =
    hash.key?('original_amount') ? hash['original_amount'] : SKIP

  # Clean out expected properties from Hash.
  additional_properties = hash.reject { |k, _| names.value?(k) }

  # Create object from extracted values.
  RemovePaymentEventData.new(transaction_id: transaction_id,
                             memo: memo,
                             applied_amount: applied_amount,
                             transaction_time: transaction_time,
                             payment_method: payment_method,
                             prepayment: prepayment,
                             original_amount: original_amount,
                             additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/advanced_billing/models/remove_payment_event_data.rb', line 43

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['transaction_id'] = 'transaction_id'
  @_hash['memo'] = 'memo'
  @_hash['original_amount'] = 'original_amount'
  @_hash['applied_amount'] = 'applied_amount'
  @_hash['transaction_time'] = 'transaction_time'
  @_hash['payment_method'] = 'payment_method'
  @_hash['prepayment'] = 'prepayment'
  @_hash
end

.nullablesObject

An array for nullable fields



63
64
65
# File 'lib/advanced_billing/models/remove_payment_event_data.rb', line 63

def self.nullables
  []
end

.optionalsObject

An array for optional fields



56
57
58
59
60
# File 'lib/advanced_billing/models/remove_payment_event_data.rb', line 56

def self.optionals
  %w[
    original_amount
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



124
125
126
127
128
129
130
131
132
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
# File 'lib/advanced_billing/models/remove_payment_event_data.rb', line 124

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.transaction_id,
                            ->(val) { val.instance_of? Integer }) and
        APIHelper.valid_type?(value.memo,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.applied_amount,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.transaction_time,
                              ->(val) { val.instance_of? DateTime }) and
        UnionTypeLookUp.get(:InvoiceEventPayment)
                       .validate(value.payment_method) and
        APIHelper.valid_type?(value.prepayment,
                              ->(val) { val.instance_of? TrueClass or val.instance_of? FalseClass })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['transaction_id'],
                          ->(val) { val.instance_of? Integer }) and
      APIHelper.valid_type?(value['memo'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['applied_amount'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['transaction_time'],
                            ->(val) { val.instance_of? String }) and
      UnionTypeLookUp.get(:InvoiceEventPayment)
                     .validate(value['payment_method']) and
      APIHelper.valid_type?(value['prepayment'],
                            ->(val) { val.instance_of? TrueClass or val.instance_of? FalseClass })
  )
end

Instance Method Details

#to_custom_transaction_timeObject



118
119
120
# File 'lib/advanced_billing/models/remove_payment_event_data.rb', line 118

def to_custom_transaction_time
  DateTimeHelper.to_rfc3339(transaction_time)
end