+sub batch_gateways {
+ my $conf = FS::Conf->new;
+ # returns a list of arrayrefs: [ gateway, payby, agentnum ]
+ my %opt = @_;
+ my @agentnums;
+ if ( $conf->exists('batch-spoolagent') ) {
+ if ( $opt{a} ) {
+ @agentnums = split(',', $opt{a});
+ } else {
+ @agentnums = map { $_->agentnum } qsearch('agent');
+ }
+ } else {
+ @agentnums = ('');
+ if ( $opt{a} ) {
+ warn "Payment batch processing skipped in per-agent mode.\n" if $DEBUG;
+ return;
+ }
+ }
+ my @return;
+ foreach my $agentnum (@agentnums) {
+ my %gateways;
+ foreach my $payby ('CARD', 'CHEK') {
+ my $gatewaynum = $conf->config("batch-gateway-$payby", $agentnum);
+ next if !$gatewaynum;
+ my $gateway = FS::payment_gateway->by_key($gatewaynum)
+ or die "payment_gateway '$gatewaynum' not found\n";
+ push @return, [ $gateway, $payby, $agentnum ];
+ }
+ }
+ @return;
+}
+