Class: ApiReference::CreateOneOffInvoiceParams

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/api_reference/models/create_one_off_invoice_params.rb

Overview

CreateOneOffInvoiceParams 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(currency:, invoice_date:, line_items:, metadata: SKIP, customer_id: SKIP, external_customer_id: SKIP, memo: SKIP, will_auto_issue: false, net_terms: SKIP, due_date: SKIP, discount: SKIP, auto_collection: SKIP) ⇒ CreateOneOffInvoiceParams

Returns a new instance of CreateOneOffInvoiceParams.



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/api_reference/models/create_one_off_invoice_params.rb', line 126

def initialize(currency:, invoice_date:, line_items:, metadata: SKIP,
               customer_id: SKIP, external_customer_id: SKIP, memo: SKIP,
               will_auto_issue: false, net_terms: SKIP, due_date: SKIP,
               discount: SKIP, auto_collection: SKIP)
  @metadata =  unless  == SKIP
  @customer_id = customer_id unless customer_id == SKIP
  @external_customer_id = external_customer_id unless external_customer_id == SKIP
  @currency = currency
  @memo = memo unless memo == SKIP
  @will_auto_issue = will_auto_issue unless will_auto_issue == SKIP
  @invoice_date = invoice_date
  @net_terms = net_terms unless net_terms == SKIP
  @due_date = due_date unless due_date == SKIP
  @line_items = line_items
  @discount = discount unless discount == SKIP
  @auto_collection = auto_collection unless auto_collection == SKIP
end

Instance Attribute Details

#auto_collectionTrueClass | FalseClass

Determines whether this invoice will automatically attempt to charge a saved payment method, if any. If not specified, the invoice inherits the customer's auto_collection setting.

Returns:

  • (TrueClass | FalseClass)


77
78
79
# File 'lib/api_reference/models/create_one_off_invoice_params.rb', line 77

def auto_collection
  @auto_collection
end

#currencyString

An ISO 4217 currency string. Must be the same as the customer's currency if it is set.

Returns:

  • (String)


31
32
33
# File 'lib/api_reference/models/create_one_off_invoice_params.rb', line 31

def currency
  @currency
end

#customer_idString

The id of the Customer to create this invoice for. One of customer_id and external_customer_id are required.

Returns:

  • (String)


21
22
23
# File 'lib/api_reference/models/create_one_off_invoice_params.rb', line 21

def customer_id
  @customer_id
end

#discountObject

An optional discount to attach to the invoice.

Returns:

  • (Object)


71
72
73
# File 'lib/api_reference/models/create_one_off_invoice_params.rb', line 71

def discount
  @discount
end

#due_dateObject

An optional custom due date for the invoice. If not set, the due date will be calculated based on the net_terms value.

Returns:

  • (Object)


62
63
64
# File 'lib/api_reference/models/create_one_off_invoice_params.rb', line 62

def due_date
  @due_date
end

#external_customer_idString

The external_customer_id of the Customer to create this invoice for. One of customer_id and external_customer_id are required.

Returns:

  • (String)


26
27
28
# File 'lib/api_reference/models/create_one_off_invoice_params.rb', line 26

def external_customer_id
  @external_customer_id
end

#invoice_dateObject

An ISO 8601 date or timestamp, interpreted in the customer's timezone. Must be in the past. If a date is set without a time, invoice_date is set to midnight on the chosen date in the customer's timezone.

Returns:

  • (Object)


48
49
50
# File 'lib/api_reference/models/create_one_off_invoice_params.rb', line 48

def invoice_date
  @invoice_date
end

#line_itemsArray[InvoiceLineItemParams]

An optional custom due date for the invoice. If not set, the due date will be calculated based on the net_terms value.

Returns:



67
68
69
# File 'lib/api_reference/models/create_one_off_invoice_params.rb', line 67

def line_items
  @line_items
end

#memoString

An optional memo to attach to the invoice. If no memo is provided, we will attach the default memo

Returns:

  • (String)


36
37
38
# File 'lib/api_reference/models/create_one_off_invoice_params.rb', line 36

def memo
  @memo
end

#metadataHash[String, String]

User-specified key/value pairs for the resource. Individual keys can be removed by setting the value to null, and the entire metadata mapping can be cleared by setting metadata to null.

Returns:

  • (Hash[String, String])


16
17
18
# File 'lib/api_reference/models/create_one_off_invoice_params.rb', line 16

def 
  @metadata
end

#net_termsInteger

The net terms determines the due date of the invoice. Due date is calculated based on the invoice or issuance date, depending on the account's configured due date calculation method. A value of '0' here represents that the invoice is due on issue, whereas a value of '30' represents that the customer has 30 days to pay the invoice. Do not set this field if you want to set a custom due date.

Returns:

  • (Integer)


57
58
59
# File 'lib/api_reference/models/create_one_off_invoice_params.rb', line 57

def net_terms
  @net_terms
end

#will_auto_issueTrueClass | FalseClass

When true, this invoice will be submitted for issuance upon creation. When false, the resulting invoice will require manual review to issue. Defaulted to false.

Returns:

  • (TrueClass | FalseClass)


42
43
44
# File 'lib/api_reference/models/create_one_off_invoice_params.rb', line 42

def will_auto_issue
  @will_auto_issue
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



145
146
147
148
149
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/api_reference/models/create_one_off_invoice_params.rb', line 145

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  currency = hash.key?('currency') ? hash['currency'] : nil
  invoice_date = hash.key?('invoice_date') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:CreateOneOffInvoiceParamsInvoiceDate), hash['invoice_date']
  ) : nil
  # 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 << (InvoiceLineItemParams.from_hash(structure) if structure)
    end
  end

  line_items = nil unless hash.key?('line_items')
   = hash.key?('metadata') ? hash['metadata'] : SKIP
  customer_id = hash.key?('customer_id') ? hash['customer_id'] : SKIP
  external_customer_id =
    hash.key?('external_customer_id') ? hash['external_customer_id'] : SKIP
  memo = hash.key?('memo') ? hash['memo'] : SKIP
  will_auto_issue = hash['will_auto_issue'] ||= false
  net_terms = hash.key?('net_terms') ? hash['net_terms'] : SKIP
  due_date = hash.key?('due_date') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:CreateOneOffInvoiceParamsDueDate), hash['due_date']
  ) : SKIP
  discount = hash.key?('discount') ? hash['discount'] : SKIP
  auto_collection =
    hash.key?('auto_collection') ? hash['auto_collection'] : SKIP

  # Create object from extracted values.
  CreateOneOffInvoiceParams.new(currency: currency,
                                invoice_date: invoice_date,
                                line_items: line_items,
                                metadata: ,
                                customer_id: customer_id,
                                external_customer_id: external_customer_id,
                                memo: memo,
                                will_auto_issue: will_auto_issue,
                                net_terms: net_terms,
                                due_date: due_date,
                                discount: discount,
                                auto_collection: auto_collection)
end

.namesObject

A mapping from model property names to API property names.



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/api_reference/models/create_one_off_invoice_params.rb', line 80

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['metadata'] = 'metadata'
  @_hash['customer_id'] = 'customer_id'
  @_hash['external_customer_id'] = 'external_customer_id'
  @_hash['currency'] = 'currency'
  @_hash['memo'] = 'memo'
  @_hash['will_auto_issue'] = 'will_auto_issue'
  @_hash['invoice_date'] = 'invoice_date'
  @_hash['net_terms'] = 'net_terms'
  @_hash['due_date'] = 'due_date'
  @_hash['line_items'] = 'line_items'
  @_hash['discount'] = 'discount'
  @_hash['auto_collection'] = 'auto_collection'
  @_hash
end

.nullablesObject

An array for nullable fields



113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/api_reference/models/create_one_off_invoice_params.rb', line 113

def self.nullables
  %w[
    metadata
    customer_id
    external_customer_id
    memo
    net_terms
    due_date
    discount
    auto_collection
  ]
end

.optionalsObject

An array for optional fields



98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/api_reference/models/create_one_off_invoice_params.rb', line 98

def self.optionals
  %w[
    metadata
    customer_id
    external_customer_id
    memo
    will_auto_issue
    net_terms
    due_date
    discount
    auto_collection
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/api_reference/models/create_one_off_invoice_params.rb', line 206

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.currency,
                            ->(val) { val.instance_of? String }) and
        UnionTypeLookUp.get(:CreateOneOffInvoiceParamsInvoiceDate)
                       .validate(value.invoice_date) and
        APIHelper.valid_type?(value.line_items,
                              ->(val) { InvoiceLineItemParams.validate(val) },
                              is_model_hash: true,
                              is_inner_model_hash: true)
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['currency'],
                          ->(val) { val.instance_of? String }) and
      UnionTypeLookUp.get(:CreateOneOffInvoiceParamsInvoiceDate)
                     .validate(value['invoice_date']) and
      APIHelper.valid_type?(value['line_items'],
                            ->(val) { InvoiceLineItemParams.validate(val) },
                            is_model_hash: true,
                            is_inner_model_hash: true)
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



245
246
247
248
249
250
251
252
253
# File 'lib/api_reference/models/create_one_off_invoice_params.rb', line 245

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} metadata: #{@metadata.inspect}, customer_id: #{@customer_id.inspect},"\
  " external_customer_id: #{@external_customer_id.inspect}, currency: #{@currency.inspect},"\
  " memo: #{@memo.inspect}, will_auto_issue: #{@will_auto_issue.inspect}, invoice_date:"\
  " #{@invoice_date.inspect}, net_terms: #{@net_terms.inspect}, due_date:"\
  " #{@due_date.inspect}, line_items: #{@line_items.inspect}, discount: #{@discount.inspect},"\
  " auto_collection: #{@auto_collection.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



235
236
237
238
239
240
241
242
# File 'lib/api_reference/models/create_one_off_invoice_params.rb', line 235

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} metadata: #{@metadata}, customer_id: #{@customer_id}, external_customer_id:"\
  " #{@external_customer_id}, currency: #{@currency}, memo: #{@memo}, will_auto_issue:"\
  " #{@will_auto_issue}, invoice_date: #{@invoice_date}, net_terms: #{@net_terms}, due_date:"\
  " #{@due_date}, line_items: #{@line_items}, discount: #{@discount}, auto_collection:"\
  " #{@auto_collection}>"
end

#to_union_type_due_dateObject



198
199
200
201
202
# File 'lib/api_reference/models/create_one_off_invoice_params.rb', line 198

def to_union_type_due_date
  UnionTypeLookUp.get(:CreateOneOffInvoiceParamsDueDate)
                 .validate(due_date)
                 .serialize(due_date)
end

#to_union_type_invoice_dateObject



192
193
194
195
196
# File 'lib/api_reference/models/create_one_off_invoice_params.rb', line 192

def to_union_type_invoice_date
  UnionTypeLookUp.get(:CreateOneOffInvoiceParamsInvoiceDate)
                 .validate(invoice_date)
                 .serialize(invoice_date)
end