0.08, fix a warning
[Business-OnlinePayment-WesternACH.git] / lib / Business / OnlinePayment / WesternACH.pm
index e81f0a3..5240dab 100644 (file)
@@ -11,7 +11,7 @@ use Date::Parse  'str2time';
 use vars qw($VERSION @ISA $me $DEBUG);
 
 @ISA = qw(Business::OnlinePayment::HTTPS);
-$VERSION = '0.06';
+$VERSION = '0.08';
 $me = 'Business::OnlinePayment::WesternACH';
 
 $DEBUG = 0;
@@ -179,8 +179,9 @@ sub get_returns {
   if(exists($content->{'command'})) {
     croak 'get_returns: command is already set on this transaction';
   }
-  if ($content->{'returns_method'} eq 'requester') {
-# Obsolete, deprecated method supported for now as a fallback option.
+  if ( exists($content->{'returns_method'}) &&
+      $content->{'returns_method'} eq 'requester') {
+    # Obsolete, deprecated method supported for now as a fallback option.
     $content->{'command'} = 'get_returns';
     $self->submit;
     if($self->is_success) {
@@ -229,6 +230,7 @@ sub get_returns {
           $self->is_success(0);
           return;
         }
+        my $index_date_ret = 2; # Usual position of 'Date Returned'
         foreach my $trans (split("\cJ", $page)) {
           my @fields = split(',', $trans);
           # fields:
@@ -237,8 +239,13 @@ sub get_returns {
 
           # we only care about id and date.
           next if scalar(@fields) < 10;
+          if($fields[0] eq 'id') {
+            # Use this header row to find the 'Date Returned' field.
+            ($index_date_ret) = grep { lc($fields[$_]) eq 'date returned' } ( 0..scalar(@fields)-1 );
+            $index_date_ret ||= 2;
+          }
           next if not($fields[0] =~ /^\d+$/);
-          my $rettime = str2time($fields[1]);
+          my $rettime = str2time($fields[$index_date_ret]);
           next if (!$rettime or $rettime < $starttime or $rettime > $endtime);
           carp $trans if $DEBUG > 1;
           push @tids, $fields[0];