1 package Business::OnlinePayment::CardFortress;
3 use base qw( Business::OnlinePayment::HTTPS );
7 #use vars qw( $DEBUG $me );
10 use Crypt::OpenSSL::RSA;
16 'info_version' => '0.01',
17 'module_version' => $VERSION,
18 'supported_types' => [ 'CC' ],
19 'supported_actions' => { 'CC' => [
20 'Normal Authorization',
28 #need to figure out how to pass through for gateways that do... an option?
29 #'CC_void_requires_card' => 1,
37 $self->server('gw.cardfortress.com') unless $self->server;
39 $self->port('443') unless $self->port;
40 $self->path('/bop/index.html') unless $self->path;
42 $self->build_subs(qw( order_number avs_code cvv2_response
43 response_page response_code response_headers
44 card_token private_key
51 $self->server('test.cardfortress.com') if $self->test_transaction;
53 my %content = $self->content;
54 $content{$_} = $self->$_() for qw( gateway gateway_login gateway_password );
56 my ($page,$server_response,%headers) = $self->https_post(%content);
58 die "$server_response\n" unless $server_response =~ /^200/;
61 #this encoding good enough? wfm... if something's easier for other
62 #languages they can always use a different URL
63 foreach my $line ( grep /^\w+=/, split(/\n/, $page) ) {
64 $line =~ /^(\w+)=(.*)$/ or next;
68 foreach (qw( is_success error_message failure_status
69 authorization order_number
70 fraud_score fraud_transaction_id
71 result_code avs_code cvv2_response
74 $self->$_($response{$_});
77 #map these to gateway_response_code, etc?
82 #handle the challenge/response handshake
83 if ( $self->error_message eq '_challenge' ) { #XXX infinite loop protection?
85 my $private_key = $self->private_key
86 or die "no private key available";
88 $private_key = read_file($private_key)
89 if $private_key !~ /-----BEGIN/ && -r $private_key;
91 #decrypt the challenge with the private key
92 my $challenge = decode_base64($response{'card_challenge'});
94 #here is the hardest part to implement at each client side
95 my $rsa_priv = Crypt::OpenSSL::RSA->new_private_key($private_key);
96 my $response = $rsa_priv->decrypt($challenge);
98 #try the transaction again with the challenge response
99 # (B:OP could sure use a better way to alter one value)
100 my %content = $self->content;
101 $content{'card_response'} = encode_base64($response, '');
102 $self->content(%content);
114 Business::OnlinePayment::CardFortress - CardFortress backend for Business::OnlinePayment
118 use Business::OnlinePayment;
120 my $tx = new Business::OnlinePayment(
122 'gateway' => 'ProcessingGateway',
123 'gateway_login' => 'gwlogin',
124 'gateway_password' => 'gwpass',
125 #private_key not necessary
130 login => 'cardfortress_login',
131 password => 'cardfortress_pass',
132 action => 'Normal Authorization',
133 description => 'Business::OnlinePayment test',
135 customer_id => 'tfb',
136 name => 'Tofu Beast',
137 address => '123 Anystreet',
141 card_number => '4007000000027',
142 expiration => '09/02',
143 cvv2 => '1234', #optional (not stored)
147 if($tx->is_success()) {
148 print "Card processed successfully: ".$tx->authorization."\n";
149 $token = $tx->card_token;
150 print "Card token is: $token\n";
152 print "Card was rejected: ".$tx->error_message."\n";
155 # ... time slips by ...
157 my $rx = new Business::OnlinePayment(
159 'gateway' => 'ProcessingGateway',
160 'gateway_login' => 'gwlogin',
161 'gateway_password' => 'gwpass',
162 'private_key' => $private_key_string, #or filename
167 login => 'cardfortress_login',
168 password => 'cardfortress_pass',
169 action => 'Normal Authorization',
170 description => 'Business::OnlinePayment test',
172 card_token => $card_token
173 cvv2 => '1234', #optional, typically not necessary w/followup tx
179 This is a Business::OnlinePayment backend module for the gateway-independent
180 CardFortress storage service (http://cardfortress.com/).
182 =head1 SUPPORTED TRANSACTION TYPES
184 =head2 CC, Visa, MasterCard, American Express, Discover
186 Content required: type, login, action, amount, card_number, expiration.
188 =head1 METHODS AND FUNCTIONS
190 See L<Business::OnlinePayment> for the complete list. The following methods either override the methods in L<Business::OnlinePayment> or provide additional functions.
194 Returns the card token for any transaction. The card token can be used in
195 a subsequent transaction as a replacement for the card number and expiration
196 (as well as customer/AVS data).
200 Returns the response error code.
204 Returns the response error description text.
206 =head2 server_response
208 Returns the complete response from the server.
212 Ivan Kohler C<< <ivan-bop-cardfortress at freeside.biz> >>
214 =head1 COPYRIGHT & LICENSE
216 Copyright 2008-2010 Freeside Internet Services, Inc. (http://freeside.biz/)
219 This program is free software; you can redistribute it and/or modify it
220 under the same terms as Perl itself.