licence pednatry, dh-make-perl complains
[Business-OnlineThirdPartyPayment.git] / OnlineThirdPartyPayment.pm
1 package Business::OnlineThirdPartyPayment;
2
3 use strict;
4 use vars qw($VERSION);
5 use Carp;
6 use base qw(Business::OnlinePayment);
7
8 require 5.005;
9
10 $VERSION = '3.00_09';
11 $VERSION = eval $VERSION; # modperlstyle: convert the string into a number
12
13 my %fields = (
14     authorization        => undef,
15     error_message        => undef,
16     failure_status       => undef,
17     fraud_detect         => undef,  # unsupported
18     is_success           => undef,
19     maximum_risk         => undef,  # unsupported
20     path                 => undef,
21     port                 => undef,
22     require_avs          => undef,
23     result_code          => undef,
24     server               => undef,
25     server_response      => undef,
26     test_transaction     => undef,
27     transaction_type     => undef,
28     fraud_score          => undef,  # unsupported
29     fraud_transaction_id => undef,  # unsupported
30     popup_url            => undef,
31     collectitems         => undef,
32 );
33
34 sub new {
35     my($class,$processor,%data) = @_;
36
37     croak("unspecified processor") unless $processor;
38
39     my $subclass = "${class}::$processor";
40     eval "use $subclass";
41     croak("unknown processor $processor ($@)") if $@;
42
43     my $self = bless {processor => $processor}, $subclass;
44     $self->build_subs(keys %fields);
45
46     if($self->can("set_defaults")) {
47         $self->set_defaults(%data);
48     }
49
50     foreach(keys %data) {
51         my $key = lc($_);
52         my $value = $data{$_};
53         $key =~ s/^\-+//;
54         $self->build_subs($key);
55         $self->$key($value);
56     }
57
58     return $self;
59 }
60
61 sub reference {
62     my($self) = @_;
63
64     croak("Processor subclass did not override reference function");
65 }
66
67 1;
68
69 __END__
70
71 =head1 NAME
72
73 Business::OnlineThirdPartyPayment - Perl extension for third party web page based online payment processing
74
75 =head1 SYNOPSIS
76
77   use Business::OnlineThirdPartyPayment;
78
79   my $transaction =
80     new Business::OnlineThirdPartyPayment($processor, %processor_info);
81   $transaction->content(
82                         type        => 'CC',
83                         action      => 'Authorization Only',
84                         amount      => '49.95',
85                         reference   => '3735928559',
86                        );
87   $transaction->submit();
88   
89   if($transaction->is_success()) {
90     print "Success!  Redirect browser to ". $transaction->popup_url();
91   } else {
92     print "Card was rejected: ", $transaction->error_message(), "\n";
93   }
94
95   #when the provider calls us back via HTTP
96   use CGI;
97   my $cgi = new CGI;  #initialized to current page
98   
99   my $reference = $transaction->reference($cgi->Vars);
100   $transaction->content(
101                         type        => 'CC',
102                         action      => 'Post Authorization',
103                         reference   => $reference,
104                        );
105   $transaction->submit();
106   if($transaction->is_success()) {
107     print "Card processed scucessfully: ", $transaction->authorization(), "\n";
108   } else {
109     print "Card was rejected: ", $transaction->error_message(), "\n";
110   }
111
112   
113
114 =head1 DESCRIPTION
115
116 Business::OnlineThirdPartyPayment is a generic module for processing payments
117 through online credit card processors, electronic cash systems, etc. through
118 which the payors web browser is redirected.  It is a subclass of
119 L<Business::OnlinePayment>
120
121 =head1 METHODS AND FUNCTIONS
122
123 =head2 new($processor, %processor_options);
124
125 Create a new Business::OnlineThirdPartyPayment object, $processor is required,
126 and defines the online processor to use.  If necessary, processor
127 options can be specified, currently supported options are 'Server',
128 'Port', and 'Path', which specify how to find the online processor
129 (https://server:port/path), but individual processor modules should
130 supply reasonable defaults for this information, override the defaults
131 only if absolutely necessary (especially path), as the processor
132 module was probably written with a specific target script in mind.
133
134 =head2 content(%content);
135
136 The information necessary for the transaction, this tends to vary a
137 little depending on the processor, so we have chosen to use a system
138 which defines specific fields in the frontend which get mapped to the
139 correct fields in the backend.  Currently defined fields are:
140
141 =head3 PROCESSOR FIELDS
142
143 =over 4
144
145 =item * reference
146
147 A unique reference for this transaction.
148
149 =back
150
151 For additional fields, see L<Business::OnlinePayment> and the specific
152 processor module used.
153
154 =head2 submit();
155
156 Submit the transaction to the processor for completion
157
158 =head2 is_success();
159
160 Returns true if the transaction was submitted successfully, false if
161 it failed (or undef if it has not been submitted yet).
162
163 =head2 test_transaction();
164
165 Most processors provide a test mode, where submitted transactions will
166 not actually be charged or added to your batch, calling this function
167 with a true argument will turn that mode on if the processor supports
168 it, or generate a fatal error if the processor does not support a test
169 mode (which is probably better than accidentally making real charges).
170
171 =head1 AUTHOR
172
173 Jeff Finucane <business-onlinethirdpartypayment@weasellips>
174
175 =head1 COPYRIGHT
176
177 Partially based on code from Business::OnlinePayment.
178
179 Copyright (c) 1999-2004 Jason Kohles.
180 Copyright (c) 2004 Ivan Kohler
181 Copyright (c) 2007-2009 Freeside Internet Services, Inc.
182
183 All rights reserved. This program is free software; you can redistribute
184 it and/or modify it under the same terms as Perl itself.
185
186 =head1 DISCLAIMER
187
188 THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
189 WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
190 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
191
192 =head1 SEE ALSO
193
194 L<Business::OnlinePayment>, http://420.am/business-onlinepayment/
195
196 For verification of credit card checksums, see L<Business::CreditCard>.
197
198 =cut