fix certain problems with third-party payment, #23579
[freeside.git] / FS / FS / agent.pm
index b476847..0bb7561 100644 (file)
@@ -248,8 +248,27 @@ sub payment_gateway {
     # seeing the card number
     my $gatewaynum =
       $conf->config('selfservice-payment_gateway', $self->agentnum);
-    my $gateway = FS::payment_gateway->by_key($gatewaynum)
-      if $gatewaynum;
+    my $gateway;
+    $gateway = FS::payment_gateway->by_key($gatewaynum) if $gatewaynum;
+    return $gateway if $gateway;
+
+    # a little less kludgey than the above, and allows PayPal to coexist 
+    # with credit card gateways
+    my $is_paypal = { op => '!=', value => 'PayPal' };
+    if ( uc($options{method}) eq 'PAYPAL' ) {
+      $is_paypal = 'PayPal';
+    }
+
+    $gateway = qsearchs({
+        table     => 'payment_gateway',
+        addl_from => ' JOIN agent_payment_gateway USING (gatewaynum) ',
+        hashref   => {
+          gateway_namespace => 'Business::OnlineThirdPartyPayment',
+          gateway_module    => $is_paypal,
+          disabled          => '',
+        },
+        extra_sql => ' AND agentnum = '.$self->agentnum,
+    });
 
     if ( $gateway ) {
       return $gateway;
@@ -419,6 +438,29 @@ sub cust_main_sql {
   );
 }
 
+=item num_ordered_cust_main
+
+Returns the number of ordered customers for this agent (customers with packages
+ordered, but not yet billed).
+
+=cut
+
+sub num_ordered_cust_main {
+  shift->num_sql(FS::cust_main->ordered_sql);
+}
+
+=item ordered_cust_main
+
+Returns the ordered customers for this agent (customers with packages ordered,
+but not yet billed), as cust_main objects.
+
+=cut
+
+sub ordered_cust_main {
+  shift->cust_main_sql(FS::cust_main->ordered_sql);
+}
+
+
 =item num_active_cust_main
 
 Returns the number of active customers for this agent (customers with active