Class: NewStoreApi::TransactionDto
- Defined in:
- lib/new_store_api/models/transaction_dto.rb
Overview
TransactionDto Model.
Instance Attribute Summary collapse
-
#calculation_mode ⇒ CalculationModeEnum
TODO: Write general description for this method.
-
#exemption_class ⇒ ExemptionClassEnum
TODO: Write general description for this method.
-
#exemption_number ⇒ String
The number of the customer's exemption certificate.
-
#items ⇒ Array[Object]
A list of the items sold/returned in the transaction.
-
#order_id ⇒ String
The order ID that will be used as a reference to link the order to the created tax transaction in the tax provider records.
-
#return_id ⇒ String
The return ID that will be used as a reference to link the order to the created tax transaction in the tax provider records.
-
#tax_date ⇒ DateTime
Date of the transaction (in UTC timezone) that'll be used in committing taxes.
-
#tax_exempt ⇒ TrueClass | FalseClass
Defines the tax exemption status of the transaction.
-
#transaction_type ⇒ TransactionTypeEnum
Defines the tax exemption status of the transaction.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
-
.names ⇒ Object
A mapping from model property names to API property names.
-
.nullables ⇒ Object
An array for nullable fields.
-
.optionals ⇒ Object
An array for optional fields.
-
.validate(value) ⇒ Object
Validates an instance of the object from a given value.
Instance Method Summary collapse
-
#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
constructor
A new instance of TransactionDto.
-
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
- #to_custom_tax_date ⇒ Object
-
#to_s ⇒ Object
Provides a human-readable string representation of the object.
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_mode ⇒ CalculationModeEnum
TODO: Write general description for this method
15 16 17 |
# File 'lib/new_store_api/models/transaction_dto.rb', line 15 def calculation_mode @calculation_mode end |
#exemption_class ⇒ ExemptionClassEnum
TODO: Write general description for this method
19 20 21 |
# File 'lib/new_store_api/models/transaction_dto.rb', line 19 def exemption_class @exemption_class end |
#exemption_number ⇒ String
The number of the customer's exemption certificate.
- The given value can be verified by the auditors in the event of a tax audit.
25 26 27 |
# File 'lib/new_store_api/models/transaction_dto.rb', line 25 def exemption_number @exemption_number end |
#items ⇒ Array[Object]
A list of the items sold/returned in the transaction.
- The type
ReverseCalculationTransactionItemDtoshould be used when thecalculation_modeis set toREVERSE. - The type
TransactionItemDtoshould be used When thecalculation_modeis not sent or set toSTANDARD.
33 34 35 |
# File 'lib/new_store_api/models/transaction_dto.rb', line 33 def items @items end |
#order_id ⇒ String
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.
41 42 43 |
# File 'lib/new_store_api/models/transaction_dto.rb', line 41 def order_id @order_id end |
#return_id ⇒ String
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.
48 49 50 |
# File 'lib/new_store_api/models/transaction_dto.rb', line 48 def return_id @return_id end |
#tax_date ⇒ DateTime
Date of the transaction (in UTC timezone) that'll be used in committing taxes.
53 54 55 |
# File 'lib/new_store_api/models/transaction_dto.rb', line 53 def tax_date @tax_date end |
#tax_exempt ⇒ TrueClass | FalseClass
Defines the tax exemption status of the transaction.
57 58 59 |
# File 'lib/new_store_api/models/transaction_dto.rb', line 57 def tax_exempt @tax_exempt end |
#transaction_type ⇒ TransactionTypeEnum
Defines the tax exemption status of the transaction.
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 |
.names ⇒ Object
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 |
.nullables ⇒ Object
An array for nullable fields
92 93 94 |
# File 'lib/new_store_api/models/transaction_dto.rb', line 92 def self.nullables [] end |
.optionals ⇒ Object
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.
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
#inspect ⇒ Object
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_date ⇒ Object
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_s ⇒ Object
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 |