require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') module Savon class Operation def httpi $httpi || HTTPI end def call_with_logging(request) @logger.log(request) { httpi.post(request) } end end end require 'savon/mock/spec_helper' describe HeartlandPortico::ACH do include Savon::SpecHelper before(:all) { savon.mock! } after(:all) { savon.unmock! } let(:client) { HeartlandPortico::ACH.new(config['credentials']) } let(:config) { YAML.load(File.read('./config/spec.yml')) } let(:expected_request) { xml_fixture("check_sale_request_stub") } let(:success_response) { xml_fixture("check_sale_response_success") } let(:auth_error_response) { xml_fixture("response_authentication_error") } describe '#sale' do let(:params) {{ :sec_code => 'PPD', :check_type => 'PERSONAL', :account_type => 'CHECKING', :routing_number => '490000018', :account_number => '24413815', :first_name => "Bob", :last_name => "Smith", :address => "123 Main St", :city => "New York", :state => "NY", :zip => "10120", :phone => "5555551234", :memo => "Heartland Pays", }} let(:amount) { 100 } describe "standard request" do let(:response) { savon.expects(:do_transaction).with(:message => expected_request).returns(success_response) client.sale(amount, params) } it { expect(response.message).to eq("Transaction Approved")} it { expect(response).to be_success } it { expect(response.authorization).to eq("20865555")} end describe "with bad authentication" do let(:response) { savon.expects(:do_transaction).with(:message => expected_request).returns(auth_error_response) client.sale(amount, params) } it { expect(response.message).to eq("ERROR")} it { expect(response).to_not be_success } end end end describe HeartlandPortico::ACH, :remote => true do let(:client) { HeartlandPortico::ACH.new(config['credentials']) } let(:config) { # Copy config/spec.yml to config/cert.yml and replace values # as provided by your certification contact to run remote specs. YAML.load(File.read('./config/cert.yml')) } describe '#sale' do let(:params) {{ :sec_code => 'PPD', :check_type => 'PERSONAL', :account_type => 'CHECKING', :routing_number => '490000018', :account_number => '24413815', :first_name => "Bob", :last_name => "Smith", :address => "123 Main St", :city => "New York", :state => "NY", :zip => "10120", :phone => "5555551234", :memo => "Heartland Pays", }} let(:amount) { "1.00" } let(:response) { client.sale(amount, params) } describe "for great success" do it { expect(response).to be_success } it { expect(response).to be_successful_request } it { expect(response.message).to eq("Transaction Approved") } end end end