use vars qw($VERSION @ISA $me $DEBUG);
@ISA = qw(Business::OnlinePayment::HTTPS);
-$VERSION = '0.04';
+$VERSION = '0.07';
$me = 'Business::OnlinePayment::WesternACH';
$DEBUG = 0;
sub submit {
my $self = shift;
$Business::OnlinePayment::HTTPS::DEBUG = $DEBUG;
+ $DB::single = $DEBUG; # If you're debugging this, you probably want to stop here.
my $xml_request;
if ($self->{_content}->{command} eq 'get_returns') {
$xml_request = XMLout($self->build($request), KeepRoot => 1);
}
- $DB::single=1;
my ($xml_reply, $response, %reply_headers) = $self->https_post({ 'Content-Type' => 'text/xml' }, $xml_request);
if(not $response =~ /^200/) {
$self->error_message($reply->{FatalException});
}
- $DB::single = 1 if $DEBUG;
return;
}
if(exists($content->{'command'})) {
croak 'get_returns: command is already set on this transaction';
}
- if ($content->{'returns_method'} eq 'transret') {
+ if ($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) {
+ if(exists($content->{'returns'})) {
+ return @{$content->{'returns'}};
+ }
+ else {
+ return ();
+ }
+ }
+ # you need to check error_message() for details.
+ return ();
+ }
+ else {
$Business::OnlinePayment::HTTPS::DEBUG = $DEBUG;
+ $DB::single = $DEBUG;
if (defined($content->{'login'}) and defined($content->{'password'})) {
- # date range doesn't work quite right with transret
+ # transret.php doesn't respect date ranges. It returns anything from the
+ # same month as the date argument. Therefore we generate one request for
+ # each month in the date range, and then filter them by date later.
my $path = ('transret.php?style=csv&sort=id&date=');
my $starttime = str2time($self->_start);
my $endtime = str2time($self->_end) - 1;
- $DB::single=1;
my @months = map { s/^(....)(..)$/$1-$2-01/; $_ } (
time2str('%Y%m', $starttime)..time2str('%Y%m', $endtime)
);
my @tids;
foreach my $m (@months) {
$self->path($path . $m);
+ # B:OP:HTTPS::https_get doesn't use $DEBUG.
my ($page, $reply, %headers) =
$self->https_get(
{ headers => $headers },
}
else {
$self->error_message($reply);
- carp $page if $DEBUG > 1;
+ carp $reply if $DEBUG;
+ carp $page if $DEBUG >= 3;
$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:
- # id, Date Returned, Type, Amount, Name, Customer ID Number, Email Address, Invoice Number, Status Code, SEC
+ # id, Date Returned, Type, Amount, Name, Customer ID Number,
+ # Email Address, Invoice Number, Status Code, SEC
+
# 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];
croak 'login and password required';
}
}
- else {
- $content->{'command'} = 'get_returns';
- $self->submit;
- if($self->is_success) {
- if(exists($content->{'returns'})) {
- return @{$content->{'returns'}};
- }
- else {
- return ();
- }
- } else {
- # you need to check error_message() for details.
- return ();
- }
- }
}
sub build {