diff options
author | Jonathan Prykop <jonathan@freeside.biz> | 2016-01-15 12:41:48 -0600 |
---|---|---|
committer | Jonathan Prykop <jonathan@freeside.biz> | 2016-01-26 14:48:49 -0600 |
commit | f685af08c55b6eaac2c87132bc2f0f5113b869d7 (patch) | |
tree | 0bd15c71b5ea3087e649ea1e98e7c1a5681d1df1 /httemplate/misc | |
parent | 19e69d1b833894aa23a1143398b0b334151f8ba2 (diff) |
RT#38363: use cust_payby when saving cards during payments
Diffstat (limited to 'httemplate/misc')
-rw-r--r-- | httemplate/misc/payment.cgi | 40 | ||||
-rw-r--r-- | httemplate/misc/process/payment.cgi | 85 |
2 files changed, 75 insertions, 50 deletions
diff --git a/httemplate/misc/payment.cgi b/httemplate/misc/payment.cgi index f4f0b56dd..7afdfd159 100644 --- a/httemplate/misc/payment.cgi +++ b/httemplate/misc/payment.cgi @@ -33,15 +33,22 @@ &> % } +% my $auto = 0; % if ( $payby eq 'CARD' ) { % % my( $payinfo, $paycvv, $month, $year ) = ( '', '', '', '' ); % my $payname = $cust_main->first. ' '. $cust_main->getfield('last'); -% if ( $cust_main->payby =~ /^(CARD|DCRD)$/ ) { -% $payinfo = $cust_main->paymask; -% $paycvv = $cust_main->paycvv; -% ( $month, $year ) = $cust_main->paydate_monthyear; -% $payname = $cust_main->payname if $cust_main->payname; +% my $location = $cust_main->bill_location; +% +% #auto-fill with the highest weighted match +% my ($cust_payby) = $cust_main->cust_payby('CARD','DCRD'); +% if ($cust_payby) { +% $payinfo = $cust_payby->paymask; +% $paycvv = $cust_payby->paycvv; +% ( $month, $year ) = $cust_payby->paydate_monthyear; +% $payname = $cust_payby->payname if $cust_payby->payname; +% $location = $cust_payby->cust_location || $location; +% $auto = 1 if $cust_payby->payby eq 'CARD'; % } <TR> @@ -87,7 +94,7 @@ </TR> <& /elements/location.html, - 'object' => $cust_main->bill_location, + 'object' => $location, 'no_asterisks' => 1, 'address1_label' => emt('Card billing address'), &> @@ -97,16 +104,19 @@ % my( $account, $aba, $branch, $payname, $ss, $paytype, $paystate, % $stateid, $stateid_state ) % = ( '', '', '', '', '', '', '', '', '' ); -% if ( $cust_main->payby =~ /^(CHEK|DCHK)$/ ) { -% $cust_main->paymask =~ /^([\dx]+)\@([\d\.x]*)$/i -% or die "unparsable payinfo ". $cust_main->payinfo; +% my ($cust_payby) = $cust_main->cust_payby('CHEK','DCHK'); +% if ($cust_payby) { +% $cust_payby->paymask =~ /^([\dx]+)\@([\d\.x]*)$/i +% or die "unparsable paymask ". $cust_payby->paymask; % ($account, $aba) = ($1, $2); % ($branch,$aba) = split('\.',$aba) % if $conf->config('echeck-country') eq 'CA'; -% $payname = $cust_main->payname; +% $payname = $cust_payby->payname; +% $paytype = $cust_payby->getfield('paytype'); +% $paystate = $cust_payby->getfield('paystate'); +% $auto = 1 if $cust_payby->payby eq 'CHEK'; +% # these values aren't in cust_payby, but maybe should be... % $ss = $cust_main->ss; -% $paytype = $cust_main->getfield('paytype'); -% $paystate = $cust_main->getfield('paystate'); % $stateid = $cust_main->getfield('stateid'); % $stateid_state = $cust_main->getfield('stateid_state'); % } @@ -228,7 +238,7 @@ <TR> <TD COLSPAN=2> - <INPUT TYPE="checkbox"<% ( ( $payby eq 'CARD' && $cust_main->payby ne 'DCRD' ) || ( $payby eq 'CHEK' && $cust_main->payby eq 'CHEK' ) ) ? ' CHECKED' : '' %> NAME="auto" VALUE="1" onClick="if (this.checked) { document.OneTrueForm.save.checked=true; }"> + <INPUT TYPE="checkbox"<% $auto ? ' CHECKED' : '' %> NAME="auto" VALUE="1" onClick="if (this.checked) { document.OneTrueForm.save.checked=true; }"> <% mt("Charge future payments to this [_1] automatically",$type{$payby}) |h %> </TD> </TR> @@ -260,10 +270,6 @@ my $custnum = $1; my $cust_main = qsearchs( 'cust_main', { 'custnum'=>$custnum } ); die "unknown custnum $custnum" unless $cust_main; -my $location = $cust_main->bill_location; -# no proper error handling on this anyway, but when we have it, -# remember to repopulate fields in $location - my $balance = $cust_main->balance; my $payinfo = ''; diff --git a/httemplate/misc/process/payment.cgi b/httemplate/misc/process/payment.cgi index efba9ed9a..5cd5d31b5 100644 --- a/httemplate/misc/process/payment.cgi +++ b/httemplate/misc/process/payment.cgi @@ -76,11 +76,29 @@ 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; - $paymask = $cust_main->paymask; + + 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')); @@ -99,10 +117,22 @@ if ( $payby eq 'CHEK' ) { } elsif ( $payby eq 'CARD' ) { $payinfo = $cgi->param('payinfo'); - if ($payinfo eq $cust_main->paymask) { - $payinfo = $cust_main->payinfo; - $paymask = $cust_main->paymask; + 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; @@ -114,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})$/ @@ -140,42 +170,31 @@ 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' => ''); - } + my %saveopt; 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 + $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 { - $new->set( $_ => $cgi->param($_) ) foreach @{$payby2fields{$payby}}; + # ss/stateid/stateid_state won't be saved, but should be harmless to pass + %saveopt = map { $_ => scalar($cgi->param($_)) } @{$payby2fields{$payby}}; } - my $error = $new->replace($cust_main); + 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; - $cust_main = $new; + if $error; } my $error = ''; |