Class: AdvancedBilling::UpdateInvoice

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

Overview

Attributes of a draft ad hoc invoice which can be updated. Only the submitted attributes are changed.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

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

Constructor Details

#initialize(line_items: SKIP, issue_date: SKIP, net_terms: SKIP, payment_instructions: SKIP, memo: SKIP, seller_address: SKIP, billing_address: SKIP, shipping_address: SKIP, coupons: SKIP, additional_properties: {}) ⇒ UpdateInvoice

Returns a new instance of UpdateInvoice.



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/advanced_billing/models/update_invoice.rb', line 92

def initialize(line_items: SKIP, issue_date: SKIP, net_terms: SKIP,
               payment_instructions: SKIP, memo: SKIP, seller_address: SKIP,
               billing_address: SKIP, shipping_address: SKIP, coupons: SKIP,
               additional_properties: {})
  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end

  @line_items = line_items unless line_items == SKIP
  @issue_date = issue_date unless issue_date == SKIP
  @net_terms = net_terms unless net_terms == SKIP
  @payment_instructions = payment_instructions unless payment_instructions == SKIP
  @memo = memo unless memo == SKIP
  @seller_address = seller_address unless seller_address == SKIP
  @billing_address = billing_address unless billing_address == SKIP
  @shipping_address = shipping_address unless shipping_address == SKIP
  @coupons = coupons unless coupons == SKIP
end

Instance Attribute Details

#billing_addressCreateInvoiceAddress

Replaces the billing address on the invoice



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

def billing_address
  @billing_address
end

#couponsArray[CreateInvoiceCoupon]

When present, replaces all discounts currently applied to the invoice. Send an empty array to remove all discounts.

Returns:



55
56
57
# File 'lib/advanced_billing/models/update_invoice.rb', line 55

def coupons
  @coupons
end

#issue_dateDate

New issue date for the invoice (format YYYY-MM-DD). This date is interpreted and validated in your site's time zone. It must be today or a date in the past — future dates are not accepted. The due date is recalculated from the issue date and net terms.

Returns:

  • (Date)


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

def issue_date
  @issue_date
end

#line_itemsArray[UpdateInvoiceItem]

Line item changes to apply. Line items without a uid are added, line items with a uid are updated, and line items with a uid and _destroy set to true are removed. Existing line items not referenced in the array remain unchanged.

Returns:



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

def line_items
  @line_items
end

#memoString

A custom memo displayed on the invoice.

Returns:

  • (String)


38
39
40
# File 'lib/advanced_billing/models/update_invoice.rb', line 38

def memo
  @memo
end

#net_termsInteger

Number of days after the issue date on which the invoice is due. The due date is recalculated when net terms or the issue date change.

Returns:

  • (Integer)


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

def net_terms
  @net_terms
end

#payment_instructionsString

Custom payment instructions displayed on the invoice.

Returns:

  • (String)


34
35
36
# File 'lib/advanced_billing/models/update_invoice.rb', line 34

def payment_instructions
  @payment_instructions
end

#seller_addressCreateInvoiceAddress

Replaces the seller address on the invoice



42
43
44
# File 'lib/advanced_billing/models/update_invoice.rb', line 42

def seller_address
  @seller_address
end

#shipping_addressCreateInvoiceAddress

Replaces the shipping address on the invoice



50
51
52
# File 'lib/advanced_billing/models/update_invoice.rb', line 50

def shipping_address
  @shipping_address
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



113
114
115
116
117
118
119
120
121
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
156
157
158
159
160
161
162
163
# File 'lib/advanced_billing/models/update_invoice.rb', line 113

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  # Parameter is an array, so we need to iterate through it
  line_items = nil
  unless hash['line_items'].nil?
    line_items = []
    hash['line_items'].each do |structure|
      line_items << (UpdateInvoiceItem.from_hash(structure) if structure)
    end
  end

  line_items = SKIP unless hash.key?('line_items')
  issue_date = hash.key?('issue_date') ? hash['issue_date'] : SKIP
  net_terms = hash.key?('net_terms') ? hash['net_terms'] : SKIP
  payment_instructions =
    hash.key?('payment_instructions') ? hash['payment_instructions'] : SKIP
  memo = hash.key?('memo') ? hash['memo'] : SKIP
  seller_address = CreateInvoiceAddress.from_hash(hash['seller_address']) if
    hash['seller_address']
  billing_address = CreateInvoiceAddress.from_hash(hash['billing_address']) if
    hash['billing_address']
  shipping_address = CreateInvoiceAddress.from_hash(hash['shipping_address']) if
    hash['shipping_address']
  # Parameter is an array, so we need to iterate through it
  coupons = nil
  unless hash['coupons'].nil?
    coupons = []
    hash['coupons'].each do |structure|
      coupons << (CreateInvoiceCoupon.from_hash(structure) if structure)
    end
  end

  coupons = SKIP unless hash.key?('coupons')

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

  # Create object from extracted values.
  UpdateInvoice.new(line_items: line_items,
                    issue_date: issue_date,
                    net_terms: net_terms,
                    payment_instructions: payment_instructions,
                    memo: memo,
                    seller_address: seller_address,
                    billing_address: billing_address,
                    shipping_address: shipping_address,
                    coupons: coupons,
                    additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/advanced_billing/models/update_invoice.rb', line 58

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['line_items'] = 'line_items'
  @_hash['issue_date'] = 'issue_date'
  @_hash['net_terms'] = 'net_terms'
  @_hash['payment_instructions'] = 'payment_instructions'
  @_hash['memo'] = 'memo'
  @_hash['seller_address'] = 'seller_address'
  @_hash['billing_address'] = 'billing_address'
  @_hash['shipping_address'] = 'shipping_address'
  @_hash['coupons'] = 'coupons'
  @_hash
end

.nullablesObject

An array for nullable fields



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

def self.nullables
  []
end

.optionalsObject

An array for optional fields



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

def self.optionals
  %w[
    line_items
    issue_date
    net_terms
    payment_instructions
    memo
    seller_address
    billing_address
    shipping_address
    coupons
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



176
177
178
179
180
181
182
183
# File 'lib/advanced_billing/models/update_invoice.rb', line 176

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} line_items: #{@line_items.inspect}, issue_date: #{@issue_date.inspect},"\
  " net_terms: #{@net_terms.inspect}, payment_instructions: #{@payment_instructions.inspect},"\
  " memo: #{@memo.inspect}, seller_address: #{@seller_address.inspect}, billing_address:"\
  " #{@billing_address.inspect}, shipping_address: #{@shipping_address.inspect}, coupons:"\
  " #{@coupons.inspect}, additional_properties: #{get_additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



166
167
168
169
170
171
172
173
# File 'lib/advanced_billing/models/update_invoice.rb', line 166

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} line_items: #{@line_items}, issue_date: #{@issue_date}, net_terms:"\
  " #{@net_terms}, payment_instructions: #{@payment_instructions}, memo: #{@memo},"\
  " seller_address: #{@seller_address}, billing_address: #{@billing_address},"\
  " shipping_address: #{@shipping_address}, coupons: #{@coupons}, additional_properties:"\
  " #{get_additional_properties}>"
end