[freeside-commits] freeside/FS/bin freeside-void-payments, 1.1.2.3, 1.1.2.4
Mark Wells
mark at wavetail.420.am
Thu Sep 17 16:55:55 PDT 2009
Update of /home/cvs/cvsroot/freeside/FS/bin
In directory wavetail.420.am:/tmp/cvs-serv11935/FS/bin
Modified Files:
Tag: FREESIDE_1_7_BRANCH
freeside-void-payments
Log Message:
Add option to freeside-void-payments to cancel customers
Index: freeside-void-payments
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/bin/freeside-void-payments,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -u -d -r1.1.2.3 -r1.1.2.4
--- freeside-void-payments 23 Jul 2009 19:40:29 -0000 1.1.2.3
+++ freeside-void-payments 17 Sep 2009 23:55:53 -0000 1.1.2.4
@@ -8,13 +8,14 @@
use FS::Conf;
use FS::cust_main;
use FS::cust_pay;
+use FS::cust_pay_void;
use Business::OnlinePayment; # For retrieving the void list only.
use Time::Local;
use Date::Parse 'str2time';
use Date::Format 'time2str';
my %opt;
-getopts("r:f:ca:g:s:e:", \%opt);
+getopts("r:f:ca:g:s:e:vX:", \%opt);
$user = shift or die &usage;
&adminsuidsetup( $user );
@@ -33,6 +34,10 @@
or die "Agent has no payment gateway for method '$method'.";
}
+if(defined($opt{'X'}) and !qsearchs('reason', { reasonnum => $opt{'X'} })) {
+ die "Cancellation reason not found: '".$opt{'X'}."'";
+}
+
my ($processor, $login, $password, $action, @bop_options) =
FS::cust_main->default_payment_gateway($method);
my $gatewaynum = '';
@@ -80,20 +85,61 @@
}
$opt{'r'} ||= 'freeside-void-payments';
+my $success = 0;
+my $notfound = 0;
+my $canceled = 0;
foreach my $authnum (@auths) {
my $paybatch = $gatewaynum . $processor . ':' . $authnum;
my $cust_pay = qsearchs('cust_pay', { paybatch => $paybatch } );
+ my $error;
+ my $cancel_error;
if($cust_pay) {
- $cust_pay->void($opt{'r'});
+ $error = $cust_pay->void($opt{'r'});
+ $success++ if not $error;
+ if($opt{'X'} and not $error) {
+ $cancel_error = join(';', $cust_pay->cust_main->cancel(reason => $opt{'X'}));
+ $canceled++ if !$cancel_error;
+ }
}
else {
- warn "cust_pay record not found: '$paybatch'";
+ my $cpv = qsearchs('cust_pay_void', { paybatch => $paybatch });
+ if($cpv) {
+ $error = 'already voided '.time2str('%Y-%m-%d', $cpv->void_date).
+ ' by '.$cpv->otaker;
+ }
+ else {
+ $error = 'not found';
+ $notfound++;
+ }
+ }
+ if($opt{'v'}) {
+ print $authnum;
+ if($error) {
+ print "\t$error";
+ }
+ elsif($opt{'X'}) {
+ print "\t(canceled service)" if !$cancel_error;
+ print "\n\t(cancellation failed: $cancel_error)" if $cancel_error;
+ }
+ print "\n";
}
}
+if($opt{'v'}) {
+ print scalar(@auths)." transactions: $success voided, $notfound not found\n";
+ print "$canceled customer".($canceled == 1 ? '' : 's')." canceled\n" if $opt{'X'};
+}
+
sub usage {
- die "Usage:\n\n freeside-void-payments [ -f file | [ -s start-date ] [ -e end-date ] ] [ -r 'reason' ] [ -g gatewaynum | -a agentnum ] [ -c ] user\n";
+ die
+"Usage:
+freeside-void-payments [ -f file | [ -s start-date ] [ -e end-date ] ]
+ [ -r 'reason' ]
+ [ -g gatewaynum | -a agentnum ]
+ [ -c ] [ -v ] [ -n ]
+ [ -X reasonnum ]
+ user\n";
}
__END__
@@ -106,7 +152,12 @@
=head1 SYNOPSIS
- freeside-void-payments [ -f file | [ -s start-date ] [ -e end-date ] ] [ -r 'reason' ] [ -g gatewaynum | -a agentnum ] [ -c ] user
+ freeside-void-payments [ -f file | [ -s start-date ] [ -e end-date ] ]
+ [ -r 'reason' ]
+ [ -g gatewaynum | -a agentnum ]
+ [ -c ] [ -v ]
+ [ -X reasonnum ]
+ user
=head1 DESCRIPTION
@@ -144,6 +195,11 @@
-c: Use the default gateway for check transactions rather than
credit cards.
+
+ -v: Be verbose.
+
+ -X: Automatically cancel all packages belonging to customers whose payments
+ were returned. Requires a cancellation reasonnum (from L<FS::reason>).
A warning will be emitted for each transaction that can't be found.
This may happen if it's already been voided, or if the gateway
@@ -168,7 +224,7 @@
=head1 BUGS
-Most payment gateways don't support it, making the script largely useless.
+Most payment gateways don't support it.
=head1 SEE ALSO
More information about the freeside-commits
mailing list