Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added new Source option.
* New Source option to GatewayLog, accessed via source(), intended to set
  into the request_source field. Default sets to `hostname -s`.

* Replaced hard-coded set of request_field value from gateway modules with
  value returned from source().

* Refactored constructor to call out to init() sub for setting params passed
  in appropriately.

* Adjusted POD in GatewayLog module.
  • Loading branch information
msjohns1 committed Nov 4, 2017
1 parent 6dc4dc1 commit 3b84966
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 24 deletions.
6 changes: 2 additions & 4 deletions lib/Vend/Payment/AuthorizeNet.pm
Expand Up @@ -529,6 +529,7 @@ sub authorizenet {
-> new({
Enabled => charge_param('gwl_enabled'),
LogTable => charge_param('gwl_table'),
Source => charge_param('gwl_source'),
})
;

Expand Down Expand Up @@ -708,12 +709,9 @@ sub log_it {
request => ::uneval($request) || '',
response => ::uneval($response) || '',
session_id => $::Session->{id},
request_source => $self->source,
);

my $hostname = `hostname -s`;
chomp $hostname;
$fields{request_source} = $hostname;

$fields{order_md5} =
Digest::MD5::md5_hex(
$request->{x_Email},
Expand Down
54 changes: 42 additions & 12 deletions lib/Vend/Payment/GatewayLog.pm
Expand Up @@ -6,13 +6,27 @@ use warnings;
use Time::HiRes;

sub new {
my ($class, $self) = @_;
#::logDebug("Called in class $class, with initial hash %s", ::uneval($self));
$self = {} unless ref ($self) eq 'HASH';
$self->{_log_table} = $self->{LogTable} || 'gateway_log';
$self->{_enabled} = $self->{Enabled} || '';
my ($class, $opt) = @_;
#::logDebug("Called in class $class, with opt hash %s", ::uneval($opt));
my $self = bless ({}, $class);
$self->init($opt);
$Vend::Payment::Global_Timeout = undef;
bless ($self, $class);
return $self;
}

sub init {
my $self = shift;
my $opt = shift;
$self->{_log_table} = $opt->{LogTable} || 'gateway_log';
$self->{_enabled} = $opt->{Enabled} || '';
$self->{_source} = $opt->{Source} || '';

unless (length ($self->{_source})) {
my $host = `hostname -s`;
chomp ($self->{_source} = $host);
}

return 1;
}

sub start {
Expand Down Expand Up @@ -145,6 +159,10 @@ sub _enabled {
return shift()->{_enabled};
}

sub source {
return shift()->{_source};
}

sub DESTROY {
my $self = shift;
return 1 unless $self->_enabled;
Expand Down Expand Up @@ -224,15 +242,23 @@ Pass hashref to the constructor to include the following options:
=item Enabled
Boolean to indicate that actual logging should be performed. Default is false;
thus logging must be explicitly requested. Route indicator should be
"gwl_enabled" for consistency and so that global logging can be enabled by
setting MV_PAYMENT_GWL_ENABLED in catalog.cfg.
thus logging must be explicitly requested. Can be set in the constructor with
Route param "gwl_enabled" or globally with MV_PAYMENT_GWL_ENABLED in
catalog.cfg.
=item LogTable
Name of table to which logging should be directed. Default is gateway_log.
Route indicator should be "gwl_table" for consistency and so that a global
target table can be set through MV_PAYMENT_GWL_TABLE in catalog.cfg.
Name of table to which logging should be directed. Default is gateway_log. Can
be set in the constructor with Route param "gwl_table" or globally with
MV_PAYMENT_GWL_TABLE in catalog.cfg.
=item Source
Maps to the request_source field in the log table. Value is most meaningful in
a distributed environment, where multiple servers running the Interchange
application may be handling requests behind a load balancer. Default value
obtained from `hostname -s`. Can be set in the constructor with Route param
"gwl_source" or globally with MV_PAYMENT_GWL_SOURCE in catalog.cfg.
=back
Expand Down Expand Up @@ -317,6 +343,10 @@ Returns the name of the table against which the database update is to be
performed. Default is 'gateway_log', but can be overridden in the constructor
using the LogTable option.
=item source()
Returns the value set in the constructor for the Source option.
=back
=head1 AUTHOR
Expand Down
6 changes: 2 additions & 4 deletions lib/Vend/Payment/PayflowPro.pm
Expand Up @@ -678,6 +678,7 @@ sub payflowpro {
-> new({
Enabled => charge_param('gwl_enabled'),
LogTable => charge_param('gwl_table'),
Source => charge_param('gwl_source'),
})
;

Expand Down Expand Up @@ -911,12 +912,9 @@ sub log_it {
request => ::uneval($request) || '',
response => ::uneval($response) || '',
session_id => $::Session->{id},
request_source => $self->source,
);

my $hostname = `hostname -s`;
chomp $hostname;
$fields{request_source} = $hostname;

$fields{order_md5} =
Digest::MD5::md5_hex(
$request->{EMAIL},
Expand Down
6 changes: 2 additions & 4 deletions lib/Vend/Payment/PaypalExpress.pm
Expand Up @@ -1266,6 +1266,7 @@ EOB
amount => $amount,
Enabled => charge_param('gwl_enabled'),
LogTable => charge_param('gwl_table'),
Source => charge_param('gwl_source'),
})
;
$method = SOAP::Data->name('DoExpressCheckoutPaymentReq')->attr({xmlns => $xmlns});
Expand Down Expand Up @@ -2108,12 +2109,9 @@ sub log_it {
request => ::uneval($request) || '',
response => ::uneval($response) || '',
session_id => $::Session->{id},
request_source => $self->source,
);

my $hostname = `hostname -s`;
chomp $hostname;
$fields{request_source} = $hostname;

$fields{order_md5} =
Digest::MD5::md5_hex(
$self->{email},
Expand Down

0 comments on commit 3b84966

Please sign in to comment.