Mailing List Archive

[interchange] GatewayLog adjustments
commit b18828b0be4b57eb905b16ad98d359d0ab57c509
Author: Mark Johnson <mark@endpoint.com>
Date: Sat Jan 6 14:08:03 2018 -0500

GatewayLog adjustments

* Add fallback to session ID in PayflowPro

* Allow arbitrary attributes to be added to the Vend::Payment::GatewayLog
object.

* Pull email field in PaypalExpress directly from $Values; in testing,
$actual and $opt->{actual} were undefined.

* Field modifications for gateway log

+ Remove order_md5

+ Add amount, host_ip, username

+ Create cart_md5 that hashes $Vend::Items if it has any items.
Otherwise, left blank.

dist/strap/dbconf/mysql/gateway_log.mysql | 2 --
dist/strap/dbconf/sqlite/gateway_log.lite | 2 --
dist/strap/products/gateway_log.txt | 2 +-
lib/Vend/Payment/AuthorizeNet.pm | 26 +++++++++++++++-----------
lib/Vend/Payment/Braintree.pm | 26 +++++++++++++++-----------
lib/Vend/Payment/CyberSource.pm | 26 +++++++++++++++-----------
lib/Vend/Payment/GatewayLog.pm | 15 ++++++++++-----
lib/Vend/Payment/PayflowPro.pm | 26 +++++++++++++++-----------
lib/Vend/Payment/PaypalExpress.pm | 28 ++++++++++++++++------------
9 files changed, 87 insertions(+), 66 deletions(-)
---
diff --git a/dist/strap/dbconf/mysql/gateway_log.mysql b/dist/strap/dbconf/mysql/gateway_log.mysql
index e08f7e5..0f351b9 100644
--- a/dist/strap/dbconf/mysql/gateway_log.mysql
+++ b/dist/strap/dbconf/mysql/gateway_log.mysql
@@ -3,7 +3,6 @@ Database gateway_log gateway_log.txt __SQLDSN__
Database gateway_log DEFAULT_TYPE text not null default ''
Database gateway_log AUTO_SEQUENCE 1
Database gateway_log KEY gateway_log_id
-Database gateway_log COLUMN_DEF "order_md5=varchar(32) not null default ''"
Database gateway_log COLUMN_DEF "request_date=varchar(32) not null default ''"
Database gateway_log COLUMN_DEF "request_id=varchar(255) not null default ''"
Database gateway_log COLUMN_DEF "order_number=varchar(32) not null default ''"
@@ -12,5 +11,4 @@ Database gateway_log INDEX request_date
Database gateway_log INDEX request_id
Database gateway_log INDEX order_number
Database gateway_log INDEX email
-Database gateway_log INDEX order_md5
Database gateway_log NO_ASCII_INDEX 1
diff --git a/dist/strap/dbconf/sqlite/gateway_log.lite b/dist/strap/dbconf/sqlite/gateway_log.lite
index e08f7e5..0f351b9 100644
--- a/dist/strap/dbconf/sqlite/gateway_log.lite
+++ b/dist/strap/dbconf/sqlite/gateway_log.lite
@@ -3,7 +3,6 @@ Database gateway_log gateway_log.txt __SQLDSN__
Database gateway_log DEFAULT_TYPE text not null default ''
Database gateway_log AUTO_SEQUENCE 1
Database gateway_log KEY gateway_log_id
-Database gateway_log COLUMN_DEF "order_md5=varchar(32) not null default ''"
Database gateway_log COLUMN_DEF "request_date=varchar(32) not null default ''"
Database gateway_log COLUMN_DEF "request_id=varchar(255) not null default ''"
Database gateway_log COLUMN_DEF "order_number=varchar(32) not null default ''"
@@ -12,5 +11,4 @@ Database gateway_log INDEX request_date
Database gateway_log INDEX request_id
Database gateway_log INDEX order_number
Database gateway_log INDEX email
-Database gateway_log INDEX order_md5
Database gateway_log NO_ASCII_INDEX 1
diff --git a/dist/strap/products/gateway_log.txt b/dist/strap/products/gateway_log.txt
index a04a22b..e2e2a45 100644
--- a/dist/strap/products/gateway_log.txt
+++ b/dist/strap/products/gateway_log.txt
@@ -1 +1 @@
-gateway_log_id trans_type processor catalog order_md5 result_code result_subcode reason_code response_msg request_id order_number email session_id request_source request_date request_duration request response
+gateway_log_id trans_type processor catalog cart_md5 result_code result_subcode reason_code response_msg request_id order_number email amount session_id host_ip username request_source request_date request_duration request response
diff --git a/lib/Vend/Payment/AuthorizeNet.pm b/lib/Vend/Payment/AuthorizeNet.pm
index 3faecc6..22e772f 100644
--- a/lib/Vend/Payment/AuthorizeNet.pm
+++ b/lib/Vend/Payment/AuthorizeNet.pm
@@ -708,20 +708,24 @@ sub log_it {
email => $request->{x_Email} || $response->{x_email} || '',
request => ::uneval($request) || '',
response => ::uneval($response) || '',
- session_id => $::Session->{id},
+ session_id => $::Session->{id} || '',
request_source => $self->source,
+ amount => $request->{x_Amount} || '',
+ host_ip => $::Session->{shost} || $::Session->{ohost} || '',
+ username => $::Session->{username} || '',
+ cart_md5 => '',
);

- $fields{order_md5} =
- Digest::MD5::md5_hex(
- $request->{x_Email},
- $request->{x_Type},
- $request->{x_Auth_Code},
- $request->{x_Amount},
- $::Session->{id},
- map { ($_->{code}, $_->{quantity}) } @$Vend::Items
- )
- ;
+ if (@$Vend::Items) {
+ my $dump = Data::Dumper
+ -> new($Vend::Items)
+ -> Indent(0)
+ -> Terse(1)
+ -> Deepcopy(1)
+ -> Sortkeys(1)
+ ;
+ $fields{cart_md5} = Digest::MD5::md5_hex($dump->Dump);
+ }

$self->write(\%fields);
}
diff --git a/lib/Vend/Payment/Braintree.pm b/lib/Vend/Payment/Braintree.pm
index 738cdde..8561474 100644
--- a/lib/Vend/Payment/Braintree.pm
+++ b/lib/Vend/Payment/Braintree.pm
@@ -1242,19 +1242,23 @@ sub log_it {
email => $opt->{actual}{email} || '',
request => ::uneval($request) || '',
response => ::uneval($thinned_response) || '',
- session_id => $::Session->{id},
+ session_id => $::Session->{id} || '',
+ amount => $request->{args}{AMT} || $request->{args}{amount} || '',
+ host_ip => $::Session->{shost} || $::Session->{ohost} || '',
+ username => $::Session->{username} || '',
+ cart_md5 => '',
);

- $fields{order_md5} =
- Digest::MD5::md5_hex(
- $opt->{actual}{email},
- $opt->{transtype} || 'x',
- $request->{args}{ORIGID},
- $request->{args}{AMT} || $request->{args}{amount},
- $::Session->{id},
- map { ($_->{code}, $_->{quantity}) } @$Vend::Items
- )
- ;
+ if (@$Vend::Items) {
+ my $dump = Data::Dumper
+ -> new($Vend::Items)
+ -> Indent(0)
+ -> Terse(1)
+ -> Deepcopy(1)
+ -> Sortkeys(1)
+ ;
+ $fields{cart_md5} = Digest::MD5::md5_hex($dump->Dump);
+ }

$self->write(\%fields);
}
diff --git a/lib/Vend/Payment/CyberSource.pm b/lib/Vend/Payment/CyberSource.pm
index 861dab0..923ad78 100644
--- a/lib/Vend/Payment/CyberSource.pm
+++ b/lib/Vend/Payment/CyberSource.pm
@@ -2622,20 +2622,24 @@ sub log_it {
email => $request->{billTo_email} || '',
request => ::uneval($request) || '',
response => ::uneval($response) || '',
- session_id => $::Session->{id},
+ session_id => $::Session->{id} || '',
request_source => $self->source,
+ amount => $request->{purchaseTotals_grandTotalAmount} || '',
+ host_ip => $::Session->{shost} || $::Session->{ohost} || '',
+ username => $::Session->{username} || '',
+ cart_md5 => '',
);

- $fields{order_md5} =
- Digest::MD5::md5_hex(
- $request->{billTo_email},
- $self->{trans_type},
- $self->{origid},
- $request->{purchaseTotals_grandTotalAmount},
- $::Session->{id},
- map { ($_->{code}, $_->{quantity}) } @$Vend::Items
- )
- ;
+ if (@$Vend::Items) {
+ my $dump = Data::Dumper
+ -> new($Vend::Items)
+ -> Indent(0)
+ -> Terse(1)
+ -> Deepcopy(1)
+ -> Sortkeys(1)
+ ;
+ $fields{cart_md5} = Digest::MD5::md5_hex($dump->Dump);
+ }

$self->write(\%fields);
}
diff --git a/lib/Vend/Payment/GatewayLog.pm b/lib/Vend/Payment/GatewayLog.pm
index 3c9e4bb..cf7a4cc 100644
--- a/lib/Vend/Payment/GatewayLog.pm
+++ b/lib/Vend/Payment/GatewayLog.pm
@@ -9,23 +9,27 @@ sub new {
my ($class, $opt) = @_;
#::logDebug("Called in class $class, with opt hash %s", ::uneval($opt));
my $self = bless ({}, $class);
- $self->init($opt);
+ $self->init(%{$opt || {}});
$Vend::Payment::Global_Timeout = undef;
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} || '';
+ my %opt = @_;
+ $self->{_log_table} = delete ($opt{LogTable}) || 'gateway_log';
+ $self->{_enabled} = delete ($opt{Enabled}) || '';
+ $self->{_source} = delete ($opt{Source}) || '';

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

+ if (my @k = keys %opt) {
+ @$self{@k} = @opt{@k};
+ }
+
return 1;
}

@@ -120,6 +124,7 @@ sub write {
my $self = shift;
my $data = shift;

+#::logDebug('Ready to write: %s', ::uneval($data));
eval {
my $table = $self->table;
my $db = ::database_exists_ref($table)
diff --git a/lib/Vend/Payment/PayflowPro.pm b/lib/Vend/Payment/PayflowPro.pm
index 796136c..7ae64ef 100644
--- a/lib/Vend/Payment/PayflowPro.pm
+++ b/lib/Vend/Payment/PayflowPro.pm
@@ -911,20 +911,24 @@ sub log_it {
email => $request->{EMAIL} || '',
request => ::uneval($request) || '',
response => ::uneval($response) || '',
- session_id => $::Session->{id},
+ session_id => $::Session->{id} || '',
request_source => $self->source,
+ amount => $request->{AMT} || '',
+ host_ip => $::Session->{shost} || $::Session->{ohost} || '',
+ username => $::Session->{username} || '',
+ cart_md5 => '',
);

- $fields{order_md5} =
- Digest::MD5::md5_hex(
- $request->{EMAIL},
- $request->{TRXTYPE},
- $request->{ORIGID},
- $request->{AMT},
- $::Session->{id},
- map { ($_->{code}, $_->{quantity}) } @$Vend::Items
- )
- ;
+ if (@$Vend::Items) {
+ my $dump = Data::Dumper
+ -> new($Vend::Items)
+ -> Indent(0)
+ -> Terse(1)
+ -> Deepcopy(1)
+ -> Sortkeys(1)
+ ;
+ $fields{cart_md5} = Digest::MD5::md5_hex($dump->Dump);
+ }

$self->write(\%fields);
}
diff --git a/lib/Vend/Payment/PaypalExpress.pm b/lib/Vend/Payment/PaypalExpress.pm
index 10f1f47..ca709be 100644
--- a/lib/Vend/Payment/PaypalExpress.pm
+++ b/lib/Vend/Payment/PaypalExpress.pm
@@ -1262,7 +1262,7 @@ EOB
Vend::Payment::PaypalExpress
-> new({
order_number => $opt->{order_id},
- email => $opt->{actual}{email},
+ email => $::Values->{email} || '',
amount => $amount,
Enabled => charge_param('gwl_enabled'),
LogTable => charge_param('gwl_table'),
@@ -2112,20 +2112,24 @@ sub log_it {
email => $self->{email} || '',
request => ::uneval($request) || '',
response => ::uneval($response) || '',
- session_id => $::Session->{id},
+ session_id => $::Session->{id} || '',
request_source => $self->source,
+ amount => $self->{amount} || '',
+ host_ip => $::Session->{shost} || $::Session->{ohost} || '',
+ username => $::Session->{username} || '',
+ cart_md5 => '',
);

- $fields{order_md5} =
- Digest::MD5::md5_hex(
- $self->{email},
- $response->{DoExpressCheckoutPaymentResponseDetails}{PaymentInfo}{TransactionType},
- $::Scratch->{token},
- $self->{amount},
- $::Session->{id},
- map { ($_->{code}, $_->{quantity}) } @$Vend::Items
- )
- ;
+ if (@$Vend::Items) {
+ my $dump = Data::Dumper
+ -> new($Vend::Items)
+ -> Indent(0)
+ -> Terse(1)
+ -> Deepcopy(1)
+ -> Sortkeys(1)
+ ;
+ $fields{cart_md5} = Digest::MD5::md5_hex($dump->Dump);
+ }

$self->write(\%fields);
}

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