Initial dummy module for testing, submit always returns success
[Business-OnlinePayment-Dummy.git] / Dummy.pm
1 package Business::OnlinePayment::Dummy;
2
3 use strict;
4 use Carp;
5 use Business::OnlinePayment;
6 use vars qw($VERSION @ISA $me);
7
8 @ISA = qw(Business::OnlinePayment);
9 $VERSION = '0.01';
10 $me = 'Business::OnlinePayment::Dummy';
11
12 sub submit {
13     my($self) = @_;
14     $self->authorization(time . int(rand(10000)));
15     $self->is_success(1);
16 }
17
18 1;
19
20 __END__
21
22 =head1 NAME
23
24 Business::OnlinePayment::AuthorizeNet - AuthorizeNet backend for Business::OnlinePayment
25
26 =head1 SYNOPSIS
27
28   use Business::OnlinePayment;
29
30   ####
31   # One step transaction, the simple case.
32   ####
33
34   my $tx = new Business::OnlinePayment("AuthorizeNet");
35   $tx->content(
36       type           => 'VISA',
37       login          => 'testdrive',
38       password       => '', #password or transaction key
39       action         => 'Normal Authorization',
40       description    => 'Business::OnlinePayment test',
41       amount         => '49.95',
42       invoice_number => '100100',
43       customer_id    => 'jsk',
44       email          => 'jason@example.com',
45       first_name     => 'Jason',
46       last_name      => 'Kohles',
47       address        => '123 Anystreet',
48       city           => 'Anywhere',
49       state          => 'UT',
50       zip            => '84058',
51       country        => 'US',
52       card_number    => '4007000000027',
53       expiration     => '09/02',
54       cvv2           => '1234', #optional
55       referer        => 'http://valid.referer.url/',
56   );
57   $tx->submit();
58
59   if($tx->is_success()) {
60       print "Card processed successfully: ".$tx->authorization."\n";
61   } else {
62       print "Card was rejected: ".$tx->error_message."\n";
63   }
64
65   ####
66   # Two step transaction, authorization and capture.
67   # If you don't need to review order before capture, you can
68   # process in one step as above.
69   ####
70
71   my $tx = new Business::OnlinePayment("AuthorizeNet");
72   $tx->content(
73       type           => 'VISA',
74       login          => 'testdrive',
75       password       => '',  #password or transaction key
76       action         => 'Authorization Only',
77       description    => 'Business::OnlinePayment test',
78       amount         => '49.95',
79       invoice_number => '100100',
80       customer_id    => 'jsk',
81       email          => 'jason@example.com',
82       first_name     => 'Jason',
83       last_name      => 'Kohles',
84       address        => '123 Anystreet',
85       city           => 'Anywhere',
86       state          => 'UT',
87       zip            => '84058',
88       country        => 'US',
89       card_number    => '4007000000027',
90       expiration     => '09/02',
91       cvv2           => '1234', #optional
92       referer        => 'http://valid.referer.url/',
93   );
94   $tx->submit();
95
96   if($tx->is_success()) {
97       # get information about authorization
98       $authorization = $tx->authorization
99       $ordernum = $tx->order_number;
100       $avs_code = $tx->avs_code; # AVS Response Code
101       $cvv2_response = $tx->cvv2_response; # CVV2/CVC2/CID Response Code
102       $cavv_response = $tx->cavv_response; # Cardholder Authentication
103                                            # Verification Value (CAVV) Response
104                                            # Code
105
106       # now capture transaction
107       my $capture = new Business::OnlinePayment("AuthorizeNet");
108
109       $capture->content(
110           type           => 'CC',
111           action         => 'Post Authorization',
112           login          => 'YOURLOGIN
113           password       => 'YOURPASSWORD', #or transaction key
114           order_number   => $ordernum,
115           amount         => '49.95',
116       );
117
118       $capture->submit();
119
120       if($capture->is_success()) { 
121           print "Card captured successfully: ".$capture->authorization."\n";
122       } else {
123           print "Card was rejected: ".$capture->error_message."\n";
124       }
125
126   } else {
127       print "Card was rejected: ".$tx->error_message."\n";
128   }
129
130   ####
131   # One step subscription, the simple case.
132   ####
133
134   my $tx = new Business::OnlinePayment("AuthorizeNet::ARB");
135   $tx->content(
136       type           => 'CC',
137       login          => 'testdrive',
138       password       => 'testpass', #or transaction key
139       action         => 'Recurring Authorization',
140       interval       => '7 days',
141       start          => '2008-3-10',
142       periods        => '16',
143       amount         => '99.95',
144       trialperiods   => '4',
145       trialamount    => '0',
146       description    => 'Business::OnlinePayment test',
147       invoice_number => '1153B33F',
148       customer_id    => 'vip',
149       first_name     => 'Tofu',
150       last_name      => 'Beast',
151       address        => '123 Anystreet',
152       city           => 'Anywhere',
153       state          => 'GA',
154       zip            => '84058',
155       card_number    => '4111111111111111',
156       expiration     => '09/02',
157   );
158   $tx->submit();
159
160   if($tx->is_success()) {
161       print "Card processed successfully: ".$tx->order_number."\n";
162   } else {
163       print "Card was rejected: ".$tx->error_message."\n";
164   }
165   my $subscription = $tx->order_number
166
167
168   ####
169   # Subscription change.   Modestly more complicated.
170   ####
171
172   $tx->content(
173       type           => 'CC',
174       subscription   => '99W2C',
175       login          => 'testdrive',
176       password       => 'testpass', #or transaction key
177       action         => 'Modify Recurring Authorization',
178       interval       => '7 days',
179       start          => '2008-3-10',
180       periods        => '16',
181       amount         => '29.95',
182       trialperiods   => '4',
183       trialamount    => '0',
184       description    => 'Business::OnlinePayment test',
185       invoice_number => '1153B340',
186       customer_id    => 'vip',
187       first_name     => 'Tofu',
188       last_name      => 'Beast',
189       address        => '123 Anystreet',
190       city           => 'Anywhere',
191       state          => 'GA',
192       zip            => '84058',
193       card_number    => '4111111111111111',
194       expiration     => '09/02',
195   );
196   $tx->submit();
197
198   if($tx->is_success()) {
199       print "Update processed successfully."\n";
200   } else {
201       print "Update was rejected: ".$tx->error_message."\n";
202   }
203   $tx->content(
204       subscription   => '99W2D',
205       login          => 'testdrive',
206       password       => 'testpass', # or transaction key
207       action         => 'Cancel Recurring Authorization',
208   );
209   $tx->submit();
210
211   ####
212   # Subscription cancellation.   It happens.
213   ####
214
215   if($tx->is_success()) {
216       print "Cancellation processed successfully."\n";
217   } else {
218       print "Cancellation was rejected: ".$tx->error_message."\n";
219   }
220
221
222 =head1 SUPPORTED TRANSACTION TYPES
223
224 =head2 CC, Visa, MasterCard, American Express, Discover
225
226 Content required: type, login, password, action, amount, first_name, last_name, card_number, expiration.
227
228 =head2 Check
229
230 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).
231
232 =head2 Subscriptions
233
234 Additional content required: interval, start, periods.
235
236 =head1 DESCRIPTION
237
238 For detailed information see L<Business::OnlinePayment>.
239
240 =head1 METHODS AND FUNCTIONS
241
242 See L<Business::OnlinePayment> for the complete list. The following methods either override the methods in L<Business::OnlinePayment> or provide additional functions.  
243
244 =head2 result_code
245
246 Returns the response reason code (from the message.code field for subscriptions).
247
248 =head2 error_message
249
250 Returns the response reason text (from the message.text field for subscriptions.
251
252 =head2 server_response
253
254 Returns the complete response from the server.
255
256 =head1 Handling of content(%content) data:
257
258 =head2 action
259
260 The following actions are valid
261
262   normal authorization
263   authorization only
264   credit
265   post authorization
266   void
267   recurring authorization
268   modify recurring authorization
269   cancel recurring authorization
270
271 =head2 interval
272
273   Interval contains a number of digits, whitespace, and the units of days or months in either singular or plural form.
274   
275
276 =head1 Setting AuthorizeNet ARB parameters from content(%content)
277
278 The following rules are applied to map data to AuthorizeNet ARB parameters
279 from content(%content):
280
281       # ARB param => $content{<key>}
282       merchantAuthentication
283         name                     =>  'login',
284         transactionKey           =>  'password',
285       subscription
286         paymentSchedule
287           interval
288             length               => \( the digits in 'interval' ),
289             unit                 => \( days or months gleaned from 'interval' ),          startDate              => 'start',
290           totalOccurrences       => 'periods',
291           trialOccurrences       => 'trialperiods',
292         amount                   => 'amount',
293         trialAmount              => 'trialamount',
294         payment
295           creditCard
296             cardNumber           => 'card_number',
297             expiration           => \( $year.'-'.$month ), # YYYY-MM from 'expiration'
298           bankAccount
299             accountType          => 'account_type',
300             routingNumber        => 'routing_code',
301             accountNumber        => 'account_number,
302             nameOnAccount        => 'name',
303             bankName             => 'bank_name',
304             echeckType           => 'check_type',
305         order
306           invoiceNumber          => 'invoice_number',
307           description            => 'description',
308         customer
309           type                   => 'customer_org',
310           id                     => 'customer_id',
311           email                  => 'email',
312           phoneNumber            => 'phone',
313           faxNumber              => 'fax',
314           driversLicense
315             number               => 'license_num',
316             state                => 'license_state',
317             dateOfBirth          => 'license_dob',
318           taxid                  => 'customer_ssn',
319         billTo
320           firstName              => 'first_name',
321           lastName               => 'last_name',
322           company                => 'company',
323           address                => 'address',
324           city                   => 'city',
325           state                  => 'state',
326           zip                    => 'zip',
327           country                => 'country',
328         shipTo
329           firstName              => 'ship_first_name',
330           lastName               => 'ship_last_name',
331           company                => 'ship_company',
332           address                => 'ship_address',
333           city                   => 'ship_city',
334           state                  => 'ship_state',
335           zip                    => 'ship_zip',
336           country                => 'ship_country',
337
338 =head1 NOTES
339
340 Use your transaction key in the password field.
341
342 Unlike Business::OnlinePayment or pre-3.0 versions of
343 Business::OnlinePayment::AuthorizeNet, 3.1 requires separate first_name and
344 last_name fields.
345
346 Business::OnlinePayment::AuthorizeNet uses Authorize.Net's "Advanced
347 Integration Method (AIM) (formerly known as ADC direct response)" and
348 "Automatic Recurring Billing (ARB)", sending a username and password (or
349 transaction key as password) with every transaction.  Therefore,
350 Authorize.Net's referrer "security" is not necessary.  In your Authorize.Net
351 interface at https://secure.authorize.net/ make sure the list of allowable
352 referers is blank.  Alternatively, set the B<referer> field in the transaction
353 content.
354
355 To settle an authorization-only transaction (where you set action to
356 'Authorization Only'), submit the nine-digit transaction id code in
357 the field "order_number" with the action set to "Post Authorization".
358 You can get the transaction id from the authorization by calling the
359 order_number method on the object returned from the authorization.
360 You must also submit the amount field with a value less than or equal
361 to the amount specified in the original authorization.
362
363 For the subscription actions an authorization code is never returned by
364 the module.  Instead it returns the value of subscriptionId in order_number.
365 This is the value to use for changing or cancelling subscriptions.
366
367 Authorize.Net has turned address verification on by default for all merchants
368 since 2002.  If you do not have valid address information for your customer
369 (such as in an IVR application), you must disable address verification in the
370 Merchant Menu page at https://secure.authorize.net/ so that the transactions
371 aren't denied due to a lack of address information.
372
373 =head1 COMPATIBILITY
374
375 This module implements Authorize.Net's API using the Advanced Integration
376 Method (AIM) version 3.1, formerly known as ADC Direct Response and the 
377 Automatic Recurring Billing version 1.0 using the XML interface.  See
378 http://www.authorize.net/support/AIM_guide.pdf and http://www.authorize.net/support/ARB_guide.pdf for details.
379
380 =head1 AUTHORS
381
382 Original author: Jason Kohles, jason@mediabang.com
383
384 Ivan Kohler <ivan-authorizenet@freeside.biz> updated it for Authorize.Net
385 protocol 3.0/3.1 and is the current maintainer.  Please see the next section
386 for for information on contributing.
387
388 Jason Spence <jspence@lightconsulting.com> contributed support for separate
389 Authorization Only and Post Authorization steps and wrote some docs.
390 OST <services@ostel.com> paid for it.
391
392 Jeff Finucane <authorizenetarb@weasellips.com> added the ARB support.
393 ARB support sponsored by Plus Three, LP. L<http://www.plusthree.com>.
394
395 T.J. Mather <tjmather@maxmind.com> sent a number of CVV2 patches.
396
397 Mike Barry <mbarry@cos.com> sent in a patch for the referer field and a fix for
398 ship_company.
399
400 Yuri V. Mkrtumyan <yuramk@novosoft.ru> sent in a patch to add the void action.
401
402 Paul Zimmer <AuthorizeNetpm@pzimmer.box.bepress.com> sent in a patch for
403 card-less post authorizations.
404
405 Daemmon Hughes <daemmon@daemmonhughes.com> sent in a patch for "transaction
406 key" authentication as well support for the recurring_billing flag and the md5
407 method that returns the MD5 hash which is returned by the gateway.
408
409 Steve Simitzis contributed a patch for better compatibility with
410 eProcessingNetwork's AuthorizeNet compatibility mode.
411
412 Michael G. Schwern contributed cleanups, test fixes, and more.
413
414 Erik Hollensbe implemented card-present data (track1/track2), the
415 duplicate_window parameter, and test fixes.
416
417 Paul Timmins added the check_number field.
418
419 Nate Nuss implemented the ("Additional Shipping Information (Level 2 Data)"
420 fields: tax, freight, duty, tax_exempt, po_number.
421
422 Michael Peters fixed a bug in email address handling.
423
424 Thomas Sibley <trs@bestpractical.com> wrote B:OP:AuthorizeNet::AIM::ErrorCodes
425 which was borged and used to provide more descriptive error messages.
426
427 Craig Pearlman <cpearlma@yahoo.com> sent in a patch to more accurately declare
428 required fields for E-check transcations.
429
430 =head1 CONTRIBUTIONS AND REPOSITORY
431
432 Please send patches as unified diffs (diff -u) to (in order of preference):
433
434 =over 4
435
436 =item CPAN RT
437
438 http://rt.cpan.org/Public/Bug/Report.html?Queue=Business-OnlinePayment-AuthorizeNet
439
440 =item The bop-devel mailing list
441
442 http://420.am/cgi-bin/mailman/listinfo/bop-devel
443
444 =item Ivan
445
446 Ivan Kohler <ivan-authorizenet@freeside.biz>
447
448 =back
449
450 The code is available from our public CVS repository:
451
452   export CVSROOT=":pserver:anonymous@cvs.freeside.biz:/home/cvs/cvsroot"
453   cvs login
454   # The password for the user `anonymous' is `anonymous'.
455   cvs checkout Business-OnlinePayment-AuthorizeNet
456
457 Or on the web:
458
459   http://freeside.biz/cgi-bin/viewvc.cgi/Business-OnlinePayment-AuthorizeNet/
460
461 =head1 A WORD FROM OUR SPONSOR
462
463 This module and the Business::OnlinePayment framework are maintained by by
464 Freeside Internet Services.  If you need a complete, open-source web-based
465 application to manage your customers, billing and trouble ticketing, please
466 visit http://freeside.biz/
467
468 =head1 COPYRIGHT & LICENSE
469
470 Copyright 2010 Freeside Internet Services, Inc.
471 Copyright 2008 Thomas Sibley
472 All rights reserved.
473
474 This program is free software; you can redistribute it and/or modify it
475 under the same terms as Perl itself.
476
477 =head1 SEE ALSO
478
479 perl(1). L<Business::OnlinePayment>.
480
481 =cut
482