X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_pay_pending.pm;h=8f313f422117a553531cb3ca4932df6410d335f1;hp=8e29f08b670e77006eeb510ffaffadb9cdb5f222;hb=5372897f367498972c96f5494e142e6e11b29eb8;hpb=3564f619654c5cbf22fc2acbe7eff0c08308e859 diff --git a/FS/FS/cust_pay_pending.pm b/FS/FS/cust_pay_pending.pm index 8e29f08b6..8f313f422 100644 --- a/FS/FS/cust_pay_pending.pm +++ b/FS/FS/cust_pay_pending.pm @@ -1,17 +1,13 @@ package FS::cust_pay_pending; +use base qw( FS::payinfo_transaction_Mixin FS::cust_main_Mixin FS::Record ); use strict; -use vars qw( @ISA @encrypted_fields ); -use FS::Record qw( qsearch qsearchs dbh ); #dbh for _upgrade_data -use FS::payinfo_transaction_Mixin; -use FS::cust_main_Mixin; -use FS::cust_main; -use FS::cust_pkg; +use vars qw( @encrypted_fields ); +use FS::Record qw( qsearchs dbh ); #dbh for _upgrade_data use FS::cust_pay; -@ISA = qw( FS::payinfo_transaction_Mixin FS::cust_main_Mixin FS::Record ); - @encrypted_fields = ('payinfo'); +sub nohistory_fields { ('payinfo'); } =head1 NAME @@ -124,6 +120,13 @@ Transaction recorded in database Additional status information. +=item failure_status + +One of the standard failure status strings defined in +L: "expired", "nsf", "stolen", "pickup", +"blacklisted", "declined". If the transaction status is not "declined", +this will be empty. + =item gatewaynum L id. @@ -132,6 +135,10 @@ L id. Payment number (L) of the completed payment. +=item void_paynum + +Payment number of the payment if it's been voided. + =item invnum Invoice number (L) to try to apply this payment to. @@ -208,24 +215,30 @@ sub check { my $error = $self->ut_numbern('paypendingnum') - || $self->ut_foreign_key('custnum', 'cust_main', 'custnum') + || $self->ut_foreign_keyn('custnum', 'cust_main', 'custnum') || $self->ut_money('paid') || $self->ut_numbern('_date') || $self->ut_textn('payunique') || $self->ut_text('status') #|| $self->ut_textn('statustext') || $self->ut_anything('statustext') + || $self->ut_textn('failure_status') #|| $self->ut_money('cust_balance') || $self->ut_hexn('session_id') || $self->ut_foreign_keyn('paynum', 'cust_pay', 'paynum' ) || $self->ut_foreign_keyn('pkgnum', 'cust_pkg', 'pkgnum') || $self->ut_foreign_keyn('invnum', 'cust_bill', 'invnum') + || $self->ut_foreign_keyn('void_paynum', 'cust_pay_void', 'paynum' ) || $self->ut_flag('manual') || $self->ut_numbern('discount_term') || $self->payinfo_check() #payby/payinfo/paymask/paydate ; return $error if $error; + if (!$self->custnum and !$self->get('custnum_pending')) { + return 'custnum required'; + } + $self->_date(time) unless $self->_date; # UNIQUE index should catch this too, without race conditions, but this @@ -251,12 +264,6 @@ Returns the associated L record if any. Otherwise returns false. =cut -sub cust_main { - my $self = shift; - qsearchs('cust_main', { custnum => $self->custnum } ); -} - - #these two are kind-of false laziness w/cust_main::realtime_bop #(currently only used when resolving pending payments manually) @@ -390,6 +397,8 @@ sub approve { warn $e; return $e; } + + $self->set('jobnum',''); } if ( $opt{'paynum_ref'} ) { @@ -425,10 +434,11 @@ sub approve { ''; } -=item decline [ STATUSTEXT ] +=item decline [ STATUSTEXT [ STATUS ] ] Sets the status of this pending payment to "done" (with statustext -"declined (manual)" unless otherwise specified). +"declined (manual)" unless otherwise specified). The optional STATUS can be +used to set the failure_status field. Currently only used when resolving pending payments manually. @@ -437,8 +447,32 @@ Currently only used when resolving pending payments manually. sub decline { my $self = shift; my $statustext = shift || "declined (manual)"; + my $failure_status = shift || ''; #could send decline email too? doesn't seem useful in manual resolution + # this is also used for thirdparty payment execution failures, but a decline + # email isn't useful there either, and will just confuse people. + + $self->status('done'); + $self->statustext($statustext); + $self->failure_status($failure_status); + $self->replace; +} + +=item reverse [ STATUSTEXT ] + +Sets the status of this pending payment to "done" (with statustext +"reversed (manual)" unless otherwise specified). + +Currently only used when resolving pending payments manually. + +=cut + +# almost complete false laziness with decline, +# but want to avoid confusion, in case any additional steps/defaults are ever added to either +sub reverse { + my $self = shift; + my $statustext = shift || "reversed (manual)"; $self->status('done'); $self->statustext($statustext); @@ -460,6 +494,29 @@ sub _upgrade_data { #class method } +sub _upgrade_schema { + my ($class, %opts) = @_; + + # fix records where jobnum points to a nonexistent queue job + my $sql = 'UPDATE cust_pay_pending SET jobnum = NULL + WHERE NOT EXISTS ( + SELECT 1 FROM queue WHERE queue.jobnum = cust_pay_pending.jobnum + )'; + my $sth = dbh->prepare($sql) or die dbh->errstr; + $sth->execute or die $sth->errstr; + + # fix records where custnum points to a nonexistent customer + $sql = 'UPDATE cust_pay_pending SET custnum = NULL + WHERE NOT EXISTS ( + SELECT 1 FROM cust_main WHERE cust_main.custnum = cust_pay_pending.custnum + )'; + $sth = dbh->prepare($sql) or die dbh->errstr; + $sth->execute or die $sth->errstr; + + + ''; +} + =back =head1 BUGS