Class: AdvancedBilling::ChangeInvoiceStatusEventData

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

Overview

Example schema for an ‘change_invoice_status` event

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(from_status:, to_status:, gateway_trans_id: SKIP, amount: SKIP, consolidation_level: SKIP, additional_properties: {}) ⇒ ChangeInvoiceStatusEventData

Returns a new instance of ChangeInvoiceStatusEventData.



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

def initialize(from_status:, to_status:, gateway_trans_id: SKIP,
               amount: SKIP, consolidation_level: SKIP,
               additional_properties: {})
  @gateway_trans_id = gateway_trans_id unless gateway_trans_id == SKIP
  @amount = amount unless amount == SKIP
  @from_status = from_status
  @to_status = to_status
  @consolidation_level = consolidation_level unless consolidation_level == SKIP

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

Instance Attribute Details

#amountString

The monetary value associated with the linked payment, expressed in dollars.

Returns:

  • (String)


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

def amount
  @amount
end

#consolidation_levelInvoiceConsolidationLevel

The updated status of the invoice after changes have been made. See [Invoice Statuses](maxio.zendesk.com/hc/en-us/articles/24252287829645-Advan ced-Billing-Invoices-Overview#invoice-statuses) for more.



39
40
41
# File 'lib/advanced_billing/models/change_invoice_status_event_data.rb', line 39

def consolidation_level
  @consolidation_level
end

#from_statusInvoiceStatus

The status of the invoice before any changes occurred. See [Invoice Statuses](maxio.zendesk.com/hc/en-us/articles/24252287829645-Advan ced-Billing-Invoices-Overview#invoice-statuses) for more.

Returns:



25
26
27
# File 'lib/advanced_billing/models/change_invoice_status_event_data.rb', line 25

def from_status
  @from_status
end

#gateway_trans_idString

Identifier for the transaction within the payment gateway.

Returns:

  • (String)


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

def gateway_trans_id
  @gateway_trans_id
end

#to_statusInvoiceStatus

The updated status of the invoice after changes have been made. See [Invoice Statuses](maxio.zendesk.com/hc/en-us/articles/24252287829645-Advan ced-Billing-Invoices-Overview#invoice-statuses) for more.

Returns:



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

def to_status
  @to_status
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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/change_invoice_status_event_data.rb', line 82

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  from_status = hash.key?('from_status') ? hash['from_status'] : nil
  to_status = hash.key?('to_status') ? hash['to_status'] : nil
  gateway_trans_id =
    hash.key?('gateway_trans_id') ? hash['gateway_trans_id'] : SKIP
  amount = hash.key?('amount') ? hash['amount'] : SKIP
  consolidation_level =
    hash.key?('consolidation_level') ? hash['consolidation_level'] : SKIP

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

  # Create object from extracted values.
  ChangeInvoiceStatusEventData.new(from_status: from_status,
                                   to_status: to_status,
                                   gateway_trans_id: gateway_trans_id,
                                   amount: amount,
                                   consolidation_level: consolidation_level,
                                   additional_properties: hash)
end

.namesObject

A mapping from model property names to API property names.



42
43
44
45
46
47
48
49
50
# File 'lib/advanced_billing/models/change_invoice_status_event_data.rb', line 42

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['gateway_trans_id'] = 'gateway_trans_id'
  @_hash['amount'] = 'amount'
  @_hash['from_status'] = 'from_status'
  @_hash['to_status'] = 'to_status'
  @_hash['consolidation_level'] = 'consolidation_level'
  @_hash
end

.nullablesObject

An array for nullable fields



62
63
64
# File 'lib/advanced_billing/models/change_invoice_status_event_data.rb', line 62

def self.nullables
  []
end

.optionalsObject

An array for optional fields



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

def self.optionals
  %w[
    gateway_trans_id
    amount
    consolidation_level
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/advanced_billing/models/change_invoice_status_event_data.rb', line 108

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.from_status,
                            ->(val) { InvoiceStatus.validate(val) }) and
        APIHelper.valid_type?(value.to_status,
                              ->(val) { InvoiceStatus.validate(val) })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['from_status'],
                          ->(val) { InvoiceStatus.validate(val) }) and
      APIHelper.valid_type?(value['to_status'],
                            ->(val) { InvoiceStatus.validate(val) })
  )
end