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;
14 @ISA = qw( FS::Record FS::payinfo_Mixin );
16 @encrypted_fields = ('payinfo');
20 FS::cust_pay_void - Object methods for cust_pay_void objects
24 use FS::cust_pay_void;
26 $record = new FS::cust_pay_void \%hash;
27 $record = new FS::cust_pay_void { 'column' => 'value' };
29 $error = $record->insert;
31 $error = $new_record->replace($old_record);
33 $error = $record->delete;
35 $error = $record->check;
39 An FS::cust_pay_void object represents a voided payment. The following fields
40 are currently supported:
46 primary key (assigned automatically for new payments)
50 customer (see L<FS::cust_main>)
54 Amount of this payment
58 specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
59 L<Time::Local> and L<Date::Parse> for conversion functions.
63 `CARD' (credit cards), `CHEK' (electronic check/ACH),
64 `LECB' (phone bill billing), `BILL' (billing), `CASH' (cash),
65 `WEST' (Western Union), `MCRD' (Manual credit card), or `COMP' (free)
69 card number, check #, or comp issuer (4-8 lowercase alphanumerics; think username), respectively
73 text field for tracking card processing
77 books closed flag, empty or `Y'
81 Desired pkgnum when using experimental package balances.
95 Creates a new payment. To add the payment to the databse, see L<"insert">.
99 sub table { 'cust_pay_void'; }
103 Adds this voided payment to the database.
107 "Un-void"s this payment: Deletes the voided payment from the database and adds
108 back a normal payment.
115 local $SIG{HUP} = 'IGNORE';
116 local $SIG{INT} = 'IGNORE';
117 local $SIG{QUIT} = 'IGNORE';
118 local $SIG{TERM} = 'IGNORE';
119 local $SIG{TSTP} = 'IGNORE';
120 local $SIG{PIPE} = 'IGNORE';
122 my $oldAutoCommit = $FS::UID::AutoCommit;
123 local $FS::UID::AutoCommit = 0;
126 my $cust_pay = new FS::cust_pay ( {
127 map { $_ => $self->get($_) } fields('cust_pay')
129 my $error = $cust_pay->insert;
131 $dbh->rollback if $oldAutoCommit;
135 $error = $self->delete;
137 $dbh->rollback if $oldAutoCommit;
141 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
149 Deletes this voided payment. You probably don't want to use this directly; see
150 the B<unvoid> method to add the original payment back.
152 =item replace OLD_RECORD
154 Currently unimplemented.
159 return "Can't modify voided payments!";
164 Checks all fields to make sure this is a valid voided payment. If there is an
165 error, returns the error, otherwise returns false. Called by the insert
174 $self->ut_numbern('paynum')
175 || $self->ut_numbern('custnum')
176 || $self->ut_money('paid')
177 || $self->ut_number('_date')
178 || $self->ut_textn('paybatch')
179 || $self->ut_enum('closed', [ '', 'Y' ])
180 || $self->ut_foreign_keyn('pkgnum', 'cust_pkg', 'pkgnum')
181 || $self->ut_numbern('void_date')
182 || $self->ut_textn('reason')
184 return $error if $error;
186 return "paid must be > 0 " if $self->paid <= 0;
188 return "unknown cust_main.custnum: ". $self->custnum
190 || qsearchs( 'cust_main', { 'custnum' => $self->custnum } );
192 $self->void_date(time) unless $self->void_date;
194 $self->payby =~ /^(CARD|CHEK|LECB|BILL|COMP|PREP|CASH|WEST|MCRD)$/
195 or return "Illegal payby";
198 #false laziness with cust_refund::check
199 if ( $self->payby eq 'CARD' ) {
200 my $payinfo = $self->payinfo;
202 $self->payinfo($payinfo);
203 if ( $self->payinfo ) {
204 $self->payinfo =~ /^(\d{13,16})$/
205 or return "Illegal (mistyped?) credit card number (payinfo)";
207 validate($self->payinfo) or return "Illegal credit card number";
208 return "Unknown card type" if cardtype($self->payinfo) eq "Unknown";
210 $self->payinfo('N/A');
214 $error = $self->ut_textn('payinfo');
215 return $error if $error;
218 $self->otaker(getotaker);
225 Returns the parent customer object (see L<FS::cust_main>).
231 qsearchs( 'cust_main', { 'custnum' => $self->custnum } );
238 Delete and replace methods.
242 L<FS::cust_pay>, L<FS::Record>, schema.html from the base documentation.