SFTP transport and encryption
[Business-BatchPayment-TD_EFT.git] / TD_EFT.pm
index c33ad93..494f216 100644 (file)
--- a/TD_EFT.pm
+++ b/TD_EFT.pm
@@ -31,6 +31,14 @@ my $processor = Business::BatchPayment->processor('TD_EFT',
   return_branch   => '10202',   # 0004 + 5-digit branch number
   return_account  => '00124598951', # 11 digits
   cpa_code        => '120',
+  # optional, for SFTP file transport
+  host            => '192.168.100.1',
+  login           => 'mylogin',
+  password        => 'mypassword',
+  # optional, for encryption
+  encrypt_cmd     => 'compx ASCII DE3',
+  decrypt_cmd     => 'decompx',
+  encrypt_key     => '/path/to/encrypt.key',
 );
 
 my $result = $processor->submit(@items);
@@ -58,6 +66,32 @@ to use for returned payments.
 
 =back
 
+=head2 TRANSPORT ATTRIBUTES
+
+These need to be specified only if you're using the SFTP transport.
+
+=over 4
+
+=item host - SFTP hostname
+
+=item login - SFTP username
+
+=item password - SFTP password
+
+=item encrypt_cmd - Command to use to encrypt/compress batches before 
+sending.  This will be called, somewhat awkwardly, with the name of the 
+output file inserted as the first argument, and the name of the input 
+file (the plaintext) passed on standard input.  If empty, batches will
+be sent as plaintext.
+
+=item descrypt_cmd - Command to decrypt/decompress downloaded batches.
+
+=item encrypt_key - File to copy into the working directory before 
+running encrypt/decrypt commands.  COMPX requires the encryption key
+to be supplied like this.
+
+=back
+
 =cut
 
 use DateTime;
@@ -81,6 +115,13 @@ has 'datacentre' => (
   required => 1,
 );
 
+has [ qw( login password host encrypt_cmd encrypt_key decrypt_cmd ) ] =>
+(
+  is => 'rw',
+  isa => 'Str',
+  required => 0,
+); # only required for the default transport
+
 sub BUILD {
   my $self = shift;
   # should be a parametric string type or something
@@ -93,6 +134,21 @@ sub BUILD {
     unless length($self->return_branch) == 9;
 }
 
+sub default_transport {
+  my $self = shift;
+  Business::BatchPayment->create('TD_EFT::Transport' =>
+    login     => $self->login,
+    password  => $self->password,
+    host      => $self->host,
+    put_path  => 'APXBA807/',
+    debug     => $self->debug,
+    encrypt_cmd => $self->encrypt_cmd,
+    decrypt_cmd => $self->decrypt_cmd,
+    encrypt_key => $self->encrypt_key,
+  );
+}
+
+
 before format_request => sub {
   my ($self, $batch) = @_;
   #shazam!
@@ -372,11 +428,10 @@ use Moose::Role;
 use List::Util qw(sum);
 
 has [qw( create_date fcn )] => ( is => 'rw', isa => 'Str' );
+# XXX use the "totals" method instead
 has [qw( row total_payment total_credit count_payment count_credit )] =>
   ( is => 'rw', isa => 'Int', default => 0 );
 
-=back
-
 =head1 AUTHOR
 
 Mark Wells, C<< <mark at freeside.biz> >>