|
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_amount, :tax_name, :tax_description, :freight, :freight_name, :freight_description, :duty, :duty_amount, :duty_name, :duty_description, :tax_exempt, :po_num, :line_items |
|
9
|
|
|
attr_accessor :shipping_amount, :shipping_name, :shipping_description |
|
10
|
|
|
|
|
11
|
|
|
def add_line_item(id = nil, name = nil, description = nil, quantity = nil, price = nil, taxable = nil) |
|
12
|
|
|
if id.kind_of?(AuthorizeNet::LineItem) |
|
13
|
|
|
line_item = id |
|
14
|
|
|
else |
|
15
|
|
|
line_item = AuthorizeNet::LineItem.new({:id => id, :name => name, :description => description, :quantity => quantity, :price => price, :taxable => taxable}) |
|
16
|
|
|
end |
|
17
|
|
|
@line_items = @line_items.to_a << line_item |
|
18
|
|
|
end |
|
19
|
|
|
|
|
20
|
|
|
def to_hash |
|
21
|
|
|
hash = { |
|
22
|
|
|
:invoice_num => @invoice_num, |
|
23
|
|
|
:description => @description, |
|
24
|
|
|
:tax => @tax, |
|
25
|
|
|
:tax_amount => @tax_amount, |
|
26
|
|
|
:tax_name => @tax_name, |
|
27
|
|
|
:tax_description => @tax_description, |
|
28
|
|
|
:freight => @freight, |
|
29
|
|
|
:freight_name => @freight_name, |
|
30
|
|
|
:freight_description => @freight_description, |
|
31
|
|
|
:duty => @duty, |
|
32
|
|
|
:duty_amount => @duty_amount, |
|
33
|
|
|
:duty_name => @duty_name, |
|
34
|
|
|
:duty_description => @duty_description, |
|
35
|
|
|
:shipping_amount => @shipping_amount, |
|
36
|
|
|
:shipping_name => @shipping_name, |
|
37
|
|
|
:shipping_description => @shipping_description, |
|
38
|
|
|
:tax_exempt => @tax_exempt, |
|
39
|
|
|
:po_num => @po_num, |
|
40
|
|
|
:line_items => handle_multivalue_hashing(@line_items) |
|
41
|
|
|
} |
|
42
|
|
|
hash.delete_if {|k, v| v.nil?} |
|
43
|
|
|
hash |
|
44
|
|
|
end |
|
45
|
|
|
|
|
46
|
|
|
end |
|
47
|
|
|
|
|
48
|
|
|
end |
|
49
|
|
|
|