1 package FS::cust_pay_void;
4 use base qw( FS::otaker_Mixin FS::payinfo_Mixin FS::Record );
5 use vars qw( @encrypted_fields $otaker_upgrade_kludge );
6 use Business::CreditCard;
7 use FS::UID qw(getotaker);
8 use FS::Record qw(qsearchs dbh fields); # qsearch );
11 #use FS::cust_bill_pay;
12 #use FS::cust_pay_refund;
16 @encrypted_fields = ('payinfo');
17 $otaker_upgrade_kludge = 0;
21 FS::cust_pay_void - Object methods for cust_pay_void objects
25 use FS::cust_pay_void;
27 $record = new FS::cust_pay_void \%hash;
28 $record = new FS::cust_pay_void { 'column' => 'value' };
30 $error = $record->insert;
32 $error = $new_record->replace($old_record);
34 $error = $record->delete;
36 $error = $record->check;
40 An FS::cust_pay_void object represents a voided payment. The following fields
41 are currently supported:
47 primary key (assigned automatically for new payments)
51 customer (see L<FS::cust_main>)
55 Amount of this payment
59 specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
60 L<Time::Local> and L<Date::Parse> for conversion functions.
64 order taker (see L<FS::access_user>)
68 `CARD' (credit cards), `CHEK' (electronic check/ACH),
69 `LECB' (phone bill billing), `BILL' (billing), `CASH' (cash),
70 `WEST' (Western Union), `MCRD' (Manual credit card), or `COMP' (free)
74 card number, check #, or comp issuer (4-8 lowercase alphanumerics; think username), respectively
78 text field for tracking card processing
82 books closed flag, empty or `Y'
86 Desired pkgnum when using experimental package balances.
100 Creates a new payment. To add the payment to the databse, see L<"insert">.
104 sub table { 'cust_pay_void'; }
108 Adds this voided payment to the database.
112 "Un-void"s this payment: Deletes the voided payment from the database and adds
113 back a normal payment.
120 local $SIG{HUP} = 'IGNORE';
121 local $SIG{INT} = 'IGNORE';
122 local $SIG{QUIT} = 'IGNORE';
123 local $SIG{TERM} = 'IGNORE';
124 local $SIG{TSTP} = 'IGNORE';
125 local $SIG{PIPE} = 'IGNORE';
127 my $oldAutoCommit = $FS::UID::AutoCommit;
128 local $FS::UID::AutoCommit = 0;
131 my $cust_pay = new FS::cust_pay ( {
132 map { $_ => $self->get($_) } fields('cust_pay')
134 my $error = $cust_pay->insert;
136 $dbh->rollback if $oldAutoCommit;
140 $error = $self->delete;
142 $dbh->rollback if $oldAutoCommit;
146 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
154 Deletes this voided payment. You probably don't want to use this directly; see
155 the B<unvoid> method to add the original payment back.
157 =item replace OLD_RECORD
159 Currently unimplemented.
164 return "Can't modify voided payments!" unless $otaker_upgrade_kludge;
165 shift->SUPER::replace(@_);
170 Checks all fields to make sure this is a valid voided payment. If there is an
171 error, returns the error, otherwise returns false. Called by the insert
180 $self->ut_numbern('paynum')
181 || $self->ut_numbern('custnum')
182 || $self->ut_money('paid')
183 || $self->ut_number('_date')
184 || $self->ut_textn('paybatch')
185 || $self->ut_enum('closed', [ '', 'Y' ])
186 || $self->ut_foreign_keyn('pkgnum', 'cust_pkg', 'pkgnum')
187 || $self->ut_numbern('void_date')
188 || $self->ut_textn('reason')
190 return $error if $error;
192 return "paid must be > 0 " if $self->paid <= 0;
194 return "unknown cust_main.custnum: ". $self->custnum
196 || qsearchs( 'cust_main', { 'custnum' => $self->custnum } );
198 $self->void_date(time) unless $self->void_date;
200 $self->payby =~ /^(CARD|CHEK|LECB|BILL|COMP|PREP|CASH|WEST|MCRD)$/
201 or return "Illegal payby";
204 #false laziness with cust_refund::check
205 if ( $self->payby eq 'CARD' ) {
206 my $payinfo = $self->payinfo;
208 $self->payinfo($payinfo);
209 if ( $self->payinfo ) {
210 $self->payinfo =~ /^(\d{13,16})$/
211 or return "Illegal (mistyped?) credit card number (payinfo)";
213 validate($self->payinfo) or return "Illegal credit card number";
214 return "Unknown card type" if cardtype($self->payinfo) eq "Unknown";
216 $self->payinfo('N/A');
220 $error = $self->ut_textn('payinfo');
221 return $error if $error;
224 $self->otaker(getotaker) unless $self->otaker;
231 Returns the parent customer object (see L<FS::cust_main>).
237 qsearchs( 'cust_main', { 'custnum' => $self->custnum } );
240 # Used by FS::Upgrade to migrate to a new database.
241 sub _upgrade_data { # class method
242 my ($class, %opts) = @_;
243 local($otaker_upgrade_kludge) = 1;
244 $class->_upgrade_otaker(%opts);
251 Delete and replace methods.
255 L<FS::cust_pay>, L<FS::Record>, schema.html from the base documentation.