diff options
author | ivan <ivan> | 2008-03-02 01:31:39 +0000 |
---|---|---|
committer | ivan <ivan> | 2008-03-02 01:31:39 +0000 |
commit | 53547a802d5c76be967cc14301fc8a692f0fe066 (patch) | |
tree | 54f1d62bf4b0e1cde08249798339358437fa9693 | |
parent | c21f9fadde9100aedb8c4cfc35629bc3294ba91e (diff) |
add payment gateway disabling (and move payment gateway browse over to new template)
-rw-r--r-- | FS/FS/payment_gateway.pm | 55 | ||||
-rw-r--r-- | httemplate/browse/payment_gateway.html | 147 | ||||
-rw-r--r-- | httemplate/misc/disable-payment_gateway.cgi | 25 | ||||
-rw-r--r-- | httemplate/search/elements/search.html | 4 |
4 files changed, 163 insertions, 68 deletions
diff --git a/FS/FS/payment_gateway.pm b/FS/FS/payment_gateway.pm index a5cdd9d..35b4f08 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<disabled> field to "B<Y>". + +=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 671f711..848c58a 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, + ], + ) +%> -<A HREF="<% $p %>edit/payment_gateway.html"><I>Add a new payment gateway</I></A><BR><BR> +</TABLE> -<% $cgi->param('showdisabled') - ? do { $cgi->param('showdisabled', 0); - '( <a href="'. $cgi->self_url. '">hide disabled gateways</a> )'; } - : do { $cgi->param('showdisabled', 1); - '( <a href="'. $cgi->self_url. '">show disabled gateways</a> )'; } -%> +<% include('/elements/footer.html') %> +<%once> -<% table() %> -<TR> - <TH COLSPAN=<% $cgi->param('showdisabled') ? 1 : 2 %>>#</TH> - <TH>Gateway</TH> - <TH>Username</TH> - <TH>Password</TH> - <TH>Action</TH> - <TH>Options</TH> -</TR> -% foreach my $payment_gateway ( qsearch( 'payment_gateway', \%search ) ) { - - - <TR> - <TD><% $payment_gateway->gatewaynum %></TD> -% if ( !$cgi->param('showdisabled') ) { - - <TD><% $payment_gateway->disabled ? 'DISABLED' : '' %></TD> -% } - - <TD><% $payment_gateway->gateway_module %> - <FONT SIZE="-1"> - <A HREF="<%$p%>edit/payment_gateway.html?<% $payment_gateway->gatewaynum %>">(edit)</A> - <% !$payment_gateway->disabled - ? '<A HREF="'. $p. 'misc/disable-payment_gateway.cgi?'. $payment_gateway->gatewaynum.'">(disable)</A>' - : '' - %> - </FONT> - </TD> - <TD><% $payment_gateway->gateway_username %></TD> - <TD> - </TD> - <TD><% $payment_gateway->gateway_action %></TD> - <TD> - <TABLE CELLSPACING=0 CELLPADDING=0> -% my %options = $payment_gateway->options; -% foreach my $option ( keys %options ) { -% - - <TR> - <TH><% $option %>:</TH> - <TD><% $options{$option} %></TD> - </TR> -% } - - </TABLE> - </TD> - </TR> -% } +my $html_init = qq! + <A HREF="${p}edit/payment_gateway.html"><I>Add a new payment gateway</I></A> + <BR><BR> + <SCRIPT> + function areyousure(href) { + if (confirm("Are you sure you want to disable this payment gateway?") == true) + window.location.href = href; + } + </SCRIPT> -</TABLE> +!; -<% include('/elements/footer.html') %> +my $gateway_sub = sub { + my($payment_gateway) = @_; + + my $gatewaynum = $payment_gateway->gatewaynum; + + my $html = $payment_gateway->gateway_module. ' '. qq! + <FONT SIZE="-1"> + <A HREF="${p}edit/payment_gateway.html?$gatewaynum">(edit)</A> + !; + + unless ( $payment_gateway->disabled ) { + $html .= qq! + <A HREF="javascript:areyousure('${p}misc/disable-payment_gateway.cgi?$gatewaynum')">(disable)</A> + !; + } + + $html .= '</FONT>'; + $html; + +}; + +my $options_sub = sub { + my($payment_gateway) = @_; + + #should return a structure instead of this manual formatting... + + my $html = '<TABLE CELLSPACING=0 CELLPADDING=0>'; + + my %options = $payment_gateway->options; + foreach my $option ( keys %options ) { + $html .= '<TR><TH>'. $option. ':</TH>'. + '<TD>'. $options{$option}. '</TD></TR>'; + } + $html .= '</TABLE>'; + + $html; +}; + +my $count_query = 'SELECT COUNT(*) FROM payment_gateway'; + +</%once> <%init> die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); -my %search; -if ( $cgi->param('showdisabled') ) { - %search = (); -} else { - %search = ( 'disabled' => '' ); -} - </%init> diff --git a/httemplate/misc/disable-payment_gateway.cgi b/httemplate/misc/disable-payment_gateway.cgi new file mode 100644 index 0000000..13e1f92 --- /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; + +</%init> diff --git a/httemplate/search/elements/search.html b/httemplate/search/elements/search.html index 14c6a0b..e1bc024 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.<BR> % } -% } else { +% } +% +% if ( $total || $opt{'disableable'} ) { #hmm... and there *are* ones to show?? <TABLE> <TR> |