1 package Business::OnlinePayment::AuthorizeNet;
3 # $Id: AuthorizeNet.pm,v 1.1 2001-09-01 21:47:31 ivan Exp $
6 use Business::OnlinePayment;
7 use Net::SSLeay qw/make_form post_https/;
9 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
13 @ISA = qw(Exporter AutoLoader Business::OnlinePayment);
21 $self->server('secure.authorize.net');
23 $self->path('/gateway/transact.dll');
29 my %content = $self->content();
32 my %actions = ('normal authorization' => 'AUTH_CAPTURE',
33 'authorization only' => 'AUTH_ONLY',
35 'post authorization' => 'PRIOR_AUTH_CAPTURE',
37 $content{'action'} = $actions{lc($content{'action'})} || $content{'action'};
40 my %types = ('visa' => 'CC',
42 'american express' => 'CC',
46 $content{'type'} = $types{lc($content{'type'})} || $content{'type'};
47 $self->transaction_type($content{'type'});
49 # stuff it back into %content
50 $self->content(%content);
56 my %content = $self->content();
58 $content{$map{$_}} = $content{$_};
60 $self->content(%content);
64 my($self,@fields) = @_;
66 my %content = $self->content();
68 foreach( grep defined $content{$_}, @fields) { $new{$_} = $content{$_}; }
79 password => 'x_Password',
81 description => 'x_Description',
83 invoice_number => 'x_Invoice_Num',
84 customer_id => 'x_Cust_ID',
85 last_name => 'x_Last_Name',
86 first_name => 'x_First_Name',
87 address => 'x_Address',
91 card_number => 'x_Card_Num',
92 expiration => 'x_Exp_Date',
93 account_number => 'x_Bank_Acct_Num',
94 routing_code => 'x_Bank_ABA_Code',
95 bank_name => 'x_Bank_Name',
96 country => 'x_Country',
100 company => 'x_Company',
103 if($self->transaction_type() eq "ECHECK") {
104 $self->required_fields(qw/type login password action amount last_name
105 first_name account_number routing_code
107 } elsif($self->transaction_type() eq 'CC' ) {
108 $self->required_fields(qw/type login password action amount last_name
109 first_name card_number expiration/);
111 Carp::croak("AuthorizeNet can't handle transaction type: ".
112 $self->transaction_type());
115 my %post_data = $self->get_fields(qw/x_Login x_Password x_Invoice_Num
116 x_Description x_Amount x_Cust_ID
117 x_Method x_Type x_Card_Num x_Exp_Date
118 x_Auth_Code x_Bank_Acct_Num
119 x_Bank_ABA_Code x_Bank_Name
120 x_Last_Name x_First_Name x_Address
121 x_City x_State x_Zip x_Country x_Phone
122 x_Fax x_Email x_Email_Customer
123 x_Company x_Country/);
124 $post_data{'x_Test_Request'} = $self->test_transaction()?"TRUE":"FALSE";
125 $post_data{'x_ADC_Delim_Data'} = 'TRUE';
126 $post_data{'x_ADC_URL'} = 'FALSE';
127 $post_data{'x_Version'} = '3.0';
129 my $pd = make_form(%post_data);
130 my $s = $self->server();
131 my $p = $self->port();
132 my $t = $self->path();
133 my($page,$server_response,%headers) = post_https($s,$p,$t,'',$pd);
135 my $csv = new Text::CSV();
137 my @col = $csv->fields();
139 $self->server_response($page);
140 if($col[0] eq "1" ) { # Authorized/Pending/Test
141 $self->is_success(1);
142 $self->result_code($col[0]);
143 $self->authorization($col[4]);
145 $self->is_success(0);
146 $self->result_code($col[2]);
147 $self->error_message($col[3]);
156 Business::OnlinePayment::AuthorizeNet - AuthorizeNet backend for Business::OnlinePayment
160 use Business::OnlinePayment;
162 my $tx = new Business::OnlinePayment("AuthorizeNet");
165 login => 'testdrive',
167 action => 'Normal Authorization',
168 description => 'Business::OnlinePayment test',
170 invoice_number => '100100',
171 customer_id => 'jsk',
172 first_name => 'Jason',
173 last_name => 'Kohles',
174 address => '123 Anystreet',
178 card_number => '4007000000027',
179 expiration => '09/99',
183 if($tx->is_success()) {
184 print "Card processed successfully: ".$tx->authorization."\n";
186 print "Card was rejected: ".$tx->error_message."\n";
189 =head1 SUPPORTED TRANSACTION TYPES
191 =head2 Visa, MasterCard, American Express, Discover
193 Content required: type, login, password, action, amount, first_name, last_name, card_number, expiration.
197 Content required: type, login, password, action, amount, first_name, last_name, account_number, routing_code, bank_name.
201 For detailed information see L<Business::OnlinePayment>.
205 Unlike Business::OnlinePayment or previous verisons of
206 Business::OnlinePayment::AuthorizeNet, 3.0 requires separate first_name and
211 This module implements Authorize.Net's API verison 3.0.
215 Jason Kohles, jason@mediabang.com
217 Ivan Kohler <ivan-authorizenet@420.am> updated it for Authorize.Net protocol
218 3.0 and is the current maintainer.
222 perl(1). L<Business::OnlinePayment>.