add Reverse Authorization support, patch from dougforpres
[Business-OnlinePayment-IPPay.git] / IPPay.pm
index bc97446..963ba5b 100644 (file)
--- a/IPPay.pm
+++ b/IPPay.pm
@@ -11,7 +11,7 @@ use Business::OnlinePayment::HTTPS;
 use vars qw($VERSION $DEBUG @ISA $me);
 
 @ISA = qw(Business::OnlinePayment::HTTPS);
-$VERSION = '0.05_01';
+$VERSION = '0.07_01';
 $VERSION = eval $VERSION; # modperlstyle: convert the string into a number
 
 $DEBUG = 0;
@@ -28,6 +28,7 @@ sub _info {
                                      'Post Authorization',
                                      'Void',
                                      'Credit',
+                                     'Reverse Authorization',
                                    ],
                                    'ECHECK' => [
                                      'Normal Authorization',
@@ -36,6 +37,7 @@ sub _info {
                                    ],
                                  },
     'CC_void_requires_card' => 1,
+    'ECHECK_void_requires_account' => 1,
   };
 }
 
@@ -88,6 +90,7 @@ sub map_fields {
       ( 'normal authorization'            => 'SALE',
         'authorization only'              => 'AUTHONLY',
         'post authorization'              => 'CAPT',
+        'reverse authorization'           => 'REVERSEAUTH',
         'void'                            => 'VOID',
         'credit'                          => 'CREDIT',
       );
@@ -188,6 +191,8 @@ sub submit {
         
   }elsif ( $action eq 'post authorization' && $type eq 'CC') {
     push @required_fields, qw( order_number );
+  }elsif ( $action eq 'reverse authorization' && $type eq 'CC') {
+    push @required_fields, qw( order_number card_number expiration amount );
   }elsif ( $action eq 'void') {
     push @required_fields, qw( order_number amount );
 
@@ -212,6 +217,14 @@ sub submit {
 
   $self->required_fields(@required_fields);
 
+  #quick validation because ippay dumps an error indecipherable to the end user
+  if (grep { /^routing_code$/ } @required_fields) {
+    unless( $content{routing_code} =~ /^\d{9}$/ ) {
+      $self->_error_response('Invalid routing code');
+      return;
+    }
+  }
+
   if ($self->test_transaction()) {
     $self->server('test1.jetpay.com');
     $self->port('443');
@@ -300,6 +313,7 @@ sub submit {
                             Phone               => 'phone',
                           );
   }
+  delete $shippingaddr{Country} unless $shippingaddr{Country};
 
   tie my %shippinginfo, 'Tie::IxHash',
     $self->revmap_fields(
@@ -353,6 +367,7 @@ sub submit {
                           IndustryInfo        => \%industryinfo,
                           ShippingInfo        => \%shippinginfo,
                         );
+  delete $req{BillingCountry} unless $req{BillingCountry};
 
   my $post_data;
   my $writer = new XML::Writer( OUTPUT      => \$post_data,
@@ -407,6 +422,17 @@ sub submit {
 
 }
 
+sub _error_response {
+  my ($self, $error_message) = (shift, shift);
+  $self->result_code('');
+  $self->order_number('');
+  $self->authorization('');
+  $self->cvv2_response('');
+  $self->avs_code('');
+  $self->is_success( 0);
+  $self->error_message($error_message);
+}
+
 sub _xmlwrite {
   my ($self, $writer, $item, $value) = @_;
   $writer->startTag($item);
@@ -499,6 +525,7 @@ The following actions are valid
 
   normal authorization
   authorization only
+  reverse authorization
   post authorization
   credit
   void
@@ -571,9 +598,13 @@ Business::OnlinePayment::IPPay uses IPPay XML Product Specifications version
 
 See http://www.ippay.com/ for more information.
 
-=head1 AUTHOR
+=head1 AUTHORS
+
+Original author: Jeff Finucane
+
+Current maintainer: Ivan Kohler <ivan-ippay@freeside.biz>
 
-Jeff Finucane, ippay@weasellips.com
+Reverse Authorization patch from dougforpres
 
 =head1 SEE ALSO