5 use Business::CreditCard;
6 use FS::Record qw( qsearchs );
9 @ISA = qw( FS::Record );
13 FS::cust_pay - Object methods for cust_pay objects
19 $record = new FS::cust_pay \%hash;
20 $record = new FS::cust_pay { 'column' => 'value' };
22 $error = $record->insert;
24 $error = $new_record->replace($old_record);
26 $error = $record->delete;
28 $error = $record->check;
32 An FS::cust_pay object represents a payment; the transfer of money from a
33 customer. FS::cust_pay inherits from FS::Record. The following fields are
38 =item paynum - primary key (assigned automatically for new payments)
40 =item invnum - Invoice (see L<FS::cust_bill>)
42 =item paid - Amount of this payment
44 =item _date - specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
45 L<Time::Local> and L<Date::Parse> for conversion functions.
47 =item payby - `CARD' (credit cards), `BILL' (billing), or `COMP' (free)
49 =item payinfo - card number, P.O.#, or comp issuer (4-8 lowercase alphanumerics; think username)
51 =item paybatch - text field for tracking card processing
61 Creates a new payment. To add the payment to the databse, see L<"insert">.
65 sub table { 'cust_pay'; }
69 Adds this payment to the databse, and updates the invoice (see
77 my $error = $self->check;
78 return $error if $error;
80 my $old_cust_bill = qsearchs( 'cust_bill', { 'invnum' => $self->invnum } );
81 return "Unknown invnum" unless $old_cust_bill;
88 Currently unimplemented (accounting reasons).
93 return "Can't (yet?) delete cust_pay records!";
96 =item replace OLD_RECORD
98 Currently unimplemented (accounting reasons).
103 return "Can't (yet?) modify cust_pay records!";
108 Checks all fields to make sure this is a valid payment. If there is an error,
109 returns the error, otherwise returns false. Called by the insert method.
119 $self->ut_numbern('paynum')
120 || $self->ut_number('invnum')
121 || $self->ut_money('paid')
122 || $self->ut_numbern('_date')
124 return $error if $error;
126 $self->_date(time) unless $self->_date;
128 $self->payby =~ /^(CARD|BILL|COMP)$/ or return "Illegal payby";
131 if ( $self->payby eq 'CARD' ) {
132 my $payinfo = $self->payinfo;
134 $self->payinfo($payinfo);
135 if ( $self->payinfo ) {
136 $self->payinfo =~ /^(\d{13,16})$/
137 or return "Illegal (mistyped?) credit card number (payinfo)";
139 validate($self->payinfo) or return "Illegal credit card number";
140 return "Unknown card type" if cardtype($self->payinfo) eq "Unknown";
142 $self->payinfo('N/A');
146 $error = $self->ut_textn('payinfo');
147 return $error if $error;
150 $error = $self->ut_textn('paybatch');
151 return $error if $error;
161 $Id: cust_pay.pm,v 1.3 2001-04-09 23:05:15 ivan Exp $
165 Delete and replace methods.
169 L<FS::Record>, L<FS::cust_bill>, schema.html from the base documentation.