Skip to content

Commit

Permalink
fixed deprecated calls, added returned items
Browse files Browse the repository at this point in the history
  • Loading branch information
ksondere committed Jun 4, 2014
1 parent 311e133 commit b69a465
Show file tree
Hide file tree
Showing 11 changed files with 341 additions and 141 deletions.
1 change: 1 addition & 0 deletions lib/authorize_net.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
require "authorize_net/reporting/batch_statistics"
require "authorize_net/reporting/transaction_details"
require "authorize_net/reporting/fds_filter"
require "authorize_net/reporting/returned_item"
require "authorize_net/response"
require "authorize_net/key_value_response"
require "authorize_net/xml_response"
Expand Down
12 changes: 12 additions & 0 deletions lib/authorize_net/fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,18 @@ module Fields
],
AuthorizeNet::LineItem
)

attr_accessor :id, :date_utc, :date_local, :code, :description
RETURNED_ITEM_ENTITY_DESCRIPTION = EntityDescription.new([
{:id => :id},
{:dateUTC => :date_utc},
{:dateLocal => :date_local},
{:code => :code},
{:description => :description}
],
AuthorizeNet::Reporting::ReturnedItem
)


TRANSACTION_DETAILS_ENTITY_DESCRIPTION = EntityDescription.new([
{:transId => :id},
Expand Down
17 changes: 17 additions & 0 deletions lib/authorize_net/reporting/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,23 @@ def transaction
transaction.subscription_paynum = value_to_decimal(pay_num) unless pay_num.nil?
end

solution = @transaction.at_css('solution')
unless solution.nil?
solution_id = node_content_unless_nil(@transaction.at_css('solution').at_css('id'))
transaction.solution_id = value_to_decimal(solution_id) unless solution_id.nil?

transaction.solution_name = node_content_unless_nil(@transaction.at_css('solution').at_css('name'))
end

returned_items = @transaction.at_css('returnedItems')
unless returned_items.nil?
transaction.returns ||= AuthorizeNet::Reporting::ReturnedItem.new
returned_items.element_children.each do |child|
returned_item = build_entity(child, Fields::RETURNED_ITEM_ENTITY_DESCRIPTION)
transaction.returns.add_returned_item(returned_item)
end
end

return transaction
end
end
Expand Down
46 changes: 46 additions & 0 deletions lib/authorize_net/reporting/returned_item.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module AuthorizeNet::Reporting

class ReturnedItem
include AuthorizeNet::Model

attr_accessor :id, :date_utc, :date_local, :code, :description, :returned_items

def date_utc=(time)
if time.kind_of?(DateTime)
@date_utc = time
else
@date_utc = DateTime.parse(time.to_s)
end
end

def date_local=(time)
if time.kind_of?(DateTime)
@date_local = time
else
@date_local = DateTime.parse(time.to_s)
end
end

def add_returned_item(id = nil, date_utc = nil, date_local = nil, code = nil, description = nil)
if id.kind_of?(AuthorizeNet::Reporting::ReturnedItem)
returned_item = id
else
returned_item = AuthorizeNet::Reporting::ReturnedItem.new({:return_item_id => id, :return_item_date_utc => date_utc, :return_item_date_utc => date_local, :return_item_code => code, :line_item_description => description})
end
@returned_items = @returned_items.to_a << returned_item
end

def to_hash
hash = {
:id => @id,
:date_utc => @date_utc,
:date_local => @date_local,
:code => @code,
:description => @description,
:returned_items => handle_multivalue_hashing(@returned_items)
}
hash.delete_if { |k, v| v.nil? }
hash
end
end
end
2 changes: 1 addition & 1 deletion lib/authorize_net/reporting/transaction_details.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TransactionDetails
:auth_code, :avs_response, :card_code_response, :cavv_response,
:fds_filter_action, :fds_filters, :batch, :prepaid_balance_remaining,
:payment_method, :recurring_billing, :bill_to, :ship_to, :auth_amount,
:subscription_id, :subscription_paynum
:subscription_id, :subscription_paynum, :solution_id, :solution_name, :returns

def submitted_at=(time)
if time.kind_of?(DateTime)
Expand Down
56 changes: 28 additions & 28 deletions spec/aim_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@

it "should know if its in test mode" do
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => AuthorizeNet::AIM::Transaction::Gateway::TEST, :test => true)
transaction.test?.should be_true
transaction.test?.should be_truthy
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => AuthorizeNet::AIM::Transaction::Gateway::TEST, :test => false)
transaction.test?.should be_true
transaction.test?.should be_truthy
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => AuthorizeNet::AIM::Transaction::Gateway::LIVE, :test => true)
transaction.test?.should be_true
transaction.test?.should be_truthy
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => AuthorizeNet::AIM::Transaction::Gateway::LIVE, :test => false)
transaction.test?.should be_false
transaction.test?.should be_falsey
end

it "should not have a response if the transaciton hasn't been run" do
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => @gateway, :test => @test_mode)
transaction.has_response?.should be_false
transaction.has_response?.should be_falsey
end

it "should support the addition of fields to the transaction body" do
Expand Down Expand Up @@ -89,7 +89,7 @@
response = transaction.purchase(@amount, @credit_card)
response.should be_kind_of(AuthorizeNet::AIM::Response)
response.transaction_id.length.should >= 3
response.success?.should be_true
response.success?.should be_truthy
response.avs_response.should == AuthorizeNet::AIM::Response::AVSResponseCode::ADDRESS_AND_ZIP5_MATCH
response.card_type.should == AuthorizeNet::AIM::Response::CardType::VISA
response.card_type.should_not == AuthorizeNet::AIM::Response::CardType::MASTER_CARD
Expand Down Expand Up @@ -126,7 +126,7 @@
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => @gateway, :test => @test_mode)
transaction.purchase(@amount, @credit_card).should be_kind_of(AuthorizeNet::AIM::Response)
transaction.response.fields[:amount].should == @amount
transaction.response.success?.should be_true
transaction.response.success?.should be_truthy
end

it "should support custom fields in the response" do
Expand Down Expand Up @@ -156,14 +156,14 @@
it "should accept an ECheck for a purchase" do
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => @gateway, :test => @test_mode)
transaction.purchase(@amount, @echeck).should be_kind_of(AuthorizeNet::AIM::Response)
transaction.response.success?.should be_true
transaction.response.success?.should be_truthy
end

it "should support adding line items" do
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => @gateway, :test => @test_mode)
transaction.add_line_item("item1", "Foo", "Bar", "5", "5.00", "TRUE")
transaction.purchase(@amount, @credit_card).should be_kind_of(AuthorizeNet::AIM::Response)
transaction.response.success?.should be_true
transaction.response.success?.should be_truthy
transaction.fields[:line_item].should == ["item1<|>Foo<|>Bar<|>5<|>5.00<|>TRUE"]
end

Expand All @@ -172,108 +172,108 @@
customer = AuthorizeNet::Customer.new(:ip => '127.0.0.1')
transaction.set_customer(customer)
transaction.purchase(@amount, @credit_card).should be_kind_of(AuthorizeNet::AIM::Response)
transaction.response.success?.should be_true
transaction.response.success?.should be_truthy
end

it "should support setting an address" do
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => @gateway, :test => @test_mode)
address = AuthorizeNet::Address.new(:city => 'San Francisco', :state => 'NY')
transaction.set_address(address)
transaction.purchase(@amount, @credit_card).should be_kind_of(AuthorizeNet::AIM::Response)
transaction.response.success?.should be_true
transaction.response.success?.should be_truthy
end

it "should support setting a shipping address" do
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => @gateway, :test => @test_mode)
address = AuthorizeNet::ShippingAddress.new(:city => 'San Francisco', :state => 'NY', :tax => 10.00)
transaction.set_shipping_address(address)
transaction.purchase(@amount, @credit_card).should be_kind_of(AuthorizeNet::AIM::Response)
transaction.response.success?.should be_true
transaction.response.success?.should be_truthy
end

it "should support adding an email receipt" do
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => @gateway, :test => @test_mode)
email = AuthorizeNet::EmailReceipt.new(:header => 'TEST!')
transaction.set_email_receipt(email)
transaction.purchase(@amount, @credit_card).should be_kind_of(AuthorizeNet::AIM::Response)
transaction.response.success?.should be_true
transaction.response.success?.should be_truthy
end

it "should be able to void a purchase" do
purchase = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => @gateway, :test => false)
purchase.purchase(@amount, @credit_card).should be_kind_of(AuthorizeNet::AIM::Response)
purchase.response.fields[:amount].should == @amount
purchase.response.success?.should be_true
purchase.response.success?.should be_truthy
void = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :gateway => @gateway, :test => false)
void.void(purchase.response.transaction_id)
void.response.success?.should be_true
void.response.success?.should be_truthy
end

it "should be able to capture a prior authorization" do
auth = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => @gateway, :test => false)
auth.authorize(@amount, @credit_card).should be_kind_of(AuthorizeNet::AIM::Response)
auth.response.fields[:amount].should == @amount
auth.response.success?.should be_true
auth.response.success?.should be_truthy
capture = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :gateway => @gateway, :test => false)
capture.prior_auth_capture(auth.response.transaction_id)
capture.response.success?.should be_true
capture.response.success?.should be_truthy
end

it "should be able to run a card present purchase with track 1 data" do
@credit_card = AuthorizeNet::CreditCard.new(nil, nil, :track_1 => '%B4111111111111111^DOE/JOHN^1803101000000000020000831000000?')
purchase = AuthorizeNet::AIM::Transaction.new(@cp_api_login, @cp_api_key, :gateway => :card_present_test, :test => false)
response = purchase.purchase(@amount, @credit_card)
response.success?.should be_true
response.success?.should be_truthy
end

it "should be able to run a card present purchase with LRC codes in the track 1 data" do
@credit_card = AuthorizeNet::CreditCard.new(nil, nil, :track_1 => "%B4111111111111111^DOE/JOHN^1803101000000000020000831000000?\xAA")
purchase = AuthorizeNet::AIM::Transaction.new(@cp_api_login, @cp_api_key, :gateway => :card_present_test, :test => false)
response = purchase.purchase(@amount, @credit_card)
response.success?.should be_true
response.success?.should be_truthy
end

it "should be able to run a card present purchase with no LRC or Start/End Sentinels in track 1 data" do
@credit_card = AuthorizeNet::CreditCard.new(nil, nil, :track_1 => "B4111111111111111^DOE/JOHN^1803101000000000020000831000000")
purchase = AuthorizeNet::AIM::Transaction.new(@cp_api_login, @cp_api_key, :gateway => :card_present_test, :test => false)
response = purchase.purchase(@amount, @credit_card)
response.success?.should be_true
response.success?.should be_truthy
end

it "should be able to run a card present purchase with track 2 data" do
@credit_card = AuthorizeNet::CreditCard.new(nil, nil, :track_2 => ';4111111111111111=1803101000020000831?')
purchase = AuthorizeNet::AIM::Transaction.new(@cp_api_login, @cp_api_key, :gateway => :card_present_test, :test => false)
response = purchase.purchase(@amount, @credit_card)
response.success?.should be_true
response.success?.should be_truthy
end

it "should be able to run a card present purchase with LRC codes in the track 2 data" do
@credit_card = AuthorizeNet::CreditCard.new(nil, nil, :track_2 => ";4111111111111111=1803101000020000831?\x33")
purchase = AuthorizeNet::AIM::Transaction.new(@cp_api_login, @cp_api_key, :gateway => :card_present_test, :test => false)
response = purchase.purchase(@amount, @credit_card)
response.success?.should be_true
response.success?.should be_truthy
end

it "should be able to run a card present purchase with no LRC or Start/End Sentinels in track 2 data" do
@credit_card = AuthorizeNet::CreditCard.new(nil, nil, :track_2 => "4111111111111111=1803101000020000831")
purchase = AuthorizeNet::AIM::Transaction.new(@cp_api_login, @cp_api_key, :gateway => :card_present_test, :test => false)
response = purchase.purchase(@amount, @credit_card)
response.success?.should be_true
response.success?.should be_truthy
end

it "should be able to validate the passed MD5 hash" do
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => @gateway, :test => @test_mode)
transaction.purchase(@amount, @credit_card).should be_kind_of(AuthorizeNet::AIM::Response)
transaction.response.success?.should be_true
transaction.response.valid_md5?(@api_login, @md5_value).should be_true
transaction.response.success?.should be_truthy
transaction.response.valid_md5?(@api_login, @md5_value).should be_truthy
end

it "should be able to validate the passed MD5 hash for card present transactions" do
@credit_card = AuthorizeNet::CreditCard.new(nil, nil, :track_1 => '%B4111111111111111^DOE/JOHN^1803101000000000020000831000000?')
purchase = AuthorizeNet::AIM::Transaction.new(@cp_api_login, @cp_api_key, :gateway => :card_present_test, :test => false)
response = purchase.purchase(@amount, @credit_card)
response.success?.should be_true
response.valid_md5?(@cp_api_login, @cp_md5_value).should be_true
response.success?.should be_truthy
response.valid_md5?(@cp_api_login, @cp_md5_value).should be_truthy
end
end

Expand Down Expand Up @@ -304,7 +304,7 @@
@element.should be_kind_of(Nokogiri::XML::Element)
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :test => false)
response = AuthorizeNet::AIM::Response.new(@element, transaction)
response.success?.should be_true
response.success?.should be_truthy
response.response_reason_text.should == 'This transaction has been approved.'
end
end
22 changes: 11 additions & 11 deletions spec/arb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

it "should not have a response if the transaction hasn't been run" do
transaction = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, :gateway => @gateway)
transaction.has_response?.should be_false
transaction.has_response?.should be_falsey
end

it "should support the returning its response object" do
Expand All @@ -49,11 +49,11 @@

it "should know if its running against the sandbox or not" do
transaction = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
transaction.test?.should be_true
transaction.test?.should be_truthy
transaction = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, :gateway => :live)
transaction.test?.should be_false
transaction.test?.should be_falsey
transaction = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, :gateway => 'moose')
transaction.test?.should be_true
transaction.test?.should be_truthy
end

it "should have a response after running a transaction" do
Expand All @@ -65,36 +65,36 @@
it "should support creating a subscription" do
transaction = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
response = transaction.create(@subscription)
response.success?.should be_true
response.success?.should be_truthy
end

it "should support canceling a subscription" do
transaction = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
response = transaction.create(@subscription)
response.success?.should be_true
response.success?.should be_truthy
cancel = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
response = cancel.cancel(response.subscription_id)
response.success?.should be_true
response.success?.should be_truthy
end

it "should support getting the status of a subscription" do
create = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
response = create.create(@subscription)
response.success?.should be_true
response.success?.should be_truthy
status = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
response = status.get_status(response.subscription_id)
response.success?.should be_true
response.success?.should be_truthy
response.subscription_status.should == AuthorizeNet::ARB::Subscription::Status::ACTIVE
end

it "should support updating a subscription" do
create = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
response = create.create(@subscription)
response.success?.should be_true
response.success?.should be_truthy
update = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
subscription = AuthorizeNet::ARB::Subscription.new(:subscription_id => response.subscription_id, :billing_address => AuthorizeNet::Address.new(:first_name => 'Jane', :last_name => 'Doe'))
response = update.update(subscription)
response.success?.should be_true
response.success?.should be_truthy
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/authorize_net_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
describe AuthorizeNet do

it "should have a module called AuthorizeNet" do
defined?(AuthorizeNet).should be_true
defined?(AuthorizeNet).should be_truthy
AuthorizeNet.class.should equal(Module)
end

it "should have a module called AIM" do
defined?(AuthorizeNet::AIM).should be_true
defined?(AuthorizeNet::AIM).should be_truthy
AuthorizeNet::AIM.class.should equal(Module)
end

Expand Down
Loading

0 comments on commit b69a465

Please sign in to comment.