1 package Business::OnlinePayment::AuthorizeNet;
5 use Business::OnlinePayment;
6 use vars qw($VERSION @ISA $me);
8 @ISA = qw(Business::OnlinePayment);
10 $me = 'Business::OnlinePayment::AuthorizeNet';
15 $self->build_subs(qw( order_number md5 avs_code cvv2_response
23 my %content = $self->content();
24 my %processors = ('recurring authorization' => 'ARB',
25 'modify recurring authorization' => 'ARB',
26 'cancel recurring authorization' => 'ARB',
28 $processors{lc($content{'action'})} || 'AIM';
34 my $processor = $me. "::". $self->_map_processor();
36 eval "use $processor";
37 croak("unknown processor $processor ($@)") if $@;
39 my $object = bless $self, $processor;
40 $object->set_defaults();
50 Business::OnlinePayment::AuthorizeNet - AuthorizeNet backend for Business::OnlinePayment
54 use Business::OnlinePayment;
57 # One step transaction, the simple case.
60 my $tx = new Business::OnlinePayment("AuthorizeNet");
64 password => '', #password or transaction key
65 action => 'Normal Authorization',
66 description => 'Business::OnlinePayment test',
68 invoice_number => '100100',
70 email => 'jason@example.com',
71 first_name => 'Jason',
72 last_name => 'Kohles',
73 address => '123 Anystreet',
78 card_number => '4007000000027',
79 expiration => '09/02',
80 cvv2 => '1234', #optional
81 referer => 'http://valid.referer.url/',
85 if($tx->is_success()) {
86 print "Card processed successfully: ".$tx->authorization."\n";
88 print "Card was rejected: ".$tx->error_message."\n";
92 # Two step transaction, authorization and capture.
93 # If you don't need to review order before capture, you can
94 # process in one step as above.
97 my $tx = new Business::OnlinePayment("AuthorizeNet");
100 login => 'testdrive',
101 password => '', #password or transaction key
102 action => 'Authorization Only',
103 description => 'Business::OnlinePayment test',
105 invoice_number => '100100',
106 customer_id => 'jsk',
107 email => 'jason@example.com',
108 first_name => 'Jason',
109 last_name => 'Kohles',
110 address => '123 Anystreet',
115 card_number => '4007000000027',
116 expiration => '09/02',
117 cvv2 => '1234', #optional
118 referer => 'http://valid.referer.url/',
122 if($tx->is_success()) {
123 # get information about authorization
124 $authorization = $tx->authorization
125 $ordernum = $tx->order_number;
126 $avs_code = $tx->avs_code; # AVS Response Code
127 $cvv2_response = $tx->cvv2_response; # CVV2/CVC2/CID Response Code
128 $cavv_response = $tx->cavv_response; # Cardholder Authentication
129 # Verification Value (CAVV) Response
132 # now capture transaction
133 my $capture = new Business::OnlinePayment("AuthorizeNet");
137 action => 'Post Authorization',
139 password => 'YOURPASSWORD', #or transaction key
140 order_number => $ordernum,
146 if($capture->is_success()) {
147 print "Card captured successfully: ".$capture->authorization."\n";
149 print "Card was rejected: ".$capture->error_message."\n";
153 print "Card was rejected: ".$tx->error_message."\n";
157 # One step subscription, the simple case.
160 my $tx = new Business::OnlinePayment("AuthorizeNet::ARB");
163 login => 'testdrive',
164 password => 'testpass', #or transaction key
165 action => 'Recurring Authorization',
166 interval => '7 days',
167 start => '2008-3-10',
172 description => 'Business::OnlinePayment test',
173 invoice_number => '1153B33F',
174 customer_id => 'vip',
175 first_name => 'Tofu',
176 last_name => 'Beast',
177 address => '123 Anystreet',
181 card_number => '4111111111111111',
182 expiration => '09/02',
186 if($tx->is_success()) {
187 print "Card processed successfully: ".$tx->order_number."\n";
189 print "Card was rejected: ".$tx->error_message."\n";
191 my $subscription = $tx->order_number
195 # Subscription change. Modestly more complicated.
200 subscription => '99W2C',
201 login => 'testdrive',
202 password => 'testpass', #or transaction key
203 action => 'Modify Recurring Authorization',
204 interval => '7 days',
205 start => '2008-3-10',
210 description => 'Business::OnlinePayment test',
211 invoice_number => '1153B340',
212 customer_id => 'vip',
213 first_name => 'Tofu',
214 last_name => 'Beast',
215 address => '123 Anystreet',
219 card_number => '4111111111111111',
220 expiration => '09/02',
224 if($tx->is_success()) {
225 print "Update processed successfully."\n";
227 print "Update was rejected: ".$tx->error_message."\n";
230 subscription => '99W2D',
231 login => 'testdrive',
232 password => 'testpass', # or transaction key
233 action => 'Cancel Recurring Authorization',
238 # Subscription cancellation. It happens.
241 if($tx->is_success()) {
242 print "Cancellation processed successfully."\n";
244 print "Cancellation was rejected: ".$tx->error_message."\n";
248 =head1 SUPPORTED TRANSACTION TYPES
250 =head2 CC, Visa, MasterCard, American Express, Discover
252 Content required: type, login, password, action, amount, first_name, last_name, card_number, expiration.
256 Content required: type, login, password, action, amount, first_name, last_name, account_number, routing_code, bank_name (non-subscription), account_type (subscription), check_type (subscription).
260 Additional content required: interval, start, periods.
264 For detailed information see L<Business::OnlinePayment>.
266 =head1 METHODS AND FUNCTIONS
268 See L<Business::OnlinePayment> for the complete list. The following methods either override the methods in L<Business::OnlinePayment> or provide additional functions.
272 Returns the response reason code (from the message.code field for subscriptions).
276 Returns the response reason text (from the message.text field for subscriptions.
278 =head2 server_response
280 Returns the complete response from the server.
282 =head1 Handling of content(%content) data:
286 The following actions are valid
293 recurring authorization
294 modify recurring authorization
295 cancel recurring authorization
299 Interval contains a number of digits, whitespace, and the units of days or months in either singular or plural form.
302 =head1 Setting AuthorizeNet ARB parameters from content(%content)
304 The following rules are applied to map data to AuthorizeNet ARB parameters
305 from content(%content):
307 # ARB param => $content{<key>}
308 merchantAuthentication
310 transactionKey => 'password',
314 length => \( the digits in 'interval' ),
315 unit => \( days or months gleaned from 'interval' ), startDate => 'start',
316 totalOccurrences => 'periods',
317 trialOccurrences => 'trialperiods',
319 trialAmount => 'trialamount',
322 cardNumber => 'card_number',
323 expiration => \( $year.'-'.$month ), # YYYY-MM from 'expiration'
325 accountType => 'account_type',
326 routingNumber => 'routing_code',
327 accountNumber => 'account_number,
328 nameOnAccount => 'name',
329 bankName => 'bank_name',
330 echeckType => 'check_type',
332 invoiceNumber => 'invoice_number',
333 description => 'description',
335 type => 'customer_org',
338 phoneNumber => 'phone',
341 number => 'license_num',
342 state => 'license_state',
343 dateOfBirth => 'license_dob',
344 taxid => 'customer_ssn',
346 firstName => 'first_name',
347 lastName => 'last_name',
348 company => 'company',
349 address => 'address',
353 country => 'country',
355 firstName => 'ship_first_name',
356 lastName => 'ship_last_name',
357 company => 'ship_company',
358 address => 'ship_address',
360 state => 'ship_state',
362 country => 'ship_country',
366 Use your transaction key in the password field.
368 Unlike Business::OnlinePayment or pre-3.0 versions of
369 Business::OnlinePayment::AuthorizeNet, 3.1 requires separate first_name and
372 Business::OnlinePayment::AuthorizeNet uses Authorize.Net's "Advanced
373 Integration Method (AIM) (formerly known as ADC direct response)" and
374 "Automatic Recurring Billing (ARB)", sending a username and password (or
375 transaction key as password) with every transaction. Therefore,
376 Authorize.Net's referrer "security" is not necessary. In your Authorize.Net
377 interface at https://secure.authorize.net/ make sure the list of allowable
378 referers is blank. Alternatively, set the B<referer> field in the transaction
381 To settle an authorization-only transaction (where you set action to
382 'Authorization Only'), submit the nine-digit transaction id code in
383 the field "order_number" with the action set to "Post Authorization".
384 You can get the transaction id from the authorization by calling the
385 order_number method on the object returned from the authorization.
386 You must also submit the amount field with a value less than or equal
387 to the amount specified in the original authorization.
389 For the subscription actions an authorization code is never returned by
390 the module. Instead it returns the value of subscriptionId in order_number.
391 This is the value to use for changing or cancelling subscriptions.
393 Authorize.Net has turned address verification on by default for all merchants
394 since 2002. If you do not have valid address information for your customer
395 (such as in an IVR application), you must disable address verification in the
396 Merchant Menu page at https://secure.authorize.net/ so that the transactions
397 aren't denied due to a lack of address information.
401 This module implements Authorize.Net's API using the Advanced Integration
402 Method (AIM) version 3.1, formerly known as ADC Direct Response and the
403 Automatic Recurring Billing version 1.0 using the XML interface. See
404 http://www.authorize.net/support/AIM_guide.pdf and http://www.authorize.net/support/ARB_guide.pdf for details.
408 Original author: Jason Kohles, jason@mediabang.com
410 Ivan Kohler <ivan-authorizenet@freeside.biz> updated it for Authorize.Net
411 protocol 3.0/3.1 and is the current maintainer. Please see the next section
412 for for information on contributing.
414 Jason Spence <jspence@lightconsulting.com> contributed support for separate
415 Authorization Only and Post Authorization steps and wrote some docs.
416 OST <services@ostel.com> paid for it.
418 Jeff Finucane <authorizenetarb@weasellips.com> added the ARB support.
419 ARB support sponsored by Plus Three, LP. L<http://www.plusthree.com>.
421 T.J. Mather <tjmather@maxmind.com> sent a number of CVV2 patches.
423 Mike Barry <mbarry@cos.com> sent in a patch for the referer field and a fix for
426 Yuri V. Mkrtumyan <yuramk@novosoft.ru> sent in a patch to add the void action.
428 Paul Zimmer <AuthorizeNetpm@pzimmer.box.bepress.com> sent in a patch for
429 card-less post authorizations.
431 Daemmon Hughes <daemmon@daemmonhughes.com> sent in a patch for "transaction
432 key" authentication as well support for the recurring_billing flag and the md5
433 method that returns the MD5 hash which is returned by the gateway.
435 Steve Simitzis contributed a patch for better compatibility with
436 eProcessingNetwork's AuthorizeNet compatibility mode.
438 Michael G. Schwern contributed cleanups, test fixes, and more.
440 Erik Hollensbe implemented card-present data (track1/track2), the
441 duplicate_window parameter, and test fixes.
443 Paul Timmins added the check_number field.
445 Nate Nuss implemented the ("Additional Shipping Information (Level 2 Data)"
446 fields: tax, freight, duty, tax_exempt, po_number.
448 Michael Peters fixed a bug in email address handling.
450 Thomas Sibley <trs@bestpractical.com> wrote B:OP:AuthorizeNet::AIM::ErrorCodes
451 which was borged and used to provide more descriptive error messages.
453 Craig Pearlman <cpearlma@yahoo.com> sent in a patch to more accurately declare
454 required fields for E-check transcations.
456 =head1 CONTRIBUTIONS AND REPOSITORY
458 Please send patches as unified diffs (diff -u) to (in order of preference):
464 http://rt.cpan.org/Public/Bug/Report.html?Queue=Business-OnlinePayment-AuthorizeNet
466 =item The bop-devel mailing list
468 http://420.am/cgi-bin/mailman/listinfo/bop-devel
472 Ivan Kohler <ivan-authorizenet@freeside.biz>
476 The code is available from our public CVS repository:
478 export CVSROOT=":pserver:anonymous@cvs.freeside.biz:/home/cvs/cvsroot"
480 # The password for the user `anonymous' is `anonymous'.
481 cvs checkout Business-OnlinePayment-AuthorizeNet
485 http://freeside.biz/cgi-bin/viewvc.cgi/Business-OnlinePayment-AuthorizeNet/
487 =head1 A WORD FROM OUR SPONSOR
489 This module and the Business::OnlinePayment framework are maintained by by
490 Freeside Internet Services. If you need a complete, open-source web-based
491 application to manage your customers, billing and trouble ticketing, please
492 visit http://freeside.biz/
494 =head1 COPYRIGHT & LICENSE
496 Copyright 2010 Freeside Internet Services, Inc.
497 Copyright 2008 Thomas Sibley
500 This program is free software; you can redistribute it and/or modify it
501 under the same terms as Perl itself.
505 perl(1). L<Business::OnlinePayment>.