1 package FS::cust_pay_pending;
4 use vars qw( @ISA @encrypted_fields );
5 use FS::Record qw( qsearch qsearchs );
11 @ISA = qw(FS::Record FS::payinfo_Mixin);
13 @encrypted_fields = ('payinfo');
17 FS::cust_pay_pending - Object methods for cust_pay_pending records
21 use FS::cust_pay_pending;
23 $record = new FS::cust_pay_pending \%hash;
24 $record = new FS::cust_pay_pending { 'column' => 'value' };
26 $error = $record->insert;
28 $error = $new_record->replace($old_record);
30 $error = $record->delete;
32 $error = $record->check;
36 An FS::cust_pay_pending object represents an pending payment. It reflects
37 local state through the multiple stages of processing a real-time transaction
38 with an external gateway. FS::cust_pay_pending inherits from FS::Record. The
39 following fields are currently supported:
43 =item paypendingnum - primary key
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 - Payment Type (See L<FS::payinfo_Mixin> for valid payby values)
54 =item payinfo - Payment Information (See L<FS::payinfo_Mixin> for data format)
56 =item paymask - Masked payinfo (See L<FS::payinfo_Mixin> for how this works)
58 =item paydate - Expiration date
60 =item payunique - Unique identifer to prevent duplicate transactions.
62 =item status - new (acquires basic lock on payunique), pending (transaction is pending with the gateway), authorized (only used for two-stage transactions that require a separate capture step), captured/declined (transaction completed with payment gateway, not yet recorded in the database), done (transaction recorded in database)
81 Creates a new pending payment. To add the pending payment to the database, see L<"insert">.
83 Note that this stores the hash reference, not a distinct copy of the hash it
84 points to. You can ask the object for a copy with the I<hash> method.
88 # the new method can be inherited from FS::Record, if a table method is defined
90 sub table { 'cust_pay_pending'; }
94 Adds this record to the database. If there is an error, returns the error,
95 otherwise returns false.
99 # the insert method can be inherited from FS::Record
103 Delete this record from the database.
107 # the delete method can be inherited from FS::Record
109 =item replace OLD_RECORD
111 Replaces the OLD_RECORD with this one in the database. If there is an error,
112 returns the error, otherwise returns false.
116 # the replace method can be inherited from FS::Record
120 Checks all fields to make sure this is a valid pending payment. If there is
121 an error, returns the error, otherwise returns false. Called by the insert
126 # the check method should currently be supplied - FS::Record contains some
127 # data checking routines
133 $self->ut_numbern('paypendingnum')
134 || $self->ut_foreign_key('custnum', 'cust_main', 'custnum')
135 || $self->ut_money('paid')
136 || $self->ut_numbern('_date')
137 || $self->ut_textn('payunique')
138 || $self->ut_text('status')
139 #|| $self->ut_textn('statustext')
140 || $self->ut_anything('statustext')
141 #|| $self->ut_money('cust_balance')
142 || $self->ut_foreign_keyn('paynum', 'cust_pay', 'paynum' )
143 || $self->payinfo_check() #payby/payinfo/paymask/paydate
145 return $error if $error;
147 $self->_date(time) unless $self->_date;
149 # UNIQUE index should catch this too, without race conditions, but this
150 # should give a better error message the other 99.9% of the time...
151 if ( length($self->payunique) ) {
152 my $cust_pay_pending = qsearchs('cust_pay_pending', {
153 'payunique' => $self->payunique,
154 'paypendingnum' => { op=>'!=', value=>$self->paypendingnum },
156 if ( $cust_pay_pending ) {
157 #well, it *could* be a better error message
158 return "duplicate transaction - a payment with unique identifer ".
159 $self->payunique. " already exists";
172 L<FS::Record>, schema.html from the base documentation.