From 0536726f420e8bbfd874abab32e15436807ac3d0 Mon Sep 17 00:00:00 2001 From: mark Date: Thu, 13 Aug 2009 22:07:10 +0000 Subject: [PATCH] Use new get_returns method by default --- Changes | 6 +++- lib/Business/OnlinePayment/WesternACH.pm | 51 ++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/Changes b/Changes index b97d0b1..937b5d3 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,10 @@ Revision history for Business-OnlinePayment-WesternACH -0.05 Fri Aug 8 14:25:01 PDT 2009 +0.06 Thu Aug 13 14:56:12 PDT 2009 + - Make transret.php the default returns method. + - Old method is still available via returns_method => 'requester'. + +0.05 Fri Aug 7 14:25:01 PDT 2009 - Correctly handle get_returns when there is only one transaction - Add support for alternate returns interface (transret.php) diff --git a/lib/Business/OnlinePayment/WesternACH.pm b/lib/Business/OnlinePayment/WesternACH.pm index 03a8e83..e81f0a3 100644 --- a/lib/Business/OnlinePayment/WesternACH.pm +++ b/lib/Business/OnlinePayment/WesternACH.pm @@ -11,7 +11,7 @@ use Date::Parse 'str2time'; use vars qw($VERSION @ISA $me $DEBUG); @ISA = qw(Business::OnlinePayment::HTTPS); -$VERSION = '0.05'; +$VERSION = '0.06'; $me = 'Business::OnlinePayment::WesternACH'; $DEBUG = 0; @@ -106,6 +106,7 @@ sub set_defaults { 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') { @@ -135,7 +136,6 @@ sub submit { $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/) { @@ -169,7 +169,6 @@ sub submit { $self->error_message($reply->{FatalException}); } - $DB::single = 1 if $DEBUG; return; } @@ -180,14 +179,31 @@ sub get_returns { 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) ); @@ -197,6 +213,7 @@ sub get_returns { 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 }, @@ -207,14 +224,17 @@ sub get_returns { } else { $self->error_message($reply); - carp $page if $DEBUG > 1; + carp $reply if $DEBUG; + carp $page if $DEBUG >= 3; $self->is_success(0); return; } 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; next if not($fields[0] =~ /^\d+$/); @@ -230,21 +250,6 @@ sub get_returns { 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 { -- 2.11.0