Skip to content

Commit

Permalink
GatewayLog adjustments
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
msjohns1 committed Jan 6, 2018
1 parent 7982277 commit b18828b
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 66 deletions.
2 changes: 0 additions & 2 deletions dist/strap/dbconf/mysql/gateway_log.mysql
Expand Up @@ -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 ''"
Expand All @@ -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
2 changes: 0 additions & 2 deletions dist/strap/dbconf/sqlite/gateway_log.lite
Expand Up @@ -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 ''"
Expand All @@ -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
2 changes: 1 addition & 1 deletion 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
26 changes: 15 additions & 11 deletions lib/Vend/Payment/AuthorizeNet.pm
Expand Up @@ -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);
}
Expand Down
26 changes: 15 additions & 11 deletions lib/Vend/Payment/Braintree.pm
Expand Up @@ -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);
}
Expand Down
26 changes: 15 additions & 11 deletions lib/Vend/Payment/CyberSource.pm
Expand Up @@ -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);
}
Expand Down
15 changes: 10 additions & 5 deletions lib/Vend/Payment/GatewayLog.pm
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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)
Expand Down
26 changes: 15 additions & 11 deletions lib/Vend/Payment/PayflowPro.pm
Expand Up @@ -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);
}
Expand Down
28 changes: 16 additions & 12 deletions lib/Vend/Payment/PaypalExpress.pm
Expand Up @@ -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'),
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit b18828b

Please sign in to comment.