1 package FS::cust_pay_void;
4 use Business::CreditCard;
5 use FS::UID qw(getotaker);
6 use FS::Record qw(qsearchs dbh fields); # qsearch );
9 #use FS::cust_bill_pay;
10 #use FS::cust_pay_refund;
13 @ISA = qw( FS::Record );
17 FS::cust_pay_void - Object methods for cust_pay_void objects
21 use FS::cust_pay_void;
23 $record = new FS::cust_pay_void \%hash;
24 $record = new FS::cust_pay_void { 'column' => 'value' };
26 $error = $record->insert;
28 $error = $new_record->replace($old_record);
30 $error = $record->delete;
32 $error = $record->check;
36 An FS::cust_pay_void object represents a voided payment. The following fields
37 are currently supported:
41 =item paynum - primary key (assigned automatically for new payments)
43 =item custnum - customer (see L<FS::cust_main>)
45 =item paid - Amount of this payment
47 =item _date - specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
48 L<Time::Local> and L<Date::Parse> for conversion functions.
50 =item payby - `CARD' (credit cards), `CHEK' (electronic check/ACH),
51 `LECB' (phone bill billing), `BILL' (billing), `CASH' (cash),
52 `WEST' (Western Union), `MCRD' (Manual credit card), or `COMP' (free)
54 =item payinfo - card number, check #, or comp issuer (4-8 lowercase alphanumerics; think username), respectively
56 =item paybatch - text field for tracking card processing
58 =item closed - books closed flag, empty or `Y'
72 Creates a new payment. To add the payment to the databse, see L<"insert">.
76 sub table { 'cust_pay_void'; }
80 Adds this voided payment to the database.
84 "Un-void"s this payment: Deletes the voided payment from the database and adds
85 back a normal payment.
92 local $SIG{HUP} = 'IGNORE';
93 local $SIG{INT} = 'IGNORE';
94 local $SIG{QUIT} = 'IGNORE';
95 local $SIG{TERM} = 'IGNORE';
96 local $SIG{TSTP} = 'IGNORE';
97 local $SIG{PIPE} = 'IGNORE';
99 my $oldAutoCommit = $FS::UID::AutoCommit;
100 local $FS::UID::AutoCommit = 0;
103 my $cust_pay = new FS::cust_pay ( {
104 map { $_ => $self->get($_) } fields('cust_pay')
106 my $error = $cust_pay->insert;
108 $dbh->rollback if $oldAutoCommit;
112 $error = $self->delete;
114 $dbh->rollback if $oldAutoCommit;
118 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
126 Deletes this voided payment. You probably don't want to use this directly; see
127 the B<unvoid> method to add the original payment back.
129 =item replace OLD_RECORD
131 Currently unimplemented.
136 return "Can't modify voided payments!";
141 Checks all fields to make sure this is a valid voided payment. If there is an
142 error, returns the error, otherwise returns false. Called by the insert
151 $self->ut_numbern('paynum')
152 || $self->ut_numbern('custnum')
153 || $self->ut_money('paid')
154 || $self->ut_number('_date')
155 || $self->ut_textn('paybatch')
156 || $self->ut_enum('closed', [ '', 'Y' ])
157 || $self->ut_numbern('void_date')
158 || $self->ut_textn('reason')
160 return $error if $error;
162 return "paid must be > 0 " if $self->paid <= 0;
164 return "unknown cust_main.custnum: ". $self->custnum
166 || qsearchs( 'cust_main', { 'custnum' => $self->custnum } );
168 $self->void_date(time) unless $self->void_date;
170 $self->payby =~ /^(CARD|CHEK|LECB|BILL|COMP|PREP|CASH|WEST|MCRD)$/
171 or return "Illegal payby";
174 #false laziness with cust_refund::check
175 if ( $self->payby eq 'CARD' ) {
176 my $payinfo = $self->payinfo;
178 $self->payinfo($payinfo);
179 if ( $self->payinfo ) {
180 $self->payinfo =~ /^(\d{13,16})$/
181 or return "Illegal (mistyped?) credit card number (payinfo)";
183 validate($self->payinfo) or return "Illegal credit card number";
184 return "Unknown card type" if cardtype($self->payinfo) eq "Unknown";
186 $self->payinfo('N/A');
190 $error = $self->ut_textn('payinfo');
191 return $error if $error;
194 $self->otaker(getotaker);
201 Returns the parent customer object (see L<FS::cust_main>).
207 qsearchs( 'cust_main', { 'custnum' => $self->custnum } );
212 Returns a "masked" payinfo field with all but the last four characters replaced
213 by 'x'es. Useful for displaying credit cards.
219 my $payinfo = $self->payinfo;
220 'x'x(length($payinfo)-4). substr($payinfo,(length($payinfo)-4));
227 Delete and replace methods.
231 L<FS::cust_pay>, L<FS::Record>, schema.html from the base documentation.