[freeside-commits] freeside/FS/FS cust_pay_pending.pm, 1.5, 1.6 cust_main.pm, 1.406, 1.407 AccessRight.pm, 1.34, 1.35
Ivan,,,
ivan at wavetail.420.am
Mon Feb 16 15:54:40 PST 2009
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv20615/FS/FS
Modified Files:
cust_pay_pending.pm cust_main.pm AccessRight.pm
Log Message:
add reporting on (and resolution of) stuck pending transactions, RT#4837 (RT#3572)
Index: AccessRight.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/AccessRight.pm,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- AccessRight.pm 10 Feb 2009 10:35:12 -0000 1.34
+++ AccessRight.pm 16 Feb 2009 23:54:38 -0000 1.35
@@ -152,6 +152,8 @@
'Resend invoices', #NEWNEW
'View customer tax exemptions', #yow
'View customer batched payments', #NEW
+ 'View customer pending payments', #NEW
+ 'Edit customer pending payments', #NEW
'View customer billing events', #NEW
],
Index: cust_main.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_main.pm,v
retrieving revision 1.406
retrieving revision 1.407
diff -u -d -r1.406 -r1.407
--- cust_main.pm 4 Feb 2009 15:58:36 -0000 1.406
+++ cust_main.pm 16 Feb 2009 23:54:38 -0000 1.407
@@ -3691,7 +3691,7 @@
'country' => ( exists($options{'country'})
? $options{'country'}
: $self->country ),
- 'referer' => 'http://cleanwhisker.420.am/',
+ 'referer' => 'http://cleanwhisker.420.am/', #XXX fix referer :/
'email' => $email,
'phone' => $self->daytime || $self->night,
%content, #after
@@ -3847,6 +3847,7 @@
$cust_pay_pending->status('done');
$cust_pay_pending->statustext('captured');
+ $cust_pay_pending->paynum($cust_pay->paynum);
my $cpp_done_err = $cust_pay_pending->replace;
if ( $cpp_done_err ) {
@@ -4196,7 +4197,7 @@
'password' => $password,
'order_number' => $order_number,
'amount' => $amount,
- 'referer' => 'http://cleanwhisker.420.am/',
+ 'referer' => 'http://cleanwhisker.420.am/', #XXX fix referer :/
);
$content{authorization} = $auth
if length($auth); #echeck/ACH transactions have an order # but no auth
@@ -5349,6 +5350,41 @@
qsearch( 'cust_pay_batch', { 'custnum' => $self->custnum } )
}
+=item cust_pay_pending
+
+Returns all pending payments (see L<FS::cust_pay_pending>) for this customer
+(without status "done").
+
+=cut
+
+sub cust_pay_pending {
+ my $self = shift;
+ return $self->num_cust_pay_pending unless wantarray;
+ sort { $a->_date <=> $b->_date }
+ qsearch( 'cust_pay_pending', {
+ 'custnum' => $self->custnum,
+ 'status' => { op=>'!=', value=>'done' },
+ },
+ );
+}
+
+=item num_cust_pay_pending
+
+Returns the number of pending payments (see L<FS::cust_pay_pending>) for this
+customer (without status "done"). Also called automatically when the
+cust_pay_pending method is used in a scalar context.
+
+=cut
+
+sub num_cust_pay_pending {
+ my $self = shift;
+ my $sql = " SELECT COUNT(*) FROM cust_pay_pending ".
+ " WHERE custnum = ? AND status != 'done' ";
+ my $sth = dbh->prepare($sql) or die dbh->errstr;
+ $sth->execute($self->custnum) or die $sth->errstr;
+ $sth->fetchrow_arrayref->[0];
+}
+
=item cust_refund
Returns all the refunds (see L<FS::cust_refund>) for this customer.
Index: cust_pay_pending.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_pay_pending.pm,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- cust_pay_pending.pm 30 May 2008 01:02:12 -0000 1.5
+++ cust_pay_pending.pm 16 Feb 2009 23:54:37 -0000 1.6
@@ -3,12 +3,12 @@
use strict;
use vars qw( @ISA @encrypted_fields );
use FS::Record qw( qsearch qsearchs dbh ); #dbh for _upgrade_data
-use FS::payby;
-use FS::payinfo_Mixin;
+use FS::payinfo_transaction_Mixin;
+use FS::cust_main_Mixin;
use FS::cust_main;
use FS::cust_pay;
- at ISA = qw(FS::Record FS::payinfo_Mixin);
+ at ISA = qw( FS::payinfo_transaction_Mixin FS::cust_main_Mixin FS::Record );
@encrypted_fields = ('payinfo');
@@ -215,6 +215,83 @@
$self->SUPER::check;
}
+#these two are kind-of false laziness w/cust_main::realtime_bop
+#(currently only used when resolving pending payments manually)
+
+=item insert_cust_pay
+
+Sets the status of this pending pament to "done" (with statustext
+"captured (manual)"), and inserts a payment record (see L<FS::cust_pay>).
+
+Currently only used when resolving pending payments manually.
+
+=cut
+
+sub insert_cust_pay {
+ my $self = shift;
+
+ my $cust_pay = new FS::cust_pay ( {
+ 'custnum' => $self->custnum,
+ 'paid' => $self->paid,
+ '_date' => $self->_date, #better than passing '' for now
+ 'payby' => $self->payby,
+ 'payinfo' => $self->payinfo,
+ 'paybatch' => $self->paybatch,
+ 'paydate' => $self->paydate,
+ } );
+
+ my $oldAutoCommit = $FS::UID::AutoCommit;
+ local $FS::UID::AutoCommit = 0;
+ my $dbh = dbh;
+
+ #start a transaction, insert the cust_pay and set cust_pay_pending.status to done in a single transction
+
+ my $error = $cust_pay->insert;#($options{'manual'} ? ( 'manual' => 1 ) : () );
+
+ if ( $error ) {
+ # gah.
+ $dbh->rollback or die $dbh->errstr if $oldAutoCommit;
+ return $error;
+ }
+
+ $self->status('done');
+ $self->statustext('captured (manual)');
+ $self->paynum($cust_pay->paynum);
+ my $cpp_done_err = $self->replace;
+
+ if ( $cpp_done_err ) {
+
+ $dbh->rollback or die $dbh->errstr if $oldAutoCommit;
+ return $cpp_done_err;
+
+ } else {
+
+ $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+ return ''; #no error
+
+ }
+
+}
+
+=item decline
+
+Sets the status of this pending pament to "done" (with statustext
+"declined (manual)").
+
+Currently only used when resolving pending payments manually.
+
+=cut
+
+sub decline {
+ my $self = shift;
+
+ #could send decline email too? doesn't seem useful in manual resolution
+
+ $self->status('done');
+ $self->statustext("declined (manual)");
+ $self->replace;
+}
+
# _upgrade_data
#
# Used by FS::Upgrade to migrate to a new database.
More information about the freeside-commits
mailing list