Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Vend::Payment::GatewayLog
* New module facilitates adding logging support for all
  transactions through any of the standard gateway modules.

* Introduce logging support to Vend::Payment::PayflowPro.

* Fully sever database connections in Vend::Payment when
  global timeout is invoked. Code operating in production
  proved to behave unpredictably when parent and child shared
  the same database server.

* Add gateway_log table to standard in expected format for each
  DBI database type.

* Adjusted Vend::Table::DBI to support SQLite's AUTOINCREMENT
  in parallel to same support of MySQL's feature.
  • Loading branch information
msjohns1 committed Nov 4, 2017
1 parent b90cef0 commit c366818
Show file tree
Hide file tree
Showing 8 changed files with 491 additions and 33 deletions.
16 changes: 16 additions & 0 deletions dist/standard/dbconf/mysql/gateway_log.mysql
@@ -0,0 +1,16 @@
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 ''"
Database gateway_log COLUMN_DEF "email=varchar(128) not null default ''"
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
11 changes: 11 additions & 0 deletions dist/standard/dbconf/pgsql/gateway_log.pgsql
@@ -0,0 +1,11 @@
Database gateway_log gateway_log.txt __SQLDSN__

Database gateway_log DEFAULT_TYPE TEXT NOT NULL DEFAULT ''
Database gateway_log AUTO_SEQUENCE gateway_log_id_seq
Database gateway_log KEY gateway_log_id
Database gateway_log COLUMN_DEF "gateway_log_id=INTEGER PRIMARY KEY NOT NULL DEFAULT NEXTVAL('gateway_log_id_seq')"
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 NO_ASCII_INDEX 1
16 changes: 16 additions & 0 deletions dist/standard/dbconf/sqlite/gateway_log.lite
@@ -0,0 +1,16 @@
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 ''"
Database gateway_log COLUMN_DEF "email=varchar(128) not null default ''"
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
1 change: 1 addition & 0 deletions dist/standard/products/gateway_log.txt
@@ -0,0 +1 @@
gateway_log_id trans_type processor catalog result_code response_msg request_id order_number email session_id request_source request_date request_duration request response
47 changes: 27 additions & 20 deletions lib/Vend/Payment.pm
Expand Up @@ -40,7 +40,7 @@ use Vend::Order;
use IO::Pipe;
use strict;

use vars qw/$Have_LWP $Have_Net_SSLeay/;
use vars qw/$Have_LWP $Have_Net_SSLeay $Global_Timeout/;

my $pay_opt;

Expand Down Expand Up @@ -399,17 +399,24 @@ sub charge {
my $pipe = IO::Pipe->new;

unless ($pid = fork) {
Vend::Server::child_process_dbi_prep();

$pipe->writer;

Vend::Server::sever_database();
local $SIG{USR2} = sub {
$Global_Timeout = 'Global Timeout on gateway request';
exit;
};

my %rv = $sub->($pay_opt);

$pipe->print( ::uneval(\%rv) );
exit;
}
}

$pipe->reader;

my $to_msg = $pay_opt->{global_timeout_msg}
|| charge_param('global_timeout_msg')
my $to_msg = charge_param('global_timeout_msg')
|| 'Due to technical difficulties, your order could not be processed.';
local $SIG{ALRM} = sub { die "$to_msg\n" };

Expand All @@ -422,24 +429,24 @@ sub charge {
my $rv = eval join ('', $pipe->getlines);

return %$rv;
}
}

return $sub->($pay_opt);
};

if($@) {
my $msg = errmsg(
"payment routine '%s' returned error: %s",
$charge_type,
$@,
);
kill (KILL => $pid)
};

if($@) {
my $msg = errmsg(
"payment routine '%s' returned error: %s",
$charge_type,
$@,
);
kill (USR2 => $pid)
if $pid && kill (0 => $pid);
::logError($msg);
$result{MStatus} = 'died';
$result{MErrMsg} = $msg;
}
}
::logError($msg);
$result{MStatus} = 'died';
$result{MErrMsg} = $msg;
}
}
elsif($charge_type =~ /^\s*custom\s+(\w+)(?:\s+(.*))?/si) {
#::logDebug("Charge custom");
# MV4 and IC4.6.x methods
Expand Down

0 comments on commit c366818

Please sign in to comment.