Class: ApiReference::AddIncrementCreditLedgerEntryRequestParams

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

Overview

AddIncrementCreditLedgerEntryRequestParams 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(amount:, metadata: SKIP, currency: SKIP, description: SKIP, expiry_date: SKIP, effective_date: SKIP, per_unit_cost_basis: SKIP, invoice_settings: SKIP, filters: SKIP, additional_properties: nil) ⇒ AddIncrementCreditLedgerEntryRequestParams

Returns a new instance of AddIncrementCreditLedgerEntryRequestParams.



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/api_reference/models/add_increment_credit_ledger_entry_request_params.rb', line 111

def initialize(amount:, metadata: SKIP, currency: SKIP, description: SKIP,
               expiry_date: SKIP, effective_date: SKIP,
               per_unit_cost_basis: SKIP, invoice_settings: SKIP,
               filters: SKIP, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @metadata =  unless  == SKIP
  @currency = currency unless currency == SKIP
  @description = description unless description == SKIP
  @entry_type = 'increment'
  @amount = amount
  @expiry_date = expiry_date unless expiry_date == SKIP
  @effective_date = effective_date unless effective_date == SKIP
  @per_unit_cost_basis = per_unit_cost_basis unless per_unit_cost_basis == SKIP
  @invoice_settings = invoice_settings unless invoice_settings == SKIP
  @filters = filters unless filters == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#amountFloat

The number of credits to effect. Note that this is required for increment, decrement, void, or undo operations.

Returns:

  • (Float)


38
39
40
# File 'lib/api_reference/models/add_increment_credit_ledger_entry_request_params.rb', line 38

def amount
  @amount
end

#currencyString

The currency or custom pricing unit to use for this ledger entry. If this is a real-world currency, it must match the customer's invoicing currency.

Returns:

  • (String)


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

def currency
  @currency
end

#descriptionString

Optional metadata that can be specified when adding ledger results via the API. For example, this can be used to note an increment refers to trial credits, or for noting corrections as a result of an incident, etc.

Returns:

  • (String)


27
28
29
# File 'lib/api_reference/models/add_increment_credit_ledger_entry_request_params.rb', line 27

def description
  @description
end

#effective_dateObject

An ISO 8601 format date that denotes when this credit balance should become available for use.

Returns:

  • (Object)


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

def effective_date
  @effective_date
end

#entry_typeString (readonly)

Optional metadata that can be specified when adding ledger results via the API. For example, this can be used to note an increment refers to trial credits, or for noting corrections as a result of an incident, etc.

Returns:

  • (String)


33
34
35
# File 'lib/api_reference/models/add_increment_credit_ledger_entry_request_params.rb', line 33

def entry_type
  @entry_type
end

#expiry_dateObject

An ISO 8601 format date that denotes when this credit balance should expire.

Returns:

  • (Object)


43
44
45
# File 'lib/api_reference/models/add_increment_credit_ledger_entry_request_params.rb', line 43

def expiry_date
  @expiry_date
end

#filtersArray[BlockPriceFilter]

Optional filter to specify which items this credit block applies to. If not specified, the block will apply to all items for the pricing unit.

Returns:



65
66
67
# File 'lib/api_reference/models/add_increment_credit_ledger_entry_request_params.rb', line 65

def filters
  @filters
end

#invoice_settingsIncrementCreditLedgerEntryInvoiceSettings

Passing invoice_settings automatically generates an invoice for the newly added credits. If invoice_settings is passed, you must specify per_unit_cost_basis, as the calculation of the invoice total is done on that basis.



60
61
62
# File 'lib/api_reference/models/add_increment_credit_ledger_entry_request_params.rb', line 60

def invoice_settings
  @invoice_settings
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/add_increment_credit_ledger_entry_request_params.rb', line 16

def 
  @metadata
end

#per_unit_cost_basisString

Can only be specified when entry_type=increment. How much, in the customer's currency, a customer paid for a single credit in this block

Returns:

  • (String)


53
54
55
# File 'lib/api_reference/models/add_increment_credit_ledger_entry_request_params.rb', line 53

def per_unit_cost_basis
  @per_unit_cost_basis
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/api_reference/models/add_increment_credit_ledger_entry_request_params.rb', line 132

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  amount = hash.key?('amount') ? hash['amount'] : nil
   = hash.key?('metadata') ? hash['metadata'] : SKIP
  currency = hash.key?('currency') ? hash['currency'] : SKIP
  description = hash.key?('description') ? hash['description'] : SKIP
  expiry_date = hash.key?('expiry_date') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:AddIncrementCreditLedgerEntryRequestParamsExpiryDate), hash['expiry_date']
  ) : SKIP
  effective_date = hash.key?('effective_date') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:AddIncrementCreditLedgerEntryRequestParamsEffectiveDate), hash['effective_date']
  ) : SKIP
  per_unit_cost_basis =
    hash.key?('per_unit_cost_basis') ? hash['per_unit_cost_basis'] : SKIP
  if hash['invoice_settings']
    invoice_settings = IncrementCreditLedgerEntryInvoiceSettings.from_hash(hash['invoice_settings'])
  end
  # Parameter is an array, so we need to iterate through it
  filters = nil
  unless hash['filters'].nil?
    filters = []
    hash['filters'].each do |structure|
      filters << (BlockPriceFilter.from_hash(structure) if structure)
    end
  end

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

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  AddIncrementCreditLedgerEntryRequestParams.new(amount: amount,
                                                 metadata: ,
                                                 currency: currency,
                                                 description: description,
                                                 expiry_date: expiry_date,
                                                 effective_date: effective_date,
                                                 per_unit_cost_basis: per_unit_cost_basis,
                                                 invoice_settings: invoice_settings,
                                                 filters: filters,
                                                 additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/api_reference/models/add_increment_credit_ledger_entry_request_params.rb', line 68

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['metadata'] = 'metadata'
  @_hash['currency'] = 'currency'
  @_hash['description'] = 'description'
  @_hash['entry_type'] = 'entry_type'
  @_hash['amount'] = 'amount'
  @_hash['expiry_date'] = 'expiry_date'
  @_hash['effective_date'] = 'effective_date'
  @_hash['per_unit_cost_basis'] = 'per_unit_cost_basis'
  @_hash['invoice_settings'] = 'invoice_settings'
  @_hash['filters'] = 'filters'
  @_hash
end

.nullablesObject

An array for nullable fields



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

def self.nullables
  %w[
    metadata
    currency
    description
    expiry_date
    effective_date
    per_unit_cost_basis
    invoice_settings
    filters
  ]
end

.optionalsObject

An array for optional fields



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/api_reference/models/add_increment_credit_ledger_entry_request_params.rb', line 84

def self.optionals
  %w[
    metadata
    currency
    description
    expiry_date
    effective_date
    per_unit_cost_basis
    invoice_settings
    filters
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/api_reference/models/add_increment_credit_ledger_entry_request_params.rb', line 196

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.entry_type,
                            ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.amount,
                              ->(val) { val.instance_of? Float })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['entry_type'],
                          ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['amount'],
                            ->(val) { val.instance_of? Float })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



227
228
229
230
231
232
233
234
235
# File 'lib/api_reference/models/add_increment_credit_ledger_entry_request_params.rb', line 227

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} metadata: #{@metadata.inspect}, currency: #{@currency.inspect},"\
  " description: #{@description.inspect}, entry_type: #{@entry_type.inspect}, amount:"\
  " #{@amount.inspect}, expiry_date: #{@expiry_date.inspect}, effective_date:"\
  " #{@effective_date.inspect}, per_unit_cost_basis: #{@per_unit_cost_basis.inspect},"\
  " invoice_settings: #{@invoice_settings.inspect}, filters: #{@filters.inspect},"\
  " additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



217
218
219
220
221
222
223
224
# File 'lib/api_reference/models/add_increment_credit_ledger_entry_request_params.rb', line 217

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} metadata: #{@metadata}, currency: #{@currency}, description:"\
  " #{@description}, entry_type: #{@entry_type}, amount: #{@amount}, expiry_date:"\
  " #{@expiry_date}, effective_date: #{@effective_date}, per_unit_cost_basis:"\
  " #{@per_unit_cost_basis}, invoice_settings: #{@invoice_settings}, filters: #{@filters},"\
  " additional_properties: #{@additional_properties}>"
end

#to_union_type_effective_dateObject



188
189
190
191
192
# File 'lib/api_reference/models/add_increment_credit_ledger_entry_request_params.rb', line 188

def to_union_type_effective_date
  UnionTypeLookUp.get(:AddIncrementCreditLedgerEntryRequestParamsEffectiveDate)
                 .validate(effective_date)
                 .serialize(effective_date)
end

#to_union_type_expiry_dateObject



182
183
184
185
186
# File 'lib/api_reference/models/add_increment_credit_ledger_entry_request_params.rb', line 182

def to_union_type_expiry_date
  UnionTypeLookUp.get(:AddIncrementCreditLedgerEntryRequestParamsExpiryDate)
                 .validate(expiry_date)
                 .serialize(expiry_date)
end