diff options
author | jeff <jeff> | 2006-05-20 20:06:30 +0000 |
---|---|---|
committer | jeff <jeff> | 2006-05-20 20:06:30 +0000 |
commit | 50f25b285b2caf77d267ed66f03e56924ad7229f (patch) | |
tree | 492bbc92656fbcbdfdc6880d88639388e9226225 /FS | |
parent | 64dc1bb0f70ccc0b828cc1d758cd82f040e0ec33 (diff) |
first stab at BoM download
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS.pm | 4 | ||||
-rw-r--r-- | FS/FS/Schema.pm | 15 | ||||
-rw-r--r-- | FS/FS/cust_bill.pm | 20 | ||||
-rw-r--r-- | FS/FS/cust_pay_batch.pm | 40 | ||||
-rw-r--r-- | FS/FS/pay_batch.pm | 121 | ||||
-rw-r--r-- | FS/MANIFEST | 6 | ||||
-rw-r--r-- | FS/t/pay_batch.t | 5 |
7 files changed, 196 insertions, 15 deletions
@@ -142,7 +142,9 @@ L<FS::cust_credit_bill> - Credit application to invoice class L<FS::cust_pay_refund> - Refund application to payment class -L<FS::cust_pay_batch> - Credit card transaction queue class +L<FS::pay_batch> - Credit card transaction queue class + +L<FS::cust_pay_batch> - Credit card transaction member queue class L<FS::prepay_credit> - Prepaid "calling card" credit class. diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index e81185666..17d541e8c 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -538,10 +538,21 @@ sub tables_hashref { 'index' => [ [ 'paynum' ], [ 'invnum' ] ], }, + 'pay_batch' => { #batches of payments to an external processor + 'columns' => [ + 'batchnum', 'serial', '', '', '', '', + 'status', 'char', 'NULL', 1, '', '', + ], + 'primary_key' => 'batchnum', + 'unique' => [], + 'index' => [], + }, + 'cust_pay_batch' => { #what's this used for again? list of customers #in current CARD batch? (necessarily CARD?) 'columns' => [ 'paybatchnum', 'serial', '', '', '', '', + 'batchnum', 'int', '', '', '', '', 'invnum', 'int', '', '', '', '', 'custnum', 'int', '', '', '', '', 'last', 'varchar', '', $char_d, '', '', @@ -553,7 +564,7 @@ sub tables_hashref { 'zip', 'varchar', 'NULL', 10, '', '', 'country', 'char', '', 2, '', '', # 'trancode', 'int', '', '', '', '' - 'cardnum', 'varchar', '', 16, '', '', + 'payinfo', 'varchar', '', 512, '', '', #'exp', @date_type, '', '' 'exp', 'varchar', '', 11, '', '', 'payname', 'varchar', 'NULL', $char_d, '', '', @@ -561,7 +572,7 @@ sub tables_hashref { ], 'primary_key' => 'paybatchnum', 'unique' => [], - 'index' => [ ['invnum'], ['custnum'] ], + 'index' => [ ['batchnum'], ['invnum'], ['custnum'] ], }, 'cust_pkg' => { diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index bcae4d646..c2a39afda 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -13,7 +13,7 @@ use HTML::Entities; use Locale::Country; use FS::UID qw( datasrc ); use FS::Misc qw( send_email send_fax ); -use FS::Record qw( qsearch qsearchs ); +use FS::Record qw( qsearch qsearchs dbh ); use FS::cust_main_Mixin; use FS::cust_main; use FS::cust_bill_pkg; @@ -1282,8 +1282,22 @@ L<FS::cust_pay_batch>). sub batch_card { my $self = shift; my $cust_main = $self->cust_main; + my $oldAutoCommit = $FS::UID::AutoCommit; + local $FS::UID::AutoCommit = 0; + my $dbh = dbh; + + my $pay_batch = qsearchs('pay_batch'=> ''); + + unless ($pay_batch) { + $pay_batch = new FS::pay_batch; + my $error = $pay_batch->insert; + if ( $error ) { + die "error creating new batch: $error\n"; + } + } my $cust_pay_batch = new FS::cust_pay_batch ( { + 'batchnum' => $pay_batch->getfield('batchnum'), 'invnum' => $self->getfield('invnum'), 'custnum' => $cust_main->getfield('custnum'), 'last' => $cust_main->getfield('last'), @@ -1294,7 +1308,7 @@ sub batch_card { 'state' => $cust_main->getfield('state'), 'zip' => $cust_main->getfield('zip'), 'country' => $cust_main->getfield('country'), - 'cardnum' => $cust_main->payinfo, + 'payinfo' => $cust_main->payinfo, 'exp' => $cust_main->getfield('paydate'), 'payname' => $cust_main->getfield('payname'), 'amount' => $self->owed, @@ -1302,6 +1316,8 @@ sub batch_card { my $error = $cust_pay_batch->insert; die $error if $error; + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + ''; } diff --git a/FS/FS/cust_pay_batch.pm b/FS/FS/cust_pay_batch.pm index 25b796ba9..117d72561 100644 --- a/FS/FS/cust_pay_batch.pm +++ b/FS/FS/cust_pay_batch.pm @@ -37,7 +37,7 @@ following fields are currently supported: =item paybatchnum - primary key (automatically assigned) -=item cardnum +=item payinfo =item exp - card expiration @@ -119,7 +119,7 @@ sub check { my $error = $self->ut_numbern('paybatchnum') || $self->ut_numbern('trancode') #depriciated - || $self->ut_number('cardnum') + || $self->ut_number('payinfo') || $self->ut_money('amount') || $self->ut_number('invnum') || $self->ut_number('custnum') @@ -137,14 +137,19 @@ sub check { $self->first =~ /^([\w \,\.\-\']+)$/ or return "Illegal first name"; $self->first($1); - my $cardnum = $self->cardnum; - $cardnum =~ s/\D//g; - $cardnum =~ /^(\d{13,16})$/ - or return "Illegal credit card number"; - $cardnum = $1; - $self->cardnum($cardnum); - validate($cardnum) or return "Illegal credit card number"; - return "Unknown card type" if cardtype($cardnum) eq "Unknown"; + # FIXME + # there is no point in false laziness here + # we will effectively set "check_payinfo to 0" + # we can change that when we finish the refactor + + #my $cardnum = $self->cardnum; + #$cardnum =~ s/\D//g; + #$cardnum =~ /^(\d{13,16})$/ + # or return "Illegal credit card number"; + #$cardnum = $1; + #$self->cardnum($cardnum); + #validate($cardnum) or return "Illegal credit card number"; + #return "Unknown card type" if cardtype($cardnum) eq "Unknown"; if ( $self->exp eq '' ) { return "Expiration date required"; #unless @@ -305,6 +310,21 @@ sub import_results { local $FS::UID::AutoCommit = 0; my $dbh = dbh; + my $pay_batch = qsearchs('pay_batch',{'batchnum'=> $paybatch}); + unless ($pay_batch && $pay_batch->status eq 'I') { + $dbh->rollback if $oldAutoCommit; + return "batch $paybatch is not in transit"; + }; + + my %batchhash = $pay_batch->hash; + $batchhash{'status'} = 'R'; # Resolved + my $newbatch = new FS::pay_batch ( \%batchhash ); + my $error = $newbatch->replace($paybatch); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error + } + my $total = 0; my $line; while ( defined($line=<$fh>) ) { diff --git a/FS/FS/pay_batch.pm b/FS/FS/pay_batch.pm new file mode 100644 index 000000000..192c5df83 --- /dev/null +++ b/FS/FS/pay_batch.pm @@ -0,0 +1,121 @@ +package FS::pay_batch; + +use strict; +use vars qw( @ISA ); +use FS::Record qw( qsearch qsearchs ); + +@ISA = qw(FS::Record); + +=head1 NAME + +FS::pay_batch - Object methods for pay_batch records + +=head1 SYNOPSIS + + use FS::pay_batch; + + $record = new FS::pay_batch \%hash; + $record = new FS::pay_batch { 'column' => 'value' }; + + $error = $record->insert; + + $error = $new_record->replace($old_record); + + $error = $record->delete; + + $error = $record->check; + +=head1 DESCRIPTION + +An FS::pay_batch object represents an example. FS::pay_batch inherits from +FS::Record. The following fields are currently supported: + +=over 4 + +=item batchnum - primary key + +=item status - + + +=back + +=head1 METHODS + +=over 4 + +=item new HASHREF + +Creates a new example. To add the example to the database, see L<"insert">. + +Note that this stores the hash reference, not a distinct copy of the hash it +points to. You can ask the object for a copy with the I<hash> method. + +=cut + +# the new method can be inherited from FS::Record, if a table method is defined + +sub table { 'pay_batch'; } + +=item insert + +Adds this record to the database. If there is an error, returns the error, +otherwise returns false. + +=cut + +# the insert method can be inherited from FS::Record + +=item delete + +Delete this record from the database. + +=cut + +# the delete method can be inherited from FS::Record + +=item replace OLD_RECORD + +Replaces the OLD_RECORD with this one in the database. If there is an error, +returns the error, otherwise returns false. + +=cut + +# the replace method can be inherited from FS::Record + +=item check + +Checks all fields to make sure this is a valid example. If there is +an error, returns the error, otherwise returns false. Called by the insert +and replace methods. + +=cut + +# the check method should currently be supplied - FS::Record contains some +# data checking routines + +sub check { + my $self = shift; + + my $error = + $self->ut_numbern('batchnum') + || $self->ut_enum('status', [ '', 'I', 'R' ]) + ; + return $error if $error; + + $self->SUPER::check; +} + +=back + +=head1 BUGS + +The author forgot to customize this manpage. + +=head1 SEE ALSO + +L<FS::Record>, schema.html from the base documentation. + +=cut + +1; + diff --git a/FS/MANIFEST b/FS/MANIFEST index bd810a8db..4e71e720b 100644 --- a/FS/MANIFEST +++ b/FS/MANIFEST @@ -340,3 +340,9 @@ t/access_groupagent.t FS/access_right.pm t/access_right.t FS/m2m_Common.pm +FS/pay_batch.pm +t/pay_batch.t +FS/pay_batch.pm +t/pay_batch.t +FS/pay_batch.pm +t/pay_batch.t diff --git a/FS/t/pay_batch.t b/FS/t/pay_batch.t new file mode 100644 index 000000000..c43133dc2 --- /dev/null +++ b/FS/t/pay_batch.t @@ -0,0 +1,5 @@ +BEGIN { $| = 1; print "1..1\n" } +END {print "not ok 1\n" unless $loaded;} +use FS::pay_batch; +$loaded=1; +print "ok 1\n"; |