# Run with: # CERTIFY=true b ruby -Ilib:test test/remote/gateways/certification_test.rb # ACH_CERTIFY=true b ruby -Ilib:test test/remote/gateways/certification_test.rb require 'test_helper' require 'active_merchant/billing/gateways/heartland_portico' require 'heartland_portico' require 'heartland_portico/ach' class RemoteHeartlandPorticoCertificationTest < Test::Unit::TestCase def options $invoice_base ||= Time.now.strftime("%Y%m%d%H%M-") $invoice_id ||= 0 $invoice_id += 1 { :allow_dup => 'Y', :invoice => $invoice_base+$invoice_id.to_s, :invoice_ship_month => Date.today.month, :invoice_ship_day => Date.today.day, } end def test_certification return unless ENV['CERTIFY'] gateway = HeartlandPorticoGateway.new(fixtures(:heartland_portico)) visa = credit_card('', fixtures(:heartland_portico_visa)) mastercard = credit_card('', fixtures(:heartland_portico_mastercard)) discover = credit_card('', fixtures(:heartland_portico_discover)) amex = credit_card('', fixtures(:heartland_portico_amex)) jcb = credit_card('', fixtures(:heartland_portico_jcb)) zip_only = { :billing_address => { :zip => "75024" }} street_zip = { :billing_address => { :address1 => "6860 Dallas Pkwy", :zip => "75024" }} street_zip9 = { :billing_address => { :address1 => "6860 Dallas Pkwy", :zip => "750241234" }} number_zip = { :billing_address => { :address1 => "6860", :zip => "75024" }} number_zip9 = { :billing_address => { :address1 => "6860", :zip => "750241234" }} # Card Verify (1-4) assert_success gateway.verify(visa, options) assert_success gateway.verify(mastercard, options) assert_success gateway.verify(discover, options.merge(zip_only)) assert_success gateway.verify(amex, options.merge(zip_only)) # Sale (10-14) assert_success r10 = gateway.purchase(1701, visa, options.merge(street_zip)) assert_success gateway.purchase(1702, mastercard, options.merge(number_zip)) assert_success gateway.purchase(1703, discover, options.merge(number_zip9)) assert_success gateway.purchase(1704, amex, options.merge(street_zip)) assert_success gateway.purchase(1705, jcb, options.merge(street_zip9)) # Authorize (15-17) assert_success r15 = gateway.authorize(1706, visa, options.merge(street_zip)) assert_success r16 = gateway.authorize(1707, mastercard, options.merge(street_zip9)) assert_success r17 = gateway.authorize(1708, discover, options.merge(number_zip)) # Capture (15-17) assert_success gateway.capture(1706, r15.authorization) assert_success gateway.capture(1707, r16.authorization) # Do not capture auth 17 # Not Yet Implemented: Level II Corporate Purchase Card (21-32) # Return (34) assert_success gateway.return(1515, mastercard, options) # Void/Reversal (35) assert_success gateway.void(r10.authorization) end def ach_options { :check_action => 'SALE', # OVERRIDE, RETURN :data_entry_mode => 'MANUAL', # SWIPE } end def test_ach_certification return unless ENV['ACH_CERTIFY'] consumer = {:sec_code => 'PPD'} corporate = {:sec_code => 'CCD'} web = {:sec_code => 'WEB'} bank_account = { :routing_number => '490000018', :account_number => '24413815' } checking = {:account_type => 'CHECKING'}.merge(bank_account) savings = {:account_type => 'SAVINGS'}.merge(bank_account) personal = {:check_type => 'PERSONAL'} business = {:check_type => 'BUSINESS'} consumer_account_holder = { :first_name => "Bob", :last_name => "Smith", :address => "123 Main St", :city => "New York", :state => "NY", :zip => "10120", :phone => "5555551234", } corporate_account_holder = { :first_name => "Bob", :last_name => "Smith", :address => "123 Main St", :city => "New York", :state => "NY", :zip => "10120", :phone => "5555551234", :memo => "Heartland Pays", } client = HeartlandPortico::ACH.new(fixtures(:heartland_portico), true) # # ACH Debit - Consumer (1-4) r1 = client.sale(1100, [ach_options, consumer, checking, personal, consumer_account_holder].inject(&:merge)) assert_equal "Transaction Approved", r1.message r2 = client.sale(1200, [ach_options, consumer, checking, business, consumer_account_holder].inject(&:merge)) assert_equal "Transaction Approved", r2.message r3 = client.sale(1300, [ach_options, consumer, savings, personal, consumer_account_holder].inject(&:merge)) assert_equal "Transaction Approved", r3.message r4 = client.sale(1400, [ach_options, consumer, savings, business, consumer_account_holder].inject(&:merge)) assert_equal "Transaction Approved", r4.message # # ACH Debit - Corporate (5-8) r5 = client.sale(1500, [ach_options, corporate, checking, personal, corporate_account_holder].inject(&:merge)) assert_equal "Transaction Approved", r5.message r6 = client.sale(1600, [ach_options, corporate, checking, business, corporate_account_holder].inject(&:merge)) assert_equal "Transaction Approved", r6.message r7 = client.sale(1700, [ach_options, corporate, savings, personal, corporate_account_holder].inject(&:merge)) assert_equal "Transaction Approved", r7.message r8 = client.sale(1800, [ach_options, corporate, savings, business, corporate_account_holder].inject(&:merge)) assert_equal "Transaction Approved", r8.message # Checks-by-web (21-24) r21 = client.sale(1900, [ach_options, web, checking, personal, corporate_account_holder].inject(&:merge)) assert_equal "Transaction Approved", r21.message r22 = client.sale(2000, [ach_options, web, checking, business, corporate_account_holder].inject(&:merge)) assert_equal "Transaction Approved", r22.message r23 = client.sale(2100, [ach_options, web, savings, personal, corporate_account_holder].inject(&:merge)) assert_equal "Transaction Approved", r23.message r24 = client.sale(2200, [ach_options, web, savings, business, corporate_account_holder].inject(&:merge)) assert_equal "Transaction Approved", r24.message # Void (25-29) r25 = client.void(:gateway_txn_id => r1.authorization) assert_equal "Transaction Approved", r25.message r26 = client.void(:gateway_txn_id => r5.authorization) assert_equal "Transaction Approved", r26.message # 27: we do not run test 10 # 28: we do not run test 14 r29 = client.void(:gateway_txn_id => r23.authorization) assert_equal "Transaction Approved", r29.message end end