From e74f5f0a651caeff48076605e220e3600118ae47 Mon Sep 17 00:00:00 2001 From: mark Date: Tue, 15 Jun 2010 19:43:31 +0000 Subject: [PATCH] Cleanup for public release --- Changes | 2 ++ MANIFEST | 2 ++ NMI.pm | 7 +++--- t/01-cc.t | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ t/02-ach.t | 59 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 146 insertions(+), 3 deletions(-) create mode 100644 t/01-cc.t create mode 100644 t/02-ach.t diff --git a/Changes b/Changes index 609d30a..63d34c2 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ Revision history for Business-OnlinePayment-NMI +0.02 Tue Jun 15 12:16:59 PDT 2010 + Clean up for public release, add functional tests. 0.01 Tue May 18 11:53:39 PDT 2010 Initial release diff --git a/MANIFEST b/MANIFEST index a88f430..4aac8c6 100644 --- a/MANIFEST +++ b/MANIFEST @@ -4,3 +4,5 @@ Makefile.PL README NMI.pm t/00-load.t +t/01-cc.t +t/02-ach.t diff --git a/NMI.pm b/NMI.pm index ca4cdb6..a20c959 100644 --- a/NMI.pm +++ b/NMI.pm @@ -9,7 +9,7 @@ use URI::Escape; use vars qw($VERSION @ISA $DEBUG); @ISA = qw(Business::OnlinePayment::HTTPS); -$VERSION = '0.01'; +$VERSION = '0.02'; $DEBUG = 0; @@ -151,12 +151,13 @@ sub map_fields { $content{'payment'} = $types{lc($content{'type'})} or die "Payment method '$content{type}' not supported.\n"; $content{'action'} = $actions{lc($content{'action'})} or die "Transaction type '$content{action}' not supported.\n"; - $content{'expiration'} =~ s/\D//g; + $content{'expiration'} =~ s/\D//g if defined($content{'expiration'}); $content{'account_type'} ||= 'personal checking'; @content{'account_holder_type', 'account_type'} = map {lc} split /\s/, $content{'account_type'}; - $content{'ship_name'} = $content{'ship_first_name'}.' '.$content{'ship_last_name'}; + $content{'ship_name'} = $content{'ship_first_name'} ? + ($content{'ship_first_name'}.' '.$content{'ship_last_name'}) : ''; $self->content(%content); } diff --git a/t/01-cc.t b/t/01-cc.t new file mode 100644 index 0000000..2444480 --- /dev/null +++ b/t/01-cc.t @@ -0,0 +1,79 @@ +use Test::More tests => 6; + +use Business::OnlinePayment; + +my %defaults = ( + name => 'Joe Tester', + address => '888', + city => 'Nowhere', + state => 'CA', + zip => '77777', + phone => '510-555-0021', + email => 'joe@example.com', + description => 'Business::OnlinePayment::NMI Test', + + action => 'Normal Authorization', + card_number => '5431111111111111', + expiration => '10/10', + amount => '12.00', + ); + +# SALE +my %content = %defaults; +my $ordernum = ok_test(\%content, 'credit card sale'); + +# REFUND +%content = ( + action => 'Credit', + order_number => $ordernum, + amount => '6.00', +); +ok_test(\%content, 'credit card refund'); + +# AUTH/CAPTURE +%content = %defaults; +$content{'action'} = 'Authorization Only'; +$ordernum = ok_test(\%content, 'credit card auth'); + +%content = ( + action => 'Post Authorization', + order_number => $ordernum, + amount => '12.00', +); +ok_test(\%content, 'credit card capture'); + +#VOID +%content = ( + action => 'Void', + order_number => $ordernum, +); +ok_test(\%content, 'credit card void'); + +#FAILURE +%content = %defaults; +$content{amount} = '0.10'; # amounts < 1.00 are declined on the demo account +$content{fail} = 1; +ok_test(\%content, 'credit card decline'); + +sub ok_test { + my ($content, $label) = @_; + my $fail = delete $content{fail} or 0; + my $trans = new Business::OnlinePayment('NMI'); + $trans->content( + login => 'demo', + password => 'password', + type => 'CC', + %$content + ); + $trans->submit; + diag($trans->error_message) if (!$fail and $trans->error_message); + if($fail) { + ok(!$trans->is_success, $label) + } + else { + ok($trans->is_success, $label); + } + return $trans->order_number; +} + +1; diff --git a/t/02-ach.t b/t/02-ach.t new file mode 100644 index 0000000..4ff80ff --- /dev/null +++ b/t/02-ach.t @@ -0,0 +1,59 @@ +use Test::More tests => 3; + +use Business::OnlinePayment; + +my %defaults = ( + name => 'Joe Tester', + address => '888', + city => 'Nowhere', + state => 'CA', + zip => '77777', + phone => '510-555-0021', + email => 'joe@example.com', + description => 'Business::OnlinePayment::NMI Test', + + action => 'Normal Authorization', + account_number => '222223333344', # meaningless + routing_code => '411151111', + amount => '13.00', + ); + +# SALE +my %content = %defaults; +my $ordernum = ok_test(\%content, 'echeck sale'); + +#VOID +%content = ( + action => 'Void', + order_number => $ordernum, +); +ok_test(\%content, 'echeck void'); + +#FAILURE +%content = %defaults; +$content{amount} = '0.10'; # amounts < 1.00 are declined on the demo account +$content{fail} = 1; +ok_test(\%content, 'echeck decline'); + +sub ok_test { + my ($content, $label) = @_; + my $fail = delete $content{fail} or 0; + my $trans = new Business::OnlinePayment('NMI'); + $trans->content( + login => 'demo', + password => 'password', + type => 'echeck', + %$content + ); + $trans->submit; + diag($trans->error_message) if (!$fail and $trans->error_message); + if($fail) { + ok(!$trans->is_success, $label) + } + else { + ok($trans->is_success, $label); + } + return $trans->order_number; +} + +1; -- 2.11.0