return txn_date
[Business-OnlinePayment-CardFortress.git] / lib / Business / OnlinePayment / CardFortress.pm
index 1946624..ea438fa 100644 (file)
@@ -5,14 +5,15 @@ use base qw( Business::OnlinePayment::HTTPS );
 use warnings;
 use strict;
 #use vars qw( $DEBUG $me );
+use File::Slurp;
 use MIME::Base64;
 use Crypt::OpenSSL::RSA;
 
-our $VERSION = 0.01;
+our $VERSION = 0.03;
 
 sub _info {
   {
-    'info_version'      => '0.01',
+    'info_compat'       => '0.01',
     'module_version'    => $VERSION,
     'supported_types'   => [ 'CC' ],
     'supported_actions' => { 'CC' => [
@@ -21,9 +22,10 @@ sub _info {
                                        'Post Authorization',
                                        'Void',
                                        'Credit',
+                                       'Tokenize',
                                      ],
                            },
-    'token_support'     => 'challenge/response',
+    'token_support'     => 1,
     #need to figure out how to pass through for gateways that do... an option?
     #'CC_void_requires_card' => 1,
   };
@@ -52,6 +54,8 @@ sub submit {
   my %content = $self->content;
   $content{$_} = $self->$_() for qw( gateway gateway_login gateway_password );
 
+  $content{$_} = $self->$_() for grep $self->can($_), qw( bop_options );
+
   my ($page,$server_response,%headers) = $self->https_post(%content);
 
   die "$server_response\n" unless $server_response =~ /^200/;
@@ -69,6 +73,7 @@ sub submit {
                fraud_score fraud_transaction_id
                result_code avs_code cvv2_response
                card_token
+               txn_date
              )) {
     $self->$_($response{$_});
   }
@@ -81,13 +86,17 @@ sub submit {
   #handle the challenge/response handshake
   if ( $self->error_message eq '_challenge' ) { #XXX infinite loop protection?
 
-    die "no private key available" unless $self->private_key;
+    my $private_key = $self->private_key
+      or die "no private key available";
+
+    $private_key = read_file($private_key)
+      if $private_key !~ /-----BEGIN/ && -r $private_key;
 
     #decrypt the challenge with the private key
     my $challenge = decode_base64($response{'card_challenge'});
 
     #here is the hardest part to implement at each client side
-    my $rsa_priv = Crypt::OpenSSL::RSA->new_private_key($self->private_key);
+    my $rsa_priv = Crypt::OpenSSL::RSA->new_private_key($private_key);
     my $response = $rsa_priv->decrypt($challenge);
 
     #try the transaction again with the challenge response
@@ -112,12 +121,13 @@ Business::OnlinePayment::CardFortress - CardFortress backend for Business::Onlin
 
   use Business::OnlinePayment;
 
-  my $tx = new Business::OnlinePayment( 'CardFortress',
-                                          'gateway' => 'ProcessingGateway',
-                                          'gateway_login' => 'gwlogin',
-                                          'gateway_password' => 'gwpass',
-                                          #private_key not necessary
-                                      );
+  my $tx = new Business::OnlinePayment(
+    'CardFortress',
+      'gateway'          => 'ProcessingGateway',
+      'gateway_login'    => 'gwlogin',
+      'gateway_password' => 'gwpass',
+      #private_key not necessary
+  );
 
   $tx->content(
       type           => 'VISA',
@@ -148,12 +158,14 @@ Business::OnlinePayment::CardFortress - CardFortress backend for Business::Onlin
 
   # ... time slips by ...
 
-  my $rx = new Business::OnlinePayment( 'CardFortress',
-                                          'gateway' => 'ProcessingGateway',
-                                          'gateway_login' => 'gwlogin',
-                                          'gateway_password' => 'gwpass',
-                                          'private_key' => $private_key_string,
-                                      );
+  my $rx = new Business::OnlinePayment(
+    'CardFortress',
+      'gateway'          => 'ProcessingGateway',
+      'gateway_login'    => 'gwlogin',
+      'gateway_password' => 'gwpass',
+      'private_key'      => $private_key_string, #or filename
+      'bop_options'      => join('/', map "$_=".$options{$_}, keys %options),
+  );
 
   $rx->content(
       type           => 'VISA',