Class: NewStoreApi::TaxTotalsDto

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

Overview

TaxTotalsDto 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(discount_total = nil, grand_total = nil, net_total = nil, shipping_tax_amount = nil, shipping_total = nil, subtotal = nil, tax_rates_summary = nil, tax_strategy = nil, tax_total = nil) ⇒ TaxTotalsDto

Returns a new instance of TaxTotalsDto.



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

def initialize(discount_total = nil, grand_total = nil, net_total = nil,
               shipping_tax_amount = nil, shipping_total = nil,
               subtotal = nil, tax_rates_summary = nil, tax_strategy = nil,
               tax_total = nil)
  @discount_total = discount_total
  @grand_total = grand_total
  @net_total = net_total
  @shipping_tax_amount = shipping_tax_amount
  @shipping_total = shipping_total
  @subtotal = subtotal
  @tax_rates_summary = tax_rates_summary
  @tax_strategy = tax_strategy
  @tax_total = tax_total
end

Instance Attribute Details

#discount_totalFloat

The total discount amount.

Returns:

  • (Float)


14
15
16
# File 'lib/new_store_api/models/tax_totals_dto.rb', line 14

def discount_total
  @discount_total
end

#grand_totalFloat

The amount consumer has to pay for the order.

Returns:

  • (Float)


18
19
20
# File 'lib/new_store_api/models/tax_totals_dto.rb', line 18

def grand_total
  @grand_total
end

#net_totalFloat

The sum of net prices of all the items including shipping and gift wrapping

Returns:

  • (Float)


23
24
25
# File 'lib/new_store_api/models/tax_totals_dto.rb', line 23

def net_total
  @net_total
end

#shipping_tax_amountFloat

The shipping tax amount.

Returns:

  • (Float)


27
28
29
# File 'lib/new_store_api/models/tax_totals_dto.rb', line 27

def shipping_tax_amount
  @shipping_tax_amount
end

#shipping_totalFloat

The total shipping amount.

Returns:

  • (Float)


31
32
33
# File 'lib/new_store_api/models/tax_totals_dto.rb', line 31

def shipping_total
  @shipping_total
end

#subtotalFloat

The sum of item prices incl. or excl. tax (depending on tax method).

Returns:

  • (Float)


35
36
37
# File 'lib/new_store_api/models/tax_totals_dto.rb', line 35

def subtotal
  @subtotal
end

#tax_rates_summaryArray[TaxRateDto]

Summary of the tax rates applied on the line items of the transaction grouped by the tax name and tax rate.

Returns:



40
41
42
# File 'lib/new_store_api/models/tax_totals_dto.rb', line 40

def tax_rates_summary
  @tax_rates_summary
end

#tax_strategyTaxCalculationStrategyEnum

Summary of the tax rates applied on the line items of the transaction grouped by the tax name and tax rate.



45
46
47
# File 'lib/new_store_api/models/tax_totals_dto.rb', line 45

def tax_strategy
  @tax_strategy
end

#tax_totalFloat

The total tax sum (grand total tax incl. shipping tax).

Returns:

  • (Float)


49
50
51
# File 'lib/new_store_api/models/tax_totals_dto.rb', line 49

def tax_total
  @tax_total
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/new_store_api/models/tax_totals_dto.rb', line 92

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  discount_total =
    hash.key?('discount_total') ? hash['discount_total'] : nil
  grand_total = hash.key?('grand_total') ? hash['grand_total'] : nil
  net_total = hash.key?('net_total') ? hash['net_total'] : nil
  shipping_tax_amount =
    hash.key?('shipping_tax_amount') ? hash['shipping_tax_amount'] : nil
  shipping_total =
    hash.key?('shipping_total') ? hash['shipping_total'] : nil
  subtotal = hash.key?('subtotal') ? hash['subtotal'] : nil
  # Parameter is an array, so we need to iterate through it
  tax_rates_summary = nil
  unless hash['tax_rates_summary'].nil?
    tax_rates_summary = []
    hash['tax_rates_summary'].each do |structure|
      tax_rates_summary << (TaxRateDto.from_hash(structure) if structure)
    end
  end

  tax_rates_summary = nil unless hash.key?('tax_rates_summary')
  tax_strategy = hash.key?('tax_strategy') ? hash['tax_strategy'] : nil
  tax_total = hash.key?('tax_total') ? hash['tax_total'] : nil

  # Create object from extracted values.
  TaxTotalsDto.new(discount_total,
                   grand_total,
                   net_total,
                   shipping_tax_amount,
                   shipping_total,
                   subtotal,
                   tax_rates_summary,
                   tax_strategy,
                   tax_total)
end

.namesObject

A mapping from model property names to API property names.



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/new_store_api/models/tax_totals_dto.rb', line 52

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['discount_total'] = 'discount_total'
  @_hash['grand_total'] = 'grand_total'
  @_hash['net_total'] = 'net_total'
  @_hash['shipping_tax_amount'] = 'shipping_tax_amount'
  @_hash['shipping_total'] = 'shipping_total'
  @_hash['subtotal'] = 'subtotal'
  @_hash['tax_rates_summary'] = 'tax_rates_summary'
  @_hash['tax_strategy'] = 'tax_strategy'
  @_hash['tax_total'] = 'tax_total'
  @_hash
end

.nullablesObject

An array for nullable fields



72
73
74
# File 'lib/new_store_api/models/tax_totals_dto.rb', line 72

def self.nullables
  []
end

.optionalsObject

An array for optional fields



67
68
69
# File 'lib/new_store_api/models/tax_totals_dto.rb', line 67

def self.optionals
  []
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



140
141
142
143
144
145
146
147
# File 'lib/new_store_api/models/tax_totals_dto.rb', line 140

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} discount_total: #{@discount_total.inspect}, grand_total:"\
  " #{@grand_total.inspect}, net_total: #{@net_total.inspect}, shipping_tax_amount:"\
  " #{@shipping_tax_amount.inspect}, shipping_total: #{@shipping_total.inspect}, subtotal:"\
  " #{@subtotal.inspect}, tax_rates_summary: #{@tax_rates_summary.inspect}, tax_strategy:"\
  " #{@tax_strategy.inspect}, tax_total: #{@tax_total.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



131
132
133
134
135
136
137
# File 'lib/new_store_api/models/tax_totals_dto.rb', line 131

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} discount_total: #{@discount_total}, grand_total: #{@grand_total},"\
  " net_total: #{@net_total}, shipping_tax_amount: #{@shipping_tax_amount}, shipping_total:"\
  " #{@shipping_total}, subtotal: #{@subtotal}, tax_rates_summary: #{@tax_rates_summary},"\
  " tax_strategy: #{@tax_strategy}, tax_total: #{@tax_total}>"
end