-<% include( '/elements/header.html', ucfirst($type{$payby}). ' processing successful',
- include('/elements/menubar.html'),
+% if ( $cgi->param('batch') ) {
- )
-%>
-<% include( '/elements/small_custview.html', $cust_main, '', '', popurl(3). "view/cust_main.cgi" ) %>
+ <% include( '/elements/header.html', ucfirst($type{$payby}). ' processing successful',
+ include('/elements/menubar.html'),
-<% include('/elements/footer.html') %>
+ )
+ %>
+
+ <% include( '/elements/small_custview.html', $cust_main, '', '', popurl(3). "view/cust_main.cgi" ) %>
+
+ <% include('/elements/footer.html') %>
+
+% #2.5/2.7?# } elsif ( $curuser->access_right('View payments') ) {
+% } elsif ( $curuser->access_right(['View invoices', 'View payments']) ) {
+<% $cgi->redirect(popurl(3). "view/cust_pay.html?paynum=$paynum" ) %>
+% } else {
+<% $cgi->redirect(popurl(3). "view/cust_main.html?custnum=$custnum" ) %>
+% }
<%init>
+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+)$/
my $amount = $1;
errorpage("amount <= 0") unless $amount > 0;
+if ( $cgi->param('fee') =~ /^\s*(\d*(\.\d\d)?)\s*$/ ) {
+ my $fee = $1;
+ $amount = sprintf('%.2f', $amount + $fee);
+}
+
$cgi->param('year') =~ /^(\d+)$/
or errorpage("illegal year ". $cgi->param('year'));
my $year = $1;
or errorpage("illegal payby ". $cgi->param('payby'));
my $payby = $1;
my %payby2fields = (
- 'CARD' => [ qw( address1 address2 city state zip ) ],
+ 'CARD' => [ qw( address1 address2 city county state zip country ) ],
'CHEK' => [ qw( ss paytype paystate stateid stateid_state ) ],
);
my %type = ( 'CARD' => 'credit card',
or errorpage(gettext('illegal_text'). " payunique: ". $cgi->param('payunique'));
my $payunique = $1;
+$cgi->param('balance') =~ /^\s*(\-?\s*\d*(\.\d\d)?)\s*$/
+ or errorpage("illegal balance");
+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;
$cgi->param('payinfo2') =~ /^(\d+)$/
- or errorpage("illegal ABA/routing number ". $cgi->param('payinfo2'));
+ 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;
}
$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})$/
- or errorpage(gettext('invalid_card')); # . ": ". $self->payinfo;
+ $payinfo =~ /^(\d{13,16}|\d{8,9})$/
+ or errorpage(gettext('invalid_card'));
$payinfo = $1;
validate($payinfo)
- or errorpage(gettext('invalid_card')); # . ": ". $self->payinfo;
- errorpage(gettext('unknown_card_type'))
- if cardtype($payinfo) eq "Unknown";
+ or errorpage(gettext('invalid_card'));
+
+ unless ( $payinfo =~ /^99\d{14}$/ ) { #token
+
+ my $cardtype = cardtype($payinfo);
+
+ errorpage(gettext('unknown_card_type'))
+ if $cardtype 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 ( length($cgi->param('paycvv') ) ) {
or errorpage("CVV2 (CVC2/CID) is three digits.");
$paycvv = $1;
}
+ }elsif( $conf->exists('backoffice-require_cvv') ){
+ errorpage("CVV2 is required");
}
}
die "unknown payby $payby";
}
-my $error = '';
-if ( $cgi->param('batch') ) {
-
- $error = $cust_main->batch_card(
- 'payby' => $payby,
- 'amount' => $amount,
- 'payinfo' => $payinfo,
- 'paydate' => "$year-$month-01",
- 'payname' => $payname,
- map { $_ => $cgi->param($_) }
- @{$payby2fields{$payby}}
- );
- errotpage($error) if $error;
-
-} else {
-
- $error = $cust_main->realtime_bop( $FS::payby::payby2bop{$payby}, $amount,
- 'quiet' => 1,
- 'manual' => 1,
- 'payinfo' => $payinfo,
- 'paydate' => "$year-$month-01",
- 'payname' => $payname,
- 'payunique' => $payunique,
- 'paycvv' => $paycvv,
- map { $_ => $cgi->param($_) } @{$payby2fields{$payby}}
- );
- errorpage($error) if $error;
-
- $cust_main->apply_payments;
-
-}
+$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' ) {
} else {
die "unknown payby $payby";
}
- $new->set( 'payinfo' => $payinfo );
+ $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
- my $conf = new FS::Conf;
if ( $payby eq 'CARD' &&
grep { $_ eq cardtype($payinfo) } $conf->config('cvv-save') ) {
$new->set( 'paycvv' => $paycvv );
$new->set( 'paycvv' => '');
}
- $new->set( $_ => $cgi->param($_) ) foreach @{$payby2fields{$payby}};
+ 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("payment processed successfully, but error saving info: $error")
+ errorpage("error saving info, payment not processed: $error")
if $error;
$cust_main = $new;
}
+my $error = '';
+my $paynum = '';
+if ( $cgi->param('batch') ) {
+
+ $error = 'Prepayment discounts not supported with batched payments'
+ if $discount_term;
+
+ $error ||= $cust_main->batch_card(
+ 'payby' => $payby,
+ 'amount' => $amount,
+ 'payinfo' => $payinfo,
+ 'paydate' => "$year-$month-01",
+ 'payname' => $payname,
+ map { $_ => scalar($cgi->param($_)) }
+ @{$payby2fields{$payby}}
+ );
+ errorpage($error) if $error;
+
+} else {
+
+ $error = $cust_main->realtime_bop( $FS::payby::payby2bop{$payby}, $amount,
+ 'quiet' => 1,
+ 'manual' => 1,
+ 'balance' => $balance,
+ 'payinfo' => $payinfo,
+ 'paymask' => $paymask,
+ 'paydate' => "$year-$month-01",
+ 'payname' => $payname,
+ 'payunique' => $payunique,
+ 'paycvv' => $paycvv,
+ 'paynum_ref' => \$paynum,
+ 'discount_term' => $discount_term,
+ 'no_auto_apply' => ($cgi->param('apply') eq 'never') ? 'Y' : '',
+ map { $_ => scalar($cgi->param($_)) } @{$payby2fields{$payby}}
+ );
+ errorpage($error) if $error;
+
+ #no error, so order the fee package if applicable...
+ if ( $cgi->param('fee_pkgpart') =~ /^(\d+)$/ ) {
+
+ my $cust_pkg = new FS::cust_pkg { 'pkgpart' => $1 };
+
+ my $error = $cust_main->order_pkg( 'cust_pkg' => $cust_pkg );
+ errorpage("payment processed successfully, but error ordering fee: $error")
+ if $error;
+
+ #and generate an invoice for it now too
+ $error = $cust_main->bill( 'pkg_list' => [ $cust_pkg ] );
+ errorpage("payment processed and fee ordered sucessfully, but error billing fee: $error")
+ if $error;
+
+ }
+
+ $cust_main->apply_payments if ($cgi->param('apply') eq 'yes');
+
+}
+
#success!
</%init>