Mailing List Archive

[interchange/gateway_log: 5/11] Added new Source option.
commit 3b84966a142a7a9312f5efd33dc304583c4e3015
Author: Mark Johnson <mark@endpoint.com>
Date: Thu Dec 17 23:25:22 2009 -0500

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.

lib/Vend/Payment/AuthorizeNet.pm | 6 +---
lib/Vend/Payment/GatewayLog.pm | 54 ++++++++++++++++++++++++++++--------
lib/Vend/Payment/PayflowPro.pm | 6 +---
lib/Vend/Payment/PaypalExpress.pm | 6 +---
4 files changed, 48 insertions(+), 24 deletions(-)
---
diff --git a/lib/Vend/Payment/AuthorizeNet.pm b/lib/Vend/Payment/AuthorizeNet.pm
index 7388860..3faecc6 100644
--- a/lib/Vend/Payment/AuthorizeNet.pm
+++ b/lib/Vend/Payment/AuthorizeNet.pm
@@ -529,6 +529,7 @@ sub authorizenet {
-> new({
Enabled => charge_param('gwl_enabled'),
LogTable => charge_param('gwl_table'),
+ Source => charge_param('gwl_source'),
})
;

@@ -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},
diff --git a/lib/Vend/Payment/GatewayLog.pm b/lib/Vend/Payment/GatewayLog.pm
index 6ae2ac0..4ae80e3 100644
--- a/lib/Vend/Payment/GatewayLog.pm
+++ b/lib/Vend/Payment/GatewayLog.pm
@@ -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 {
@@ -145,6 +159,10 @@ sub _enabled {
return shift()->{_enabled};
}

+sub source {
+ return shift()->{_source};
+}
+
sub DESTROY {
my $self = shift;
return 1 unless $self->_enabled;
@@ -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

@@ -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
diff --git a/lib/Vend/Payment/PayflowPro.pm b/lib/Vend/Payment/PayflowPro.pm
index fb383c2..796136c 100644
--- a/lib/Vend/Payment/PayflowPro.pm
+++ b/lib/Vend/Payment/PayflowPro.pm
@@ -678,6 +678,7 @@ sub payflowpro {
-> new({
Enabled => charge_param('gwl_enabled'),
LogTable => charge_param('gwl_table'),
+ Source => charge_param('gwl_source'),
})
;

@@ -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},
diff --git a/lib/Vend/Payment/PaypalExpress.pm b/lib/Vend/Payment/PaypalExpress.pm
index 8a92b57..3052f6e 100644
--- a/lib/Vend/Payment/PaypalExpress.pm
+++ b/lib/Vend/Payment/PaypalExpress.pm
@@ -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});
@@ -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},

_______________________________________________
interchange-cvs mailing list
interchange-cvs@icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-cvs