initial import
[Business-OnlinePayment-CardFortress.git] / lib / Business / OnlinePayment / CardFortress.pm
1 package Business::OnlinePayment::CardFortress;
2
3 use base qw( Business::OnlinePayment::HTTPS );
4
5 use warnings;
6 use strict;
7 #use vars qw( $DEBUG $me );
8
9 our $VERSION = 0.01;
10
11 sub _info {
12   {
13     'info_version'      => '0.01',
14     'module_version'    => $VERSION,
15     'supported_types'   => [ 'CC' ],
16     'supported_actions' => { 'CC' => [
17                                        'Normal Authorization',
18                                        'Authorization Only',
19                                        'Post Authorization',
20                                        'Void',
21                                        'Credit',
22                                      ],
23                            },
24     'token_support'     => 'challenge/response',
25     #need to figure out how to pass through for gateways that do... an option?
26     #'CC_void_requires_card' => 1,
27   };
28 }
29
30 sub set_defaults {
31   my $self = shift;
32   my %opts = @_;
33   
34   $self->server('gw.cardfortress.com') unless $self->server;
35
36   $self->port('443') unless $self->port;
37   $self->path('/bop/index.html') unless $self->path;
38
39   $self->build_subs(qw( order_number avs_code cvv2_response
40                         response_page response_code response_headers
41                         card_token
42                    ));
43 }
44
45 sub submit {
46   my $self = shift;
47
48   $self->server('test.cardfortress.com');
49
50   my ($page,$server_response,%headers) = $self->https_post($self->content);
51
52   die $server_response unless $server_response =~ /^200/;
53
54   my %response = {};
55   #this encoding good enough?  wfm... if something's easier for other
56   #languages they can always use a different URL
57   foreach my $line ( grep /^\w+=/, split(/\n/, $page) ) {
58     $line =~ /^(\w+)=(.*)$/ or next;
59     $response{$1} = $2;
60   }
61
62   foreach (qw( is_success error_message failure_status
63                authorization order_number
64                fraud_score fraud_transaction_id
65                result_code avs_code cvv2_response
66                card_token
67              )) {
68     $self->$_($response{$_});
69   }
70
71   #map these to gateway_response_code, etc?
72   # response_code()
73   # response_headers()
74   # response_page()
75
76 }
77
78 1;
79
80 __END__
81
82 =head1 NAME
83
84 Business::OnlinePayment::CardFortress - CardFortress backend for Business::OnlinePayment
85
86 =head1 SYNOPSIS
87
88   use Business::OnlinePayment;
89
90   my $tx = new Business::OnlinePayment( 'CardFortress',
91                                           'gateway' => 'ProcessingGateway',
92                                           'gateway_login' => 'gwlogin',
93                                           'gateway_password' => 'gwpass',
94                                           #private_key not necessary
95                                       );
96
97   $tx->content(
98       type           => 'VISA',
99       login          => 'cardfortress_login',
100       password       => 'cardfortress_pass',
101       action         => 'Normal Authorization',
102       description    => 'Business::OnlinePayment test',
103       amount         => '49.95',
104       customer_id    => 'tfb',
105       name           => 'Tofu Beast',
106       address        => '123 Anystreet',
107       city           => 'Anywhere',
108       state          => 'UT',
109       zip            => '84058',
110       card_number    => '4007000000027',
111       expiration     => '09/02',
112       cvv2           => '1234', #optional (not stored)
113   );
114   $tx->submit();
115
116   if($tx->is_success()) {
117       print "Card processed successfully: ".$tx->authorization."\n";
118       $token = $tx->card_token;
119       print "Card token is: $token\n";
120   } else {
121       print "Card was rejected: ".$tx->error_message."\n";
122   }
123
124   # ... time slips by ...
125
126   my $rx = new Business::OnlinePayment( 'CardFortress',
127                                           'gateway' => 'ProcessingGateway',
128                                           'gateway_login' => 'gwlogin',
129                                           'gateway_password' => 'gwpass',
130                                           'private_key' => '/path/to/keyfile',
131                                       );
132
133   $rx->content(
134       type           => 'VISA',
135       login          => 'cardfortress_login',
136       password       => 'cardfortress_pass',
137       action         => 'Normal Authorization',
138       description    => 'Business::OnlinePayment test',
139       amount         => '49.95',
140       card_token     => $card_token
141       cvv2           => '1234', #optional, typically not necessary w/followup tx
142   );
143   $rx->submit();
144
145 =head1 DESCRIPTION
146
147 This is a Business::OnlinePayment backend module for the gateway-independent
148 CardFortress storage service (http://cardfortress.com/).
149
150 =head1 SUPPORTED TRANSACTION TYPES
151
152 =head2 CC, Visa, MasterCard, American Express, Discover
153
154 Content required: type, login, action, amount, card_number, expiration.
155
156 =head1 METHODS AND FUNCTIONS
157
158 See L<Business::OnlinePayment> for the complete list. The following methods either override the methods in L<Business::OnlinePayment> or provide additional functions.  
159
160 =head2 card_token
161
162 Returns the card token for any transaction.  The card token can be used in
163 a subsequent transaction as a replacement for the card number and expiration
164 (as well as customer/AVS data).
165
166 =head2 result_code
167
168 Returns the response error code.
169
170 =head2 error_message
171
172 Returns the response error description text.
173
174 =head2 server_response
175
176 Returns the complete response from the server.
177
178 =head1 AUTHOR
179
180 Ivan Kohler C<< <ivan-bop-cardfortress at freeside.biz> >>
181
182 =head1 COPYRIGHT & LICENSE
183
184 Copyright 2008-2010 Freeside Internet Services, Inc. (http://freeside.biz/)
185 All rights reserved.
186
187 This program is free software; you can redistribute it and/or modify it
188 under the same terms as Perl itself.
189
190 =cut
191
192 1;