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;