Class: AdvancedBilling::VoidRemainderEventData

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

Overview

Example schema for an ‘void_remainder` event

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(credit_note_attributes:, memo:, applied_amount:, transaction_time:, additional_properties: {}) ⇒ VoidRemainderEventData

Returns a new instance of VoidRemainderEventData.



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/advanced_billing/models/void_remainder_event_data.rb', line 50

def initialize(credit_note_attributes:, memo:, applied_amount:,
               transaction_time:, additional_properties: {})
  @credit_note_attributes = credit_note_attributes
  @memo = memo
  @applied_amount = applied_amount
  @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

#applied_amountString

The amount of the void.

Returns:

  • (String)


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

def applied_amount
  @applied_amount
end

#credit_note_attributesCreditNote

TODO: Write general description for this method

Returns:



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

def credit_note_attributes
  @credit_note_attributes
end

#memoString

The memo provided during invoice remainder voiding.

Returns:

  • (String)


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

def memo
  @memo
end

#transaction_timeDateTime

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

Returns:

  • (DateTime)


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

def transaction_time
  @transaction_time
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/advanced_billing/models/void_remainder_event_data.rb', line 64

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  credit_note_attributes = CreditNote.from_hash(hash['credit_note_attributes']) if
    hash['credit_note_attributes']
  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

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

  # Create object from extracted values.
  VoidRemainderEventData.new(credit_note_attributes: credit_note_attributes,
                             memo: memo,
                             applied_amount: applied_amount,
                             transaction_time: transaction_time,
                             additional_properties: hash)
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/void_remainder_event_data.rb', line 31

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['credit_note_attributes'] = 'credit_note_attributes'
  @_hash['memo'] = 'memo'
  @_hash['applied_amount'] = 'applied_amount'
  @_hash['transaction_time'] = 'transaction_time'
  @_hash
end

.nullablesObject

An array for nullable fields



46
47
48
# File 'lib/advanced_billing/models/void_remainder_event_data.rb', line 46

def self.nullables
  []
end

.optionalsObject

An array for optional fields



41
42
43
# File 'lib/advanced_billing/models/void_remainder_event_data.rb', line 41

def self.optionals
  []
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/advanced_billing/models/void_remainder_event_data.rb', line 94

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.credit_note_attributes,
                            ->(val) { CreditNote.validate(val) },
                            is_model_hash: true) 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 })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['credit_note_attributes'],
                          ->(val) { CreditNote.validate(val) },
                          is_model_hash: true) 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 })
  )
end

Instance Method Details

#to_custom_transaction_timeObject



88
89
90
# File 'lib/advanced_billing/models/void_remainder_event_data.rb', line 88

def to_custom_transaction_time
  DateTimeHelper.to_rfc3339(transaction_time)
end