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
README
NMI.pm
t/00-load.t
+t/01-cc.t
+t/02-ach.t
use vars qw($VERSION @ISA $DEBUG);
@ISA = qw(Business::OnlinePayment::HTTPS);
-$VERSION = '0.01';
+$VERSION = '0.02';
$DEBUG = 0;
$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);
}
--- /dev/null
+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;
--- /dev/null
+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;