Class: AdvancedBilling::DebitNote

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

Overview

DebitNote Model.

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(uid: SKIP, site_id: SKIP, customer_id: SKIP, subscription_id: SKIP, number: SKIP, sequence_number: SKIP, origin_credit_note_uid: SKIP, origin_credit_note_number: SKIP, issue_date: SKIP, applied_date: SKIP, due_date: SKIP, status: SKIP, memo: SKIP, role: SKIP, currency: SKIP, seller: SKIP, customer: SKIP, billing_address: SKIP, shipping_address: SKIP, line_items: SKIP, discounts: SKIP, taxes: SKIP, refunds: SKIP, additional_properties: {}) ⇒ DebitNote

Returns a new instance of DebitNote.



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/advanced_billing/models/debit_note.rb', line 183

def initialize(uid: SKIP, site_id: SKIP, customer_id: SKIP,
               subscription_id: SKIP, number: SKIP, sequence_number: SKIP,
               origin_credit_note_uid: SKIP,
               origin_credit_note_number: SKIP, issue_date: SKIP,
               applied_date: SKIP, due_date: SKIP, status: SKIP, memo: SKIP,
               role: SKIP, currency: SKIP, seller: SKIP, customer: SKIP,
               billing_address: SKIP, shipping_address: SKIP,
               line_items: SKIP, discounts: SKIP, taxes: SKIP,
               refunds: SKIP, additional_properties: {})
  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end

  @uid = uid unless uid == SKIP
  @site_id = site_id unless site_id == SKIP
  @customer_id = customer_id unless customer_id == SKIP
  @subscription_id = subscription_id unless subscription_id == SKIP
  @number = number unless number == SKIP
  @sequence_number = sequence_number unless sequence_number == SKIP
  @origin_credit_note_uid = origin_credit_note_uid unless origin_credit_note_uid == SKIP
  unless origin_credit_note_number == SKIP
    @origin_credit_note_number =
      origin_credit_note_number
  end
  @issue_date = issue_date unless issue_date == SKIP
  @applied_date = applied_date unless applied_date == SKIP
  @due_date = due_date unless due_date == SKIP
  @status = status unless status == SKIP
  @memo = memo unless memo == SKIP
  @role = role unless role == SKIP
  @currency = currency unless currency == SKIP
  @seller = seller unless seller == SKIP
  @customer = customer unless customer == SKIP
  @billing_address = billing_address unless billing_address == SKIP
  @shipping_address = shipping_address unless shipping_address == SKIP
  @line_items = line_items unless line_items == SKIP
  @discounts = discounts unless discounts == SKIP
  @taxes = taxes unless taxes == SKIP
  @refunds = refunds unless refunds == SKIP
end

Instance Attribute Details

#applied_dateDate

Debit notes are applied to invoices to offset invoiced amounts - they adjust the amount due. This field is the date the debit note document became fully applied to the invoice. The format is “YYYY-MM-DD”.

Returns:

  • (Date)


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

def applied_date
  @applied_date
end

#billing_addressInvoiceAddress

The billing address of the debited subscription.

Returns:



98
99
100
# File 'lib/advanced_billing/models/debit_note.rb', line 98

def billing_address
  @billing_address
end

#currencyString

The ISO 4217 currency code (3 character string) representing the currency of the credit note amount fields.

Returns:

  • (String)


84
85
86
# File 'lib/advanced_billing/models/debit_note.rb', line 84

def currency
  @currency
end

#customerInvoiceCustomer

Information about the customer who is owner or recipient the debited subscription.

Returns:



94
95
96
# File 'lib/advanced_billing/models/debit_note.rb', line 94

def customer
  @customer
end

#customer_idInteger

ID of the customer to which the debit note belongs.

Returns:

  • (Integer)


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

def customer_id
  @customer_id
end

#discountsArray[InvoiceDiscount]

Line items on the debit note.

Returns:



110
111
112
# File 'lib/advanced_billing/models/debit_note.rb', line 110

def discounts
  @discounts
end

#due_dateDate

Date the document is due for payment. The format is “YYYY-MM-DD”.

Returns:

  • (Date)


66
67
68
# File 'lib/advanced_billing/models/debit_note.rb', line 66

def due_date
  @due_date
end

#issue_dateDate

Date the document was issued to the customer. This is the date that the document was made available for payment. The format is “YYYY-MM-DD”.

Returns:

  • (Date)


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

def issue_date
  @issue_date
end

#line_itemsArray[CreditNoteLineItem]

Line items on the debit note.

Returns:



106
107
108
# File 'lib/advanced_billing/models/debit_note.rb', line 106

def line_items
  @line_items
end

#memoString

The memo printed on debit note, which is a description of the reason for the debit.

Returns:

  • (String)


75
76
77
# File 'lib/advanced_billing/models/debit_note.rb', line 75

def memo
  @memo
end

#numberInteger

A unique, identifier that appears on the debit note and in places it is referenced.

Returns:

  • (Integer)


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

def number
  @number
end

#origin_credit_note_numberString

A unique, identifying string of the connected credit note.

Returns:

  • (String)


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

def origin_credit_note_number
  @origin_credit_note_number
end

#origin_credit_note_uidString

Unique identifier for the connected credit note. It is generated automatically by Chargify and has the prefix “cn_” followed by alphanumeric characters. While the UID is long and not appropriate to show to customers, the number is usually shorter and consumable by the customer and the merchant alike.

Returns:

  • (String)


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

def origin_credit_note_uid
  @origin_credit_note_uid
end

#refundsArray[InvoiceRefund]

Line items on the debit note.

Returns:



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

def refunds
  @refunds
end

#roleDebitNoteRole

The role of the debit note.

Returns:



79
80
81
# File 'lib/advanced_billing/models/debit_note.rb', line 79

def role
  @role
end

#sellerInvoiceSeller

Information about the seller (merchant) listed on the masthead of the debit note.

Returns:



89
90
91
# File 'lib/advanced_billing/models/debit_note.rb', line 89

def seller
  @seller
end

#sequence_numberInteger

A monotonically increasing number assigned to debit notes as they are created.

Returns:

  • (Integer)


37
38
39
# File 'lib/advanced_billing/models/debit_note.rb', line 37

def sequence_number
  @sequence_number
end

#shipping_addressInvoiceAddress

The shipping address of the debited subscription.

Returns:



102
103
104
# File 'lib/advanced_billing/models/debit_note.rb', line 102

def shipping_address
  @shipping_address
end

#site_idInteger

ID of the site to which the debit note belongs.

Returns:

  • (Integer)


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

def site_id
  @site_id
end

#statusDebitNoteStatus

Current status of the debit note.

Returns:



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

def status
  @status
end

#subscription_idInteger

ID of the subscription that generated the debit note.

Returns:

  • (Integer)


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

def subscription_id
  @subscription_id
end

#taxesArray[InvoiceTax]

Line items on the debit note.

Returns:



114
115
116
# File 'lib/advanced_billing/models/debit_note.rb', line 114

def taxes
  @taxes
end

#uidString

Unique identifier for the debit note. It is generated automatically by Chargify and has the prefix “db_” followed by alphanumeric characters.

Returns:

  • (String)


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

def uid
  @uid
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'lib/advanced_billing/models/debit_note.rb', line 226

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  uid = hash.key?('uid') ? hash['uid'] : SKIP
  site_id = hash.key?('site_id') ? hash['site_id'] : SKIP
  customer_id = hash.key?('customer_id') ? hash['customer_id'] : SKIP
  subscription_id =
    hash.key?('subscription_id') ? hash['subscription_id'] : SKIP
  number = hash.key?('number') ? hash['number'] : SKIP
  sequence_number =
    hash.key?('sequence_number') ? hash['sequence_number'] : SKIP
  origin_credit_note_uid =
    hash.key?('origin_credit_note_uid') ? hash['origin_credit_note_uid'] : SKIP
  origin_credit_note_number =
    hash.key?('origin_credit_note_number') ? hash['origin_credit_note_number'] : SKIP
  issue_date = hash.key?('issue_date') ? hash['issue_date'] : SKIP
  applied_date = hash.key?('applied_date') ? hash['applied_date'] : SKIP
  due_date = hash.key?('due_date') ? hash['due_date'] : SKIP
  status = hash.key?('status') ? hash['status'] : SKIP
  memo = hash.key?('memo') ? hash['memo'] : SKIP
  role = hash.key?('role') ? hash['role'] : SKIP
  currency = hash.key?('currency') ? hash['currency'] : SKIP
  seller = InvoiceSeller.from_hash(hash['seller']) if hash['seller']
  customer = InvoiceCustomer.from_hash(hash['customer']) if hash['customer']
  billing_address = InvoiceAddress.from_hash(hash['billing_address']) if
    hash['billing_address']
  shipping_address = InvoiceAddress.from_hash(hash['shipping_address']) if
    hash['shipping_address']
  # 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 << (CreditNoteLineItem.from_hash(structure) if structure)
    end
  end

  line_items = SKIP unless hash.key?('line_items')
  # Parameter is an array, so we need to iterate through it
  discounts = nil
  unless hash['discounts'].nil?
    discounts = []
    hash['discounts'].each do |structure|
      discounts << (InvoiceDiscount.from_hash(structure) if structure)
    end
  end

  discounts = SKIP unless hash.key?('discounts')
  # Parameter is an array, so we need to iterate through it
  taxes = nil
  unless hash['taxes'].nil?
    taxes = []
    hash['taxes'].each do |structure|
      taxes << (InvoiceTax.from_hash(structure) if structure)
    end
  end

  taxes = SKIP unless hash.key?('taxes')
  # Parameter is an array, so we need to iterate through it
  refunds = nil
  unless hash['refunds'].nil?
    refunds = []
    hash['refunds'].each do |structure|
      refunds << (InvoiceRefund.from_hash(structure) if structure)
    end
  end

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

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

  # Create object from extracted values.
  DebitNote.new(uid: uid,
                site_id: site_id,
                customer_id: customer_id,
                subscription_id: subscription_id,
                number: number,
                sequence_number: sequence_number,
                origin_credit_note_uid: origin_credit_note_uid,
                origin_credit_note_number: origin_credit_note_number,
                issue_date: issue_date,
                applied_date: applied_date,
                due_date: due_date,
                status: status,
                memo: memo,
                role: role,
                currency: currency,
                seller: seller,
                customer: customer,
                billing_address: billing_address,
                shipping_address: shipping_address,
                line_items: line_items,
                discounts: discounts,
                taxes: taxes,
                refunds: refunds,
                additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



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

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['uid'] = 'uid'
  @_hash['site_id'] = 'site_id'
  @_hash['customer_id'] = 'customer_id'
  @_hash['subscription_id'] = 'subscription_id'
  @_hash['number'] = 'number'
  @_hash['sequence_number'] = 'sequence_number'
  @_hash['origin_credit_note_uid'] = 'origin_credit_note_uid'
  @_hash['origin_credit_note_number'] = 'origin_credit_note_number'
  @_hash['issue_date'] = 'issue_date'
  @_hash['applied_date'] = 'applied_date'
  @_hash['due_date'] = 'due_date'
  @_hash['status'] = 'status'
  @_hash['memo'] = 'memo'
  @_hash['role'] = 'role'
  @_hash['currency'] = 'currency'
  @_hash['seller'] = 'seller'
  @_hash['customer'] = 'customer'
  @_hash['billing_address'] = 'billing_address'
  @_hash['shipping_address'] = 'shipping_address'
  @_hash['line_items'] = 'line_items'
  @_hash['discounts'] = 'discounts'
  @_hash['taxes'] = 'taxes'
  @_hash['refunds'] = 'refunds'
  @_hash
end

.nullablesObject

An array for nullable fields



179
180
181
# File 'lib/advanced_billing/models/debit_note.rb', line 179

def self.nullables
  []
end

.optionalsObject

An array for optional fields



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/advanced_billing/models/debit_note.rb', line 150

def self.optionals
  %w[
    uid
    site_id
    customer_id
    subscription_id
    number
    sequence_number
    origin_credit_note_uid
    origin_credit_note_number
    issue_date
    applied_date
    due_date
    status
    memo
    role
    currency
    seller
    customer
    billing_address
    shipping_address
    line_items
    discounts
    taxes
    refunds
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (DebitNote | Hash)

    value against the validation is performed.



328
329
330
331
332
333
334
# File 'lib/advanced_billing/models/debit_note.rb', line 328

def self.validate(value)
  return true if value.instance_of? self

  return false unless value.instance_of? Hash

  true
end