From 8800e519dc0e4b8eee4ab2cddc74d52c205bc536 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 25 Sep 2009 12:29:16 +0000 Subject: [PATCH] processing fee on credit card recharges, RT#5889 --- FS/FS/Conf.pm | 42 ++++++--------------- httemplate/config/config-process.cgi | 12 +++--- httemplate/config/config-view.cgi | 11 +++--- httemplate/config/config.cgi | 2 +- httemplate/misc/payment.cgi | 73 +++++++++++++++++++++++++++++++++--- httemplate/misc/process/payment.cgi | 14 +++++++ 6 files changed, 106 insertions(+), 48 deletions(-) diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index e7a9c1601..d5304afab 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -1430,23 +1430,7 @@ worry that config_items is freeside-specific and icky. 'key' => 'signup_server-default_pkgpart', 'section' => '', 'description' => 'Default package for the signup server', - 'type' => 'select-sub', - 'options_sub' => sub { require FS::Record; - require FS::part_pkg; - map { $_->pkgpart => $_->pkg.' - '.$_->comment } - FS::Record::qsearch( 'part_pkg', - { 'disabled' => ''} - ); - }, - 'option_sub' => sub { require FS::Record; - require FS::part_pkg; - my $part_pkg = FS::Record::qsearchs( - 'part_pkg', { 'pkgpart'=>shift } - ); - $part_pkg - ? $part_pkg->pkg.' - '.$part_pkg->comment - : ''; - }, + 'type' => 'select-part_pkg', }, { @@ -1823,6 +1807,13 @@ worry that config_items is freeside-specific and icky. }, { + 'key' => 'manual_process-pkgpart', + 'section' => 'billing', + 'description' => 'Package to add to each manual credit card and ACH payments entered from the backend. Enabling this option may be in violation of your merchant agreement(s), so please check them carefully before enabling this option.', + 'type' => 'select-part_pkg', + }, + + { 'key' => 'allow_negative_charges', 'section' => 'billing', 'description' => 'Allow negative charges. Normally not used unless importing data from a legacy system that requires this.', @@ -2283,19 +2274,7 @@ worry that config_items is freeside-specific and icky. 'key' => 'postal_invoice-fee_pkgpart', 'section' => 'billing', 'description' => 'This allows selection of a package to insert on invoices for customers with postal invoices selected.', - 'type' => 'select-sub', - 'options_sub' => sub { require FS::Record; - require FS::part_pkg; - map { $_->pkgpart => $_->pkg } - FS::Record::qsearch('part_pkg', { disabled=>'' } ); - }, - 'option_sub' => sub { require FS::Record; - require FS::part_pkg; - my $part_pkg = FS::Record::qsearchs( - 'part_pkg', { 'pkgpart'=>shift } - ); - $part_pkg ? $part_pkg->pkg : ''; - }, + 'type' => 'select-part_pkg', }, { @@ -2607,7 +2586,8 @@ worry that config_items is freeside-specific and icky. 'key' => 'support_packages', 'section' => '', 'description' => 'A list of packages eligible for RT ticket time transfer, one pkgpart per line.', #this should really be a select multiple, or specified in the packages themselves... - 'type' => 'textarea', + 'type' => 'select-part_pkg', + 'multiple' => 1, }, { diff --git a/httemplate/config/config-process.cgi b/httemplate/config/config-process.cgi index 056919790..a241de854 100644 --- a/httemplate/config/config-process.cgi +++ b/httemplate/config/config-process.cgi @@ -41,16 +41,16 @@ foreach my $type ( ref($i->type) ? @{$i->type} : $i->type ) { } else { push @delete, $i->key; } - } elsif ( $type =~ /^(editlist|selectmultiple)$/ - or ( $type =~ /^select(-(sub|part_svc))?$/ || $i->multiple ) - ) - { + } elsif ( + $type =~ /^(editlist|selectmultiple)$/ + or ( $type =~ /^select(-(sub|part_svc|part_pkg))?$/ || $i->multiple ) + ) { if ( scalar(@{[ $cgi->param($i->key.$n) ]}) ) { $conf->set($i->key, join("\n", @{[ $cgi->param($i->key.$n) ]} ), $agentnum); } else { $conf->delete($i->key, $agentnum); } - } elsif ( $type =~ /^(text|select(-(sub|part_svc))?)$/ ) { + } elsif ( $type =~ /^(text|select(-(sub|part_svc|part_pkg))?)$/ ) { if ( $cgi->param($i->key.$n) ne '' ) { $conf->set($i->key, $cgi->param($i->key.$n), $agentnum); } else { @@ -104,7 +104,7 @@ $conf->delete($_, $agentnum) foreach @delete; % } elsif ( $type eq 'text' || $type eq 'select' ) { configCell.innerHTML = <% $conf->exists($i->key, $agentnum) ? $conf->config($i->key, $agentnum) : '' |js_string %>; -% } elsif ( $type eq 'select-part_svc' && ! $i->multiple ) { +% } elsif ( $type =~ /^select-(part_svc|part_pkg)$/ && ! $i->multiple ) { configCell.innerHTML = <% $conf->config($i->key, $agentnum) |js_string %> %# + ': ' + diff --git a/httemplate/config/config-view.cgi b/httemplate/config/config-view.cgi index 80a65d09b..51535d762 100644 --- a/httemplate/config/config-view.cgi +++ b/httemplate/config/config-view.cgi @@ -48,7 +48,8 @@ Click on a configuration value to change it. % foreach my $i (@{ $section_items{$section} }) { % my @types = ref($i->type) ? @{$i->type} : ($i->type); -% my( $width, $height ) = ( 522, 336 ); +%# my( $width, $height ) = ( 522, 336 ); +% my( $width, $height ) = ( 600, 336 ); % if ( grep $_ eq 'textarea', @types ) { % #800x600 % $width = 763; @@ -208,14 +209,14 @@ Click on a configuration value to change it. -% } elsif ( $type eq 'select-part_svc' ) { -% my @svcparts = $conf->config($i->key, $agentnum); +% } elsif ( $type =~ /^select-(part_svc|part_pkg)$/ ) { +% my @keys = $conf->config($i->key, $agentnum); - <% join('
', map { $_ # ': '. $svc + <% join('
', map { $_ # ': '. $svc, $pkg, whatever } - @svcparts + @keys ) %> diff --git a/httemplate/config/config.cgi b/httemplate/config/config.cgi index 4ebedc180..45d77ffce 100644 --- a/httemplate/config/config.cgi +++ b/httemplate/config/config.cgi @@ -308,7 +308,7 @@ my @config_items = $conf->config_items; my %confitems = map { $_->key => $_ } @config_items; my %element_types = map { $_ => 1 } qw( - select-part_svc + select-part_svc select-part_pkg ); diff --git a/httemplate/misc/payment.cgi b/httemplate/misc/payment.cgi index 45aeacad4..472763b2d 100644 --- a/httemplate/misc/payment.cgi +++ b/httemplate/misc/payment.cgi @@ -10,16 +10,66 @@ % #include( '/elements/table.html', '#cccccc' ) +% my $amount = $balance > 0 ? sprintf("%.2f", $balance) : ''; + <% ntable('#cccccc') %> Payment amount - +
- $"> + <% $money_char %> + +% if ( $fee ) { + + + + + <% $money_char . $fee %> + + <% $fee_pkg->pkg |h %> + = + + <% length($amount) ? $money_char. sprintf('%.2f', $amount + $fee ) : '' %> TOTAL + +% }
+% if ( $fee ) { + + + +% } + + % if ( $payby eq 'CARD' ) { % % my( $payinfo, $paycvv, $month, $year ) = ( '', '', '', '' ); @@ -237,16 +287,29 @@ my $balance = $cust_main->balance; my $payinfo = ''; -#false laziness w/selfservice make_payment.html shortcut for one-country my $conf = new FS::Conf; + +my $money_char = $conf->config('money_char') || '$'; + +#false laziness w/selfservice make_payment.html shortcut for one-country my %states = map { $_->state => 1 } qsearch('cust_main_county', { 'country' => $conf->config('countrydefault') || 'US' } ); my @states = sort { $a cmp $b } keys %states; -my $payunique = "webui-payment-". time. "-$$-". rand() * 2**32; +my $fee = ''; +my $fee_pkg = ''; +if ( $conf->config('manual_process-pkgpart') ) { + $fee_pkg = + qsearchs('part_pkg', { pkgpart=>$conf->config('manual_process-pkgpart') } ); - + #well ->unit_setup or ->calc_setup both call for a $cust_pkg + # (though ->unit_setup doesn't use it...) + $fee = $fee_pkg->option('setup_fee') + if $fee_pkg; #in case.. better than dying with a perl traceback +} +my $payunique = "webui-payment-". time. "-$$-". rand() * 2**32; + diff --git a/httemplate/misc/process/payment.cgi b/httemplate/misc/process/payment.cgi index ea0c7946d..d41bc0f14 100644 --- a/httemplate/misc/process/payment.cgi +++ b/httemplate/misc/process/payment.cgi @@ -32,6 +32,11 @@ $cgi->param('amount') =~ /^\s*(\d*(\.\d\d)?)\s*$/ 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; @@ -143,6 +148,15 @@ if ( $cgi->param('batch') ) { ); errorpage($error) if $error; + #no error, so order the fee package if applicable... + if ( $cgi->param('fee_pkgpart') =~ /^(\d+)$/ ) { + my $error = $cust_main->order_pkg( + 'cust_pkg' => new FS::cust_pkg { 'pkgpart' => $1 } + ); + errorpage("payment processed successfully, but error ordering fee: $error") + if $error; + } + $cust_main->apply_payments; } -- 2.11.0