X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=httemplate%2Fmisc%2Fprocess%2Fpayment.cgi;h=5cd5d31b50a0209a8e42338bc0a8c22617016424;hp=bfa3f0ea9367837d80d9b79ece4b43c1d70f03f1;hb=768ab093771b3305a67c9d929b461ef777ecdad8;hpb=bd376d43f95dcdebcd180e7fff5caf0678edc15d diff --git a/httemplate/misc/process/payment.cgi b/httemplate/misc/process/payment.cgi index bfa3f0ea9..5cd5d31b5 100644 --- a/httemplate/misc/process/payment.cgi +++ b/httemplate/misc/process/payment.cgi @@ -74,11 +74,31 @@ $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 = ''; +my $loaded_cust_payby; if ( $payby eq 'CHEK' ) { if ($cgi->param('payinfo1') =~ /xx/i || $cgi->param('payinfo2') =~ /xx/i ) { - $payinfo = $cust_main->payinfo; + + my $search_paymask = $cgi->param('payinfo1') . '@' . $cgi->param('payinfo2'); + $search_paymask .= '.' . $cgi->param('payinfo3') + if $conf->config('echeck-country') eq 'CA'; + + #paymask might not be saved in database, need to run paymask method for any potential match + foreach my $search_cust_payby ($cust_main->cust_payby('CHEK','DCHK')) { + if ($search_paymask eq $search_cust_payby->paymask) { + # if there are multiple matches, assume for now that it's the first one returned, + # since that's what auto-fills; it's unlikely a masked number would be entered by hand, + # but it's very likely users will just click-through what's been auto-filled + $loaded_cust_payby = $search_cust_payby; + last; + } + } + errorpage("Masked payinfo not found") unless $loaded_cust_payby; + $payinfo = $loaded_cust_payby->payinfo; + $paymask = $loaded_cust_payby->paymask; + } else { $cgi->param('payinfo1') =~ /^(\d+)$/ or errorpage("Illegal account number ". $cgi->param('payinfo1')); @@ -86,8 +106,8 @@ if ( $payby eq 'CHEK' ) { $cgi->param('payinfo2') =~ /^(\d+)$/ or errorpage("Illegal ABA/routing number ". $cgi->param('payinfo2')); my $payinfo2 = $1; - if ( $conf->exists('cust_main-require-bank-branch') ) { - $cgi->param('payinfo3') =~ /^(\d+)$/ + if ( $conf->config('echeck-country') eq 'CA' ) { + $cgi->param('payinfo3') =~ /^(\d{5})$/ or errorpage("Illegal branch number ". $cgi->param('payinfo2')); $payinfo2 = "$1.$payinfo2"; } @@ -97,9 +117,22 @@ if ( $payby eq 'CHEK' ) { } elsif ( $payby eq 'CARD' ) { $payinfo = $cgi->param('payinfo'); - if ($payinfo eq $cust_main->paymask) { - $payinfo = $cust_main->payinfo; + if ($payinfo =~ /xx/i) { + + #paymask might not be saved in database, need to run paymask method for any potential match + foreach my $search_cust_payby ($cust_main->cust_payby('CARD','DCRD')) { + if ($payinfo eq $search_cust_payby->paymask) { + $loaded_cust_payby = $search_cust_payby; + last; + } + } + + errorpage("Masked payinfo not found") unless $loaded_cust_payby; + $payinfo = $loaded_cust_payby->payinfo; + $paymask = $loaded_cust_payby->paymask; + } + $payinfo =~ s/\D//g; $payinfo =~ /^(\d{13,16}|\d{8,9})$/ or errorpage(gettext('invalid_card')); # . ": ". $self->payinfo; @@ -111,7 +144,7 @@ if ( $payby eq 'CHEK' ) { if $payinfo !~ /^99\d{14}$/ #token && cardtype($payinfo) eq "Unknown"; - if ( defined $cust_main->dbdef_table->column('paycvv') ) { + if ( defined $cust_main->dbdef_table->column('paycvv') ) { #is this test necessary anymore? if ( length($cgi->param('paycvv') ) ) { if ( cardtype($payinfo) eq 'American Express card' ) { $cgi->param('paycvv') =~ /^(\d{4})$/ @@ -122,6 +155,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"); } } @@ -129,10 +164,39 @@ 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 %saveopt; + if ( $payby eq 'CARD' ) { + my $bill_location = FS::cust_location->new; + $bill_location->set( $_ => $cgi->param($_) ) + foreach @{$payby2fields{$payby}}; + $saveopt{'bill_location'} = $bill_location; + $saveopt{'paycvv'} = $paycvv; # save_cust_payby contains conf logic for when to use this + $saveopt{'paydate'} = "$year-$month-01"; + } else { + # ss/stateid/stateid_state won't be saved, but should be harmless to pass + %saveopt = map { $_ => scalar($cgi->param($_)) } @{$payby2fields{$payby}}; + } + + my $error = $cust_main->save_cust_payby( + 'payment_payby' => $payby, + 'auto' => scalar($cgi->param('auto')), + 'payinfo' => $payinfo, + 'paymask' => $paymask, + 'payname' => $payname, + %saveopt + ); + + errorpage("error saving info, payment not processed: $error") + if $error; +} + my $error = ''; my $paynum = ''; if ( $cgi->param('batch') ) { @@ -158,6 +222,7 @@ if ( $cgi->param('batch') ) { 'manual' => 1, 'balance' => $balance, 'payinfo' => $payinfo, + 'paymask' => $paymask, 'paydate' => "$year-$month-01", 'payname' => $payname, 'payunique' => $payunique, @@ -188,36 +253,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 - 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!