From 53547a802d5c76be967cc14301fc8a692f0fe066 Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 2 Mar 2008 01:31:39 +0000 Subject: [PATCH] add payment gateway disabling (and move payment gateway browse over to new template) --- FS/FS/payment_gateway.pm | 55 ++++++++++- httemplate/browse/payment_gateway.html | 147 +++++++++++++++------------- httemplate/misc/disable-payment_gateway.cgi | 25 +++++ httemplate/search/elements/search.html | 4 +- 4 files changed, 163 insertions(+), 68 deletions(-) create mode 100644 httemplate/misc/disable-payment_gateway.cgi diff --git a/FS/FS/payment_gateway.pm b/FS/FS/payment_gateway.pm index a5cdd9d8d..35b4f0835 100644 --- a/FS/FS/payment_gateway.pm +++ b/FS/FS/payment_gateway.pm @@ -2,8 +2,9 @@ package FS::payment_gateway; use strict; use vars qw( @ISA ); -use FS::Record qw( qsearch qsearchs ); +use FS::Record qw( qsearch qsearchs dbh ); use FS::option_Common; +use FS::agent_payment_gateway; @ISA = qw( FS::option_Common ); @@ -133,6 +134,58 @@ sub check { $self->SUPER::check; } +=item agent_payment_gateway + +Returns any agent overrides for this payment gateway. + +=cut + +sub agent_payment_gateway { + my $self = shift; + qsearch('agent_payment_gateway', { 'gatewaynum' => $self->gatewaynum } ); +} + +=item disable + +Disables this payment gateway: deletes all associated agent_payment_gateway +overrides and sets the I field to "B". + +=cut + +sub disable { + my $self = shift; + + local $SIG{HUP} = 'IGNORE'; + local $SIG{INT} = 'IGNORE'; + local $SIG{QUIT} = 'IGNORE'; + local $SIG{TERM} = 'IGNORE'; + local $SIG{TSTP} = 'IGNORE'; + local $SIG{PIPE} = 'IGNORE'; + + my $oldAutoCommit = $FS::UID::AutoCommit; + local $FS::UID::AutoCommit = 0; + my $dbh = dbh; + + foreach my $agent_payment_gateway ( $self->agent_payment_gateway ) { + my $error = $agent_payment_gateway->delete; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "error deleting agent_payment_gateway override: $error"; + } + } + + $self->disabled('Y'); + my $error = $self->replace(); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "error disabling payment_gateway: $error"; + } + + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + ''; + +} + =back =head1 BUGS diff --git a/httemplate/browse/payment_gateway.html b/httemplate/browse/payment_gateway.html index 671f7118c..848c58a82 100644 --- a/httemplate/browse/payment_gateway.html +++ b/httemplate/browse/payment_gateway.html @@ -1,79 +1,94 @@ -<% include("/elements/header.html",'Payment gateways', menubar( - 'Agents' => $p. 'browse/agent.cgi', -)) %> +<% include( 'elements/browse.html', + 'title' => 'Payment gateways', + 'menubar' => [ 'Agents' => $p.'browse/agent.cgi', ], + 'html_init' => $html_init, + 'name' => 'payment gateways', + 'disableable' => 1, + 'disabled_statuspos' => 1, + 'query' => { 'table' => 'payment_gateway', + 'hashref' => {}, + }, + 'count_query' => $count_query, + 'header' => [ '#', + 'Gateway', + 'Username', + 'Password', + 'Action', + 'Options', + ], + 'fields' => [ 'gatewaynum', + $gateway_sub, + 'gateway_username', + sub { ' - '; }, + 'gateway_action', + $options_sub, + ], + ) +%> -Add a new payment gateway

+ -<% $cgi->param('showdisabled') - ? do { $cgi->param('showdisabled', 0); - '( hide disabled gateways )'; } - : do { $cgi->param('showdisabled', 1); - '( show disabled gateways )'; } -%> +<% include('/elements/footer.html') %> +<%once> -<% table() %> - - param('showdisabled') ? 1 : 2 %>># - Gateway - Username - Password - Action - Options - -% foreach my $payment_gateway ( qsearch( 'payment_gateway', \%search ) ) { - - - - <% $payment_gateway->gatewaynum %> -% if ( !$cgi->param('showdisabled') ) { - - <% $payment_gateway->disabled ? 'DISABLED' : '' %> -% } - - <% $payment_gateway->gateway_module %> - - (edit) - <% !$payment_gateway->disabled - ? '(disable)' - : '' - %> - - - <% $payment_gateway->gateway_username %> - - - <% $payment_gateway->gateway_action %> - - -% my %options = $payment_gateway->options; -% foreach my $option ( keys %options ) { -% - - - - - -% } - -
<% $option %>:<% $options{$option} %>
- - -% } +my $html_init = qq! + Add a new payment gateway +

+ - +!; -<% include('/elements/footer.html') %> +my $gateway_sub = sub { + my($payment_gateway) = @_; + + my $gatewaynum = $payment_gateway->gatewaynum; + + my $html = $payment_gateway->gateway_module. ' '. qq! + + (edit) + !; + + unless ( $payment_gateway->disabled ) { + $html .= qq! + (disable) + !; + } + + $html .= ''; + $html; + +}; + +my $options_sub = sub { + my($payment_gateway) = @_; + + #should return a structure instead of this manual formatting... + + my $html = ''; + + my %options = $payment_gateway->options; + foreach my $option ( keys %options ) { + $html .= ''. + ''; + } + $html .= '
'. $option. ':'. $options{$option}. '
'; + + $html; +}; + +my $count_query = 'SELECT COUNT(*) FROM payment_gateway'; + + <%init> die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); -my %search; -if ( $cgi->param('showdisabled') ) { - %search = (); -} else { - %search = ( 'disabled' => '' ); -} - diff --git a/httemplate/misc/disable-payment_gateway.cgi b/httemplate/misc/disable-payment_gateway.cgi new file mode 100644 index 000000000..13e1f92bc --- /dev/null +++ b/httemplate/misc/disable-payment_gateway.cgi @@ -0,0 +1,25 @@ +%if ( $error ) { +% errorpage($error); +%} else { +%#<% $cgi->redirect(popurl(2). "browse/payment_gateway.html?showdiabled=$showdisabled") %> +<% $cgi->redirect(popurl(2). "browse/payment_gateway.html") %> +%} +<%init> + +die "access deined" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + +#my $showdisabled = 0; +#$cgi->param('showdisabled') =~ /^(\d+)$/ and $showdisabled = $1; + +#$cgi->param('gatewaynum') =~ /^(\d+)$/ or die 'illegal gatewaynum'; +my($query) = $cgi->keywords; +$query =~ /^(\d+)$/ or die 'illegal gatewaynum'; +my $gatewaynum = $1; + +my $payment_gateway = + qsearchs('payment_gateway', { 'gatewaynum' => $gatewaynum } ); + +my $error = $payment_gateway->disable; + + diff --git a/httemplate/search/elements/search.html b/httemplate/search/elements/search.html index 14c6a0b6a..e1bc02450 100644 --- a/httemplate/search/elements/search.html +++ b/httemplate/search/elements/search.html @@ -319,7 +319,9 @@ Example: % unless ( $opt{'disable_nonefound'} ) { No matching <% $opt{'name'} %> found.
% } -% } else { +% } +% +% if ( $total || $opt{'disableable'} ) { #hmm... and there *are* ones to show?? -- 2.11.0