[interchange/gateway_log: 3/11] Add gateway_log to PaypalExpress.pm
Mark Johnson <[email protected]> Sat, 04 Nov 2017 18:05:24 +0000
| Newsgroups | gmane.comp.web.interchange.cvs |
|---|---|
| Message-ID | <[email protected]> |
commit 31fa9f2887f9b30475d00f74e0072762d3644d26 Author: Mark Johnson <[email protected]> Date: Tue Sep 29 15:45:34 2009 -0400 Add gateway_log to PaypalExpress.pm lib/Vend/Payment/PaypalExpress.pm | 107 ++++++++++++++++++++++++++++++++++++- 1 files changed, 105 insertions(+), 2 deletions(-) --- diff --git a/lib/Vend/Payment/PaypalExpress.pm b/lib/Vend/Payment/PaypalExpress.pm index 2477d20..8a92b57 100644 --- a/lib/Vend/Payment/PaypalExpress.pm +++ b/lib/Vend/Payment/PaypalExpress.pm @@ -1258,9 +1258,26 @@ EOB if (($nonrp == '1') and ($pprequest ne 'modifyrp')) { undef $nonrp; + my $gwl = + Vend::Payment::PaypalExpress + -> new({ + order_number => $opt->{order_id}, + email => $opt->{actual}{email}, + amount => $amount, + Enabled => charge_param('gwl_enabled'), + LogTable => charge_param('gwl_table'), + }) + ; $method = SOAP::Data->name('DoExpressCheckoutPaymentReq')->attr({xmlns => $xmlns}); + + $gwl->request({ header => $header, request => $request, method => $method }); + + $gwl->start; $response = $service->call($header, $method => $request); + $gwl->stop; + %result = %{$response->valueof('//DoExpressCheckoutPaymentResponse')}; + $gwl->response(\%result); #::logDebug("PP".__LINE__.": nonRP=$nonrp; Do Ack=$result{Ack}; ppreq=$pprequest"); my ($rpAmount, $rpPeriod, $rpFrequency, $totalBillingCycles, $trialPeriod, $trialFrequency, $trialAmount, $trialTotalBillingCycles, @setrpprofile); @@ -1281,8 +1298,7 @@ EOB # 22.11.2012, v111b $result{'gift_note'} = $result{'DoExpressCheckoutPaymentResponseDetails'}{'Note'}; - - } + } else { $::Session->{'errors'}{'PaypalExpress'} = $result{'Errors'}{'LongMessage'} if ($result{'Errors'} !~ /ARRAY/); for my $i (0 .. 3) { @@ -2025,4 +2041,91 @@ sub _pplocfilter { package Vend::Payment::PaypalExpress; +use Vend::Payment::GatewayLog; +use base qw/Vend::Payment::GatewayLog/; + +sub log_it { + my $self = shift + + my $request = $self->request; + unless ($request) { + ::logDebug('Nothing to write to %s: no request present', $self->table); + return; + } + + unless ($self->response) { + + if ($Vend::Payment::Global_Timeout) { + my $msg = errmsg('No response. Global timeout triggered'); + ::logDebug($msg); + $self->response({ + Errors => { + ErrorCode => -2, + LongMessage => $Vend::Payment::Global_Timeout, + }, + }); + } + else { + my $msg = errmsg('No response. Reason unknown'); + ::logDebug($msg); + $self->response({ + Errors => { + ErrorCode => -3, + LongMessage => $msg, + }, + }); + } + } + my $response = $self->response; + + my ($rc,$resp_msg); + if ( $response->{Ack} eq 'Success' ) { + $rc = 0; + $resp_msg = $response->{Ack}; + } + else { + $rc = $response->{Errors}{ErrorCode}; + # Just in case + $rc =~ s/[^-\d]+//g + if defined $rc; + $resp_msg = $response->{Errors}{LongMessage}; + } + + $rc = -1 + unless length ($rc) && $rc =~ /\d/; + + my %fields = ( + trans_type => $response->{DoExpressCheckoutPaymentResponseDetails}{PaymentInfo}{TransactionType} || 'x', + processor => 'paypalexpress', + catalog => $Vend::Cfg->{CatalogName}, + result_code => $rc, + response_msg => $resp_msg || '', + request_id => $response->{DoExpressCheckoutPaymentResponseDetails}{PaymentInfo}{TransactionID} || '', + order_number => $self->{order_number} || '', + request_duration => $self->duration, + request_date => $self->timestamp, + email => $self->{email} || '', + request => ::uneval($request) || '', + response => ::uneval($response) || '', + session_id => $::Session->{id}, + ); + + my $hostname = `hostname -s`; + chomp $hostname; + $fields{request_source} = $hostname; + + $fields{order_md5} = + Digest::MD5::md5_hex( + $self->{email}, + $response->{DoExpressCheckoutPaymentResponseDetails}{PaymentInfo}{TransactionType}, + $::Scratch->{token}, + $self->{amount}, + $::Session->{id}, + map { ($_->{code}, $_->{quantity}) } @$Vend::Items + ) + ; + + $self->write(\%fields); +} + 1;