1 package FS::cust_pay_void;
3 use vars qw( @ISA @encrypted_fields );
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 FS::payinfo_Mixin );
15 @encrypted_fields = ('payinfo');
19 FS::cust_pay_void - Object methods for cust_pay_void objects
23 use FS::cust_pay_void;
25 $record = new FS::cust_pay_void \%hash;
26 $record = new FS::cust_pay_void { 'column' => 'value' };
28 $error = $record->insert;
30 $error = $new_record->replace($old_record);
32 $error = $record->delete;
34 $error = $record->check;
38 An FS::cust_pay_void object represents a voided payment. The following fields
39 are currently supported:
43 =item paynum - primary key (assigned automatically for new payments)
45 =item custnum - customer (see L<FS::cust_main>)
47 =item paid - Amount of this payment
49 =item _date - specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
50 L<Time::Local> and L<Date::Parse> for conversion functions.
52 =item payby - `CARD' (credit cards), `CHEK' (electronic check/ACH),
53 `LECB' (phone bill billing), `BILL' (billing), `CASH' (cash),
54 `WEST' (Western Union), `MCRD' (Manual credit card), or `COMP' (free)
56 =item payinfo - card number, check #, or comp issuer (4-8 lowercase alphanumerics; think username), respectively
58 =item paybatch - text field for tracking card processing
60 =item closed - books closed flag, empty or `Y'
74 Creates a new payment. To add the payment to the databse, see L<"insert">.
78 sub table { 'cust_pay_void'; }
82 Adds this voided payment to the database.
86 "Un-void"s this payment: Deletes the voided payment from the database and adds
87 back a normal payment.
94 local $SIG{HUP} = 'IGNORE';
95 local $SIG{INT} = 'IGNORE';
96 local $SIG{QUIT} = 'IGNORE';
97 local $SIG{TERM} = 'IGNORE';
98 local $SIG{TSTP} = 'IGNORE';
99 local $SIG{PIPE} = 'IGNORE';
101 my $oldAutoCommit = $FS::UID::AutoCommit;
102 local $FS::UID::AutoCommit = 0;
105 my $cust_pay = new FS::cust_pay ( {
106 map { $_ => $self->get($_) } fields('cust_pay')
108 my $error = $cust_pay->insert;
110 $dbh->rollback if $oldAutoCommit;
114 $error = $self->delete;
116 $dbh->rollback if $oldAutoCommit;
120 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
128 Deletes this voided payment. You probably don't want to use this directly; see
129 the B<unvoid> method to add the original payment back.
131 =item replace OLD_RECORD
133 Currently unimplemented.
138 return "Can't modify voided payments!";
143 Checks all fields to make sure this is a valid voided payment. If there is an
144 error, returns the error, otherwise returns false. Called by the insert
153 $self->ut_numbern('paynum')
154 || $self->ut_numbern('custnum')
155 || $self->ut_money('paid')
156 || $self->ut_number('_date')
157 || $self->ut_textn('paybatch')
158 || $self->ut_enum('closed', [ '', 'Y' ])
159 || $self->ut_numbern('void_date')
160 || $self->ut_textn('reason')
162 return $error if $error;
164 return "paid must be > 0 " if $self->paid <= 0;
166 return "unknown cust_main.custnum: ". $self->custnum
168 || qsearchs( 'cust_main', { 'custnum' => $self->custnum } );
170 $self->void_date(time) unless $self->void_date;
172 $self->payby =~ /^(CARD|CHEK|LECB|BILL|COMP|PREP|CASH|WEST|MCRD)$/
173 or return "Illegal payby";
176 #false laziness with cust_refund::check
177 if ( $self->payby eq 'CARD' ) {
178 my $payinfo = $self->payinfo;
180 $self->payinfo($payinfo);
181 if ( $self->payinfo ) {
182 $self->payinfo =~ /^(\d{13,16})$/
183 or return "Illegal (mistyped?) credit card number (payinfo)";
185 validate($self->payinfo) or return "Illegal credit card number";
186 return "Unknown card type" if cardtype($self->payinfo) eq "Unknown";
188 $self->payinfo('N/A');
192 $error = $self->ut_textn('payinfo');
193 return $error if $error;
196 $self->otaker(getotaker);
203 Returns the parent customer object (see L<FS::cust_main>).
209 qsearchs( 'cust_main', { 'custnum' => $self->custnum } );
216 Delete and replace methods.
220 L<FS::cust_pay>, L<FS::Record>, schema.html from the base documentation.