X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fmisc%2Fprocess%2Fpayment.cgi;h=efba9ed9ab6511ff2e82e284448030717b834cd6;hb=f8c4741390077c1448d627949d19c9220cc8e610;hp=fb6a41bd32af05d70e0805101a14aaab184886ed;hpb=4e764e5f9a7b690baf95906c4455311c2560120f;p=freeside.git diff --git a/httemplate/misc/process/payment.cgi b/httemplate/misc/process/payment.cgi index fb6a41bd3..efba9ed9a 100644 --- a/httemplate/misc/process/payment.cgi +++ b/httemplate/misc/process/payment.cgi @@ -21,6 +21,8 @@ my $curuser = $FS::CurrentUser::CurrentUser; die "access denied" unless $curuser->access_right('Process payment'); +my $conf = new FS::Conf; + #some false laziness w/MyAccount::process_payment $cgi->param('custnum') =~ /^(\d+)$/ @@ -72,23 +74,25 @@ $cgi->param('balance') =~ /^\s*(\-?\s*\d*(\.\d\d)?)\s*$/ my $balance = $1; my $payinfo; +my $paymask; # override only used by loaded cust payinfo, only implemented for realtime processing my $paycvv = ''; if ( $payby eq 'CHEK' ) { if ($cgi->param('payinfo1') =~ /xx/i || $cgi->param('payinfo2') =~ /xx/i ) { $payinfo = $cust_main->payinfo; + $paymask = $cust_main->paymask; } else { $cgi->param('payinfo1') =~ /^(\d+)$/ - or errorpage("illegal account number ". $cgi->param('payinfo1')); + or errorpage("Illegal account number ". $cgi->param('payinfo1')); my $payinfo1 = $1; - if ( $conf->exists('echeck-no_routing') ) { - $cgi->param('payinfo2') =~ /^(\d*)$/ - or errorpage("illegal ABA/routing number ". $cgi->param('payinfo2')); - } else { - $cgi->param('payinfo2') =~ /^(\d+)$/ - or errorpage("illegal ABA/routing number ". $cgi->param('payinfo2')); - } + $cgi->param('payinfo2') =~ /^(\d+)$/ + or errorpage("Illegal ABA/routing number ". $cgi->param('payinfo2')); my $payinfo2 = $1; + if ( $conf->config('echeck-country') eq 'CA' ) { + $cgi->param('payinfo3') =~ /^(\d{5})$/ + or errorpage("Illegal branch number ". $cgi->param('payinfo2')); + $payinfo2 = "$1.$payinfo2"; + } $payinfo = $payinfo1. '@'. $payinfo2; } @@ -97,6 +101,7 @@ if ( $payby eq 'CHEK' ) { $payinfo = $cgi->param('payinfo'); if ($payinfo eq $cust_main->paymask) { $payinfo = $cust_main->payinfo; + $paymask = $cust_main->paymask; } $payinfo =~ s/\D//g; $payinfo =~ /^(\d{13,16}|\d{8,9})$/ @@ -120,6 +125,8 @@ if ( $payby eq 'CHEK' ) { or errorpage("CVV2 (CVC2/CID) is three digits."); $paycvv = $1; } + }elsif( $conf->exists('backoffice-require_cvv') ){ + errorpage("CVV2 is required"); } } @@ -127,10 +134,50 @@ if ( $payby eq 'CHEK' ) { die "unknown payby $payby"; } -$cgi->param('discount_term') =~ /^\d*$/ +$cgi->param('discount_term') =~ /^(\d*)$/ or errorpage("illegal discount_term"); my $discount_term = $1; +# save first, for proper tokenization later +if ( $cgi->param('save') ) { + my $new = new FS::cust_main { $cust_main->hash }; + if ( $payby eq 'CARD' ) { + $new->set( 'payby' => ( $cgi->param('auto') ? 'CARD' : 'DCRD' ) ); + } elsif ( $payby eq 'CHEK' ) { + $new->set( 'payby' => ( $cgi->param('auto') ? 'CHEK' : 'DCHK' ) ); + } else { + die "unknown payby $payby"; + } + $new->payinfo($payinfo); # sets default paymask, but not if it's already tokenized + $new->paymask($paymask) if $paymask; # in case it's been tokenized, override with loaded paymask + $new->set( 'paydate' => "$year-$month-01" ); + $new->set( 'payname' => $payname ); + + #false laziness w/FS:;cust_main::realtime_bop - check both to make sure + # working correctly + if ( $payby eq 'CARD' && + grep { $_ eq cardtype($payinfo) } $conf->config('cvv-save') ) { + $new->set( 'paycvv' => $paycvv ); + } else { + $new->set( 'paycvv' => ''); + } + + if ( $payby eq 'CARD' ) { + my $bill_location = FS::cust_location->new; + $bill_location->set( $_ => $cgi->param($_) ) + foreach @{$payby2fields{$payby}}; + $new->set('bill_location' => $bill_location); + # will do nothing if the fields are all unchanged + } else { + $new->set( $_ => $cgi->param($_) ) foreach @{$payby2fields{$payby}}; + } + + my $error = $new->replace($cust_main); + errorpage("error saving info, payment not processed: $error") + if $error; + $cust_main = $new; +} + my $error = ''; my $paynum = ''; if ( $cgi->param('batch') ) { @@ -156,6 +203,7 @@ if ( $cgi->param('batch') ) { 'manual' => 1, 'balance' => $balance, 'payinfo' => $payinfo, + 'paymask' => $paymask, 'paydate' => "$year-$month-01", 'payname' => $payname, 'payunique' => $payunique, @@ -186,37 +234,6 @@ if ( $cgi->param('batch') ) { } -if ( $cgi->param('save') ) { - my $new = new FS::cust_main { $cust_main->hash }; - if ( $payby eq 'CARD' ) { - $new->set( 'payby' => ( $cgi->param('auto') ? 'CARD' : 'DCRD' ) ); - } elsif ( $payby eq 'CHEK' ) { - $new->set( 'payby' => ( $cgi->param('auto') ? 'CHEK' : 'DCHK' ) ); - } else { - die "unknown payby $payby"; - } - $new->set( 'payinfo' => $cust_main->card_token || $payinfo ); - $new->set( 'paydate' => "$year-$month-01" ); - $new->set( 'payname' => $payname ); - - #false laziness w/FS:;cust_main::realtime_bop - check both to make sure - # working correctly - my $conf = new FS::Conf; - if ( $payby eq 'CARD' && - grep { $_ eq cardtype($payinfo) } $conf->config('cvv-save') ) { - $new->set( 'paycvv' => $paycvv ); - } else { - $new->set( 'paycvv' => ''); - } - - $new->set( $_ => $cgi->param($_) ) foreach @{$payby2fields{$payby}}; - - my $error = $new->replace($cust_main); - errorpage("payment processed successfully, but error saving info: $error") - if $error; - $cust_main = $new; -} - #success!