[freeside-commits] freeside/FS/FS cust_pay_batch.pm, 1.25, 1.26 pay_batch.pm, 1.32, 1.33
Mark Wells
mark at wavetail.420.am
Tue Feb 15 15:52:33 PST 2011
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv11671/FS/FS
Modified Files:
cust_pay_batch.pm pay_batch.pm
Log Message:
batch payment revocation, RT#10545
Index: pay_batch.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/pay_batch.pm,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -w -d -r1.32 -r1.33
--- pay_batch.pm 10 Feb 2011 06:08:30 -0000 1.32
+++ pay_batch.pm 15 Feb 2011 23:52:31 -0000 1.33
@@ -231,17 +231,12 @@
my $reself = $self->select_for_update;
- unless ( $reself->status eq 'I' ) {
+ if ( $reself->status ne 'I'
+ and !$conf->exists('batch-manual_approval') ) {
$dbh->rollback if $oldAutoCommit;
return "batchnum ". $self->batchnum. "no longer in transit";
}
- my $error = $self->set_status('R');
- if ( $error ) {
- $dbh->rollback if $oldAutoCommit;
- return $error;
- }
-
my $total = 0;
my $line;
@@ -396,7 +391,13 @@
$dbh->rollback;
die $@;
}
- $self->set_status('I') if !$close;
+ if ( $close ) {
+ my $error = $self->set_status('R');
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+ }
}
$dbh->commit or die $dbh->errstr if $oldAutoCommit;
@@ -538,6 +539,7 @@
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'
if ( ! $conf->exists('batch-manual_approval') );
@@ -564,6 +566,7 @@
$cust_pay_batch->hash,
'paid' => $cust_pay_batch->amount,
'_date' => $date,
+ 'usernum' => $usernum,
};
my $error = $new_cust_pay_batch->approve($paybatch);
if ( $error ) {
@@ -572,9 +575,7 @@
}
$payments++;
}
- return 'no unresolved payments in batch' if $payments == 0;
$self->set_status('R');
-
$dbh->commit;
return;
}
Index: cust_pay_batch.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_pay_batch.pm,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -w -d -r1.25 -r1.26
--- cust_pay_batch.pm 24 Dec 2010 00:40:01 -0000 1.25
+++ cust_pay_batch.pm 15 Feb 2011 23:52:31 -0000 1.26
@@ -290,6 +290,7 @@
'payinfo' => $new->payinfo || $old->payinfo,
'paid' => $new->paid,
'_date' => $new->_date,
+ 'usernum' => $new->usernum,
} );
$error = $cust_pay->insert;
if ( $error ) {
@@ -305,15 +306,36 @@
same paybatchnum, set its status to 'Declined', and run collection events
as appropriate. This should only be called from the batch import process.
-
=cut
+
sub decline {
my $new = shift;
+ my $conf = new FS::Conf;
+
my $paybatchnum = $new->paybatchnum;
my $old = qsearchs('cust_pay_batch', { paybatchnum => $paybatchnum })
or return "paybatchnum $paybatchnum not found";
- return "paybatchnum $paybatchnum already resolved ('".$old->status."')"
- if $old->status;
+ if ( $old->status ) {
+ # Handle the case where payments are rejected after the batch has been
+ # approved. Only if manual approval is enabled.
+ if ( $conf->exists('batch-manual_approval')
+ and lc($old->status) eq 'approved' ) {
+ # Void the payment
+ my $cust_pay = qsearchs('cust_pay', {
+ custnum => $new->custnum,
+ paybatch => $new->batchnum
+ });
+ if ( !$cust_pay ) {
+ # should never happen...
+ return "failed to revoke paybatchnum $paybatchnum, payment not found";
+ }
+ $cust_pay->void('Returned payment');
+ }
+ else {
+ # normal case: refuse to do anything
+ return "paybatchnum $paybatchnum already resolved ('".$old->status."')";
+ }
+ } # !$old->status
$new->status('Declined');
my $error = $new->replace($old);
if ( $error ) {
More information about the freeside-commits
mailing list