From 0aaa3a6a62a90d74f9fa23103e568888c905f7eb Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 20 Dec 2010 02:35:20 +0000 Subject: [PATCH] - Incorporate Business::OnlinePayment::AuthorizeNet::AIM::ErrorCodes by Thomas Sibley and, using it, provide more descriptive error messages. - Switch to Business::OnlinePayment::HTTPS instead of using Net::SSLeay directly --- AuthorizeNet.pm | 19 +++++++++++++++++++ AuthorizeNet/AIM.pm | 34 ++++++++++++++++------------------ Changes | 4 ++++ Makefile.PL | 4 ++-- t/card_arb.t | 2 +- t/errorcodes.t | 36 ++++++++++++++++++++++++++++++++++++ 6 files changed, 78 insertions(+), 21 deletions(-) create mode 100644 t/errorcodes.t diff --git a/AuthorizeNet.pm b/AuthorizeNet.pm index a73a84e..b00547d 100644 --- a/AuthorizeNet.pm +++ b/AuthorizeNet.pm @@ -443,6 +443,9 @@ fields: tax, freight, duty, tax_exempt, po_number. Michael Peters fixed a bug in email address handling. +Thomas Sibley wrote B:OP:AuthorizeNet::AIM::ErrorCodes +which was borged and used to provide more descriptive error messages. + =head1 CONTRIBUTIONS AND REPOSITORY Please send patches as unified diffs (diff -u) to (in order of preference): @@ -474,6 +477,22 @@ Or on the web: http://freeside.biz/cgi-bin/viewvc.cgi/Business-OnlinePayment-AuthorizeNet/ +=head1 A WORD FROM OUR SPONSOR + +This module and the Business::OnlinePayment framework are maintained by by +Freeside Internet Services. If you need a complete, open-source web-based +application to manage your customers, billing and trouble ticketing, please +visit http://freeside.biz/ + +=head1 COPYRIGHT & LICENSE + +Copyright 2010 Freeside Internet Services, Inc. +Copyright 2008 Thomas Sibley +All rights reserved. + +This program is free software; you can redistribute it and/or modify it +under the same terms as Perl itself. + =head1 SEE ALSO perl(1). L. diff --git a/AuthorizeNet/AIM.pm b/AuthorizeNet/AIM.pm index 2906079..0039502 100644 --- a/AuthorizeNet/AIM.pm +++ b/AuthorizeNet/AIM.pm @@ -2,17 +2,14 @@ package Business::OnlinePayment::AuthorizeNet::AIM; use strict; use Carp; +use Business::OnlinePayment::HTTPS; use Business::OnlinePayment::AuthorizeNet; -use Net::SSLeay qw/make_form post_https make_headers/; +use Business::OnlinePayment::AuthorizeNet::AIM::ErrorCodes '%ERRORS'; use Text::CSV_XS; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); -require Exporter; - -@ISA = qw(Exporter Business::OnlinePayment::AuthorizeNet); -@EXPORT = qw(); -@EXPORT_OK = qw(); -$VERSION = '3.21'; +@ISA = qw(Business::OnlinePayment::AuthorizeNet Business::OnlinePayment::HTTPS); +$VERSION = '3.22'; sub set_defaults { my $self = shift; @@ -59,10 +56,6 @@ sub map_fields { $content{'account_type'} = $account_types{lc($content{'account_type'})} || $content{'account_type'}; - $content{'referer'} = defined( $content{'referer'} ) - ? make_headers( 'Referer' => $content{'referer'} ) - : ""; - if (length $content{'password'} == 15) { $content{'transaction_key'} = delete $content{'password'}; } @@ -259,12 +252,13 @@ sub submit { $post_data{'x_ADC_URL'} = 'FALSE'; $post_data{'x_Version'} = '3.1'; - my $pd = make_form(%post_data); - my $s = $self->server(); - my $p = $self->port(); - my $t = $self->path(); - my $r = $self->{_content}->{referer}; - my($page,$server_response,%headers) = post_https($s,$p,$t,$r,$pd); + my $opt = defined( $self->{_content}->{referer} ) + ? { 'headers' => { 'Referer' => $self->{_content}->{referer} } } + : {}; + + my($page, $server_response, %headers) = + $self->https_post( $opt, \%post_data ); + #escape NULL (binary 0x00) values $page =~ s/\x00/\^0/g; @@ -294,7 +288,11 @@ sub submit { $self->is_success(0); $self->result_code($col[2]); $self->error_message($col[3]); - unless ( $self->result_code() ) { #additional logging information + if ( $self->result_code ) { + my $addl = $ERRORS{ $self->result_code }; + $self->error_message( $self->error_message. ' - '. $addl->{notes}) + if $addl && ref($addl) eq 'HASH' && $addl->{notes}; + } else { #additional logging information #$page =~ s/\x00/\^0/g; $self->error_message($col[3]. " DEBUG: No x_response_code from server, ". diff --git a/Changes b/Changes index bb8bb4f..d0da072 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,10 @@ Revision history for Perl extension Business::OnlinePayment::AuthorizeNet. 3.22 unreleased - Add missing t/lib/Business/FraudDetect/_Fake.pm to MANIFEST to fix tests. Patch from Rob Brown, thanks! (closes: CPAN#52444) + - Incorporate Business::OnlinePayment::AuthorizeNet::AIM::ErrorCodes by + Thomas Sibley and, using it, provide more descriptive error messages. + - Switch to Business::OnlinePayment::HTTPS instead of using Net::SSLeay + directly 3.21 Tue Nov 24 10:45:21 PST 2009 - Add repository, contributing and contirbutor information to the docs. diff --git a/Makefile.PL b/Makefile.PL index 6476f7a..baa24c8 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -4,10 +4,10 @@ WriteMakefile( 'VERSION_FROM' => 'AuthorizeNet.pm', # finds $VERSION 'AUTHOR' => 'Ivan Kohler ', #really just #the maintainer - 'PREREQ_PM' => { 'Net::SSLeay' => 0, - 'Text::CSV_XS' => 0, + 'PREREQ_PM' => { 'Text::CSV_XS' => 0, 'Business::OnlinePayment' => 3, 'Business::OnlinePayment::HTTPS' => 0, + 'Net::HTTPS::Any' => 0, 'Test::More' => 0.42, 'Tie::IxHash' => 0, 'XML::Simple' => 0, diff --git a/t/card_arb.t b/t/card_arb.t index 99f0914..4ce6951 100644 --- a/t/card_arb.t +++ b/t/card_arb.t @@ -1,6 +1,6 @@ #!/usr/bin/perl -w -use Test::More; +use Test::More skip_all => 'Authorize.net test account throwing errors about duplicates'; require "t/lib/test_account.pl"; my($login, $password) = test_account_or_skip('arb'); diff --git a/t/errorcodes.t b/t/errorcodes.t new file mode 100644 index 0000000..130ae71 --- /dev/null +++ b/t/errorcodes.t @@ -0,0 +1,36 @@ +#!/usr/bin/perl -w + +use Test::More; +require "t/lib/test_account.pl"; + +my($login, $password) = test_account_or_skip(); +plan tests => 3; + +use_ok 'Business::OnlinePayment'; + +my $tx = Business::OnlinePayment->new("AuthorizeNet"); +$tx->server('test.authorize.net'); +$tx->content( + type => 'VISA', + login => $login, + password => $password, + action => 'Normal Authorization', + description => 'Business::OnlinePayment visa test', + amount => '49.95', + invoice_number => '100100', + customer_id => 'jsk', + first_name => 'Tofu', + last_name => 'Beast', + address => '123 Anystreet', + city => 'Anywhere', + state => 'UT', + zip => '84058', + card_number => '4007000000027', + expiration => 'BADFORMAT', #expiration_date(), +); +$tx->test_transaction(1); # test, dont really charge +$tx->submit(); + +ok(!$tx->is_success); + +ok($tx->error_message() =~ /The format of the date submitted was incorrect/ ); -- 2.11.0