Class: AdvancedBilling::CreditNote

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

Overview

CreditNote 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, issue_date: SKIP, applied_date: SKIP, status: SKIP, currency: SKIP, memo: SKIP, seller: SKIP, customer: SKIP, billing_address: SKIP, shipping_address: SKIP, subtotal_amount: SKIP, discount_amount: SKIP, tax_amount: SKIP, total_amount: SKIP, applied_amount: SKIP, remaining_amount: SKIP, line_items: SKIP, discounts: SKIP, taxes: SKIP, applications: SKIP, refunds: SKIP, origin_invoices: SKIP, additional_properties: {}) ⇒ CreditNote

Returns a new instance of CreditNote.



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

def initialize(uid: SKIP, site_id: SKIP, customer_id: SKIP,
               subscription_id: SKIP, number: SKIP, sequence_number: SKIP,
               issue_date: SKIP, applied_date: SKIP, status: SKIP,
               currency: SKIP, memo: SKIP, seller: SKIP, customer: SKIP,
               billing_address: SKIP, shipping_address: SKIP,
               subtotal_amount: SKIP, discount_amount: SKIP,
               tax_amount: SKIP, total_amount: SKIP, applied_amount: SKIP,
               remaining_amount: SKIP, line_items: SKIP, discounts: SKIP,
               taxes: SKIP, applications: SKIP, refunds: SKIP,
               origin_invoices: 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
  @issue_date = issue_date unless issue_date == SKIP
  @applied_date = applied_date unless applied_date == SKIP
  @status = status unless status == SKIP
  @currency = currency unless currency == SKIP
  @memo = memo unless memo == 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
  @subtotal_amount = subtotal_amount unless subtotal_amount == SKIP
  @discount_amount = discount_amount unless discount_amount == SKIP
  @tax_amount = tax_amount unless tax_amount == SKIP
  @total_amount = total_amount unless total_amount == SKIP
  @applied_amount = applied_amount unless applied_amount == SKIP
  @remaining_amount = remaining_amount unless remaining_amount == SKIP
  @line_items = line_items unless line_items == SKIP
  @discounts = discounts unless discounts == SKIP
  @taxes = taxes unless taxes == SKIP
  @applications = applications unless applications == SKIP
  @refunds = refunds unless refunds == SKIP
  @origin_invoices = origin_invoices unless origin_invoices == SKIP
end

Instance Attribute Details

#applicationsArray[CreditNoteApplication]

Line items on the credit note.

Returns:



142
143
144
# File 'lib/advanced_billing/models/credit_note.rb', line 142

def applications
  @applications
end

#applied_amountString

The amount of the credit note that has already been applied to invoices.

Returns:

  • (String)


121
122
123
# File 'lib/advanced_billing/models/credit_note.rb', line 121

def applied_amount
  @applied_amount
end

#applied_dateDate

Credit notes are applied to invoices to offset invoiced amounts - they reduce the amount due. This field is the date the credit note became fully applied to invoices. If the credit note has been partially applied, this field will not have a value until it has been fully applied. The format is ‘“YYYY-MM-DD”`.

Returns:

  • (Date)


56
57
58
# File 'lib/advanced_billing/models/credit_note.rb', line 56

def applied_date
  @applied_date
end

#billing_addressInvoiceAddress

The billing address of the credit subscription.

Returns:



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

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)


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

def currency
  @currency
end

#customerInvoiceCustomer

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

Returns:



80
81
82
# File 'lib/advanced_billing/models/credit_note.rb', line 80

def customer
  @customer
end

#customer_idInteger

ID of the customer to which the credit note belongs.

Returns:

  • (Integer)


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

def customer_id
  @customer_id
end

#discount_amountString

Total discount applied to the credit note. Note that this is a positive amount representing the discount amount being credited back to the customer (i.e. a credit on an earlier discount). For example, if the original purchase was $1.00 and the original discount was $0.10, a credit of $0.50 of the original purchase (half) would have a discount credit of $0.05 (also half).

Returns:

  • (String)


103
104
105
# File 'lib/advanced_billing/models/credit_note.rb', line 103

def discount_amount
  @discount_amount
end

#discountsArray[InvoiceDiscount]

Line items on the credit note.

Returns:



134
135
136
# File 'lib/advanced_billing/models/credit_note.rb', line 134

def discounts
  @discounts
end

#issue_dateDate

Date the credit note was issued to the customer. This is the date that the credit was made available for application, and may come before it is fully applied. The format is ‘“YYYY-MM-DD”`.

Returns:

  • (Date)


47
48
49
# File 'lib/advanced_billing/models/credit_note.rb', line 47

def issue_date
  @issue_date
end

#line_itemsArray[CreditNoteLineItem]

Line items on the credit note.

Returns:



130
131
132
# File 'lib/advanced_billing/models/credit_note.rb', line 130

def line_items
  @line_items
end

#memoString

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

Returns:

  • (String)


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

def memo
  @memo
end

#numberString

A unique, identifying string that appears on the credit note and in places it is referenced. 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)


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

def number
  @number
end

#origin_invoicesArray[OriginInvoice]

An array of origin invoices for the credit note. Learn more about [Origin Invoice from our docs](maxio.zendesk.com/hc/en-us/articles/24252261284749-Credit-No tes-Proration#origin-invoices)

Returns:



153
154
155
# File 'lib/advanced_billing/models/credit_note.rb', line 153

def origin_invoices
  @origin_invoices
end

#refundsArray[InvoiceRefund]

Line items on the credit note.

Returns:



146
147
148
# File 'lib/advanced_billing/models/credit_note.rb', line 146

def refunds
  @refunds
end

#remaining_amountString

The amount of the credit note remaining to be applied to invoices, which is ‘total_amount - applied_amount`.

Returns:

  • (String)


126
127
128
# File 'lib/advanced_billing/models/credit_note.rb', line 126

def remaining_amount
  @remaining_amount
end

#sellerInvoiceSeller

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

Returns:



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

def seller
  @seller
end

#sequence_numberInteger

A monotonically increasing number assigned to credit notes as they are created. This number is unique within a site and can be used to sort and order credit notes.

Returns:

  • (Integer)


40
41
42
# File 'lib/advanced_billing/models/credit_note.rb', line 40

def sequence_number
  @sequence_number
end

#shipping_addressInvoiceAddress

The shipping address of the credited subscription.

Returns:



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

def shipping_address
  @shipping_address
end

#site_idInteger

ID of the site to which the credit note belongs.

Returns:

  • (Integer)


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

def site_id
  @site_id
end

#statusCreditNoteStatus

Current status of the credit note.

Returns:



60
61
62
# File 'lib/advanced_billing/models/credit_note.rb', line 60

def status
  @status
end

#subscription_idInteger

ID of the subscription that generated the credit note.

Returns:

  • (Integer)


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

def subscription_id
  @subscription_id
end

#subtotal_amountString

Subtotal of the credit note, which is the sum of all line items before discounts or taxes. Note that this is a positive amount representing the credit back to the customer.

Returns:

  • (String)


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

def subtotal_amount
  @subtotal_amount
end

#tax_amountString

Total tax of the credit note. Note that this is a positive amount representing a previously taxex amount being credited back to the customer (i.e. a credit of an earlier tax). For example, if the original purchase was $1.00 and the original tax was $0.10, a credit of $0.50 of the original purchase (half) would also have a tax credit of $0.05 (also half).

Returns:

  • (String)


112
113
114
# File 'lib/advanced_billing/models/credit_note.rb', line 112

def tax_amount
  @tax_amount
end

#taxesArray[InvoiceTax]

Line items on the credit note.

Returns:



138
139
140
# File 'lib/advanced_billing/models/credit_note.rb', line 138

def taxes
  @taxes
end

#total_amountString

The credit note total, which is ‘subtotal_amount - discount_amount + tax_amount`.’

Returns:

  • (String)


117
118
119
# File 'lib/advanced_billing/models/credit_note.rb', line 117

def total_amount
  @total_amount
end

#uidString

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

Returns:

  • (String)


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

def uid
  @uid
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
# File 'lib/advanced_billing/models/credit_note.rb', line 271

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
  issue_date = hash.key?('issue_date') ? hash['issue_date'] : SKIP
  applied_date = hash.key?('applied_date') ? hash['applied_date'] : SKIP
  status = hash.key?('status') ? hash['status'] : SKIP
  currency = hash.key?('currency') ? hash['currency'] : SKIP
  memo = hash.key?('memo') ? hash['memo'] : 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']
  subtotal_amount =
    hash.key?('subtotal_amount') ? hash['subtotal_amount'] : SKIP
  discount_amount =
    hash.key?('discount_amount') ? hash['discount_amount'] : SKIP
  tax_amount = hash.key?('tax_amount') ? hash['tax_amount'] : SKIP
  total_amount = hash.key?('total_amount') ? hash['total_amount'] : SKIP
  applied_amount =
    hash.key?('applied_amount') ? hash['applied_amount'] : SKIP
  remaining_amount =
    hash.key?('remaining_amount') ? hash['remaining_amount'] : SKIP
  # 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
  applications = nil
  unless hash['applications'].nil?
    applications = []
    hash['applications'].each do |structure|
      applications << (CreditNoteApplication.from_hash(structure) if structure)
    end
  end

  applications = SKIP unless hash.key?('applications')
  # 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')
  # Parameter is an array, so we need to iterate through it
  origin_invoices = nil
  unless hash['origin_invoices'].nil?
    origin_invoices = []
    hash['origin_invoices'].each do |structure|
      origin_invoices << (OriginInvoice.from_hash(structure) if structure)
    end
  end

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

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

  # Create object from extracted values.
  CreditNote.new(uid: uid,
                 site_id: site_id,
                 customer_id: customer_id,
                 subscription_id: subscription_id,
                 number: number,
                 sequence_number: sequence_number,
                 issue_date: issue_date,
                 applied_date: applied_date,
                 status: status,
                 currency: currency,
                 memo: memo,
                 seller: seller,
                 customer: customer,
                 billing_address: billing_address,
                 shipping_address: shipping_address,
                 subtotal_amount: subtotal_amount,
                 discount_amount: discount_amount,
                 tax_amount: tax_amount,
                 total_amount: total_amount,
                 applied_amount: applied_amount,
                 remaining_amount: remaining_amount,
                 line_items: line_items,
                 discounts: discounts,
                 taxes: taxes,
                 applications: applications,
                 refunds: refunds,
                 origin_invoices: origin_invoices,
                 additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/advanced_billing/models/credit_note.rb', line 156

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['issue_date'] = 'issue_date'
  @_hash['applied_date'] = 'applied_date'
  @_hash['status'] = 'status'
  @_hash['currency'] = 'currency'
  @_hash['memo'] = 'memo'
  @_hash['seller'] = 'seller'
  @_hash['customer'] = 'customer'
  @_hash['billing_address'] = 'billing_address'
  @_hash['shipping_address'] = 'shipping_address'
  @_hash['subtotal_amount'] = 'subtotal_amount'
  @_hash['discount_amount'] = 'discount_amount'
  @_hash['tax_amount'] = 'tax_amount'
  @_hash['total_amount'] = 'total_amount'
  @_hash['applied_amount'] = 'applied_amount'
  @_hash['remaining_amount'] = 'remaining_amount'
  @_hash['line_items'] = 'line_items'
  @_hash['discounts'] = 'discounts'
  @_hash['taxes'] = 'taxes'
  @_hash['applications'] = 'applications'
  @_hash['refunds'] = 'refunds'
  @_hash['origin_invoices'] = 'origin_invoices'
  @_hash
end

.nullablesObject

An array for nullable fields



222
223
224
# File 'lib/advanced_billing/models/credit_note.rb', line 222

def self.nullables
  []
end

.optionalsObject

An array for optional fields



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

def self.optionals
  %w[
    uid
    site_id
    customer_id
    subscription_id
    number
    sequence_number
    issue_date
    applied_date
    status
    currency
    memo
    seller
    customer
    billing_address
    shipping_address
    subtotal_amount
    discount_amount
    tax_amount
    total_amount
    applied_amount
    remaining_amount
    line_items
    discounts
    taxes
    applications
    refunds
    origin_invoices
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (CreditNote | Hash)

    value against the validation is performed.



401
402
403
404
405
406
407
# File 'lib/advanced_billing/models/credit_note.rb', line 401

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

  return false unless value.instance_of? Hash

  true
end