Class: NewStoreApi::TransactionDto

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/new_store_api/models/transaction_dto.rb

Overview

TransactionDto 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(items = nil, order_id = nil, calculation_mode = SKIP, exemption_class = SKIP, exemption_number = SKIP, return_id = SKIP, tax_date = SKIP, tax_exempt = false, transaction_type = SKIP) ⇒ TransactionDto

Returns a new instance of TransactionDto.



96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/new_store_api/models/transaction_dto.rb', line 96

def initialize(items = nil, order_id = nil, calculation_mode = SKIP,
               exemption_class = SKIP, exemption_number = SKIP,
               return_id = SKIP, tax_date = SKIP, tax_exempt = false,
               transaction_type = SKIP)
  @calculation_mode = calculation_mode unless calculation_mode == SKIP
  @exemption_class = exemption_class unless exemption_class == SKIP
  @exemption_number = exemption_number unless exemption_number == SKIP
  @items = items
  @order_id = order_id
  @return_id = return_id unless return_id == SKIP
  @tax_date = tax_date unless tax_date == SKIP
  @tax_exempt = tax_exempt unless tax_exempt == SKIP
  @transaction_type = transaction_type unless transaction_type == SKIP
end

Instance Attribute Details

#calculation_modeCalculationModeEnum

TODO: Write general description for this method

Returns:



15
16
17
# File 'lib/new_store_api/models/transaction_dto.rb', line 15

def calculation_mode
  @calculation_mode
end

#exemption_classExemptionClassEnum

TODO: Write general description for this method

Returns:



19
20
21
# File 'lib/new_store_api/models/transaction_dto.rb', line 19

def exemption_class
  @exemption_class
end

#exemption_numberString

The number of the customer's exemption certificate.

  • The given value can be verified by the auditors in the event of a tax audit.

Returns:

  • (String)


25
26
27
# File 'lib/new_store_api/models/transaction_dto.rb', line 25

def exemption_number
  @exemption_number
end

#itemsArray[Object]

A list of the items sold/returned in the transaction.

  • The type ReverseCalculationTransactionItemDto should be used when the calculation_mode is set to REVERSE.
  • The type TransactionItemDto should be used When the calculation_mode is not sent or set to STANDARD.

Returns:

  • (Array[Object])


33
34
35
# File 'lib/new_store_api/models/transaction_dto.rb', line 33

def items
  @items
end

#order_idString

The order ID that will be used as a reference to link the order to the created tax transaction in the tax provider records.

  • In case the order ID is not provided then a randomly generated identifier will be used instead.
  • The tax transaction will be stored by using the given value.

Returns:

  • (String)


41
42
43
# File 'lib/new_store_api/models/transaction_dto.rb', line 41

def order_id
  @order_id
end

#return_idString

The return ID that will be used as a reference to link the order to the created tax transaction in the tax provider records.

  • The tax transaction for returns will be stored by using the given value.
  • If the value is not set, the return transaction will not be stored.

Returns:

  • (String)


48
49
50
# File 'lib/new_store_api/models/transaction_dto.rb', line 48

def return_id
  @return_id
end

#tax_dateDateTime

Date of the transaction (in UTC timezone) that'll be used in committing taxes.

Returns:

  • (DateTime)


53
54
55
# File 'lib/new_store_api/models/transaction_dto.rb', line 53

def tax_date
  @tax_date
end

#tax_exemptTrueClass | FalseClass

Defines the tax exemption status of the transaction.

Returns:

  • (TrueClass | FalseClass)


57
58
59
# File 'lib/new_store_api/models/transaction_dto.rb', line 57

def tax_exempt
  @tax_exempt
end

#transaction_typeTransactionTypeEnum

Defines the tax exemption status of the transaction.

Returns:



61
62
63
# File 'lib/new_store_api/models/transaction_dto.rb', line 61

def transaction_type
  @transaction_type
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



112
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
# File 'lib/new_store_api/models/transaction_dto.rb', line 112

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  items = hash.key?('items') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:TransactionDtoItems), hash['items']
  ) : nil
  order_id = hash.key?('order_id') ? hash['order_id'] : nil
  calculation_mode =
    hash.key?('calculation_mode') ? hash['calculation_mode'] : SKIP
  exemption_class =
    hash.key?('exemption_class') ? hash['exemption_class'] : SKIP
  exemption_number =
    hash.key?('exemption_number') ? hash['exemption_number'] : SKIP
  return_id = hash.key?('return_id') ? hash['return_id'] : SKIP
  tax_date = if hash.key?('tax_date')
               (DateTimeHelper.from_rfc3339(hash['tax_date']) if hash['tax_date'])
             else
               SKIP
             end
  tax_exempt = hash['tax_exempt'] ||= false
  transaction_type =
    hash.key?('transaction_type') ? hash['transaction_type'] : SKIP

  # Create object from extracted values.
  TransactionDto.new(items,
                     order_id,
                     calculation_mode,
                     exemption_class,
                     exemption_number,
                     return_id,
                     tax_date,
                     tax_exempt,
                     transaction_type)
end

.namesObject

A mapping from model property names to API property names.



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/new_store_api/models/transaction_dto.rb', line 64

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['calculation_mode'] = 'calculation_mode'
  @_hash['exemption_class'] = 'exemption_class'
  @_hash['exemption_number'] = 'exemption_number'
  @_hash['items'] = 'items'
  @_hash['order_id'] = 'order_id'
  @_hash['return_id'] = 'return_id'
  @_hash['tax_date'] = 'tax_date'
  @_hash['tax_exempt'] = 'tax_exempt'
  @_hash['transaction_type'] = 'transaction_type'
  @_hash
end

.nullablesObject

An array for nullable fields



92
93
94
# File 'lib/new_store_api/models/transaction_dto.rb', line 92

def self.nullables
  []
end

.optionalsObject

An array for optional fields



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/new_store_api/models/transaction_dto.rb', line 79

def self.optionals
  %w[
    calculation_mode
    exemption_class
    exemption_number
    return_id
    tax_date
    tax_exempt
    transaction_type
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (TransactionDto | Hash)

    value against the validation is performed.



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/new_store_api/models/transaction_dto.rb', line 154

def self.validate(value)
  if value.instance_of? self
    return (
      UnionTypeLookUp.get(:TransactionDtoItems)
                     .validate(value.items) and
        APIHelper.valid_type?(value.order_id,
                              ->(val) { val.instance_of? String })
    )
  end

  return false unless value.instance_of? Hash

  (
    UnionTypeLookUp.get(:TransactionDtoItems)
                   .validate(value['items']) and
      APIHelper.valid_type?(value['order_id'],
                            ->(val) { val.instance_of? String })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



184
185
186
187
188
189
190
191
# File 'lib/new_store_api/models/transaction_dto.rb', line 184

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} calculation_mode: #{@calculation_mode.inspect}, exemption_class:"\
  " #{@exemption_class.inspect}, exemption_number: #{@exemption_number.inspect}, items:"\
  " #{@items.inspect}, order_id: #{@order_id.inspect}, return_id: #{@return_id.inspect},"\
  " tax_date: #{@tax_date.inspect}, tax_exempt: #{@tax_exempt.inspect}, transaction_type:"\
  " #{@transaction_type.inspect}>"
end

#to_custom_tax_dateObject



148
149
150
# File 'lib/new_store_api/models/transaction_dto.rb', line 148

def to_custom_tax_date
  DateTimeHelper.to_rfc3339(tax_date)
end

#to_sObject

Provides a human-readable string representation of the object.



175
176
177
178
179
180
181
# File 'lib/new_store_api/models/transaction_dto.rb', line 175

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} calculation_mode: #{@calculation_mode}, exemption_class:"\
  " #{@exemption_class}, exemption_number: #{@exemption_number}, items: #{@items}, order_id:"\
  " #{@order_id}, return_id: #{@return_id}, tax_date: #{@tax_date}, tax_exempt:"\
  " #{@tax_exempt}, transaction_type: #{@transaction_type}>"
end