Completed
Push — master ( d1113e...330dad )
by
unknown
10s
created

Order   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 37
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A add_line_item() 0 8 2
A to_hash() 0 20 1
1
module AuthorizeNet
2
  
3
  # Models an order.
4
  class Order
5
    
6
    include AuthorizeNet::Model
7
    
8
    attr_accessor :invoice_num, :description, :tax, :tax_name, :tax_description, :freight, :freight_name, :freight_description, :duty, :duty_name, :duty_description, :tax_exempt, :po_num, :line_items
9
    
10
    def add_line_item(id = nil, name = nil, description = nil, quantity = nil, price = nil, taxable = nil)
11
      if id.kind_of?(AuthorizeNet::LineItem)
12
        line_item = id
13
      else
14
        line_item = AuthorizeNet::LineItem.new({:id => id, :name => name, :description => description, :quantity => quantity, :price => price, :taxable => taxable})
15
      end
16
      @line_items = @line_items.to_a << line_item
17
    end
18
    
19
    def to_hash
20
      hash = {
21
        :invoice_num => @invoice_num,
22
        :description => @description,
23
        :tax => @tax,
24
        :tax_name => @tax_name,
25
        :tax_description => @tax_description,
26
        :freight => @freight,
27
        :freight_name => @freight_name,
28
        :freight_description => @freight_description,
29
        :duty => @duty,
30
        :duty_name => @duty_name,
31
        :duty_description => @duty_description,
32
        :tax_exempt => @tax_exempt,
33
        :po_num => @po_num,
34
        :line_items => handle_multivalue_hashing(@line_items)
35
      }
36
      hash.delete_if {|k, v| v.nil?}
37
      hash
38
    end
39
    
40
  end
41
  
42
end