Class: AdvancedBilling::RefundInvoiceEventData

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

Overview

Example schema for an ‘refund_invoice` event

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(apply_credit:, credit_note_attributes:, payment_id:, refund_amount:, refund_id:, transaction_time:, consolidation_level: SKIP, memo: SKIP, original_amount: SKIP, additional_properties: {}) ⇒ RefundInvoiceEventData

Returns a new instance of RefundInvoiceEventData.



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/advanced_billing/models/refund_invoice_event_data.rb', line 101

def initialize(apply_credit:, credit_note_attributes:, payment_id:,
               refund_amount:, refund_id:, transaction_time:,
               consolidation_level: SKIP, memo: SKIP, original_amount: SKIP,
               additional_properties: {})
  @apply_credit = apply_credit
  @consolidation_level = consolidation_level unless consolidation_level == SKIP
  @credit_note_attributes = credit_note_attributes
  @memo = memo unless memo == SKIP
  @original_amount = original_amount unless original_amount == SKIP
  @payment_id = payment_id
  @refund_amount = refund_amount
  @refund_id = refund_id
  @transaction_time = transaction_time

  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end
end

Instance Attribute Details

#apply_creditTrueClass | FalseClass

If true, credit was created and applied it to the invoice.

Returns:

  • (TrueClass | FalseClass)


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

def apply_credit
  @apply_credit
end

#consolidation_levelInvoiceConsolidationLevel

Consolidation level of the invoice, which is applicable to invoice consolidation. It will hold one of the following values:

  • “none”: A normal invoice with no consolidation.

  • “child”: An invoice segment which has been combined into a consolidated

invoice.

  • “parent”: A consolidated invoice, whose contents are composed of invoice

segments. “Parent” invoices do not have lines of their own, but they have subtotals and totals which aggregate the member invoice segments. See also the [invoice consolidation documentation](maxio.zendesk.com/hc/en-us/articles/24252269909389- Invoice-Consolidation).



30
31
32
# File 'lib/advanced_billing/models/refund_invoice_event_data.rb', line 30

def consolidation_level
  @consolidation_level
end

#credit_note_attributesCreditNote

Consolidation level of the invoice, which is applicable to invoice consolidation. It will hold one of the following values:

  • “none”: A normal invoice with no consolidation.

  • “child”: An invoice segment which has been combined into a consolidated

invoice.

  • “parent”: A consolidated invoice, whose contents are composed of invoice

segments. “Parent” invoices do not have lines of their own, but they have subtotals and totals which aggregate the member invoice segments. See also the [invoice consolidation documentation](maxio.zendesk.com/hc/en-us/articles/24252269909389- Invoice-Consolidation).

Returns:



45
46
47
# File 'lib/advanced_billing/models/refund_invoice_event_data.rb', line 45

def credit_note_attributes
  @credit_note_attributes
end

#memoString

The refund memo.

Returns:

  • (String)


49
50
51
# File 'lib/advanced_billing/models/refund_invoice_event_data.rb', line 49

def memo
  @memo
end

#original_amountString

The full, original amount of the refund.

Returns:

  • (String)


53
54
55
# File 'lib/advanced_billing/models/refund_invoice_event_data.rb', line 53

def original_amount
  @original_amount
end

#payment_idInteger

The ID of the payment transaction to be refunded.

Returns:

  • (Integer)


57
58
59
# File 'lib/advanced_billing/models/refund_invoice_event_data.rb', line 57

def payment_id
  @payment_id
end

#refund_amountString

The amount of the refund.

Returns:

  • (String)


61
62
63
# File 'lib/advanced_billing/models/refund_invoice_event_data.rb', line 61

def refund_amount
  @refund_amount
end

#refund_idInteger

The ID of the refund transaction.

Returns:

  • (Integer)


65
66
67
# File 'lib/advanced_billing/models/refund_invoice_event_data.rb', line 65

def refund_id
  @refund_id
end

#transaction_timeDateTime

The time the refund was applied, in ISO 8601 format, i.e. “2019-06-07T17:20:06Z”

Returns:

  • (DateTime)


70
71
72
# File 'lib/advanced_billing/models/refund_invoice_event_data.rb', line 70

def transaction_time
  @transaction_time
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



122
123
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
# File 'lib/advanced_billing/models/refund_invoice_event_data.rb', line 122

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  apply_credit = hash.key?('apply_credit') ? hash['apply_credit'] : nil
  credit_note_attributes = CreditNote.from_hash(hash['credit_note_attributes']) if
    hash['credit_note_attributes']
  payment_id = hash.key?('payment_id') ? hash['payment_id'] : nil
  refund_amount = hash.key?('refund_amount') ? hash['refund_amount'] : nil
  refund_id = hash.key?('refund_id') ? hash['refund_id'] : nil
  transaction_time = if hash.key?('transaction_time')
                       (DateTimeHelper.from_rfc3339(hash['transaction_time']) if hash['transaction_time'])
                     end
  consolidation_level =
    hash.key?('consolidation_level') ? hash['consolidation_level'] : SKIP
  memo = hash.key?('memo') ? hash['memo'] : SKIP
  original_amount =
    hash.key?('original_amount') ? hash['original_amount'] : SKIP

  # Clean out expected properties from Hash.
  names.each_value { |k| hash.delete(k) }

  # Create object from extracted values.
  RefundInvoiceEventData.new(apply_credit: apply_credit,
                             credit_note_attributes: credit_note_attributes,
                             payment_id: payment_id,
                             refund_amount: refund_amount,
                             refund_id: refund_id,
                             transaction_time: transaction_time,
                             consolidation_level: consolidation_level,
                             memo: memo,
                             original_amount: original_amount,
                             additional_properties: hash)
end

.namesObject

A mapping from model property names to API property names.



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/advanced_billing/models/refund_invoice_event_data.rb', line 73

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['apply_credit'] = 'apply_credit'
  @_hash['consolidation_level'] = 'consolidation_level'
  @_hash['credit_note_attributes'] = 'credit_note_attributes'
  @_hash['memo'] = 'memo'
  @_hash['original_amount'] = 'original_amount'
  @_hash['payment_id'] = 'payment_id'
  @_hash['refund_amount'] = 'refund_amount'
  @_hash['refund_id'] = 'refund_id'
  @_hash['transaction_time'] = 'transaction_time'
  @_hash
end

.nullablesObject

An array for nullable fields



97
98
99
# File 'lib/advanced_billing/models/refund_invoice_event_data.rb', line 97

def self.nullables
  []
end

.optionalsObject

An array for optional fields



88
89
90
91
92
93
94
# File 'lib/advanced_billing/models/refund_invoice_event_data.rb', line 88

def self.optionals
  %w[
    consolidation_level
    memo
    original_amount
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



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
# File 'lib/advanced_billing/models/refund_invoice_event_data.rb', line 163

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.apply_credit,
                            ->(val) { val.instance_of? TrueClass or val.instance_of? FalseClass }) and
        APIHelper.valid_type?(value.credit_note_attributes,
                              ->(val) { CreditNote.validate(val) },
                              is_model_hash: true) and
        APIHelper.valid_type?(value.payment_id,
                              ->(val) { val.instance_of? Integer }) and
        APIHelper.valid_type?(value.refund_amount,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.refund_id,
                              ->(val) { val.instance_of? Integer }) and
        APIHelper.valid_type?(value.transaction_time,
                              ->(val) { val.instance_of? DateTime })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['apply_credit'],
                          ->(val) { val.instance_of? TrueClass or val.instance_of? FalseClass }) and
      APIHelper.valid_type?(value['credit_note_attributes'],
                            ->(val) { CreditNote.validate(val) },
                            is_model_hash: true) and
      APIHelper.valid_type?(value['payment_id'],
                            ->(val) { val.instance_of? Integer }) and
      APIHelper.valid_type?(value['refund_amount'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['refund_id'],
                            ->(val) { val.instance_of? Integer }) and
      APIHelper.valid_type?(value['transaction_time'],
                            ->(val) { val.instance_of? String })
  )
end

Instance Method Details

#to_custom_transaction_timeObject



157
158
159
# File 'lib/advanced_billing/models/refund_invoice_event_data.rb', line 157

def to_custom_transaction_time
  DateTimeHelper.to_rfc3339(transaction_time)
end