X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fmisc%2Fprocess%2Fpayment.cgi;h=01f7deebcad1b43d44b5fb5d6dde0babbccae290;hb=4da3c98f2f021ac48b195dd205bdbb85dc5b58b9;hp=506e26684eae5e30b8752335cfb8f4538e80b127;hpb=fa33561ed20c57b0f63221d6a0f9c0cf5ebbef14;p=freeside.git diff --git a/httemplate/misc/process/payment.cgi b/httemplate/misc/process/payment.cgi index 506e26684..01f7deebc 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')); @@ -97,21 +117,42 @@ 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; + or errorpage(gettext('invalid_card')); $payinfo = $1; validate($payinfo) - or errorpage(gettext('invalid_card')); # . ": ". $self->payinfo; + or errorpage(gettext('invalid_card')); + + unless ( $self->payinfo =~ /^99\d{14}$/ ) { #token + + my $cardtype = cardtype($payinfo); + + errorpage(gettext('unknown_card_type')) + if $cardtype eq "Unknown"; - errorpage(gettext('unknown_card_type')) - if $payinfo !~ /^99\d{14}$/ #token - && cardtype($payinfo) eq "Unknown"; + my %bop_card_types = map { $_=>1 } values %{ card_types() }; + errorpage("$cardtype not accepted") unless $bop_card_types{$cardtype}; - 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 +163,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"); } } @@ -133,6 +176,36 @@ $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, + 'paytype => $paytype, + %saveopt + ); + + errorpage("error saving info, payment not processed: $error") + if $error; +} + my $error = ''; my $paynum = ''; if ( $cgi->param('batch') ) { @@ -158,6 +231,7 @@ if ( $cgi->param('batch') ) { 'manual' => 1, 'balance' => $balance, 'payinfo' => $payinfo, + 'paymask' => $paymask, 'paydate' => "$year-$month-01", 'payname' => $payname, 'payunique' => $payunique, @@ -188,36 +262,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!