Skip Menu |

This queue is for tickets about the Business-OnlinePayment-AuthorizeNet CPAN distribution.

Report information
The Basics
Id: 22076
Status: resolved
Priority: 0/
Queue: Business-OnlinePayment-AuthorizeNet

People
Owner: ivan-pause [...] 420.am
Requestors: mschwern [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 3.15
Fixed in: (no value)



Subject: Have tests ask for an account to use.
The attached patch makes it so the Makefile.PL asks the user for an authorize.net login and password to use for testing. It also updates the tests to use Test::More. Also... * Made the check test work by putting in a real routing code and the additional fields required for a check. Often an authorize.net account won't be allowed to handle checks (error code 18) so the test will skip if that happens. capture.t is failing. I don't know why yet but I don't think I broke it. t/capture........NOK 4/4 # Failed test in t/capture.t at line 55. # (TESTMODE) The transaction cannot be found. # Looks like you failed 1 test of 4.
Subject: bop_an_tests.patch
=== Makefile.PL ================================================================== --- Makefile.PL (revision 19628) +++ Makefile.PL (local) @@ -1,15 +1,47 @@ use ExtUtils::MakeMaker; -# See lib/ExtUtils/MakeMaker.pm for details of how to influence -# the contents of the Makefile that is written. + +ask_for_test_account(); + WriteMakefile( 'NAME' => 'Business::OnlinePayment::AuthorizeNet', 'VERSION_FROM' => 'AuthorizeNet.pm', # finds $VERSION 'AUTHOR' => 'Ivan Kohler <ivan-authorizenet@420.am>', #really just #the maintainer - #'NORECURS' => 1, # dont descend into subdirectories 'PREREQ_PM' => { 'Net::SSLeay' => 0, 'Text::CSV_XS' => 0, 'Business::OnlinePayment' => 0, + 'Test::More' => 0.42, }, - #'dist' => {CI => 'ci -l'}, ); + + +sub ask_for_test_account { + print <<END_OF_MESSAGE; +This test requires a valid Authorize.net test account to contact Authorize.net +and test itself against their servers. If you don't have one the test will +be skipped. Test accounts can be obtained via http://developer.authorize.net. + +END_OF_MESSAGE + + my $have_account = + prompt("Do you have an authorize.net test account?", "No"); + + if( is_yes($have_account) ) { + my $login = prompt("Login?"); + my $password = prompt("Password?"); + + open TEST_ACCOUNT, "> t/test_account" or die $!; + print TEST_ACCOUNT "$login\n"; + print TEST_ACCOUNT "$password\n"; + close TEST_ACCOUNT + } + else { + 1 while unlink "t/test_account"; + } +} + + +sub is_yes { + my $answer = shift; + return $answer =~ /^y(es)?$/i ? 1 : 0; +} === t/bop.t ================================================================== --- t/bop.t (revision 19628) +++ t/bop.t (local) @@ -1,5 +1,5 @@ -BEGIN { $| = 1; print "1..1\n"; } -END {print "not ok 1\n" unless $loaded;} -use Business::OnlinePayment; -$loaded = 1; -print "ok 1\n"; +#!/usr/bin/perl -w + +use Test::More tests => 1; + +use_ok 'Business::OnlinePayment'; === t/capture.t ================================================================== --- t/capture.t (revision 19628) +++ t/capture.t (local) @@ -1,17 +1,18 @@ -BEGIN { $| = 1; print "1..2\n"; } +#!/usr/bin/perl -w -#testing/testing is valid and seems to work... (but not for auth + capture) -print "ok 1 # Skipped: need a valid Authorize.Net login/password to test\n"; -print "ok 2 # Skipped: need a valid Authorize.Net login/password to test\n"; -exit; +use Test::More; +require "t/lib/test_account.pl"; -use Business::OnlinePayment; +my($login, $password) = test_account_or_skip(); +plan tests => 4; -my $tx = new Business::OnlinePayment("AuthorizeNet"); +use_ok 'Business::OnlinePayment'; + +my $tx = Business::OnlinePayment->new("AuthorizeNet"); $tx->content( type => 'VISA', - login => 'testing',# CHANGE THESE TO TEST - password => 'testing',# + login => $login, + password => $password, action => 'Authorization Only', description => 'Business::OnlinePayment visa test', amount => '49.95', @@ -24,41 +25,31 @@ state => 'UT', zip => '84058', card_number => '4007000000027', - expiration => '08/06', + expiration => expiration_date(), ); $tx->test_transaction(1); # test, dont really charge $tx->submit(); -unless($tx->is_success()) { - print "not ok 1\n"; - print "not ok 2\n"; -} else { - my $order_number = $tx->order_number; - warn $order_number; - print "ok 1\n"; +ok($tx->is_success()) or diag $tx->error_message; - my $settle_tx = new Business::OnlinePayment("AuthorizeNet"); - $settle_tx->content( - type => 'VISA', - login => 'testing', # CHANGE THESE TO TEST - password => 'testing', # - action => 'Post Authorization', - description => 'Business::OnlinePayment visa test', - amount => '49.95', - invoice_number => '100100', - order_number => '111', - card_number => '4007000000027', - expiration => '08/06', - ); +my $order_number = $tx->order_number; +like $order_number, qr/^\d+$/; - $settle_tx->test_transaction(1); # test, dont really charge - $settle_tx->submit(); +my $settle_tx = Business::OnlinePayment->new("AuthorizeNet"); +$settle_tx->content( + type => 'VISA', + login => $login, + password => $password, + action => 'Post Authorization', + description => 'Business::OnlinePayment visa test', + amount => '49.95', + invoice_number => '100100', + order_number => '111', + card_number => '4007000000027', + expiration => expiration_date(), +); - if($settle_tx->is_success()) { - print "ok 2\n"; - } else { - warn $settle_tx->error_message; - print "not ok 2\n"; - } +$settle_tx->test_transaction(1); # test, dont really charge +$settle_tx->submit(); -} +ok($settle_tx->is_success()) || diag $settle_tx->error_message; === t/check.t ================================================================== --- t/check.t (revision 19628) +++ t/check.t (local) @@ -1,32 +1,38 @@ -BEGIN { $| = 1; print "1..1\n"; } +#!/usr/bin/perl -w -print "ok 1 # Skipped: testing account won't accept ACH transactions\n"; exit; +use Test::More; +require "t/lib/test_account.pl"; -use Business::OnlinePayment; +my($login, $password) = test_account_or_skip(); +plan tests => 2; -# checks are broken it seems -my $ctx = new Business::OnlinePayment("AuthorizeNet"); +use_ok 'Business::OnlinePayment'; + +my $ctx = Business::OnlinePayment->new("AuthorizeNet"); $ctx->content( type => 'CHECK', - login => 'testing', - password => 'testing', + login => $login, + password => $password, action => 'Normal Authorization', amount => '49.95', invoice_number => '100100', customer_id => 'jsk', first_name => 'Tofu', last_name => 'Beast', + account_name => 'Tofu Beast', account_number => '12345', - routing_code => '123456789', + routing_code => '111000025', # BoA in Texas taken from Wikipedia bank_name => 'First National Test Bank', + account_type => 'Checking', + license_num => '12345678', + license_state => 'OR', + license_dob => '1975-05-21', ); $ctx->test_transaction(1); # test, dont really charge $ctx->submit(); -print $ctx->is_success()."\n"; +SKIP: { + skip $ctx->error_message, 1 if $ctx->result_code == 18; -if($ctx->is_success()) { - print "ok 1\n"; -} else { - print "not ok 1 (".$ctx->error_message().")\n"; + ok( $ctx->is_success() ) || diag $ctx->error_message; } === t/credit_card.t ================================================================== --- t/credit_card.t (revision 19628) +++ t/credit_card.t (local) @@ -1,15 +1,19 @@ -BEGIN { $| = 1; print "1..1\n"; } +#!/usr/bin/perl -w -#testing/testing is valid and seems to work... -#print "ok 1 # Skipped: need a valid Authorize.Net login/password to test\n"; exit; +use Test::More; +require "t/lib/test_account.pl"; -use Business::OnlinePayment; +my($login, $password) = test_account_or_skip(); +plan tests => 2; -my $tx = new Business::OnlinePayment("AuthorizeNet"); +use_ok 'Business::OnlinePayment'; + + +my $tx = Business::OnlinePayment->new("AuthorizeNet"); $tx->content( type => 'VISA', - login => 'testing', - password => 'testing', + login => $login, + password => $password, action => 'Normal Authorization', description => 'Business::OnlinePayment visa test', amount => '49.95', @@ -22,14 +26,9 @@ state => 'UT', zip => '84058', card_number => '4007000000027', - expiration => '08/06', + expiration => expiration_date(), ); $tx->test_transaction(1); # test, dont really charge $tx->submit(); -if($tx->is_success()) { - print "ok 1\n"; -} else { - #warn $tx->error_message; - print "not ok 1\n"; -} +ok($tx->is_success()) or diag $tx->error_message; === t/load.t ================================================================== --- t/load.t (revision 19628) +++ t/load.t (local) @@ -1,5 +1,5 @@ -BEGIN { $| = 1; print "1..1\n"; } -END {print "not ok 1\n" unless $loaded;} -use Business::OnlinePayment::AuthorizeNet; -$loaded = 1; -print "ok 1\n"; +#!/usr/bin/perl -w + +use Test::More tests => 1; + +use_ok 'Business::OnlinePayment::AuthorizeNet'; === t/lib (new directory) ================================================================== === t/lib/test_account.pl ================================================================== --- t/lib/test_account.pl (revision 19628) +++ t/lib/test_account.pl (local) @@ -0,0 +1,28 @@ +sub test_account_or_skip { + my($login, $password) = test_account(); + + unless( defined $login ) { + plan skip_all => "No test account"; + } + + return($login, $password); +} + +sub test_account { + open TEST_ACCOUNT, "t/test_account" or return; + my($login, $password) = <TEST_ACCOUNT>; + chomp $login; + chomp $password; + + return($login, $password); +} + +sub expiration_date { + my($month, $year) = (localtime)[4,5]; + $year++; # So we expire next year. + $year %= 100; # y2k? What's that? + + return sprintf("%02d/%02d", $month, $year); +} + +1;
I just got a reply from the authorize.net folks and they said its ok to simply get a test account from them and hard code that into the BOP::AN tests. Thus eliminating the need to ask the user. http://developer.authorize.net/testaccount/ If you like I can get that account for you. Michael, We can set up another test account for your application, just fill out the test account form again: http://test.authorize.net/gateway/transact.dll One thing to note is that the URL's for test and production are separate, so if the application uses the test server to test, you're switch to live mode will have to include changing the URL and prompting the user for their production account details. Regards Corey
On Fri Oct 13 15:54:22 2006, MSCHWERN wrote: Show quoted text
> I just got a reply from the authorize.net folks and they said its ok
to Show quoted text
> simply get a test account from them and hard code that into the
BOP::AN Show quoted text
> tests. Thus eliminating the need to ask the user.
That sounds better than prompting the user. Show quoted text
> http://developer.authorize.net/testaccount/ > > If you like I can get that account for you.
I've filled out the Authorize.net form and requested one, hopefully that should work. -- _ivan
Applied this patch (except for the part that asks for a test account) and added t/test_account containing a test account issued from Authorize.Net. will be in 3.16. credit_card.t, check.t and capture.t are now giving: (TESTMODE) This account has not been given the permission(s) required for this request. Guessing this will probably be resolved when Authorize.net flips the magic enable switch for the new test account; I have emailed developer@Authorize.net On Fri Oct 13 05:32:35 2006, MSCHWERN wrote: Show quoted text
> The attached patch makes it so the Makefile.PL asks the user for an > authorize.net login and password to use for testing. It also
updates Show quoted text
> the tests to use Test::More. > > Also... > * Made the check test work by putting in a real routing code and the > additional fields required for a check. Often an authorize.net
account Show quoted text
> won't be allowed to handle checks (error code 18) so the test will
skip Show quoted text
> if that happens. > > capture.t is failing. I don't know why yet but I don't think I
broke it. Show quoted text
> > t/capture........NOK 4/4 > > # Failed test in t/capture.t at line 55. > # (TESTMODE) The transaction cannot be found. > # Looks like you failed 1 test of 4.
got working card and ACH test accounts from authorize.net to replace testing/test; all tests now pass again. time for a 3.16 release? snapshot at http://www.sisd.com/cgi-bin/viewcvs.cgi/Business-OnlinePayment-AuthorizeNet.tar.gz?view=tar
Subject: Re: [rt.cpan.org #22076] get and hardcode a new testing account from authorize.net
Date: Sun, 22 Oct 2006 12:55:41 -0700
To: bug-Business-OnlinePayment-AuthorizeNet [...] rt.cpan.org
From: Michael G Schwern <schwern [...] gmail.com>
via RT wrote: Show quoted text
> <URL: http://rt.cpan.org/Ticket/Display.html?id=22076 > > > got working card and ACH test accounts from authorize.net to replace > testing/test; all tests now pass again. > > time for a 3.16 release? > > snapshot at > http://www.sisd.com/cgi-bin/viewcvs.cgi/Business-OnlinePayment-AuthorizeNet.tar.gz?view=tar
0 Windhund-V /usr/local/src/CPAN/Business-OnlinePayment-AuthorizeNet$ make test PERL_DL_NONLAZY=1 /usr/local/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t t/bop............ok t/capture........ok 2/4Subroutine require_avs redefined at (eval 26) line 1, <TEST_ACCOUNT> line 2. Subroutine path redefined at (eval 27) line 1, <TEST_ACCOUNT> line 2. Subroutine port redefined at (eval 28) line 1, <TEST_ACCOUNT> line 2. Subroutine authorization redefined at (eval 29) line 1, <TEST_ACCOUNT> line 2. Subroutine is_success redefined at (eval 30) line 1, <TEST_ACCOUNT> line 2. Subroutine result_code redefined at (eval 31) line 1, <TEST_ACCOUNT> line 2. Subroutine error_message redefined at (eval 32) line 1, <TEST_ACCOUNT> line 2. Subroutine server_response redefined at (eval 33) line 1, <TEST_ACCOUNT> line 2. Subroutine server redefined at (eval 34) line 1, <TEST_ACCOUNT> line 2. Subroutine transaction_type redefined at (eval 35) line 1, <TEST_ACCOUNT> line 2. Subroutine test_transaction redefined at (eval 36) line 1, <TEST_ACCOUNT> line 2. Subroutine order_number redefined at (eval 37) line 1, <TEST_ACCOUNT> line 2. Subroutine md5 redefined at (eval 38) line 1, <TEST_ACCOUNT> line 2. Subroutine avs_code redefined at (eval 39) line 1, <TEST_ACCOUNT> line 2. Subroutine cvv2_response redefined at (eval 40) line 1, <TEST_ACCOUNT> line 2. Subroutine cavv_response redefined at (eval 41) line 1, <TEST_ACCOUNT> line 2. t/capture........ok t/check..........ok t/credit_card....ok t/load...........ok All tests successful. Files=5, Tests=10, 8 wallclock secs ( 0.27 cusr + 0.10 csys = 0.37 CPU) This is against BOP 2.01. I guess this is the build_subs() redef problem so it would be nice if 3.00 got out, but don't hold up 3.16 for it. Otherwise looks good.
fixed in 3.16 (doesn't seem to be showing up in the custom fields...)