Skip to content

Commit

Permalink
adds missing attr_accessors to AuthorizeNet::Order class
Browse files Browse the repository at this point in the history
  • Loading branch information
chas-mcmahon committed Oct 27, 2017
1 parent b6ab908 commit 520e50b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
24 changes: 15 additions & 9 deletions lib/authorize_net/order.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
module AuthorizeNet

# Models an order.
class Order

include AuthorizeNet::Model

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


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
attr_accessor :shipping_amount, :shipping_name, :shipping_description

def add_line_item(id = nil, name = nil, description = nil, quantity = nil, price = nil, taxable = nil)
if id.kind_of?(AuthorizeNet::LineItem)
line_item = id
Expand All @@ -15,28 +16,33 @@ def add_line_item(id = nil, name = nil, description = nil, quantity = nil, price
end
@line_items = @line_items.to_a << line_item
end

def to_hash
hash = {
:invoice_num => @invoice_num,
:description => @description,
:tax => @tax,
:tax_amount => @tax_amount,
:tax_name => @tax_name,
:tax_description => @tax_description,
:freight => @freight,
:freight_name => @freight_name,
:freight_description => @freight_description,
:duty => @duty,
:duty_amount => @duty_amount,
:duty_name => @duty_name,
:duty_description => @duty_description,
:shipping_amount => @shipping_amount,
:shipping_name => @shipping_name,
:shipping_description => @shipping_description,
:tax_exempt => @tax_exempt,
:po_num => @po_num,
:line_items => handle_multivalue_hashing(@line_items)
}
hash.delete_if {|k, v| v.nil?}
hash
end

end
end

end
27 changes: 27 additions & 0 deletions spec/reporting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,21 @@
</order>
<authAmount>10.00</authAmount>
<settleAmount>10.00</settleAmount>
<tax>
<amount>0.00</amount>
<name>tax name</name>
<description>tax description</description>
</tax>
<shipping>
<amount>0.00</amount>
<name>shipping name</name>
<description>shipping description</description>
</shipping>
<duty>
<amount>0.00</amount>
<name>duty name</name>
<description>duty description</description>
</duty>
<lineItems>
<lineItem>
<itemId>ITEM00001</itemId>
Expand Down Expand Up @@ -438,6 +453,18 @@
transaction.order.line_items[0].should be_kind_of(AuthorizeNet::LineItem)
transaction.order.tax_exempt.should be_falsey

transaction.order.tax_amount.should == 0.00
transaction.order.tax_name.should == 'tax name'
transaction.order.tax_description.should == 'tax description'

transaction.order.duty_amount.should == 0.00
transaction.order.duty_name.should == 'duty name'
transaction.order.duty_description.should == 'duty description'

transaction.order.shipping_amount.should == 0.00
transaction.order.shipping_name.should == 'shipping name'
transaction.order.shipping_description.should == 'shipping description'

transaction.payment_method.should be_kind_of(AuthorizeNet::CreditCard)
transaction.payment_method.card_number.should == 'XXXX1111'

Expand Down

0 comments on commit 520e50b

Please sign in to comment.