[freeside-commits] branch master updated. 45346fd655ba53b82c80b920da945cc0b87ece01

Ivan ivan at 420.am
Fri Aug 3 13:09:06 PDT 2012


The branch, master has been updated
       via  45346fd655ba53b82c80b920da945cc0b87ece01 (commit)
      from  8b4b2a97a84d17087c3fac19b8f768ca146cf897 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 45346fd655ba53b82c80b920da945cc0b87ece01
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Fri Aug 3 13:09:05 2012 -0700

    selfservice payment fees, RT#18345

diff --git a/FS/FS/ClientAPI/MasonComponent.pm b/FS/FS/ClientAPI/MasonComponent.pm
index 534b48a..c72d268 100644
--- a/FS/FS/ClientAPI/MasonComponent.pm
+++ b/FS/FS/ClientAPI/MasonComponent.pm
@@ -26,6 +26,7 @@ my %allowed_comps = map { $_=>1 } qw(
 
 my %session_comps = map { $_=>1 } qw(
   /elements/location.html
+  /elements/tr-amount_fee.html
   /edit/cust_main/first_pkg/select-part_pkg.html
 );
 
@@ -41,6 +42,28 @@ my %session_callbacks = (
     return ''; #no error
   },
 
+  '/elements/tr-amount_fee.html' => sub {
+    my( $custnum, $argsref ) = @_;
+
+    my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
+      or return "unknown custnum $custnum";
+
+    my $conf = new FS::Conf;
+
+    my %args = @$argsref;
+    %args = (
+      %args,
+      'process-pkgpart'    => scalar($conf->config('selfservice_process-pkgpart')),
+      'process-display'    => scalar($conf->config('selfservice_process-display')),
+      'process-skip-first' => $conf->exists('selfservice_process-skip_first'),
+      'num_payments'       => scalar($cust_main->cust_pay), 
+      'surcharge_percentage' => scalar($conf->config('credit-card-surcharge-percentage')),
+    );
+    @$argsref = ( %args );
+
+    return ''; #no error
+  },
+
   '/edit/cust_main/first_pkg/select-part_pkg.html' => sub {
     my( $custnum, $argsref ) = @_;
     my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm
index 54799b8..151a2ed 100644
--- a/FS/FS/ClientAPI/MyAccount.pm
+++ b/FS/FS/ClientAPI/MyAccount.pm
@@ -38,6 +38,7 @@ use FS::cust_main;
 use FS::cust_bill;
 use FS::legacy_cust_bill;
 use FS::cust_main_county;
+use FS::part_pkg;
 use FS::cust_pkg;
 use FS::payby;
 use FS::acct_rt_transaction;
@@ -926,6 +927,16 @@ sub validate_payment {
   my $amount = $1;
   return { error => 'Amount must be greater than 0' } unless $amount > 0;
 
+  #false laziness w/tr-amount_fee.html, but we don't want selfservice users
+  #changing the hidden form values
+  my $conf = new FS::Conf;
+  my $fee_display = $conf->config('selfservice_process-display') || 'add';
+  my $fee_pkgpart = $conf->config('selfservice_process-pkgpart');
+  if ( $fee_display eq 'add' && $fee_pkgpart ) {
+    my $fee_pkg = qsearchs('part_pkg', { pkgpart=>$fee_pkgpart } );
+    $amount = sprintf('%.2f', $amount + $fee_pkg->option('setup_fee') );
+  }
+
   $p->{'discount_term'} =~ /^\s*(\d*)\s*$/
     or return { 'error' => gettext('illegal_discount_term'). ': '. $p->{'discount_term'} };
   my $discount_term = $1;
@@ -1085,6 +1096,24 @@ sub do_process_payment {
   );
   return { 'error' => $error } if $error;
 
+  #no error, so order the fee package if applicable...
+  my $conf = new FS::Conf;
+  my $fee_pkgpart = $conf->config('selfservice_process-pkgpart');
+  if ( $fee_pkgpart ) {
+
+    my $cust_pkg = new FS::cust_pkg { 'pkgpart' => $fee_pkgpart };
+
+    $error = $cust_main->order_pkg( 'cust_pkg' => $cust_pkg );
+    return { 'error' => "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 ] );
+    return { 'error' => "payment processed and fee ordered sucessfully, but error billing fee: $error" }
+      if $error;
+
+  }
+
   $cust_main->apply_payments;
 
   if ( $validate->{'save'} ) {
diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index 8069fb4..39b59cf 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -2592,30 +2592,30 @@ and customer address. Include units.',
     'type'        => 'checkbox',
   },
 
-  {
-    'key'         => 'suto_process-pkgpart',
-    'section'     => 'billing',
-    'description' => 'Package to add to each automatic credit card and ACH payment processed by billing events.  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'         => 'auto_process-display',
+#    'key'         => 'auto_process-pkgpart',
 #    'section'     => 'billing',
-#    'description' => 'When using auto_process-pkgpart, add the fee to the amount entered (default), or subtract the fee from the amount entered.',
-#    'type'        => 'select',
-#    'select_hash' => [
-#                       'add'      => 'Add fee to amount entered',
-#                       'subtract' => 'Subtract fee from amount entered',
-#                     ],
+#    'description' => 'Package to add to each automatic credit card and ACH payment processed by billing events.  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'         => 'auto_process-display',
+##    'section'     => 'billing',
+##    'description' => 'When using auto_process-pkgpart, add the fee to the amount entered (default), or subtract the fee from the amount entered.',
+##    'type'        => 'select',
+##    'select_hash' => [
+##                       'add'      => 'Add fee to amount entered',
+##                       'subtract' => 'Subtract fee from amount entered',
+##                     ],
+##  },
+#
+#  {
+#    'key'         => 'auto_process-skip_first',
+#    'section'     => 'billing',
+#    'description' => "When using auto_process-pkgpart, omit the fee if it is the customer's first payment.",
+#    'type'        => 'checkbox',
 #  },
-
-  {
-    'key'         => 'auto_process-skip_first',
-    'section'     => 'billing',
-    'description' => "When using auto_process-pkgpart, omit the fee if it is the customer's first payment.",
-    'type'        => 'checkbox',
-  },
 
   {
     'key'         => 'allow_negative_charges',
diff --git a/fs_selfservice/FS-SelfService/cgi/make_payment.html b/fs_selfservice/FS-SelfService/cgi/make_payment.html
index bec37ca..defd4a5 100644
--- a/fs_selfservice/FS-SelfService/cgi/make_payment.html
+++ b/fs_selfservice/FS-SelfService/cgi/make_payment.html
@@ -9,29 +9,15 @@
   <TH ALIGN="right">Amount Due</TH>
   <TD COLSPAN=7>
     <TABLE><TR><TD BGCOLOR="#ffffff">
-      $<%=sprintf("%.2f",$balance)%>
-    </TD></TR></TABLE>
-  </TD>
-</TR>
-<TR>
-  <TH ALIGN="right">Payment amount</TH>
-  <TD COLSPAN=7>
-    <TABLE><TR><TD BGCOLOR="#ffffff">
-<%=
-    $amt = '';
-    if ( $balance > 0 ) {
-        $amt = $balance;
-        $amt += $amt * $credit_card_surcharge_percentage/100
-                                    if $credit_card_surcharge_percentage > 0;
-        $amt = sprintf("%.2f",$amt);
-    }
-    '';
-%>
-      $<INPUT TYPE="text" NAME="amount" SIZE=8 VALUE="<%=$amt%>">
+      <FONT COLOR="#000000">$<%=sprintf("%.2f",$balance)%></FONT>
     </TD></TR></TABLE>
   </TD>
 </TR>
+
+<%= $tr_amount_fee %>
+
 <%= include('discount_term') %>
+
 <TR>
   <TH ALIGN="right">Card type</TH>
   <TD COLSPAN=7>
diff --git a/fs_selfservice/FS-SelfService/cgi/selfservice.cgi b/fs_selfservice/FS-SelfService/cgi/selfservice.cgi
old mode 100644
new mode 100755
index fe8d082..61361b8
--- a/fs_selfservice/FS-SelfService/cgi/selfservice.cgi
+++ b/fs_selfservice/FS-SelfService/cgi/selfservice.cgi
@@ -476,7 +476,21 @@ sub process_order_recharge {
 }
 
 sub make_payment {
-  payment_info( 'session_id' => $session_id );
+
+  my $payment_info = payment_info( 'session_id' => $session_id );
+
+  my $tr_amount_fee = mason_comp(
+    'session_id' => $session_id,
+    'comp'       => '/elements/tr-amount_fee.html',
+    'args'       => [ 'amount' => $payment_info->{'balance'},
+                    ],
+  );
+
+  $tr_amount_fee = $tr_amount_fee->{'error'} || $tr_amount_fee->{'output'};
+
+  $payment_info->{'tr_amount_fee'} = $tr_amount_fee;
+
+  $payment_info;
 }
 
 sub payment_results {
diff --git a/httemplate/elements/tr-amount_fee.html b/httemplate/elements/tr-amount_fee.html
index a1a9e34..1248852 100644
--- a/httemplate/elements/tr-amount_fee.html
+++ b/httemplate/elements/tr-amount_fee.html
@@ -90,7 +90,9 @@ if ( $amount > 0 ) {
   $amount += $fee
     if $fee && $fee_display eq 'subtract';
 
-  &{ $opt{post_fee_callback} }( \$amount ) if $opt{post_fee_callback};
+  #&{ $opt{post_fee_callback} }( \$amount ) if $opt{post_fee_callback};
+  $amount += $amount * $opt{'surcharge_percentage'}/100
+    if $opt{'surcharge_percentage'} > 0;
 
   $amount = sprintf("%.2f", $amount);
 }
diff --git a/httemplate/misc/payment.cgi b/httemplate/misc/payment.cgi
index 1ae15b9..e221c60 100644
--- a/httemplate/misc/payment.cgi
+++ b/httemplate/misc/payment.cgi
@@ -16,7 +16,7 @@
        'process-display'    => scalar($conf->config('manual_process-display')),
        'process-skip-first' => $conf->exists('manual_process-skip_first'),
        'num_payments'       => scalar($cust_main->cust_pay), 
-       'post_fee_callback'  => $post_fee_callback,
+       'surcharge_percentage' => scalar($conf->config('credit-card-surcharge-percentage')),
   &>
 
   <& /elements/tr-select-discount_term.html,
@@ -269,19 +269,6 @@ if ( $balance > 0 ) {
   $amount = $balance;
 }
 
-my $post_fee_callback = sub {
-  my( $amountref ) = @_;
-
-  return unless $$amountref > 0;
-
-  my $conf = new FS::Conf;
-
-  my $cc_surcharge_pct = $conf->config('credit-card-surcharge-percentage');
-  $$amountref += $$amountref * $cc_surcharge_pct/100 if $cc_surcharge_pct > 0;
-
-  $$amountref = sprintf("%.2f", $$amountref);
-};
-
 my $payunique = "webui-payment-". time. "-$$-". rand() * 2**32;
 
 </%init>

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/ClientAPI/MasonComponent.pm                  |   23 +++++++++++
 FS/FS/ClientAPI/MyAccount.pm                       |   29 +++++++++++++
 FS/FS/Conf.pm                                      |   42 ++++++++++----------
 .../FS-SelfService/cgi/make_payment.html           |   24 ++---------
 fs_selfservice/FS-SelfService/cgi/selfservice.cgi  |   16 +++++++-
 httemplate/elements/tr-amount_fee.html             |    4 +-
 httemplate/misc/payment.cgi                        |   15 +-------
 7 files changed, 97 insertions(+), 56 deletions(-)
 mode change 100644 => 100755 fs_selfservice/FS-SelfService/cgi/selfservice.cgi




More information about the freeside-commits mailing list