X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fpay_batch.pm;h=b6b69f3adbd2442a3e65fde7c1dd7a3c1a2bbc91;hp=813d096b497e27663af57c4f0e4ab88b8ad466a6;hb=7516e3da0f17eeecba27219ef96a8b5f46af2083;hpb=8c450aab9bae89373c2c1b35c85597bb52299de3 diff --git a/FS/FS/pay_batch.pm b/FS/FS/pay_batch.pm index 813d096b4..b6b69f3ad 100644 --- a/FS/FS/pay_batch.pm +++ b/FS/FS/pay_batch.pm @@ -1,21 +1,19 @@ package FS::pay_batch; +use base qw( FS::Record ); use strict; -use vars qw( @ISA $DEBUG %import_info %export_info $conf ); +use vars qw( $DEBUG %import_info %export_info $conf ); +use Scalar::Util qw(blessed); +use IO::Scalar; +use List::Util qw(sum); use Time::Local; use Text::CSV_XS; -use FS::Record qw( dbh qsearch qsearchs ); -use FS::Conf; -use FS::cust_pay; -use FS::agent; use Date::Parse qw(str2time); use Business::CreditCard qw(cardtype); -use Scalar::Util 'blessed'; -use IO::Scalar; use FS::Misc qw(send_email); # for error notification -use List::Util qw(sum); - -@ISA = qw(FS::Record); +use FS::Record qw( dbh qsearch qsearchs ); +use FS::Conf; +use FS::cust_pay; =head1 NAME @@ -147,22 +145,10 @@ sub check { Returns the L object for this batch. -=cut - -sub agent { - qsearchs('agent', { 'agentnum' => $_[0]->agentnum }); -} - =item cust_pay_batch Returns all L objects for this batch. -=cut - -sub cust_pay_batch { - qsearch('cust_pay_batch', { 'batchnum' => $_[0]->batchnum }); -} - =item rebalance =cut @@ -201,7 +187,7 @@ foreach my $INC (@INC) { \\%FS::pay_batch::$mod\::export_info, \$FS::pay_batch::$mod\::name)"; $name ||= $mod; # in case it's not defined - if( $@) { + if ($@) { # in FS::cdr this is a die, not a warn. That's probably a bug. warn "error using FS::pay_batch::$mod (skipping): $@\n"; next; @@ -401,12 +387,12 @@ sub import_results { foreach ('paid', '_date', 'payinfo') { $new_cust_pay_batch->$_($hash{$_}) if $hash{$_}; } - $error = $new_cust_pay_batch->approve($hash{'paybatch'} || $self->batchnum); + $error = $new_cust_pay_batch->approve(%hash); $total += $hash{'paid'}; } elsif ( &{$declined_condition}(\%hash) ) { - $error = $new_cust_pay_batch->decline; + $error = $new_cust_pay_batch->decline($hash{'error_message'});; } @@ -450,12 +436,10 @@ sub import_results { } -use MIME::Base64; -use Storable 'thaw'; use Data::Dumper; sub process_import_results { my $job = shift; - my $param = thaw(decode_base64(shift)); + my $param = shift; $param->{'job'} = $job; warn Dumper($param) if $DEBUG; my $gatewaynum = delete $param->{'gatewaynum'}; @@ -572,8 +556,6 @@ sub import_from_gateway { my $payby; # CARD or CHEK my $error; - # follow realtime gateway practice here - # though eventually this stuff should go into separate fields... my $paybatch = $gateway->gatewaynum . '-' . $gateway->gateway_module . ':' . $item->authorization . ':' . $item->order_number; @@ -644,8 +626,11 @@ sub import_from_gateway { payby => $payby, invnum => $item->invoice_number, batchnum => $pay_batch->batchnum, - paybatch => $paybatch, payinfo => $payinfo, + gatewaynum => $gateway->gatewaynum, + processor => $gateway->gateway_module, + auth => $item->authorization, + order_number => $item->order_number, } ); $error ||= $cust_pay->insert; @@ -725,11 +710,17 @@ sub import_from_gateway { # approval status if ( $item->approved ) { # follow Billing_Realtime format for paybatch - $error = $cust_pay_batch->approve($paybatch); + $error = $cust_pay_batch->approve( + 'gatewaynum' => $gateway->gatewaynum, + 'processor' => $gateway->gateway_module, + 'auth' => $item->authorization, + 'order_number' => $item->order_number, + ); $total += $cust_pay_batch->paid; } else { - $error = $cust_pay_batch->decline($item->error_message); + $error = $cust_pay_batch->decline($item->error_message, + $item->failure_status); } if ( $error ) { @@ -807,8 +798,8 @@ sub try_to_resolve { } ); - if ( @unresolved ) { - my $days = $conf->config('batch-auto_resolve_days') || ''; + if ( @unresolved and $conf->exists('batch-auto_resolve_days') ) { + my $days = $conf->config('batch-auto_resolve_days'); # can be zero # either 'approve' or 'decline' my $action = $conf->config('batch-auto_resolve_status') || ''; return unless @@ -829,6 +820,9 @@ sub try_to_resolve { } return $error if $error; } + } elsif ( @unresolved ) { + # auto resolve is not enabled, and we're not ready to resolve + return; } $self->set_status('R'); @@ -861,6 +855,9 @@ sub prepare_for_export { return "error updating pay_batch status: $error\n" if $error; } elsif ($status eq 'I' && $curuser->access_right('Reprocess batches')) { $first_download = 0; + } elsif ($status eq 'R' && + $curuser->access_right('Redownload resolved batches')) { + $first_download = 0; } else { die "No pending batch.\n"; } @@ -934,7 +931,7 @@ sub export_batch { my $info = $export_info{$format} or die "Format not found: '$format'\n"; - &{$info->{'init'}}($conf) if exists($info->{'init'}); + &{$info->{'init'}}($conf, $self->agentnum) if exists($info->{'init'}); my $oldAutoCommit = $FS::UID::AutoCommit; local $FS::UID::AutoCommit = 0; @@ -1025,7 +1022,6 @@ sub manual_approve { my $self = shift; my $date = time; my %opt = @_; - my $paybatch = $opt{'paybatch'} || $self->batchnum; my $usernum = $opt{'usernum'} || die "manual approval requires a usernum"; my $conf = FS::Conf->new; return 'manual batch approval disabled' @@ -1055,7 +1051,9 @@ sub manual_approve { '_date' => $date, 'usernum' => $usernum, }; - my $error = $new_cust_pay_batch->approve($paybatch); + my $error = $new_cust_pay_batch->approve(); + # there are no approval options here (authorization, order_number, etc.) + # because the transaction wasn't really approved if ( $error ) { $dbh->rollback; return 'paybatchnum '.$cust_pay_batch->paybatchnum.": $error"; @@ -1080,7 +1078,7 @@ sub _upgrade_data { for my $format (keys %export_info) { my $mod = "FS::pay_batch::$format"; if ( $mod->can('_upgrade_gateway') - and length( $conf->config("batchconfig-$format") ) ) { + and $conf->exists("batchconfig-$format") ) { local $@; my ($module, %gw_options) = $mod->_upgrade_gateway; @@ -1109,7 +1107,7 @@ sub _upgrade_data { # and if appropriate, make it the system default for my $payby (qw(CARD CHEK)) { - if ( $conf->config("batch-fixed_format-$payby") eq $format ) { + if ( ($conf->config("batch-fixed_format-$payby") || '') eq $format ) { warn "Setting as default for $payby.\n"; $conf->set("batch-gateway-$payby", $gateway->gatewaynum); $conf->delete("batch-fixed_format-$payby");