From: ivan Date: Wed, 20 Jan 2010 18:15:13 +0000 (+0000) Subject: rework result handling: show ProcStatusMsg/StatusMsg if present even X-Git-Url: http://git.freeside.biz/gitweb/?p=Business-OnlinePayment-PaymenTech.git;a=commitdiff_plain;h=b71f13fe1086fbcbe08df22dafd56653da052e53 rework result handling: show ProcStatusMsg/StatusMsg if present even when HTTP status != 200, decode parameters like StatusMsg that come through as a hashref with Lth and content --- diff --git a/Changes b/Changes index 104f1cb..25a1d35 100644 --- a/Changes +++ b/Changes @@ -4,6 +4,8 @@ Revision history for Business-OnlinePayment-PaymenTech - doc: in synopsis example, move merchant_id/terminal_id from content call to new constructor, and add currency. also indent the example code so it formats properly + - rework result handling: show ProcStatusMsg/StatusMsg if present even + when HTTP status != 200 2.02 Wed Jan 13 18:40:06 PST 2010 - Add B:OP, B:OP:HTTPS and XML::Simple to Makefile.PL PREREQ_PM diff --git a/lib/Business/OnlinePayment/PaymenTech.pm b/lib/Business/OnlinePayment/PaymenTech.pm index 8ce9a1e..7711e10 100644 --- a/lib/Business/OnlinePayment/PaymenTech.pm +++ b/lib/Business/OnlinePayment/PaymenTech.pm @@ -8,7 +8,7 @@ use Tie::IxHash; use vars qw($VERSION $DEBUG @ISA $me); @ISA = qw(Business::OnlinePayment::HTTPS); -$VERSION = '2.03_01'; +$VERSION = '2.03_02'; $DEBUG = 0; $me='Business::OnlinePayment::PaymenTech'; @@ -102,16 +102,17 @@ sub set_defaults { $self->build_subs(qw( order_number - ProcStatus - ApprovalStatus - StatusMsg - Response - RespCode - AuthCode - AVSRespCode - CVV2RespCode - )); - + )); + + #leaking gateway-specific anmes? need to be mapped to B:OP standards :) + # ProcStatus + # ApprovalStatus + # StatusMsg + # RespCode + # AuthCode + # AVSRespCode + # CVV2RespCode + # Response } sub build { @@ -238,42 +239,69 @@ sub submit { warn $page if $DEBUG; - my $response; - my $error = ''; - if ($server_response =~ /200/){ - $response = XMLin($page, KeepRoot => 0); - $self->Response($response); - my ($r) = values(%$response); - foreach(qw(ProcStatus RespCode AuthCode AVSRespCode CVV2RespCode)) { - if(exists($r->{$_}) and - !ref($r->{$_})) { - $self->$_($r->{$_}); - } - } - if(!exists($r->{'ProcStatus'})) { - $error = "Malformed response: '$page'"; + my $response = XMLin($page, KeepRoot => 0); + #$self->Response($response); + + #use Data::Dumper; + #warn Dumper($response) if $DEBUG; + + my ($r) = values(%$response); + #foreach(qw(ProcStatus RespCode AuthCode AVSRespCode CVV2RespCode)) { + # if(exists($r->{$_}) and + # !ref($r->{$_})) { + # $self->$_($r->{$_}); + # } + #} + + foreach (keys %$r) { + + #turn empty hashrefs into the empty string + $r->{$_} = '' if ref($r->{$_}) && ! keys %{ $r->{$_} }; + + #turn hashrefs with content into scalars + $r->{$_} = $r->{$_}{'content'} + if ref($r->{$_}) && exists($r->{$_}{'content'}); + } + + if ($server_response !~ /^200/) { + + $self->is_success(0); + my $error = "Server error: '$server_response'"; + $error .= " / Transaction error: '". + ($r->{'ProcStatusMsg'} || $r->{'StatusMsg'}) . "'" + if $r->{'ProcStatus'} != 0; + $self->error_message($error); + + } else { + + if ( !exists($r->{'ProcStatus'}) ) { + $self->is_success(0); - } - elsif( $r->{'ProcStatus'} != 0 or - # NewOrders get ApprovalStatus, Reversals don't. - ( exists($r->{'ApprovalStatus'}) ? - $r->{'ApprovalStatus'} != 1 : - $r->{'StatusMsg'} ne 'Approved' ) - ) { - $error = "Transaction error: '". ($r->{'ProcStatusMsg'} || $r->{'StatusMsg'}) . "'"; + $self->error_message( "Malformed response: '$page'" ); + + } elsif ( $r->{'ProcStatus'} != 0 or + # NewOrders get ApprovalStatus, Reversals don't. + ( exists($r->{'ApprovalStatus'}) ? + $r->{'ApprovalStatus'} != 1 : + $r->{'StatusMsg'} ne 'Approved' ) + ) + { + $self->is_success(0); - } - else { - # success! + $self->error_message( "Transaction error: '". + ($r->{'ProcStatusMsg'} || $r->{'StatusMsg'}) . "'" + ); + + } else { # success! + $self->is_success(1); # For credits, AuthCode is empty and gets converted to a hashref. $self->authorization($r->{'AuthCode'}) if !ref($r->{'AuthCode'}); $self->order_number($r->{'TxRefNum'}); } - } else { - $error = "Server error: '$server_response'"; + } - $self->error_message($error); + } 1; @@ -313,9 +341,9 @@ Business::OnlinePayment::PaymenTech - Chase Paymentech backend for Business::Onl =head1 NOTES -The only supported transaction types are Normal Authorization and Credit. Paymentech -supports separate Authorize and Capture actions as well as recurring billing, but -those are not yet implemented. +The only supported transaction types are Normal Authorization and Credit. +Paymentech supports separate Authorize and Capture actions as well as recurring +billing, but those are not yet implemented. Electronic check processing is not yet supported.