5 use Business::CreditCard;
6 use FS::Record qw( dbh );
10 @ISA = qw( FS::Record );
14 FS::cust_pay - Object methods for cust_pay objects
20 $record = new FS::cust_pay \%hash;
21 $record = new FS::cust_pay { 'column' => 'value' };
23 $error = $record->insert;
25 $error = $new_record->replace($old_record);
27 $error = $record->delete;
29 $error = $record->check;
33 An FS::cust_pay object represents a payment; the transfer of money from a
34 customer. FS::cust_pay inherits from FS::Record. The following fields are
39 =item paynum - primary key (assigned automatically for new payments)
41 =item paid - Amount of this payment
43 =item _date - specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
44 L<Time::Local> and L<Date::Parse> for conversion functions.
46 =item payby - `CARD' (credit cards), `BILL' (billing), or `COMP' (free)
48 =item payinfo - card number, P.O.#, or comp issuer (4-8 lowercase alphanumerics; think username)
50 =item paybatch - text field for tracking card processing
60 Creates a new payment. To add the payment to the databse, see L<"insert">.
64 sub table { 'cust_pay'; }
68 Adds this payment to the database.
70 For backwards-compatibility and convenience, if the additional field invnum
71 is defined, an FS::cust_bill_pay record for the full amount of the payment
79 local $SIG{HUP} = 'IGNORE';
80 local $SIG{INT} = 'IGNORE';
81 local $SIG{QUIT} = 'IGNORE';
82 local $SIG{TERM} = 'IGNORE';
83 local $SIG{TSTP} = 'IGNORE';
84 local $SIG{PIPE} = 'IGNORE';
86 my $oldAutoCommit = $FS::UID::AutoCommit;
87 local $FS::UID::AutoCommit = 0;
90 my $error = $self->check;
91 return $error if $error;
93 $error = $self->SUPER::insert;
95 $dbh->rollback if $oldAutoCommit;
99 if ( $self->invnum ) {
100 my $cust_bill_pay = new FS::cust_bill_pay {
101 'invnum' => $self->invnum,
102 'paynum' => $self->paynum,
103 'amount' => $self->paid,
104 '_date' => $self->_date,
106 $error = $cust_bill_pay->insert;
108 $dbh->rollback if $oldAutoCommit;
113 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
121 Currently unimplemented (accounting reasons).
126 return "Can't (yet?) delete cust_pay records!";
129 =item replace OLD_RECORD
131 Currently unimplemented (accounting reasons).
136 return "Can't (yet?) modify cust_pay records!";
141 Checks all fields to make sure this is a valid payment. If there is an error,
142 returns the error, otherwise returns false. Called by the insert method.
150 $self->ut_numbern('paynum')
151 || $self->ut_money('paid')
152 || $self->ut_numbern('_date')
153 || $self->ut_textn('paybatch')
155 return $error if $error;
157 $self->_date(time) unless $self->_date;
159 $self->payby =~ /^(CARD|BILL|COMP)$/ or return "Illegal payby";
162 if ( $self->payby eq 'CARD' ) {
163 my $payinfo = $self->payinfo;
165 $self->payinfo($payinfo);
166 if ( $self->payinfo ) {
167 $self->payinfo =~ /^(\d{13,16})$/
168 or return "Illegal (mistyped?) credit card number (payinfo)";
170 validate($self->payinfo) or return "Illegal credit card number";
171 return "Unknown card type" if cardtype($self->payinfo) eq "Unknown";
173 $self->payinfo('N/A');
177 $error = $self->ut_textn('payinfo');
178 return $error if $error;
189 $Id: cust_pay.pm,v 1.4 2001-09-01 20:11:07 ivan Exp $
193 Delete and replace methods.
197 L<FS::cust_bill_pay>, L<FS::cust_bill>, L<FS::Record>, schema.html from the