new thirdparty payment framework, #23752, #23579, #22395
[freeside.git] / FS / FS / agent.pm
index 109343a..57093e3 100644 (file)
@@ -230,7 +230,8 @@ sub ticketing_queue {
 
 Returns a payment gateway object (see L<FS::payment_gateway>) for this agent.
 
-Currently available options are I<nofatal>, I<invnum>, I<method>, and I<payinfo>.
+Currently available options are I<nofatal>, I<invnum>, I<method>, 
+I<payinfo>, and I<thirdparty>.
 
 If I<nofatal> is set, and no gateway is available, then the empty string
 will be returned instead of throwing a fatal exception.
@@ -245,10 +246,34 @@ as well.  Presently only 'CC', 'ECHECK', and 'PAYPAL' methods are meaningful.
 When the I<method> is 'CC' then the card number in I<payinfo> can direct
 this routine to route to a gateway suited for that type of card.
 
+If I<thirdparty> is set, the defined self-service payment gateway will 
+be returned.
+
 =cut
 
 sub payment_gateway {
   my ( $self, %options ) = @_;
+  
+  my $conf = new FS::Conf;
+
+  if ( $options{thirdparty} ) {
+    # still a kludge, but it gets the job done
+    # and the 'cardtype' semantics don't really apply to thirdparty
+    # gateways because we have to choose a gateway without ever 
+    # seeing the card number
+    my $gatewaynum =
+      $conf->config('selfservice-payment_gateway', $self->agentnum);
+    my $gateway = FS::payment_gateway->by_key($gatewaynum)
+      if $gatewaynum;
+
+    if ( $gateway ) {
+      return $gateway;
+    } elsif ( $options{'nofatal'} ) {
+      return '';
+    } else {
+      die "no third-party gateway configured\n";
+    }
+  }
 
   my $taxclass = '';
   if ( $options{invnum} ) {
@@ -276,8 +301,6 @@ sub payment_gateway {
       $cardtype = cardtype($options{payinfo});
     } elsif ( $options{method} eq 'ECHECK' ) {
       $cardtype = 'ACH';
-    } elsif ( $options{method} eq 'PAYPAL' ) {
-      $cardtype = 'PayPal';
     } else {
       $cardtype = $options{method}
     }
@@ -298,7 +321,6 @@ sub payment_gateway {
                                            taxclass => '',              } );
 
   my $payment_gateway;
-  my $conf = new FS::Conf;
   if ( $override ) { #use a payment gateway override
 
     $payment_gateway = $override->payment_gateway;