ACL for hardware class config, RT#85057
[freeside.git] / FS / FS / agent.pm
index b97e9b9..8aff96a 100644 (file)
@@ -239,8 +239,7 @@ sub ticketing_queue {
 
 Returns a payment gateway object (see L<FS::payment_gateway>) for this agent.
 
-Currently available options are I<nofatal>, I<method>, I<thirdparty>,
-<conf> and I<load_gatewaynum>.
+Currently available options are I<nofatal>, I<method>, I<thirdparty> and I<conf>.
 
 If I<nofatal> is set, and no gateway is available, then the empty string
 will be returned instead of throwing a fatal exception.
@@ -295,7 +294,15 @@ sub payment_gateway {
     }
   }
 
-  my $override = qsearchs('agent_payment_gateway', { agentnum => $self->agentnum } );
+  my $cardtype_search = "AND ( cardtype IS NULL OR cardtype <> 'ACH')";
+  $cardtype_search = "AND ( cardtype IS NULL OR cardtype = 'ACH' )" if $options{method} eq 'ECHECK';
+
+  my $override =
+      qsearchs({
+        "table" => 'agent_payment_gateway',
+        "hashref" => { agentnum => $self->agentnum, },
+        "extra_sql" => $cardtype_search,
+      });
 
   my $payment_gateway = FS::payment_gateway->by_key_or_default(
     gatewaynum => $override ? $override->gatewaynum : '',