1 package FS::cust_pay_void;
4 use Business::CreditCard;
5 use FS::UID qw(getotaker);
6 use FS::Record qw(qsearchs); # dbh qsearch );
8 #use FS::cust_bill_pay;
9 #use FS::cust_pay_refund;
12 @ISA = qw( FS::Record );
16 FS::cust_pay_void - Object methods for cust_pay_void objects
20 use FS::cust_pay_void;
22 $record = new FS::cust_pay_void \%hash;
23 $record = new FS::cust_pay_void { 'column' => 'value' };
25 $error = $record->insert;
27 $error = $new_record->replace($old_record);
29 $error = $record->delete;
31 $error = $record->check;
35 An FS::cust_pay_void object represents a voided payment. The following fields
36 are currently supported:
40 =item paynum - primary key (assigned automatically for new payments)
42 =item custnum - customer (see L<FS::cust_main>)
44 =item paid - Amount of this payment
46 =item _date - specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
47 L<Time::Local> and L<Date::Parse> for conversion functions.
49 =item payby - `CARD' (credit cards), `CHEK' (electronic check/ACH),
50 `LECB' (phone bill billing), `BILL' (billing), `CASH' (cash),
51 `WEST' (Western Union) or `COMP' (free)
53 =item payinfo - card number, check #, or comp issuer (4-8 lowercase alphanumerics; think username), respectively
55 =item paybatch - text field for tracking card processing
57 =item closed - books closed flag, empty or `Y'
71 Creates a new payment. To add the payment to the databse, see L<"insert">.
75 sub table { 'cust_pay_void'; }
79 Adds this voided payment to the database.
83 Currently unimplemented.
88 return "Can't delete voided payments!";
91 =item replace OLD_RECORD
93 Currently unimplemented.
98 return "Can't modify voided payments!";
103 Checks all fields to make sure this is a valid voided payment. If there is an
104 error, returns the error, otherwise returns false. Called by the insert
113 $self->ut_numbern('paynum')
114 || $self->ut_numbern('custnum')
115 || $self->ut_money('paid')
116 || $self->ut_number('_date')
117 || $self->ut_textn('paybatch')
118 || $self->ut_enum('closed', [ '', 'Y' ])
119 || $self->ut_numbern('void_date')
120 || $self->ut_textn('reason')
122 return $error if $error;
124 return "paid must be > 0 " if $self->paid <= 0;
126 return "unknown cust_main.custnum: ". $self->custnum
128 || qsearchs( 'cust_main', { 'custnum' => $self->custnum } );
130 $self->void_date(time) unless $self->void_date;
132 $self->payby =~ /^(CARD|CHEK|LECB|BILL|COMP|PREP|CASH|WEST)$/
133 or return "Illegal payby";
136 #false laziness with cust_refund::check
137 if ( $self->payby eq 'CARD' ) {
138 my $payinfo = $self->payinfo;
140 $self->payinfo($payinfo);
141 if ( $self->payinfo ) {
142 $self->payinfo =~ /^(\d{13,16})$/
143 or return "Illegal (mistyped?) credit card number (payinfo)";
145 validate($self->payinfo) or return "Illegal credit card number";
146 return "Unknown card type" if cardtype($self->payinfo) eq "Unknown";
148 $self->payinfo('N/A');
152 $error = $self->ut_textn('payinfo');
153 return $error if $error;
156 $self->otaker(getotaker);
163 Returns the parent customer object (see L<FS::cust_main>).
169 qsearchs( 'cust_main', { 'custnum' => $self->custnum } );
174 Returns a "masked" payinfo field with all but the last four characters replaced
175 by 'x'es. Useful for displaying credit cards.
181 my $payinfo = $self->payinfo;
182 'x'x(length($payinfo)-4). substr($payinfo,(length($payinfo)-4));
189 Delete and replace methods.
193 L<FS::cust_pay>, L<FS::Record>, schema.html from the base documentation.