X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_pay_batch.pm;h=2931fe79d7e3c179bf24f72cc4d3f56e82cf9614;hp=a5fa89b19c81883f060df9d0833e03651837ce75;hb=8d0e8149e7b19ad8543ac6c8c663be63dbc34762;hpb=6821ffc8988f64ddeefe1219b32d00cc57c4ccde diff --git a/FS/FS/cust_pay_batch.pm b/FS/FS/cust_pay_batch.pm index a5fa89b19..2931fe79d 100644 --- a/FS/FS/cust_pay_batch.pm +++ b/FS/FS/cust_pay_batch.pm @@ -3,7 +3,7 @@ use base qw( FS::payinfo_Mixin FS::cust_main_Mixin FS::Record ); use strict; use vars qw( $DEBUG ); -use Carp qw( confess ); +use Carp qw( carp confess ); use Business::CreditCard 0.28; use FS::Record qw(dbh qsearch qsearchs); @@ -63,6 +63,8 @@ following fields are currently supported: =item payname - name on card +=item paytype - account type ((personal|business) (checking|savings)) + =item first - name =item last - name @@ -156,6 +158,18 @@ sub check { $error = $self->payinfo_check(); return $error if $error; + if ( $self->payby eq 'CHEK' ) { + # because '' is on the list of paytypes: + my $paytype = $self->paytype or return "Bank account type required"; + if (grep { $_ eq $paytype} FS::cust_payby->paytypes) { + #ok + } else { + return "Bank account type '$paytype' is not allowed" + } + } else { + $self->set('paytype', ''); + } + if ( $self->exp eq '' ) { return "Expiration date required" unless $self->payby =~ /^(CHEK|DCHK|WEST)$/; @@ -225,7 +239,7 @@ sub expmmyy { =item pay_batch -Returns the payment batch this payment belongs to (L). =cut @@ -279,14 +293,19 @@ sub approve { if ( $error ) { return "error approving paybatchnum $paybatchnum: $error\n"; } + + return if $new->paycode eq "C"; + my $cust_pay = new FS::cust_pay ( { 'custnum' => $new->custnum, 'payby' => $new->payby, 'payinfo' => $new->payinfo || $old->payinfo, + 'paymask' => $new->mask_payinfo, 'paid' => $new->paid, '_date' => $new->_date, 'usernum' => $new->usernum, 'batchnum' => $new->batchnum, + 'invnum' => $old->invnum, 'gatewaynum' => $opt{'gatewaynum'}, 'processor' => $opt{'processor'}, 'auth' => $opt{'auth'}, @@ -408,12 +427,23 @@ sub request_item { $self->payinfo =~ /(\d+)@(\d+)/; # or else what? $payment{account_number} = $1; $payment{routing_code} = $2; - $payment{account_type} = $cust_main->paytype; + $payment{account_type} = $self->paytype; # XXX what if this isn't their regular payment method? } else { die "unsupported BatchPayment method: ".$pay_batch->payby; } + my $recurring; + if ( $cust_main->status =~ /^active|suspended|ordered$/ ) { + if ( $self->payinfo_used ) { + $recurring = 'S'; # subsequent + } else { + $recurring = 'F'; # first use + } + } else { + $recurring = 'N'; # non-recurring + } + Business::BatchPayment->create(Item => # required action => 'payment', @@ -429,6 +459,7 @@ sub request_item { ( map { $_ => $location->$_ } qw(address2 city state country zip) ), invoice_number => $self->invnum, + recurring_billing => $recurring, %payment, ); } @@ -451,8 +482,8 @@ sub process_unbatch_and_delete { =item unbatch_and_delete May only be called on a record with an empty status and an associated -L with a status of 'O' (not yet in transit.) Deletes all associated -records from L and then deletes this record. +L with a status of 'O' (not yet in transit.) Deletes all associated +records from L and then deletes this record. If there is an error, returns the error, otherwise returns false. =cut @@ -502,6 +533,19 @@ sub unbatch_and_delete { } +=item cust_bill + +Returns the invoice linked to this batched payment. Deprecated, will be +removed. + +=cut + +sub cust_bill { + carp "FS::cust_pay_batch->cust_bill is deprecated"; + my $self = shift; + $self->invnum ? qsearchs('cust_bill', { invnum => $self->invnum }) : ''; +} + =back =head1 BUGS